arsa  2.7
Public Member Functions | Public Attributes | List of all members
irr::video::SColor Class Reference

Class representing a 32 bit ARGB color. More...

#include <SColor.h>

Public Member Functions

 SColor ()
 Constructor of the Color. Does nothing. More...
 
 SColor (u32 a, u32 r, u32 g, u32 b)
 Constructs the color from 4 values representing the alpha, red, green and blue component. More...
 
 SColor (u32 clr)
 Constructs the color from a 32 bit value. Could be another color. More...
 
u32 getAlpha () const
 Returns the alpha component of the color. More...
 
u32 getRed () const
 Returns the red component of the color. More...
 
u32 getGreen () const
 Returns the green component of the color. More...
 
u32 getBlue () const
 Returns the blue component of the color. More...
 
f32 getLightness () const
 Get lightness of the color in the range [0,255]. More...
 
f32 getLuminance () const
 Get luminance of the color in the range [0,255]. More...
 
u32 getAverage () const
 Get average intensity of the color in the range [0,255]. More...
 
void setAlpha (u32 a)
 Sets the alpha component of the Color. More...
 
void setRed (u32 r)
 Sets the red component of the Color. More...
 
void setGreen (u32 g)
 Sets the green component of the Color. More...
 
void setBlue (u32 b)
 Sets the blue component of the Color. More...
 
u16 toA1R5G5B5 () const
 Calculates a 16 bit A1R5G5B5 value of this color. More...
 
void toOpenGLColor (u8 *dest) const
 Converts color to OpenGL color format. More...
 
void set (u32 a, u32 r, u32 g, u32 b)
 Sets all four components of the color at once. More...
 
void set (u32 col)
 
bool operator== (const SColor &other) const
 Compares the color to another color. More...
 
bool operator!= (const SColor &other) const
 Compares the color to another color. More...
 
bool operator< (const SColor &other) const
 comparison operator More...
 
SColor operator+ (const SColor &other) const
 Adds two colors, result is clamped to 0..255 values. More...
 
SColor getInterpolated (const SColor &other, f32 d) const
 Interpolates the color with a f32 value to another color. More...
 
SColor getInterpolated_quadratic (const SColor &c1, const SColor &c2, f32 d) const
 Returns interpolated color. ( quadratic ) More...
 
void setData (const void *data, ECOLOR_FORMAT format)
 set the color by expecting data in the given format More...
 
void getData (void *data, ECOLOR_FORMAT format) const
 Write the color to data in the defined format. More...
 

Public Attributes

u32 color
 color in A8R8G8B8 Format More...
 

Detailed Description

Class representing a 32 bit ARGB color.

The color values for alpha, red, green, and blue are stored in a single u32. So all four values may be between 0 and 255. Alpha in Irrlicht is opacity, so 0 is fully transparent, 255 is fully opaque (solid). This class is used by most parts of the Irrlicht Engine to specify a color. Another way is using the class SColorf, which stores the color values in 4 floats. This class must consist of only one u32 and must not use virtual functions.

Definition at line 316 of file SColor.h.

Constructor & Destructor Documentation

◆ SColor() [1/3]

irr::video::SColor::SColor ( )
inline

Constructor of the Color. Does nothing.

The color value is not initialized to save time.

Definition at line 322 of file SColor.h.

322 {}

◆ SColor() [2/3]

irr::video::SColor::SColor ( u32  a,
u32  r,
u32  g,
u32  b 
)
inline

Constructs the color from 4 values representing the alpha, red, green and blue component.

Must be values between 0 and 255.

Definition at line 326 of file SColor.h.

