]> Creatis software - gdcm.git/blob - src/gdcmFile.h
2004-04-28 Jean-Pierre Roux
[gdcm.git] / src / gdcmFile.h
1 // gdcmFile.h
2 //-----------------------------------------------------------------------------
3 #ifndef GDCMFILE_H
4 #define GDCMFILE_H
5
6 #include "gdcmCommon.h"
7 #include "gdcmHeader.h"
8
9 //-----------------------------------------------------------------------------
10 /*
11  * In addition to Dicom header exploration, this class is designed
12  * for accessing the image/volume content. One can also use it to
13  * write Dicom/ACR-NEMA/RAW files.
14  */
15 class GDCM_EXPORT gdcmFile
16 {
17 public:
18    gdcmFile(gdcmHeader *header);
19    gdcmFile(std::string & filename, 
20               bool  exception_on_error = false, 
21               bool  enable_sequences   = false,
22               bool  skip_shadow        = false);
23  
24    gdcmFile(const char * filename, 
25               bool  exception_on_error = false, 
26               bool  enable_sequences   = false,
27               bool  skip_shadow        = false);
28  
29    virtual ~gdcmFile(void);
30         
31    gdcmHeader *GetHeader(void);
32
33         // For promotion (performs a deepcopy of pointed header object)
34         // TODO Swig gdcmFile(gdcmHeader* header);
35         // TODO Swig ~gdcmFile();
36
37         // On writing purposes. When instance was created through
38         // gdcmFile(std::string filename) then the filename argument MUST be
39         // different from the constructor's one (no overwriting allowed).
40         // TODO Swig int SetFileName(std::string filename);
41
42    void   SetPixelDataSizeFromHeader(void);
43    size_t GetImageDataSize();
44    size_t GetImageDataSizeRaw();
45
46    void * GetImageData();
47    size_t GetImageDataIntoVector(void* destination, size_t MaxSize);
48    void * GetImageDataRaw();
49    size_t GetImageDataIntoVectorRaw(void* destination, size_t MaxSize);
50         
51       // Allocates ExpectedSize bytes of memory at this->Data and copies the
52       // pointed data to it. Copying the image might look useless but
53       // the caller might destroy it's image (without knowing it: think
54       // of a complicated interface where display is done with a library
55       // e.g. VTK) before calling the Write
56       
57    // voir gdcmHeader::SetImageDataSize ?!?         
58    bool SetImageData     (void * Data, size_t ExpectedSize);
59       // When the caller is aware we simply point to the data:
60       // TODO int SetImageDataNoCopy (void * Data, size_t ExpectedSize);
61         
62         // Push to disk.
63         // A NE PAS OUBLIER : que fait-on en cas de Transfert Syntax (dans l'entete)
64         // incohérente avec l'ordre des octets en mémoire ? 
65         // TODO Swig int Write();
66         
67    // Write pixels of ONE image on hard drive
68    // No test is made on processor "endianity"
69    // The user must call his reader correctly
70    bool WriteRawData  (std::string fileName);
71    bool WriteDcmImplVR(std::string fileName);
72    bool WriteDcmImplVR(const char * fileName);
73    bool WriteDcmExplVR(std::string fileName);
74    bool WriteAcr      (std::string fileName);
75
76    // Body in file gdcmParse.cxx
77    bool ParsePixelData(void);
78      
79 protected:
80    bool WriteBase(std::string FileName, FileType type);
81
82 private:
83    void SwapZone(void* im, int swap, int lgr, int nb);
84    
85    bool ReadPixelData(void * destination);
86    
87    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
88    bool gdcm_read_JPEG_file     (FILE *fp,void * image_buffer); 
89    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
90                                      long uncompressedSegmentSize,FILE *fp);
91    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
92    bool gdcm_read_JPEG_file12   (FILE *fp,void * image_buffer);
93    // For JPEG 2000, body in file gdcmJpeg2000.cxx
94    bool gdcm_read_JPEG2000_file (FILE *fp,void * image_buffer);
95
96    // For Run Length Encoding (TOCHECK)
97    bool gdcm_read_RLE_file      (FILE *fp,void * image_buffer); 
98
99 // Variables
100    /// Header to use to load the file
101    gdcmHeader *Header;   
102    bool SelfHeader;
103
104    void* PixelData;
105    
106    /// Area length to receive the pixels
107    size_t lgrTotaleRaw;
108    
109    /// Area length to receive the RGB pixels
110    /// from Grey Plane + Palette Color  
111    size_t lgrTotale; 
112        
113   /// ==1  if GetImageDataRaw was used
114   /// ==0  if GetImageData    was used
115   /// ==-1 if ImageData never read                       
116    int PixelRead;     
117
118    /// weather already parsed 
119    int Parsed;
120    
121    /// To avoid file overwrite              
122    std::string OrigFileName;    
123 };
124
125 //-----------------------------------------------------------------------------
126 #endif