1 /* 2 * 3 * Copyright (C) 1996-2002, OFFIS 4 * 5 * This software and supporting documentation were developed by 6 * 7 * Kuratorium OFFIS e.V. 8 * Healthcare Information and Communication Systems 9 * Escherweg 2 10 * D-26121 Oldenburg, Germany 11 * 12 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 13 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 14 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 15 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 16 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 17 * 18 * Module: dcmimgle 19 * 20 * Author: Joerg Riesmeier 21 * 22 * Purpose: DicomMonochromeScaleTemplate (Header) 23 * 24 */ 25 26 27 #ifndef __DIMOSCT_H 28 #define __DIMOSCT_H 29 30 #include "osconfig.h" 31 #include "dctypes.h" 32 33 #include "dimopxt.h" 34 #include "discalet.h" 35 36 37 /*---------------------* 38 * class declaration * 39 *---------------------*/ 40 41 /** Template class to scale monochrome images (on pixel data level). 42 */ 43 template<class T> 44 class DiMonoScaleTemplate 45 : public DiMonoPixelTemplate<T>, 46 protected DiScaleTemplate<T> 47 { 48 public: 49 50 /** constructor 51 * 52 ** @param pixel pointer to intermediate pixel representation 53 * @param columns width of source image 54 * @param rows height of source image 55 * @param left_pos left coordinate of clipping area 56 * @param top_pos top coordinate of clipping area 57 * @param src_cols width of clipping area 58 * @param src_rows height of clipping area 59 * @param dest_cols width of destination image (scaled image) 60 * @param dest_rows height of destination image 61 * @param frames number of frames 62 * @param interpolate use of interpolation when scaling 63 * @param pvalue value possibly used for regions outside the image boundaries 64 */ DiMonoScaleTemplate(const DiMonoPixel * pixel,const Uint16 columns,const Uint16 rows,const signed long left_pos,const signed long top_pos,const Uint16 src_cols,const Uint16 src_rows,const Uint16 dest_cols,const Uint16 dest_rows,const Uint32 frames,const int interpolate,const Uint16 pvalue)65 DiMonoScaleTemplate(const DiMonoPixel *pixel, 66 const Uint16 columns, 67 const Uint16 rows, 68 const signed long left_pos, 69 const signed long top_pos, 70 const Uint16 src_cols, 71 const Uint16 src_rows, 72 const Uint16 dest_cols, 73 const Uint16 dest_rows, 74 const Uint32 frames, 75 const int interpolate, 76 const Uint16 pvalue) 77 : DiMonoPixelTemplate<T>(pixel, (unsigned long)dest_cols * (unsigned long)dest_rows * frames), 78 DiScaleTemplate<T>(1, columns, rows, left_pos, top_pos, src_cols, src_rows, dest_cols, dest_rows, frames) 79 { 80 if ((pixel != NULL) && (pixel->getCount() > 0)) 81 { 82 if (pixel->getCount() == (unsigned long)columns * (unsigned long)rows * frames) 83 { 84 scale((const T *)pixel->getData(), pixel->getBits(), interpolate, pvalue); 85 this->determineMinMax(); 86 } else { 87 if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings)) 88 { 89 ofConsole.lockCerr() << "WARNING: could not scale image ... corrupted data." << endl; 90 ofConsole.unlockCerr(); 91 } 92 } 93 } 94 } 95 96 /** destructor 97 */ ~DiMonoScaleTemplate()98 virtual ~DiMonoScaleTemplate() 99 { 100 } 101 102 103 private: 104 105 /** scale pixel data 106 * 107 ** @param pixel pointer to pixel data to be scaled 108 * @param bits bit depth of pixel data 109 * @param interpolate use of interpolation when scaling 110 * @param pvalue value possibly used for regions outside the image boundaries 111 */ scale(const T * pixel,const unsigned int bits,const int interpolate,const Uint16 pvalue)112 inline void scale(const T *pixel, 113 const unsigned int bits, 114 const int interpolate, 115 const Uint16 pvalue) 116 { 117 if (pixel != NULL) 118 { 119 this->Data = new T[this->getCount()]; 120 if (this->Data != NULL) 121 { 122 const T value = (T)((double)DicomImageClass::maxval(bits) * (double)pvalue / 123 (double)DicomImageClass::maxval(WIDTH_OF_PVALUES)); 124 DiScaleTemplate<T>::scaleData(&pixel, &this->Data, interpolate, value); 125 } 126 } 127 } 128 }; 129 130 131 #endif 132