]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
Add some accessors for debugging purpose
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2005/06/17 12:35:00 $
7   Version:   $Revision: 1.23 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19
20 #ifndef GDCMPIXELREADCONVERT_H
21 #define GDCMPIXELREADCONVERT_H
22
23 #include "gdcmBase.h"
24 #include "gdcmException.h"
25 #include <fstream>
26
27 namespace gdcm
28 {
29 class File;
30 class RLEFramesInfo;
31 class JPEGFragmentsInfo;
32
33 /**
34  * \brief Utility container for gathering the various forms the pixel data
35  *        migth take during the user demanded processes.
36  */
37 class GDCM_EXPORT PixelReadConvert : public Base
38 {
39 public:
40    PixelReadConvert();
41    virtual ~PixelReadConvert();
42
43    void Print( std::ostream &os = std::cout, std::string const &indent = "" );
44
45    // Getter accessors:
46    uint8_t *GetRGB()           { return RGB;     }
47    size_t   GetRGBSize()       { return RGBSize; }
48    uint8_t *GetRaw()           { return Raw;     }
49    size_t   GetRawSize()       { return RawSize; }
50    uint8_t *GetLutRGBA()       { return LutRGBA; }
51    int      GetLutItemNumber() { return LutItemNumber; }
52    int      GetLutItemSize()   { return LutItemSize;   }
53    // Predicates:
54    bool IsRawRGB();
55
56 // In progress
57    void GrabInformationsFromFile( File *file );
58    bool ReadAndDecompressPixelData( std::ifstream *fp );
59    void Squeeze();
60    bool BuildRGBImage();
61    void BuildLUTRGBA();
62
63 private:
64    // Use the fp:
65    void ReadAndDecompress12BitsTo16Bits( std::ifstream *fp ) 
66                                  throw ( FormatError );
67    bool ReadAndDecompressJPEGFile( std::ifstream *fp );
68
69    // In place (within Decompressed and with no fp access) decompression
70    // or convertion:
71    void ConvertSwapZone();
72    void ConvertReorderEndianity();
73    bool ConvertReArrangeBits() throw ( FormatError );
74    void ConvertFixGreyLevels();
75    void ConvertRGBPlanesToRGBPixels();
76    void ConvertYcBcRPlanesToRGBPixels();
77    void ConvertHandleColor();
78
79    void ComputeRawAndRGBSizes();
80    void AllocateRGB();
81    void AllocateRaw();
82
83 // Variables
84 /**
85  * \brief Pixel data represented as RGB after LUT color interpretation.
86  *        'uint8_t' is just to avoid warnings at compile time.
87  *        feel free to cast it as uint16_t if you need
88  */ 
89    uint8_t *RGB;
90    /// Size of RGB image.
91    size_t   RGBSize;
92    /// Pixel data after decompression and bit/byte rearrangement.
93    uint8_t *Raw;
94    /// Size of Decompressed image.
95    size_t   RawSize;
96    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
97    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
98    uint8_t *LutRGBA;
99    int LutItemNumber;
100    int LutItemSize;
101
102    // *ALL* the following info belong to the FileHelper
103    // One should think there is an analyze error in the model !
104
105    size_t PixelOffset;
106    size_t PixelDataLength;
107    int XSize;
108    int YSize;
109    int ZSize;
110    int BitsAllocated;
111    int BitsStored;
112    int HighBitPosition;
113    int SamplesPerPixel;
114    int PixelSize;
115    bool PixelSign;
116    int SwapCode;
117
118    bool IsRaw;
119    bool IsJPEG2000;
120    bool IsJPEGLS;
121    bool IsJPEGLossless;
122    bool IsJPEGLossy;
123    bool IsJPEG;
124    bool IsRLELossless;
125    bool IsMPEG;
126
127    RLEFramesInfo *RLEInfo;
128    JPEGFragmentsInfo *JPEGInfo;
129
130    // For handling color stage
131    int PlanarConfiguration;
132    bool IsMonochrome;
133    bool IsMonochrome1;
134    bool IsPaletteColor;
135    bool IsYBRFull;
136    bool HasLUT;
137    // The 3 LUT descriptors may be different:
138    std::string LutRedDescriptor;
139    std::string LutGreenDescriptor;
140    std::string LutBlueDescriptor;
141    uint8_t *LutRedData;
142    uint8_t *LutGreenData;
143    uint8_t *LutBlueData;
144 };
145 } // end namespace gdcm
146
147 //-----------------------------------------------------------------------------
148 #endif