]> Creatis software - gdcm.git/blob - src/gdcmPixelReadConvert.h
In order to avoid confusing user with 'public' methods he is not allowed to use,
[gdcm.git] / src / gdcmPixelReadConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/23 15:09:19 $
7   Version:   $Revision: 1.26 $
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 friend class FileHelper;
44
45 private:
46    PixelReadConvert();
47    virtual ~PixelReadConvert();
48
49    void Print( std::ostream &os = std::cout, std::string const &indent = "" );
50
51    // Getter accessors:
52    /// \brief returns pixel area holding RGB Pixels, made from Grey level + LUT
53    uint8_t *GetRGB()           { return RGB;     }
54    /// \brief returns pixel area length -RGB Pixels, (from Grey level + LUT)-
55    size_t   GetRGBSize()       { return RGBSize; }
56    /// \brief returns pixel area holding native RGB Pixels or Grey level
57    uint8_t *GetRaw()           { return Raw;     }
58    /// \brief returns pixel area size -native RGB Pixels or Grey level-
59    size_t   GetRawSize()       { return RawSize; }
60    /// \brief returns Red Green Blue Alpha LUT
61    uint8_t *GetLutRGBA()       { return LutRGBA; }
62    /// \brief returns Lut Item Number
63    int      GetLutItemNumber() { return LutItemNumber; }
64    /// \brief returns Lut Item Size
65    int      GetLutItemSize()   { return LutItemSize;   }
66    // Predicates:
67    bool IsRawRGB();
68
69 // In progress
70    void GrabInformationsFromFile( File *file );
71    bool ReadAndDecompressPixelData( std::ifstream *fp );
72    void Squeeze();
73    bool BuildRGBImage();
74    void BuildLUTRGBA();
75 /// \brief Allow user to pass his own function to modify pixels 
76 ///        (e.g; mirror, upsidedown, ...) just after reading
77    void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc ) 
78                          { UserFunction = userFunc; }
79
80    // Use the fp:
81    void ReadAndDecompress12BitsTo16Bits( std::ifstream *fp ) 
82                                  throw ( FormatError );
83    bool ReadAndDecompressJPEGFile( std::ifstream *fp );
84
85    // In place (within Decompressed and with no fp access) decompression
86    // or convertion:
87    void ConvertSwapZone();
88    void ConvertReorderEndianity();
89    bool ConvertReArrangeBits() throw ( FormatError );
90    void ConvertFixGreyLevels();
91    void ConvertRGBPlanesToRGBPixels();
92    void ConvertYcBcRPlanesToRGBPixels();
93    void ConvertHandleColor();
94
95    void ComputeRawAndRGBSizes();
96    void AllocateRGB();
97    void AllocateRaw();
98
99 // Variables
100 /**
101  * \brief Pixel data represented as RGB after LUT color interpretation.
102  *        'uint8_t' is just to avoid warnings at compile time.
103  *        feel free to cast it as uint16_t if you need
104  */ 
105    uint8_t *RGB;
106    /// Size of RGB image.
107    size_t   RGBSize;
108    /// Pixel data after decompression and bit/byte rearrangement.
109    uint8_t *Raw;
110    /// Size of Decompressed image.
111    size_t   RawSize;
112    /// \brief Red/Green/Blue/Alpha LookUpTable build out of the
113    ///        Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
114    uint8_t *LutRGBA;
115    int LutItemNumber;
116    int LutItemSize;
117
118    // *ALL* the following info belong to the FileHelper
119    // One should think there is an analyze error in the model !
120
121    size_t PixelOffset;
122    size_t PixelDataLength;
123    int XSize;
124    int YSize;
125    int ZSize;
126    int BitsAllocated;
127    int BitsStored;
128    int HighBitPosition;
129    int SamplesPerPixel;
130    //int PixelSize; // useless
131    bool PixelSign;
132    int SwapCode;
133
134    bool IsRaw;
135    bool IsPrivateGETransferSyntax;
136    bool IsJPEG2000;
137    bool IsJPEGLS;
138    bool IsJPEGLossless;
139    bool IsJPEGLossy;
140    bool IsJPEG;
141    bool IsRLELossless;
142    bool IsMPEG;
143
144    RLEFramesInfo *RLEInfo;
145    JPEGFragmentsInfo *JPEGInfo;
146
147    // For handling color stage
148    int PlanarConfiguration;
149    bool IsMonochrome;
150    bool IsMonochrome1;
151    bool IsPaletteColor;
152    bool IsYBRFull;
153    bool HasLUT;
154    // The 3 LUT descriptors may be different:
155    std::string LutRedDescriptor;
156    std::string LutGreenDescriptor;
157    std::string LutBlueDescriptor;
158    uint8_t *LutRedData;
159    uint8_t *LutGreenData;
160    uint8_t *LutBlueData;
161    
162    File *FileInternal; // must be passed to User Function
163    VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
164 };
165 } // end namespace gdcm
166
167 //-----------------------------------------------------------------------------
168 #endif