OFFIS DCMTK  Version 3.6.0
dihsvpxt.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: DicomHSVPixelTemplate (Header)
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2011-11-17 16:13:14 $
22  * CVS/RCS Revision: $Revision: 1.26 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIHSVPXT_H
31 #define DIHSVPXT_H
32 
33 #include "dcmtk/config/osconfig.h"
34 
35 #include "dcmtk/dcmimage/dicopxt.h"
36 #include "dcmtk/dcmimgle/diinpx.h" /* gcc 3.4 needs this */
37 
38 
39 /*---------------------*
40  * class declaration *
41  *---------------------*/
42 
45 template<class T1, class T2>
47  : public DiColorPixelTemplate<T2>
48 {
49 
50  public:
51 
61  const DiInputPixel *pixel,
62  EI_Status &status,
63  const unsigned long planeSize,
64  const int bits)
65  : DiColorPixelTemplate<T2>(docu, pixel, 3, status)
66  {
67  if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
68  convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), planeSize, bits);
69  }
70 
74  {
75  }
76 
77 
78  private:
79 
86  void convert(const T1 *pixel,
87  const unsigned long planeSize,
88  const int bits)
89  {
90  if (this->Init(pixel))
91  {
92  register T2 *r = this->Data[0];
93  register T2 *g = this->Data[1];
94  register T2 *b = this->Data[2];
95  const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
96  const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
97  // use the number of input pixels derived from the length of the 'PixelData'
98  // attribute), but not more than the size of the intermediate buffer
99  const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
100  if (this->PlanarConfiguration)
101  {
102 /*
103  register const T1 *h = pixel;
104  register const T1 *s = h + this->InputCount;
105  register const T1 *v = s + this->InputCount;
106  for (i = count; i != 0; --i)
107  convertValue(*(r++), *(g++), *(b++), removeSign(*(h++), offset), removeSign(*(s++), offset),
108  removeSign(*(v++), offset), maxvalue);
109 */
110  register unsigned long l;
111  register unsigned long i = count;
112  register const T1 *h = pixel;
113  register const T1 *s = h + planeSize;
114  register const T1 *v = s + planeSize;
115  while (i != 0)
116  {
117  /* convert a single frame */
118  for (l = planeSize; (l != 0) && (i != 0); --l, --i)
119  {
120  convertValue(*(r++), *(g++), *(b++), removeSign(*(h++), offset), removeSign(*(s++), offset),
121  removeSign(*(v++), offset), maxvalue);
122  }
123  /* jump to next frame start (skip 2 planes) */
124  h += 2 * planeSize;
125  s += 2 * planeSize;
126  v += 2 * planeSize;
127  }
128  }
129  else
130  {
131  register const T1 *p = pixel;
132  register T2 h;
133  register T2 s;
134  register T2 v;
135  register unsigned long i;
136  for (i = count; i != 0; --i)
137  {
138  h = removeSign(*(p++), offset);
139  s = removeSign(*(p++), offset);
140  v = removeSign(*(p++), offset);
141  convertValue(*(r++), *(g++), *(b++), h, s, v, maxvalue);
142  }
143  }
144  }
145  }
146 
149  void convertValue(T2 &red,
150  T2 &green,
151  T2 &blue,
152  const T2 hue,
153  const T2 saturation,
154  const T2 value,
155  const T2 maxvalue)
156  {
157  /*
158  * conversion algorithm taken from Foley et al.: 'Computer Graphics: Principles and Practice' (1990)
159  */
160 
161  if (saturation == 0)
162  {
163  red = value;
164  green = value;
165  blue = value;
166  }
167  else
168  {
169  const double h = (OFstatic_cast(double, hue) * 6) / (OFstatic_cast(double, maxvalue) + 1); // '... + 1' to assert h < 6
170  const double s = OFstatic_cast(double, saturation) / OFstatic_cast(double, maxvalue);
171  const double v = OFstatic_cast(double, value) / OFstatic_cast(double, maxvalue);
172  const T2 hi = OFstatic_cast(T2, h);
173  const double hf = h - hi;
174  const T2 p = OFstatic_cast(T2, maxvalue * v * (1 - s));
175  const T2 q = OFstatic_cast(T2, maxvalue * v * (1 - s * hf));
176  const T2 t = OFstatic_cast(T2, maxvalue * v * (1 - s * (1 - hf)));
177  switch (hi)
178  {
179  case 0:
180  red = value;
181  green = t;
182  blue = p;
183  break;
184  case 1:
185  red = q;
186  green = value;
187  blue = p;
188  break;
189  case 2:
190  red = p;
191  green = value;
192  blue = t;
193  break;
194  case 3:
195  red = p;
196  green = q;
197  blue = value;
198  break;
199  case 4:
200  red = t;
201  green = p;
202  blue = value;
203  break;
204  case 5:
205  red = value;
206  green = p;
207  blue = q;
208  break;
209  default:
210  DCMIMAGE_WARN("invalid value for 'hi' while converting HSV to RGB");
211  }
212  }
213  }
214 };
215 
216 
217 #endif
218 
219 
220 /*
221  *
222  * CVS/RCS Log:
223  * $Log: dihsvpxt.h,v $
224  * Revision 1.26 2011-11-17 16:13:14 joergr
225  * Minor fixes to keep XCode 4.2 on Mac OS X Lion (clang compiler) quiet.
226  *
227  * Revision 1.25 2010-10-14 13:16:29 joergr
228  * Updated copyright header. Added reference to COPYRIGHT file.
229  *
230  * Revision 1.24 2010-03-01 09:08:46 uli
231  * Removed some unnecessary include directives in the headers.
232  *
233  * Revision 1.23 2009-11-25 14:31:21 joergr
234  * Removed inclusion of header file "ofconsol.h".
235  *
236  * Revision 1.22 2009-10-14 10:25:14 joergr
237  * Fixed minor issues in log output. Also updated copyright date (if required).
238  *
239  * Revision 1.21 2009-10-13 14:08:33 uli
240  * Switched to logging mechanism provided by the "new" oflog module
241  *
242  * Revision 1.20 2006-08-15 16:35:01 meichel
243  * Updated the code in module dcmimage to correctly compile when
244  * all standard C++ classes remain in namespace std.
245  *
246  * Revision 1.19 2005/12/08 16:01:39 meichel
247  * Changed include path schema for all DCMTK header files
248  *
249  * Revision 1.18 2004/04/21 10:00:31 meichel
250  * Minor modifications for compilation with gcc 3.4.0
251  *
252  * Revision 1.17 2003/12/23 11:48:23 joergr
253  * Adapted type casts to new-style typecast operators defined in ofcast.h.
254  * Removed leading underscore characters from preprocessor symbols (reserved
255  * symbols). Updated copyright header.
256  * Replaced post-increment/decrement operators by pre-increment/decrement
257  * operators where appropriate (e.g. 'i++' by '++i').
258  *
259  * Revision 1.16 2002/06/26 16:18:10 joergr
260  * Enhanced handling of corrupted pixel data and/or length.
261  * Corrected decoding of multi-frame, planar images.
262  *
263  * Revision 1.15 2001/11/09 16:47:01 joergr
264  * Removed 'inline' specifier from certain methods.
265  *
266  * Revision 1.14 2001/06/01 15:49:30 meichel
267  * Updated copyright header
268  *
269  * Revision 1.13 2000/04/28 12:39:32 joergr
270  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
271  *
272  * Revision 1.12 2000/04/27 13:15:13 joergr
273  * Dcmimage library code now consistently uses ofConsole for error output.
274  *
275  * Revision 1.11 2000/03/08 16:21:52 meichel
276  * Updated copyright header.
277  *
278  * Revision 1.10 2000/03/03 14:07:52 meichel
279  * Implemented library support for redirecting error messages into memory
280  * instead of printing them to stdout/stderr for GUI applications.
281  *
282  * Revision 1.9 1999/09/17 14:03:45 joergr
283  * Enhanced efficiency of some "for" loops.
284  *
285  * Revision 1.8 1999/04/28 12:47:04 joergr
286  * Introduced new scheme for the debug level variable: now each level can be
287  * set separately (there is no "include" relationship).
288  *
289  * Revision 1.7 1999/02/03 16:54:27 joergr
290  * Moved global functions maxval() and determineRepresentation() to class
291  * DicomImageClass (as static methods).
292  *
293  * Revision 1.6 1999/01/20 14:46:15 joergr
294  * Replaced invocation of getCount() by member variable Count where possible.
295  *
296  * Revision 1.5 1998/11/27 13:51:50 joergr
297  * Added copyright message.
298  *
299  * Revision 1.4 1998/05/11 14:53:16 joergr
300  * Added CVS/RCS header to each file.
301  *
302  *
303  */


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