diutils.h

00001 /*
00002  *
00003  *  Copyright (C) 1996-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  dcmimgle
00019  *
00020  *  Author:  Joerg Riesmeier
00021  *
00022  *  Purpose: Utilities (Header)
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:48:12 $
00026  *  CVS/RCS Revision: $Revision: 1.31 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef DIUTILS_H
00035 #define DIUTILS_H
00036 
00037 #include "dcmtk/config/osconfig.h"
00038 #include "dcmtk/dcmdata/dctypes.h"
00039 #include "dcmtk/ofstd/ofglobal.h"
00040 #include "dcmtk/ofstd/ofcast.h"
00041 
00042 #define INCLUDE_CSTDLIB
00043 #define INCLUDE_CSTDIO
00044 #define INCLUDE_LIBC
00045 #include "dcmtk/ofstd/ofstdinc.h"
00046 
00047 /*---------------------*
00048  *  const definitions  *
00049  *---------------------*/
00050 
00055 
00057 const unsigned long CIF_AcrNemaCompatibility         = 0x0000001;
00058 
00060 const unsigned long CIF_WrongPaletteAttributeTags    = 0x0000002;
00061 
00063 const unsigned long CIF_MayDetachPixelData           = 0x0000004;
00064 
00066 const unsigned long CIF_UsePresentationState         = 0x0000008;
00067 
00069 const unsigned long CIF_KeepYCbCrColorModel          = 0x0000010;
00070 
00072 const unsigned long CIF_TakeOverExternalDataset      = 0x0000020;
00073 
00075 const unsigned long CIF_IgnoreModalityTransformation = 0x0000040;
00076 
00078 const unsigned long CIF_IgnoreModalityLutBitDepth    = 0x0000080;
00080 
00081 
00082 // / true color color mode (for monochrome images only)
00083 const int MI_PastelColor = -1;
00084 
00085 
00086 /*--------------------*
00087  *  type definitions  *
00088  *--------------------*/
00089 
00092 enum EP_Interpretation
00093 {
00095     EPI_Unknown,
00097     EPI_Monochrome1,
00099     EPI_Monochrome2,
00101     EPI_PaletteColor,
00103     EPI_RGB,
00105     EPI_HSV,
00107     EPI_ARGB,
00109     EPI_CMYK,
00111     EPI_YBR_Full,
00113     EPI_YBR_Full_422,
00115     EPI_YBR_Partial_422
00116 };
00117 
00118 
00121 struct SP_Interpretation
00122 {
00124     const char *Name;
00126     EP_Interpretation Type;
00127 };
00128 
00129 
00132 struct SB_BitmapFileHeader
00133 {
00135     char bfType[2];
00137     Uint32 bfSize;
00139     Uint16 bfReserved1;
00141     Uint16 bfReserved2;
00143     Uint32 bfOffBits;
00144 };
00145 
00146 
00149 struct SB_BitmapInfoHeader
00150 {
00152     Uint32 biSize;
00154     Sint32 biWidth;
00156     Sint32 biHeight;
00158     Uint16 biPlanes;
00160     Uint16 biBitCount;
00162     Uint32 biCompression;
00164     Uint32 biSizeImage;
00166     Sint32 biXPelsPerMeter;
00168     Sint32 biYPelsPerMeter;
00170     Uint32 biClrUsed;
00172     Uint32 biClrImportant;
00173 };
00174 
00175 
00178 enum EP_Representation
00179 {
00181     EPR_Uint8, EPR_MinUnsigned = EPR_Uint8,
00183     EPR_Sint8, EPR_MinSigned = EPR_Sint8,
00185     EPR_Uint16,
00187     EPR_Sint16,
00189     EPR_Uint32, EPR_MaxUnsigned = EPR_Uint32,
00191     EPR_Sint32, EPR_MaxSigned = EPR_Sint32
00192 };
00193 
00194 
00197 enum EI_Status
00198 {
00200     EIS_Normal,
00202     EIS_NoDataDictionary,
00204     EIS_InvalidDocument,
00206     EIS_MissingAttribute,
00208     EIS_InvalidValue,
00210     EIS_NotSupportedValue,
00212     EIS_MemoryFailure,
00214     EIS_InvalidImage,
00216     EIS_OtherError
00217 };
00218 
00219 
00223 enum EM_Overlay
00224 {
00226     EMO_Default,
00228     EMO_Replace,
00230     EMO_Graphic = EMO_Replace,
00232     EMO_ThresholdReplace,
00234     EMO_Complement,
00236     EMO_InvertBitmap,
00238     EMO_RegionOfInterest,
00240     EMO_BitmapShutter
00241 };
00242 
00243 
00246 enum ES_PresentationLut
00247 {
00249     ESP_Default,
00251     ESP_Identity,
00253     ESP_Inverse,
00255     ESP_LinOD
00256 };
00257 
00258 
00261 enum EP_Polarity
00262 {
00264     EPP_Normal,
00266     EPP_Reverse
00267 };
00268 
00269 
00270 /*----------------------------*
00271  *  constant initializations  *
00272  *----------------------------*/
00273 
00274 const SP_Interpretation PhotometricInterpretationNames[] =
00275 {
00276     {"MONOCHROME1",   EPI_Monochrome1},
00277     {"MONOCHROME2",   EPI_Monochrome2},
00278     {"PALETTECOLOR",  EPI_PaletteColor},        // space deleted to simplify detection
00279     {"RGB",           EPI_RGB},
00280     {"HSV",           EPI_HSV},
00281     {"ARGB",          EPI_ARGB},
00282     {"CMYK",          EPI_CMYK},
00283     {"YBRFULL",       EPI_YBR_Full},            // underscore deleted to simplify detection
00284     {"YBRFULL422",    EPI_YBR_Full_422},        // underscores deleted to simplify detection
00285     {"YBRPARTIAL422", EPI_YBR_Partial_422},     // underscores deleted to simplify detection
00286     {NULL,            EPI_Unknown}
00287 };
00288 
00289 
00290 /*---------------------*
00291  *  macro definitions  *
00292  *---------------------*/
00293 
00294 #define MAX_UINT Uint32
00295 #define MAX_SINT Sint32
00296 
00297 #define MAX_BITS 32
00298 #define MAX_BITS_TYPE Uint32
00299 #define MAX_RAWPPM_BITS 8
00300 #define MAX_INTERPOLATION_BITS 16
00301 
00302 #define bitsof(expr) (sizeof(expr) << 3)
00303 
00304 
00305 /*----------------------*
00306  *  class declarations  *
00307  *----------------------*/
00308 
00312 class DicomImageClass
00313 {
00314 
00315  public:
00316 
00324     static inline unsigned long maxval(const int mv_bits,
00325                                        const unsigned long mv_pos = 1)
00326     {
00327         return (mv_bits < MAX_BITS) ?
00328             (OFstatic_cast(unsigned long, 1) << mv_bits) - mv_pos : OFstatic_cast(MAX_BITS_TYPE, -1);
00329     }
00330 
00338     static inline unsigned int tobits(unsigned long tb_value,
00339                                       const unsigned long tb_pos = 1)
00340     {
00341         if (tb_value > 0)
00342             tb_value -= tb_pos;
00343         register unsigned int tb_bits = 0;
00344         while (tb_value > 0)
00345         {
00346             ++tb_bits;
00347             tb_value >>= 1;
00348         }
00349         return tb_bits;
00350     }
00351 
00359     static unsigned int rangeToBits(double minvalue,
00360                                     double maxvalue);
00361 
00369     static EP_Representation determineRepresentation(double minvalue,
00370                                                      double maxvalue);
00371 
00376     static void setDebugLevel(const int level)
00377     {
00378         DebugLevel.set(level);
00379     }
00380 
00385     static int getDebugLevel()
00386     {
00387         return DebugLevel.get();
00388     }
00389 
00396     static int checkDebugLevel(const int level)
00397     {
00398         return DebugLevel.get() & level;
00399     }
00400 
00401 
00403     static const int DL_NoMessages;
00405     static const int DL_Errors;
00407     static const int DL_Warnings;
00409     static const int DL_Informationals;
00411     static const int DL_DebugMessages;
00412 
00413 
00414   private:
00415 
00417     static OFGlobal<int> DebugLevel;
00418 };
00419 
00420 
00421 #endif
00422 
00423 
00424 /*
00425  *
00426  * CVS/RCS Log:
00427  * $Log: diutils.h,v $
00428  * Revision 1.31  2005/12/08 16:48:12  meichel
00429  * Changed include path schema for all DCMTK header files
00430  *
00431  * Revision 1.30  2005/03/09 17:29:42  joergr
00432  * Added support for new overlay mode "invert bitmap".
00433  * Added new helper function rangeToBits().
00434  *
00435  * Revision 1.29  2004/11/29 16:52:22  joergr
00436  * Removed email address from CVS log.
00437  *
00438  * Revision 1.28  2004/11/29 11:15:16  joergr
00439  * Introduced new integer type MAX_BITS_TYPE for internal use.
00440  *
00441  * Revision 1.27  2004/11/25 09:38:43  meichel
00442  * Fixed bug in DicomImageClass::maxval affecting 64-bit platforms.
00443  *
00444  * Revision 1.26  2004/08/03 11:41:50  meichel
00445  * Headers libc.h and unistd.h are now included via ofstdinc.h
00446  *
00447  * Revision 1.25  2003/12/23 15:53:22  joergr
00448  * Replaced post-increment/decrement operators by pre-increment/decrement
00449  * operators where appropriate (e.g. 'i++' by '++i').
00450  *
00451  * Revision 1.24  2003/12/17 16:17:29  joergr
00452  * Added new compatibility flag that allows to ignore the third value of LUT
00453  * descriptors and to determine the bits per table entry automatically.
00454  *
00455  * Revision 1.23  2003/12/08 18:49:54  joergr
00456  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00457  * Removed leading underscore characters from preprocessor symbols (reserved
00458  * symbols). Updated copyright header.
00459  *
00460  * Revision 1.22  2003/05/20 09:19:51  joergr
00461  * Added new configuration/compatibility flag that allows to ignore the
00462  * modality transform stored in the dataset.
00463  *
00464  * Revision 1.21  2002/11/27 14:08:08  meichel
00465  * Adapted module dcmimgle to use of new header file ofstdinc.h
00466  *
00467  * Revision 1.20  2002/06/26 16:08:14  joergr
00468  * Added configuration flag that enables the DicomImage class to take the
00469  * responsibility of an external DICOM dataset (i.e. delete it on destruction).
00470  *
00471  * Revision 1.19  2001/11/09 16:25:59  joergr
00472  * Added support for Window BMP file format.
00473  *
00474  * Revision 1.18  2001/09/28 13:11:00  joergr
00475  * Added new flag (CIF_KeepYCbCrColorModel) which avoids conversion of YCbCr
00476  * color models to RGB.
00477  *
00478  * Revision 1.17  2001/06/01 15:49:52  meichel
00479  * Updated copyright header
00480  *
00481  * Revision 1.16  2000/07/07 13:40:31  joergr
00482  * Added support for LIN OD presentation LUT shape.
00483  *
00484  * Revision 1.15  2000/06/07 14:30:28  joergr
00485  * Added method to set the image polarity (normal, reverse).
00486  *
00487  * Revision 1.14  2000/04/28 12:32:33  joergr
00488  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
00489  *
00490  * Revision 1.13  2000/03/08 16:24:25  meichel
00491  * Updated copyright header.
00492  *
00493  * Revision 1.12  2000/02/23 15:12:16  meichel
00494  * Corrected macro for Borland C++ Builder 4 workaround.
00495  *
00496  * Revision 1.11  2000/02/01 10:52:38  meichel
00497  * Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4,
00498  *   workaround for bug in compiler header files.
00499  *
00500  * Revision 1.10  1999/09/17 13:08:13  joergr
00501  * Added/changed/completed DOC++ style comments in the header files.
00502  *
00503  * Revision 1.9  1999/07/23 14:16:16  joergr
00504  * Added flag to avoid color space conversion for color images (not yet
00505  * implemented).
00506  *
00507  * Revision 1.8  1999/04/30 16:33:19  meichel
00508  * Now including stdio.h in diutils.h, required on SunOS
00509  *
00510  * Revision 1.7  1999/04/28 14:55:41  joergr
00511  * Added experimental support to create grayscale images with more than 256
00512  * shades of gray to be displayed on a consumer monitor (use pastel colors).
00513  *
00514  * Revision 1.6  1999/03/24 17:20:28  joergr
00515  * Added/Modified comments and formatting.
00516  *
00517  * Revision 1.5  1999/02/03 17:36:06  joergr
00518  * Moved global functions maxval() and determineRepresentation() to class
00519  * DicomImageClass (as static methods).
00520  * Added BEGIN_EXTERN_C and END_EXTERN_C to some C includes.
00521  *
00522  * Revision 1.4  1999/01/20 15:13:12  joergr
00523  * Added new overlay plane mode for bitmap shutters.
00524  *
00525  * Revision 1.3  1998/12/23 11:38:08  joergr
00526  * Introduced new overlay mode item EMO_Graphic (= EMO_Replace).
00527  *
00528  * Revision 1.2  1998/12/16 16:40:15  joergr
00529  * Some layouting.
00530  *
00531  * Revision 1.1  1998/11/27 15:51:45  joergr
00532  * Added copyright message.
00533  * Introduced global debug level for dcmimage module to control error output.
00534  * Moved type definitions to diutils.h.
00535  * Added methods to support presentation LUTs and shapes.
00536  * Introduced configuration flags to adjust behaviour in different cases.
00537  *
00538  * Revision 1.5  1998/06/25 08:50:10  joergr
00539  * Added compatibility mode to support ACR-NEMA images and wrong
00540  * palette attribute tags.
00541  *
00542  * Revision 1.4  1998/05/11 14:53:30  joergr
00543  * Added CVS/RCS header to each file.
00544  *
00545  *
00546  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5