utils

package
v0.3.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlendImagesNrgba

func BlendImagesNrgba(a, b *image.NRGBA, mode BlendingMode) (*image.NRGBA, error)

Blend two NRGBA images using a given blending mode into a new image.

func BlendNrgba

func BlendNrgba(a, b color.NRGBA, mode BlendingMode) color.NRGBA

Perform blending of two color.NRGBA colors according to a given blending mode TODO: Currently the alpha channel of the output color has a fixed 0xff value

func CIntn

func CIntn(n int) int

Thread-safe equivalent of rand.Intn that generates values in range: [0, n). See rand.Intn specification for more details. This implementation does not support seeds.

func CalculatePerceivedBrightness

func CalculatePerceivedBrightness(c color.RGBA) float64

Calculate the perceived brightness of the color given in the RGBA color space. https://stackoverflow.com/questions/596216/formula-to-determine-perceived-brightness-of-rgb-color

func EscapePathQuotes

func EscapePathQuotes(path string) (string, error)

Remove the quotes surrounding the path. The operation will fail for more than 10 iterations.

func GetImageCopyNrgba

func GetImageCopyNrgba(i *image.NRGBA) *image.NRGBA

Get a copy of the provided image.NRGBA image. This function will panic if the provided image pointer is nil.

func GetImageCopyRgba

func GetImageCopyRgba(i *image.RGBA) *image.RGBA

Get a copy of the provided image.RGBA image. This function will panic if the provided image pointer is nil.

func GetImageFromFile

func GetImageFromFile(filePath string) (image.Image, error)

Get the image from a file specified by the given path

func ImageToNrgbaImage

func ImageToNrgbaImage(i image.Image) *image.NRGBA

Convert a image represented by image.Image to a NRGBA image. If the underlying type is already NRGBA a reference to the original input will be returned, otherwis a copy will be created.

func ImageToRgbaImage

func ImageToRgbaImage(i image.Image) *image.RGBA

Convert a image represented by image.Image to a RGBA image. If the underlying type is already RGBA a reference to the original input will be returned, otherwis a copy will be created.

func InterpolateRgba

func InterpolateRgba(a, b color.RGBA, t float64) color.RGBA

Performa a linear interpolation between two color.RGBA colors and return the interpolated color for the given t point

func InvertImageNrgba

func InvertImageNrgba(i *image.NRGBA) *image.NRGBA

Invert the colors (negative-effect) of the given NRGBA image.

func Lerp

func Lerp(a, b, t float64) float64

Perform a linear interpolation between value "a" and "b" and return the interpolated value at "t"

func NewErrorTrap

func NewErrorTrap() *errorTrap

Create a new atomic error trap which can be used to capture the first error accross multiple goroutines.

func NrgbaToGrayscaleComponent

func NrgbaToGrayscaleComponent(c color.NRGBA) int

Convert the color.NRGBA color to the Y grayscale component represented as a integer in range from 0 to 255. Note that the alpha channel is not taken under account and the result is non-alpha-premultiplied.

func NrgbaToRgbaImage

func NrgbaToRgbaImage(i *image.NRGBA) *image.RGBA

Create a RGBA color-space copy of an image represented in the NRGBA color-space.

func RgbaToHsla

func RgbaToHsla(c color.RGBA) (int, float64, float64, float64)

Convert a color.RGBA color to HSL+Alpha components where Hue is expressed in degress (0-360) and the saturation, lightnes and alpha\ in percentage (0.0-1.0)

func RgbaToNormalizedComponents

func RgbaToNormalizedComponents(c color.RGBA) (float64, float64, float64)

Convert the color.RGBA struct tu individual RGB components represented as floating point numbers in range from 0.0 to 1.0

func RgbaToNrgbaImage

func RgbaToNrgbaImage(i *image.RGBA) *image.NRGBA

Create a NRGBA color-space copy of an image represented in the RGBA color-space. TODO: Reimplement this function using the pimit parallelization

func RotateImageNrgba

func RotateImageNrgba(i *image.NRGBA, angle int) *image.NRGBA

Rotate the NRGBA image counter-clockwise by a given angle.

func RotateImageWithRevertNrgba

func RotateImageWithRevertNrgba(i *image.NRGBA, angle int) (*image.NRGBA, func(*image.NRGBA) *image.NRGBA)

Rotate the NRGBA image counter-clockwise by a given angle and expose a function that can be used to rotate the image back to its previous state and remove excess workspace transparency.

func ScaleImageNrgba

func ScaleImageNrgba(i *image.NRGBA, percentage float64) (*image.NRGBA, error)

Function used to scale a NRGBA image down according to given percentage parameter (Value from 0.0 to 1.0).

func StoreImageToFile

func StoreImageToFile(filePath string, fileFormat string, img image.Image) error

Create a new file with the given name and format and store the given image in it

Types

type BlendingMode

type BlendingMode int

Representation of a blending mode algorithm

const (
	LightenOnly BlendingMode = iota
	DarkenOnly
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL