]> Creatis software - gdcm.git/blob - src/gdcmPixelConvert.h
* src/gdcmDebug.cxx last ditch attempt to get warning/error messages
[gdcm.git] / src / gdcmPixelConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/10/15 10:43:28 $
7   Version:   $Revision: 1.9 $
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
28 namespace gdcm
29 {
30                                                                                 
31 /*
32  * \brief Utility container for gathering the various forms the pixel data
33  *        migth take during the user demanded processes.
34  */
35 class GDCM_EXPORT PixelConvert {
36 friend class File;
37    /// Pixel data represented as RGB after color interpretation
38    uint8_t* RGB;
39    size_t   RGBSize;          //aka ImageDataSize
40    /// Pixel data after decompression and bit/byte rearrangement.
41    uint8_t* Decompressed;
42    size_t   DecompressedSize;
43
44    // Set by the accessors:
45    size_t PixelOffset;
46    size_t PixelDataLength;
47    int XSize;
48    int YSize;
49    int ZSize;
50    int BitsAllocated;
51    int BitsStored;
52    int HighBitPosition;
53    int SamplesPerPixel;
54    int PixelSize;
55    bool PixelSign;
56    int SwapCode;
57
58    bool IsUncompressed;
59    bool IsJPEG2000;
60    bool IsJPEGLossless;
61    bool IsRLELossless;
62
63    RLEFramesInfo* RLEInfo;
64    JPEGFragmentsInfo* JPEGInfo;
65
66    // For handling color stage
67    int PlanarConfiguration;
68    bool IsMonochrome;
69    bool IsPaletteColor;
70    bool IsYBRFull;
71    bool HasLUT;
72
73 public:
74    PixelConvert();
75    ~PixelConvert();
76
77    //// Setter accessors:
78    void SetXSize( int xSize ) { XSize = xSize; }
79    void SetYSize( int ySize ) { YSize = ySize; }
80    void SetZSize( int zSize ) { ZSize = zSize; }
81    void SetBitsAllocated( int bitsAllocated ) { BitsAllocated = bitsAllocated; }
82    void SetBitsStored( int bitsStored ) { BitsStored = bitsStored; }
83    void SetHighBitPosition( int highBitPosition )
84            { HighBitPosition = highBitPosition; }
85    void SetSamplesPerPixel( int samplesPerPixel )
86            { SamplesPerPixel = samplesPerPixel; }
87    void SetPixelSize( int pixelSize ) { PixelSize = pixelSize; }
88    void SetPixelSign( int pixelSign ) { PixelSign = pixelSign; }
89    void SetSwapCode( int swapCode ) { SwapCode = swapCode; }
90    void SetIsUncompressed( bool isUncompressed )
91            { IsUncompressed = isUncompressed; }
92    void SetIsJPEG2000( bool isJPEG2000 ) { IsJPEG2000 = isJPEG2000; }
93    void SetIsJPEGLossless( bool isJPEGLossless )
94            { IsJPEGLossless = isJPEGLossless; }
95    void SetIsRLELossless( bool isRLELossless )
96            { IsRLELossless = isRLELossless; }
97    void SetPixelOffset( size_t pixelOffset ) { PixelOffset = pixelOffset; }
98    void SetPixelDataLength( size_t pixelDataLength )
99            { PixelDataLength = pixelDataLength; }
100    void SetRLEInfo( RLEFramesInfo* inRLEFramesInfo )
101            { RLEInfo = inRLEFramesInfo; }
102    void SetJPEGInfo( JPEGFragmentsInfo* inJPEGFragmentsInfo )
103            { JPEGInfo = inJPEGFragmentsInfo; }
104
105    void SetPlanarConfiguration( size_t planarConfiguration )
106            { PlanarConfiguration = planarConfiguration; }
107    void SetIsMonochrome( bool isMonochrome ) { IsMonochrome = isMonochrome; }
108    void SetIsPaletteColor( bool isPaletteColor )
109            { IsPaletteColor = isPaletteColor; }
110    void SetIsYBRFull( bool isYBRFull ) { IsYBRFull = isYBRFull; }
111    void SetHasLUT ( bool hasLUT ) { HasLUT = hasLUT; }
112  
113    void     SetRGBSize( size_t size ) { RGBSize = size; }
114    void     SetDecompressedSize( size_t size ) { DecompressedSize = size; }
115
116    //// Getter accessors:
117    uint8_t* GetRGB() { return RGB; }
118    size_t   GetRGBSize() { return RGBSize; }
119    uint8_t* GetDecompressed() { return Decompressed; }
120    size_t   GetDecompressedSize() { return DecompressedSize; }
121
122    //// Predicates:
123    bool IsDecompressedRGB();
124
125 //////////////////////////////////////////////////////////
126 private:
127    // Use the fp:
128    bool ReadAndDecompressRLEFragment(
129                   uint8_t* decodedZone,
130                   long fragmentSize,
131                   long uncompressedSegmentSize,
132                   FILE* fp );
133    void ReadAndDecompress12BitsTo16Bits( FILE* fp ) throw ( FormatError );
134    bool ReadAndDecompressRLEFile( FILE* fp );
135    bool ReadAndDecompressJPEGFile( FILE* fp );
136
137    // In place (within Decompressed and with no fp access) decompression
138    // or convertion:
139    bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames );
140    void ConvertSwapZone();
141    void ConvertReorderEndianity();
142    bool ConvertReArrangeBits() throw ( FormatError );
143    void ConvertRGBPlanesToRGBPixels();
144    void ConvertYcBcRPlanesToRGBPixels();
145    void ConvertHandleColor();
146
147    void ComputeDecompressedImageDataSize();
148    void AllocateRGB();
149    void AllocateDecompressed();
150 public:
151 // In progress
152    bool ReadAndDecompressPixelData( FILE* fp );
153    void Squeeze();
154 };
155 } // end namespace gdcm
156
157 //-----------------------------------------------------------------------------
158 #endif