327  : color(((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff)) {}
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
u32 color
color in A8R8G8B8 Format
Definition: SColor.h:562

◆ SColor() [3/3]

irr::video::SColor::SColor ( u32  clr)
inline

Constructs the color from a 32 bit value. Could be another color.

Definition at line 330 of file SColor.h.

331  : color(clr) {}
u32 color
color in A8R8G8B8 Format
Definition: SColor.h:562

Member Function Documentation

◆ getAlpha()

u32 irr::video::SColor::getAlpha ( ) const
inline

Returns the alpha component of the color.

The alpha component defines how opaque a color is.

Returns
The alpha value of the color. 0 is fully transparent, 255 is fully opaque.

Definition at line 336 of file SColor.h.

336 { return color>>24; }
GLuint color

◆ getAverage()

u32 irr::video::SColor::getAverage ( ) const
inline

Get average intensity of the color in the range [0,255].

Definition at line 366 of file SColor.h.

367  {
368  return ( getRed() + getGreen() + getBlue() ) / 3;
369  }
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351

◆ getBlue()

u32 irr::video::SColor::getBlue ( ) const
inline

Returns the blue component of the color.

Returns
Value between 0 and 255, specifying how blue the color is. 0 means no blue, 255 means full blue.

Definition at line 351 of file SColor.h.

351 { return color & 0xff; }
GLuint color

◆ getData()

void irr::video::SColor::getData ( void data,
ECOLOR_FORMAT  format 
) const
inline

Write the color to data in the defined format.

Parameters
datatarget to write the color. Must contain sufficiently large memory to receive the number of bytes neede for format
formattells the format used to write the color into data

Definition at line 522 of file SColor.h.

523  {
524  switch(format)
525  {
526  case ECF_A1R5G5B5:
527  {
528  u16 * dest = (u16*)data;
529  *dest = video::A8R8G8B8toA1R5G5B5( color );
530  }
531  break;
532 
533  case ECF_R5G6B5:
534  {
535  u16 * dest = (u16*)data;
536  *dest = video::A8R8G8B8toR5G6B5( color );
537  }
538  break;
539 
540  case ECF_R8G8B8:
541  {
542  u8* dest = (u8*)data;
543  dest[0] = (u8)getRed();
544  dest[1] = (u8)getGreen();
545  dest[2] = (u8)getBlue();
546  }
547  break;
548 
549  case ECF_A8R8G8B8:
550  {
551  u32 * dest = (u32*)data;
552  *dest = color;
553  }
554  break;
555 
556  default:
557  break;
558  }
559  }
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
unsigned short u16
16 bit unsigned variable.
Definition: irrTypes.h:44
SDL_AudioFormat format
Definition: SDL_audio.h:194
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
16 bit color format used by the software driver.
Definition: SColor.h:26
u16 A8R8G8B8toR5G6B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit R5G6B5 color.
Definition: SColor.h:222
Standard 16 bit color format.
Definition: SColor.h:29
u16 A8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition: SColor.h:212
GLuint color
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351
u32 color
color in A8R8G8B8 Format
Definition: SColor.h:562

◆ getGreen()

u32 irr::video::SColor::getGreen ( ) const
inline

Returns the green component of the color.

Returns
Value between 0 and 255, specifying how green the color is. 0 means no green, 255 means full green.

Definition at line 346 of file SColor.h.

346 { return (color>>8) & 0xff; }
GLuint color

◆ getInterpolated()

SColor irr::video::SColor::getInterpolated ( const SColor other,
f32  d 
) const
inline

Interpolates the color with a f32 value to another color.

Parameters
otherOther color
dvalue between 0.0f and 1.0f. d=0 returns other, d=1 returns this, values between interpolate.
Returns
Interpolated color.

Definition at line 455 of file SColor.h.

456  {
457  d = core::clamp(d, 0.f, 1.f);
458  const f32 inv = 1.0f - d;
459  return SColor((u32)core::round32(other.getAlpha()*inv + getAlpha()*d),
460  (u32)core::round32(other.getRed()*inv + getRed()*d),
461  (u32)core::round32(other.getGreen()*inv + getGreen()*d),
462  (u32)core::round32(other.getBlue()*inv + getBlue()*d));
463  }
REALINLINE s32 round32(f32 x)
Definition: irrMath.h:657
u32 getAlpha() const
Returns the alpha component of the color.
Definition: SColor.h:336
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
SColor()
Constructor of the Color. Does nothing.
Definition: SColor.h:322
GLfloat f
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167

◆ getInterpolated_quadratic()

SColor irr::video::SColor::getInterpolated_quadratic ( const SColor c1,
const SColor c2,
f32  d 
) const
inline

Returns interpolated color. ( quadratic )

Parameters
c1first color to interpolate with
c2second color to interpolate with
dvalue between 0.0f and 1.0f.

Definition at line 469 of file SColor.h.

470  {
471  // this*(1-d)*(1-d) + 2 * c1 * (1-d) + c2 * d * d;
472  d = core::clamp(d, 0.f, 1.f);
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;
477 
478  return SColor(
480  getAlpha() * mul0 + c1.getAlpha() * mul1 + c2.getAlpha() * mul2 ), 0, 255 ),
482  getRed() * mul0 + c1.getRed() * mul1 + c2.getRed() * mul2 ), 0, 255 ),
484  getGreen() * mul0 + c1.getGreen() * mul1 + c2.getGreen() * mul2 ), 0, 255 ),
486  getBlue() * mul0 + c1.getBlue() * mul1 + c2.getBlue() * mul2 ), 0, 255 ));
487  }
u32 getAlpha() const
Returns the alpha component of the color.
Definition: SColor.h:336
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
SColor()
Constructor of the Color. Does nothing.
Definition: SColor.h:322
GLfloat f
REALINLINE s32 floor32(f32 x)
Definition: irrMath.h:646
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167

