]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
ENH: Huge commit to remove the previous implementation for jpeg/fragments/multiframes...
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2005/01/31 03:22:26 $
7   Version:   $Revision: 1.15 $
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 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    //// 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 GrabInformationsFromFile( File *file );
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
72    void BuildLUTRGBA( std::ifstream *fp );
73
74    // In place (within Decompressed and with no fp access) decompression
75    // or convertion:
76    void BuildLUTRGBA();
77    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
78    void ConvertSwapZone();
79    void ConvertReorderEndianity();
80    bool ConvertReArrangeBits() throw ( FormatError );
81    void ConvertRGBPlanesToRGBPixels();
82    void ConvertYcBcRPlanesToRGBPixels();
83    void ConvertHandleColor();
84
85    void ComputeRawAndRGBSizes();
86    void AllocateRGB();
87    void AllocateRaw();
88
89 // Variables
90    /// Pixel data represented as RGB after LUT color interpretation.
91    uint8_t *RGB;
92    /// Size of RGB image.
93    size_t   RGBSize;
94    /// Pixel data after decompression and bit/byte rearrangement.
95    uint8_t *Raw;
96    /// Size of Decompressed image.
97    size_t   RawSize;
98    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
99    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
100    uint8_t *LutRGBA;
101
102    size_t PixelOffset;
103    size_t PixelDataLength;
104    int XSize;
105    int YSize;
106    int ZSize;
107    int BitsAllocated;
108    int BitsStored;
109    int HighBitPosition;
110    int SamplesPerPixel;
111    int PixelSize;
112    bool PixelSign;
113    int SwapCode;
114
115    bool IsRaw;
116    bool IsJPEG2000;
117    bool IsJPEGLS;
118    bool IsJPEGLossless;
119    bool IsJPEGLossy;
120    bool IsJPEG;
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