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

Class representing a color in HSL format. More...

#include <SColor.h>

Public Member Functions

 SColorHSL (f32 h=0.f, f32 s=0.f, f32 l=0.f)
 
void fromRGB (const SColorf &color)
 
void toRGB (SColorf &color) const
 

Public Attributes

f32 Hue
 
f32 Saturation
 
f32 Luminance
 

Detailed Description

Class representing a color in HSL format.

The color values for hue, saturation, luminance are stored in 32bit floating point variables. Hue is in range [0,360], Luminance and Saturation are in percent [0,100]

Definition at line 707 of file SColor.h.

Constructor & Destructor Documentation

◆ SColorHSL()

irr::video::SColorHSL::SColorHSL ( f32  h = 0.f,
f32  s = 0.f,
f32  l = 0.f 
)
inline

Definition at line 710 of file SColor.h.

711  : Hue ( h ), Saturation ( s ), Luminance ( l ) {}
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
Definition: SDL_opengl.h:2063

Member Function Documentation

◆ fromRGB()

void irr::video::SColorHSL::fromRGB ( const SColorf color)
inline

Definition at line 725 of file SColor.h.

726  {
727  const f32 maxVal = core::max_(color.getRed(), color.getGreen(), color.getBlue());
728  const f32 minVal = (f32)core::min_(color.getRed(), color.getGreen(), color.getBlue());
729  Luminance = (maxVal+minVal)*50;
730  if (core::equals(maxVal, minVal))
731  {
732  Hue=0.f;
733  Saturation=0.f;
734  return;
735  }
736 
737  const f32 delta = maxVal-minVal;
738  if ( Luminance <= 50 )
739  {
740  Saturation = (delta)/(maxVal+minVal);
741  }
742  else
743  {
744  Saturation = (delta)/(2-maxVal-minVal);
745  }
746  Saturation *= 100;
747 
748  if (core::equals(maxVal, color.getRed()))
749  Hue = (color.getGreen()-color.getBlue())/delta;
750  else if (core::equals(maxVal, color.getGreen()))
751  Hue = 2+((color.getBlue()-color.getRed())/delta);
752  else // blue is max
753  Hue = 4+((color.getRed()-color.getGreen())/delta);
754 
755  Hue *= 60.0f;
756  while ( Hue < 0.f )
757  Hue += 360;
758  }
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
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.h:246
GLfloat f
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
GLuint color

◆ toRGB()

void irr::video::SColorHSL::toRGB ( SColorf color) const
inline

Definition at line 761 of file SColor.h.

762  {
763  const f32 l = Luminance/100;
764  if (core::iszero(Saturation)) // grey
765  {
766  color.set(l, l, l);
767  return;
768  }
769 
770  f32 rm2;
771 
772  if ( Luminance <= 50 )
773  {
774  rm2 = l + l * (Saturation/100);
775  }
776  else
777  {
778  rm2 = l + (1 - l) * (Saturation/100);
779  }
780 
781  const f32 rm1 = 2.0f * l - rm2;
782 
783  const f32 h = Hue / 360.0f;
784  color.set( toRGB1(rm1, rm2, h + 1.f/3.f),
785  toRGB1(rm1, rm2, h),
786  toRGB1(rm1, rm2, h - 1.f/3.f)
787  );
788  }
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition: irrMath.h:307
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
GLfloat GLfloat GLfloat GLfloat h
GLfloat f
GLuint color

Member Data Documentation

◆ Hue

f32 irr::video::SColorHSL::Hue

Definition at line 716 of file SColor.h.

◆ Luminance

f32 irr::video::SColorHSL::Luminance

Definition at line 718 of file SColor.h.

◆ Saturation

f32 irr::video::SColorHSL::Saturation

Definition at line 717 of file SColor.h.


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