◆ getLightness()

f32 irr::video::SColor::getLightness ( ) const
inline

Get lightness of the color in the range [0,255].

Definition at line 354 of file SColor.h.

355  {
357  }
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
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:124
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:138
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351

◆ getLuminance()

f32 irr::video::SColor::getLuminance ( ) const
inline

Get luminance of the color in the range [0,255].

Definition at line 360 of file SColor.h.

361  {
362  return 0.3f*getRed() + 0.59f*getGreen() + 0.11f*getBlue();
363  }
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351

◆ getRed()

u32 irr::video::SColor::getRed ( ) const
inline

Returns the red component of the color.

Returns
Value between 0 and 255, specifying how red the color is. 0 means no red, 255 means full red.

Definition at line 341 of file SColor.h.

341 { return (color>>16) & 0xff; }
GLuint color

◆ operator!=()

bool irr::video::SColor::operator!= ( const SColor other) const
inline

Compares the color to another color.

Returns
True if the colors are different, and false if they are the same.

Definition at line 434 of file SColor.h.

434 { return other.color != color; }
u32 color
color in A8R8G8B8 Format
Definition: SColor.h:562

◆ operator+()

SColor irr::video::SColor::operator+ ( const SColor other) const
inline

Adds two colors, result is clamped to 0..255 values.

Parameters
otherColor to add to this color
Returns
Addition of the two colors, clamped to 0..255 values

Definition at line 443 of file SColor.h.

444  {
445  return SColor(core::min_(getAlpha() + other.getAlpha(), 255u),
446  core::min_(getRed() + other.getRed(), 255u),
447  core::min_(getGreen() + other.getGreen(), 255u),
448  core::min_(getBlue() + other.getBlue(), 255u));
449  }
u32 getAlpha() const
Returns the alpha component of the color.
Definition: SColor.h:336
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
SColor()
Constructor of the Color. Does nothing.
Definition: SColor.h:322
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:124
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351

◆ operator<()

bool irr::video::SColor::operator< ( const SColor other) const
inline

comparison operator

Returns
True if this color is smaller than the other one

Definition at line 438 of file SColor.h.

438 { return (color < other.color); }
GLuint color

◆ operator==()

bool irr::video::SColor::operator== ( const SColor other) const
inline

Compares the color to another color.

Returns
True if the colors are the same, and false if not.

Definition at line 430 of file SColor.h.

430 { return other.color == color; }
u32 color
color in A8R8G8B8 Format
Definition: SColor.h:562

◆ set() [1/2]

void irr::video::SColor::set ( u32  a,
u32  r,
u32  g,
u32  b 
)
inline

Sets all four components of the color at once.

Constructs the color from 4 values representing the alpha, red, green and blue components of the color. Must be values between 0 and 255.

Parameters
aAlpha component of the color. The alpha component defines how transparent a color should be. Has to be a value between 0 and 255. 255 means not transparent (opaque), 0 means fully transparent.
rSets the red component of the Color. Has to be a value between 0 and 255. 0 means no red, 255 means full red.
gSets the green component of the Color. Has to be a value between 0 and 255. 0 means no green, 255 means full green.
bSets the blue component of the Color. Has to be a value between 0 and 255. 0 means no blue, 255 means full blue.

Definition at line 422 of file SColor.h.

