]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
* src/gdcmFile.[h|cxx] : add the Print method
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/16 11:37:03 $
7   Version:   $Revision: 1.6 $
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::ostream &os = std::cout );
52    void Print( std::string indent = "", std::ostream &os = std::cout );
53
54 // In progress
55    void GrabInformationsFromHeader( Header* header );
56    bool ReadAndDecompressPixelData( std::ifstream* fp );
57    void Squeeze();
58    bool BuildRGBImage();
59
60 private:
61    // Use the fp:
62    bool ReadAndDecompressRLEFragment(
63                   uint8_t* subDecompressed,
64                   long fragmentSize,
65                   long decompressedSegmentSize,
66                   std::ifstream* fp );
67    void ReadAndDecompress12BitsTo16Bits( std::ifstream* fp ) throw ( FormatError );
68    bool ReadAndDecompressRLEFile( std::ifstream* fp );
69    bool ReadAndDecompressJPEGFile( std::ifstream* fp );
70    bool ReadAndDecompressJPEGFramesFromFile( std::ifstream* fp );
71    bool ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream* fp );
72    bool ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream* fp );
73
74
75    void BuildLUTRGBA( std::ifstream* fp );
76
77    // In place (within Decompressed and with no fp access) decompression
78    // or convertion:
79    void BuildLUTRGBA();
80    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
81    void ConvertSwapZone();
82    void ConvertReorderEndianity();
83    bool ConvertReArrangeBits() throw ( FormatError );
84    void ConvertRGBPlanesToRGBPixels();
85    void ConvertYcBcRPlanesToRGBPixels();
86    void ConvertHandleColor();
87
88    void ComputeRawAndRGBSizes();
89    void AllocateRGB();
90    void AllocateRaw();
91
92 // Variables
93    /// Pixel data represented as RGB after LUT color interpretation.
94    uint8_t* RGB;
95    /// Size of \ref RGB image.
96    size_t   RGBSize;
97    /// Pixel data after decompression and bit/byte rearrangement.
98    uint8_t* Raw;
99    /// Size of \ref Decompressed image.
100    size_t   RawSize;
101    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
102    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
103    uint8_t* LutRGBA;
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 IsJPEGLossless;
121    bool IsRLELossless;
122
123    RLEFramesInfo* RLEInfo;
124    JPEGFragmentsInfo* JPEGInfo;
125
126    // For handling color stage
127    int PlanarConfiguration;
128    bool IsMonochrome;
129    bool IsPaletteColor;
130    bool IsYBRFull;
131    bool HasLUT;
132    // The 3 LUT descriptors may be different:
133    std::string LutRedDescriptor;
134    std::string LutGreenDescriptor;
135    std::string LutBlueDescriptor;
136    uint8_t* LutRedData;
137    uint8_t* LutGreenData;
138    uint8_t* LutBlueData;
139
140 };
141 } // end namespace gdcm
142
143 //-----------------------------------------------------------------------------
144 #endif