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