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