rgba
Colors

Next:<rgba> ( red green blue alpha -- rgba )


Vocabulary
colors

Class description
The class of colors with red, green, blue and alpha channel components. The slots store color components, which are real numbers in the range 0 to 1, inclusive.

Definition


Methods







M: rgba >hsla
>rgba-components [
3 load-locals -2 get-local -1 get-local 0 get-local min
min load-local
-3 get-local -2 get-local -1 get-local max max
load-local -1 get-local 0 get-local + 2 / load-local
-1 get-local -2 get-local - load-local 0 get-local zero?
[ 0.0 0.0 ] -2 get-local -6 get-local -5 get-local -4
get-local 0 get-local -1 get-local -3 get-local [
7 load-locals -6 get-local dup -5 get-local =
-4 get-local -3 get-local -2 get-local [
3 load-locals drop -2 get-local -1 get-local -
0 get-local / -2 get-local -1 get-local <
6.0 0.0 ? 3 drop-locals +
] curry curry curry
-4 get-local -3 get-local -5 get-local -2 get-local
[
4 load-locals dup -3 get-local =
-2 get-local -1 get-local 0 get-local [
3 load-locals drop
-2 get-local -1 get-local - 0 get-local /
2.0 3 drop-locals +
] curry curry curry
-2 get-local -1 get-local -3 get-local 0
get-local [
4 load-locals dup -3 get-local =
-2 get-local -1 get-local 0 get-local [
3 load-locals drop
-2 get-local -1 get-local -
0 get-local / 4.0 3 drop-locals +
] curry curry curry
[ no-case ] 4 drop-locals if
] curry curry curry curry 4 drop-locals if
] curry curry curry curry if 6.0 /
-1 get-local 0.5 >
-2 get-local -6 get-local 0 get-local [
3 load-locals -2 get-local 2 -1 get-local -
0 get-local - 3 drop-locals /
] curry curry curry
-2 get-local -6 get-local 0 get-local [
3 load-locals
-2 get-local -1 get-local 0 get-local +
3 drop-locals /
] curry curry curry 7 drop-locals if
] curry curry curry curry curry curry curry if
-1 get-local 7 drop-locals
] dip <hsla> ;



M:: rgba >hsva ( rgba -- hsva )
rgba >rgba-components :> ( r g b a ) r g b sort-triple
:> ( z y x ) x z = x zero? or
[ 0 0 x a <hsva> ] [
{
{ [ r x = g z = and ] [ 5 x b - x z - / + ] }
{ [ r x = g z > and ] [ 1 x g - x z - / - ] }
{ [ g x = b z = and ] [ 1 x r - x z - / + ] }
{ [ g x = b z > and ] [ 3 x b - x z - / - ] }
{ [ b x = r z = and ] [ 3 x g - x z - / + ] }
{ [ b x = r z > and ] [ 5 x r - x z - / - ] }
} cond 6 / 360 * x z - x / x a <hsva>
] if ;















M: rgba >xyza
[
[ red>> ] [ green>> ] [ blue>> ] tri
[ invert-rgb-compand ] tri@ load-local load-local
load-local 0 get-local 0.4124564 *
-1 get-local 0.3575761 * -2 get-local 0.1804375 * + +
0 get-local 0.2126729 * -1 get-local 0.7151522 *
-2 get-local 0.072175 * + + 0 get-local 0.0193339 *
-1 get-local 0.119192 * -2 get-local 0.9503041 * +
3 drop-locals +
] [ alpha>> ] bi <xyza> ;



M:: rgba >yiqa ( rgba -- yiqa )
rgba >rgba-components :> ( r g b a ) 0.3 r * 0.59 g *
0.11 b * + + :> y r y - :> r-y b y - :> b-y 0.74 r-y *
0.27 b-y * - :> i 0.48 r-y * 0.41 b-y * +
:> q y i q a <yiqa> ;



M:: rgba >yuva ( rgba -- yuva )
rgba >rgba-components :> ( r g b a ) Wr r * Wg g * Wb b * +
+ :> y Umax 1 Wb - / b y - * :> u Vmax 1 Wr - / r y - *
:> v y u v a <yuva> ;