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