29 const T minComp = std::min(other.
r, std::min(other.
g,other.
b));
30 const T maxComp = std::max(other.
r, std::max(other.
g,other.
b));
31 const T delta = maxComp - minComp;
34 if (maxComp != minComp) {
35 if (maxComp == other.
r)
36 h = fmod((T(60) * ((other.
g - other.
b) / delta) + T(360)), T(360));
37 else if (maxComp == other.
g)
38 h = fmod((T(60) * ((other.
b - other.
r) / delta) + T(120)), T(360));
39 else if (maxComp == other.
b)
40 h = fmod((T(60) * ((other.
r - other.
g) / delta) + T(240)), T(360));
43 const T s = (maxComp == T(0)) ? T(0) : (delta / maxComp);
57 const T h = T(int32_t(other.
x) % 360) / T(60);
58 const T s = std::max(T(0), std::min(T(1), other.
y));
59 const T v = std::max(T(0), std::min(T(1), other.
z));
61 if (s == 0)
return {v,v,v};
63 const int32_t i = int32_t(floor(h));
65 const T p = v * (T(1) - s);
66 const T q = v * (T(1) - s * f);
67 const T t = v * (T(1) - s * (T(1) - f));
70 case 0:
return {v,t,p};
71 case 1:
return {q,v,p};
72 case 2:
return {p,v,t};
73 case 3:
return {p,q,v};
74 case 4:
return {t,p,v};
75 default:
return {v,p,q};
90 const T v = s*std::min(l,T(1)-l)+l;
91 return {h,(v > T(0)) ? T(2)-T(2)*l/v : T(0), v};
106 T m = std::min(l,T(1)-l);
107 return {h,(m > T(0)) ? (v-l)/m : l, l};
117 return {T(1)-other.
x,T(1)-other.
y,T(1)-other.
z};
128 const T minVal = std::min(cmy.
x,std::min(cmy.
y,cmy.
z));
129 return {cmy-minVal,minVal};
139 return {T(1)-other.
x,T(1)-other.
y,T(1)-other.
z};
149 return {T(1)-(other.
x+other.
w),T(1)-(other.
y+other.
w),T(1)-(other.
z+other.
w)};
159 const Mat4t<T> c{ T(0.299), T(0.587), T(0.114), T(0),
160 T(-0.147), T(-0.289), T(0.436), T(0),
161 T(0.615), T(-0.515), T(-0.100), T(0),
162 T(0), T(0), T(0), T(1)
174 const Mat4t<T> c{ T(1), T(0), T(1.140), T(0),
175 T(1), T(-0.395), T(-0.581), T(0),
176 T(1), T(2.032), T(0), T(0),
177 T(0), T(0), T(0), T(1)
4×4 matrix template for 3D transformations, projections, and stereo sets.
3D vector template with arithmetic, geometry helpers, and RNG utilities.
4D vector template with arithmetic, length helpers, and utilities.
Vec4t< float > Vec4
4D float vector (x,y,z,w).
Definition Vec4.h:337
Definition ColorConversion.h:21
Vec3t< T > hsvToHsl(const Vec3t< T > &other)
Convert HSV to HSL.
Definition ColorConversion.h:100
Vec3t< T > rgbToHsv(const Vec3t< T > &other)
Convert linear RGB to HSV.
Definition ColorConversion.h:28
Vec4t< T > rgbToCmyk(const Vec3t< T > &other)
Convert RGB to CMYK.
Definition ColorConversion.h:126
Vec3t< T > rgbToYuv(const Vec3t< T > &other)
Convert RGB to a simple YUV (luma/chroma) space via a linear matrix.
Definition ColorConversion.h:158
Vec3t< T > hsvToRgb(const Vec3t< T > &other)
Convert HSV to linear RGB.
Definition ColorConversion.h:56
Vec3t< T > rgbToCmy(const Vec3t< T > &other)
Convert RGB to CMY.
Definition ColorConversion.h:116
Vec3t< T > hslToHsv(const Vec3t< T > &other)
Convert HSL to HSV.
Definition ColorConversion.h:85
Vec3t< T > cmyToRgb(const Vec3t< T > &other)
Convert CMY to RGB.
Definition ColorConversion.h:138
Vec3t< T > cmykToRgb(const Vec4 &other)
Convert CMYK to RGB.
Definition ColorConversion.h:148
Vec3t< T > yuvToRgb(const Vec3t< T > &other)
Convert the simple YUV (above) back to RGB.
Definition ColorConversion.h:173