OFFIS DCMTK  Version 3.6.0
procline.h
1 //
2 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 //
4 #ifndef CHARLS_PROCESSLINE
5 #define CHARLS_PROCESSLINE
6 
7 #include "clrtrans.h"
8 
9 //
10 // This file defines the ProcessLine base class, its derivitives and helper functions.
11 // During coding/decoding, CharLS process one line at a time. The different Processline implementations
12 // convert the uncompressed format to and from the internal format for encoding.
13 // Conversions include color transforms, line interleaved vs sample interleaved, masking out unused bits,
14 // accounting for line padding etc.
15 // This mechanism could be used to encode/decode images as they are received.
16 //
17 
19 {
20 public:
21  virtual ~ProcessLine() {}
22  virtual void NewLineDecoded(const void* pSrc, int pixelCount, int bytesperline) = 0;
23  virtual void NewLineRequested(void* pSrc, int pixelCount, int bytesperline) = 0;
24 };
25 
26 
28 {
29 public:
30  PostProcesSingleComponent(void* pbyteOutput, const JlsParameters& info, int bytesPerPixel) :
31  _pbyteOutput((BYTE*)pbyteOutput),
32  _bytesPerPixel(bytesPerPixel),
33  _bytesPerLine(info.bytesperline)
34  {
35  }
36 
37  void NewLineRequested(void* pDst, int pixelCount, int /*byteStride*/)
38  {
39  OFBitmanipTemplate<BYTE>::copyMem(_pbyteOutput, (BYTE*) pDst, pixelCount * _bytesPerPixel);
40  _pbyteOutput += _bytesPerLine;
41  }
42 
43  void NewLineDecoded(const void* pSrc, int pixelCount, int /*byteStride*/)
44  {
45  OFBitmanipTemplate<BYTE>::copyMem((BYTE*) pSrc, _pbyteOutput, pixelCount * _bytesPerPixel);
46  _pbyteOutput += _bytesPerLine;
47  }
48 
49 private:
50  BYTE* _pbyteOutput;
51  int _bytesPerPixel;
52  int _bytesPerLine;
53 };
54 
55 
56 template<class TRANSFORM, class SAMPLE>
57 void TransformLineToQuad(const SAMPLE* ptypeInput, LONG pixelStrideIn, Quad<SAMPLE>* pbyteBuffer, LONG pixelStride, TRANSFORM& transform)
58 {
59  int cpixel = MIN(pixelStride, pixelStrideIn);
60  Quad<SAMPLE>* ptypeBuffer = (Quad<SAMPLE>*)pbyteBuffer;
61 
62  for (int x = 0; x < cpixel; ++x)
63  {
64  Quad<SAMPLE> pixel(transform(ptypeInput[x], ptypeInput[x + pixelStrideIn], ptypeInput[x + 2*pixelStrideIn]),ptypeInput[x + 3*pixelStrideIn]) ;
65 
66  ptypeBuffer[x] = pixel;
67  }
68 }
69 
70 
71 template<class TRANSFORM, class SAMPLE>
72 void TransformQuadToLine(const Quad<SAMPLE>* pbyteInput, LONG pixelStrideIn, SAMPLE* ptypeBuffer, LONG pixelStride, TRANSFORM& transform)
73 {
74  int cpixel = MIN(pixelStride, pixelStrideIn);
75  const Quad<SAMPLE>* ptypeBufferIn = (Quad<SAMPLE>*)pbyteInput;
76 
77  for (int x = 0; x < cpixel; ++x)
78  {
79  Quad<SAMPLE> color = ptypeBufferIn[x];
80  Quad<SAMPLE> colorTranformed(transform(color.v1, color.v2, color.v3), color.v4);
81 
82  ptypeBuffer[x] = colorTranformed.v1;
83  ptypeBuffer[x + pixelStride] = colorTranformed.v2;
84  ptypeBuffer[x + 2 *pixelStride] = colorTranformed.v3;
85  ptypeBuffer[x + 3 *pixelStride] = colorTranformed.v4;
86  }
87 }
88 
89 
90 template<class SAMPLE>
91 void TransformRgbToBgr(SAMPLE* pDest, int samplesPerPixel, int pixelCount)
92 {
93  for (int i = 0; i < pixelCount; ++i)
94  {
95  SAMPLE tmp = pDest[0];
96  pDest[0] = pDest[2];
97  pDest[2] = tmp;
98  pDest += samplesPerPixel;
99  }
100 }
101 
102 
103 template<class TRANSFORM, class SAMPLE>
104 void TransformLine(Triplet<SAMPLE>* pDest, const Triplet<SAMPLE>* pSrc, int pixelCount, TRANSFORM& transform)
105 {
106  for (int i = 0; i < pixelCount; ++i)
107  {
108  pDest[i] = transform(pSrc[i].v1, pSrc[i].v2, pSrc[i].v3);
109  }
110 }
111 
112 
113 template<class TRANSFORM, class SAMPLE>
114 void TransformLineToTriplet(const SAMPLE* ptypeInput, LONG pixelStrideIn, Triplet<SAMPLE>* pbyteBuffer, LONG pixelStride, TRANSFORM& transform)
115 {
116  int cpixel = MIN(pixelStride, pixelStrideIn);
117  Triplet<SAMPLE>* ptypeBuffer = (Triplet<SAMPLE>*)pbyteBuffer;
118 
119  for (int x = 0; x < cpixel; ++x)
120  {
121  ptypeBuffer[x] = transform(ptypeInput[x], ptypeInput[x + pixelStrideIn], ptypeInput[x + 2*pixelStrideIn]);
122  }
123 }
124 
125 
126 template<class TRANSFORM, class SAMPLE>
127 void TransformTripletToLine(const Triplet<SAMPLE>* pbyteInput, LONG pixelStrideIn, SAMPLE* ptypeBuffer, LONG pixelStride, TRANSFORM& transform)
128 {
129  int cpixel = MIN(pixelStride, pixelStrideIn);
130  const Triplet<SAMPLE>* ptypeBufferIn = (Triplet<SAMPLE>*)pbyteInput;
131 
132  for (int x = 0; x < cpixel; ++x)
133  {
134  Triplet<SAMPLE> color = ptypeBufferIn[x];
135  Triplet<SAMPLE> colorTranformed = transform(color.v1, color.v2, color.v3);
136 
137  ptypeBuffer[x] = colorTranformed.v1;
138  ptypeBuffer[x + pixelStride] = colorTranformed.v2;
139  ptypeBuffer[x + 2 *pixelStride] = colorTranformed.v3;
140  }
141 }
142 
143 
144 template<class TRANSFORM>
146 {
147  typedef typename TRANSFORM::SAMPLE SAMPLE;
148 
150 public:
151  ProcessTransformed(void* pbyteOutput, const JlsParameters& info, TRANSFORM transform) :
152  _pbyteOutput((BYTE*)pbyteOutput),
153  _info(info),
154  _templine(info.width * info.components),
155  _transform(transform),
156  _inverseTransform(transform)
157  {
158 // ASSERT(_info.components == sizeof(TRIPLET)/sizeof(TRIPLET::SAMPLE));
159  }
160 
161 
162  void NewLineRequested(void* pDst, int pixelCount, int stride)
163  {
164  SAMPLE* pLine = (SAMPLE*)_pbyteOutput;
165  if (_info.outputBgr)
166  {
167  pLine = &_templine[0];
168  memcpy(pLine, _pbyteOutput, sizeof(Triplet<SAMPLE>)*pixelCount);
169  TransformRgbToBgr(pLine, _info.components, pixelCount);
170  }
171 
172  if (_info.components == 3)
173  {
174  if (_info.ilv == ILV_SAMPLE)
175  {
176  TransformLine((Triplet<SAMPLE>*)pDst, (const Triplet<SAMPLE>*)pLine, pixelCount, _transform);
177  }
178  else
179  {
180  TransformTripletToLine((const Triplet<SAMPLE>*)pLine, pixelCount, (SAMPLE*)pDst, stride, _transform);
181  }
182  }
183  else if (_info.components == 4 && _info.ilv == ILV_LINE)
184  {
185  TransformQuadToLine((const Quad<SAMPLE>*)pLine, pixelCount, (SAMPLE*)pDst, stride, _transform);
186  }
187  _pbyteOutput += _info.bytesperline;
188  }
189 
190 
191  void NewLineDecoded(const void* pSrc, int pixelCount, int byteStride)
192  {
193  if (_info.components == 3)
194  {
195  if (_info.ilv == ILV_SAMPLE)
196  {
197  TransformLine((Triplet<SAMPLE>*)_pbyteOutput, (const Triplet<SAMPLE>*)pSrc, pixelCount, _inverseTransform);
198  }
199  else
200  {
201  TransformLineToTriplet((const SAMPLE*)pSrc, byteStride, (Triplet<SAMPLE>*)_pbyteOutput, pixelCount, _inverseTransform);
202  }
203  }
204  else if (_info.components == 4 && _info.ilv == ILV_LINE)
205  {
206  TransformLineToQuad((const SAMPLE*)pSrc, byteStride, (Quad<SAMPLE>*)_pbyteOutput, pixelCount, _inverseTransform);
207  }
208 
209  if (_info.outputBgr)
210  {
211  TransformRgbToBgr(_pbyteOutput, _info.components, pixelCount);
212  }
213  _pbyteOutput += _info.bytesperline;
214  }
215 
216 
217 private:
218  BYTE* _pbyteOutput;
219  const JlsParameters& _info;
220  OFVector<SAMPLE> _templine;
221  TRANSFORM _transform;
222  typename TRANSFORM::INVERSE _inverseTransform;
223 };
224 
225 
226 
227 #endif


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