]> Creatis software - gdcm.git/blob - src/gdcmPixelConvert.h
* CLEANUP_ROUND (11) for gdcmPixelConvert (cafeine is my friend stage)
[gdcm.git] / src / gdcmPixelConvert.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmPixelConvert.h,v $
5   Language:  C++
6   Date:      $Date: 2004/10/12 09:59:45 $
7   Version:   $Revision: 1.7 $
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    bool IsUncompressed;
58    bool IsJPEG2000;
59    bool IsJPEGLossless;
60    bool IsRLELossless;
61    RLEFramesInfo* RLEInfo;
62    JPEGFragmentsInfo* JPEGInfo;
63    
64 private:
65    bool ReadAndUncompressRLEFragment(
66                   uint8_t* decodedZone,
67                   long fragmentSize,
68                   long uncompressedSegmentSize,
69                   FILE* fp );
70 public:
71    PixelConvert();
72    ~PixelConvert();
73
74    void SetXSize( int xSize ) { XSize = xSize; }
75    void SetYSize( int ySize ) { YSize = ySize; }
76    void SetZSize( int zSize ) { ZSize = zSize; }
77    void SetBitsAllocated( int bitsAllocated ) { BitsAllocated = bitsAllocated; }
78    void SetBitsStored( int bitsStored ) { BitsStored = bitsStored; }
79    void SetHighBitPosition( int highBitPosition )
80            { HighBitPosition = highBitPosition; }
81    void SetSamplesPerPixel( int samplesPerPixel )
82            { SamplesPerPixel = samplesPerPixel; }
83    void SetPixelSize( int pixelSize ) { PixelSize = pixelSize; }
84    void SetPixelSign( int pixelSign ) { PixelSign = pixelSign; }
85    void SetSwapCode( int swapCode ) { SwapCode = swapCode; }
86    void SetIsUncompressed( bool isUncompressed )
87            { IsUncompressed = isUncompressed; }
88    void SetIsJPEG2000( bool isJPEG2000 ) { IsJPEG2000 = isJPEG2000; }
89    void SetIsJPEGLossless( bool isJPEGLossless )
90            { IsJPEGLossless = isJPEGLossless; }
91    void SetIsRLELossless( bool isRLELossless )
92            { IsRLELossless = isRLELossless; }
93    void SetPixelOffset( size_t pixelOffset ) { PixelOffset = pixelOffset; }
94    void SetPixelDataLength( size_t pixelDataLength )
95            { PixelDataLength = pixelDataLength; }
96    void SetRLEInfo( RLEFramesInfo* inRLEFramesInfo )
97            { RLEInfo = inRLEFramesInfo; }
98    void SetJPEGInfo( JPEGFragmentsInfo* inJPEGFragmentsInfo )
99            { JPEGInfo = inJPEGFragmentsInfo; }
100
101    uint8_t* GetRGB() { return RGB; }
102    void     SetRGBSize( size_t size ) { RGBSize = size; }
103    size_t   GetRGBSize() { return RGBSize; }
104    void     AllocateRGB();
105
106    uint8_t* GetDecompressed() { return Decompressed; }
107    void     SetDecompressedSize( size_t size ) { DecompressedSize = size; }
108    size_t   GetDecompressedSize() { return DecompressedSize; }
109    void     AllocateDecompressed();
110
111 //////////////////////////////////////////////////////////
112 // In progress
113 private:
114    bool UncompressRLE16BitsFromRLE8Bits(
115                   int NumberOfFrames,
116                   uint8_t* fixMemUncompressed );
117    void ComputeDecompressedImageDataSize();
118    void Decompress12BitsTo16Bits(
119                   uint8_t* pixelZone,
120                   FILE* filePtr) throw ( FormatError );
121    bool ReadAndDecompressRLEFile( void* image_buffer, FILE* fp );
122    bool ReadAndDecompressJPEGFile( uint8_t* destination, FILE* fp );
123    void SwapZone( uint8_t* im );
124 public:
125    void ReorderEndianity( uint8_t* pixelZone );
126    bool ReArrangeBits( uint8_t* pixelZone ) throw ( FormatError );
127          void ConvertRGBPlanesToRGBPixels(
128                   uint8_t* destination,
129                   size_t imageDataSize );
130           void ConvertYcBcRPlanesToRGBPixels(
131                   uint8_t* destination,
132                   size_t imageDataSize );
133           bool ReadAndDecompressPixelData( void* destination, FILE* fp );
134    void Squeeze();
135 };
136 } // end namespace gdcm
137
138 //-----------------------------------------------------------------------------
139 #endif