]> Creatis software - gdcm.git/blob - src/gdcmFile.h
Temporary (?) uncomment of method gdcmElementSet::GetEntry()
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/09/03 07:57:10 $
7   Version:   $Revision: 1.44 $
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    size_t GetImageDataSizeRaw();
50
51    void * GetImageData();
52    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
53    void * GetImageDataRaw();
54    size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
55
56    // Allocates ExpectedSize bytes of memory at this->Data and copies the
57    // pointed data to it. Copying the image might look useless but
58    // the caller might destroy it's image (without knowing it: think
59    // of a complicated interface where display is done with a library
60    // e.g. VTK) before calling the Write
61       
62    // see also gdcmHeader::SetImageDataSize ?!?         
63    bool SetImageData (void * 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    // Don't look any longer for the code : 
77    // It's in file gdcmParsePixels.cxx
78    bool ParsePixelData();
79
80    virtual bool SetEntryByNumber(std::string const & content,
81                                  uint16_t group, uint16_t element)
82    { 
83       Header->SetEntryByNumber(content,group,element);
84       return true;
85    }
86      
87 protected:
88    bool WriteBase(std::string const & fileName, FileType type);
89
90 private:
91    void SwapZone(void* im, int swap, int lgr, int nb);
92    
93    bool ReadPixelData(void * destination);
94    
95    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
96    bool gdcm_read_JPEG_file     (FILE *fp, void * image_buffer); 
97    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
98                                      long uncompressedSegmentSize, FILE *fp);
99
100    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
101    bool gdcm_read_JPEG_file12   (FILE *fp, void* image_buffer);
102
103    // For JPEG 2000, body in file gdcmJpeg2000.cxx
104    bool gdcm_read_JPEG2000_file (FILE *fp, void* image_buffer);
105
106    // For Run Length Encoding
107    bool gdcm_read_RLE_file      (FILE *fp, void* image_buffer); 
108
109 // members variables:
110
111    /// \brief Header to use to load the file
112    gdcmHeader *Header;
113
114    /// \brief Whether the underlying \ref gdcmHeader was loaded by
115    ///  the constructor or passed to the constructor. When false
116    ///  the destructor is in charge of deletion.
117    bool SelfHeader;
118
119    /// \brief to hold the Pixels (when read)
120    void* PixelData;
121    
122    /// \brief Area length to receive the pixels
123    size_t ImageDataSizeRaw;
124    
125    /// \brief Area length to receive the RGB pixels
126    /// from Grey Plane + Palette Color  
127    size_t ImageDataSize;
128        
129   /// \brief ==1  if GetImageDataRaw was used
130   ///        ==0  if GetImageData    was used
131   ///        ==-1 if ImageData never read                       
132    int PixelRead;
133    
134   /// wether already parsed 
135    bool Parsed;
136       
137   /// \brief length of the last allocated area devoided to receive Pixels
138   ///        ( to allow us not to (free + new) if un necessary )     
139    size_t LastAllocatedPixelDataLength; 
140    
141   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
142    std::string InitialSpp;
143   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
144    std::string InitialPhotInt;
145   /// \brief Planar Configuration        (0x0028,0x0006), as found on disk   
146    std::string InitialPlanConfig;    
147   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
148    std::string InitialBitsAllocated;
149    
150
151 };
152
153 //-----------------------------------------------------------------------------
154 #endif