34 #ifndef AIMS_UTILITY_CONVERTER_HSV_H 35 #define AIMS_UTILITY_CONVERTER_HSV_H 43 #define MIN3(x,y,z) ((y) <= (z) ? \ 44 ((x) <= (y) ? (x) : (y)) \ 46 ((x) <= (z) ? (x) : (z))) 48 #define MAX3(x,y,z) ((y) >= (z) ? \ 49 ((x) >= (y) ? (x) : (y)) \ 51 ((x) >= (z) ? (x) : (z))) 56 template <
class T>
inline 59 byte rgb_min, rgb_max;
60 rgb_min =
MIN3(in.red(), in.green(), in.blue());
61 rgb_max =
MAX3(in.red(), in.green(), in.blue());
64 out.
value() = rgb_max;
65 if (out.
value() == 0) {
70 out.
saturation() = uint8_t( rint(255.0 *
double(rgb_max - rgb_min)
77 if (rgb_max == in.red()) {
78 out.
hue() = uint8_t( rint(43.0 *
double(in.green()
79 - in.blue())/(rgb_max - rgb_min)) );
80 }
else if (rgb_max == in.green()) {
81 out.
hue() = 85 + uint8_t( rint(43.0 *
double(in.blue()
82 - in.red())/(rgb_max - rgb_min)) );
84 out.
hue() = 171 + uint8_t( rint(43.0 *
double(in.red()
85 - in.green())/(rgb_max - rgb_min)) );
91 template <
class T>
inline 94 double f, h, s, v, r0 = 360.0 / 255, r1 = 1.0 / 255;
99 out.red() = out.green() = out.blue() = in.
value();
103 h = double( in.
hue() ) * r0;
105 v = double( in.
value() ) * r1;
106 i = long( floor( h / 60 ) ) % 6;
108 p =
byte( v * ( 1.0 - s ) * 255 );
109 q =
byte( v * ( 1.0 - f * s ) * 255 );
110 t =
byte( v * ( 1.0 - ( 1.0 - f ) * s ) * 255 );
114 out.red() = in.
value();
120 out.green() = in.
value();
125 out.green() = in.
value();
131 out.blue() = in.
value();
136 out.blue() = in.
value();
139 out.red() = in.
value();
158 rgbtohsv<AimsRGB>( tmp, out );
161 template <
class OUTP>
174 hsvtorgb<AimsRGB>( in, tmp );
175 out = (OUTP) ( sqrt( ( (
double) tmp.
red() ) * tmp.
red()
177 + ( (double) tmp.
blue() ) * tmp.
blue() ) );
186 hsvtorgb<AimsRGB>( in, out );
196 hsvtorgb<AimsRGBA>( in, out );
207 rgbtohsv<AimsRGB>( in, out );
217 rgbtohsv<AimsRGBA>( in, out );
void convert(const AimsRGBA &in, AimsHSV &out) const
void convert(const INP &in, OUTP &out) const
void rgbtohsv(const T &in, AimsHSV &out)
void hsvtorgb(const AimsHSV &in, T &out)
const uint8_t & hue() const
void convert(const AimsRGB &in, AimsHSV &out) const
void convert(const AimsHSV &in, AimsRGB &out) const
const uint8_t & value() const
void convert(const AimsHSV &in, AimsRGBA &out) const
const uint8_t & blue() const
const uint8_t & saturation() const
const uint8_t & green() const
const uint8_t & red() const