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