00001 /* 00002 * 00003 * Copyright (C) 1996-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmimage 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: DicomARGBPixelTemplate (Header) - UNTESTED !!! 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:16:29 $ 00022 * CVS/RCS Revision: $Revision: 1.21 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 00030 #ifndef DIARGPXT_H 00031 #define DIARGPXT_H 00032 00033 #include "dcmtk/config/osconfig.h" 00034 00035 #include "dcmtk/dcmimage/dicopxt.h" 00036 #include "dcmtk/dcmimgle/diluptab.h" 00037 #include "dcmtk/dcmimgle/diinpx.h" /* gcc 3.4 needs this */ 00038 00039 /*---------------------* 00040 * class declaration * 00041 *---------------------*/ 00042 00045 template<class T1, class T2, class T3> 00046 class DiARGBPixelTemplate 00047 : public DiColorPixelTemplate<T3> 00048 { 00049 00050 public: 00051 00061 DiARGBPixelTemplate(const DiDocument *docu, 00062 const DiInputPixel *pixel, 00063 DiLookupTable *palette[3], 00064 EI_Status &status, 00065 const unsigned long planeSize, 00066 const int bits) 00067 : DiColorPixelTemplate<T3>(docu, pixel, 4, status) 00068 { 00069 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal)) 00070 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), palette, planeSize, bits); 00071 } 00072 00075 virtual ~DiARGBPixelTemplate() 00076 { 00077 } 00078 00079 00080 private: 00081 00089 void convert(const T1 *pixel, 00090 DiLookupTable *palette[3], 00091 const unsigned long planeSize, 00092 const int bits) 00093 { // not very much optimized, but no one really uses ARGB !! 00094 if (Init(pixel)) 00095 { 00096 register T2 value; 00097 const T1 offset = OFstatic_cast(T1, DicomImageClass::maxval(bits - 1)); 00098 // use the number of input pixels derived from the length of the 'PixelData' 00099 // attribute), but not more than the size of the intermediate buffer 00100 const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count; 00101 if (this->PlanarConfiguration) 00102 { 00103 /* 00104 register const T1 *a = pixel; // points to alpha plane 00105 const T1 *rgb[3]; 00106 rgb[0] = a + this->InputCount; // points to red plane 00107 rgb[1] = rgb[0] + this->InputCount; // points to green plane 00108 rgb[2] = rgb[1] + this->InputCount; // points to blue plane 00109 for (i = 0; i < count; ++i) 00110 { 00111 value = OFstatic_cast(T2, *(a++)); // get alpha value 00112 if (value > 0) 00113 { 00114 for (int j = 0; j < 3; ++j) // set palette color 00115 { 00116 if (value <= palette[j]->getFirstEntry(value)) 00117 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue()); 00118 else if (value >= palette[j]->getLastEntry(value)) 00119 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue()); 00120 else 00121 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value)); 00122 ++rgb[j]; // skip RGB values 00123 } 00124 } 00125 else 00126 { 00127 for (j = 0; j < 3; ++j) // copy RGB values 00128 this->Data[j][i] = OFstatic_cast(T3, removeSign(*(rgb[j]++), offset)); 00129 } 00130 } 00131 */ 00132 register unsigned long l; 00133 register unsigned long i = 0; 00134 register const T1 *a = pixel; // points to alpha plane 00135 const T1 *rgb[3]; 00136 rgb[0] = a + planeSize; // points to red plane 00137 rgb[1] = rgb[0] + planeSize; // points to green plane 00138 rgb[2] = rgb[1] + planeSize; // points to blue plane 00139 while (i < count) 00140 { 00141 /* convert a single frame */ 00142 for (l = planeSize; (l != 0) && (i < count); --l, ++i) 00143 { 00144 value = OFstatic_cast(T2, *(a++)); // get alpha value 00145 if (value > 0) 00146 { 00147 for (int j = 0; j < 3; ++j) // set palette color 00148 { 00149 if (value <= palette[j]->getFirstEntry(value)) 00150 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue()); 00151 else if (value >= palette[j]->getLastEntry(value)) 00152 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue()); 00153 else 00154 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value)); 00155 ++rgb[j]; // skip RGB values 00156 } 00157 } 00158 else 00159 { 00160 for (int j = 0; j < 3; ++j) // copy RGB values 00161 this->Data[j][i] = OFstatic_cast(T3, removeSign(*(rgb[j]++), offset)); 00162 } 00163 } 00164 /* jump to next frame start (skip 2 planes) */ 00165 a += 2 * planeSize; 00166 for (int j = 0; j < 3; ++j) 00167 rgb[j] += 2 * planeSize; 00168 } 00169 } else { 00170 register unsigned long i; 00171 register const T1 *p = pixel; 00172 for (i = 0; i < count; ++i) 00173 { 00174 value = OFstatic_cast(T2, *(p++)); // get alpha value 00175 if (value > 0) 00176 { 00177 for (int j = 0; j < 3; ++j) // set palette color 00178 { 00179 if (value <= palette[j]->getFirstEntry(value)) 00180 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue()); 00181 else if (value >= palette[j]->getLastEntry(value)) 00182 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue()); 00183 else 00184 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value)); 00185 } 00186 p += 3; // skip RGB values 00187 } 00188 else 00189 { 00190 for (int j = 0; j < 3; ++j) // copy RGB values 00191 this->Data[j][i] = OFstatic_cast(T3, removeSign(*(p++), offset)); 00192 } 00193 } 00194 } 00195 } 00196 } 00197 }; 00198 00199 00200 #endif 00201 00202 00203 /* 00204 * 00205 * CVS/RCS Log: 00206 * $Log: diargpxt.h,v $ 00207 * Revision 1.21 2010-10-14 13:16:29 joergr 00208 * Updated copyright header. Added reference to COPYRIGHT file. 00209 * 00210 * Revision 1.20 2005/12/08 16:01:25 meichel 00211 * Changed include path schema for all DCMTK header files 00212 * 00213 * Revision 1.19 2004/04/21 10:00:31 meichel 00214 * Minor modifications for compilation with gcc 3.4.0 00215 * 00216 * Revision 1.18 2003/12/23 16:06:21 joergr 00217 * Replaced additional post-increment/decrement operators by pre-increment/ 00218 * decrement operators. 00219 * 00220 * Revision 1.17 2003/12/23 12:38:51 joergr 00221 * Replaced post-increment/decrement operators by pre-increment/decrement 00222 * operators where appropriate (e.g. 'i++' by '++i'). 00223 * 00224 * Revision 1.16 2003/12/23 11:15:07 joergr 00225 * Adapted type casts to new-style typecast operators defined in ofcast.h. 00226 * Removed leading underscore characters from preprocessor symbols (reserved 00227 * symbols). Updated copyright header. 00228 * 00229 * Revision 1.15 2002/06/26 16:16:07 joergr 00230 * Enhanced handling of corrupted pixel data and/or length. 00231 * Corrected decoding of multi-frame, planar images. 00232 * 00233 * Revision 1.14 2001/11/09 16:39:37 joergr 00234 * Removed 'inline' specifier from certain methods. 00235 * 00236 * Revision 1.13 2001/06/01 15:49:27 meichel 00237 * Updated copyright header 00238 * 00239 * Revision 1.12 2000/04/27 13:15:12 joergr 00240 * Dcmimage library code now consistently uses ofConsole for error output. 00241 * 00242 * Revision 1.11 2000/03/08 16:21:48 meichel 00243 * Updated copyright header. 00244 * 00245 * Revision 1.10 1999/04/28 12:51:54 joergr 00246 * Corrected some typos, comments and formatting. 00247 * 00248 * Revision 1.9 1999/02/03 16:47:54 joergr 00249 * Moved global functions maxval() and determineRepresentation() to class 00250 * DicomImageClass (as static methods). 00251 * 00252 * Revision 1.8 1999/01/20 14:36:22 joergr 00253 * Replaced invocation of getCount() by member variable Count where possible. 00254 * 00255 * Revision 1.7 1998/12/14 17:08:43 joergr 00256 * Added support for signed values as second entry in look-up tables 00257 * (= first value mapped). 00258 * 00259 * Revision 1.6 1998/11/27 13:40:11 joergr 00260 * Added copyright message. 00261 * 00262 * Revision 1.5 1998/07/01 08:39:18 joergr 00263 * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional 00264 * options), e.g. add copy constructors. 00265 * 00266 * Revision 1.4 1998/05/11 14:53:08 joergr 00267 * Added CVS/RCS header to each file. 00268 * 00269 * 00270 */