34 double hls_value(
double n1,
double n2,
double hue)
41 return (n1+(n2-n1)*hue/60.);
45 return (n1+(n2-n1)*(240-hue)/60.);
53 #define thisTTClass CMYUnit
54 #define thisTTClassName "unit.cmy"
55 #define thisTTClassTags "dataspace.unit, color"
61 CMYUnit::~CMYUnit(){;}
75 output[0] = 255 * (1 - (
TTFloat64)input[0]);
76 output[1] = 255 * (1 - (
TTFloat64)input[1]);
77 output[2] = 255 * (1 - (
TTFloat64)input[2]);
82 #undef thisTTClassName
83 #undef thisTTClassTags
87 #define thisTTClass HSLUnit
88 #define thisTTClassName "unit.hsl"
89 #define thisTTClassTags "dataspace.unit, color"
95 HSLUnit::~HSLUnit(){;}
102 double red, green, blue;
103 double m1, m2, hue, lightness, saturation;
107 saturation = s/100.0;
111 m2 = lightness*(1.0+saturation);
113 m2 = lightness+saturation-lightness*saturation;
115 m1 = 2.0 * lightness-m2;
116 if(saturation == 0.0){
122 red = hls_value(m1, m2, hue+120.0);
123 green = hls_value(m1, m2, hue);
124 blue = hls_value(m1, m2, hue-120.0);
139 double hue, lightness, saturation;
140 double max,min,delta;
165 S = delta/(2.0-max-min);
179 saturation = S * 100.0;
180 lightness = L * 100.0;
184 output[1] = saturation;
185 output[2] = lightness;
190 #undef thisTTClassName
191 #undef thisTTClassTags
209 #define thisTTClass HSVUnit
210 #define thisTTClassName "unit.hsv"
211 #define thisTTClassTags "dataspace.unit, color"
217 HSVUnit::~HSVUnit(){;}
235 double var_h = h * 6;
236 double var_i = floor( var_h );
237 double var_1 = v * ( 1 - s );
238 double var_2 = v * ( 1 - s * ( var_h - var_i ) );
239 double var_3 = v * ( 1 - s * ( 1 - ( var_h - var_i ) ) );
241 if ( var_i == 0 ) { r = v ; g = var_3 ; b = var_1; }
242 else if ( var_i == 1 ) { r = var_2 ; g = v ; b = var_1; }
243 else if ( var_i == 2 ) { r = var_1 ; g = v ; b = var_3; }
244 else if ( var_i == 3 ) { r = var_1 ; g = var_2 ; b = v; }
245 else if ( var_i == 4 ) { r = var_3 ; g = var_1 ; b = v; }
246 else { r = v ; g = var_1 ; b = var_2; }
312 #undef thisTTClassName
313 #undef thisTTClassTags
317 #define thisTTClass RGBUnit
318 #define thisTTClassName "unit.rgb"
319 #define thisTTClassTags "dataspace.unit, color"
325 RGBUnit::~RGBUnit(){;}
340 #undef thisTTClassName
341 #undef thisTTClassTags
345 #define thisTTClass RGB8Unit
346 #define thisTTClassName "unit.rgb8"
347 #define thisTTClassTags "dataspace.unit, color"
353 RGB8Unit::~RGB8Unit(){;}
374 #undef thisTTClassName
375 #undef thisTTClassTags
379 #define thisTTClass ColorDataspace
380 #define thisTTClassName "dataspace.color"
381 #define thisTTClassTags "foundationDataspaceLib, dataspace, color"
386 registerUnit(
TT(
"unit.cmy"),
TT(
"cmy"));
387 registerUnit(
TT(
"unit.hsl"),
TT(
"hsl"));
388 registerUnit(
TT(
"unit.hsv"),
TT(
"hsv"));
389 registerUnit(
TT(
"unit.rgb"),
TT(
"rgb"));
390 registerUnit(
TT(
"unit.rgb8"),
TT(
"rgb8"));
393 neutralUnit =
TT(
"rgb");
396 setInputUnit(neutralUnit);
397 setOutputUnit(neutralUnit);
401 ColorDataspace::~ColorDataspace()
407 #undef thisTTClassName
408 #undef thisTTClassTags
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from HSV to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to HSL.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from radians to neutral unit.
TTFOUNDATION_EXPORT const TTFloat64 kTTInv255
Constant for color representation when converting from char8 to float representation.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to RGB8.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from RGB8 to neutral unit.
double TTFloat64
64 bit floating point number
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to HSV.
Specification for the base class of each DataspaceUnit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to CMY.
The ColorDataspace converts between different measurement units describing colors.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to RGB.
TT_OBJECT_CONSTRUCTOR
Constructor macro.
void resize(size_type n)
Change the number of elements.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from HSL to neutral unit.
[doxygenAppendixC_copyExample]
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from CMY to neutral unit.