5 #ifndef __COLOR_H_INCLUDED__ 6 #define __COLOR_H_INCLUDED__ 62 return (
u16)((a & 0x80) << 8 |
90 ( color & 0x00F80000) >> 9 |
91 ( color & 0x0000F800) >> 6 |
92 ( color & 0x000000F8) >> 3);
99 return (
u16)(( color & 0x80000000) >> 16|
100 ( color & 0x00F80000) >> 9 |
101 ( color & 0x0000F800) >> 6 |
102 ( color & 0x000000F8) >> 3);
109 return (
u16)(( color & 0x00F80000) >> 8 |
110 ( color & 0x0000FC00) >> 5 |
111 ( color & 0x000000F8) >> 3);
119 return ( (( -( (
s32) color & 0x00008000 ) >> (
s32) 31 ) & 0xFF000000 ) |
120 (( color & 0x00007C00 ) << 9) | (( color & 0x00007000 ) << 4) |
121 (( color & 0x000003E0 ) << 6) | (( color & 0x00000380 ) << 1) |
122 (( color & 0x0000001F ) << 3) | (( color & 0x0000001C ) >> 2)
131 ((color & 0xF800) << 8)|
132 ((color & 0x07E0) << 5)|
133 ((color & 0x001F) << 3);
140 return 0x8000 | (((color & 0xFFC0) >> 1) | (color & 0x1F));
147 return (((color & 0x7FE0) << 1) | (color & 0x1F));
157 return ((color >> 15)&0x1);
165 return ((color >> 10)&0x1F);
173 return ((color >> 5)&0x1F);
181 return (color & 0x1F);
212 :
color(((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff)) {}
309 color = (((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff));
343 const f32 inv = 1.0f - d;
358 const f32 inv = 1.f - d;
359 const f32 mul0 = inv * inv;
360 const f32 mul1 = 2.f * d * inv;
361 const f32 mul2 = d * d;
394 set(255, p[0],p[1],p[2]);
427 u8* dest = (
u8*)data;
463 SColorf() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {}
483 const f32 inv = 1.0f / 255.0f;
503 void set(
f32 rr,
f32 gg,
f32 bb) {r = rr; g =gg; b = bb; }
514 void set(
f32 aa,
f32 rr,
f32 gg,
f32 bb) {a = aa; r = rr; g =gg; b = bb; }
523 const f32 inv = 1.0f - d;
525 other.
g*inv + g*d, other.
b*inv + b*d, other.
a*inv + a*d);
537 const f32 inv = 1.f - d;
538 const f32 mul0 = inv * inv;
539 const f32 mul1 = 2.f * d * inv;
540 const f32 mul2 = d * d;
542 return SColorf (r * mul0 + c1.
r * mul1 + c2.
r * mul2,
543 g * mul0 + c1.
g * mul1 + c2.
g * mul2,
544 b * mul0 + c1.
b * mul1 + c2.
b * mul2,
545 a * mul0 + c1.
a * mul1 + c2.
a * mul2);
554 case 0: r = value;
break;
555 case 1: g = value;
break;
556 case 2: b = value;
break;
557 case 3: a = value;
break;
596 : Hue ( h ), Saturation ( s ), Luminance ( l ) {}
599 void toRGB(
SColorf &color)
const;
614 Luminance = (maxVal+minVal)*50;
622 const f32 delta = maxVal-minVal;
623 if ( Luminance <= 50 )
625 Saturation = (delta)/(maxVal+minVal);
629 Saturation = (delta)/(2-maxVal-minVal);
648 const f32 l = Luminance/100;
657 if ( Luminance <= 50 )
659 rm2 = l + l * (Saturation/100);
663 rm2 = l + (1 - l) * (Saturation/100);
666 const f32 rm1 = 2.0f * l - rm2;
668 const f32 h = Hue / 360.0f;
669 color.
set( toRGB1(rm1, rm2, h + 1.f/3.f),
671 toRGB1(rm1, rm2, h - 1.f/3.f)
677 inline f32 SColorHSL::toRGB1(
f32 rm1,
f32 rm2,
f32 rh)
const 685 rm1 = rm1 + (rm2 - rm1) * rh*6.f;
688 else if (rh < 2.f/3.f)
689 rm1 = rm1 + (rm2 - rm1) * ((2.f/3.f)-rh)*6.f;
24 bit color, no alpha channel, but 8 bit for red, green and blue.
signed short s16
16 bit signed variable.
f32 getAlpha() const
Returns the alpha component of the color in the range 0.0 (transparent) to 1.0 (opaque) ...
u16 RGB16(u32 r, u32 g, u32 b)
Creates a 16 bit A1R5G5B5 color.
REALINLINE s32 round32(f32 x)
void setBlue(u32 b)
Sets the blue component of the Color.
u32 getAlpha() const
Returns the alpha component of the color.
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
void set(f32 rr, f32 gg, f32 bb)
Sets three color components to new values at once.
f32 g
green color component
64 bit floating point format using 32 bits for the red channel and 32 bits for the green channel...
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
SColor operator+(const SColor &other) const
Adds two colors, result is clamped to 0..255 values.
float f32
32 bit floating point variable.
u32 getGreen() const
Returns the green component of the color.
void setRed(u32 r)
Sets the red component of the Color.
64 bit floating point format 16 bits are used for the red, green, blue and alpha channels.
32 bit floating point format using 32 bits for the red channel.
void toRGB(SColorf &color) const
ECOLOR_FORMAT
An enum for the color format of textures used by the Irrlicht Engine.
u16 RGBA16(u32 r, u32 g, u32 b, u32 a=0xFF)
Creates a 16 bit A1R5G5B5 color.
f32 getLightness() const
Get lightness of the color in the range [0,255].
Everything in the Irrlicht Engine can be found in this namespace.
u32 A1R5G5B5toA8R8G8B8(u16 color)
Convert A8R8G8B8 Color from A1R5G5B5 color.
16 bit floating point format using 16 bits for the red channel.
void toOpenGLColor(u8 *dest) const
Converts color to OpenGL color format.
u16 RGB16from16(u16 r, u16 g, u16 b)
Creates a 16bit A1R5G5B5 color, based on 16bit input values.
void setAlpha(u32 a)
Sets the alpha component of the Color.
SColorHSL(f32 h=0.f, f32 s=0.f, f32 l=0.f)
unsigned char u8
8 bit unsigned variable.
SColorf getInterpolated_quadratic(const SColorf &c1, const SColorf &c2, f32 d) const
Returns interpolated color. ( quadratic )
unsigned short u16
16 bit unsigned variable.
void setData(const void *data, ECOLOR_FORMAT format)
set the color by expecting data in the given format
f32 a
alpha color component
SColor()
Constructor of the Color. Does nothing.
void setColorComponentValue(s32 index, f32 value)
Sets a color component by index. R=0, G=1, B=2, A=3.
bool operator<(const SColor &other) const
comparison operator
signed int s32
32 bit signed variable.
u16 R5G6B5toA1R5G5B5(u16 color)
Returns A1R5G5B5 Color from R5G6B5 color.
f32 getBlue() const
Returns the blue component of the color in the range 0.0 to 1.0.
f32 getRed() const
Returns the red component of the color in the range 0.0 to 1.0.
u32 getAlpha(u16 color)
Returns the alpha component from A1R5G5B5 color.
128 bit floating point format. 32 bits are used for the red, green, blue and alpha channels...
unsigned int u32
32 bit unsigned variable.
16 bit color format used by the software driver.
SColor toSColor() const
Converts this color to a SColor without floats.
u16 A1R5G5B5toR5G6B5(u16 color)
Returns R5G6B5 Color from A1R5G5B5 color.
const T & min_(const T &a, const T &b)
returns minimum of two values. Own implementation to get rid of the STL (VS6 problems) ...
SColor(u32 a, u32 r, u32 g, u32 b)
Constructs the color from 4 values representing the alpha, red, green and blue component.
void setGreen(u32 g)
Sets the green component of the Color.
bool operator==(const SColor &other) const
Compares the color to another color.
const T & max_(const T &a, const T &b)
returns maximum of two values. Own implementation to get rid of the STL (VS6 problems) ...
bool operator!=(const SColor &other) const
Compares the color to another color.
s32 getAverage(s16 color)
Returns the average from a 16 bit A1R5G5B5 color.
u16 toA1R5G5B5() const
Calculates a 16 bit A1R5G5B5 value of this color.
void getData(void *data, ECOLOR_FORMAT format)
Write the color to data in the defined format.
u16 X8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (X8R8G8B8) color to a 16bit A1R5G5B5 color.
Class representing a 32 bit ARGB color.
f32 getLuminance() const
Get luminance of the color in the range [0,255].
u32 getGreen(u16 color)
Returns the green component from A1R5G5B5 color.
u16 A8R8G8B8toR5G6B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit R5G6B5 color.
Standard 16 bit color format.
u32 getBlue(u16 color)
Returns the blue component from A1R5G5B5 color.
u16 A8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
SColorf()
Default constructor for SColorf.
f32 getGreen() const
Returns the green component of the color in the range 0.0 to 1.0.
SColorf(SColor c)
Constructs a color from 32 bit Color.
SColorf(f32 r, f32 g, f32 b, f32 a=1.0f)
Constructs a color from up to four color values: red, green, blue, and alpha.
Default 32 bit color format. 8 bits are used for every component: red, green, blue and alpha...
REALINLINE s32 floor32(f32 x)
SColorf getInterpolated(const SColorf &other, f32 d) const
Interpolates the color with a f32 value to another color.
u32 getRed(u16 color)
Returns the red component from A1R5G5B5 color.
Class representing a color in HSL format.
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
SColor(u32 clr)
Constructs the color from a 32 bit value. Could be another color.
Class representing a color with four floats.
u32 getRed() const
Returns the red component of the color.
32 bit floating point format using 16 bits for the red channel and 16 bits for the green channel...
u32 getBlue() const
Returns the blue component of the color.
u32 getAverage() const
Get average intensity of the color in the range [0,255].
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
u32 color
color in A8R8G8B8 Format
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, f32 d) const
Returns interpolated color. ( quadratic )
u32 R5G6B5toA8R8G8B8(u16 color)
Returns A8R8G8B8 Color from R5G6B5 color.
void fromRGB(const SColorf &color)