mirror of
https://github.com/odrling/Aegisub
synced 2025-04-11 22:56:02 +02:00
colorspace.(cpp|h) cosmetics
Originally committed to SVN as r6458.
This commit is contained in:
parent
16627dbfe7
commit
e20bc09052
@ -40,14 +40,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
/// @brief matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
// Matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
||||||
/// @param Y
|
|
||||||
/// @param U
|
|
||||||
/// @param V
|
|
||||||
/// @param R
|
|
||||||
/// @param G
|
|
||||||
/// @param B
|
|
||||||
///
|
|
||||||
void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigned char *B)
|
void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigned char *B)
|
||||||
{
|
{
|
||||||
U = U - 128;
|
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
|
// Algorithm from http://130.113.54.154/~monger/hsl-rgb.html
|
||||||
/// @param H
|
|
||||||
/// @param S
|
|
||||||
/// @param L
|
|
||||||
/// @param R
|
|
||||||
/// @param G
|
|
||||||
/// @param B
|
|
||||||
/// @return
|
|
||||||
///
|
|
||||||
void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigned char *B)
|
void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigned char *B)
|
||||||
{
|
{
|
||||||
if (S == 0) {
|
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));
|
*B = clip_colorval((int)(b*255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
/// @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
|
|
||||||
///
|
|
||||||
void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigned char *B)
|
void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigned char *B)
|
||||||
{
|
{
|
||||||
*R = *G = *B = 0;
|
*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);
|
*B = clip_colorval(b/256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
||||||
|
|
||||||
/// @brief matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
|
|
||||||
/// @param R
|
|
||||||
/// @param G
|
|
||||||
/// @param B
|
|
||||||
/// @param Y
|
|
||||||
/// @param U
|
|
||||||
/// @param V
|
|
||||||
///
|
|
||||||
void rgb_to_yuv(int R, int G, int B, unsigned char *Y, unsigned char *U, unsigned char *V)
|
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);
|
*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);
|
*V = clip_colorval(( int(0.615*65536) * R - int(0.515*65536) * G - int(0.100*65536) * B) / 65536 + 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Algorithm from http://130.113.54.154/~monger/hsl-rgb.html
|
||||||
|
|
||||||
/// @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
|
|
||||||
///
|
|
||||||
void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *L)
|
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;
|
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));
|
*L = clip_colorval(int(l*255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Formulas from http://en.wikipedia.org/wiki/HSV_color_space
|
||||||
|
|
||||||
/// @brief formulas from http://en.wikipedia.org/wiki/HSV_color_space
|
|
||||||
/// @param R
|
|
||||||
/// @param G
|
|
||||||
/// @param B
|
|
||||||
/// @param H
|
|
||||||
/// @param S
|
|
||||||
/// @param V
|
|
||||||
///
|
|
||||||
void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *V)
|
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;
|
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));
|
*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)
|
void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, unsigned char *oL)
|
||||||
{
|
{
|
||||||
int p = iV * (255 - iS);
|
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)
|
void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, unsigned char *oV)
|
||||||
{
|
{
|
||||||
*oH = iH;
|
*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)
|
wxString color_to_html(wxColour color)
|
||||||
{
|
{
|
||||||
return wxString::Format("#%02X%02X%02X", color.Red(), color.Green(), color.Blue());
|
return wxString::Format("#%02X%02X%02X", color.Red(), color.Green(), color.Blue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief DOCME
|
|
||||||
/// @param html
|
|
||||||
///
|
|
||||||
wxColour html_to_color(wxString html)
|
wxColour html_to_color(wxString html)
|
||||||
{
|
{
|
||||||
html.Trim(true);
|
html.Trim(true);
|
||||||
@ -490,6 +407,3 @@ wxColour html_to_color(wxString html)
|
|||||||
return wxColour(*wxBLACK);
|
return wxColour(*wxBLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,42 +34,33 @@
|
|||||||
/// @ingroup utility
|
/// @ingroup utility
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
#include <wx/colour.h>
|
#include <wx/colour.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// @brief DOCME
|
|
||||||
/// @param val
|
|
||||||
///
|
|
||||||
inline unsigned int clip_colorval(int val)
|
inline unsigned int clip_colorval(int val)
|
||||||
{
|
{
|
||||||
if (val < 0) return 0;
|
return std::max(0, std::min(val, 255));
|
||||||
if (val > 255) return 255;
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
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);
|
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);
|
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);
|
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);
|
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 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);
|
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);
|
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);
|
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);
|
wxColour html_to_color(wxString html);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user