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