1 /* 2 * 3 * Copyright (C) 1996-2001, 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: DicomBaseLUT (Header) 23 * 24 */ 25 26 27 #ifndef __DIBASLUT_H 28 #define __DIBASLUT_H 29 30 #include "osconfig.h" 31 #include "ofstring.h" 32 33 #include "diutils.h" 34 35 36 /*---------------------* 37 * macro definitions * 38 *---------------------*/ 39 40 #define MIN_TABLE_ENTRY_SIZE 8 41 #define MAX_TABLE_ENTRY_SIZE 16 42 #define MAX_TABLE_ENTRY_COUNT 65536 43 44 45 /*---------------------* 46 * class declaration * 47 *---------------------*/ 48 49 /** Base class to handle look-up tables 50 */ 51 class DiBaseLUT 52 { 53 public: 54 55 /** constructor 56 * 57 ** @param count number of LUT entries 58 * @param bits number of bits per entry 59 */ 60 DiBaseLUT(const Uint32 count = 0, 61 const Uint16 bits = 0); 62 63 /** destructor 64 */ 65 virtual ~DiBaseLUT(); 66 67 /** get number of LUT entries 68 * 69 ** @return number of LUT entries 70 */ getCount()71 inline Uint32 getCount() const 72 { 73 return Count; 74 } 75 76 /** get number of bits per entry 77 * 78 ** @return number of bits per entry 79 */ getBits()80 inline Uint16 getBits() const 81 { 82 return Bits; 83 } 84 85 /** get index of first LUT entry. 86 * First input value mapped (FIV) in LUT descriptor is US -> 16 bit unsigned. 87 * ... or the previous pixel transformation requires an unsigned LUT input value. 88 * 89 ** @param dummy (used to distinguish between signed and unsigned methods) 90 * 91 ** @return index of first LUT entry 92 */ 93 inline Uint32 getFirstEntry(const Uint32 = 0) const 94 { 95 return FirstEntry; 96 } 97 98 /** get index of first LUT entry. 99 * First input value mapped (FIV) in LUT descriptor is SS -> 16 bit signed. 100 * ... or the previous pixel transformation requires a signed LUT input value. 101 * 102 ** @param dummy (used to distinguish between signed and unsigned methods) 103 * 104 ** @return index of first LUT entry 105 */ getFirstEntry(const Sint32)106 inline Sint32 getFirstEntry(const Sint32) const 107 { 108 return (Sint16)FirstEntry; 109 } 110 111 /** get index of last LUT entry. 112 * FIV in LUT descriptor is US -> 16 bit unsigned. 113 * ... or the previous pixel transformation requires an unsigned LUT input value. 114 * 115 ** @param dummy (used to distinguish between signed and unsigned methods) 116 * 117 ** @return index of last LUT entry 118 */ 119 inline Uint32 getLastEntry(const Uint32 = 0) const 120 { 121 return FirstEntry + Count - 1; 122 } 123 124 /** get index of last LUT entry. 125 * FIV in LUT descriptor is SS -> 16 bit signed. 126 * ... or the previous pixel transformation requires a signed LUT input value. 127 * 128 ** @param dummy (used to distinguish between signed and unsigned methods) 129 * 130 ** @return index of first LUT entry 131 */ getLastEntry(const Sint32)132 inline Sint32 getLastEntry(const Sint32) const 133 { 134 return (Sint32)((Sint16)FirstEntry) + Count - 1; 135 } 136 137 /** get value of specified LUT entry 138 * 139 ** @param pos position in the LUT to be returned 140 * 141 ** @return value of specified LUT entry 142 */ getValue(const Uint16 pos)143 inline Uint16 getValue(const Uint16 pos) const 144 { 145 return Data[pos]; 146 } 147 148 /** get value of specified LUT entry. 149 * FIV in LUT descriptor is US -> 16 bit unsigned. 150 * ... or the previous pixel transformation requires an unsigned LUT input value. 151 * 152 ** @param pos position in the LUT to be returned 153 * 154 ** @return value of specified LUT entry 155 */ getValue(const Uint32 pos)156 inline Uint16 getValue(const Uint32 pos) const 157 { 158 return Data[pos - FirstEntry]; 159 } 160 161 /** get value of specified LUT entry. 162 * FIV in LUT descriptor is SS -> 16 bit signed. 163 * ... or the previous pixel transformation requires a signed LUT input value. 164 * 165 ** @param pos position in the LUT to be returned 166 * 167 ** @return value of specified LUT entry 168 */ getValue(const Sint32 pos)169 inline Uint16 getValue(const Sint32 pos) const 170 { 171 return Data[pos - (Sint32)((Sint16)FirstEntry)]; 172 } 173 174 /** get value of first LUT entry. 175 * 176 ** @return value of first LUT entry 177 */ getFirstValue()178 inline Uint16 getFirstValue() const 179 { 180 return Data[0]; 181 } 182 183 /** get value of last LUT entry. 184 * 185 ** @return value of last LUT entry 186 */ getLastValue()187 inline Uint16 getLastValue() const 188 { 189 return Data[Count - 1]; 190 } 191 192 /** get pointer to LUT data 193 * 194 ** @return pointer to LUT data 195 */ getData()196 inline const Uint16 *getData() const 197 { 198 return Data; 199 } 200 201 /** get minimum value of the LUT. 202 * 203 ** @return minimum value of the LUT 204 */ getMinValue()205 inline Uint16 getMinValue() const 206 { 207 return MinValue; 208 } 209 210 /** get maximum value of the LUT. 211 * 212 ** @return maximum value of the LUT 213 */ getMaxValue()214 inline Uint16 getMaxValue() const 215 { 216 return MaxValue; 217 } 218 219 /** get absolute value range of the LUT entries. 220 * The maximum value which could be stored with the specified bit depth is calculated. 221 * 222 ** @return absolute range of LUT entries 223 */ getAbsMaxRange()224 inline Uint32 getAbsMaxRange() const 225 { 226 return DicomImageClass::maxval(Bits, 0); 227 } 228 229 /** check whether LUT is valid 230 * 231 ** @return status, true if valid, false otherwise 232 */ isValid()233 inline int isValid() const 234 { 235 return Valid; 236 } 237 238 /** get LUT explanation string 239 * 240 ** @return LUT explanation string if successful, NULL otherwise 241 */ getExplanation()242 inline const char *getExplanation() const 243 { 244 return (Explanation.empty()) ? (const char *)NULL : Explanation.c_str(); 245 } 246 247 /** compares current LUT with specified LUT 248 * 249 ** @param lut LUT to be compared with the current one 250 * 251 ** @return OFTrue if LUTs are equal, OFFalse otherwise 252 */ 253 virtual OFBool operator==(const DiBaseLUT &lut); 254 255 256 protected: 257 258 /** constructor 259 * 260 ** @param buffer pointer to array with LUT entries 261 * @param count number of LUT entries 262 * @param bits number of bits per entry 263 */ 264 DiBaseLUT(Uint16 *buffer, 265 const Uint32 count = 0, 266 const Uint16 bits = 0); 267 268 /** compares current LUT with specified LUT 269 * 270 ** @param lut LUT to be compared with the current one 271 * 272 ** @return true if LUTs are not equal (1 = invalid LUT, 273 * 2 = descriptor differs, 274 * 3 = data differs) 275 * false (0) otherwise 276 */ 277 int compare(const DiBaseLUT *lut); 278 279 /// number of LUT entries 280 Uint32 Count; 281 /// first input value mapped (FIV) 282 Uint16 FirstEntry; 283 /// number of bits per entry 284 Uint16 Bits; 285 286 /// minimum LUT value 287 Uint16 MinValue; 288 /// maximum LUT value 289 Uint16 MaxValue; 290 291 /// status code, indicating whether LUT is valid 292 int Valid; 293 294 /// LUT explanation string 295 OFString Explanation; 296 297 /// pointer to lookup table data 298 const Uint16 *Data; 299 /// pointer to data buffer (will be deleted in the destructor) 300 Uint16 *DataBuffer; 301 302 303 private: 304 305 // --- declarations to avoid compiler warnings 306 307 DiBaseLUT(const DiBaseLUT &); 308 DiBaseLUT &operator=(const DiBaseLUT &); 309 }; 310 311 312 #endif 313