1 /*=========================================================================
2 
3   Program: GDCM (Grassroots DICOM). A DICOM library
4 
5   Copyright (c) 2006-2011 Mathieu Malaterre
6   All rights reserved.
7   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef GDCMICONIMAGEGENERATOR_H
15 #define GDCMICONIMAGEGENERATOR_H
16 
17 #include "gdcmPixmap.h"
18 #include "gdcmIconImage.h"
19 
20 namespace gdcm
21 {
22 class IconImageGeneratorInternals;
23 /**
24  * \brief IconImageGenerator
25  * \details This filter will generate a valid Icon from the Pixel Data element (an
26  * instance of Pixmap).
27  * To generate a valid Icon, one is only allowed the following Photometric
28  * Interpretation:
29  * - MONOCHROME1
30  * - MONOCHROME2
31  * - PALETTE_COLOR
32  *
33  * The Pixel Bits Allocated is restricted to 8bits, therefore 16 bits image
34  * needs to be rescaled. By default the filter will use the full scalar range
35  * of 16bits image to rescale to unsigned 8bits.
36  * This may not be ideal for some situation, in which case the API
37  * SetPixelMinMax can be used to overwrite the default min,max interval used.
38  *
39  * \see ImageReader
40  */
41 class GDCM_EXPORT IconImageGenerator
42 {
43 public:
44   IconImageGenerator();
45   ~IconImageGenerator();
46 
47   /// Set/Get File
SetPixmap(const Pixmap & p)48   void SetPixmap(const Pixmap& p) { P = p; }
GetPixmap()49   Pixmap &GetPixmap() { return *P; }
GetPixmap()50   const Pixmap &GetPixmap() const { return *P; }
51 
52   /// Set Target dimension of output Icon
53   void SetOutputDimensions(const unsigned int dims[2]);
54 
55   /// Override default min/max to compute best rescale for 16bits -> 8bits
56   /// downscale. Typically those value can be read from the SmallestImagePixelValue
57   /// LargestImagePixelValue DICOM attribute.
58   void SetPixelMinMax(double min, double max);
59 
60   /// Instead of explicitly specifying the min/max value for the rescale
61   /// operation, let the internal mechanism compute the min/max of icon and
62   /// rescale to best appropriate.
63   void AutoPixelMinMax(bool b);
64 
65   /// Converting from RGB to PALETTE_COLOR can be a slow operation. However DICOM
66   /// standard requires that color icon be described as palette. Set this boolean
67   /// to false only if you understand the consequences.
68   /// default value is true, false generates invalid Icon Image Sequence
69   void ConvertRGBToPaletteColor(bool b);
70 
71   /// Set a pixel value that should be discarded. This happen typically for CT image, where
72   /// a pixel has been used to pad outside the image (see Pixel Padding Value).
73   /// Requires AutoPixelMinMax(true)
74   void SetOutsideValuePixel(double v);
75 
76   /// Generate Icon
77   bool Generate();
78 
79   /// Retrieve generated Icon
GetIconImage()80   const IconImage& GetIconImage() const { return *I; }
81 
82 protected:
83 
84 private:
85   void BuildLUT( Bitmap & bitmap, unsigned int maxcolor );
86 
87   SmartPointer<Pixmap> P;
88   SmartPointer<IconImage> I;
89   IconImageGeneratorInternals *Internals;
90 };
91 
92 } // end namespace gdcm
93 
94 #endif //GDCMICONIMAGEGENERATOR_H
95