utils

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 ColorToRgba

func ColorToRgba(c color.Color) (color.RGBA, error)

Convert a color represented as color.Color interface to color.RGBA struct. This function will return an error if the underlying color is not a color.RGBA

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 interface slice specified by the x image index

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 interface slice specified by the y image index

func HasAnyTransparency

func HasAnyTransparency(c color.RGBA) bool

Return a boolean value indicating if the given color.RGBA color has the alpha channel >255

func InvertImage

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

Invert the colors (negative-effect) of the image

func NrgbaToGrayscaleComponent

func NrgbaToGrayscaleComponent(c color.NRGBA) int

Convert the color.NRGBA struct to the Y grayscale component represented as integer in range from 0 to 255

func NrgbaToIntComponents

func NrgbaToIntComponents(c color.NRGBA) (int, int, int)

Convert the color.NRGBA struct to individual RGB components represented as integers in range from 0 to 255

func RgbaToGrayscaleComponent

func RgbaToGrayscaleComponent(c color.RGBA) int

Convert the color.RGBA struct to the Y grayscale component represented as integer in range from 0 to 255

func RgbaToHsl

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

Convert a color represented as color.RGBA to HSL components where Hue is expressed in degress (0-360) and the saturation and lightnes in percentage (0.0-1.0)

func RgbaToIntComponents

func RgbaToIntComponents(c color.RGBA) (int, int, int)

Convert the color.RGBA struct to individual RGB components represented as integers in range from 0 to 255

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 draw.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 SetImageColumn

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

Append a Color interface slice representing a column at a given x index of the given image

func SetImageRow

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

Append a Color interface slice representing a row at a given y index of the given image

func StoreImageToFile

func StoreImageToFile(fileName 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

This section is empty.

Jump to

Keyboard shortcuts

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