OFFIS DCMTK  Version 3.6.0
diargpxt.h
1 /*
2  *
3  * Copyright (C) 1996-2011, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmimage
15  *
16  * Author: Joerg Riesmeier
17  *
18  * Purpose: DicomARGBPixelTemplate (Header) - UNTESTED !!!
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2011-11-17 16:13:14 $
22  * CVS/RCS Revision: $Revision: 1.22 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIARGPXT_H
31 #define DIARGPXT_H
32 
33 #include "dcmtk/config/osconfig.h"
34 
35 #include "dcmtk/dcmimage/dicopxt.h"
36 #include "dcmtk/dcmimgle/diluptab.h"
37 #include "dcmtk/dcmimgle/diinpx.h" /* gcc 3.4 needs this */
38 
39 /*---------------------*
40  * class declaration *
41  *---------------------*/
42 
45 template<class T1, class T2, class T3>
47  : public DiColorPixelTemplate<T3>
48 {
49 
50  public:
51 
62  const DiInputPixel *pixel,
63  DiLookupTable *palette[3],
64  EI_Status &status,
65  const unsigned long planeSize,
66  const int bits)
67  : DiColorPixelTemplate<T3>(docu, pixel, 4, status)
68  {
69  if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
70  convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), palette, planeSize, bits);
71  }
72 
76  {
77  }
78 
79 
80  private:
81 
89  void convert(const T1 *pixel,
90  DiLookupTable *palette[3],
91  const unsigned long planeSize,
92  const int bits)
93  { // not very much optimized, but no one really uses ARGB !!
94  if (this->Init(pixel))
95  {
96  register T2 value;
97  const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
98  // use the number of input pixels derived from the length of the 'PixelData'
99  // attribute), but not more than the size of the intermediate buffer
100  const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
101  if (this->PlanarConfiguration)
102  {
103 /*
104  register const T1 *a = pixel; // points to alpha plane
105  const T1 *rgb[3];
106  rgb[0] = a + this->InputCount; // points to red plane
107  rgb[1] = rgb[0] + this->InputCount; // points to green plane
108  rgb[2] = rgb[1] + this->InputCount; // points to blue plane
109  for (i = 0; i < count; ++i)
110  {
111  value = OFstatic_cast(T2, *(a++)); // get alpha value
112  if (value > 0)
113  {
114  for (int j = 0; j < 3; ++j) // set palette color
115  {
116  if (value <= palette[j]->getFirstEntry(value))
117  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue());
118  else if (value >= palette[j]->getLastEntry(value))
119  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue());
120  else
121  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value));
122  ++rgb[j]; // skip RGB values
123  }
124  }
125  else
126  {
127  for (j = 0; j < 3; ++j) // copy RGB values
128  this->Data[j][i] = OFstatic_cast(T3, removeSign(*(rgb[j]++), offset));
129  }
130  }
131 */
132  register unsigned long l;
133  register unsigned long i = 0;
134  register const T1 *a = pixel; // points to alpha plane
135  const T1 *rgb[3];
136  rgb[0] = a + planeSize; // points to red plane
137  rgb[1] = rgb[0] + planeSize; // points to green plane
138  rgb[2] = rgb[1] + planeSize; // points to blue plane
139  while (i < count)
140  {
141  /* convert a single frame */
142  for (l = planeSize; (l != 0) && (i < count); --l, ++i)
143  {
144  value = OFstatic_cast(T2, *(a++)); // get alpha value
145  if (value > 0)
146  {
147  for (int j = 0; j < 3; ++j) // set palette color
148  {
149  if (value <= palette[j]->getFirstEntry(value))
150  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue());
151  else if (value >= palette[j]->getLastEntry(value))
152  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue());
153  else
154  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value));
155  ++rgb[j]; // skip RGB values
156  }
157  }
158  else
159  {
160  for (int j = 0; j < 3; ++j) // copy RGB values
161  this->Data[j][i] = OFstatic_cast(T3, removeSign(*(rgb[j]++), offset));
162  }
163  }
164  /* jump to next frame start (skip 2 planes) */
165  a += 2 * planeSize;
166  for (int j = 0; j < 3; ++j)
167  rgb[j] += 2 * planeSize;
168  }
169  } else {
170  register unsigned long i;
171  register const T1 *p = pixel;
172  for (i = 0; i < count; ++i)
173  {
174  value = OFstatic_cast(T2, *(p++)); // get alpha value
175  if (value > 0)
176  {
177  for (int j = 0; j < 3; ++j) // set palette color
178  {
179  if (value <= palette[j]->getFirstEntry(value))
180  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue());
181  else if (value >= palette[j]->getLastEntry(value))
182  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue());
183  else
184  this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value));
185  }
186  p += 3; // skip RGB values
187  }
188  else
189  {
190  for (int j = 0; j < 3; ++j) // copy RGB values
191  this->Data[j][i] = OFstatic_cast(T3, removeSign(*(p++), offset));
192  }
193  }
194  }
195  }
196  }
197 };
198 
199 
200 #endif
201 
202 
203 /*
204  *
205  * CVS/RCS Log:
206  * $Log: diargpxt.h,v $
207  * Revision 1.22 2011-11-17 16:13:14 joergr
208  * Minor fixes to keep XCode 4.2 on Mac OS X Lion (clang compiler) quiet.
209  *
210  * Revision 1.21 2010-10-14 13:16:29 joergr
211  * Updated copyright header. Added reference to COPYRIGHT file.
212  *
213  * Revision 1.20 2005/12/08 16:01:25 meichel
214  * Changed include path schema for all DCMTK header files
215  *
216  * Revision 1.19 2004/04/21 10:00:31 meichel
217  * Minor modifications for compilation with gcc 3.4.0
218  *
219  * Revision 1.18 2003/12/23 16:06:21 joergr
220  * Replaced additional post-increment/decrement operators by pre-increment/
221  * decrement operators.
222  *
223  * Revision 1.17 2003/12/23 12:38:51 joergr
224  * Replaced post-increment/decrement operators by pre-increment/decrement
225  * operators where appropriate (e.g. 'i++' by '++i').
226  *
227  * Revision 1.16 2003/12/23 11:15:07 joergr
228  * Adapted type casts to new-style typecast operators defined in ofcast.h.
229  * Removed leading underscore characters from preprocessor symbols (reserved
230  * symbols). Updated copyright header.
231  *
232  * Revision 1.15 2002/06/26 16:16:07 joergr
233  * Enhanced handling of corrupted pixel data and/or length.
234  * Corrected decoding of multi-frame, planar images.
235  *
236  * Revision 1.14 2001/11/09 16:39:37 joergr
237  * Removed 'inline' specifier from certain methods.
238  *
239  * Revision 1.13 2001/06/01 15:49:27 meichel
240  * Updated copyright header
241  *
242  * Revision 1.12 2000/04/27 13:15:12 joergr
243  * Dcmimage library code now consistently uses ofConsole for error output.
244  *
245  * Revision 1.11 2000/03/08 16:21:48 meichel
246  * Updated copyright header.
247  *
248  * Revision 1.10 1999/04/28 12:51:54 joergr
249  * Corrected some typos, comments and formatting.
250  *
251  * Revision 1.9 1999/02/03 16:47:54 joergr
252  * Moved global functions maxval() and determineRepresentation() to class
253  * DicomImageClass (as static methods).
254  *
255  * Revision 1.8 1999/01/20 14:36:22 joergr
256  * Replaced invocation of getCount() by member variable Count where possible.
257  *
258  * Revision 1.7 1998/12/14 17:08:43 joergr
259  * Added support for signed values as second entry in look-up tables
260  * (= first value mapped).
261  *
262  * Revision 1.6 1998/11/27 13:40:11 joergr
263  * Added copyright message.
264  *
265  * Revision 1.5 1998/07/01 08:39:18 joergr
266  * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
267  * options), e.g. add copy constructors.
268  *
269  * Revision 1.4 1998/05/11 14:53:08 joergr
270  * Added CVS/RCS header to each file.
271  *
272  *
273  */


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