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