1 /* 2 * 3 * Copyright (C) 1996-2016, 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: DicomPalettePixelTemplate (Header) 19 * 20 */ 21 22 23 #ifndef DIPALPXT_H 24 #define DIPALPXT_H 25 26 #include "dcmtk/config/osconfig.h" 27 28 #include "dcmtk/dcmimage/dicopxt.h" 29 #include "dcmtk/dcmimgle/diluptab.h" 30 #include "dcmtk/dcmimgle/diinpx.h" /* gcc 3.4 needs this */ 31 32 33 /*---------------------* 34 * class declaration * 35 *---------------------*/ 36 37 /** Template class to handle Palette color pixel data 38 */ 39 template<class T1, class T2, class T3> 40 class DiPalettePixelTemplate 41 : public DiColorPixelTemplate<T3> 42 { 43 44 public: 45 46 /** constructor 47 * 48 ** @param docu pointer to DICOM document 49 * @param pixel pointer to input pixel representation 50 * @param palette pointer to RGB color palette 51 * @param status reference to status variable 52 */ DiPalettePixelTemplate(const DiDocument * docu,const DiInputPixel * pixel,DiLookupTable * palette[3],EI_Status & status)53 DiPalettePixelTemplate(const DiDocument *docu, 54 const DiInputPixel *pixel, 55 DiLookupTable *palette[3], 56 EI_Status &status) 57 : DiColorPixelTemplate<T3>(docu, pixel, 1, status) 58 { 59 if ((pixel != NULL) && (this->Count > 0) && (status == EIS_Normal)) 60 { 61 if (this->PlanarConfiguration) 62 { 63 status = EIS_InvalidValue; 64 DCMIMAGE_ERROR("invalid value for 'PlanarConfiguration' (" << this->PlanarConfiguration << ")"); 65 } 66 else 67 convert(OFstatic_cast(const T1 *, pixel->getData()) + pixel->getPixelStart(), palette); 68 } 69 } 70 71 /** destructor 72 */ ~DiPalettePixelTemplate()73 virtual ~DiPalettePixelTemplate() 74 { 75 } 76 77 78 private: 79 80 /** convert input pixel data to intermediate representation 81 * 82 ** @param pixel pointer to input pixel data 83 * @param palette pointer to RGB color palette 84 */ convert(const T1 * pixel,DiLookupTable * palette[3])85 void convert(const T1 *pixel, 86 DiLookupTable *palette[3]) 87 { // can be optimized if necessary ! 88 if (this->Init(pixel)) 89 { 90 const T1 *p = pixel; 91 T2 value = 0; 92 unsigned long i; 93 int j; 94 // use the number of input pixels derived from the length of the 'PixelData' 95 // attribute), but not more than the size of the intermediate buffer 96 const unsigned long count = (this->InputCount < this->Count) ? this->InputCount : this->Count; 97 for (i = 0; i < count; ++i) 98 { 99 value = OFstatic_cast(T2, *(p++)); 100 for (j = 0; j < 3; ++j) 101 { 102 if (value <= palette[j]->getFirstEntry(value)) 103 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getFirstValue()); 104 else if (value >= palette[j]->getLastEntry(value)) 105 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getLastValue()); 106 else 107 this->Data[j][i] = OFstatic_cast(T3, palette[j]->getValue(value)); 108 } 109 } 110 } 111 } 112 }; 113 114 115 #endif 116