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

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.

fromHsl
Color fromHsl(real[3] hsl)

Converts hsl to rgb

fromHsl
Color fromHsl(double h, double s, double l, double a)

Converts hsl to rgb

fromOklab
Color fromOklab(Lab c)

OKLab colorspace conversions to/from Color. See: https://bottosson.github.io/posts/oklab/

lighten
Color lighten(Color c, double percentage)

.

linearOffset
int linearOffset(Point pos, int width)
int linearOffset(int width, Point pos)

Calculates the linear offset of a point from the start (0/0) of a rectangle.

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.

oppositeLightness
Color oppositeLightness(Color c)

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

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)
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.

toOklab
Lab toOklab(Color c)

OKLab colorspace conversions to/from Color. See: https://bottosson.github.io/posts/oklab/

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

Angle
struct Angle

A type to represent an angle, taking away ambiguity of if it wants degrees or radians.

Color
struct Color

Represents an RGBA color

ColorF
struct ColorF

Represents an RGBA color in floating-point (from 0 to 1.0).

Lab
struct Lab

OKLab colorspace conversions to/from Color. See: https://bottosson.github.io/posts/oklab/

Point
struct Point

2D location point

Rectangle
struct Rectangle
Size
struct Size

Meta