]> Creatis software - gdcm.git/blob - src/gdcmFile.h
Cosmetic modifs to be more Coding style compliant
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/09/24 11:39:21 $
7   Version:   $Revision: 1.51 $
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.htm 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    void   SetPixelDataSizeFromHeader();
43    
44
45 /// \brief     Returns the size (in bytes) of required memory to hold
46 ///            the pixel data represented in this file.
47    size_t GetImageDataSize(){ return ImageDataSize; };
48
49    
50 /// \brief     Returns the size (in bytes) of required memory to hold
51 ///            the pixel data represented in this file, if user DOESN'T want 
52 ///            to get RGB pixels image when it's stored as a PALETTE COLOR image
53 ///            -the (vtk) user is supposed to know how to deal with LUTs-     
54    size_t GetImageDataSizeRaw(){ return ImageDataSizeRaw; };
55
56    uint8_t* GetImageData();
57    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
58    uint8_t* GetImageDataRaw();
59    size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
60
61    // Allocates ExpectedSize bytes of memory at this->Data and copies the
62    // pointed data to it. Copying the image might look useless but
63    // the caller might destroy it's image (without knowing it: think
64    // of a complicated interface where display is done with a library
65    // e.g. VTK) before calling the Write
66       
67    // see also gdcmHeader::SetImageDataSize ?!?         
68    bool SetImageData (uint8_t* data, size_t expectedSize);
69
70    /// \todo When the caller is aware we simply point to the data:
71    /// int SetImageDataNoCopy (void* Data, size_t ExpectedSize);
72
73    // Write pixels of ONE image on hard drive
74    // No test is made on processor "endianity"
75    // The user must call his reader correctly
76    bool WriteRawData  (std::string const& fileName);
77    bool WriteDcmImplVR(std::string const& fileName);
78    bool WriteDcmExplVR(std::string const& fileName);
79    bool WriteAcr      (std::string const& fileName);
80
81    // Don't look any longer for the code : 
82    // It's in file gdcmParsePixels.cxx
83    bool ParsePixelData();
84
85    virtual bool SetEntryByNumber(std::string const& content,
86                                  uint16_t group, uint16_t element)
87    { 
88       Header->SetEntryByNumber(content,group,element);
89       return true;
90    }
91      
92 protected:
93    bool WriteBase(std::string const& fileName, FileType type);
94
95 private:
96    void SwapZone(void* im, int swap, int lgr, int nb);
97
98    bool ReadPixelData(void* destination);
99    
100    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
101    bool gdcm_read_JPEG_file     (FILE* fp, void* image_buffer); 
102    bool gdcm_write_JPEG_file    (FILE* fp, void* image_buffer, 
103                                  int image_width, int image_heigh,
104                                  int quality);
105
106    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
107    bool gdcm_read_JPEG_file12   (FILE* fp, void* image_buffer);
108    bool gdcm_write_JPEG_file12  (FILE* fp, void* image_buffer, 
109                                  int image_width, int image_height,
110                                  int quality);
111
112    // For JPEG 2000, body in file gdcmJpeg2000.cxx
113    bool gdcm_read_JPEG2000_file (FILE* fp, void* image_buffer);
114
115    // For Run Length Encoding
116    bool gdcm_read_RLE_file      (FILE* fp, void* image_buffer);
117 // FIXME : *sure* it's NOT static (C++)
118 // (would be static in C, or embedded in ADA)
119 // It's NOT a method, but a not user intended fonction.
120 // How do we write that in C++ ?)
121    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
122                                      long uncompressedSegmentSize, FILE* fp);
123
124    void SaveInitialValues();    // will belong to the future gdcmPixelData class
125    void RestoreInitialValues(); // will belong to the future gdcmPixelData class
126    void DeleteInitialValues();  // will belong to the future gdcmPixelData class 
127
128 // members variables:
129
130    /// \brief Header to use to load the file
131    gdcmHeader *Header;
132
133    /// \brief Whether the underlying \ref gdcmHeader was loaded by
134    ///  the constructor or passed to the constructor. When false
135    ///  the destructor is in charge of deletion.
136    bool SelfHeader;
137    
138    /// wether already parsed 
139    bool Parsed;
140       
141    //
142    // --------------- Will be moved to a gdcmPixelData class
143    //
144
145    /// \brief to hold the Pixels (when read)
146    uint8_t* Pixel_Data;  // (was PixelData)
147    
148    /// \brief Area length to receive the Gray Level pixels
149    size_t ImageDataSizeRaw;
150    
151    /// \brief Area length to receive the pixels making RGB
152    ///        from Plane R, Plane G, Plane B 
153    ///     or from Grey Plane + Palette Color
154    ///     or from YBR Pixels (or from RGB Pixels, as well) 
155    size_t ImageDataSize;
156        
157   /// \brief ==1  if GetImageDataRaw was used
158   ///        ==0  if GetImageData    was used
159   ///        ==-1 if ImageData never read                       
160    int PixelRead;
161
162   /// \brief length of the last allocated area devoided to receive Pixels
163   ///        ( to allow us not to (free + new) if un necessary )     
164    size_t LastAllocatedPixelDataLength; 
165
166   // Initial values of some fields that can be modified during reading process
167   // (in a future stage, they will be modified just before the writting process
168   //  and restored just after)
169   // if user asked to transform gray level + LUT image into RGB image
170      
171   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
172    std::string InitialSpp;
173   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
174    std::string InitialPhotInt;
175   /// \brief Planar Configuration        (0x0028,0x0006), as found on disk   
176    std::string InitialPlanConfig;
177     
178   // Initial values of some fields that can be modified during reading process
179   // (in a future stage, they will be modified just before the writting process
180   //  and restored just after)
181   // if the image was a 'strange' ACR-NEMA 
182   // (Bits Allocated=12, High Bit not equal to Bits stored +1) 
183   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
184    std::string InitialBitsAllocated;
185   /// \brief High Bit                    (0x0028,0x0102), as found on disk
186    std::string InitialHighBit;
187   
188   // some DocEntry that can be moved out of the H table during reading process
189   // (in a future stage, they will be modified just before the writting process
190   //  and restored just after)
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