]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
Now gdcm deals with 16 bits per pixel images with 16 bits Palette colors
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2005/06/14 13:56:42 $
7   Version:   $Revision: 1.22 $
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
52    // Predicates:
53    bool IsRawRGB();
54
55 // In progress
56    void GrabInformationsFromFile( File *file );
57    bool ReadAndDecompressPixelData( std::ifstream *fp );
58    void Squeeze();
59    bool BuildRGBImage();
60
61 private:
62    // Use the fp:
63    void ReadAndDecompress12BitsTo16Bits( std::ifstream *fp ) 
64                                  throw ( FormatError );
65    bool ReadAndDecompressJPEGFile( std::ifstream *fp );
66
67    // In place (within Decompressed and with no fp access) decompression
68    // or convertion:
69    void BuildLUTRGBA();
70    void ConvertSwapZone();
71    void ConvertReorderEndianity();
72    bool ConvertReArrangeBits() throw ( FormatError );
73    void ConvertFixGreyLevels();
74    void ConvertRGBPlanesToRGBPixels();
75    void ConvertYcBcRPlanesToRGBPixels();
76    void ConvertHandleColor();
77
78    void ComputeRawAndRGBSizes();
79    void AllocateRGB();
80    void AllocateRaw();
81
82 // Variables
83 /**
84  * \brief Pixel data represented as RGB after LUT color interpretation.
85  *        'uint8_t' is just to avoid warnings at compile time.
86  *        feel free to cast it as uint16_t if you need
87  */ 
88    uint8_t *RGB;
89    /// Size of RGB image.
90    size_t   RGBSize;
91    /// Pixel data after decompression and bit/byte rearrangement.
92    uint8_t *Raw;
93    /// Size of Decompressed image.
94    size_t   RawSize;
95    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
96    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
97    uint8_t *LutRGBA;
98
99    size_t PixelOffset;
100    size_t PixelDataLength;
101    int XSize;
102    int YSize;
103    int ZSize;
104    int BitsAllocated;
105    int BitsStored;
106    int HighBitPosition;
107    int SamplesPerPixel;
108    int PixelSize;
109    bool PixelSign;
110    int SwapCode;
111
112    bool IsRaw;
113    bool IsJPEG2000;
114    bool IsJPEGLS;
115    bool IsJPEGLossless;
116    bool IsJPEGLossy;
117    bool IsJPEG;
118    bool IsRLELossless;
119    bool IsMPEG;
120
121    RLEFramesInfo *RLEInfo;
122    JPEGFragmentsInfo *JPEGInfo;
123
124    // For handling color stage
125    int PlanarConfiguration;
126    bool IsMonochrome;
127    bool IsMonochrome1;
128    bool IsPaletteColor;
129    bool IsYBRFull;
130    bool HasLUT;
131    // The 3 LUT descriptors may be different:
132    std::string LutRedDescriptor;
133    std::string LutGreenDescriptor;
134    std::string LutBlueDescriptor;
135    uint8_t *LutRedData;
136    uint8_t *LutGreenData;
137    uint8_t *LutBlueData;
138
139 };
140 } // end namespace gdcm
141
142 //-----------------------------------------------------------------------------
143 #endif