 |
Irrlicht 3D Engine
|
|
Go to the documentation of this file.
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;
483 const f32 inv = 1.0f / 255.0f;
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;
622 const f32 delta = maxVal-minVal;
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;
const T & max_(const T &a, const T &b)
returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)
f32 a
alpha color component
bool operator<(const SColor &other) const
comparison operator
@ ECF_G32R32F
64 bit floating point format using 32 bits for the red channel and 32 bits for the green channel.
Class representing a color in HSL format.
u32 getGreen(u16 color)
Returns the green component from A1R5G5B5 color.
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
u16 R5G6B5toA1R5G5B5(u16 color)
Returns A1R5G5B5 Color from R5G6B5 color.
u16 X8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (X8R8G8B8) color to a 16bit A1R5G5B5 color.
void toRGB(SColorf &color) const
u16 A8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
bool operator!=(const SColor &other) const
Compares the color to another color.
u16 toA1R5G5B5() const
Calculates a 16 bit A1R5G5B5 value of this color.
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
u32 getBlue(u16 color)
Returns the blue component from A1R5G5B5 color.
@ ECF_R8G8B8
24 bit color, no alpha channel, but 8 bit for red, green and blue.
signed short s16
16 bit signed variable.
SColorHSL(f32 h=0.f, f32 s=0.f, f32 l=0.f)
u32 getRed(u16 color)
Returns the red component from A1R5G5B5 color.
u32 getGreen() const
Returns the green component of the color.
@ ECF_A16B16G16R16F
64 bit floating point format 16 bits are used for the red, green, blue and alpha channels.
void setData(const void *data, ECOLOR_FORMAT format)
set the color by expecting data in the given format
void setColorComponentValue(s32 index, f32 value)
Sets a color component by index. R=0, G=1, B=2, A=3.
SColorf getInterpolated(const SColorf &other, f32 d) const
Interpolates the color with a f32 value to another 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.
u16 A8R8G8B8toR5G6B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit R5G6B5 color.
@ ECF_R32F
32 bit floating point format using 32 bits for the red channel.
signed int s32
32 bit signed variable.
u32 getRed() const
Returns the red component of the color.
u16 RGB16(u32 r, u32 g, u32 b)
Creates a 16 bit A1R5G5B5 color.
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, f32 d) const
Returns interpolated color. ( quadratic )
Class representing a color with four floats.
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
f32 getAlpha() const
Returns the alpha component of the color in the range 0.0 (transparent) to 1.0 (opaque)
@ ECF_UNKNOWN
Unknown color format:
@ ECF_A32B32G32R32F
128 bit floating point format. 32 bits are used for the red, green, blue and alpha channels.
u32 color
color in A8R8G8B8 Format
u32 R5G6B5toA8R8G8B8(u16 color)
Returns A8R8G8B8 Color from R5G6B5 color.
SColorf()
Default constructor for SColorf.
void setAlpha(u32 a)
Sets the alpha component of the Color.
void setGreen(u32 g)
Sets the green component of the Color.
REALINLINE s32 floor32(f32 x)
SColor(u32 a, u32 r, u32 g, u32 b)
Constructs the color from 4 values representing the alpha, red, green and blue component.
f32 getRed() const
Returns the red component of the color in the range 0.0 to 1.0.
SColorf getInterpolated_quadratic(const SColorf &c1, const SColorf &c2, f32 d) const
Returns interpolated color. ( quadratic )
float f32
32 bit floating point variable.
u32 getBlue() const
Returns the blue component of the color.
u32 getAverage() const
Get average intensity of the color in the range [0,255].
bool operator==(const SColor &other) const
Compares the color to another color.
SColor operator+(const SColor &other) const
Adds two colors, result is clamped to 0..255 values.
void set(f32 aa, f32 rr, f32 gg, f32 bb)
Sets all four color components to new values at once.
void setBlue(u32 b)
Sets the blue component of the Color.
void getData(void *data, ECOLOR_FORMAT format)
Write the color to data in the defined format.
f32 getLuminance() const
Get luminance of the color in the range [0,255].
@ ECF_A8R8G8B8
Default 32 bit color format. 8 bits are used for every component: red, green, blue and alpha.
@ ECF_R5G6B5
Standard 16 bit color format.
u16 RGB16from16(u16 r, u16 g, u16 b)
Creates a 16bit A1R5G5B5 color, based on 16bit input values.
u16 RGBA16(u32 r, u32 g, u32 b, u32 a=0xFF)
Creates a 16 bit A1R5G5B5 color.
f32 getGreen() const
Returns the green component of the color in the range 0.0 to 1.0.
void setRed(u32 r)
Sets the red component of the Color.
Everything in the Irrlicht Engine can be found in this namespace.
unsigned short u16
16 bit unsigned variable.
u32 A1R5G5B5toA8R8G8B8(u16 color)
Convert A8R8G8B8 Color from A1R5G5B5 color.
void set(f32 rr, f32 gg, f32 bb)
Sets three color components to new values at once.
unsigned int u32
32 bit unsigned variable.
f32 g
green color component
SColor toSColor() const
Converts this color to a SColor without floats.
@ ECF_R16F
16 bit floating point format using 16 bits for the red channel.
void toOpenGLColor(u8 *dest) const
Converts color to OpenGL color format.
f32 getLightness() const
Get lightness of the color in the range [0,255].
u32 getAlpha(u16 color)
Returns the alpha component from A1R5G5B5 color.
void set(u32 a, u32 r, u32 g, u32 b)
Sets all four components of the color at once.
REALINLINE s32 round32(f32 x)
@ ECF_G16R16F
32 bit floating point format using 16 bits for the red channel and 16 bits for the green channel.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
void fromRGB(const SColorf &color)
SColorf(SColor c)
Constructs a color from 32 bit Color.
ECOLOR_FORMAT
An enum for the color format of textures used by the Irrlicht Engine.
SColor()
Constructor of the Color. Does nothing.
@ ECF_A1R5G5B5
16 bit color format used by the software driver.
Class representing a 32 bit ARGB 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)
u16 A1R5G5B5toR5G6B5(u16 color)
Returns R5G6B5 Color from A1R5G5B5 color.
unsigned char u8
8 bit unsigned variable.
SColor(u32 clr)
Constructs the color from a 32 bit value. Could be another color.
u32 getAlpha() const
Returns the alpha component of the color.
s32 getAverage(s16 color)
Returns the average from a 16 bit A1R5G5B5 color.
f32 getBlue() const
Returns the blue component of the color in the range 0.0 to 1.0.