]> Creatis software - gdcm.git/blob - src/gdcmPixelConvert.h
9c67e06af10ed558a62ff570055e32fdcf701c1e
[gdcm.git] / src / gdcmPixelConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/10/13 14:15:30 $
7   Version:   $Revision: 1.8 $
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
72 private:
73    bool ReadAndUncompressRLEFragment(
74                   uint8_t* decodedZone,
75                   long fragmentSize,
76                   long uncompressedSegmentSize,
77                   FILE* fp );
78 public:
79    PixelConvert();
80    ~PixelConvert();
81
82    void SetXSize( int xSize ) { XSize = xSize; }
83    void SetYSize( int ySize ) { YSize = ySize; }
84    void SetZSize( int zSize ) { ZSize = zSize; }
85    void SetBitsAllocated( int bitsAllocated ) { BitsAllocated = bitsAllocated; }
86    void SetBitsStored( int bitsStored ) { BitsStored = bitsStored; }
87    void SetHighBitPosition( int highBitPosition )
88            { HighBitPosition = highBitPosition; }
89    void SetSamplesPerPixel( int samplesPerPixel )
90            { SamplesPerPixel = samplesPerPixel; }
91    void SetPixelSize( int pixelSize ) { PixelSize = pixelSize; }
92    void SetPixelSign( int pixelSign ) { PixelSign = pixelSign; }
93    void SetSwapCode( int swapCode ) { SwapCode = swapCode; }
94    void SetIsUncompressed( bool isUncompressed )
95            { IsUncompressed = isUncompressed; }
96    void SetIsJPEG2000( bool isJPEG2000 ) { IsJPEG2000 = isJPEG2000; }
97    void SetIsJPEGLossless( bool isJPEGLossless )
98            { IsJPEGLossless = isJPEGLossless; }
99    void SetIsRLELossless( bool isRLELossless )
100            { IsRLELossless = isRLELossless; }
101    void SetPixelOffset( size_t pixelOffset ) { PixelOffset = pixelOffset; }
102    void SetPixelDataLength( size_t pixelDataLength )
103            { PixelDataLength = pixelDataLength; }
104    void SetRLEInfo( RLEFramesInfo* inRLEFramesInfo )
105            { RLEInfo = inRLEFramesInfo; }
106    void SetJPEGInfo( JPEGFragmentsInfo* inJPEGFragmentsInfo )
107            { JPEGInfo = inJPEGFragmentsInfo; }
108
109    void SetPlanarConfiguration( size_t planarConfiguration )
110            { PlanarConfiguration = planarConfiguration; }
111    void SetIsMonochrome( bool isMonochrome ) { IsMonochrome = isMonochrome; }
112    void SetIsPaletteColor( bool isPaletteColor )
113            { IsPaletteColor = isPaletteColor; }
114    void SetIsYBRFull( bool isYBRFull ) { IsYBRFull = isYBRFull; }
115
116    uint8_t* GetRGB() { return RGB; }
117    void     SetRGBSize( size_t size ) { RGBSize = size; }
118    size_t   GetRGBSize() { return RGBSize; }
119    void     AllocateRGB();
120
121    uint8_t* GetDecompressed() { return Decompressed; }
122    void     SetDecompressedSize( size_t size ) { DecompressedSize = size; }
123    size_t   GetDecompressedSize() { return DecompressedSize; }
124    void     AllocateDecompressed();
125
126 //////////////////////////////////////////////////////////
127 // In progress
128 private:
129    bool UncompressRLE16BitsFromRLE8Bits(
130                   int NumberOfFrames,
131                   uint8_t* fixMemUncompressed );
132    void ComputeDecompressedImageDataSize();
133    void ReadAndDecompress12BitsTo16Bits(
134                   uint8_t* pixelZone,
135                   FILE* filePtr) throw ( FormatError );
136    bool ReadAndDecompressRLEFile( void* image_buffer, FILE* fp );
137    bool ReadAndDecompressJPEGFile( uint8_t* destination, FILE* fp );
138    void SwapZone( uint8_t* im );
139    void ReorderEndianity( uint8_t* pixelZone );
140    bool ReArrangeBits( uint8_t* pixelZone ) throw ( FormatError );
141    void ConvertRGBPlanesToRGBPixels( uint8_t* destination );
142    void ConvertYcBcRPlanesToRGBPixels( uint8_t* destination );
143 public:
144    bool ReadAndDecompressPixelData( void* destination, FILE* fp );
145    bool HandleColor( uint8_t* destination );
146    void Squeeze();
147 };
148 } // end namespace gdcm
149
150 //-----------------------------------------------------------------------------
151 #endif