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