colorspace.(cpp|h) cosmetics
Originally committed to SVN as r6458.
This commit is contained in:
parent
16627dbfe7
commit
e20bc09052
2 changed files with 16 additions and 111 deletions
|
@ -40,14 +40,7 @@
|
|||
#include "utils.h"
|
||||
|
||||
|
||||
/// @brief matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
||||
/// @param Y
|
||||
/// @param U
|
||||
/// @param V
|
||||
/// @param R
|
||||
/// @param G
|
||||
/// @param B
|
||||
///
|
||||
// Matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
||||
void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigned char *B)
|
||||
{
|
||||
U = U - 128;
|
||||
|
@ -59,15 +52,7 @@ void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigne
|
|||
|
||||
|
||||
|
||||
/// @brief making every value into 0..255 range though algorithm from http://130.113.54.154/~monger/hsl-rgb.html
|
||||
/// @param H
|
||||
/// @param S
|
||||
/// @param L
|
||||
/// @param R
|
||||
/// @param G
|
||||
/// @param B
|
||||
/// @return
|
||||
///
|
||||
// Algorithm from http://130.113.54.154/~monger/hsl-rgb.html
|
||||
void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigned char *B)
|
||||
{
|
||||
if (S == 0) {
|
||||
|
@ -167,17 +152,8 @@ void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigne
|
|||
*B = clip_colorval((int)(b*255));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief the range for H is 0..255 instead of 0..359, so 60 degrees has been translated to 256/6 here formulas taken from wikipedia: http://en.wikipedia.org/wiki/HSV_color_space
|
||||
/// @param H
|
||||
/// @param S
|
||||
/// @param V
|
||||
/// @param R
|
||||
/// @param G
|
||||
/// @param B
|
||||
/// @return
|
||||
///
|
||||
// Formulas taken from wikipedia: http://en.wikipedia.org/wiki/HSV_color_space
|
||||
// The range for H is 0..255 instead of 0..359, so 60 degrees has been translated to 256/6 here
|
||||
void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigned char *B)
|
||||
{
|
||||
*R = *G = *B = 0;
|
||||
|
@ -279,16 +255,7 @@ void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigne
|
|||
*B = clip_colorval(b/256);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
||||
/// @param R
|
||||
/// @param G
|
||||
/// @param B
|
||||
/// @param Y
|
||||
/// @param U
|
||||
/// @param V
|
||||
///
|
||||
// Matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
||||
void rgb_to_yuv(int R, int G, int B, unsigned char *Y, unsigned char *U, unsigned char *V)
|
||||
{
|
||||
*Y = clip_colorval(( int(0.299*65536) * R + int(0.587*65536) * G + int(0.114*65536) * B) / 65536);
|
||||
|
@ -296,16 +263,7 @@ void rgb_to_yuv(int R, int G, int B, unsigned char *Y, unsigned char *U, unsigne
|
|||
*V = clip_colorval(( int(0.615*65536) * R - int(0.515*65536) * G - int(0.100*65536) * B) / 65536 + 128);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief still keeping everything integer also from http://130.113.54.154/~monger/hsl-rgb.html
|
||||
/// @param R
|
||||
/// @param G
|
||||
/// @param B
|
||||
/// @param H
|
||||
/// @param S
|
||||
/// @param L
|
||||
///
|
||||
/// Algorithm from http://130.113.54.154/~monger/hsl-rgb.html
|
||||
void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *L)
|
||||
{
|
||||
float r = R/255.f, g = G/255.f, b = B/255.f;
|
||||
|
@ -341,16 +299,7 @@ void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
|
|||
*L = clip_colorval(int(l*255));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief formulas from http://en.wikipedia.org/wiki/HSV_color_space
|
||||
/// @param R
|
||||
/// @param G
|
||||
/// @param B
|
||||
/// @param H
|
||||
/// @param S
|
||||
/// @param V
|
||||
///
|
||||
/// Formulas from http://en.wikipedia.org/wiki/HSV_color_space
|
||||
void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *V)
|
||||
{
|
||||
float r = R/255.f, g = G/255.f, b = B/255.f;
|
||||
|
@ -384,16 +333,6 @@ void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
|
|||
*V = clip_colorval(int(v*255));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief DOCME
|
||||
/// @param iH
|
||||
/// @param iS
|
||||
/// @param iV
|
||||
/// @param oH
|
||||
/// @param oS
|
||||
/// @param oL
|
||||
///
|
||||
void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, unsigned char *oL)
|
||||
{
|
||||
int p = iV * (255 - iS);
|
||||
|
@ -408,17 +347,6 @@ void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, un
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief DOCME
|
||||
/// @param iH
|
||||
/// @param iS
|
||||
/// @param iL
|
||||
/// @param oH
|
||||
/// @param oS
|
||||
/// @param oV
|
||||
/// @return
|
||||
///
|
||||
void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, unsigned char *oV)
|
||||
{
|
||||
*oH = iH;
|
||||
|
@ -438,22 +366,11 @@ void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, un
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief DOCME
|
||||
/// @param color
|
||||
/// @return
|
||||
///
|
||||
wxString color_to_html(wxColour color)
|
||||
{
|
||||
return wxString::Format("#%02X%02X%02X", color.Red(), color.Green(), color.Blue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief DOCME
|
||||
/// @param html
|
||||
///
|
||||
wxColour html_to_color(wxString html)
|
||||
{
|
||||
html.Trim(true);
|
||||
|
@ -490,6 +407,3 @@ wxColour html_to_color(wxString html)
|
|||
return wxColour(*wxBLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -34,42 +34,33 @@
|
|||
/// @ingroup utility
|
||||
///
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <wx/colour.h>
|
||||
#include <wx/string.h>
|
||||
#endif
|
||||
|
||||
|
||||
/// @brief DOCME
|
||||
/// @param val
|
||||
///
|
||||
inline unsigned int clip_colorval(int val)
|
||||
{
|
||||
if (val < 0) return 0;
|
||||
if (val > 255) return 255;
|
||||
return val;
|
||||
return std::max(0, std::min(val, 255));
|
||||
}
|
||||
|
||||
|
||||
// Convert an YUV color to RGB; all values are expected to be in range 0..255
|
||||
/// Convert an YUV color to RGB; all values are expected to be in range 0..255
|
||||
void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigned char *B);
|
||||
|
||||
// Convert a HSL color to RGB; all values are expected to be in range 0..255
|
||||
/// Convert a HSL color to RGB; all values are expected to be in range 0..255
|
||||
void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigned char *B);
|
||||
|
||||
// Convert a HSV color to RGB; all values are expected to be in range 0..255
|
||||
/// Convert a HSV color to RGB; all values are expected to be in range 0..255
|
||||
void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigned char *B);
|
||||
|
||||
// Convert an RGB color to YUV; all values are expected to be in range 0..255
|
||||
/// Convert an RGB color to YUV; all values are expected to be in range 0..255
|
||||
void rgb_to_yuv(int R, int G, int B, unsigned char *Y, unsigned char *U, unsigned char *V);
|
||||
|
||||
// Convert an RGB color to HSL; all values are expected to be in range 0..255
|
||||
/// Convert an RGB color to HSL; all values are expected to be in range 0..255
|
||||
void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *L);
|
||||
|
||||
// Convert an RGB color to HSV; all values are expected to be in range 0..255
|
||||
/// Convert an RGB color to HSV; all values are expected to be in range 0..255
|
||||
void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *V);
|
||||
|
||||
void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, unsigned char *oL);
|
||||
|
@ -77,8 +68,8 @@ void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, un
|
|||
void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, unsigned char *oV);
|
||||
|
||||
|
||||
// Convert a wxColour to a HTML hex string
|
||||
/// Convert a wxColour to a HTML hex string
|
||||
wxString color_to_html(wxColour color);
|
||||
|
||||
// Convert a HTML hex string to a wxColour
|
||||
/// Convert a HTML hex string to a wxColour
|
||||
wxColour html_to_color(wxString html);
|
||||
|
|
Loading…
Reference in a new issue