Documentation ¶
Overview ¶
Package utils provides useful helper functions for working with Images and Colors.
Index ¶
- Constants
- Variables
- func Average(cs ...color.Color) color.Color
- func ChopRectangle(rect image.Rectangle, rows, cols int, mode ExcessMode) []image.Rectangle
- func ChopRectangleToSizes(rect image.Rectangle, rowHeight, colWidth int, mode ExcessMode) []image.Rectangle
- func Closeness(one, two color.Color) uint32
- func EachColor(img image.Image, f func(c color.Color))
- func EachColorInRectangle(img image.Image, b image.Rectangle, f func(c color.Color))
- func FlagVisited(name string, flags flag.FlagSet) (didFind bool)
- func GetOutput(args []string) []string
- func Map(f func() Composable) func(image.Image) image.Image
- func MapAdjuster(f func(Adjuster) Composable) func(image.Image, Adjuster) image.Image
- func MapColor(img image.Image, f Composable) image.Image
- func MapColorInRectangle(img image.Image, bounds image.Rectangle, dest draw.Image, f Composable)
- func Max(ns ...uint32) (n uint32)
- func Maxf(ns ...float64) (n float64)
- func Min(ns ...uint32) (n uint32)
- func Minf(ns ...float64) (n float64)
- func NormalisedRGBA(c color.Color) (r, g, b, a uint32)
- func NormalisedRGBAf(c color.Color) (float64, float64, float64, float64)
- func PEachColor(img image.Image, f func(c color.Color))
- func RatioRGBA(c color.Color) (float64, float64, float64, float64)
- func ReadStdin() (image.Image, *exif.Exif)
- func Truncate(n uint32) uint32
- func Truncatef(n float64) float64
- func Warn(s ...interface{})
- func WriteStdout(img image.Image, data *exif.Exif)
- type Adjuster
- type Composable
- type Dimension
- type Direction
- type ExcessMode
Constants ¶
const ( PNG output = "png" JPEG = "jpeg" TIFF = "tiff" )
Formats that can be created by img.
Variables ¶
var Output = PNG
Output is the currently selected output type, and shouldn't be modified by anything other than GetOutput.
Functions ¶
func Average ¶
Average takes a list of colours and returns the average. Given an empty list it returns Black.
func ChopRectangle ¶
ChopRectangle splits a Rectangle into the number of rows and columns given.
func ChopRectangleToSizes ¶
func ChopRectangleToSizes(rect image.Rectangle, rowHeight, colWidth int, mode ExcessMode) []image.Rectangle
ChopRectangleToSizes splits a Rectangle into smaller Rectangles with the size given.
func Closeness ¶
Closeness calculates the "closeness" of two colours by finding the sum of differences in each colour channel.
func EachColor ¶
EachColor iterates through each pixel of the Image, applying the function to each colour.
func EachColorInRectangle ¶
EachColorInRectangle is a helper function for working on a part of an image.
func FlagVisited ¶
FlagVisited determines whether the named flag has been visited in the FlagSet given. This is helpful if you want to have a flag that triggers an action when given, but is not a boolean flag.
func GetOutput ¶
GetOutput takes the os.Args array as input, uses it to set the output format, then returns the new os.Args array.
os.Args = utils.GetOutput(os.Args) flag.Parse()
func Map ¶
func Map(f func() Composable) func(image.Image) image.Image
Map takes a Composable function, and returns a function that applies it to every pixel of an Image.
func MapAdjuster ¶
MapAdjuster takes a Composable function and an Adjuster, and returns a function that applies the function to every pixel of an Image.
func MapColor ¶
func MapColor(img image.Image, f Composable) image.Image
MapColor iterates through each pixel of the Image and applies the given function, drawing the returned colour to a new Image which is then returned.
func MapColorInRectangle ¶
MapColorInRectangle is a helper function for working on part of an image. It takes the original image, a function to use, a image to write to, and the bounds of the original (and therefore the final image) to act upon.
func NormalisedRGBA ¶
NormalisedRGBA returns the RGBA colour channel values of a Color in a normalised form. The values are in non-premultiplied form and are in the range 0-255.
This is modified from image/color.nrgbaModel
func NormalisedRGBAf ¶
NormalisedRGBAf returns the RGBA colour channel values as floating point numbers with values from 0 to 255.
func PEachColor ¶
PEachColor is like EachColor, but runs in parallel. This means that order can not be guaranteed.
func RatioRGBA ¶
RatioRGBA returns the RGBA colour channel values as floating point numbers with values from 0 to 1.
func Truncate ¶
Truncate takes a colour channel value and forces it into the range 0 to 255 by setting any value below 0 to 0 and and any above 255 to 255.
Types ¶
type Adjuster ¶
An Adjuster is a function which takes a floating point value, most likely between 0 and 1, and returns another floating point value, again between 0 and 1 (though this is not a requirement).
func Adder ¶
Adder returns an Adjuster which adds the value with to the returned Adjusters argument.
func Multiplier ¶
Multiplier returns an Adjuster which multiplies a given value with ratio.
type Composable ¶
A Composable function is one which can be composed with another function of the same type. It simply transforms a Color into another Color.
func Compose ¶
func Compose(fs ...Composable) Composable
Compose takes a variable list of Composable functions and returns a single Composable function which performs them sequentially. For example,
var f Composable = Compose( greyscale.BlueC(), brightness.AdjustC(utils.Adder(0.05)), ) // Only loops through image once! img = MapColors(img, f)
type Dimension ¶
type Dimension struct {
H, W int
}
Dimension represents a rectangle with Height and Width.
func SizeForCols ¶
SizeForCols determines the maximum (square) Dimensions to use that will fit the given number of columns into the image.
func SizeForRows ¶
SizeForRows determines the maximum (square) Dimensions to use that will fit the given number of rows into the image.
func SizeForRowsAndCols ¶
SizeForRowsAndCols determines the maximum (rectangular) Dimensions to use that will fit the given number of rows and columns into the image.
type Direction ¶
type Direction int
Direction represents one of 9 directions. these being the 4 vertices, the 4 sides, and the Centre of a square.
type ExcessMode ¶
type ExcessMode int
ExcessMode specifies how excess space is dealt with for tools that may produce results with different dimensions to the input image.
const ( // Ignore any "left over" space. So the resultant Rectangles may be smaller // than the original given. IGNORE ExcessMode = iota // Add the excess to the right- and bottom-most Rectangles. So the resultant // Rectangles will be the same size, but some edge Rectangles may be larger. ADD // Separate the excess into new Rectangles. So the resultant Rectangles will // be the same size, but some edge Rectangles may be smaller. SEPARATE )