]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* FIX compilation error for zorglub and smallfry.­kitwareout
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/11/23 09:13:26 $
7   Version:   $Revision: 1.72 $
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 #include "gdcmPixelConvert.h"
25 #include "gdcmDocEntryArchive.h"
26
27 namespace gdcm 
28 {
29 //-----------------------------------------------------------------------------
30 /*
31  * In addition to Dicom header exploration, this class is designed
32  * for accessing the image/volume content. One can also use it to
33  * write Dicom/ACR-NEMA/RAW files.
34  */
35 class GDCM_EXPORT File
36 {
37 public:
38    enum TWriteMode
39    {
40       WMODE_NATIVE,
41       WMODE_DECOMPRESSED,
42       WMODE_RGB
43    };
44      
45    enum TWriteType
46    {
47       WTYPE_IMPL_VR,
48       WTYPE_EXPL_VR,
49       WTYPE_ACR
50    };
51      
52 public:
53    File( Header* header );
54    File( std::string const& filename );
55  
56    virtual ~File();
57
58    /// Accessor to \ref Header
59    Header* GetHeader() { return HeaderInternal; }
60
61    /// Accessor to \ref ImageDataSize
62    size_t GetImageDataSize() { return ImageDataSize; };
63
64    /// Accessor to \ref ImageDataSizeRaw
65    size_t GetImageDataSizeRaw() { return ImageDataSizeRaw; };
66
67    /// Accessor to \ref PixelConverter
68    PixelConvert* GetPixelConverter() { return PixelConverter; };
69
70    uint8_t* GetImageData();
71    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
72    uint8_t* GetImageDataRaw();
73
74    // see also Header::SetImageDataSize ?!?         
75    bool SetImageData (uint8_t* data, size_t expectedSize);
76
77    // Write pixels of ONE image on hard drive
78    // No test is made on processor "endianity"
79    // The user must call his reader correctly
80    bool WriteRawData  (std::string const& fileName);
81    bool WriteDcmImplVR(std::string const& fileName);
82    bool WriteDcmExplVR(std::string const& fileName);
83    bool WriteAcr      (std::string const& fileName);
84    bool Write(std::string const& fileName);
85
86    virtual bool SetEntryByNumber(std::string const& content,
87                                  uint16_t group, uint16_t element)
88    { 
89       HeaderInternal->SetEntryByNumber(content,group,element);
90       return true;
91    }
92    uint8_t* GetLutRGBA();
93
94    // Write mode
95    void SetWriteModeToNative()          { SetWriteMode(WMODE_NATIVE); };
96    void SetWriteModeToDecompressed()    { SetWriteMode(WMODE_DECOMPRESSED); };
97    void SetWriteModeToRGB()             { SetWriteMode(WMODE_RGB); };
98    void SetWriteMode(unsigned int mode) { WriteMode = mode; };
99    unsigned int GetWriteMode()          { return WriteMode; };
100
101    // Write format
102    void SetWriteTypeToDcmImplVR()         { SetWriteType(WTYPE_EXPL_VR); };
103    void SetWriteTypeToDcmExplVR()         { SetWriteType(WTYPE_EXPL_VR); };
104    void SetWriteTypeToAcr()               { SetWriteType(WTYPE_ACR); };
105    void SetWriteType(unsigned int format) { WriteType = format; };
106    unsigned int GetWriteType()            { return WriteType; };
107
108 protected:
109    bool WriteBase(std::string const& fileName, FileType type);
110
111    void SetToRAW();
112    void SetToRGB();
113    void Restore();
114
115    void SetToLibido();
116    void RestoreFromLibido();
117
118 private:
119    void Initialise();
120
121    void SaveInitialValues();    // will belong to the future PixelData class
122    void RestoreInitialValues(); // will belong to the future PixelData class
123    void DeleteInitialValues();  // will belong to the future PixelData class 
124    uint8_t* GetDecompressed();
125    int ComputeDecompressedPixelDataSizeFromHeader();
126
127 private:
128    void SetPixelData(uint8_t* data);
129
130 // members variables:
131
132    /// Header to use to load the file
133    Header *HeaderInternal;
134
135    /// \brief Whether the underlying \ref Header was loaded by
136    ///  the constructor or passed to the constructor. When false
137    ///  the destructor is in charge of deletion.
138    bool SelfHeader;
139    
140    /// Wether already parsed or not
141    bool Parsed;
142       
143    /// Utility pixel converter
144    PixelConvert* PixelConverter;
145
146    // Utility header archive
147    DocEntryArchive *Archive;
148
149    // Write variables
150    unsigned int WriteMode;
151    unsigned int WriteType;
152
153 /// FIXME
154 // --------------- Will be moved to a PixelData class
155 //
156
157    /// \brief to hold the Pixels (when read)
158    uint8_t* Pixel_Data;  // (was PixelData)
159    
160    /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
161    ///        represented in this file. This is used when the user DOESN'T want
162    ///        the RGB pixels image when it's stored as a PALETTE COLOR image
163    size_t ImageDataSizeRaw;
164    
165    /// \brief Size (in bytes) of requited memory to hold the the pixels
166    ///        of this image in it's RGB convertion either from:
167    ///        - Plane R, Plane G, Plane B 
168    ///        - Grey Plane + Palette Color
169    ///        - YBR Pixels (or from RGB Pixels, as well) 
170    size_t ImageDataSize;
171        
172   /// \brief ==1  if GetImageDataRaw was used
173   ///        ==0  if GetImageData    was used
174   ///        ==-1 if ImageData never read                       
175    int PixelRead;
176
177   /// \brief length of the last allocated area devoided to receive Pixels
178   ///        ( to allow us not to (free + new) if un necessary )     
179    size_t LastAllocatedPixelDataLength; 
180
181   // Initial values of some fields that can be modified during reading process
182   // if user asked to transform gray level + LUT image into RGB image
183      
184   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
185    std::string InitialSpp;
186   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
187    std::string InitialPhotInt;
188   /// \brief Planar Configuration        (0x0028,0x0006), as found on disk   
189    std::string InitialPlanConfig;
190     
191   // Initial values of some fields that can be modified during reading process
192   // if the image was a 'strange' ACR-NEMA 
193   // (Bits Allocated=12, High Bit not equal to Bits stored +1) 
194   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
195    std::string InitialBitsAllocated;
196   /// \brief High Bit                    (0x0028,0x0102), as found on disk
197    std::string InitialHighBit;
198   
199   // some DocEntry that can be moved out of the H table during reading process
200   // if user asked to transform gray level + LUT image into RGB image
201   // We keep a pointer on them for a future use.
202      
203   /// \brief Red Palette Color Lookup Table Descriptor   0028 1101 as read
204   DocEntry* InitialRedLUTDescr;  
205   /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
206   DocEntry* InitialGreenLUTDescr;
207   /// \brief Blue Palette Color Lookup Table Descriptor  0028 1103 as read
208   DocEntry* InitialBlueLUTDescr;
209   
210   /// \brief Red Palette Color Lookup Table Data         0028 1201 as read
211   DocEntry* InitialRedLUTData;  
212   /// \brief Green Palette Color Lookup Table Data       0028 1202 as read
213   DocEntry* InitialGreenLUTData;
214   /// \brief Blue Palette Color Lookup Table Data        0028 1203 as read
215   DocEntry* InitialBlueLUTData;
216   
217 //
218 // --------------- end of future PixelData class
219 //  
220
221 };
222 } // end namespace gdcm
223
224 //-----------------------------------------------------------------------------
225 #endif