]> Creatis software - gdcm.git/blob - src/gdcmFile.h
693bea288d7e845713aba397093b51eedf4df744
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/09/30 12:51:55 $
7   Version:   $Revision: 1.54 $
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 #ifndef GDCMFILE_H
20 #define GDCMFILE_H
21
22 #include "gdcmCommon.h"
23 #include "gdcmHeader.h"
24
25 //-----------------------------------------------------------------------------
26 /*
27  * In addition to Dicom header exploration, this class is designed
28  * for accessing the image/volume content. One can also use it to
29  * write Dicom/ACR-NEMA/RAW files.
30  */
31 class GDCM_EXPORT gdcmFile
32 {
33 public:
34    gdcmFile( gdcmHeader *header );
35    gdcmFile( std::string const& filename );
36  
37    virtual ~gdcmFile();
38
39    /// Accessor to \ref Header
40    gdcmHeader* GetHeader() { return Header; }
41
42    int ComputeDecompressedPixelDataSizeFromHeader();
43
44    void ConvertRGBPlanesToRGBPixels( uint8_t* source, uint8_t* destination );
45    void ConvertYcBcRPlanesToRGBPixels( uint8_t* source, uint8_t* destination );
46    void ConvertReArrangeBits( uint8_t* pixelZone,
47                               size_t imageDataSize,
48                               int numberBitsStored,
49                               int numberBitsAllocated,
50                               int highBitPosition ) throw ( gdcmFormatError );
51    void ConvertReorderEndianity( uint8_t* pixelZone,
52                                  size_t imageDataSize,
53                                  int numberBitsStored,
54                                  int numberBitsAllocated,
55                                  bool signedPixel );
56
57    
58    /// Accessor to \ref ImageDataSize
59    size_t GetImageDataSize(){ return ImageDataSize; };
60
61    /// Accessor to \ref ImageDataSizeRaw
62    size_t GetImageDataSizeRaw(){ return ImageDataSizeRaw; };
63
64    uint8_t* GetImageData();
65    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
66    uint8_t* GetImageDataRaw();
67    size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
68
69    // see also gdcmHeader::SetImageDataSize ?!?         
70    bool SetImageData (uint8_t* data, size_t expectedSize);
71
72    /// \todo When the caller is aware we simply point to the data:
73    /// int SetImageDataNoCopy (void* Data, size_t ExpectedSize);
74
75    // Write pixels of ONE image on hard drive
76    // No test is made on processor "endianity"
77    // The user must call his reader correctly
78    bool WriteRawData  (std::string const& fileName);
79    bool WriteDcmImplVR(std::string const& fileName);
80    bool WriteDcmExplVR(std::string const& fileName);
81    bool WriteAcr      (std::string const& fileName);
82
83    // Don't look any longer for the code : 
84    // It's in file gdcmParsePixels.cxx
85    bool ParsePixelData();
86
87    virtual bool SetEntryByNumber(std::string const& content,
88                                  uint16_t group, uint16_t element)
89    { 
90       Header->SetEntryByNumber(content,group,element);
91       return true;
92    }
93      
94 protected:
95    bool WriteBase(std::string const& fileName, FileType type);
96
97 private:
98    void Initialise();
99    void SwapZone(void* im, int swap, int lgr, int nb);
100
101    bool ReadPixelData(void* destination);
102    
103    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
104    bool gdcm_read_JPEG_file     (FILE* fp, void* image_buffer); 
105    bool gdcm_write_JPEG_file    (FILE* fp, void* image_buffer, 
106                                  int image_width, int image_heigh,
107                                  int quality);
108
109    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
110    bool gdcm_read_JPEG_file12   (FILE* fp, void* image_buffer);
111    bool gdcm_write_JPEG_file12  (FILE* fp, void* image_buffer, 
112                                  int image_width, int image_height,
113                                  int quality);
114
115    // For JPEG 2000, body in file gdcmJpeg2000.cxx
116    bool gdcm_read_JPEG2000_file (FILE* fp, void* image_buffer);
117
118    // For Run Length Encoding
119    bool gdcm_read_RLE_file      (FILE* fp, void* image_buffer);
120 // FIXME : *sure* it's NOT static (C++)
121 // (would be static in C, or embedded in ADA)
122 // It's NOT a method, but a not user intended fonction.
123 // How do we write that in C++ ?)
124    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
125                                      long uncompressedSegmentSize, FILE* fp);
126
127    void SaveInitialValues();    // will belong to the future gdcmPixelData class
128    void RestoreInitialValues(); // will belong to the future gdcmPixelData class
129    void DeleteInitialValues();  // will belong to the future gdcmPixelData class 
130
131 // members variables:
132
133    /// \brief Header to use to load the file
134    gdcmHeader *Header;
135
136    /// \brief Whether the underlying \ref gdcmHeader was loaded by
137    ///  the constructor or passed to the constructor. When false
138    ///  the destructor is in charge of deletion.
139    bool SelfHeader;
140    
141    /// wether already parsed 
142    bool Parsed;
143       
144 //
145 // --------------- Will be moved to a gdcmPixelData class
146 //
147
148    /// \brief to hold the Pixels (when read)
149    uint8_t* Pixel_Data;  // (was PixelData)
150    
151    /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
152    ///        represented in this file. This is used when the user DOESN'T want
153    ///        the RGB pixels image when it's stored as a PALETTE COLOR image
154    size_t ImageDataSizeRaw;
155    
156    /// \brief Size (in bytes) of requited memory to hold the the pixels
157    ///        of this image in it's RGB convertion either from:
158    ///        - Plane R, Plane G, Plane B 
159    ///        - Grey Plane + Palette Color
160    ///        - YBR Pixels (or from RGB Pixels, as well) 
161    size_t ImageDataSize;
162        
163   /// \brief ==1  if GetImageDataRaw was used
164   ///        ==0  if GetImageData    was used
165   ///        ==-1 if ImageData never read                       
166    int PixelRead;
167
168   /// \brief length of the last allocated area devoided to receive Pixels
169   ///        ( to allow us not to (free + new) if un necessary )     
170    size_t LastAllocatedPixelDataLength; 
171
172   // Initial values of some fields that can be modified during reading process
173   // if user asked to transform gray level + LUT image into RGB image
174      
175   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
176    std::string InitialSpp;
177   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
178    std::string InitialPhotInt;
179   /// \brief Planar Configuration        (0x0028,0x0006), as found on disk   
180    std::string InitialPlanConfig;
181     
182   // Initial values of some fields that can be modified during reading process
183   // if the image was a 'strange' ACR-NEMA 
184   // (Bits Allocated=12, High Bit not equal to Bits stored +1) 
185   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
186    std::string InitialBitsAllocated;
187   /// \brief High Bit                    (0x0028,0x0102), as found on disk
188    std::string InitialHighBit;
189   
190   // some DocEntry that can be moved out of the H table during reading process
191   // if user asked to transform gray level + LUT image into RGB image
192   // We keep a pointer on them for a future use.
193      
194   /// \brief Red Palette Color Lookup Table Descriptor   0028 1101 as read
195   gdcmDocEntry* InitialRedLUTDescr;  
196   /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
197   gdcmDocEntry* InitialGreenLUTDescr;
198   /// \brief Blue Palette Color Lookup Table Descriptor  0028 1103 as read
199   gdcmDocEntry* InitialBlueLUTDescr;
200   
201   /// \brief Red Palette Color Lookup Table Data         0028 1201 as read
202   gdcmDocEntry* InitialRedLUTData;  
203   /// \brief Green Palette Color Lookup Table Data       0028 1202 as read
204   gdcmDocEntry* InitialGreenLUTData;
205   /// \brief Blue Palette Color Lookup Table Data        0028 1203 as read
206   gdcmDocEntry* InitialBlueLUTData;
207   
208 //
209 // --------------- end of future gdcmPixelData class
210 //  
211
212 };
213
214 //-----------------------------------------------------------------------------
215 #endif