OFFIS DCMTK  Version 3.6.0
diutils.h
1 /*
2  *
3  * Copyright (C) 1996-2010, 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: dcmimgle
15  *
16  * Author: Joerg Riesmeier
17  *
18  * Purpose: Utilities (Header)
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:16:27 $
22  * CVS/RCS Revision: $Revision: 1.42 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIUTILS_H
31 #define DIUTILS_H
32 
33 #include "dcmtk/config/osconfig.h"
34 
35 #include "dcmtk/ofstd/oftypes.h"
36 #include "dcmtk/ofstd/ofcast.h"
37 
38 #include "dcmtk/oflog/oflog.h"
39 
40 OFLogger DCM_dcmimgleGetLogger();
41 
42 #define DCMIMGLE_TRACE(msg) OFLOG_TRACE(DCM_dcmimgleGetLogger(), msg)
43 #define DCMIMGLE_DEBUG(msg) OFLOG_DEBUG(DCM_dcmimgleGetLogger(), msg)
44 #define DCMIMGLE_INFO(msg) OFLOG_INFO(DCM_dcmimgleGetLogger(), msg)
45 #define DCMIMGLE_WARN(msg) OFLOG_WARN(DCM_dcmimgleGetLogger(), msg)
46 #define DCMIMGLE_ERROR(msg) OFLOG_ERROR(DCM_dcmimgleGetLogger(), msg)
47 #define DCMIMGLE_FATAL(msg) OFLOG_FATAL(DCM_dcmimgleGetLogger(), msg)
48 
49 
50 /*---------------------*
51  * const definitions *
52  *---------------------*/
53 
58 
60 const unsigned long CIF_AcrNemaCompatibility = 0x0000001;
61 
63 const unsigned long CIF_WrongPaletteAttributeTags = 0x0000002;
64 
66 const unsigned long CIF_MayDetachPixelData = 0x0000004;
67 
69 const unsigned long CIF_UsePresentationState = 0x0000008;
70 
72 const unsigned long CIF_KeepYCbCrColorModel = 0x0000010;
73 
75 const unsigned long CIF_TakeOverExternalDataset = 0x0000020;
76 
78 const unsigned long CIF_IgnoreModalityTransformation = 0x0000040;
79 
81 const unsigned long CIF_IgnoreModalityLutBitDepth = 0x0000080;
82 
84 const unsigned long CIF_CheckLutBitDepth = 0x0000100;
85 
87 const unsigned long CIF_UseAbsolutePixelRange = 0x0000200;
88 
90 const unsigned long CIF_UsePartialAccessToPixelData = 0x0000400;
91 
93 const unsigned long CIF_DecompressCompletePixelData = 0x0000800;
94 
96 const unsigned long CIF_NeverAccessEmbeddedOverlays = 0x0001000;
98 
99 
100 // / true color color mode (for monochrome images only)
101 const int MI_PastelColor = -1;
102 
103 
104 /*--------------------*
105  * type definitions *
106  *--------------------*/
107 
110 enum EP_Interpretation
111 {
113  EPI_Unknown,
114  // no element value available
115  EPI_Missing,
117  EPI_Monochrome1,
119  EPI_Monochrome2,
121  EPI_PaletteColor,
123  EPI_RGB,
125  EPI_HSV,
127  EPI_ARGB,
129  EPI_CMYK,
131  EPI_YBR_Full,
133  EPI_YBR_Full_422,
135  EPI_YBR_Partial_422
136 };
137 
138 
142 {
144  const char *Name;
146  const char *DefinedTerm;
148  EP_Interpretation Type;
149 };
150 
151 
155 {
157  char bfType[2];
159  Uint32 bfSize;
161  Uint16 bfReserved1;
163  Uint16 bfReserved2;
165  Uint32 bfOffBits;
166 };
167 
168 
172 {
174  Uint32 biSize;
176  Sint32 biWidth;
178  Sint32 biHeight;
180  Uint16 biPlanes;
182  Uint16 biBitCount;
186  Uint32 biSizeImage;
192  Uint32 biClrUsed;
195 };
196 
197 
200 enum EP_Representation
201 {
203  EPR_Uint8, EPR_MinUnsigned = EPR_Uint8,
205  EPR_Sint8, EPR_MinSigned = EPR_Sint8,
207  EPR_Uint16,
209  EPR_Sint16,
211  EPR_Uint32, EPR_MaxUnsigned = EPR_Uint32,
213  EPR_Sint32, EPR_MaxSigned = EPR_Sint32
214 };
215 
216 
219 enum EI_Status
220 {
222  EIS_Normal,
224  EIS_NoDataDictionary,
226  EIS_InvalidDocument,
228  EIS_MissingAttribute,
230  EIS_InvalidValue,
232  EIS_NotSupportedValue,
234  EIS_MemoryFailure,
236  EIS_InvalidImage,
238  EIS_OtherError
239 };
240 
241 
245 enum EM_Overlay
246 {
248  EMO_Default,
250  EMO_Replace,
252  EMO_Graphic = EMO_Replace,
254  EMO_ThresholdReplace,
256  EMO_Complement,
258  EMO_InvertBitmap,
260  EMO_RegionOfInterest,
262  EMO_BitmapShutter
263 };
264 
265 
268 enum EF_VoiLutFunction
269 {
271  EFV_Default,
273  EFV_Linear,
275  EFV_Sigmoid
276 };
277 
278 
281 enum ES_PresentationLut
282 {
284  ESP_Default,
286  ESP_Identity,
288  ESP_Inverse,
290  ESP_LinOD
291 };
292 
293 
296 enum EP_Polarity
297 {
299  EPP_Normal,
301  EPP_Reverse
302 };
303 
304 
308 enum EL_BitsPerTableEntry
309 {
311  ELM_UseValue,
313  ELM_IgnoreValue,
315  ELM_CheckValue
316 };
317 
318 
319 /*----------------------------*
320  * constant initializations *
321  *----------------------------*/
322 
323 const SP_Interpretation PhotometricInterpretationNames[] =
324 {
325  {"MONOCHROME1", "MONOCHROME1", EPI_Monochrome1},
326  {"MONOCHROME2", "MONOCHROME2", EPI_Monochrome2},
327  {"PALETTECOLOR", "PALETTE COLOR", EPI_PaletteColor}, // space deleted to simplify detection
328  {"RGB", "RGB", EPI_RGB},
329  {"HSV", "HSV", EPI_HSV},
330  {"ARGB", "ARGB", EPI_ARGB},
331  {"CMYK", "CMYK", EPI_CMYK},
332  {"YBRFULL", "YBR_FULL", EPI_YBR_Full}, // underscore deleted to simplify detection
333  {"YBRFULL422", "YBR_FULL_422", EPI_YBR_Full_422}, // underscores deleted to simplify detection
334  {"YBRPARTIAL422", "YBR_PARTIAL_422", EPI_YBR_Partial_422}, // underscores deleted to simplify detection
335  {NULL, NULL, EPI_Unknown}
336 };
337 
338 
339 /*---------------------*
340  * macro definitions *
341  *---------------------*/
342 
343 #define MAX_UINT Uint32
344 #define MAX_SINT Sint32
345 
346 #define MAX_BITS 32
347 #define MAX_BITS_TYPE Uint32
348 #define MAX_RAWPPM_BITS 8
349 #define MAX_INTERPOLATION_BITS 16
350 
351 #define bitsof(expr) (sizeof(expr) << 3)
352 
353 
354 /*----------------------*
355  * class declarations *
356  *----------------------*/
357 
362 {
363 
364  public:
365 
373  static inline unsigned long maxval(const int mv_bits,
374  const unsigned long mv_pos = 1)
375  {
376  return (mv_bits < MAX_BITS) ?
377  (OFstatic_cast(unsigned long, 1) << mv_bits) - mv_pos : OFstatic_cast(MAX_BITS_TYPE, -1);
378  }
379 
387  static inline unsigned int tobits(unsigned long tb_value,
388  const unsigned long tb_pos = 1)
389  {
390  if (tb_value > 0)
391  tb_value -= tb_pos;
392  register unsigned int tb_bits = 0;
393  while (tb_value > 0)
394  {
395  ++tb_bits;
396  tb_value >>= 1;
397  }
398  return tb_bits;
399  }
400 
408  static unsigned int rangeToBits(double minvalue,
409  double maxvalue);
410 
417  static int isRepresentationSigned(EP_Representation repres);
418 
425  static unsigned int getRepresentationBits(EP_Representation repres);
426 
434  static EP_Representation determineRepresentation(double minvalue,
435  double maxvalue);
436 
437 };
438 
439 
440 #endif
441 
442 
443 /*
444  *
445  * CVS/RCS Log:
446  * $Log: diutils.h,v $
447  * Revision 1.42 2010-10-14 13:16:27 joergr
448  * Updated copyright header. Added reference to COPYRIGHT file.
449  *
450  * Revision 1.41 2010-10-05 15:24:02 joergr
451  * Added preliminary support for VOI LUT function. Please note, however, that
452  * the sigmoid transformation is not yet implemented.
453  *
454  * Revision 1.40 2010-03-01 09:08:47 uli
455  * Removed some unnecessary include directives in the headers.
456  *
457  * Revision 1.39 2010-02-23 16:31:34 joergr
458  * Added new helper function which determines whether an integer representation
459  * is signed or unsigned.
460  *
461  * Revision 1.38 2009-11-25 14:59:11 joergr
462  * Added list of Defined Terms for the attribute PhotometricInterpretation.
463  *
464  * Revision 1.37 2009-11-17 17:55:47 joergr
465  * Added new enum value for missing photometric interpretation value.
466  * Added new configuration flags for the upcoming support of partial access to
467  * pixel data, i.e. without decompressing/loading a complete multi-frame image.
468  *
469  * Revision 1.36 2009-10-28 14:38:17 joergr
470  * Fixed minor issues in log output.
471  *
472  * Revision 1.35 2009-10-28 09:53:40 uli
473  * Switched to logging mechanism provided by the "new" oflog module.
474  *
475  * Revision 1.34 2009-04-21 08:19:51 joergr
476  * Added new compatibility flag CIF_UseAbsolutePixelRange which changes the way
477  * the internal representation of monochrome images is determined.
478  *
479  * Revision 1.33 2009-04-20 12:19:40 joergr
480  * Added new helper function getRepresentationBits().
481  *
482  * Revision 1.32 2007/03/16 11:56:06 joergr
483  * Introduced new flag that allows to select how to handle the BitsPerTableEntry
484  * value in the LUT descriptor (use, ignore or check).
485  *
486  * Revision 1.31 2005/12/08 16:48:12 meichel
487  * Changed include path schema for all DCMTK header files
488  *
489  * Revision 1.30 2005/03/09 17:29:42 joergr
490  * Added support for new overlay mode "invert bitmap".
491  * Added new helper function rangeToBits().
492  *
493  * Revision 1.29 2004/11/29 16:52:22 joergr
494  * Removed email address from CVS log.
495  *
496  * Revision 1.28 2004/11/29 11:15:16 joergr
497  * Introduced new integer type MAX_BITS_TYPE for internal use.
498  *
499  * Revision 1.27 2004/11/25 09:38:43 meichel
500  * Fixed bug in DicomImageClass::maxval affecting 64-bit platforms.
501  *
502  * Revision 1.26 2004/08/03 11:41:50 meichel
503  * Headers libc.h and unistd.h are now included via ofstdinc.h
504  *
505  * Revision 1.25 2003/12/23 15:53:22 joergr
506  * Replaced post-increment/decrement operators by pre-increment/decrement
507  * operators where appropriate (e.g. 'i++' by '++i').
508  *
509  * Revision 1.24 2003/12/17 16:17:29 joergr
510  * Added new compatibility flag that allows to ignore the third value of LUT
511  * descriptors and to determine the bits per table entry automatically.
512  *
513  * Revision 1.23 2003/12/08 18:49:54 joergr
514  * Adapted type casts to new-style typecast operators defined in ofcast.h.
515  * Removed leading underscore characters from preprocessor symbols (reserved
516  * symbols). Updated copyright header.
517  *
518  * Revision 1.22 2003/05/20 09:19:51 joergr
519  * Added new configuration/compatibility flag that allows to ignore the
520  * modality transform stored in the dataset.
521  *
522  * Revision 1.21 2002/11/27 14:08:08 meichel
523  * Adapted module dcmimgle to use of new header file ofstdinc.h
524  *
525  * Revision 1.20 2002/06/26 16:08:14 joergr
526  * Added configuration flag that enables the DicomImage class to take the
527  * responsibility of an external DICOM dataset (i.e. delete it on destruction).
528  *
529  * Revision 1.19 2001/11/09 16:25:59 joergr
530  * Added support for Window BMP file format.
531  *
532  * Revision 1.18 2001/09/28 13:11:00 joergr
533  * Added new flag (CIF_KeepYCbCrColorModel) which avoids conversion of YCbCr
534  * color models to RGB.
535  *
536  * Revision 1.17 2001/06/01 15:49:52 meichel
537  * Updated copyright header
538  *
539  * Revision 1.16 2000/07/07 13:40:31 joergr
540  * Added support for LIN OD presentation LUT shape.
541  *
542  * Revision 1.15 2000/06/07 14:30:28 joergr
543  * Added method to set the image polarity (normal, reverse).
544  *
545  * Revision 1.14 2000/04/28 12:32:33 joergr
546  * DebugLevel - global for the module - now derived from OFGlobal (MF-safe).
547  *
548  * Revision 1.13 2000/03/08 16:24:25 meichel
549  * Updated copyright header.
550  *
551  * Revision 1.12 2000/02/23 15:12:16 meichel
552  * Corrected macro for Borland C++ Builder 4 workaround.
553  *
554  * Revision 1.11 2000/02/01 10:52:38 meichel
555  * Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4,
556  * workaround for bug in compiler header files.
557  *
558  * Revision 1.10 1999/09/17 13:08:13 joergr
559  * Added/changed/completed DOC++ style comments in the header files.
560  *
561  * Revision 1.9 1999/07/23 14:16:16 joergr
562  * Added flag to avoid color space conversion for color images (not yet
563  * implemented).
564  *
565  * Revision 1.8 1999/04/30 16:33:19 meichel
566  * Now including stdio.h in diutils.h, required on SunOS
567  *
568  * Revision 1.7 1999/04/28 14:55:41 joergr
569  * Added experimental support to create grayscale images with more than 256
570  * shades of gray to be displayed on a consumer monitor (use pastel colors).
571  *
572  * Revision 1.6 1999/03/24 17:20:28 joergr
573  * Added/Modified comments and formatting.
574  *
575  * Revision 1.5 1999/02/03 17:36:06 joergr
576  * Moved global functions maxval() and determineRepresentation() to class
577  * DicomImageClass (as static methods).
578  * Added BEGIN_EXTERN_C and END_EXTERN_C to some C includes.
579  *
580  * Revision 1.4 1999/01/20 15:13:12 joergr
581  * Added new overlay plane mode for bitmap shutters.
582  *
583  * Revision 1.3 1998/12/23 11:38:08 joergr
584  * Introduced new overlay mode item EMO_Graphic (= EMO_Replace).
585  *
586  * Revision 1.2 1998/12/16 16:40:15 joergr
587  * Some layouting.
588  *
589  * Revision 1.1 1998/11/27 15:51:45 joergr
590  * Added copyright message.
591  * Introduced global debug level for dcmimage module to control error output.
592  * Moved type definitions to diutils.h.
593  * Added methods to support presentation LUTs and shapes.
594  * Introduced configuration flags to adjust behaviour in different cases.
595  *
596  * Revision 1.5 1998/06/25 08:50:10 joergr
597  * Added compatibility mode to support ACR-NEMA images and wrong
598  * palette attribute tags.
599  *
600  * Revision 1.4 1998/05/11 14:53:30 joergr
601  * Added CVS/RCS header to each file.
602  *
603  *
604  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2