utils

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlendImages

func BlendImages(a, b image.Image, mode BlendingMode) (draw.Image, error)

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

func BlendRGBA

func BlendRGBA(a, b color.RGBA, mode BlendingMode) color.RGBA

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

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 ColorToGrayscaleComponent

func ColorToGrayscaleComponent(c color.Color) int

Convert the color.Color interface instance to the Y grayscale component represented as a integer in range from 0 to 255

func ColorToHsla

func ColorToHsla(c color.Color) (int, float64, float64, float64)

Convert a color represented as color.Color interface implementation 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 ColorToRgba

func ColorToRgba(c color.Color) color.RGBA

Convert a color represented as color.Color interface to color.RGBA struct. If the underlying color is a color.RGBA the original struct will be returned, otherwise a new color.RGBA instance will be created

func EscapePathQuotes

func EscapePathQuotes(path string) (string, error)

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

func GetDrawableImage

func GetDrawableImage(i image.Image) (draw.Image, error)

Get the drawable copy of the provided image. The image is also redrawn to a new image.RGBA struct

func GetImageColumn

func GetImageColumn(image image.Image, xIndex int) ([]color.Color, error)

Get the image column as a color.Color interface implementation slice specified by the x image index. The retrieval process is run parallel in several goroutines.

func GetImageFromFile

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

Get the image from a file specified by the given path

func GetImageRow

func GetImageRow(image image.Image, yIndex int) ([]color.Color, error)

Get the image row as a color.Color interface implementation slice specified by the y image index. The retrieval process is run parallel in several goroutines.

func HasAnyTransparency

func HasAnyTransparency(c color.Color) bool

Return a boolean value indicating if the given color.Color interface implementation has the alpha channel <255

func InvertImage

func InvertImage(i image.Image) (draw.Image, error)

Invert the colors (negative-effect) of the image

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 RotateImage

func RotateImage(i image.Image, angle int) draw.Image

Rotate the image by a given angle

Beacuse the dependency internal rotate implementation is using a custom pixel color handling solution we need to redraw the result image to ensure that the colors space is RGBA

func ScaleImage

func ScaleImage(i image.Image, percentage float64) (draw.Image, error)

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

func SetImageColumn

func SetImageColumn(image draw.Image, column []color.Color, xIndex int) error

Set the colors of the column of the given image specified by the xIndex, according to the slice containing implementations of the color.Color interface. The changes made will be applied to the given draw.Image reference. The write process is run parallel in several goroutines.

func SetImageRow

func SetImageRow(image draw.Image, row []color.Color, yIndex int) error

Set the colors of the row of the given image specified by the yIndex, according to the slice containing implementations of the color.Color interface. The changes made will be applied to the given draw.Image reference. The write process is run parallel in several goroutines.

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 TrimImageTransparentWorkspace

func TrimImageTransparentWorkspace(imageWithWorkspace draw.Image, imageOriginal image.Image) draw.Image

FIXME: Fix borders after interpolation and implement full transparency support in order to preserve PNG data. FIXME: Better handling for situations where there is not requirement to trim the workspace. Currently in such situation we are returning the original imageWithWorkspace draw.Image instead of creating a copy.

Remove all excess transparent workspace created during the rotation process from the image. The function is calculating the image located in the middle of the workspace and is cropping it. Due to rotation interpolation the borders of the image are not matching the original image, and the whole operation can cause some problems realted to transparent colors.

Time complexity: O(n)

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