In order operate more easily with the components of the color spaces we shall define every color space as a structure.
| Color space | Structure | Members |
| RGB | RgbFColor | double R,G,B |
| RGB | RgbIColor | uint8_t R,G,B |
| HSI | HsiColor | double H,S,I |
| HSL | HslColor | double H,S,L |
| HSV | HsvColor | double H,S,V |
| YIQ | YiqColor | double Y,I,Q |
| YUV | YuvColor | double Y,U,V |
The RgbIColor is associated with the RGB color space model and it will contain the R,G,B components expressed as natural numbers in the range [0,255].
The RbgFColor is associated with the RGB color space model and it will contain the R,G,B components expressed as real numbers in the range [0.0, 1.0].
The HslColor is associated with the HSL color space model and it will contain the H,S,L components expressed as real numbers where H is in the range [0.0, 360.0] and S and L are in the range [0.0, 1.0].
The HsvColor is associated with the HSV color space model and it will contain the H,S,V components expressed as real numbers where H is in the range [0.0, 360.0] and S and V are in the range [0.0, 1.0].
The HsiColor is associated with the HSI color space model and it will contain the H,S,I components expressed as real numbers where H is in the range [0.0, 360.0] and S and I are in the range [0.0, 1.0].
The YiqColor is associated with the YIQ color space model and it will contain the Y,I,Q components expressed as real numbers where Y is in the range [0.0, 1.0], I is in the range [-0.5957, 0.5957], Q is in the range [-0.5226, 0.5226].
The YuvColor is associated with the YUV color space model and it will contain the Y,U,V components expressed as real numbers where Y is in the range [0.0, 1.0], U is in the range [-0.436, 0.436], Q is in the range [-0.615, 0.615].
We shall also define the following functions which will be used for the conversion algorithms:
/*
* Description:
* Checks if a value is within a specified interval
* Parameters:
* value - the value who is checked
* lowerLimit - the lower limit of the interval
* upperLimit - the upper limit of the interval
* Returns:
* true if the value is within the interval
* false if the value is not within the interval
*/
bool RealIsWithinBounds(double value, double lowerLimit, double upperLimit);
/*
* Description:
* Checks if a value is within a specified interval
* Parameters:
* value - the value who is checked
* lowerLimit - the lower limit of the interval
* upperLimit - the upper limit of the interval
* Returns:
* true if the value is within the interval
* false if the value is not within the interval
*/
bool IntegerIsWithinBounds(uint8_t value, uint8_t lowerLimit, uint8_t upperLimit);
/*
* Description:
* Returns the smallest of the three parameters
* Parameters
* r,g,b - 3 real numbers
* Returns
* The smallest real number from the set {r,g,b}
*/
double Double_GetMinimum(double r, double g, double b);
/*
* Description:
* Returns the largest of the three parameters
* Parameters
* r,g,b - 3 real numbers
* Returns
* The largest real number from the set {r,g,b}
*/
double Double_GetMaximum(double r, double g, double b);
/*
* Description:
* Checks if the RGB components are valid
* Parameters:
* r,g,b - the components of an RGB model expressed
* as real numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool RgbF_IsValid(double r, double g, double b);
/*
* Description:
* Checks if the HSI components are valid
* Parameters:
* h,s,i - the components of an HSI model expressed
* as real numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool Hsi_IsValid(double h, double s, double i);
/*
* Description:
* Checks if the RGB components are valid
* Parameters:
* r,g,b - the components of an RGB model expressed
* as natural numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool RgbI_IsValid(uint8_t r, uint8_t g, uint8_t b);
/*
* Description:
* Checks if the HSL components are valid
* Parameters:
* h,s,l - the components of an HSL model expressed
* as real numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool Hsl_IsValid(double h, double s, double l);
/*
* Description:
* Checks if the HSV components are valid
* Parameters:
* h,s,v - the components of an HSV model expressed
* as real numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool Hsv_IsValid(double h, double s, double v);
/*
* Description:
* Checks if the YIQ components are valid
* Parameters:
* y,i,q - the components of an YIQ model expressed
* as real numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool Yiq_IsValid(double y, double i, double q);
/*
* Description:
* Checks if the YUV components are valid
* Parameters:
* y,u,v - the components of an YUV model expressed
* as real numbers
* Returns:
* true if the values are correct
* false if the values are incorrect
*/
bool Yuv_IsValid(double y, double u, double v);
If you want to view the implementation of these functions, see the links below:
No comments:
Post a Comment
Got a question regarding something in the article? Leave me a comment and I will get back at you as soon as I can!