arsd.color

Members

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, real percentage)

.

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

the opposite of moderate. Make darks darker and lights lighter

findNearestColor
ubyte findNearestColor(in Color[] palette, in 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, in TrueColorImage original)

Dithers img in place to look more like original.

fromHsl
Color fromHsl(real[3] hsl)

Converts hsl to rgb

fromHsl
Color fromHsl(real h, real s, real l, real a = 255)

Converts hsl to rgb

lighten
Color lighten(Color c, real 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, real percentage)

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

oppositeLightness
Color oppositeLightness(Color c)

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

quantize
IndexedImage quantize(in TrueColorImage img, Color[] palette = null, in int maxColors = 256)

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, real degrees)
saturate
Color saturate(Color c, real percentage)
setHue
Color setHue(Color c, real hue)
setSaturation
Color setSaturation(Color c, real saturation)
toHsl
real[3] toHsl(Color c, bool useWeightedLightness = false)

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.

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.

Structs

Color
struct Color

Represents an RGBA color

Point
struct Point
Rectangle
struct Rectangle
Size
struct Size

Meta