arsd.color

Base module for working with colors and in-memory image pixmaps.

Also has various basic data type definitions that are generally useful with images like Point, Size, and Rectangle.

Members

Aliases

Comparator
alias Comparator = int function(scope const void*, scope const void*) @(system)
Undocumented in source.

Classes

IndexedImage
class IndexedImage

An image that consists of indexes into a color palette. Use getAsTrueColorImage if you don't care about palettes

TrueColorImage
class TrueColorImage

An RGBA array of image data. Use the free function quantize() to convert to an IndexedImage

Functions

alphaBlend
Color alphaBlend(Color foreground, Color background)

Perform alpha-blending of fore to this color, return new color. WARNING! This function does blending in RGB space, and RGB space is not linear!

colorFromString
Color colorFromString(string s)
darken
Color darken(Color c, double percentage)

.

desaturate
Color desaturate(Color c, double percentage)
extremify
Color extremify(Color c, double percentage)

the opposite of moderate. Make darks darker and lights lighter

findNearestColor
ubyte findNearestColor(Color[] palette, Color pixel)

Finds the best match for pixel in palette (currently by checking for minimum euclidean distance in rgb colorspace)

floodFill
void floodFill(T[] what, int width, int height, T target, T replacement, int x, int y, bool delegate(int x, int y) @(safe) additionalCheck)

Implements a flood fill algorithm, like the bucket tool in MS Paint.

floydSteinbergDither
void floydSteinbergDither(IndexedImage img, TrueColorImage original)

Dithers img in place to look more like original.

fromHex
int fromHex(string s)
Undocumented in source. Be warned that the author may not have intended to support it.
fromHsl
Color fromHsl(real[3] hsl)

Converts hsl to rgb

fromHsl
Color fromHsl(double[3] hsl)
Undocumented in source. Be warned that the author may not have intended to support it.
fromHsl
Color fromHsl(double h, double s, double l, double a)

Converts hsl to rgb

lighten
Color lighten(Color c, double percentage)

.

makeAlpha
ubyte makeAlpha(ubyte colorYouHave, ubyte backgroundColor)
makeTextColor
Color makeTextColor(Color c)

Try to determine a text color - either white or black - based on the input

moderate
Color moderate(Color c, double percentage)

for light colors, call darken. for dark colors, call lighten. The goal: get toward center grey.

nonPhobosSort
void nonPhobosSort(T[] obj, Comparator comparator)
Undocumented in source. Be warned that the author may not have intended to support it.
oppositeLightness
Color oppositeLightness(Color c)

Move around the lightness wheel, trying not to break on moderate things

premultiplyBgra
void premultiplyBgra(ubyte[] bgra)
Undocumented in source.
quantize
IndexedImage quantize(TrueColorImage img, Color[] palette, int maxColors)

Converts true color to an indexed image. It uses palette as the starting point, adding entries until maxColors as needed. If palette is null, it creates a whole new palette.

rotateHue
Color rotateHue(Color c, double degrees)
saturate
Color saturate(Color c, double percentage)
setHue
Color setHue(Color c, double hue)
setLightness
Color setLightness(Color c, double lightness)
Undocumented in source. Be warned that the author may not have intended to support it.
setSaturation
Color setSaturation(Color c, double saturation)
srgbToLinearRgb
double srgbToLinearRgb(double u)

Assumes the input u is already between 0 and 1 fyi.

toHsl
double[3] toHsl(Color c, bool useWeightedLightness)

Converts an RGB color into an HSL triplet. useWeightedLightness will try to get a better value for luminosity for the human eye, which is more sensitive to green than red and more to red than blue. If it is false, it just does average of the rgb.

toInternal
string toInternal(int a)
Undocumented in source. Be warned that the author may not have intended to support it.
unPremultiplyRgba
void unPremultiplyRgba(ubyte[] rgba)
Undocumented in source.
unalpha
ubyte unalpha(ubyte colorYouHave, float alpha, ubyte backgroundColor)

Interfaces

MemoryImage
interface MemoryImage

This provides two image classes and a bunch of functions that work on them.

Manifest constants

arsd_jsvar_compatible
enum arsd_jsvar_compatible;
Undocumented in source.

Structs

Color
struct Color

Represents an RGBA color

Point
struct Point
Rectangle
struct Rectangle
Size
struct Size

Meta