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


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