1 /* 2 * 3 * Copyright (C) 1997-2018, 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: dcmjpeg 15 * 16 * Author: Norbert Olges, Marco Eichelberg 17 * 18 * Purpose: codec parameter class for dcmjpeg codecs 19 * 20 */ 21 22 #ifndef DJCPARAM_H 23 #define DJCPARAM_H 24 25 #include "dcmtk/config/osconfig.h" 26 #include "dcmtk/dcmdata/dccodec.h" /* for DcmCodecParameter */ 27 #include "dcmtk/dcmjpeg/djutils.h" /* for enums */ 28 29 /** codec parameter for IJG codecs 30 */ 31 class DCMTK_DCMJPEG_EXPORT DJCodecParameter: public DcmCodecParameter 32 { 33 public: 34 35 /** constructor. 36 * @param pCompressionCSConversion color conversion mode for compression 37 * @param pDecompressionCSConversion color conversion mode for decompression 38 * @param pCreateSOPInstanceUID mode for SOP Instance UID creation 39 * @param pPlanarConfiguration flag describing how planar configuration of 40 * decompressed color images should be handled 41 * @param predictor6WorkaroundEnable enable workaround for buggy lossless compressed images with 42 * overflow in predictor 6 for images with 16 bits/pixel 43 * @param cornellWorkaroundEnable enable workaround for buggy Cornell lossless compressed images with 44 * Huffman table overflow 45 * @param pForceSingleFragmentPerFrame while decompressing a multiframe image, 46 * assume one fragment per frame even if the JPEG data for some frame is incomplete 47 * @param pOptimizeHuffman perform huffman table optimization for 8 bits/pixel compression? 48 * @param pSmoothingFactor smoothing factor for image compression, 0..100 49 * @param pForcedBitDepth forced bit depth for image compression, 0 (auto) or 8/12/16 50 * @param pFragmentSize maximum fragment size (in kbytes) for compression, 0 for unlimited. 51 * @param pCreateOffsetTable create offset table during image compression? 52 * @param pSampleFactors subsampling mode for color image compression 53 * @param pWriteYBR422 flag indicating whether a compressed YBR color stream should 54 * be marked as YBR_FULL or YBR_FULL_422 on DICOM level 55 * @param pConvertToSC flag indicating whether image should be converted to 56 * Secondary Capture upon compression 57 * @param pWindowType mode for VOI transformation of monochrome images 58 * @param pWindowParameter parameter for VOI transform of monochrome images, used in modes 1, 2, 4, 6 59 * @param pVoiCenter VOI window center for mode 5 60 * @param pVoiWidth VOI window width for mode 5 61 * @param pRoiLeft Region of Interest left corner for for VOI transform of monochrome images, mode 7 62 * @param pRoiTop Region of Interest upper corner for for VOI transform of monochrome images, mode 7 63 * @param pRoiWidth Region of Interest width for for VOI transform of monochrome images, mode 7 64 * @param pRoiHeight Region of Interest height for for VOI transform of monochrome images, mode 7 65 * @param pUsePixelValues check smallest and largest pixel value and optimize compression, mode 0 only 66 * @param pUseModalityRescale create Rescale Slope/Intercept to scale back to original pixel range, mode 0 only 67 * @param pAcceptWrongPaletteTags accept wrong palette attribute tags (only "pseudo lossless" encoder) 68 * @param pAcrNemaCompatibility accept old ACR-NEMA images without photometric interpretation 69 * (only "pseudo" lossless encoder) 70 * @param pTrueLosslessMode Enables true lossless compression (replaces old "pseudo lossless" encoder) 71 */ 72 DJCodecParameter( 73 E_CompressionColorSpaceConversion pCompressionCSConversion, 74 E_DecompressionColorSpaceConversion pDecompressionCSConversion, 75 E_UIDCreation pCreateSOPInstanceUID, 76 E_PlanarConfiguration pPlanarConfiguration, 77 OFBool predictor6WorkaroundEnable = OFFalse, 78 OFBool cornellWorkaroundEnable = OFFalse, 79 OFBool pForceSingleFragmentPerFrame = OFFalse, 80 OFBool pOptimizeHuffman = OFFalse, 81 int pSmoothingFactor = 0, 82 int pForcedBitDepth = 0, 83 Uint32 pFragmentSize = 0, 84 OFBool pCreateOffsetTable = OFTrue, 85 E_SubSampling pSampleFactors = ESS_444, 86 OFBool pWriteYBR422 = OFFalse, 87 OFBool pConvertToSC = OFFalse, 88 size_t pWindowType = 0, 89 size_t pWindowParameter = 0, 90 double pVoiCenter = 0.0, 91 double pVoiWidth = 0.0, 92 size_t pRoiLeft = 0, 93 size_t pRoiTop = 0, 94 size_t pRoiWidth = 0, 95 size_t pRoiHeight = 0, 96 OFBool pUsePixelValues = OFTrue, 97 OFBool pUseModalityRescale = OFFalse, 98 OFBool pAcceptWrongPaletteTags = OFFalse, 99 OFBool pAcrNemaCompatibility = OFFalse, 100 OFBool pTrueLosslessMode = OFTrue); 101 102 /// copy constructor 103 DJCodecParameter(const DJCodecParameter& arg); 104 105 /// destructor 106 virtual ~DJCodecParameter(); 107 108 /** this methods creates a copy of type DcmCodecParameter * 109 * it must be overweritten in every subclass. 110 * @return copy of this object 111 */ 112 virtual DcmCodecParameter *clone() const; 113 114 /** returns the class name as string. 115 * can be used as poor man's RTTI replacement. 116 */ 117 virtual const char *className() const; 118 119 /** returns huffman table optimization flag for 8 bits/pixel compression 120 * @return huffman table optimization flag for 8 bits/pixel compression 121 */ getOptimizeHuffmanCoding()122 OFBool getOptimizeHuffmanCoding() const 123 { 124 return optimizeHuffman; 125 } 126 127 /** returns smoothing factor for image compression, 0..100 128 * @return smoothing factor for image compression, 0..100 129 */ getSmoothingFactor()130 int getSmoothingFactor() const 131 { 132 return smoothingFactor; 133 } 134 135 /** returns forced bit depth for image compression, 0 (auto) or 8/12/16 136 * @return forced bit depth for image compression 137 */ getForcedBitDepth()138 int getForcedBitDepth() const 139 { 140 return forcedBitDepth; 141 } 142 143 /** returns maximum fragment size (in kbytes) for compression, 0 for unlimited. 144 * @returnmaximum fragment size for compression 145 */ getFragmentSize()146 Uint32 getFragmentSize() const 147 { 148 return fragmentSize; 149 } 150 151 /** returns offset table creation flag 152 * @return offset table creation flag 153 */ getCreateOffsetTable()154 OFBool getCreateOffsetTable() const 155 { 156 return createOffsetTable; 157 } 158 159 /** returns subsampling mode for color image compression 160 * @return subsampling mode for color image compression 161 */ getSampleFactors()162 E_SubSampling getSampleFactors() const 163 { 164 return sampleFactors; 165 } 166 167 /** returns flag indicating whether a compressed YBR color stream should be marked 168 * as YBR_FULL or YBR_FULL_422 on DICOM level 169 * @return YBR422 flag 170 */ getWriteYBR422()171 OFBool getWriteYBR422() const 172 { 173 return writeYBR422; 174 } 175 176 /** returns secondary capture conversion flag 177 * @return secondary capture conversion flag 178 */ getConvertToSC()179 OFBool getConvertToSC() const 180 { 181 return convertToSC; 182 } 183 184 /** returns mode for SOP Instance UID creation 185 * @return mode for SOP Instance UID creation 186 */ getUIDCreation()187 E_UIDCreation getUIDCreation() const 188 { 189 return uidCreation; 190 } 191 192 /** returns mode for VOI transformation of monochrome images. 193 * @return mode for VOI transformation of monochrome images 194 */ getWindowType()195 size_t getWindowType() const 196 { 197 return windowType; 198 } 199 200 /** returns parameter for VOI transform of monochrome images, used in VOI modes 1, 2, 4, 6 201 * @return parameter for VOI transform of monochrome images, used in VOI modes 1, 2, 4, 6 202 */ getWindowParameter()203 size_t getWindowParameter() const 204 { 205 return windowParameter; 206 } 207 208 /** returns VOI window center and width for VOI mode 5 209 * @param center VOI center returned in this parameter 210 * @param width VOI width returned in this parameter 211 */ getVOIWindow(double & center,double & width)212 void getVOIWindow(double& center, double& width) const 213 { 214 center = voiCenter; 215 width = voiWidth; 216 } 217 218 /** returns ROI coordinates for VOI mode 7 219 * @param left_pos ROI left edge returned in this parameter 220 * @param top_pos ROI top edge returned in this parameter 221 * @param width ROI width returned in this parameter 222 * @param height ROI height returned in this parameter 223 */ getROI(size_t & left_pos,size_t & top_pos,size_t & width,size_t & height)224 void getROI( 225 size_t& left_pos, 226 size_t& top_pos, 227 size_t& width, 228 size_t& height) const 229 { 230 left_pos = roiLeft; 231 top_pos = roiTop; 232 width = roiWidth; 233 height = roiHeight; 234 } 235 236 /** returns planar configuration flag 237 * @return planar configuration flag 238 */ getPlanarConfiguration()239 E_PlanarConfiguration getPlanarConfiguration() const 240 { 241 return planarConfiguration; 242 } 243 244 /** returns color conversion mode for compression 245 * @return color conversion mode for compression 246 */ getCompressionColorSpaceConversion()247 E_CompressionColorSpaceConversion getCompressionColorSpaceConversion() const 248 { 249 return compressionCSConversion; 250 } 251 252 /** returns color conversion mode for compression 253 * @return color conversion mode for compression 254 */ getDecompressionColorSpaceConversion()255 E_DecompressionColorSpaceConversion getDecompressionColorSpaceConversion() const 256 { 257 return decompressionCSConversion; 258 } 259 260 /** returns flag indicating if compression to be optimized for real pixel values 261 * @return flag indicating if compression to be optimized for real pixel values 262 */ getUsePixelValues()263 OFBool getUsePixelValues() const 264 { 265 return usePixelValues; 266 } 267 268 /** returns flag indicating if compression should compute Rescale Slope/Intercept 269 * @return flag indicating if compression should compute Rescale Slope/Intercept 270 */ getUseModalityRescale()271 OFBool getUseModalityRescale() const 272 { 273 return useModalityRescale; 274 } 275 276 /** Returns flag indicating if incorrect palette attribute tags should be accepted 277 * @return flag indicating if incorrect palette attribute tags should be accepted 278 */ getAcceptWrongPaletteTags()279 OFBool getAcceptWrongPaletteTags() const 280 { 281 return acceptWrongPaletteTags; 282 } 283 284 /** Returns flag indicating if compatibility to old ACR-NEMA images without 285 * photometric interpretation is enabled. 286 * @return flag indicating if ACR-NEMA compatibility is enabled 287 */ 288 getAcrNemaCompatibility()289 OFBool getAcrNemaCompatibility() const 290 { 291 return acrNemaCompatibility; 292 } 293 294 /** returns flag indicating if real lossless mode is enabled 295 * @return flag indicating if real lossless mode is enabled 296 */ getTrueLosslessMode()297 OFBool getTrueLosslessMode() const 298 { 299 return trueLosslessMode; 300 } 301 302 /** returns flag indicating whether the workaround for buggy JPEG lossless images with incorrect predictor 6 is enabled 303 * @return flag indicating whether the workaround for buggy JPEG lossless images with incorrect predictor 6 is enabled 304 */ predictor6WorkaroundEnabled()305 OFBool predictor6WorkaroundEnabled() const 306 { 307 return predictor6WorkaroundEnabled_; 308 } 309 310 /** returns flag indicating whether the workaround for buggy Cornell JPEG lossless images with Huffman table overflow is enabled 311 * @return flag indicating whether the workaround for buggy Cornell JPEG lossless images with Huffman table overflow is enabled 312 */ cornellWorkaroundEnabled()313 OFBool cornellWorkaroundEnabled() const 314 { 315 return cornellWorkaroundEnabled_; 316 } 317 318 /** returns flag indicating whether one fragment per frame should be enforced while decoding 319 * @return flag indicating whether one fragment per frame should be enforced while decoding 320 */ getForceSingleFragmentPerFrame()321 OFBool getForceSingleFragmentPerFrame() const 322 { 323 return forceSingleFragmentPerFrame; 324 } 325 326 private: 327 328 /// private undefined copy assignment operator 329 DJCodecParameter& operator=(const DJCodecParameter&); 330 331 /// color conversion mode for compression 332 E_CompressionColorSpaceConversion compressionCSConversion; 333 334 /// color conversion mode for decompression 335 E_DecompressionColorSpaceConversion decompressionCSConversion; 336 337 /// flag describing how planar configuration of decompressed color images should be handled 338 E_PlanarConfiguration planarConfiguration; 339 340 /// perform huffman table optimization for 8 bits/pixel compression? 341 OFBool optimizeHuffman; 342 343 /// smoothing factor for image compression, 0..100 344 int smoothingFactor; 345 346 /// forced bit depth for image compression, 0 (auto) or 8/12/16 347 int forcedBitDepth; 348 349 /// maximum fragment size (in kbytes) for compression, 0 for unlimited. 350 Uint32 fragmentSize; 351 352 /// create offset table during image compression 353 OFBool createOffsetTable; 354 355 /// subsampling mode for color image compression 356 E_SubSampling sampleFactors; 357 358 /** flag indicating whether a compressed YBR color stream should be marked 359 * as YBR_FULL or YBR_FULL_422 on DICOM level 360 */ 361 OFBool writeYBR422; 362 363 /// flag indicating whether image should be converted to Secondary Capture upon compression 364 OFBool convertToSC; 365 366 /// mode for SOP Instance UID creation 367 E_UIDCreation uidCreation; 368 369 /** mode for VOI transformation of monochrome images. possible values: 370 0: no VOI transformation (default). See also variables 371 usePixelValues (default) or useModalityRescale denoting two 372 further variables tweaking compression behaviour. 373 1: use the n-th VOI window from the image file (see variable windowType) 374 2: use the n-th VOI look up table from the image file (see variable windowType) 375 3: compute VOI window using min-max algorithm 376 4: compute VOI window using Histogram algorithm, ignoring n percent 377 5: compute VOI window using center r and width s 378 6: compute VOI window using min-max algorithm ignoring extremes 379 7: compute region of interest VOI window 380 */ 381 size_t windowType; 382 383 /// parameter for VOI transform of monochrome images, used in modes 1, 2, 4, 6 384 size_t windowParameter; 385 386 /// VOI window center for mode 5 387 double voiCenter; 388 389 /// VOI window width for mode 5 390 double voiWidth; 391 392 /// Region of Interest left corner for for VOI transform of monochrome images, mode 7 393 size_t roiLeft; 394 395 /// Region of Interest upper corner for for VOI transform of monochrome images, mode 7 396 size_t roiTop; 397 398 /// Region of Interest width for for VOI transform of monochrome images, mode 7 399 size_t roiWidth; 400 401 /// Region of Interest height for for VOI transform of monochrome images, mode 7 402 size_t roiHeight; 403 404 /// Check smallest and largest pixel value and optimize compression, mode 0 only 405 OFBool usePixelValues; 406 407 /// Create Rescale Slope/Intercept to scale back to original pixel range, mode 0 only 408 OFBool useModalityRescale; 409 410 /// Accept wrong palette attribute tags 411 OFBool acceptWrongPaletteTags; 412 413 /// Compatibility with old ACR-NEMA images without photometric interpretation 414 OFBool acrNemaCompatibility; 415 416 /// True losless mode, replaces old "pseudo" lossless encoders, when true (default) 417 OFBool trueLosslessMode; 418 419 /// flag indicating that the workaround for buggy JPEG lossless images with incorrect predictor 6 is enabled 420 OFBool predictor6WorkaroundEnabled_; 421 422 /// flag indicating that the workaround for buggy Cornell JPEG lossless images with huffman table overflow is enabled 423 OFBool cornellWorkaroundEnabled_; 424 425 /** flag indicating that while decompressing a multiframe image one fragment per frame 426 * should be assumed even if the JPEG data for some frame is incomplete 427 */ 428 OFBool forceSingleFragmentPerFrame; 429 430 }; 431 432 433 #endif 434