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