4 #ifndef CHARLS_COLORTRANSFORM
5 #define CHARLS_COLORTRANSFORM
13 template<
class sample>
16 typedef sample SAMPLE;
23 template<
class sample>
31 template<
class sample>
34 enum { RANGE = 1 <<
sizeof(sample)*8 };
35 typedef sample SAMPLE;
49 hp1.v1 = SAMPLE(R - G + RANGE/2);
50 hp1.v3 = SAMPLE(B - G + RANGE/2);
59 template<
class sample>
62 enum { RANGE = 1 <<
sizeof(sample)*8 };
63 typedef sample SAMPLE;
72 rgb.R = SAMPLE(v1 + v2 - RANGE/2);
74 rgb.B = SAMPLE(v3 + ((rgb.R + rgb.G) >> 1) - RANGE/2);
89 template<
class sample>
92 enum { RANGE = 1 <<
sizeof(sample)*8 };
93 typedef sample SAMPLE;
101 int G = v1 - ((v3 + v2)>>2) + RANGE/4;
103 rgb.R = SAMPLE(v3 + G - RANGE/2);
105 rgb.B = SAMPLE(v2 + G - RANGE/2);
113 hp3.v2 = SAMPLE(B - G + RANGE/2);
114 hp3.v3 = SAMPLE(R - G + RANGE/2);
115 hp3.v1 = SAMPLE(G + ((hp3.v2 + hp3.v3)>>2)) - RANGE/4;
124 template<
class TRANSFORM>
127 typedef typename TRANSFORM::SAMPLE SAMPLE;
132 _shift(transform._shift),
133 _inverseTransform(transform._colortransform)
138 Triplet<SAMPLE> result = _inverseTransform(v1 << _shift, v2 << _shift, v3 << _shift);
140 return Triplet<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift);
143 inlinehint
Quad<SAMPLE> operator() (
int v1,
int v2,
int v3,
int v4)
145 Triplet<SAMPLE> result = _inverseTransform(v1 << _shift, v2 << _shift, v3 << _shift);
147 return Quad<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift, v4);
151 typename TRANSFORM::INVERSE _inverseTransform;
162 Triplet<SAMPLE> result = _colortransform(R << _shift, G << _shift, B << _shift);
164 return Triplet<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift);
167 inlinehint
Quad<SAMPLE> operator() (
int R,
int G,
int B,
int A)
169 Triplet<SAMPLE> result = _colortransform(R << _shift, G << _shift, B << _shift);
171 return Quad<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift, A);
175 TRANSFORM _colortransform;