arsd.color
-
Declaration
struct
Color
;Represents an RGBA color
-
Declaration
ubyte[4]
components
;[r, g, b, a]
Discussion
The color
components
are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly. -
Declaration
ubyte
r
;red
Discussion
Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.
-
Declaration
ubyte
g
;green
Discussion
Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.
-
Declaration
ubyte
b
;blue
Discussion
Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.
-
Declaration
ubyte
a
;alpha. 255 == opaque
Discussion
Holder for rgba individual components. The color components are available as
a
static array, individual bytes, anda
uint inside this union. Since it is anonymous, you can use the inner members' names directly. -
Declaration
uint
asUint
;The components as a single 32 bit value (beware of endian issues!)
Discussion
The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.
-
Declaration
static pure nothrow @safe Color
fromIntegers
(intred
, intgreen
, intblue
, intalpha
= 255);Like the constructor, but this makes sure they are in range before casting. If they are out of range, it saturates: anything less than zero becomes zero and anything greater than 255 becomes 255.
-
Declaration
pure nothrow @nogc @safe this(int
red
, intgreen
, intblue
, intalpha
= 255);Construct a color with the given values. They should be in range 0 <= x <= 255, where 255 is maximum intensity and 0 is minimum intensity.
-
Declaration
static pure nothrow @nogc @safe Color
transparent
();
static pure nothrow @nogc @safe Colorwhite
();
static pure nothrow @nogc @safe Colorblack
();
static pure nothrow @nogc @safe Colorred
();
static pure nothrow @nogc @safe Colorgreen
();
static pure nothrow @nogc @safe Colorblue
();
static pure nothrow @nogc @safe Coloryellow
();
static pure nothrow @nogc @safe Colorteal
();
static pure nothrow @nogc @safe Colorpurple
();Static convenience functions for common color names
-
Declaration
Color
toBW
()();Return black-and-white color
-
Declaration
const @safe string
toCssString
();Makes a string that matches CSS syntax for websites
-
Declaration
const @safe string
toString
();Makes a hex string RRGGBBAA (aa only present if it is not 255)
-
Declaration
const @safe string
toRgbaHexString
();returns RRGGBBAA, even if a== 255
-
Declaration
static @safe Color
fromNameString
(strings
);Gets a color by name, iff the name is one of the static members listed above
-
Declaration
static @safe Color
fromString
(strings
);Reads a CSS style string to get the color. Understands #rrggbb, rgba(), hsl(), and rrggbbaa
-
Declaration
static @safe Color
fromHsl
(realh
, reals
, reall
);from hsl
-
-
Declaration
@safe Color
fromHsl
(real[3]hsl
);Converts
hsl
to rgb -
Declaration
@safe Color
fromHsl
(realh
, reals
, reall
, reala
= 255);Converts hsl to rgb
-
Declaration
@safe real[3]
toHsl
(Colorc
, booluseWeightedLightness
= 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 isfalse
, it just does average of the rgb. -
Declaration
@safe Color
lighten
(Colorc
, realpercentage
);.
-
Declaration
@safe Color
darken
(Colorc
, realpercentage
);.
-
Declaration
@safe Color
moderate
(Colorc
, realpercentage
);for light colors, call darken. for dark colors, call lighten.
Discussion
The goal: get toward center grey.
-
Declaration
@safe Color
extremify
(Colorc
, realpercentage
);the opposite of moderate. Make darks darker and lights lighter
-
Declaration
@safe Color
oppositeLightness
(Colorc
);Move around the lightness wheel, trying not to break on moderate things
-
Declaration
@safe Color
makeTextColor
(Colorc
);Try to determine a text color - either white or black - based on the input
-
Declaration
@safe Color
rotateHue
(Colorc
, realdegrees
); -
Declaration
@safe Color
setHue
(Colorc
, realhue
); -
Declaration
@safe Color
desaturate
(Colorc
, realpercentage
); -
Declaration
@safe Color
saturate
(Colorc
, realpercentage
); -
Declaration
@safe Color
setSaturation
(Colorc
, realsaturation
); -
Declaration
@safe ubyte
unalpha
(ubytecolorYouHave
, floatalpha
, ubytebackgroundColor
); -
Declaration
@safe ubyte
makeAlpha
(ubytecolorYouHave
, ubytebackgroundColor
); -
Declaration
@safe Color
colorFromString
(strings
); -
Declaration
interface
MemoryImage
;This provides two image classes and a bunch of functions that work on them.
Discussion
Why are they separate classes? I think the operations on the two of them are necessarily different. There's a whole bunch of operations that only really work on truecolor (blurs, gradients), and a few that only work on indexed images (palette swaps). Even putpixel is pretty different. On indexed, it is a palette entry's index number. On truecolor, it is the actual color. A greyscale image is the weird thing in the middle. It is truecolor, but fits in the same size as indexed. Still, I'd say it is a specialization of truecolor. There is a subset that works on both An image in memory
-
Declaration
abstract @safe TrueColorImage
getAsTrueColorImage
();gets it as a TrueColorImage. May return this or may do a conversion and return a new image
-
Declaration
abstract const @safe int
width
();Image
width
, in pixels -
Declaration
abstract const @safe int
height
();Image
height
, in pixels -
Declaration
abstract const @safe Color
getPixel
(intx
, inty
);Get image pixel. Slow, but returns valid RGBA color (completely transparent for off-image pixels).
-
Declaration
abstract @safe void
setPixel
(intx
, inty
, in Colorclr
);Set image pixel.
-
Declaration
@trusted MemoryImage
fromImage
(T : const(char)[])(Tfilename
);Load image from file. This will import arsd.png and arsd.jpeg to do the actual work, and cost nothing if you don't use it.
-
-
Declaration
class
IndexedImage
: arsd.color.MemoryImage;An image that consists of indexes into a color palette. Use [getAsTrueColorImage]() if you don't care about palettes
-
Declaration
Color[]
palette
;.
-
Declaration
ubyte[]
data
;the
data
as indexes into the palette. Stored left to right, top to bottom, no padding. -
Declaration
const @safe int
width
();.
-
Declaration
const @safe int
height
();.
-
Declaration
@safe this(int
w
, inth
);.
-
Declaration
@safe TrueColorImage
getAsTrueColorImage
();returns a new image
-
Declaration
const @safe TrueColorImage
convertToTrueColor
();Creates a new TrueColorImage based on this data
-
Declaration
@safe ubyte
getOrAddColor
(Colorc
);Gets an exact match, if possible, adds if not. See also: the findNearestColor free function.
-
Declaration
const @safe int
numColors
();Number of colors currently in the palette (note: palette entries are not necessarily used in the image data)
-
Declaration
@safe ubyte
addColor
(Colorc
);Adds an entry to the palette, returning its inded
-
-
Declaration
class
TrueColorImage
: arsd.color.MemoryImage;An RGBA array of image data. Use the free function quantize() to convert to an IndexedImage
-
Declaration
struct
Data
; -
Declaration
Data
imageData
;.
-
Declaration
const @safe int
width
();.
-
Declaration
const @safe int
height
();.
-
Declaration
@safe this(int
w
, inth
);.
-
Declaration
@safe this(int
w
, inth
, ubyte[]data
);Creates with existing
data
. Thedata
pointer is stored here. -
Declaration
@safe TrueColorImage
getAsTrueColorImage
();Returns this
-
-
Declaration
@safe IndexedImage
quantize
(in TrueColorImageimg
, Color[]palette
= null, in intmaxColors
= 256);Converts
true
color to an indexed image. It usespalette
as the starting point, adding entriesDiscussion
until
maxColors
as needed. Ifpalette
isnull
, it creates a whole newpalette
. After quantizing the image, it applies a dithering algorithm. This is not written for speed. -
Declaration
@safe ubyte
findNearestColor
(in Color[]palette
, in Colorpixel
);Finds the best match for
pixel
inpalette
(currently by checking for minimum euclidean distance in rgb colorspace) -
Declaration
@safe void
floydSteinbergDither
(IndexedImageimg
, in TrueColorImageoriginal
);Dithers
img
in place to look more likeoriginal
. -
Declaration
struct
Point
; -
Declaration
struct
Size
; -
Declaration
struct
Rectangle
;