]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
* src/gdcmFile.[h|cxx], gdcmPixelReadConvert.[h|cxx] : change the API.
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/10 13:49:07 $
7   Version:   $Revision: 1.4 $
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 "gdcmException.h"
25
26 namespace gdcm
27 {
28 class Header;
29 class RLEFramesInfo;
30 class JPEGFragmentsInfo;
31 /*
32  * \brief Utility container for gathering the various forms the pixel data
33  *        migth take during the user demanded processes.
34  */
35 class GDCM_EXPORT PixelReadConvert
36 {
37 public:
38    PixelReadConvert();
39    virtual ~PixelReadConvert();
40
41    //// Getter accessors:
42    uint8_t* GetRGB() { return RGB; }
43    size_t   GetRGBSize() { return RGBSize; }
44    uint8_t* GetRaw() { return Raw; }
45    size_t   GetRawSize() { return RawSize; }
46    uint8_t* GetLutRGBA() { return LutRGBA; }
47
48    //// Predicates:
49    bool IsRawRGB();
50
51    void Print( std::string indent = "", std::ostream &os = std::cout );
52
53 // In progress
54    void GrabInformationsFromHeader( Header* header );
55    bool ReadAndDecompressPixelData( std::ifstream* fp );
56    void Squeeze();
57    bool BuildRGBImage();
58
59 private:
60    // Use the fp:
61    bool ReadAndDecompressRLEFragment(
62                   uint8_t* subDecompressed,
63                   long fragmentSize,
64                   long decompressedSegmentSize,
65                   std::ifstream* fp );
66    void ReadAndDecompress12BitsTo16Bits( std::ifstream* fp ) throw ( FormatError );
67    bool ReadAndDecompressRLEFile( std::ifstream* fp );
68    bool ReadAndDecompressJPEGFile( std::ifstream* fp );
69    void BuildLUTRGBA( std::ifstream* fp );
70
71    // In place (within Decompressed and with no fp access) decompression
72    // or convertion:
73    void BuildLUTRGBA();
74    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
75    void ConvertSwapZone();
76    void ConvertReorderEndianity();
77    bool ConvertReArrangeBits() throw ( FormatError );
78    void ConvertRGBPlanesToRGBPixels();
79    void ConvertYcBcRPlanesToRGBPixels();
80    void ConvertHandleColor();
81
82    void ComputeRawAndRGBSizes();
83    void AllocateRGB();
84    void AllocateRaw();
85
86 // Variables
87    /// Pixel data represented as RGB after LUT color interpretation.
88    uint8_t* RGB;
89    /// Size of \ref RGB image.
90    size_t   RGBSize;
91    /// Pixel data after decompression and bit/byte rearrangement.
92    uint8_t* Raw;
93    /// Size of \ref 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 IsJPEGLossless;
115    bool IsRLELossless;
116
117    RLEFramesInfo* RLEInfo;
118    JPEGFragmentsInfo* JPEGInfo;
119
120    // For handling color stage
121    int PlanarConfiguration;
122    bool IsMonochrome;
123    bool IsPaletteColor;
124    bool IsYBRFull;
125    bool HasLUT;
126    // The 3 LUT descriptors may be different:
127    std::string LutRedDescriptor;
128    std::string LutGreenDescriptor;
129    std::string LutBlueDescriptor;
130    uint8_t* LutRedData;
131    uint8_t* LutGreenData;
132    uint8_t* LutBlueData;
133
134 };
135 } // end namespace gdcm
136
137 //-----------------------------------------------------------------------------
138 #endif