00001 /* 00002 * 00003 * Copyright (C) 1996-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmimgle 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: Utilities (Header) 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:16:27 $ 00022 * CVS/RCS Revision: $Revision: 1.42 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 00030 #ifndef DIUTILS_H 00031 #define DIUTILS_H 00032 00033 #include "dcmtk/config/osconfig.h" 00034 00035 #include "dcmtk/ofstd/oftypes.h" 00036 #include "dcmtk/ofstd/ofcast.h" 00037 00038 #include "dcmtk/oflog/oflog.h" 00039 00040 OFLogger DCM_dcmimgleGetLogger(); 00041 00042 #define DCMIMGLE_TRACE(msg) OFLOG_TRACE(DCM_dcmimgleGetLogger(), msg) 00043 #define DCMIMGLE_DEBUG(msg) OFLOG_DEBUG(DCM_dcmimgleGetLogger(), msg) 00044 #define DCMIMGLE_INFO(msg) OFLOG_INFO(DCM_dcmimgleGetLogger(), msg) 00045 #define DCMIMGLE_WARN(msg) OFLOG_WARN(DCM_dcmimgleGetLogger(), msg) 00046 #define DCMIMGLE_ERROR(msg) OFLOG_ERROR(DCM_dcmimgleGetLogger(), msg) 00047 #define DCMIMGLE_FATAL(msg) OFLOG_FATAL(DCM_dcmimgleGetLogger(), msg) 00048 00049 00050 /*---------------------* 00051 * const definitions * 00052 *---------------------*/ 00053 00058 00060 const unsigned long CIF_AcrNemaCompatibility = 0x0000001; 00061 00063 const unsigned long CIF_WrongPaletteAttributeTags = 0x0000002; 00064 00066 const unsigned long CIF_MayDetachPixelData = 0x0000004; 00067 00069 const unsigned long CIF_UsePresentationState = 0x0000008; 00070 00072 const unsigned long CIF_KeepYCbCrColorModel = 0x0000010; 00073 00075 const unsigned long CIF_TakeOverExternalDataset = 0x0000020; 00076 00078 const unsigned long CIF_IgnoreModalityTransformation = 0x0000040; 00079 00081 const unsigned long CIF_IgnoreModalityLutBitDepth = 0x0000080; 00082 00084 const unsigned long CIF_CheckLutBitDepth = 0x0000100; 00085 00087 const unsigned long CIF_UseAbsolutePixelRange = 0x0000200; 00088 00090 const unsigned long CIF_UsePartialAccessToPixelData = 0x0000400; 00091 00093 const unsigned long CIF_DecompressCompletePixelData = 0x0000800; 00094 00096 const unsigned long CIF_NeverAccessEmbeddedOverlays = 0x0001000; 00098 00099 00100 // / true color color mode (for monochrome images only) 00101 const int MI_PastelColor = -1; 00102 00103 00104 /*--------------------* 00105 * type definitions * 00106 *--------------------*/ 00107 00110 enum EP_Interpretation 00111 { 00113 EPI_Unknown, 00114 // no element value available 00115 EPI_Missing, 00117 EPI_Monochrome1, 00119 EPI_Monochrome2, 00121 EPI_PaletteColor, 00123 EPI_RGB, 00125 EPI_HSV, 00127 EPI_ARGB, 00129 EPI_CMYK, 00131 EPI_YBR_Full, 00133 EPI_YBR_Full_422, 00135 EPI_YBR_Partial_422 00136 }; 00137 00138 00141 struct SP_Interpretation 00142 { 00144 const char *Name; 00146 const char *DefinedTerm; 00148 EP_Interpretation Type; 00149 }; 00150 00151 00154 struct SB_BitmapFileHeader 00155 { 00157 char bfType[2]; 00159 Uint32 bfSize; 00161 Uint16 bfReserved1; 00163 Uint16 bfReserved2; 00165 Uint32 bfOffBits; 00166 }; 00167 00168 00171 struct SB_BitmapInfoHeader 00172 { 00174 Uint32 biSize; 00176 Sint32 biWidth; 00178 Sint32 biHeight; 00180 Uint16 biPlanes; 00182 Uint16 biBitCount; 00184 Uint32 biCompression; 00186 Uint32 biSizeImage; 00188 Sint32 biXPelsPerMeter; 00190 Sint32 biYPelsPerMeter; 00192 Uint32 biClrUsed; 00194 Uint32 biClrImportant; 00195 }; 00196 00197 00200 enum EP_Representation 00201 { 00203 EPR_Uint8, EPR_MinUnsigned = EPR_Uint8, 00205 EPR_Sint8, EPR_MinSigned = EPR_Sint8, 00207 EPR_Uint16, 00209 EPR_Sint16, 00211 EPR_Uint32, EPR_MaxUnsigned = EPR_Uint32, 00213 EPR_Sint32, EPR_MaxSigned = EPR_Sint32 00214 }; 00215 00216 00219 enum EI_Status 00220 { 00222 EIS_Normal, 00224 EIS_NoDataDictionary, 00226 EIS_InvalidDocument, 00228 EIS_MissingAttribute, 00230 EIS_InvalidValue, 00232 EIS_NotSupportedValue, 00234 EIS_MemoryFailure, 00236 EIS_InvalidImage, 00238 EIS_OtherError 00239 }; 00240 00241 00245 enum EM_Overlay 00246 { 00248 EMO_Default, 00250 EMO_Replace, 00252 EMO_Graphic = EMO_Replace, 00254 EMO_ThresholdReplace, 00256 EMO_Complement, 00258 EMO_InvertBitmap, 00260 EMO_RegionOfInterest, 00262 EMO_BitmapShutter 00263 }; 00264 00265 00268 enum EF_VoiLutFunction 00269 { 00271 EFV_Default, 00273 EFV_Linear, 00275 EFV_Sigmoid 00276 }; 00277 00278 00281 enum ES_PresentationLut 00282 { 00284 ESP_Default, 00286 ESP_Identity, 00288 ESP_Inverse, 00290 ESP_LinOD 00291 }; 00292 00293 00296 enum EP_Polarity 00297 { 00299 EPP_Normal, 00301 EPP_Reverse 00302 }; 00303 00304 00308 enum EL_BitsPerTableEntry 00309 { 00311 ELM_UseValue, 00313 ELM_IgnoreValue, 00315 ELM_CheckValue 00316 }; 00317 00318 00319 /*----------------------------* 00320 * constant initializations * 00321 *----------------------------*/ 00322 00323 const SP_Interpretation PhotometricInterpretationNames[] = 00324 { 00325 {"MONOCHROME1", "MONOCHROME1", EPI_Monochrome1}, 00326 {"MONOCHROME2", "MONOCHROME2", EPI_Monochrome2}, 00327 {"PALETTECOLOR", "PALETTE COLOR", EPI_PaletteColor}, // space deleted to simplify detection 00328 {"RGB", "RGB", EPI_RGB}, 00329 {"HSV", "HSV", EPI_HSV}, 00330 {"ARGB", "ARGB", EPI_ARGB}, 00331 {"CMYK", "CMYK", EPI_CMYK}, 00332 {"YBRFULL", "YBR_FULL", EPI_YBR_Full}, // underscore deleted to simplify detection 00333 {"YBRFULL422", "YBR_FULL_422", EPI_YBR_Full_422}, // underscores deleted to simplify detection 00334 {"YBRPARTIAL422", "YBR_PARTIAL_422", EPI_YBR_Partial_422}, // underscores deleted to simplify detection 00335 {NULL, NULL, EPI_Unknown} 00336 }; 00337 00338 00339 /*---------------------* 00340 * macro definitions * 00341 *---------------------*/ 00342 00343 #define MAX_UINT Uint32 00344 #define MAX_SINT Sint32 00345 00346 #define MAX_BITS 32 00347 #define MAX_BITS_TYPE Uint32 00348 #define MAX_RAWPPM_BITS 8 00349 #define MAX_INTERPOLATION_BITS 16 00350 00351 #define bitsof(expr) (sizeof(expr) << 3) 00352 00353 00354 /*----------------------* 00355 * class declarations * 00356 *----------------------*/ 00357 00361 class DicomImageClass 00362 { 00363 00364 public: 00365 00373 static inline unsigned long maxval(const int mv_bits, 00374 const unsigned long mv_pos = 1) 00375 { 00376 return (mv_bits < MAX_BITS) ? 00377 (OFstatic_cast(unsigned long, 1) << mv_bits) - mv_pos : OFstatic_cast(MAX_BITS_TYPE, -1); 00378 } 00379 00387 static inline unsigned int tobits(unsigned long tb_value, 00388 const unsigned long tb_pos = 1) 00389 { 00390 if (tb_value > 0) 00391 tb_value -= tb_pos; 00392 register unsigned int tb_bits = 0; 00393 while (tb_value > 0) 00394 { 00395 ++tb_bits; 00396 tb_value >>= 1; 00397 } 00398 return tb_bits; 00399 } 00400 00408 static unsigned int rangeToBits(double minvalue, 00409 double maxvalue); 00410 00417 static int isRepresentationSigned(EP_Representation repres); 00418 00425 static unsigned int getRepresentationBits(EP_Representation repres); 00426 00434 static EP_Representation determineRepresentation(double minvalue, 00435 double maxvalue); 00436 00437 }; 00438 00439 00440 #endif 00441 00442 00443 /* 00444 * 00445 * CVS/RCS Log: 00446 * $Log: diutils.h,v $ 00447 * Revision 1.42 2010-10-14 13:16:27 joergr 00448 * Updated copyright header. Added reference to COPYRIGHT file. 00449 * 00450 * Revision 1.41 2010-10-05 15:24:02 joergr 00451 * Added preliminary support for VOI LUT function. Please note, however, that 00452 * the sigmoid transformation is not yet implemented. 00453 * 00454 * Revision 1.40 2010-03-01 09:08:47 uli 00455 * Removed some unnecessary include directives in the headers. 00456 * 00457 * Revision 1.39 2010-02-23 16:31:34 joergr 00458 * Added new helper function which determines whether an integer representation 00459 * is signed or unsigned. 00460 * 00461 * Revision 1.38 2009-11-25 14:59:11 joergr 00462 * Added list of Defined Terms for the attribute PhotometricInterpretation. 00463 * 00464 * Revision 1.37 2009-11-17 17:55:47 joergr 00465 * Added new enum value for missing photometric interpretation value. 00466 * Added new configuration flags for the upcoming support of partial access to 00467 * pixel data, i.e. without decompressing/loading a complete multi-frame image. 00468 * 00469 * Revision 1.36 2009-10-28 14:38:17 joergr 00470 * Fixed minor issues in log output. 00471 * 00472 * Revision 1.35 2009-10-28 09:53:40 uli 00473 * Switched to logging mechanism provided by the "new" oflog module. 00474 * 00475 * Revision 1.34 2009-04-21 08:19:51 joergr 00476 * Added new compatibility flag CIF_UseAbsolutePixelRange which changes the way 00477 * the internal representation of monochrome images is determined. 00478 * 00479 * Revision 1.33 2009-04-20 12:19:40 joergr 00480 * Added new helper function getRepresentationBits(). 00481 * 00482 * Revision 1.32 2007/03/16 11:56:06 joergr 00483 * Introduced new flag that allows to select how to handle the BitsPerTableEntry 00484 * value in the LUT descriptor (use, ignore or check). 00485 * 00486 * Revision 1.31 2005/12/08 16:48:12 meichel 00487 * Changed include path schema for all DCMTK header files 00488 * 00489 * Revision 1.30 2005/03/09 17:29:42 joergr 00490 * Added support for new overlay mode "invert bitmap". 00491 * Added new helper function rangeToBits(). 00492 * 00493 * Revision 1.29 2004/11/29 16:52:22 joergr 00494 * Removed email address from CVS log. 00495 * 00496 * Revision 1.28 2004/11/29 11:15:16 joergr 00497 * Introduced new integer type MAX_BITS_TYPE for internal use. 00498 * 00499 * Revision 1.27 2004/11/25 09:38:43 meichel 00500 * Fixed bug in DicomImageClass::maxval affecting 64-bit platforms. 00501 * 00502 * Revision 1.26 2004/08/03 11:41:50 meichel 00503 * Headers libc.h and unistd.h are now included via ofstdinc.h 00504 * 00505 * Revision 1.25 2003/12/23 15:53:22 joergr 00506 * Replaced post-increment/decrement operators by pre-increment/decrement 00507 * operators where appropriate (e.g. 'i++' by '++i'). 00508 * 00509 * Revision 1.24 2003/12/17 16:17:29 joergr 00510 * Added new compatibility flag that allows to ignore the third value of LUT 00511 * descriptors and to determine the bits per table entry automatically. 00512 * 00513 * Revision 1.23 2003/12/08 18:49:54 joergr 00514 * Adapted type casts to new-style typecast operators defined in ofcast.h. 00515 * Removed leading underscore characters from preprocessor symbols (reserved 00516 * symbols). Updated copyright header. 00517 * 00518 * Revision 1.22 2003/05/20 09:19:51 joergr 00519 * Added new configuration/compatibility flag that allows to ignore the 00520 * modality transform stored in the dataset. 00521 * 00522 * Revision 1.21 2002/11/27 14:08:08 meichel 00523 * Adapted module dcmimgle to use of new header file ofstdinc.h 00524 * 00525 * Revision 1.20 2002/06/26 16:08:14 joergr 00526 * Added configuration flag that enables the DicomImage class to take the 00527 * responsibility of an external DICOM dataset (i.e. delete it on destruction). 00528 * 00529 * Revision 1.19 2001/11/09 16:25:59 joergr 00530 * Added support for Window BMP file format. 00531 * 00532 * Revision 1.18 2001/09/28 13:11:00 joergr 00533 * Added new flag (CIF_KeepYCbCrColorModel) which avoids conversion of YCbCr 00534 * color models to RGB. 00535 * 00536 * Revision 1.17 2001/06/01 15:49:52 meichel 00537 * Updated copyright header 00538 * 00539 * Revision 1.16 2000/07/07 13:40:31 joergr 00540 * Added support for LIN OD presentation LUT shape. 00541 * 00542 * Revision 1.15 2000/06/07 14:30:28 joergr 00543 * Added method to set the image polarity (normal, reverse). 00544 * 00545 * Revision 1.14 2000/04/28 12:32:33 joergr 00546 * DebugLevel - global for the module - now derived from OFGlobal (MF-safe). 00547 * 00548 * Revision 1.13 2000/03/08 16:24:25 meichel 00549 * Updated copyright header. 00550 * 00551 * Revision 1.12 2000/02/23 15:12:16 meichel 00552 * Corrected macro for Borland C++ Builder 4 workaround. 00553 * 00554 * Revision 1.11 2000/02/01 10:52:38 meichel 00555 * Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4, 00556 * workaround for bug in compiler header files. 00557 * 00558 * Revision 1.10 1999/09/17 13:08:13 joergr 00559 * Added/changed/completed DOC++ style comments in the header files. 00560 * 00561 * Revision 1.9 1999/07/23 14:16:16 joergr 00562 * Added flag to avoid color space conversion for color images (not yet 00563 * implemented). 00564 * 00565 * Revision 1.8 1999/04/30 16:33:19 meichel 00566 * Now including stdio.h in diutils.h, required on SunOS 00567 * 00568 * Revision 1.7 1999/04/28 14:55:41 joergr 00569 * Added experimental support to create grayscale images with more than 256 00570 * shades of gray to be displayed on a consumer monitor (use pastel colors). 00571 * 00572 * Revision 1.6 1999/03/24 17:20:28 joergr 00573 * Added/Modified comments and formatting. 00574 * 00575 * Revision 1.5 1999/02/03 17:36:06 joergr 00576 * Moved global functions maxval() and determineRepresentation() to class 00577 * DicomImageClass (as static methods). 00578 * Added BEGIN_EXTERN_C and END_EXTERN_C to some C includes. 00579 * 00580 * Revision 1.4 1999/01/20 15:13:12 joergr 00581 * Added new overlay plane mode for bitmap shutters. 00582 * 00583 * Revision 1.3 1998/12/23 11:38:08 joergr 00584 * Introduced new overlay mode item EMO_Graphic (= EMO_Replace). 00585 * 00586 * Revision 1.2 1998/12/16 16:40:15 joergr 00587 * Some layouting. 00588 * 00589 * Revision 1.1 1998/11/27 15:51:45 joergr 00590 * Added copyright message. 00591 * Introduced global debug level for dcmimage module to control error output. 00592 * Moved type definitions to diutils.h. 00593 * Added methods to support presentation LUTs and shapes. 00594 * Introduced configuration flags to adjust behaviour in different cases. 00595 * 00596 * Revision 1.5 1998/06/25 08:50:10 joergr 00597 * Added compatibility mode to support ACR-NEMA images and wrong 00598 * palette attribute tags. 00599 * 00600 * Revision 1.4 1998/05/11 14:53:30 joergr 00601 * Added CVS/RCS header to each file. 00602 * 00603 * 00604 */