1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
template <typename T>
T clamp( T min, T value, T max )
{
return !(min < value) ? min : (!(value < max) ? max : value);
}
template <typename RGB_Component_Iterator, typename YIQ_Component_Iterator>
void rgb2ntsc(
RGB_Component_Iterator first,
RGB_Component_Iterator last,
YIQ_Component_Iterator result )
{
while (first != last)
{
decltype(*first) R = *first++; if (first == last) break;
decltype(*first) G = *first++; if (first == last) break;
decltype(*first) B = *first++;
*result++ = clamp( 0.0000, R*0.299 + G*0.587 + B*0.114, 1.0000 );
*result++ = clamp( -0.5957, R*0.596 - G*0.274 - B*0.322, 0.5957 );
*result++ = clamp( -0.5226, R*0.211 - G*0.523 + B*0.312, 0.5226 );
}
}
template <typename YIQ_Component_Iterator, typename RGB_Component_Iterator>
void ntsc2rgb(
YIQ_Component_Iterator first,
YIQ_Component_Iterator last,
RGB_Component_Iterator result )
{
while (first != last)
{
decltype(*first) Y = *first++; if (first == last) break;
decltype(*first) I = *first++; if (first == last) break;
decltype(*first) Q = *first++;
*result++ = clamp( 0.0, Y + I*0.956 + Q*0.621, 1.0 );
*result++ = clamp( 0.0, Y - I*0.272 - Q*0.647, 1.0 );
*result++ = clamp( 0.0, Y - I*1.106 + Q*1.703, 1.0 );
}
}
|