423  {
424  color = (((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff));
425  }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLboolean GLboolean GLboolean b
GLuint color
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g

◆ set() [2/2]

void irr::video::SColor::set ( u32  col)
inline

Definition at line 426 of file SColor.h.

426 { color = col; }
GLuint color

◆ setAlpha()

void irr::video::SColor::setAlpha ( u32  a)
inline

Sets the alpha component of the Color.

The alpha component defines how transparent a color should be.

Parameters
aThe alpha value of the color. 0 is fully transparent, 255 is fully opaque.

Definition at line 374 of file SColor.h.

374 { color = ((a & 0xff)<<24) | (color & 0x00ffffff); }
GLuint color
GLboolean GLboolean GLboolean GLboolean a

◆ setBlue()

void irr::video::SColor::setBlue ( u32  b)
inline

Sets the blue component of the Color.

Parameters
bHas to be a value between 0 and 255. 0 means no blue, 255 means full blue.

Definition at line 389 of file SColor.h.

389 { color = (b & 0xff) | (color & 0xffffff00); }
GLboolean GLboolean GLboolean b
GLuint color

◆ setData()

void irr::video::SColor::setData ( const void data,
ECOLOR_FORMAT  format 
)
inline

set the color by expecting data in the given format

Parameters
datamust point to valid memory containing color information in the given format
formattells the format in which data is available

Definition at line 493 of file SColor.h.

494  {
495  switch (format)
496  {
497  case ECF_A1R5G5B5:
499  break;
500  case ECF_R5G6B5:
502  break;
503  case ECF_A8R8G8B8:
504  color = *(u32*)data;
505  break;
506  case ECF_R8G8B8:
507  {
508  const u8* p = (u8*)data;
509  set(255, p[0],p[1],p[2]);
510  }
511  break;
512  default:
513  color = 0xffffffff;
514  break;
515  }
516  }
GLfloat GLfloat p
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
void set(u32 a, u32 r, u32 g, u32 b)
Sets all four components of the color at once.
Definition: SColor.h:422
u32 A1R5G5B5toA8R8G8B8(u16 color)
Convert A8R8G8B8 Color from A1R5G5B5 color.
Definition: SColor.h:232
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
unsigned short u16
16 bit unsigned variable.
Definition: irrTypes.h:44
SDL_AudioFormat format
Definition: SDL_audio.h:194
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
16 bit color format used by the software driver.
Definition: SColor.h:26
Standard 16 bit color format.
Definition: SColor.h:29
GLuint color
u32 R5G6B5toA8R8G8B8(u16 color)
Returns A8R8G8B8 Color from R5G6B5 color.
Definition: SColor.h:243

◆ setGreen()

void irr::video::SColor::setGreen ( u32  g)
inline

Sets the green component of the Color.

Parameters
gHas to be a value between 0 and 255. 0 means no green, 255 means full green.

Definition at line 384 of file SColor.h.

384 { color = ((g & 0xff)<<8) | (color & 0xffff00ff); }
GLuint color
GLboolean GLboolean g

◆ setRed()

void irr::video::SColor::setRed ( u32  r)
inline

Sets the red component of the Color.

Parameters
rHas to be a value between 0 and 255. 0 means no red, 255 means full red.

Definition at line 379 of file SColor.h.

379 { color = ((r & 0xff)<<16) | (color & 0xff00ffff); }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLuint color

◆ toA1R5G5B5()

u16 irr::video::SColor::toA1R5G5B5 ( ) const
inline

Calculates a 16 bit A1R5G5B5 value of this color.

Returns
16 bit A1R5G5B5 value of this color.

Definition at line 393 of file SColor.h.

393 { return A8R8G8B8toA1R5G5B5(color); }
u16 A8R8G8B8toA1R5G5B5(u32 color)
Converts a 32bit (A8R8G8B8) color to a 16bit A1R5G5B5 color.
Definition: SColor.h:212
GLuint color

◆ toOpenGLColor()

void irr::video::SColor::toOpenGLColor ( u8 dest) const
inline

Converts color to OpenGL color format.

From ARGB to RGBA in 4 byte components for endian aware passing to OpenGL

Parameters
destaddress where the 4x8 bit OpenGL color is stored.

Definition at line 399 of file SColor.h.

400  {
401  *dest = (u8)getRed();
402  *++dest = (u8)getGreen();
403  *++dest = (u8)getBlue();
404  *++dest = (u8)getAlpha();
405  }
u32 getAlpha() const
Returns the alpha component of the color.
Definition: SColor.h:336
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351

Member Data Documentation

◆ color

u32 irr::video::SColor::color

color in A8R8G8B8 Format

Definition at line 562 of file SColor.h.


The documentation for this class was generated from the following file: