1 /*=========================================================================
4 Module: $RCSfile: gdcmFile.h,v $
6 Date: $Date: 2004/10/08 16:27:20 $
7 Version: $Revision: 1.57 $
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.html 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 );
39 /// Accessor to \ref Header
40 gdcmHeader* GetHeader() { return Header; }
42 int ComputeDecompressedPixelDataSizeFromHeader();
44 void ConvertRGBPlanesToRGBPixels( uint8_t* source, uint8_t* destination );
45 void ConvertYcBcRPlanesToRGBPixels( uint8_t* source, uint8_t* destination );
46 void ConvertReArrangeBits(
50 int numberBitsAllocated,
51 int highBitPosition ) throw ( gdcmFormatError );
52 void ConvertReorderEndianity(
56 int numberBitsAllocated,
58 void ConvertDecompress12BitsTo16Bits(
62 FILE* filePtr) throw ( gdcmFormatError);
64 /// Accessor to \ref ImageDataSize
65 size_t GetImageDataSize(){ return ImageDataSize; };
67 /// Accessor to \ref ImageDataSizeRaw
68 size_t GetImageDataSizeRaw(){ return ImageDataSizeRaw; };
70 uint8_t* GetImageData();
71 size_t GetImageDataIntoVector(void* destination, size_t maxSize);
72 uint8_t* GetImageDataRaw();
73 size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
75 // see also gdcmHeader::SetImageDataSize ?!?
76 bool SetImageData (uint8_t* data, size_t expectedSize);
78 /// \todo When the caller is aware we simply point to the data:
79 /// int SetImageDataNoCopy (void* Data, size_t ExpectedSize);
81 // Write pixels of ONE image on hard drive
82 // No test is made on processor "endianity"
83 // The user must call his reader correctly
84 bool WriteRawData (std::string const& fileName);
85 bool WriteDcmImplVR(std::string const& fileName);
86 bool WriteDcmExplVR(std::string const& fileName);
87 bool WriteAcr (std::string const& fileName);
89 // Don't look any longer for the code :
90 // It's in file gdcmParsePixels.cxx
91 bool ParsePixelData();
93 virtual bool SetEntryByNumber(std::string const& content,
94 uint16_t group, uint16_t element)
96 Header->SetEntryByNumber(content,group,element);
101 bool WriteBase(std::string const& fileName, FileType type);
105 void SwapZone(void* im, int swap, int lgr, int nb);
107 bool ReadPixelData(void* destination);
109 // For JPEG 8 Bits, body in file gdcmJpeg.cxx
110 bool gdcm_read_JPEG_file (FILE* fp, void* image_buffer);
111 bool gdcm_write_JPEG_file (FILE* fp, void* image_buffer,
112 int image_width, int image_heigh,
115 // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
116 bool gdcm_read_JPEG_file12 (FILE* fp, void* image_buffer);
117 bool gdcm_write_JPEG_file12 (FILE* fp, void* image_buffer,
118 int image_width, int image_height,
121 // For JPEG 2000, body in file gdcmJpeg2000.cxx
122 bool gdcm_read_JPEG2000_file (FILE* fp, void* image_buffer);
124 void SaveInitialValues(); // will belong to the future gdcmPixelData class
125 void RestoreInitialValues(); // will belong to the future gdcmPixelData class
126 void DeleteInitialValues(); // will belong to the future gdcmPixelData class
128 // members variables:
130 /// \brief Header to use to load the file
133 /// \brief Whether the underlying \ref gdcmHeader was loaded by
134 /// the constructor or passed to the constructor. When false
135 /// the destructor is in charge of deletion.
138 /// wether already parsed
142 // --------------- Will be moved to a gdcmPixelData class
145 /// \brief to hold the Pixels (when read)
146 uint8_t* Pixel_Data; // (was PixelData)
148 /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
149 /// represented in this file. This is used when the user DOESN'T want
150 /// the RGB pixels image when it's stored as a PALETTE COLOR image
151 size_t ImageDataSizeRaw;
153 /// \brief Size (in bytes) of requited memory to hold the the pixels
154 /// of this image in it's RGB convertion either from:
155 /// - Plane R, Plane G, Plane B
156 /// - Grey Plane + Palette Color
157 /// - YBR Pixels (or from RGB Pixels, as well)
158 size_t ImageDataSize;
160 /// \brief ==1 if GetImageDataRaw was used
161 /// ==0 if GetImageData was used
162 /// ==-1 if ImageData never read
165 /// \brief length of the last allocated area devoided to receive Pixels
166 /// ( to allow us not to (free + new) if un necessary )
167 size_t LastAllocatedPixelDataLength;
169 // Initial values of some fields that can be modified during reading process
170 // if user asked to transform gray level + LUT image into RGB image
172 /// \brief Samples Per Pixel (0x0028,0x0002), as found on disk
173 std::string InitialSpp;
174 /// \brief Photometric Interpretation (0x0028,0x0004), as found on disk
175 std::string InitialPhotInt;
176 /// \brief Planar Configuration (0x0028,0x0006), as found on disk
177 std::string InitialPlanConfig;
179 // Initial values of some fields that can be modified during reading process
180 // if the image was a 'strange' ACR-NEMA
181 // (Bits Allocated=12, High Bit not equal to Bits stored +1)
182 /// \brief Bits Allocated (0x0028,0x0100), as found on disk
183 std::string InitialBitsAllocated;
184 /// \brief High Bit (0x0028,0x0102), as found on disk
185 std::string InitialHighBit;
187 // some DocEntry that can be moved out of the H table during reading process
188 // if user asked to transform gray level + LUT image into RGB image
189 // We keep a pointer on them for a future use.
191 /// \brief Red Palette Color Lookup Table Descriptor 0028 1101 as read
192 gdcmDocEntry* InitialRedLUTDescr;
193 /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
194 gdcmDocEntry* InitialGreenLUTDescr;
195 /// \brief Blue Palette Color Lookup Table Descriptor 0028 1103 as read
196 gdcmDocEntry* InitialBlueLUTDescr;
198 /// \brief Red Palette Color Lookup Table Data 0028 1201 as read
199 gdcmDocEntry* InitialRedLUTData;
200 /// \brief Green Palette Color Lookup Table Data 0028 1202 as read
201 gdcmDocEntry* InitialGreenLUTData;
202 /// \brief Blue Palette Color Lookup Table Data 0028 1203 as read
203 gdcmDocEntry* InitialBlueLUTData;
206 // --------------- end of future gdcmPixelData class
211 //-----------------------------------------------------------------------------