OFFIS DCMTK  Version 3.6.0
diyf2pxt.h
1 /*
2  *
3  * Copyright (C) 1998-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: DicomYBR422PixelTemplate (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 DIYF2PXT_H
31 #define DIYF2PXT_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 int bits,
64  const OFBool rgb)
65  : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2)
66  {
67  if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal))
68  {
69  if (this->PlanarConfiguration)
70  {
71  status = EIS_InvalidValue;
72  DCMIMAGE_ERROR("invalid value for 'PlanarConfiguration' (" << this->PlanarConfiguration << ")");
73  }
74  else
75  convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits, rgb);
76  }
77  }
78 
82  {
83  }
84 
85 
86  private:
87 
94  void convert(const T1 *pixel,
95  const int bits,
96  const OFBool rgb)
97  {
98  if (this->Init(pixel))
99  {
100  const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1));
101  register unsigned long i;
102  register const T1 *p = pixel;
103  register T2 *r = this->Data[0];
104  register T2 *g = this->Data[1];
105  register T2 *b = this->Data[2];
106  register T2 y1;
107  register T2 y2;
108  register T2 cb;
109  register T2 cr;
110  // use the number of input pixels derived from the length of the 'PixelData'
111  // attribute), but not more than the size of the intermediate buffer
112  const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count;
113  if (rgb) /* convert to RGB model */
114  {
115  const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits));
116  for (i = count / 2; i != 0; --i)
117  {
118  y1 = removeSign(*(p++), offset);
119  y2 = removeSign(*(p++), offset);
120  cb = removeSign(*(p++), offset);
121  cr = removeSign(*(p++), offset);
122  convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue);
123  convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue);
124  }
125  } else { /* retain YCbCr model: YCbCr_422_full -> YCbCr_full */
126  for (i = count / 2; i != 0; --i)
127  {
128  y1 = removeSign(*(p++), offset);
129  y2 = removeSign(*(p++), offset);
130  cb = removeSign(*(p++), offset);
131  cr = removeSign(*(p++), offset);
132  *(r++) = y1;
133  *(g++) = cb;
134  *(b++) = cr;
135  *(r++) = y2;
136  *(g++) = cb;
137  *(b++) = cr;
138  }
139  }
140  }
141  }
142 
145  inline void convertValue(T2 &red,
146  T2 &green,
147  T2 &blue,
148  const T2 y,
149  const T2 cb,
150  const T2 cr,
151  const T2 maxvalue)
152  {
153  double dr = OFstatic_cast(double, y) + 1.4020 * OFstatic_cast(double, cr) - 0.7010 * OFstatic_cast(double, maxvalue);
154  double dg = OFstatic_cast(double, y) - 0.3441 * OFstatic_cast(double, cb) - 0.7141 * OFstatic_cast(double, cr) + 0.5291 * OFstatic_cast(double, maxvalue);
155  double db = OFstatic_cast(double, y) + 1.7720 * OFstatic_cast(double, cb) - 0.8859 * OFstatic_cast(double, maxvalue);
156  red = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr);
157  green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg);
158  blue = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db);
159  }
160 };
161 
162 
163 #endif
164 
165 
166 /*
167  *
168  * CVS/RCS Log:
169  * $Log: diyf2pxt.h,v $
170  * Revision 1.26 2011-11-17 16:13:14 joergr
171  * Minor fixes to keep XCode 4.2 on Mac OS X Lion (clang compiler) quiet.
172  *
173  * Revision 1.25 2010-10-14 13:16:30 joergr
174  * Updated copyright header. Added reference to COPYRIGHT file.
175  *
176  * Revision 1.24 2010-03-01 09:08:46 uli
177  * Removed some unnecessary include directives in the headers.
178  *
179  * Revision 1.23 2009-11-25 14:31:21 joergr
180  * Removed inclusion of header file "ofconsol.h".
181  *
182  * Revision 1.22 2009-10-14 10:25:14 joergr
183  * Fixed minor issues in log output. Also updated copyright date (if required).
184  *
185  * Revision 1.21 2009-10-13 14:08:33 uli
186  * Switched to logging mechanism provided by the "new" oflog module
187  *
188  * Revision 1.20 2006-08-15 16:35:01 meichel
189  * Updated the code in module dcmimage to correctly compile when
190  * all standard C++ classes remain in namespace std.
191  *
192  * Revision 1.19 2005/12/08 16:02:03 meichel
193  * Changed include path schema for all DCMTK header files
194  *
195  * Revision 1.18 2004/04/21 10:00:31 meichel
196  * Minor modifications for compilation with gcc 3.4.0
197  *
198  * Revision 1.17 2003/12/23 12:33:01 joergr
199  * Adapted type casts to new-style typecast operators defined in ofcast.h.
200  * Removed leading underscore characters from preprocessor symbols (reserved
201  * symbols). Updated copyright header. Added missing API documentation.
202  * Replaced post-increment/decrement operators by pre-increment/decrement
203  * operators where appropriate (e.g. 'i++' by '++i').
204  *
205  * Revision 1.16 2002/06/26 16:20:53 joergr
206  * Enhanced handling of corrupted pixel data and/or length.
207  *
208  * Revision 1.15 2002/05/24 09:53:06 joergr
209  * Added missing #include "ofconsol.h".
210  *
211  * Revision 1.14 2001/11/09 16:47:03 joergr
212  * Removed 'inline' specifier from certain methods.
213  *
214  * Revision 1.13 2001/09/28 13:55:41 joergr
215  * Added new flag (CIF_KeepYCbCrColorModel) which avoids conversion of YCbCr
216  * color models to RGB.
217  *
218  * Revision 1.12 2001/06/01 15:49:33 meichel
219  * Updated copyright header
220  *
221  * Revision 1.11 2000/04/28 12:39:33 joergr
222  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
223  *
224  * Revision 1.10 2000/04/27 13:15:16 joergr
225  * Dcmimage library code now consistently uses ofConsole for error output.
226  *
227  * Revision 1.9 2000/03/08 16:21:54 meichel
228  * Updated copyright header.
229  *
230  * Revision 1.8 2000/03/03 14:07:52 meichel
231  * Implemented library support for redirecting error messages into memory
232  * instead of printing them to stdout/stderr for GUI applications.
233  *
234  * Revision 1.7 1999/09/17 14:03:47 joergr
235  * Enhanced efficiency of some "for" loops.
236  *
237  * Revision 1.6 1999/04/28 12:45:21 joergr
238  * Introduced new scheme for the debug level variable: now each level can be
239  * set separately (there is no "include" relationship).
240  *
241  * Revision 1.5 1999/02/03 16:55:29 joergr
242  * Moved global functions maxval() and determineRepresentation() to class
243  * DicomImageClass (as static methods).
244  *
245  * Revision 1.4 1999/01/20 14:48:01 joergr
246  * Replaced invocation of getCount() by member variable Count where possible.
247  *
248  * Revision 1.3 1998/11/27 14:21:48 joergr
249  * Added copyright message.
250  * Introduced global debug level for dcmimage module to control error output.
251  *
252  * Revision 1.2 1998/05/11 14:53:33 joergr
253  * Added CVS/RCS header to each file.
254  *
255  *
256  */


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