OFFIS DCMTK  Version 3.6.0
clrtrans.h
1 //
2 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 //
4 #ifndef CHARLS_COLORTRANSFORM
5 #define CHARLS_COLORTRANSFORM
6 
7 //
8 // This file defines simple classes that define (lossless) color transforms.
9 // They are invoked in processline.h to convert between decoded values and the internal line buffers.
10 // Color transforms work best for computer generated images.
11 //
12 
13 template<class sample>
15 {
16  typedef sample SAMPLE;
17 
18  inlinehint Triplet<SAMPLE> operator() (int v1, int v2, int v3)
19  { return Triplet<SAMPLE>(v1, v2, v3); }
20 };
21 
22 
23 template<class sample>
24 struct TransformNone : public TransformNoneImpl<sample>
25 {
26  typedef struct TransformNoneImpl<sample> INVERSE;
27 };
28 
29 
30 
31 template<class sample>
33 {
34  enum { RANGE = 1 << sizeof(sample)*8 };
35  typedef sample SAMPLE;
36 
37  struct INVERSE
38  {
39  INVERSE(const TransformHp1&) {};
40 
41  inlinehint Triplet<SAMPLE> operator() (int v1, int v2, int v3)
42  { return Triplet<SAMPLE>(v1 + v2 - RANGE/2, v2, v3 + v2 - RANGE/2); }
43  };
44 
45  inlinehint Triplet<SAMPLE> operator() (int R, int G, int B)
46  {
47  Triplet<SAMPLE> hp1;
48  hp1.v2 = SAMPLE(G);
49  hp1.v1 = SAMPLE(R - G + RANGE/2);
50  hp1.v3 = SAMPLE(B - G + RANGE/2);
51  return hp1;
52  }
53 };
54 
55 
56 
57 
58 
59 template<class sample>
61 {
62  enum { RANGE = 1 << sizeof(sample)*8 };
63  typedef sample SAMPLE;
64 
65  struct INVERSE
66  {
67  INVERSE(const TransformHp2&) {};
68 
69  inlinehint Triplet<SAMPLE> operator() (int v1, int v2, int v3)
70  {
71  Triplet<SAMPLE> rgb;
72  rgb.R = SAMPLE(v1 + v2 - RANGE/2); // new R
73  rgb.G = SAMPLE(v2); // new G
74  rgb.B = SAMPLE(v3 + ((rgb.R + rgb.G) >> 1) - RANGE/2); // new B
75  return rgb;
76  }
77  };
78 
79  inlinehint Triplet<SAMPLE> operator() (int R, int G, int B)
80  {
81  return Triplet<SAMPLE>(R - G + RANGE/2, G, B - ((R+G )>>1) - RANGE/2);
82  }
83 
84 
85 };
86 
87 
88 
89 template<class sample>
91 {
92  enum { RANGE = 1 << sizeof(sample)*8 };
93  typedef sample SAMPLE;
94 
95  struct INVERSE
96  {
97  INVERSE(const TransformHp3&) {};
98 
99  inlinehint Triplet<SAMPLE> operator() (int v1, int v2, int v3)
100  {
101  int G = v1 - ((v3 + v2)>>2) + RANGE/4;
102  Triplet<SAMPLE> rgb;
103  rgb.R = SAMPLE(v3 + G - RANGE/2); // new R
104  rgb.G = SAMPLE(G); // new G
105  rgb.B = SAMPLE(v2 + G - RANGE/2); // new B
106  return rgb;
107  }
108  };
109 
110  inlinehint Triplet<SAMPLE> operator() (int R, int G, int B)
111  {
112  Triplet<SAMPLE> hp3;
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;
116  return hp3;
117  }
118 };
119 
120 
121 // Transform class that shifts bits towards the high bit when bitcount is not 8 or 16
122 // needed to make the HP color transforms work correctly.
123 
124 template<class TRANSFORM>
126 {
127  typedef typename TRANSFORM::SAMPLE SAMPLE;
128 
129  struct INVERSE
130  {
131  INVERSE(const TransformShifted& transform) :
132  _shift(transform._shift),
133  _inverseTransform(transform._colortransform)
134  {}
135 
136  inlinehint Triplet<SAMPLE> operator() (int v1, int v2, int v3)
137  {
138  Triplet<SAMPLE> result = _inverseTransform(v1 << _shift, v2 << _shift, v3 << _shift);
139 
140  return Triplet<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift);
141  }
142 
143  inlinehint Quad<SAMPLE> operator() (int v1, int v2, int v3, int v4)
144  {
145  Triplet<SAMPLE> result = _inverseTransform(v1 << _shift, v2 << _shift, v3 << _shift);
146 
147  return Quad<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift, v4);
148  }
149 
150  int _shift;
151  typename TRANSFORM::INVERSE _inverseTransform;
152  };
153 
154 
155  TransformShifted(int shift) :
156  _shift(shift)
157  {
158  }
159 
160  inlinehint Triplet<SAMPLE> operator() (int R, int G, int B)
161  {
162  Triplet<SAMPLE> result = _colortransform(R << _shift, G << _shift, B << _shift);
163 
164  return Triplet<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift);
165  }
166 
167  inlinehint Quad<SAMPLE> operator() (int R, int G, int B, int A)
168  {
169  Triplet<SAMPLE> result = _colortransform(R << _shift, G << _shift, B << _shift);
170 
171  return Quad<SAMPLE>(result.R >> _shift, result.G >> _shift, result.B >> _shift, A);
172  }
173 
174  int _shift;
175  TRANSFORM _colortransform;
176 };
177 
178 
179 
180 #endif


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2