1 /*=========================================================================
4 Module: $RCSfile: gdcmFile.h,v $
6 Date: $Date: 2004/06/23 16:22:21 $
7 Version: $Revision: 1.35 $
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.
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.
17 =========================================================================*/
22 #include "gdcmCommon.h"
23 #include "gdcmHeader.h"
25 //-----------------------------------------------------------------------------
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.
31 class GDCM_EXPORT gdcmFile
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);
42 /// \brief returns the gdcmHeader *Header
43 inline gdcmHeader *GetHeader() { return Header;};
45 // For promotion (performs a deepcopy of pointed header object)
46 // TODO Swig gdcmFile(gdcmHeader* header);
47 // TODO Swig ~gdcmFile();
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);
54 void SetPixelDataSizeFromHeader();
55 size_t GetImageDataSize();
56 size_t GetImageDataSizeRaw();
58 void * GetImageData();
59 size_t GetImageDataIntoVector(void* destination, size_t MaxSize);
60 void * GetImageDataRaw();
61 size_t GetImageDataIntoVectorRaw(void* destination, size_t MaxSize);
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
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);
75 // TODO Swig int Write();
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);
85 // Don't look any longer for the code :
86 // It's in file gdcmParsePixels.cxx
87 bool ParsePixelData();
89 inline virtual bool SetEntryByNumber(std::string const & content,
90 guint16 group, guint16 element)
92 GetHeader()->SetEntryByNumber(content,group,element);
93 return true; //default behavior ?
98 bool WriteBase(std::string const & FileName, FileType type);
101 void SwapZone(void* im, int swap, int lgr, int nb);
103 bool ReadPixelData(void * destination);
105 // For JPEG 8 Bits, body in file gdcmJpeg.cxx
106 bool gdcm_read_JPEG_file (FILE *fp,void * image_buffer);
107 static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode,
108 long uncompressedSegmentSize,FILE *fp);
109 // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
110 bool gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer);
111 // For JPEG 2000, body in file gdcmJpeg2000.cxx
112 bool gdcm_read_JPEG2000_file (FILE *fp,void * image_buffer);
114 // For Run Length Encoding (TOCHECK)
115 bool gdcm_read_RLE_file (FILE *fp,void * image_buffer);
119 /// \brief Header to use to load the file
122 /// \brief Whether the underlying \ref gdcmHeader was loaded by
123 /// the constructor or passed to the constructor. When false
124 /// the destructor is in charge of deletion.
127 /// \brief to hold the Pixels (when read)
130 /// \brief Area length to receive the pixels
133 /// \brief Area length to receive the RGB pixels
134 /// from Grey Plane + Palette Color
137 /// \brief ==1 if GetImageDataRaw was used
138 /// ==0 if GetImageData was used
139 /// ==-1 if ImageData never read
142 /// wether already parsed
145 /// To avoid file overwrite
146 std::string OrigFileName;
149 //-----------------------------------------------------------------------------