utils

package
v0.3.2-beta Latest Latest
Warning

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

Go to latest
Published: Jul 31, 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 ClampFloat64

func ClampFloat64(min, x, max float64) float64

Clamp the x float64 between min and max. Return min if x is smaller than min and max if x is greater than max, otherwise return x.

func ClampInt

func ClampInt(min, x, max int) int

Clamp the x int between min and max. Return min if x is smaller than min and max if x is greater than max, otherwise return x.

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 GrayscaleNrgba

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

Create a grayscale version of the provided NRGBA color-space image.

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 Max2Uint8

func Max2Uint8(a, b uint8) uint8

Get the greatest uint8 from the two provided values.

func Max3Float64

func Max3Float64(a, b, c float64) float64

Get the greatest float64 from the three provided values.

func Min2Uint8

func Min2Uint8(a, b uint8) uint8

Get the smallest uint8 from the two provided values.

func Min3Float64

func Min3Float64(a, b, c float64) float64

Get the smallest float64 from the three provided values.

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

func TrimImageTransparentWorkspaceNrgba

func TrimImageTransparentWorkspaceNrgba(withWorkspace *image.NRGBA, original image.Rectangle) *image.NRGBA

TODO: Add missing docs and unit tests

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