00001 /* 00002 * 00003 * Copyright (C) 1998-2005, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: dcmimage 00019 * 00020 * Author: Joerg Riesmeier 00021 * 00022 * Purpose: DicomYBR422PixelTemplate (Header) 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:02:03 $ 00026 * CVS/RCS Revision: $Revision: 1.19 $ 00027 * Status: $State: Exp $ 00028 * 00029 * CVS/RCS Log at end of file 00030 * 00031 */ 00032 00033 00034 #ifndef DIYF2PXT_H 00035 #define DIYF2PXT_H 00036 00037 #include "dcmtk/config/osconfig.h" 00038 00039 #include "dcmtk/ofstd/ofconsol.h" 00040 #include "dcmtk/dcmimage/dicopxt.h" 00041 #include "dcmtk/dcmimgle/diinpx.h" /* gcc 3.4 needs this */ 00042 00043 00044 /*---------------------* 00045 * class declaration * 00046 *---------------------*/ 00047 00050 template<class T1, class T2> 00051 class DiYBR422PixelTemplate 00052 : public DiColorPixelTemplate<T2> 00053 { 00054 00055 public: 00056 00065 DiYBR422PixelTemplate(const DiDocument *docu, 00066 const DiInputPixel *pixel, 00067 EI_Status &status, 00068 const int bits, 00069 const OFBool rgb) 00070 : DiColorPixelTemplate<T2>(docu, pixel, 3, status, 2) 00071 { 00072 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal)) 00073 { 00074 if (this->PlanarConfiguration) 00075 { 00076 status = EIS_InvalidValue; 00077 if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Errors)) 00078 { 00079 ofConsole.lockCerr() << "ERROR: invalid value for 'PlanarConfiguration' (" 00080 << this->PlanarConfiguration << ") ! " << endl; 00081 ofConsole.unlockCerr(); 00082 } 00083 } 00084 else 00085 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), bits, rgb); 00086 } 00087 } 00088 00091 virtual ~DiYBR422PixelTemplate() 00092 { 00093 } 00094 00095 00096 private: 00097 00104 void convert(const T1 *pixel, 00105 const int bits, 00106 const OFBool rgb) 00107 { 00108 if (Init(pixel)) 00109 { 00110 const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1)); 00111 register unsigned long i; 00112 register const T1 *p = pixel; 00113 register T2 *r = this->Data[0]; 00114 register T2 *g = this->Data[1]; 00115 register T2 *b = this->Data[2]; 00116 register T2 y1; 00117 register T2 y2; 00118 register T2 cb; 00119 register T2 cr; 00120 // use the number of input pixels derived from the length of the 'PixelData' 00121 // attribute), but not more than the size of the intermediate buffer 00122 const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count; 00123 if (rgb) /* convert to RGB model */ 00124 { 00125 const T2 maxvalue = OFstatic_cast(T2, DicomImageClass::maxval(bits)); 00126 for (i = count / 2; i != 0; --i) 00127 { 00128 y1 = removeSign(*(p++), offset); 00129 y2 = removeSign(*(p++), offset); 00130 cb = removeSign(*(p++), offset); 00131 cr = removeSign(*(p++), offset); 00132 convertValue(*(r++), *(g++), *(b++), y1, cb, cr, maxvalue); 00133 convertValue(*(r++), *(g++), *(b++), y2, cb, cr, maxvalue); 00134 } 00135 } else { /* retain YCbCr model: YCbCr_422_full -> YCbCr_full */ 00136 for (i = count / 2; i != 0; --i) 00137 { 00138 y1 = removeSign(*(p++), offset); 00139 y2 = removeSign(*(p++), offset); 00140 cb = removeSign(*(p++), offset); 00141 cr = removeSign(*(p++), offset); 00142 *(r++) = y1; 00143 *(g++) = cb; 00144 *(b++) = cr; 00145 *(r++) = y2; 00146 *(g++) = cb; 00147 *(b++) = cr; 00148 } 00149 } 00150 } 00151 } 00152 00155 inline void convertValue(T2 &red, 00156 T2 &green, 00157 T2 &blue, 00158 const T2 y, 00159 const T2 cb, 00160 const T2 cr, 00161 const T2 maxvalue) 00162 { 00163 double dr = OFstatic_cast(double, y) + 1.4020 * OFstatic_cast(double, cr) - 0.7010 * OFstatic_cast(double, maxvalue); 00164 double dg = OFstatic_cast(double, y) - 0.3441 * OFstatic_cast(double, cb) - 0.7141 * OFstatic_cast(double, cr) + 0.5291 * OFstatic_cast(double, maxvalue); 00165 double db = OFstatic_cast(double, y) + 1.7720 * OFstatic_cast(double, cb) - 0.8859 * OFstatic_cast(double, maxvalue); 00166 red = (dr < 0.0) ? 0 : (dr > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dr); 00167 green = (dg < 0.0) ? 0 : (dg > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, dg); 00168 blue = (db < 0.0) ? 0 : (db > OFstatic_cast(double, maxvalue)) ? maxvalue : OFstatic_cast(T2, db); 00169 } 00170 }; 00171 00172 00173 #endif 00174 00175 00176 /* 00177 * 00178 * CVS/RCS Log: 00179 * $Log: diyf2pxt.h,v $ 00180 * Revision 1.19 2005/12/08 16:02:03 meichel 00181 * Changed include path schema for all DCMTK header files 00182 * 00183 * Revision 1.18 2004/04/21 10:00:31 meichel 00184 * Minor modifications for compilation with gcc 3.4.0 00185 * 00186 * Revision 1.17 2003/12/23 12:33:01 joergr 00187 * Adapted type casts to new-style typecast operators defined in ofcast.h. 00188 * Removed leading underscore characters from preprocessor symbols (reserved 00189 * symbols). Updated copyright header. Added missing API documentation. 00190 * Replaced post-increment/decrement operators by pre-increment/decrement 00191 * operators where appropriate (e.g. 'i++' by '++i'). 00192 * 00193 * Revision 1.16 2002/06/26 16:20:53 joergr 00194 * Enhanced handling of corrupted pixel data and/or length. 00195 * 00196 * Revision 1.15 2002/05/24 09:53:06 joergr 00197 * Added missing #include "ofconsol.h". 00198 * 00199 * Revision 1.14 2001/11/09 16:47:03 joergr 00200 * Removed 'inline' specifier from certain methods. 00201 * 00202 * Revision 1.13 2001/09/28 13:55:41 joergr 00203 * Added new flag (CIF_KeepYCbCrColorModel) which avoids conversion of YCbCr 00204 * color models to RGB. 00205 * 00206 * Revision 1.12 2001/06/01 15:49:33 meichel 00207 * Updated copyright header 00208 * 00209 * Revision 1.11 2000/04/28 12:39:33 joergr 00210 * DebugLevel - global for the module - now derived from OFGlobal (MF-safe). 00211 * 00212 * Revision 1.10 2000/04/27 13:15:16 joergr 00213 * Dcmimage library code now consistently uses ofConsole for error output. 00214 * 00215 * Revision 1.9 2000/03/08 16:21:54 meichel 00216 * Updated copyright header. 00217 * 00218 * Revision 1.8 2000/03/03 14:07:52 meichel 00219 * Implemented library support for redirecting error messages into memory 00220 * instead of printing them to stdout/stderr for GUI applications. 00221 * 00222 * Revision 1.7 1999/09/17 14:03:47 joergr 00223 * Enhanced efficiency of some "for" loops. 00224 * 00225 * Revision 1.6 1999/04/28 12:45:21 joergr 00226 * Introduced new scheme for the debug level variable: now each level can be 00227 * set separately (there is no "include" relationship). 00228 * 00229 * Revision 1.5 1999/02/03 16:55:29 joergr 00230 * Moved global functions maxval() and determineRepresentation() to class 00231 * DicomImageClass (as static methods). 00232 * 00233 * Revision 1.4 1999/01/20 14:48:01 joergr 00234 * Replaced invocation of getCount() by member variable Count where possible. 00235 * 00236 * Revision 1.3 1998/11/27 14:21:48 joergr 00237 * Added copyright message. 00238 * Introduced global debug level for dcmimage module to control error output. 00239 * 00240 * Revision 1.2 1998/05/11 14:53:33 joergr 00241 * Added CVS/RCS header to each file. 00242 * 00243 * 00244 */