5#ifndef __COLOR_H_INCLUDED__
6#define __COLOR_H_INCLUDED__
145 return (
u16)((a & 0x80) << 8 |
172 return (
u16)(0x8000 |
173 ( color & 0x00F80000) >> 9 |
174 ( color & 0x0000F800) >> 6 |
175 ( color & 0x000000F8) >> 3);
182 return (
u16)(( color & 0x80000000) >> 16|
183 ( color & 0x00F80000) >> 9 |
184 ( color & 0x0000F800) >> 6 |
185 ( color & 0x000000F8) >> 3);
192 return (
u16)(( color & 0x00F80000) >> 8 |
193 ( color & 0x0000FC00) >> 5 |
194 ( color & 0x000000F8) >> 3);
202 return ( (( -( (
s32) color & 0x00008000 ) >> (
s32) 31 ) & 0xFF000000 ) |
203 (( color & 0x00007C00 ) << 9) | (( color & 0x00007000 ) << 4) |
204 (( color & 0x000003E0 ) << 6) | (( color & 0x00000380 ) << 1) |
205 (( color & 0x0000001F ) << 3) | (( color & 0x0000001C ) >> 2)
214 ((color & 0xF800) << 8)|
215 ((color & 0x07E0) << 5)|
216 ((color & 0x001F) << 3);
223 return 0x8000 | (((color & 0xFFC0) >> 1) | (color & 0x1F));
230 return (((color & 0x7FE0) << 1) | (color & 0x1F));
240 return ((color >> 15)&0x1);
248 return ((color >> 10)&0x1F);
256 return ((color >> 5)&0x1F);
264 return (color & 0x1F);
295 :
color(((a & 0xff)<<24) | ((b & 0xff)<<16) | ((g & 0xff)<<8) | (r & 0xff)) {}
392 color = (((a & 0xff)<<24) | ((b & 0xff)<<16) | ((g & 0xff)<<8) | (r & 0xff));
426 const f32 inv = 1.0f - d;
441 const f32 inv = 1.f - d;
442 const f32 mul0 = inv * inv;
443 const f32 mul1 = 2.f * d * inv;
444 const f32 mul2 = d * d;
477 set(255, p[0],p[1],p[2]);
510 u8* dest = (
u8*)data;
566 const f32 inv = 1.0f / 255.0f;
576 return SColor((
u32)core::round32(
a*255.0f), (
u32)core::round32(
r*255.0f), (
u32)core::round32(
g*255.0f), (
u32)core::round32(
b*255.0f));
606 const f32 inv = 1.0f - d;
608 other.
g*inv +
g*d, other.
b*inv +
b*d, other.
a*inv +
a*d);
620 const f32 inv = 1.f - d;
621 const f32 mul0 = inv * inv;
622 const f32 mul1 = 2.f * d * inv;
623 const f32 mul2 = d * d;
625 return SColorf (
r * mul0 + c1.
r * mul1 + c2.
r * mul2,
626 g * mul0 + c1.
g * mul1 + c2.
g * mul2,
627 b * mul0 + c1.
b * mul1 + c2.
b * mul2,
628 a * mul0 + c1.
a * mul1 + c2.
a * mul2);
637 case 0:
r = value;
break;
638 case 1:
g = value;
break;
639 case 2:
b = value;
break;
640 case 3:
a = value;
break;
678 SColorHSL (
f32 h = 0.f,
f32 s = 0.f,
f32 l = 0.f )
679 : Hue ( h ), Saturation ( s ), Luminance ( l ) {}
681 void fromRGB(
const SColorf &color);
682 void toRGB(
SColorf &color)
const;
693 inline void SColorHSL::fromRGB(
const SColorf &color)
697 Luminance = (maxVal+minVal)*50;
705 const f32 delta = maxVal-minVal;
706 if ( Luminance <= 50 )
708 Saturation = (delta)/(maxVal+minVal);
712 Saturation = (delta)/(2-maxVal-minVal);
729 inline void SColorHSL::toRGB(
SColorf &color)
const
731 const f32 l = Luminance/100;
740 if ( Luminance <= 50 )
742 rm2 = l + l * (Saturation/100);
746 rm2 = l + (1 - l) * (Saturation/100);
749 const f32 rm1 = 2.0f * l - rm2;
751 const f32 h = Hue / 360.0f;
752 color.set( toRGB1(rm1, rm2, h + 1.f/3.f),
754 toRGB1(rm1, rm2, h - 1.f/3.f)
760 inline f32 SColorHSL::toRGB1(
f32 rm1,
f32 rm2,
f32 rh)
const
768 rm1 = rm1 + (rm2 - rm1) * rh*6.f;
771 else if (rh < 2.f/3.f)
772 rm1 = rm1 + (rm2 - rm1) * ((2.f/3.f)-rh)*6.f;
Class representing a 32 bit ARGB color.
Definition SColor.h:285
u32 color
color in A8R8G8B8 Format
Definition SColor.h:530
u32 getGreen() const
Returns the green component of the color.
Definition SColor.h:314
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.h:423
bool operator!=(const SColor &other) const
Compares the color to another color.
Definition SColor.h:402
void setData(const void *data, ECOLOR_FORMAT format)
set the color by expecting data in the given format
Definition SColor.h:461
SColor operator+(const SColor &other) const
Adds two colors, result is clamped to 0..255 values.
Definition SColor.h:411
void toOpenGLColor(u8 *dest) const
Converts color to OpenGL color format.
Definition SColor.h:367
SColor(u32 clr)
Constructs the color from a 32 bit value. Could be another color.
Definition SColor.h:298
u32 getAverage() const
Get average intensity of the color in the range [0,255].
Definition SColor.h:334
bool operator==(const SColor &other) const
Compares the color to another color.
Definition SColor.h:398
u32 getRed() const
Returns the blue component of the color.
Definition SColor.h:319
f32 getLuminance() const
Get luminance of the color in the range [0,255].
Definition SColor.h:328
void setAlpha(u32 a)
Sets the alpha component of the Color.
Definition SColor.h:342
void getData(void *data, ECOLOR_FORMAT format)
Write the color to data in the defined format.
Definition SColor.h:490
u32 getAlpha() const
Returns the alpha component of the color.
Definition SColor.h:304
void set(u32 a, u32 r, u32 g, u32 b)
Sets all four components of the color at once.
Definition SColor.h:390
f32 getLightness() const
Get lightness of the color in the range [0,255].
Definition SColor.h:322
SColor(u32 a, u32 r, u32 g, u32 b)
Constructs the color from 4 values representing the alpha, red, green and blue component.
Definition SColor.h:294
u16 toA1R5G5B5() const
Calculates a 16 bit A1R5G5B5 value of this color.
Definition SColor.h:361
SColor()
Constructor of the Color. Does nothing.
Definition SColor.h:290
void setRed(u32 b)
Sets the red component of the Color.
Definition SColor.h:357
void setBlue(u32 r)
Sets the blue component of the Color.
Definition SColor.h:347
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, f32 d) const
Returns interpolated color. ( quadratic ).
Definition SColor.h:437
bool operator<(const SColor &other) const
comparison operator
Definition SColor.h:406
void setGreen(u32 g)
Sets the green component of the Color.
Definition SColor.h:352
u32 getBlue() const
Returns the red component of the color.
Definition SColor.h:309
Class representing a color with four floats.
Definition SColor.h:542
f32 getRed() const
Returns the red component of the color in the range 0.0 to 1.0.
Definition SColor.h:648
SColorf getInterpolated(const SColorf &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.h:603
f32 getGreen() const
Returns the green component of the color in the range 0.0 to 1.0.
Definition SColor.h:651
SColorf()
Default constructor for SColorf.
Definition SColor.h:546
f32 getBlue() const
Returns the blue component of the color in the range 0.0 to 1.0.
Definition SColor.h:654
SColorf(SColor c)
Constructs a color from 32 bit Color.
Definition SColor.h:564
void setColorComponentValue(s32 index, f32 value)
Sets a color component by index. R=0, G=1, B=2, A=3.
Definition SColor.h:633
f32 b
blue component
Definition SColor.h:663
void set(f32 rr, f32 gg, f32 bb)
Sets three color components to new values at once.
Definition SColor.h:586
f32 getAlpha() const
Returns the alpha component of the color in the range 0.0 (transparent) to 1.0 (opaque).
Definition SColor.h:645
f32 r
red color component
Definition SColor.h:657
f32 g
green color component
Definition SColor.h:660
SColor toSColor() const
Converts this color to a SColor without floats.
Definition SColor.h:574
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.
Definition SColor.h:559
f32 a
alpha color component
Definition SColor.h:666
void set(f32 aa, f32 rr, f32 gg, f32 bb)
Sets all four color components to new values at once.
Definition SColor.h:597
SColorf getInterpolated_quadratic(const SColorf &c1, const SColorf &c2, f32 d) const
Returns interpolated color. ( quadratic ).
Definition SColor.h:615
const T & max_(const T &a, const T &b)
returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)
Definition irrMath.h:137
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.h:166
const T & min_(const T &a, const T &b)
returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)
Definition irrMath.h:123
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
Definition irrMath.h:185
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition irrMath.h:270
The video namespace contains classes for accessing the video driver. All 2d and 3d rendering is done ...
Definition EDriverFeatures.h:11
u16 A8R8G8B8toR5G6B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit R5G6B5 color.
Definition SColor.h:190
ECOLOR_FORMAT
An enum for the color format of textures used by the Irrlicht Engine.
Definition SColor.h:18
@ ECT_PVRTC2_RGBA4444
PVRTC2 RGBA 4444.
Definition SColor.h:70
@ ECF_A1R5G5B5
16 bit color format used by the software driver.
Definition SColor.h:23
@ ECF_D16
16 bit format using 16 bits for depth.
Definition SColor.h:115
@ ECF_DXT5
DXT5 color format.
Definition SColor.h:49
@ ECT_PVRTC2_RGB565
ECT_PVRTC2_RGB 565.
Definition SColor.h:73
@ ECF_UNKNOWN
Unknown color format:
Definition SColor.h:138
@ ECF_A32B32G32R32F
128 bit format using 32 bits for the red, green, blue and alpha channels.
Definition SColor.h:110
@ ECF_D24S8
32 bit format using 24 bits for depth and 8 bits for stencil.
Definition SColor.h:121
@ ECF_R8G8B8
24 bit color, no alpha channel, but 8 bit for red, green and blue.
Definition SColor.h:29
@ ECF_R5G6B5
Standard 16 bit color format.
Definition SColor.h:26
@ ECF_DXT3
DXT3 color format.
Definition SColor.h:43
@ ECF_A8R8G8B8
Default 32 bit color format. 8 bits are used for every component: red, green, blue and alpha.
Definition SColor.h:32
@ ECT_PVRTC2_RGB888
ECT_PVRTC2_RGB 888.
Definition SColor.h:76
@ ECF_R8
8 bit format using 8 bits for the red channel.
Definition SColor.h:126
@ ECF_ETC2_RGB
ETC2 RGB.
Definition SColor.h:85
@ ECF_PVRTC2_ARGB4
PVRTC2 ARGB 4bpp.
Definition SColor.h:67
@ ECF_ETC1
ETC1 RGB.
Definition SColor.h:82
@ ECT_PVRTC2_RGBA8888
ECT_PVRTC2_RGBA 8888.
Definition SColor.h:79
@ ECF_R16
16 bit format using 16 bits for the red channel.
Definition SColor.h:132
@ ECF_ETC2_ARGB
ETC2 ARGB.
Definition SColor.h:88
@ ECF_A16B16G16R16F
64 bit format using 16 bits for the red, green, blue and alpha channels.
Definition SColor.h:101
@ ECF_G32R32F
64 bit format using 32 bits for the red and green channels.
Definition SColor.h:107
@ ECF_PVRTC_RGB2
PVRTC RGB 2bpp.
Definition SColor.h:52
@ ECF_R16G16
32 bit format using 16 bits for the red and green channels.
Definition SColor.h:135
@ ECF_PVRTC_RGB4
PVRTC RGB 4bpp.
Definition SColor.h:58
@ ECF_DXT2
DXT2 color format.
Definition SColor.h:40
@ ECF_R16F
16 bit format using 16 bits for the red channel.
Definition SColor.h:95
@ ECF_PVRTC_ARGB4
PVRTC ARGB 4bpp.
Definition SColor.h:61
@ ECF_D32
32 bit format using 32 bits for depth.
Definition SColor.h:118
@ ECF_PVRTC2_ARGB2
PVRTC2 ARGB 2bpp.
Definition SColor.h:64
@ ECF_DXT1
DXT1 color format.
Definition SColor.h:37
@ ECF_R8G8
16 bit format using 8 bits for the red and green channels.
Definition SColor.h:129
@ ECF_DXT4
DXT4 color format.
Definition SColor.h:46
@ ECF_R32F
32 bit format using 32 bits for the red channel.
Definition SColor.h:104
@ ECF_PVRTC_ARGB2
PVRTC ARGB 2bpp.
Definition SColor.h:55
@ ECF_G16R16F
32 bit format using 16 bits for the red and green channels.
Definition SColor.h:98
u16 RGB16from16(u16 r, u16 g, u16 b)
Creates a 16bit A1R5G5B5 color, based on 16bit input values.
Definition SColor.h:160
u32 getAlpha(u16 color)
Returns the alpha component from A1R5G5B5 color.
Definition SColor.h:238
u32 getGreen(u16 color)
Returns the green component from A1R5G5B5 color.
Definition SColor.h:254
u32 R5G6B5toA8R8G8B8(u16 color)
Returns A8R8G8B8 Color from R5G6B5 color.
Definition SColor.h:211
u16 A1R5G5B5toR5G6B5(u16 color)
Returns R5G6B5 Color from A1R5G5B5 color.
Definition SColor.h:228
u16 RGB16(u32 r, u32 g, u32 b)
Creates a 16 bit A1R5G5B5 color.
Definition SColor.h:153
u16 RGBA16(u32 r, u32 g, u32 b, u32 a=0xFF)
Creates a 16 bit A1R5G5B5 color.
Definition SColor.h:143
u16 X8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (X8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition SColor.h:170
u32 A1R5G5B5toA8R8G8B8(u16 color)
Convert A8R8G8B8 Color from A1R5G5B5 color.
Definition SColor.h:200
u16 A8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition SColor.h:180
u32 getRed(u16 color)
Returns the red component from A1R5G5B5 color.
Definition SColor.h:246
u16 R5G6B5toA1R5G5B5(u16 color)
Returns A1R5G5B5 Color from R5G6B5 color.
Definition SColor.h:221
s32 getAverage(s16 color)
Returns the average from a 16 bit A1R5G5B5 color.
Definition SColor.h:269
u32 getBlue(u16 color)
Returns the blue component from A1R5G5B5 color.
Definition SColor.h:262
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
signed short s16
16 bit signed variable.
Definition irrTypes.h:48
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.h:18
signed int s32
32 bit signed variable.
Definition irrTypes.h:66
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.h:40