]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
* FIX: new handling of JPEG decompression, especially when dicom
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/12 17:21:07 $
7   Version:   $Revision: 1.5 $
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    bool ReadAndDecompressJPEGFramesFromFile( std::ifstream* fp );
70    bool ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream* fp );
71    bool ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream* fp );
72
73
74    void BuildLUTRGBA( std::ifstream* fp );
75
76    // In place (within Decompressed and with no fp access) decompression
77    // or convertion:
78    void BuildLUTRGBA();
79    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
80    void ConvertSwapZone();
81    void ConvertReorderEndianity();
82    bool ConvertReArrangeBits() throw ( FormatError );
83    void ConvertRGBPlanesToRGBPixels();
84    void ConvertYcBcRPlanesToRGBPixels();
85    void ConvertHandleColor();
86
87    void ComputeRawAndRGBSizes();
88    void AllocateRGB();
89    void AllocateRaw();
90
91 // Variables
92    /// Pixel data represented as RGB after LUT color interpretation.
93    uint8_t* RGB;
94    /// Size of \ref RGB image.
95    size_t   RGBSize;
96    /// Pixel data after decompression and bit/byte rearrangement.
97    uint8_t* Raw;
98    /// Size of \ref Decompressed image.
99    size_t   RawSize;
100    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
101    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
102    uint8_t* LutRGBA;
103
104    size_t PixelOffset;
105    size_t PixelDataLength;
106    int XSize;
107    int YSize;
108    int ZSize;
109    int BitsAllocated;
110    int BitsStored;
111    int HighBitPosition;
112    int SamplesPerPixel;
113    int PixelSize;
114    bool PixelSign;
115    int SwapCode;
116
117    bool IsRaw;
118    bool IsJPEG2000;
119    bool IsJPEGLossless;
120    bool IsRLELossless;
121
122    RLEFramesInfo* RLEInfo;
123    JPEGFragmentsInfo* JPEGInfo;
124
125    // For handling color stage
126    int PlanarConfiguration;
127    bool IsMonochrome;
128    bool IsPaletteColor;
129    bool IsYBRFull;
130    bool HasLUT;
131    // The 3 LUT descriptors may be different:
132    std::string LutRedDescriptor;
133    std::string LutGreenDescriptor;
134    std::string LutBlueDescriptor;
135    uint8_t* LutRedData;
136    uint8_t* LutGreenData;
137    uint8_t* LutBlueData;
138
139 };
140 } // end namespace gdcm
141
142 //-----------------------------------------------------------------------------
143 #endif