]> Creatis software - gdcm.git/blob - src/gdcmPixelConvert.h
e65a701c0470924d1c532f48af57be3adcadb175
[gdcm.git] / src / gdcmPixelConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/10/18 12:49:23 $
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 GDCMPIXELCONVERT_H
21 #define GDCMPIXELCONVERTL_H
22
23 #include "gdcmCommon.h"
24 #include "gdcmRLEFramesInfo.h"
25 #include "gdcmJPEGFragmentsInfo.h"
26 #include "gdcmException.h"
27 #include "gdcmHeader.h"
28
29 namespace gdcm
30 {
31                                                                                 
32 /*
33  * \brief Utility container for gathering the various forms the pixel data
34  *        migth take during the user demanded processes.
35  */
36 class GDCM_EXPORT PixelConvert {
37 public:
38    PixelConvert();
39    ~PixelConvert();
40
41    //// Getter accessors:
42    uint8_t* GetRGB() { return RGB; }
43    size_t   GetRGBSize() { return RGBSize; }
44    uint8_t* GetDecompressed() { return Decompressed; }
45    size_t   GetDecompressedSize() { return DecompressedSize; }
46    uint8_t* GetLutRGBA() { return LutRGBA; }
47
48    //// Predicates:
49    bool IsDecompressedRGB();
50
51 // In progress
52    void GrabInformationsFromHeader( Header* header );
53    bool ReadAndDecompressPixelData( FILE* fp );
54    void Squeeze();
55    bool BuildRGBImage( FILE* fp );
56
57 private:
58    // Use the fp:
59    bool ReadAndDecompressRLEFragment(
60                   uint8_t* subDecompressed,
61                   long fragmentSize,
62                   long decompressedSegmentSize,
63                   FILE* fp );
64    void ReadAndDecompress12BitsTo16Bits( FILE* fp ) throw ( FormatError );
65    bool ReadAndDecompressRLEFile( FILE* fp );
66    bool ReadAndDecompressJPEGFile( FILE* fp );
67    void BuildLUTRGBA( FILE* fp );
68
69    // In place (within Decompressed and with no fp access) decompression
70    // or convertion:
71    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
72    void ConvertSwapZone();
73    void ConvertReorderEndianity();
74    bool ConvertReArrangeBits() throw ( FormatError );
75    void ConvertRGBPlanesToRGBPixels();
76    void ConvertYcBcRPlanesToRGBPixels();
77    void ConvertHandleColor();
78
79    void ComputeDecompressedAndRGBSizes();
80    void AllocateRGB();
81    void AllocateDecompressed();
82
83 // Variables
84    /// Pixel data represented as RGB after LUT color interpretation.
85    uint8_t* RGB;
86    /// Size of \ref RGB image.
87    size_t   RGBSize;
88    /// Pixel data after decompression and bit/byte rearrangement.
89    uint8_t* Decompressed;
90    /// Size of \ref Decompressed image.
91    size_t   DecompressedSize;
92    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
93    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
94    uint8_t* LutRGBA;
95
96    size_t PixelOffset;
97    size_t PixelDataLength;
98    int XSize;
99    int YSize;
100    int ZSize;
101    int BitsAllocated;
102    int BitsStored;
103    int HighBitPosition;
104    int SamplesPerPixel;
105    int PixelSize;
106    bool PixelSign;
107    int SwapCode;
108
109    bool IsDecompressed;
110    bool IsJPEG2000;
111    bool IsJPEGLossless;
112    bool IsRLELossless;
113
114    RLEFramesInfo* RLEInfo;
115    JPEGFragmentsInfo* JPEGInfo;
116
117    // For handling color stage
118    int PlanarConfiguration;
119    bool IsMonochrome;
120    bool IsPaletteColor;
121    bool IsYBRFull;
122    bool HasLUT;
123    // The 3 LUT descriptors may be different:
124    std::string LutRedDescriptor;
125    std::string LutGreenDescriptor;
126    std::string LutBlueDescriptor;
127    uint8_t* LutRedData;
128    uint8_t* LutGreenData;
129    uint8_t* LutBlueData;
130
131 };
132 } // end namespace gdcm
133
134 //-----------------------------------------------------------------------------
135 #endif