8.10
6 RRLL: Color Support
Racket Rogue-Like Library: Color Support
Various utilitis for color manipulation, blending and lighting.
6.1 Core Color Functions
Requiring this module raises error if the system word size is less
than 64 bits.
alpha-max : fixnum? = #xff
|
Defines the maximum alpha channel value for 32-bit ARGB color representation.
alpha-mask : fixnum? = #xff000000
|
Bit mask of the alpha channel part or 32-bit ARGB color representation.
Splits given 24-bit RGB value into its 8-bit components.
(split-argb color) | | → | | fixnum? | | fixnum? | | fixnum? | | fixnum? |
|
|
color : fixnum? |
Splits given 32-bit ARGB value into its 8-bit components.
(make-rgb r g b) → fixnum?
|
r : fixnum? |
g : fixnum? |
b : fixnum? |
Creates a 24-bit RGB color from 8-bit components.
(make-argb a r g b) → fixnum?
|
a : fixnum? |
r : fixnum? |
g : fixnum? |
b : fixnum? |
Creates a 32-bit ARGB color from 8-bit components.
(extract-argb-alpha argb) → fixnum?
|
argb : fixnum? |
Extracts only alpha-channel value from given 32-bit ARGB color.
(set-argb-alpha argb alpha) → fixnum?
|
argb : fixnum? |
alpha : fixnum? |
Modifies given ARGB value and returns a new one with the alpha
channel replaced by the explicit value given.
(rgb-distance^2 c1 c2) → fixnum?
|
c1 : fixnum? |
c2 : fixnum? |
Computes the square of euclidean distance in RGB space of the two colors given.
d=(r_1-r_2)^2+(g_1-g_2)^2+(b_1-b_2)^2
(is-argb? -rgb) → boolean?
|
-rgb : fixnum? |
Returns #t if the given -rgb value has non-zero
alpha channel.
6.2 Color Blending
(rgb-average color ...) → fixnum?
|
color : fixnum? |
Averages given RGB values.
(rgb-average2 c0 c1) → fixnum?
|
c0 : fixnum? |
c1 : fixnum? |
Optimized implementation that averages two RGB values.
(rgb-average4 c0 c1 c2 c3) → fixnum?
|
c0 : fixnum? |
c1 : fixnum? |
c2 : fixnum? |
c3 : fixnum? |
Optimized implementation that averages four RGB values.
(argb-average color ...) → fixnum?
|
color : fixnum? |
Averages given ARGB values.
(argb-average2 c0 c1) → fixnum?
|
c0 : fixnum? |
c1 : fixnum? |
Optimized implementation that averages two ARGB values.
(argb-average4 c0 c1 c2 c3) → fixnum?
|
c0 : fixnum? |
c1 : fixnum? |
c2 : fixnum? |
c3 : fixnum? |
Optimized implementation that averages four ARGB values.
(alpha-blend-alpha a1 a2) → fixnum?
|
a1 : fixnum? |
a2 : fixnum? |
Blends alpha2 alpha value over alpha1 value using:
\alpha=\alpha_1\cdot\alpha_2
\alpha_1,\alpha_2\in\langle 0;255\rangle \equiv \langle 0.0;1.0\rangle
(rgb-blend-argb rgb argb) → fixnum?
|
rgb : fixnum? |
argb : fixnum? |
Blends argb over rgb based on the alpha channel value.
(rgb-blend-rgb+alpha rgb0 rgb1 alpha) → fixnum?
|
rgb0 : fixnum? |
rgb1 : fixnum? |
alpha : fixnum? |
Blends rgb1 over rgb0 based on the alpha value.
\alpha\in\langle 0;255\rangle\equiv\langle 0.0;1.0\rangle
(rgb-blend-argb+alpha rgb argb alpha) → fixnum?
|
rgb : fixnum? |
argb : fixnum? |
alpha : fixnum? |
Blends argb over rgb based on the combined alpha channel and given alpha value.
\alpha\in\langle 0;255\rangle\equiv\langle 0.0;1.0\rangle
Uses alpha-blend-alpha to merge argb’s alpha channel with the alpha value.
(rgb-linear c0 c1 f) → fixnum?
|
c0 : fixnum? |
c1 : fixnum? |
f : fixnum? |
Linearly interpolates two RGB colors using given f factor.
f\in\langle 0;256\rangle\equiv\langle 0.0;1.0\rangle
(argb-linear c0 c1 f) → fixnum?
|
c0 : fixnum? |
c1 : fixnum? |
f : fixnum? |
Linearly interpolates two ARGB colors using given f factor.
f\in\langle 0;256\rangle\equiv\langle 0.0;1.0\rangle
(rgb-bilinear r0c0 r0c1 r1c0 r1c1 u v) → fixnum?
|
r0c0 : fixnum? |
r0c1 : fixnum? |
r1c0 : fixnum? |
r1c1 : fixnum? |
u : fixnum? |
v : fixnum? |
Performs bilinear interpolation between four RGB colors.
u,v\in\langle 0;256\rangle\equiv\langle 0.0;1.0\rangle
(argb-bilinear r0c0 r0c1 r1c0 r1c1 u v) → fixnum?
|
r0c0 : fixnum? |
r0c1 : fixnum? |
r1c0 : fixnum? |
r1c1 : fixnum? |
u : fixnum? |
v : fixnum? |
Performs bilinear interpolation between four ARGB colors.
u,v\in\langle 0;256\rangle\equiv\langle 0.0;1.0\rangle
6.3 Color Names
The following 16 fixnum? constants are defined:
BLACK BLUE GREEN CYAN RED MAGENTA BROWN LIGHTGRAY DARKGRAY LIGHTBLUE LIGHTGREEN LIGHTCYAN LIGHTRED LIGHTMAGENTA YELLOW WHITE
CGA-COLORS : (vectorof fixnum?)
|
Contains the ordered vector of 16 aforementioned CGA colors.
6.4 Flonum Colors
This module provides flonum?-based RGB and ARGB processing
used when color interpolation is required.
(make-flrgb r g b) → flvector?
|
r : flonum? |
g : flonum? |
b : flonum? |
Creates new RGB triplet. The result is (flvector b g r) to
keep the in-memory ordering the same as with byte-channel RGB.
(make-flargb a r g b) → flvector?
|
a : flonum? |
r : flonum? |
g : flonum? |
b : flonum? |
Creates new RGB triplet. The result is (flvector b g r a) to
keep the in-memory ordering the same as with byte-channel ARGB.
Returns the red, green and blue channels as separate values. See
make-flrgb for the in-memory data ordering.
(split-flargb fc) | | → | | flonum? | | flonum? | | flonum? | | flonum? |
|
|
fc : flvector? |
Returns the alpha, red, green and blue channels as separate
values. See make-flargb for the in-memory data ordering.
(rgb->flrgb c) → flvector?
|
c : fixnum? |
Convers given RGB color (see make-rgb) to flvector? RGB
represenation (see make-flrgb).
(flrgb->rgb fc) → fixnum?
|
fc : flvector? |
Converts given flonum? RGB color to single-fixnum?
color. See make-flrgb for the former and make-rgb
for the latter.
(argb->flargb c) → flvector?
|
c : fixnum? |
Convers given ARGB color (see make-argb) to flvector? ARGB
represenation (see make-flargb).
(flargb->argb fc) → fixnum?
|
fc : flvector? |
Converts given flonum? ARGB color to single-fixnum?
color. See make-flargb for the former and make-argb
for the latter.
(flrgb-add fc1 fc2) → flvector?
|
fc1 : flvector? |
fc2 : flvector? |
Adds two flonum? RGB triplets together. No clamping is performed.
(flargb-add fc1 fc2) → flvector?
|
fc1 : flvector? |
fc2 : flvector? |
Adds two flonum? ARGB quadruplets together. No clamping is performed.
(flrgb-div fc n) → flvector?
|
fc : flvector? |
n : flonum? |
Divides all components of a flonum? RGB color by given number.
(flargb-div fc n) → flvector?
|
fc : flvector? |
n : flonum? |
Divides all components of a flonum? ARGB color by given number.
(flrgb-mul fc n) → flvector?
|
fc : flvector? |
n : flonum? |
Multiplies all components of a flonum? RGB color by given number.
(flargb-mul fc n) → flvector?
|
fc : flvector? |
n : flonum? |
Multiplies all components of a flonum? ARGB color by given number.
6.5 Color Lighting
This module provides reference implementaiton of colored lighting
routines to be used by the renderer mostly for Goraud shading.
(make-light r g b) → flvector?
|
r : flonum? |
g : flonum? |
b : flonum? |
Creates a colored light data structure of three fload numbers in single flvector?.
(light-rgb rgb l) → fixnum?
|
rgb : fixnum? |
l : flvector? |
Applies colored light to given color value and returns the lit color.
Each component is adjusted according to:
c=c_0\cdot l
The result is fxclamped in \langle 0;255\rangle.
(light-argb argb l) → fixnum?
|
argb : fixnum? |
l : flvector? |
Applies colored light to given color value and returns the lit color
like light-rgb. The alpha component of the color is kept
unchanged.
(light-add l1 l2) → flvector?
|
l1 : flvector? |
l2 : flvector? |
An alias for flrgb-add.
6.6 Random Colors
Helper module for random RGB and ARGB colors where needed.
Generates valid random RGB color.
Generates valid random ARGB quadruplet.
6.7 Color Interpolation
This module implements a special format with more bits per channel to
allow simple iteration over (possibly multi-dimensional) field of
color values.
(rgb+add rgb+1 rgb+2) → fixnum?
|
rgb+1 : fixnum? |
rgb+2 : fixnum? |
Adds two RGB+ values maintaining the bit format.
(make-rgb+ r g b) → fixnum?
|
r : flonum? |
g : flonum? |
b : flonum? |
Returns RGB+ representation of given RGB triplet.
(rgb+>rgb rgb+) → fixnum?
|
rgb+ : fixnum? |
Converts to standard RGB representation.
(argb+add argb+1 argb+2) → fixnum?
|
argb+1 : fixnum? |
argb+2 : fixnum? |
Adds two ARGB+ values maintaining the bit format.
(make-argb+ a r g b) → fixnum?
|
a : flonum? |
r : flonum? |
g : flonum? |
b : flonum? |
Returns ARGB+ representation of given ARGB quadruplet.
(argb+>argb argb+) → fixnum?
|
argb+ : fixnum? |
Converts to standard ARGB representation.
6.8 Fixed-Point Color Light
(fxlight-rgb rgbc rgbl) → fixnum?
|
rgbc : fixnum? |
rgbl : fixnum? |
Lights given rgbc color using the rgbl light. The
light components are interpreted as follows:
These values were chosen purely for performance reasons.
(fxlight-argb argbc rgbl) → fixnum?
|
argbc : fixnum? |
rgbl : fixnum? |
Lights the argbc color using rgbl light, preserving
the alpha channel of the source.