5#ifndef DCPP_S_COLOR_HPP_INCLUDED
6#define DCPP_S_COLOR_HPP_INCLUDED
8#include <duckcpp/core/engine/dcpp_types.hpp>
9#include <duckcpp/core/engine/irrMath.hpp>
205 ( color & 0x00F80000) >> 9 |
206 ( color & 0x0000F800) >> 6 |
207 ( color & 0x000000F8) >> 3);
215 ( color & 0x00F80000) >> 9 |
216 ( color & 0x0000F800) >> 6 |
217 ( color & 0x000000F8) >> 3);
225 ( color & 0x0000FC00) >> 5 |
226 ( color & 0x000000F8) >> 3);
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));
509 set(255, p[0],p[1],p[2]);
640 other.
g*inv +
g*d, other.
b*inv +
b*d, other.
a*inv +
a*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;
738 if ( Luminance <= 50 )
740 Saturation = (delta)/(maxVal+minVal);
744 Saturation = (delta)/(2-maxVal-minVal);
761 inline void SColorHSL::toRGB(SColorf &color)
const
772 if ( Luminance <= 50 )
774 rm2 = l + l * (Saturation/100);
778 rm2 = l + (1 - l) * (Saturation/100);
784 color.set( toRGB1(rm1, rm2, h + 1.f/3.f),
786 toRGB1(rm1, rm2, h - 1.f/3.f)
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
bool operator==(const SColor &other) const
Compares the color to another color.
Definition SColor.hpp:430
SColor()
Constructor of the Color. Does nothing.
Definition SColor.hpp:322
void setGreen(dcpp::uint32_kt g)
Sets the green component of the Color.
Definition SColor.hpp:384
dcpp::float32_kt getLuminance() const
Get luminance of the color in the range [0,255].
Definition SColor.hpp:360
void set(dcpp::uint32_kt a, dcpp::uint32_kt r, dcpp::uint32_kt g, dcpp::uint32_kt b)
Sets all four components of the color at once.
Definition SColor.hpp:422
void setData(const void *data, ECOLOR_FORMAT format)
set the color by expecting data in the given format
Definition SColor.hpp:493
dcpp::uint32_kt getAlpha() const
Returns the alpha component of the color.
Definition SColor.hpp:336
SColor(dcpp::uint32_kt clr)
Constructs the color from a 32 bit value. Could be another color.
Definition SColor.hpp:330
void setBlue(dcpp::uint32_kt b)
Sets the blue component of the Color.
Definition SColor.hpp:389
dcpp::uint32_kt color
color in A8R8G8B8 Format
Definition SColor.hpp:562
dcpp::float32_kt getLightness() const
Get lightness of the color in the range [0,255].
Definition SColor.hpp:354
bool operator<(const SColor &other) const
comparison operator
Definition SColor.hpp:438
void toOpenGLColor(dcpp::uint8_kt *dest) const
Converts color to OpenGL color format.
Definition SColor.hpp:399
void setRed(dcpp::uint32_kt r)
Sets the red component of the Color.
Definition SColor.hpp:379
bool operator!=(const SColor &other) const
Compares the color to another color.
Definition SColor.hpp:434
dcpp::uint16_kt toA1R5G5B5() const
Calculates a 16 bit A1R5G5B5 value of this color.
Definition SColor.hpp:393
dcpp::uint32_kt getGreen() const
Returns the green component of the color.
Definition SColor.hpp:346
SColor getInterpolated(const SColor &other, dcpp::float32_kt d) const
Interpolates the color with a dcpp::float32_kt value to another color.
Definition SColor.hpp:455
void setAlpha(dcpp::uint32_kt a)
Sets the alpha component of the Color.
Definition SColor.hpp:374
SColor(dcpp::uint32_kt a, dcpp::uint32_kt r, dcpp::uint32_kt g, dcpp::uint32_kt b)
Constructs the color from 4 values representing the alpha, red, green and blue component.
Definition SColor.hpp:326
dcpp::uint32_kt getRed() const
Returns the red component of the color.
Definition SColor.hpp:341
dcpp::uint32_kt getBlue() const
Returns the blue component of the color.
Definition SColor.hpp:351
dcpp::uint32_kt getAverage() const
Get average intensity of the color in the range [0,255].
Definition SColor.hpp:366
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, dcpp::float32_kt d) const
Returns interpolated color. ( quadratic )
Definition SColor.hpp:469
void getData(void *data, ECOLOR_FORMAT format) const
Write the color to data in the defined format.
Definition SColor.hpp:522
SColor operator+(const SColor &other) const
Adds two colors, result is clamped to 0..255 values.
Definition SColor.hpp:443
Class representing a color with four floats.
Definition SColor.hpp:574
SColorf(dcpp::float32_kt r, dcpp::float32_kt g, dcpp::float32_kt b, dcpp::float32_kt a=1.0f)
Constructs a color from up to four color values: red, green, blue, and alpha.
Definition SColor.hpp:591
dcpp::float32_kt getRed() const
Returns the red component of the color in the range 0.0 to 1.0.
Definition SColor.hpp:680
dcpp::float32_kt b
blue component
Definition SColor.hpp:695
dcpp::float32_kt getAlpha() const
Returns the alpha component of the color in the range 0.0 (transparent) to 1.0 (opaque)
Definition SColor.hpp:677
void set(dcpp::float32_kt rr, dcpp::float32_kt gg, dcpp::float32_kt bb)
Sets three color components to new values at once.
Definition SColor.hpp:618
SColor toSColor() const
Converts this color to a SColor without floats.
Definition SColor.hpp:606
dcpp::float32_kt r
red color component
Definition SColor.hpp:689
dcpp::float32_kt a
alpha color component
Definition SColor.hpp:698
void set(dcpp::float32_kt aa, dcpp::float32_kt rr, dcpp::float32_kt gg, dcpp::float32_kt bb)
Sets all four color components to new values at once.
Definition SColor.hpp:629
void setColorComponentValue(dcpp::int32_kt index, dcpp::float32_kt value)
Sets a color component by index. R=0, G=1, B=2, A=3.
Definition SColor.hpp:665
SColorf getInterpolated_quadratic(const SColorf &c1, const SColorf &c2, dcpp::float32_kt d) const
Returns interpolated color. ( quadratic )
Definition SColor.hpp:647
dcpp::float32_kt g
green color component
Definition SColor.hpp:692
SColorf()
Default constructor for SColorf.
Definition SColor.hpp:578
SColorf(SColor c)
Constructs a color from 32 bit Color.
Definition SColor.hpp:596
dcpp::float32_kt 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, dcpp::float32_kt d) const
Interpolates the color with a dcpp::float32_kt value to another color.
Definition SColor.hpp:635
dcpp::float32_kt getBlue() const
Returns the blue component of the color in the range 0.0 to 1.0.
Definition SColor.hpp:686
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
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
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 clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
bool iszero(const dcpp::float64_kt a, const dcpp::float64_kt tolerance=ROUNDING_ERROR_Float64)
returns if a equals zero, taking rounding errors into account
Definition irrMath.hpp:304
dcpp::uint32_kt R5G6B5toA8R8G8B8(dcpp::uint16_kt color)
Returns A8R8G8B8 Color from R5G6B5 color.
Definition SColor.hpp:243
dcpp::uint32_kt A1R5G5B5toA8R8G8B8(dcpp::uint16_kt color)
Convert A8R8G8B8 Color from A1R5G5B5 color.
Definition SColor.hpp:232
dcpp::uint32_kt getBlue(dcpp::uint16_kt color)
Returns the blue component from A1R5G5B5 color.
Definition SColor.hpp:294
dcpp::uint32_kt getRed(dcpp::uint16_kt color)
Returns the red component from A1R5G5B5 color.
Definition SColor.hpp:278
dcpp::uint16_kt A8R8G8B8toR5G6B5(dcpp::uint32_kt color)
Converts a 32bit (A8R8G8B8) color to a 16bit R5G6B5 color.
Definition SColor.hpp:222
const dcpp::char_kt *const ColorFormatNames[ECF_UNKNOWN+2]
Names for ECOLOR_FORMAT types.
Definition SColor.hpp:136
dcpp::uint16_kt A1R5G5B5toR5G6B5(dcpp::uint16_kt color)
Returns R5G6B5 Color from A1R5G5B5 color.
Definition SColor.hpp:260
dcpp::uint32_kt getAlpha(dcpp::uint16_kt color)
Returns the alpha component from A1R5G5B5 color.
Definition SColor.hpp:270
dcpp::uint32_kt getGreen(dcpp::uint16_kt color)
Returns the green component from A1R5G5B5 color.
Definition SColor.hpp:286
dcpp::uint16_kt A8R8G8B8toA1R5G5B5(dcpp::uint32_kt color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition SColor.hpp:212
dcpp::uint16_kt RGBA16(dcpp::uint32_kt r, dcpp::uint32_kt g, dcpp::uint32_kt b, dcpp::uint32_kt a=0xFF)
Creates a 16 bit A1R5G5B5 color.
Definition SColor.hpp:175
dcpp::uint16_kt R5G6B5toA1R5G5B5(dcpp::uint16_kt color)
Returns A1R5G5B5 Color from R5G6B5 color.
Definition SColor.hpp:253
ECOLOR_FORMAT
An enum for the color format of textures used by the Duckcpp Engine.
Definition SColor.hpp:21
@ 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_R32F
32 bit format using 32 bits for the red channel.
Definition SColor.hpp:98
@ ECF_A16B16G16R16F
64 bit format using 16 bits for the red, green, blue and alpha channels.
Definition SColor.hpp:95
@ ECF_R8G8B8
Definition SColor.hpp:34
@ ECF_PVRTC_RGB4
PVRTC RGB 4bpp.
Definition SColor.hpp:64
@ ECF_UNKNOWN
Unknown color format:
Definition SColor.hpp:132
@ ECF_D24I8
32 bit format using 24 bits for depth and 8 bits for stencil.
Definition SColor.hpp:129
@ ECF_DXT5
DXT5 color format.
Definition SColor.hpp:55
@ ECF_D16
16 bit format using 16 bits for depth.
Definition SColor.hpp:123
@ ECF_PVRTC2_ARGB4
PVRTC2 ARGB 4bpp.
Definition SColor.hpp:73
@ ECF_R8
8 bit format using 8 bits for the red channel.
Definition SColor.hpp:109
@ ECF_A32B32G32R32F
128 bit format using 32 bits for the red, green, blue and alpha channels.
Definition SColor.hpp:104
@ ECF_DXT1
DXT1 color format.
Definition SColor.hpp:43
@ ECF_DXT2
DXT2 color format.
Definition SColor.hpp:46
@ ECF_D32
32 bit format using 32 bits for depth.
Definition SColor.hpp:126
@ ECF_A1R5G5B5
16 bit color format used by the software driver.
Definition SColor.hpp:26
@ ECF_ETC2_ARGB
ETC2 ARGB.
Definition SColor.hpp:82
@ ECF_R16G16
32 bit format using 16 bits for the red and green channels.
Definition SColor.hpp:118
@ ECF_PVRTC_ARGB4
PVRTC ARGB 4bpp.
Definition SColor.hpp:67
@ ECF_PVRTC_RGB2
PVRTC RGB 2bpp.
Definition SColor.hpp:58
@ ECF_PVRTC_ARGB2
PVRTC ARGB 2bpp.
Definition SColor.hpp:61
@ ECF_PVRTC2_ARGB2
PVRTC2 ARGB 2bpp.
Definition SColor.hpp:70
@ ECF_A8R8G8B8
Definition SColor.hpp:38
@ ECF_R8G8
16 bit format using 8 bits for the red and green channels.
Definition SColor.hpp:112
@ ECF_DXT4
DXT4 color format.
Definition SColor.hpp:52
@ ECF_G16R16F
32 bit format using 16 bits for the red and green channels.
Definition SColor.hpp:92
@ ECF_DXT3
DXT3 color format.
Definition SColor.hpp:49
@ ECF_R5G6B5
Standard 16 bit color format.
Definition SColor.hpp:29
@ ECF_ETC2_RGB
ETC2 RGB.
Definition SColor.hpp:79
@ ECF_ETC1
ETC1 RGB.
Definition SColor.hpp:76
@ ECF_R16
16 bit format using 16 bits for the red channel.
Definition SColor.hpp:115
dcpp::uint16_kt X8R8G8B8toA1R5G5B5(dcpp::uint32_kt color)
Converts a 32bit (X8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition SColor.hpp:202
dcpp::uint16_kt RGB16(dcpp::uint32_kt r, dcpp::uint32_kt g, dcpp::uint32_kt b)
Creates a 16 bit A1R5G5B5 color.
Definition SColor.hpp:185
dcpp::int32_kt getAverage(dcpp::int16_kt color)
Returns the average from a 16 bit A1R5G5B5 color.
Definition SColor.hpp:301
dcpp::uint16_kt RGB16from16(dcpp::uint16_kt r, dcpp::uint16_kt g, dcpp::uint16_kt b)
Creates a 16bit A1R5G5B5 color, based on 16bit input values.
Definition SColor.hpp:192
As of Duckcpp 1.6, position2d is a synonym for vector2d.
Definition shared_device.hpp:34
char char_kt
8 bit character variable.
Definition irrTypes.hpp:37
unsigned char uint8_kt
8 bit unsigned variable.
Definition irrTypes.hpp:24
unsigned int uint32_kt
32 bit unsigned variable.
Definition irrTypes.hpp:64
float float32_kt
32 bit floating point variable.
Definition irrTypes.hpp:108
unsigned short uint16_kt
16 bit unsigned variable.
Definition irrTypes.hpp:46
signed int int32_kt
32 bit signed variable.
Definition irrTypes.hpp:72
signed short int16_kt
16 bit signed variable.
Definition irrTypes.hpp:54