]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
Oops.
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/20 08:29:50 $
7   Version:   $Revision: 1.25 $
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 "gdcmBase.h"
24 #include "gdcmException.h"
25 #include <fstream>
26
27 namespace gdcm
28 {
29 class File;
30 class RLEFramesInfo;
31 class JPEGFragmentsInfo;
32
33 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *);
34
35 /**
36  * \brief Utility container for gathering the various forms the pixel data
37  *        migth take during the user demanded processes.
38  * WARNING : *none* of these functions may be invoked by gdm user
39  *           (internal use only)
40  */
41 class GDCM_EXPORT PixelReadConvert : public Base
42 {
43 public:
44    PixelReadConvert();
45    virtual ~PixelReadConvert();
46
47    void Print( std::ostream &os = std::cout, std::string const &indent = "" );
48
49    // Getter accessors:
50    uint8_t *GetRGB()           { return RGB;     }
51    size_t   GetRGBSize()       { return RGBSize; }
52    uint8_t *GetRaw()           { return Raw;     }
53    size_t   GetRawSize()       { return RawSize; }
54    uint8_t *GetLutRGBA()       { return LutRGBA; }
55    int      GetLutItemNumber() { return LutItemNumber; }
56    int      GetLutItemSize()   { return LutItemSize;   }
57    // Predicates:
58    bool IsRawRGB();
59
60 // In progress
61    void GrabInformationsFromFile( File *file );
62    bool ReadAndDecompressPixelData( std::ifstream *fp );
63    void Squeeze();
64    bool BuildRGBImage();
65    void BuildLUTRGBA();
66
67    void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc ) 
68                          { UserFunction = userFunc; }
69 private:
70    // Use the fp:
71    void ReadAndDecompress12BitsTo16Bits( std::ifstream *fp ) 
72                                  throw ( FormatError );
73    bool ReadAndDecompressJPEGFile( std::ifstream *fp );
74
75    // In place (within Decompressed and with no fp access) decompression
76    // or convertion:
77    void ConvertSwapZone();
78    void ConvertReorderEndianity();
79    bool ConvertReArrangeBits() throw ( FormatError );
80    void ConvertFixGreyLevels();
81    void ConvertRGBPlanesToRGBPixels();
82    void ConvertYcBcRPlanesToRGBPixels();
83    void ConvertHandleColor();
84
85    void ComputeRawAndRGBSizes();
86    void AllocateRGB();
87    void AllocateRaw();
88
89 // Variables
90 /**
91  * \brief Pixel data represented as RGB after LUT color interpretation.
92  *        'uint8_t' is just to avoid warnings at compile time.
93  *        feel free to cast it as uint16_t if you need
94  */ 
95    uint8_t *RGB;
96    /// Size of RGB image.
97    size_t   RGBSize;
98    /// Pixel data after decompression and bit/byte rearrangement.
99    uint8_t *Raw;
100    /// Size of Decompressed image.
101    size_t   RawSize;
102    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
103    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
104    uint8_t *LutRGBA;
105    int LutItemNumber;
106    int LutItemSize;
107
108    // *ALL* the following info belong to the FileHelper
109    // One should think there is an analyze error in the model !
110
111    size_t PixelOffset;
112    size_t PixelDataLength;
113    int XSize;
114    int YSize;
115    int ZSize;
116    int BitsAllocated;
117    int BitsStored;
118    int HighBitPosition;
119    int SamplesPerPixel;
120    //int PixelSize; // useless
121    bool PixelSign;
122    int SwapCode;
123
124    bool IsRaw;
125    bool IsPrivateGETransferSyntax;
126    bool IsJPEG2000;
127    bool IsJPEGLS;
128    bool IsJPEGLossless;
129    bool IsJPEGLossy;
130    bool IsJPEG;
131    bool IsRLELossless;
132    bool IsMPEG;
133
134    RLEFramesInfo *RLEInfo;
135    JPEGFragmentsInfo *JPEGInfo;
136
137    // For handling color stage
138    int PlanarConfiguration;
139    bool IsMonochrome;
140    bool IsMonochrome1;
141    bool IsPaletteColor;
142    bool IsYBRFull;
143    bool HasLUT;
144    // The 3 LUT descriptors may be different:
145    std::string LutRedDescriptor;
146    std::string LutGreenDescriptor;
147    std::string LutBlueDescriptor;
148    uint8_t *LutRedData;
149    uint8_t *LutGreenData;
150    uint8_t *LutBlueData;
151    
152    File *FileInternal; // must be passed to User Function
153    VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
154 };
155 } // end namespace gdcm
156
157 //-----------------------------------------------------------------------------
158 #endif