1 /*=========================================================================
4 Module: $RCSfile: gdcmFile.h,v $
6 Date: $Date: 2004/06/21 04:52:08 $
7 Version: $Revision: 1.31 $
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);
40 virtual ~gdcmFile(void);
42 gdcmHeader *GetHeader(void);
44 // For promotion (performs a deepcopy of pointed header object)
45 // TODO Swig gdcmFile(gdcmHeader* header);
46 // TODO Swig ~gdcmFile();
48 // On writing purposes. When instance was created through
49 // gdcmFile(std::string filename) then the filename argument MUST be
50 // different from the constructor's one (no overwriting allowed).
51 // TODO Swig int SetFileName(std::string filename);
53 void SetPixelDataSizeFromHeader(void);
54 size_t GetImageDataSize();
55 size_t GetImageDataSizeRaw();
57 void * GetImageData();
58 size_t GetImageDataIntoVector(void* destination, size_t MaxSize);
59 void * GetImageDataRaw();
60 size_t GetImageDataIntoVectorRaw(void* destination, size_t MaxSize);
62 // Allocates ExpectedSize bytes of memory at this->Data and copies the
63 // pointed data to it. Copying the image might look useless but
64 // the caller might destroy it's image (without knowing it: think
65 // of a complicated interface where display is done with a library
66 // e.g. VTK) before calling the Write
68 // voir gdcmHeader::SetImageDataSize ?!?
69 bool SetImageData (void * Data, size_t ExpectedSize);
70 // When the caller is aware we simply point to the data:
71 // TODO int SetImageDataNoCopy (void * Data, size_t ExpectedSize);
74 // A NE PAS OUBLIER : que fait-on en cas de Transfert Syntax (dans l'entete)
75 // incohérente avec l'ordre des octets en mémoire ?
76 // TODO Swig int Write();
78 // Write pixels of ONE image on hard drive
79 // No test is made on processor "endianity"
80 // The user must call his reader correctly
81 bool WriteRawData (std::string fileName);
82 bool WriteDcmImplVR(std::string fileName);
83 bool WriteDcmImplVR(const char * fileName);
84 bool WriteDcmExplVR(std::string fileName);
85 bool WriteAcr (std::string fileName);
87 // Body in file gdcmParse.cxx
88 bool ParsePixelData(void);
90 inline virtual bool SetEntryByNumber(std::string content,
91 guint16 group, guint16 element)
92 { GetHeader()->SetEntryByNumber(content,group,element); }
96 bool WriteBase(std::string FileName, FileType type);
99 void SwapZone(void* im, int swap, int lgr, int nb);
101 bool ReadPixelData(void * destination);
103 // For JPEG 8 Bits, body in file gdcmJpeg.cxx
104 bool gdcm_read_JPEG_file (FILE *fp,void * image_buffer);
105 static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode,
106 long uncompressedSegmentSize,FILE *fp);
107 // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
108 bool gdcm_read_JPEG_file12 (FILE *fp,void * image_buffer);
109 // For JPEG 2000, body in file gdcmJpeg2000.cxx
110 bool gdcm_read_JPEG2000_file (FILE *fp,void * image_buffer);
112 // For Run Length Encoding (TOCHECK)
113 bool gdcm_read_RLE_file (FILE *fp,void * image_buffer);
117 /// \brief Header to use to load the file
120 /// \brief Whether the underlying \ref gdcmHeader was loaded by
121 /// the constructor or passed to the constructor. When false
122 /// the destructor is in charge of deletion.
125 /// \brief to hold the Pixels (when read)
128 /// \brief Area length to receive the pixels
131 /// \brief Area length to receive the RGB pixels
132 /// from Grey Plane + Palette Color
135 /// \brief ==1 if GetImageDataRaw was used
136 /// ==0 if GetImageData was used
137 /// ==-1 if ImageData never read
140 /// weather already parsed
143 /// To avoid file overwrite
144 std::string OrigFileName;
147 //-----------------------------------------------------------------------------