]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
1372220154dbff8bb686a8cc16c668a835eb1d68
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2005/01/16 04:50:42 $
7   Version:   $Revision: 1.11 $
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 "gdcmCommon.h"
24 #include "gdcmBase.h"
25 #include "gdcmException.h"
26
27 namespace gdcm
28 {
29 class Header;
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    //// Getter accessors:
44    uint8_t* GetRGB() { return RGB; }
45    size_t   GetRGBSize() { return RGBSize; }
46    uint8_t* GetRaw() { return Raw; }
47    size_t   GetRawSize() { return RawSize; }
48    uint8_t* GetLutRGBA() { return LutRGBA; }
49
50    //// Predicates:
51    bool IsRawRGB();
52
53    void Print( std::ostream &os = std::cout, std::string const & indent = "" );
54
55 // In progress
56    void GrabInformationsFromHeader( Header *header );
57    bool ReadAndDecompressPixelData( std::ifstream *fp );
58    void Squeeze();
59    bool BuildRGBImage();
60
61 private:
62    // Use the fp:
63    bool ReadAndDecompressRLEFragment(
64                   uint8_t *subDecompressed,
65                   long fragmentSize,
66                   long decompressedSegmentSize,
67                   std::ifstream *fp );
68    void ReadAndDecompress12BitsTo16Bits( std::ifstream *fp ) throw ( FormatError );
69    bool ReadAndDecompressRLEFile( std::ifstream *fp );
70    bool ReadAndDecompressJPEGFile( std::ifstream *fp );
71    bool ReadAndDecompressJPEGFramesFromFile( std::ifstream *fp );
72    bool ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream *fp );
73    bool ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp );
74
75
76    void BuildLUTRGBA( std::ifstream *fp );
77
78    // In place (within Decompressed and with no fp access) decompression
79    // or convertion:
80    void BuildLUTRGBA();
81    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
82    void ConvertSwapZone();
83    void ConvertReorderEndianity();
84    bool ConvertReArrangeBits() throw ( FormatError );
85    void ConvertRGBPlanesToRGBPixels();
86    void ConvertYcBcRPlanesToRGBPixels();
87    void ConvertHandleColor();
88
89    void ComputeRawAndRGBSizes();
90    void AllocateRGB();
91    void AllocateRaw();
92
93 // Variables
94    /// Pixel data represented as RGB after LUT color interpretation.
95    uint8_t *RGB;
96    /// Size of RGB image.
97    size_t   RGBSize;
98    /// Pixel data after decompression and bit/byte rearrangement.
99    uint8_t *Raw;
100    /// Size of Decompressed image.
101    size_t   RawSize;
102    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
103    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
104    uint8_t *LutRGBA;
105
106    size_t PixelOffset;
107    size_t PixelDataLength;
108    int XSize;
109    int YSize;
110    int ZSize;
111    int BitsAllocated;
112    int BitsStored;
113    int HighBitPosition;
114    int SamplesPerPixel;
115    int PixelSize;
116    bool PixelSign;
117    int SwapCode;
118
119    bool IsRaw;
120    bool IsJPEG2000;
121    bool IsJPEGLossless;
122    bool IsRLELossless;
123
124    RLEFramesInfo *RLEInfo;
125    JPEGFragmentsInfo *JPEGInfo;
126
127    // For handling color stage
128    int PlanarConfiguration;
129    bool IsMonochrome;
130    bool IsPaletteColor;
131    bool IsYBRFull;
132    bool HasLUT;
133    // The 3 LUT descriptors may be different:
134    std::string LutRedDescriptor;
135    std::string LutGreenDescriptor;
136    std::string LutBlueDescriptor;
137    uint8_t *LutRedData;
138    uint8_t *LutGreenData;
139    uint8_t *LutBlueData;
140
141 };
142 } // end namespace gdcm
143
144 //-----------------------------------------------------------------------------
145 #endif