5#ifndef JPP_S_COLOR_HPP_INCLUDED
6#define JPP_S_COLOR_HPP_INCLUDED
8#include <jimcpp/core/engine/jpp_types.hpp>
9#include <jimcpp/core/engine/irrMath.hpp>
177 return (
u16)((a & 0x80) << 8 |
204 return (
u16)(0x8000 |
205 ( color & 0x00F80000) >> 9 |
206 ( color & 0x0000F800) >> 6 |
207 ( color & 0x000000F8) >> 3);
214 return (
u16)(( color & 0x80000000) >> 16|
215 ( color & 0x00F80000) >> 9 |
216 ( color & 0x0000F800) >> 6 |
217 ( color & 0x000000F8) >> 3);
224 return (
u16)(( color & 0x00F80000) >> 8 |
225 ( color & 0x0000FC00) >> 5 |
226 ( color & 0x000000F8) >> 3);
234 return ( (( -( (
s32) color & 0x00008000 ) >> (
s32) 31 ) & 0xFF000000 ) |
235 (( color & 0x00007C00 ) << 9) | (( color & 0x00007000 ) << 4) |
236 (( color & 0x000003E0 ) << 6) | (( color & 0x00000380 ) << 1) |
237 (( color & 0x0000001F ) << 3) | (( color & 0x0000001C ) >> 2)
246 ((color & 0xF800) << 8)|
247 ((color & 0x07E0) << 5)|
248 ((color & 0x001F) << 3);
255 return 0x8000 | (((color & 0xFFC0) >> 1) | (color & 0x1F));
262 return (((color & 0x7FE0) << 1) | (color & 0x1F));
272 return ((color >> 15)&0x1);
280 return ((color >> 10)&0x1F);
288 return ((color >> 5)&0x1F);
296 return (color & 0x1F);
327 :
color(((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff)) {}
424 color = (((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff));
458 const f32 inv = 1.0f - d;
473 const f32 inv = 1.f - d;
474 const f32 mul0 = inv * inv;
475 const f32 mul1 = 2.f * d * inv;
476 const f32 mul2 = d * d;
508 const u8* p = (
u8*)data;
509 set(255, p[0],p[1],p[2]);
542 u8* dest = (
u8*)data;
598 const f32 inv = 1.0f / 255.0f;
608 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));
638 const f32 inv = 1.0f - d;
640 other.
g*inv +
g*d, other.
b*inv +
b*d, other.
a*inv +
a*d);
652 const f32 inv = 1.f - d;
653 const f32 mul0 = inv * inv;
654 const f32 mul1 = 2.f * d * inv;
655 const f32 mul2 = d * d;
657 return SColorf (
r * mul0 + c1.
r * mul1 + c2.
r * mul2,
658 g * mul0 + c1.
g * mul1 + c2.
g * mul2,
659 b * mul0 + c1.
b * mul1 + c2.
b * mul2,
660 a * mul0 + c1.
a * mul1 + c2.
a * mul2);
669 case 0:
r = value;
break;
670 case 1:
g = value;
break;
671 case 2:
b = value;
break;
672 case 3:
a = value;
break;
711 : Hue ( h ), Saturation ( s ), Luminance ( l ) {}
713 void fromRGB(
const SColorf &color);
714 void toRGB(
SColorf &color)
const;
725 inline void SColorHSL::fromRGB(
const SColorf &color)
729 Luminance = (maxVal+minVal)*50;
737 const f32 delta = maxVal-minVal;
738 if ( Luminance <= 50 )
740 Saturation = (delta)/(maxVal+minVal);
744 Saturation = (delta)/(2-maxVal-minVal);
761 inline void SColorHSL::toRGB(SColorf &color)
const
763 const f32 l = Luminance/100;
772 if ( Luminance <= 50 )
774 rm2 = l + l * (Saturation/100);
778 rm2 = l + (1 - l) * (Saturation/100);
781 const f32 rm1 = 2.0f * l - rm2;
783 const f32 h = Hue / 360.0f;
784 color.set( toRGB1(rm1, rm2, h + 1.f/3.f),
786 toRGB1(rm1, rm2, h - 1.f/3.f)
792 inline f32 SColorHSL::toRGB1(
f32 rm1,
f32 rm2,
f32 rh)
const
800 rm1 = rm1 + (rm2 - rm1) * rh*6.f;
803 else if (rh < 2.f/3.f)
804 rm1 = rm1 + (rm2 - rm1) * ((2.f/3.f)-rh)*6.f;
Class representing a color in HSL format.
Definition SColor.hpp:708
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
u32 getAverage() const
Get average intensity of the color in the range [0,255].
Definition SColor.hpp:366
f32 getLuminance() const
Get luminance of the color in the range [0,255].
Definition SColor.hpp:360
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.hpp:455
u32 getBlue() const
Returns the blue component of the color.
Definition SColor.hpp:351
void set(u32 a, u32 r, u32 g, u32 b)
Sets all four components of the color at once.
Definition SColor.hpp:422
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, f32 d) const
Returns interpolated color. ( quadratic )
Definition SColor.hpp:469
SColor(u32 clr)
Constructs the color from a 32 bit value. Could be another color.
Definition SColor.hpp:330
void setAlpha(u32 a)
Sets the alpha component of the Color.
Definition SColor.hpp:374
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.hpp:326
void getData(void *data, ECOLOR_FORMAT format) const
Write the color to data in the defined format.
Definition SColor.hpp:522
void setRed(u32 r)
Sets the red component of the Color.
Definition SColor.hpp:379
u32 getGreen() const
Returns the green component of the color.
Definition SColor.hpp:346
bool operator==(const SColor &other) const
Compares the color to another color.
Definition SColor.hpp:430
bool operator!=(const SColor &other) const
Compares the color to another color.
Definition SColor.hpp:434
u32 color
color in A8R8G8B8 Format
Definition SColor.hpp:562
void setGreen(u32 g)
Sets the green component of the Color.
Definition SColor.hpp:384
u32 getAlpha() const
Returns the alpha component of the color.
Definition SColor.hpp:336
bool operator<(const SColor &other) const
comparison operator
Definition SColor.hpp:438
void setData(const void *data, ECOLOR_FORMAT format)
set the color by expecting data in the given format
Definition SColor.hpp:493
void setBlue(u32 b)
Sets the blue component of the Color.
Definition SColor.hpp:389
SColor operator+(const SColor &other) const
Adds two colors, result is clamped to 0..255 values.
Definition SColor.hpp:443
SColor()
Constructor of the Color. Does nothing.
Definition SColor.hpp:322
f32 getLightness() const
Get lightness of the color in the range [0,255].
Definition SColor.hpp:354
u16 toA1R5G5B5() const
Calculates a 16 bit A1R5G5B5 value of this color.
Definition SColor.hpp:393
u32 getRed() const
Returns the red component of the color.
Definition SColor.hpp:341
void toOpenGLColor(u8 *dest) const
Converts color to OpenGL color format.
Definition SColor.hpp:399
Class representing a color with four floats.
Definition SColor.hpp:574
SColorf(SColor c)
Constructs a color from 32 bit Color.
Definition SColor.hpp:596
f32 g
green color component
Definition SColor.hpp:692
f32 b
blue component
Definition SColor.hpp:695
void set(f32 rr, f32 gg, f32 bb)
Sets three color components to new values at once.
Definition SColor.hpp:618
f32 getGreen() const
Returns the green component of the color in the range 0.0 to 1.0.
Definition SColor.hpp:683
SColorf getInterpolated(const SColorf &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.hpp:635
f32 getBlue() const
Returns the blue component of the color in the range 0.0 to 1.0.
Definition SColor.hpp:686
SColor toSColor() const
Converts this color to a SColor without floats.
Definition SColor.hpp:606
f32 r
red color component
Definition SColor.hpp:689
f32 getAlpha() const
Returns the alpha component of the color in the range 0.0 (transparent) to 1.0 (opaque)
Definition SColor.hpp:677
f32 a
alpha color component
Definition SColor.hpp:698
void set(f32 aa, f32 rr, f32 gg, f32 bb)
Sets all four color components to new values at once.
Definition SColor.hpp:629
SColorf getInterpolated_quadratic(const SColorf &c1, const SColorf &c2, f32 d) const
Returns interpolated color. ( quadratic )
Definition SColor.hpp:647
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.hpp:591
void setColorComponentValue(s32 index, f32 value)
Sets a color component by index. R=0, G=1, B=2, A=3.
Definition SColor.hpp:665
SColorf()
Default constructor for SColorf.
Definition SColor.hpp:578
f32 getRed() const
Returns the red component of the color in the range 0.0 to 1.0.
Definition SColor.hpp:680
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.hpp:135
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition irrMath.hpp:243
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.hpp:121
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition irrMath.hpp:304
u32 getBlue(u16 color)
Returns the blue component from A1R5G5B5 color.
Definition SColor.hpp:294
u16 RGB16from16(u16 r, u16 g, u16 b)
Creates a 16bit A1R5G5B5 color, based on 16bit input values.
Definition SColor.hpp:192
u16 RGBA16(u32 r, u32 g, u32 b, u32 a=0xFF)
Creates a 16 bit A1R5G5B5 color.
Definition SColor.hpp:175
u32 getAlpha(u16 color)
Returns the alpha component from A1R5G5B5 color.
Definition SColor.hpp:270
u16 A8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition SColor.hpp:212
u32 getRed(u16 color)
Returns the red component from A1R5G5B5 color.
Definition SColor.hpp:278
u16 A1R5G5B5toR5G6B5(u16 color)
Returns R5G6B5 Color from A1R5G5B5 color.
Definition SColor.hpp:260
ECOLOR_FORMAT
An enum for the color format of textures used by the Jimcpp Engine.
Definition SColor.hpp:21
@ ECF_PVRTC2_ARGB2
PVRTC2 ARGB 2bpp.
Definition SColor.hpp:70
@ ECF_ETC2_RGB
ETC2 RGB.
Definition SColor.hpp:79
@ ECF_R16
16 bit format using 16 bits for the red channel.
Definition SColor.hpp:115
@ ECF_PVRTC_RGB2
PVRTC RGB 2bpp.
Definition SColor.hpp:58
@ ECF_D32
32 bit format using 32 bits for depth.
Definition SColor.hpp:126
@ ECF_PVRTC_ARGB4
PVRTC ARGB 4bpp.
Definition SColor.hpp:67
@ ECF_PVRTC_ARGB2
PVRTC ARGB 2bpp.
Definition SColor.hpp:61
@ ECF_R16G16
32 bit format using 16 bits for the red and green channels.
Definition SColor.hpp:118
@ ECF_DXT5
DXT5 color format.
Definition SColor.hpp:55
@ ECF_R32F
32 bit format using 32 bits for the red channel.
Definition SColor.hpp:98
@ ECF_DXT4
DXT4 color format.
Definition SColor.hpp:52
@ ECF_A32B32G32R32F
128 bit format using 32 bits for the red, green, blue and alpha channels.
Definition SColor.hpp:104
@ ECF_D24S8
32 bit format using 24 bits for depth and 8 bits for stencil.
Definition SColor.hpp:129
@ ECF_PVRTC2_ARGB4
PVRTC2 ARGB 4bpp.
Definition SColor.hpp:73
@ ECF_DXT2
DXT2 color format.
Definition SColor.hpp:46
@ ECF_DXT1
DXT1 color format.
Definition SColor.hpp:43
@ ECF_R8
8 bit format using 8 bits for the red channel.
Definition SColor.hpp:109
@ ECF_R5G6B5
Standard 16 bit color format.
Definition SColor.hpp:29
@ ECF_A16B16G16R16F
64 bit format using 16 bits for the red, green, blue and alpha channels.
Definition SColor.hpp:95
@ ECF_R8G8
16 bit format using 8 bits for the red and green channels.
Definition SColor.hpp:112
@ ECF_D16
16 bit format using 16 bits for depth.
Definition SColor.hpp:123
@ ECF_PVRTC_RGB4
PVRTC RGB 4bpp.
Definition SColor.hpp:64
@ ECF_UNKNOWN
Unknown color format:
Definition SColor.hpp:132
@ ECF_G16R16F
32 bit format using 16 bits for the red and green channels.
Definition SColor.hpp:92
@ ECF_R8G8B8
Definition SColor.hpp:34
@ ECF_A8R8G8B8
Definition SColor.hpp:38
@ ECF_ETC1
ETC1 RGB.
Definition SColor.hpp:76
@ ECF_DXT3
DXT3 color format.
Definition SColor.hpp:49
@ ECF_R16F
16 bit format using 16 bits for the red channel.
Definition SColor.hpp:89
@ ECF_G32R32F
64 bit format using 32 bits for the red and green channels.
Definition SColor.hpp:101
@ ECF_ETC2_ARGB
ETC2 ARGB.
Definition SColor.hpp:82
@ ECF_A1R5G5B5
16 bit color format used by the software driver.
Definition SColor.hpp:26
const c8 *const ColorFormatNames[ECF_UNKNOWN+2]
Names for ECOLOR_FORMAT types.
Definition SColor.hpp:136
s32 getAverage(s16 color)
Returns the average from a 16 bit A1R5G5B5 color.
Definition SColor.hpp:301
u16 R5G6B5toA1R5G5B5(u16 color)
Returns A1R5G5B5 Color from R5G6B5 color.
Definition SColor.hpp:253
u32 getGreen(u16 color)
Returns the green component from A1R5G5B5 color.
Definition SColor.hpp:286
u16 A8R8G8B8toR5G6B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit R5G6B5 color.
Definition SColor.hpp:222
u32 A1R5G5B5toA8R8G8B8(u16 color)
Convert A8R8G8B8 Color from A1R5G5B5 color.
Definition SColor.hpp:232
u32 R5G6B5toA8R8G8B8(u16 color)
Returns A8R8G8B8 Color from R5G6B5 color.
Definition SColor.hpp:243
u16 RGB16(u32 r, u32 g, u32 b)
Creates a 16 bit A1R5G5B5 color.
Definition SColor.hpp:185
u16 X8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (X8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition SColor.hpp:202
As of Jimcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
signed short s16
16 bit signed variable.
Definition irrTypes.hpp:54
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.hpp:24
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110
char c8
8 bit character variable.
Definition irrTypes.hpp:37