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: enumerations, error constants and helper functions for dcmjpeg 19 * 20 */ 21 22 #ifndef DJUTILS_H 23 #define DJUTILS_H 24 25 #include "dcmtk/config/osconfig.h" 26 #include "dcmtk/ofstd/ofcond.h" /* for class OFCondition */ 27 #include "dcmtk/dcmimgle/diutils.h" /* for EP_Interpretation */ 28 #include "dcmtk/oflog/oflog.h" 29 #include "dcmtk/dcmjpeg/djdefine.h" 30 31 32 // global definitions for logging mechanism provided by the oflog module 33 34 extern DCMTK_DCMJPEG_EXPORT OFLogger DCM_dcmjpegLogger; 35 36 #define DCMJPEG_TRACE(msg) OFLOG_TRACE(DCM_dcmjpegLogger, msg) 37 #define DCMJPEG_DEBUG(msg) OFLOG_DEBUG(DCM_dcmjpegLogger, msg) 38 #define DCMJPEG_INFO(msg) OFLOG_INFO(DCM_dcmjpegLogger, msg) 39 #define DCMJPEG_WARN(msg) OFLOG_WARN(DCM_dcmjpegLogger, msg) 40 #define DCMJPEG_ERROR(msg) OFLOG_ERROR(DCM_dcmjpegLogger, msg) 41 #define DCMJPEG_FATAL(msg) OFLOG_FATAL(DCM_dcmjpegLogger, msg) 42 43 44 // include this file in doxygen documentation 45 46 /** @file djutils.h 47 * @brief type definitions and constants for the dcmjpeg module 48 */ 49 50 51 // forward declarations 52 53 class DcmItem; 54 55 56 /** describes the different modes of operation of a JPEG codec 57 */ 58 enum EJ_Mode 59 { 60 /// JPEG baseline 61 EJM_baseline, 62 63 /// JPEG extended sequential 64 EJM_sequential, 65 66 /// JPEG spectral selection 67 EJM_spectralSelection, 68 69 /// JPEG full progression 70 EJM_progressive, 71 72 /// JPEG lossless 73 EJM_lossless 74 }; 75 76 /** describes the different types of component sub-sampling 77 * to be used with lossy image compression. 78 */ 79 enum E_SubSampling 80 { 81 /// 4:4:4 sampling (no subsampling) 82 ESS_444, 83 /// 4:2:2 sampling (horizontal subsampling of chroma components) 84 ESS_422, 85 /// 4:1:1 sampling (horizontal and vertical subsampling of chroma components) 86 ESS_411 87 }; 88 89 /** describes the condition under which a compressed or decompressed image 90 * receives a new SOP instance UID. 91 */ 92 enum E_UIDCreation 93 { 94 /** Upon compression, assign new SOP instance UID if compression is lossy. 95 * Upon decompression never assign new SOP instance UID. 96 */ 97 EUC_default, 98 99 /// always assign new SOP instance UID on compression and decompression 100 EUC_always, 101 102 /// never assign new SOP instance UID 103 EUC_never 104 }; 105 106 /** describes how the decoder should handle planar configuration of 107 * decompressed color images. 108 */ 109 enum E_PlanarConfiguration 110 { 111 /** automatically determine whether color-by-plane is required from 112 * the SOP Class UID and decompressed photometric interpretation 113 */ 114 EPC_default, 115 116 /// always create color-by-pixel planar configuration 117 EPC_colorByPixel, 118 119 /// always create color-by-plane planar configuration 120 EPC_colorByPlane 121 }; 122 123 /** describes how color space conversion should be handled 124 * during the conversion of an uncompressed DICOM image to 125 * a JPEG-compressed image 126 */ 127 enum E_CompressionColorSpaceConversion 128 { 129 /** encode color images in YCbCr if lossy JPEG. 130 * If lossless JPEG, images are encoded as RGB unless the source 131 * image is YCbCr in which case no color conversion is performed. 132 */ 133 ECC_lossyYCbCr, 134 135 /** encode color images in RGB unless the source 136 * image is YCbCr in which case no color conversion is performed. 137 */ 138 ECC_lossyRGB, 139 140 /** convert color images to monochrome before compressing 141 */ 142 ECC_monochrome 143 }; 144 145 /** describes how color space conversion should be handled 146 * during the conversion of a JPEG-compressed DICOM image to 147 * an uncompressed image 148 */ 149 enum E_DecompressionColorSpaceConversion 150 { 151 /** perform color space conversion from YCbCr to RGB if 152 * DICOM photometric interpretation indicates YCbCr. 153 */ 154 EDC_photometricInterpretation, 155 156 /** always perform color space conversion from YCbCr to 157 * RGB if JPEG data is color image and compression is lossy. 158 */ 159 EDC_lossyOnly, 160 161 /** always perform color space conversion from YCbCr to 162 * RGB if JPEG data is color image. 163 */ 164 EDC_always, 165 166 /** never perform any color space conversion. 167 */ 168 EDC_never, 169 170 /** perform color space conversion from YCbCr to RGB if 171 * JPEG data is color image, compression is lossy, and 172 * the underlying JPEG library "guesses" the color space 173 * to be YCbCr. 174 */ 175 EDC_guessLossyOnly, 176 177 /** perform color space conversion from YCbCr to RGB if 178 * JPEG data is color image, and the underlying JPEG 179 * library "guesses" the color space to be YCbCr. 180 */ 181 EDC_guess 182 }; 183 184 185 // CONDITION CONSTANTS 186 187 /// IJG codec suspension return 188 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_Suspension; 189 /// Buffer for decompressed image (8 bits/sample) too small 190 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_IJG8_FrameBufferTooSmall; 191 /// Buffer for decompressed image (12 bits/sample) too small 192 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_IJG12_FrameBufferTooSmall; 193 /// Buffer for decompressed image (16 bits/sample) too small 194 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_IJG16_FrameBufferTooSmall; 195 /// Codec does not support this PhotometricInterpretation 196 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_UnsupportedPhotometricInterpretation; 197 /// Codec does not support this kind of color conversion 198 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_UnsupportedColorConversion; 199 /// Codec does not support this kind of bit depth 200 extern DCMTK_DCMJPEG_EXPORT const OFConditionConst EJ_UnsupportedBitDepth; 201 202 // reserved condition codes for IJG error messages 203 const unsigned short EJCode_IJG8_Compression = 0x0100; 204 const unsigned short EJCode_IJG8_Decompression = 0x0101; 205 const unsigned short EJCode_IJG12_Compression = 0x0102; 206 const unsigned short EJCode_IJG12_Decompression = 0x0103; 207 const unsigned short EJCode_IJG16_Compression = 0x0104; 208 const unsigned short EJCode_IJG16_Decompression = 0x0105; 209 210 /** helper class with static methods used from different dcmjpeg classes 211 * (in particular from the encoder and the decoder part). 212 */ 213 class DCMTK_DCMJPEG_EXPORT DcmJpegHelper 214 { 215 public: 216 217 /** helper function that locates the photometric interpretation attribute 218 * in a DICOM dataset and returns a parsed value. 219 * @param item the dataset in which the element is searched 220 * @return photometric interpretation enum, EPI_Unknown if unknown string or attribute missing 221 */ 222 static EP_Interpretation getPhotometricInterpretation(DcmItem *item); 223 224 /** adjusts the padding of a JPEG bitstream in the buffer that has odd length, 225 * such that the End of Image (EOI) marker ends on an even byte boundary. 226 * @param buffer pointer to buffer containing compressed JPEG bitstream 227 * @param bufSize number of bytes used for the JPEG bitstream (including pad byte) 228 */ 229 static void fixPadding( 230 Uint8 *buffer, 231 Uint32 bufSize); 232 233 }; 234 235 #endif 236