Saga3D API Documentation
1.0-RC4
|
Go to the documentation of this file.
5 #ifndef __COLOR_H_INCLUDED__
6 #define __COLOR_H_INCLUDED__
10 #include "SagaConfig.h"
11 #include <glm/gtx/extended_min_max.hpp>
12 #include <glm/gtc/constants.hpp>
13 #include <glm/gtc/epsilon.hpp>
14 #include <glm/vec4.hpp>
56 inline std::uint16_t
RGBA16(std::uint32_t r, std::uint32_t g, std::uint32_t b, std::uint32_t a= 0xFF)
58 return (std::uint16_t)((a & 0x80) << 8 |
66 inline std::uint16_t
RGB16(std::uint32_t r, std::uint32_t g, std::uint32_t b)
73 inline std::uint16_t
RGB16from16(std::uint16_t r, std::uint16_t g, std::uint16_t b)
85 return (std::uint16_t)(0x8000 |
86 (color & 0x00F80000) >> 9 |
87 (color & 0x0000F800) >> 6 |
88 (color & 0x000000F8) >> 3);
95 return (std::uint16_t)((color & 0x80000000) >> 16|
96 (color & 0x00F80000) >> 9 |
97 (color & 0x0000F800) >> 6 |
98 (color & 0x000000F8) >> 3);
105 return (std::uint16_t)((color & 0x00F80000) >> 8 |
106 (color & 0x0000FC00) >> 5 |
107 (color & 0x000000F8) >> 3);
115 return (((-((std::int32_t) color & 0x00008000) >> (std::int32_t) 31) & 0xFF000000) |
116 ((color & 0x00007C00) << 9) | ((color & 0x00007000) << 4) |
117 ((color & 0x000003E0) << 6) | ((color & 0x00000380) << 1) |
118 ((color & 0x0000001F) << 3) | ((color & 0x0000001C) >> 2)
127 ((color & 0xF800) << 8)|
128 ((color & 0x07E0) << 5)|
129 ((color & 0x001F) << 3);
136 return 0x8000 | (((color & 0xFFC0) >> 1) | (color & 0x1F));
143 return (((color & 0x7FE0) << 1) | (color & 0x1F));
153 return ((color >> 15)&0x1);
159 inline std::uint32_t
getRed(std::uint16_t color)
161 return ((color >> 10)&0x1F);
169 return ((color >> 5)&0x1F);
175 inline std::uint32_t
getBlue(std::uint16_t color)
177 return (color & 0x1F);
207 SColor (std::uint32_t a, std::uint32_t r, std::uint32_t g, std::uint32_t b)
208 :
color(((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff)) {}
282 *dest = (std::uint8_t)
getRed();
284 *++dest = (std::uint8_t)
getBlue();
305 void set(std::uint32_t a, std::uint32_t r, std::uint32_t g, std::uint32_t b)
307 color = (((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff));
341 const float inv = 1.0f - d;
343 (std::uint32_t)glm::round(other.
getRed()*inv +
getRed()*d),
356 const float inv = 1.f - d;
357 const float mul0 = inv * inv;
358 const float mul1 = 2.f * d * inv;
359 const float mul2 = d * d;
384 color = *(std::uint32_t*)data;
388 std::uint8_t* p = (std::uint8_t*)data;
389 set(255, p[0],p[1],p[2]);
408 std::uint16_t * dest = (std::uint16_t*)data;
415 std::uint8_t* dest = (std::uint8_t*)data;
416 dest[0] = (std::uint8_t)
getRed();
418 dest[2] = (std::uint8_t)
getBlue();
424 std::uint32_t * dest = (std::uint32_t*)data;
471 const float inv = 1.0f / 255.0f;
481 return SColor((std::uint32_t)glm::round(
a*255.0f), (std::uint32_t)glm::round(
r*255.0f), (std::uint32_t)glm::round(
g*255.0f), (std::uint32_t)glm::round(
b*255.0f));
491 void set(
float rr,
float gg,
float bb) {
r = rr;
g =gg;
b = bb; }
502 void set(
float aa,
float rr,
float gg,
float bb) {
a = aa;
r = rr;
g =gg;
b = bb; }
511 const float inv = 1.0f - d;
513 other.
g*inv +
g*d, other.
b*inv +
b*d, other.
a*inv +
a*d);
525 const float inv = 1.f - d;
526 const float mul0 = inv * inv;
527 const float mul1 = 2.f * d * inv;
528 const float mul2 = d * d;
530 return SColorf (
r * mul0 + c1.
r * mul1 + c2.
r * mul2,
531 g * mul0 + c1.
g * mul1 + c2.
g * mul2,
532 b * mul0 + c1.
b * mul1 + c2.
b * mul2,
533 a * mul0 + c1.
a * mul1 + c2.
a * mul2);
542 case 0:
r = value;
break;
543 case 1:
g = value;
break;
544 case 2:
b = value;
break;
545 case 3:
a = value;
break;
594 inline float toRGB1(
float rm1,
float rm2,
float rh)
const;
603 if (glm::epsilonEqual(maxVal, minVal, glm::epsilon<float>()))
610 const float delta = maxVal-minVal;
621 if (glm::epsilonEqual(maxVal, color.
getRed(), glm::epsilon<float>()))
623 else if (glm::epsilonEqual(maxVal, color.
getGreen(), glm::epsilon<float>()))
654 const float rm1 = 2.0f * l - rm2;
656 const float h =
Hue / 360.0f;
657 color.
set(toRGB1(rm1, rm2, h + 1.f/3.f),
659 toRGB1(rm1, rm2, h - 1.f/3.f)
665 inline float SColorHSL::toRGB1(
float rm1,
float rm2,
float rh)
const
673 rm1 = rm1 + (rm2 - rm1) * rh*6.f;
676 else if (rh < 2.f/3.f)
677 rm1 = rm1 + (rm2 - rm1) * ((2.f/3.f)-rh)*6.f;
void setAlpha(std::uint32_t a)
Sets the alpha component of the Color.
SColorf(SColor c)
Constructs a color from 32 bit Color.
void fromRGB(const SColorf &color)
constexpr auto enumToPOD(E e) noexcept
std::uint16_t RGB16from16(std::uint16_t r, std::uint16_t g, std::uint16_t b)
Creates a 16bit A1R5G5B5 color, based on 16bit input values.
std::uint32_t getAlpha() const
Returns the alpha component of the color.
float r
red color component
float getAlpha() const
Returns the alpha component of the color in the range 0.0 (transparent) to 1.0 (opaque)
SColorf(float r, float g, float b, float a=1.0f)
Constructs a color from up to four color values: red, green, blue, and alpha.
float getGreen() const
Returns the green component of the color in the range 0.0 to 1.0.
std::uint16_t A1R5G5B5toR5G6B5(std::uint16_t color)
Returns R5G6B5 Color from A1R5G5B5 color.
Class representing a color in HSL format.
SColorf getInterpolated_quadratic(const SColorf &c1, const SColorf &c2, float d) const
Returns interpolated color. (quadratic)
SColorHSL(float h=0.f, float s=0.f, float l=0.f)
Class representing a color with four floats.
std::uint16_t A8RGB8toA1R5G5B5(std::uint32_t color)
Converts a 32bit (A8RGB8) color to a 16bit A1R5G5B5 color.
void setColorComponentValue(std::int32_t index, float value)
Sets a color component by index. R= 0, G=1, B=2, A=3.
void toRGB(SColorf &color) const
void setBlue(std::uint32_t b)
Sets the blue component of the Color.
std::uint16_t RGB16(std::uint32_t r, std::uint32_t g, std::uint32_t b)
Creates a 16 bit A1R5G5B5 color.
void getData(void *data, E_PIXEL_FORMAT format) const
Write the color to data in the defined format.
SColor operator+(const SColor &other) const
Adds two colors, result is clamped to 0..255 values.
std::uint16_t RGBA16(std::uint32_t r, std::uint32_t g, std::uint32_t b, std::uint32_t a=0xFF)
Creates a 16 bit A1R5G5B5 color.
SColorf getInterpolated(const SColorf &other, float d) const
Interpolates the color with a float value to another color.
float getRed() const
Returns the red component of the color in the range 0.0 to 1.0.
void toOpenGLColor(std::uint8_t *dest) const
Converts color to OpenGL color format.
void set(float aa, float rr, float gg, float bb)
Sets all four color components to new values at once.
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, float d) const
Returns interpolated color. (quadratic)
std::int32_t getAverage(std::int16_t color)
Returns the average from a 16 bit A1R5G5B5 color.
std::uint16_t R5G6B5toA1R5G5B5(std::uint16_t color)
Returns A1R5G5B5 Color from R5G6B5 color.
std::uint32_t getBlue(std::uint16_t color)
Returns the blue component from A1R5G5B5 color.
SColorf()
Default constructor for SColorf.
@ RGBA8
Vulkan swapchain format.
std::uint32_t getBlue() const
Returns the blue component of the color.
void set(std::uint32_t a, std::uint32_t r, std::uint32_t g, std::uint32_t b)
Sets all four components of the color at once.
std::uint32_t A1R5G5B5toA8RGB8(std::uint16_t color)
Convert A8RGB8 Color from A1R5G5B5 color.
SColor(std::uint32_t a, std::uint32_t r, std::uint32_t g, std::uint32_t b)
Constructs the color from 4 values representing the alpha, red, green and blue component.
std::uint32_t getRed(std::uint16_t color)
Returns the red component from A1R5G5B5 color.
float getLightness() const
Get lightness of the color in the range [0,255].
std::uint32_t getAverage() const
Get average intensity of the color in the range [0,255].
SColor()
Constructor of the Color. Does nothing.
float g
green color component
std::uint32_t getGreen(std::uint16_t color)
Returns the green component from A1R5G5B5 color.
std::uint16_t X8RGB8toA1R5G5B5(std::uint32_t color)
Converts a 32bit (X8RGB8) color to a 16bit A1R5G5B5 color.
SColor toSColor() const
Converts this color to a SColor without floats.
std::uint32_t color
color in A8RGB8 Format
void set(std::uint32_t col)
void setGreen(std::uint32_t g)
Sets the green component of the Color.
std::uint32_t getAlpha(std::uint16_t color)
Returns the alpha component from A1R5G5B5 color.
std::uint32_t getRed() const
Returns the red component of the color.
const char *const ColorFormatNames[saga::core::enumToPOD(E_PIXEL_FORMAT::UNKNOWN)+2]
An enum class for the color format of textures used by the Irrlicht Engine.
bool operator==(const SColor &other) const
Compares the color to another color.
E_PIXEL_FORMAT
Enumeration for all primitive types there are.
void setRed(std::uint32_t r)
Sets the red component of the Color.
void setData(const void *data, E_PIXEL_FORMAT format)
set the color by expecting data in the given format
Class representing a 32 bit ARGB color.
std::uint32_t getGreen() const
Returns the green component of the color.
SColor(std::uint32_t clr)
Constructs the color from a 32 bit value. Could be another color.
std::uint16_t A8RGB8toR5G6B5(std::uint32_t color)
Converts a 32bit (A8RGB8) color to a 16bit R5G6B5 color.
bool operator!=(const SColor &other) const
Compares the color to another color.
SColor getInterpolated(const SColor &other, float d) const
Interpolates the color with a float value to another color.
std::uint32_t R5G6B5toA8RGB8(std::uint16_t color)
Returns A8RGB8 Color from R5G6B5 color.
float getLuminance() const
Get luminance of the color in the range [0,255].
float getBlue() const
Returns the blue component of the color in the range 0.0 to 1.0.
std::uint16_t toA1R5G5B5() const
Calculates a 16 bit A1R5G5B5 value of this color.
void set(float rr, float gg, float bb)
Sets three color components to new values at once.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
float a
alpha color component
bool operator<(const SColor &other) const
comparison operator