]> Creatis software - gdcm.git/blob - src/gdcmFile.h
ENH: Some cosmetic cleanup of gdcmFile, main changes are: lgrTotal -> ImageDataSize...
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/06/26 04:09:33 $
7   Version:   $Revision: 1.36 $
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             bool  exception_on_error = false, 
37             bool  enable_sequences   = false,
38             bool  skip_shadow        = false);
39  
40    virtual ~gdcmFile();
41
42    /// \brief returns the gdcmHeader *Header
43    inline gdcmHeader *GetHeader() { return Header; }
44
45    // For promotion (performs a deepcopy of pointed header object)
46    // TODO Swig gdcmFile(gdcmHeader* header);
47    // TODO Swig ~gdcmFile();
48
49    // On writing purposes. When instance was created through
50    // gdcmFile(std::string filename) then the filename argument MUST be
51         // different from the constructor's one (no overwriting allowed).
52    // TODO Swig int SetFileName(std::string filename);
53
54    void   SetPixelDataSizeFromHeader();
55    size_t GetImageDataSize();
56    size_t GetImageDataSizeRaw();
57
58    void * GetImageData();
59    size_t GetImageDataIntoVector(void* destination, size_t MaxSize);
60    void * GetImageDataRaw();
61    size_t GetImageDataIntoVectorRaw(void* destination, size_t MaxSize);
62
63       // Allocates ExpectedSize bytes of memory at this->Data and copies the
64       // pointed data to it. Copying the image might look useless but
65       // the caller might destroy it's image (without knowing it: think
66       // of a complicated interface where display is done with a library
67       // e.g. VTK) before calling the Write
68       
69    // voir gdcmHeader::SetImageDataSize ?!?         
70    bool SetImageData     (void * Data, size_t ExpectedSize);
71       // When the caller is aware we simply point to the data:
72       // TODO int SetImageDataNoCopy (void * Data, size_t ExpectedSize);
73
74   // Push to disk.
75   // TODO Swig int Write();
76
77    // Write pixels of ONE image on hard drive
78    // No test is made on processor "endianity"
79    // The user must call his reader correctly
80    bool WriteRawData  (std::string const & fileName);
81    bool WriteDcmImplVR(std::string const & fileName);
82    bool WriteDcmExplVR(std::string const & fileName);
83    bool WriteAcr      (std::string const & fileName);
84
85    // Don't look any longer for the code : 
86    // It's in file gdcmParsePixels.cxx
87    bool ParsePixelData();
88
89    inline virtual bool SetEntryByNumber(std::string const & content,
90                                         guint16 group, guint16 element)
91    { 
92       GetHeader()->SetEntryByNumber(content,group,element);
93       return true;  //default behavior ?
94    }
95      
96 protected:
97    bool WriteBase(std::string const & FileName, FileType type);
98
99 private:
100    void SwapZone(void* im, int swap, int lgr, int nb);
101    
102    bool ReadPixelData(void * destination);
103    
104    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
105    bool gdcm_read_JPEG_file     (FILE *fp,void * image_buffer); 
106    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
107                                      long uncompressedSegmentSize,FILE *fp);
108    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
109    bool gdcm_read_JPEG_file12   (FILE *fp,void * image_buffer);
110    // For JPEG 2000, body in file gdcmJpeg2000.cxx
111    bool gdcm_read_JPEG2000_file (FILE *fp,void * image_buffer);
112
113    // For Run Length Encoding (TOCHECK)
114    bool gdcm_read_RLE_file      (FILE *fp,void * image_buffer); 
115
116 // Variables
117
118    /// \brief Header to use to load the file
119    gdcmHeader *Header;
120
121    /// \brief Whether the underlying \ref gdcmHeader was loaded by
122    ///  the constructor or passed to the constructor. When false
123    ///  the destructor is in charge of deletion.
124    bool SelfHeader;
125
126    /// \brief to hold the Pixels (when read)
127    void* PixelData;
128    
129    /// \brief Area length to receive the pixels
130    size_t ImageDataSizeRaw;
131    
132    /// \brief Area length to receive the RGB pixels
133    /// from Grey Plane + Palette Color  
134    size_t ImageDataSize;
135        
136   /// \brief ==1  if GetImageDataRaw was used
137   ///        ==0  if GetImageData    was used
138   ///        ==-1 if ImageData never read                       
139    int PixelRead;     
140
141    /// wether already parsed 
142    int Parsed;
143 };
144
145 //-----------------------------------------------------------------------------
146 #endif