]> Creatis software - gdcm.git/blob - src/gdcmFile.h
be828e5ecafdb9f600da74a22c23661f897f0e5d
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/07/16 15:18:05 $
7   Version:   $Revision: 1.38 $
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    /// Accessor to \ref Header
43    gdcmHeader* GetHeader() { return Header; }
44
45    void   SetPixelDataSizeFromHeader();
46    size_t GetImageDataSize();
47    size_t GetImageDataSizeRaw();
48
49    void * GetImageData();
50    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
51    void * GetImageDataRaw();
52    size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
53
54       // Allocates ExpectedSize bytes of memory at this->Data and copies the
55       // pointed data to it. Copying the image might look useless but
56       // the caller might destroy it's image (without knowing it: think
57       // of a complicated interface where display is done with a library
58       // e.g. VTK) before calling the Write
59       
60    // voir gdcmHeader::SetImageDataSize ?!?         
61    bool SetImageData (void * data, size_t expectedSize);
62
63    /// \todo When the caller is aware we simply point to the data:
64    /// int SetImageDataNoCopy (void * Data, size_t ExpectedSize);
65
66    // Write pixels of ONE image on hard drive
67    // No test is made on processor "endianity"
68    // The user must call his reader correctly
69    bool WriteRawData  (std::string const & fileName);
70    bool WriteDcmImplVR(std::string const & fileName);
71    bool WriteDcmExplVR(std::string const & fileName);
72    bool WriteAcr      (std::string const & fileName);
73
74    // Don't look any longer for the code : 
75    // It's in file gdcmParsePixels.cxx
76    bool ParsePixelData();
77
78    virtual bool SetEntryByNumber(std::string const & content,
79                                  uint16_t group, uint16_t element)
80    { 
81       Header->SetEntryByNumber(content,group,element);
82       return true;
83    }
84      
85 protected:
86    bool WriteBase(std::string const & fileName, FileType type);
87
88 private:
89    void SwapZone(void* im, int swap, int lgr, int nb);
90    
91    bool ReadPixelData(void * destination);
92    
93    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
94    bool gdcm_read_JPEG_file     (FILE *fp, void * image_buffer); 
95    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
96                                      long uncompressedSegmentSize, FILE *fp);
97    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
98    bool gdcm_read_JPEG_file12   (FILE *fp, void* image_buffer);
99    // For JPEG 2000, body in file gdcmJpeg2000.cxx
100    bool gdcm_read_JPEG2000_file (FILE *fp, void* image_buffer);
101
102    // For Run Length Encoding (TOCHECK)
103    bool gdcm_read_RLE_file      (FILE *fp, void* image_buffer); 
104
105 // Variables
106
107    /// \brief Header to use to load the file
108    gdcmHeader *Header;
109
110    /// \brief Whether the underlying \ref gdcmHeader 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    /// \brief to hold the Pixels (when read)
116    void* PixelData;
117    
118    /// \brief Area length to receive the pixels
119    size_t ImageDataSizeRaw;
120    
121    /// \brief Area length to receive the RGB pixels
122    /// from Grey Plane + Palette Color  
123    size_t ImageDataSize;
124        
125   /// \brief ==1  if GetImageDataRaw was used
126   ///        ==0  if GetImageData    was used
127   ///        ==-1 if ImageData never read                       
128    int PixelRead;     
129
130    /// wether already parsed 
131    int Parsed;
132 };
133
134 //-----------------------------------------------------------------------------
135 #endif