1 /*=========================================================================
4 Module: $RCSfile: gdcmFile.h,v $
6 Date: $Date: 2004/11/19 18:49:39 $
7 Version: $Revision: 1.70 $
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"
24 #include "gdcmPixelConvert.h"
25 #include "gdcmDocEntryArchive.h"
29 //-----------------------------------------------------------------------------
31 * In addition to Dicom header exploration, this class is designed
32 * for accessing the image/volume content. One can also use it to
33 * write Dicom/ACR-NEMA/RAW files.
35 class GDCM_EXPORT File
53 File( Header* header );
54 File( std::string const& filename );
58 /// Accessor to \ref Header
59 Header* GetHeader() { return HeaderInternal; }
61 /// Accessor to \ref ImageDataSize
62 size_t GetImageDataSize() { return ImageDataSize; };
64 /// Accessor to \ref ImageDataSizeRaw
65 size_t GetImageDataSizeRaw() { return ImageDataSizeRaw; };
67 /// Accessor to \ref PixelConverter
68 PixelConvert* GetPixelConverter() { return PixelConverter; };
70 uint8_t* GetImageData();
71 size_t GetImageDataIntoVector(void* destination, size_t maxSize);
72 uint8_t* GetImageDataRaw();
74 // see also Header::SetImageDataSize ?!?
75 bool SetImageData (uint8_t* data, size_t expectedSize);
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);
84 bool Write(std::string const& fileName);
86 virtual bool SetEntryByNumber(std::string const& content,
87 uint16_t group, uint16_t element)
89 HeaderInternal->SetEntryByNumber(content,group,element);
92 uint8_t* GetLutRGBA();
95 void SetWriteModeToNative() { SetWriteMode(WMODE_NATIVE); };
96 void SetWriteModeToDecompressed() { SetWriteMode(WMODE_DECOMPRESSED); };
97 void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); };
98 void SetWriteMode(TWriteMode mode) { WriteMode = mode; };
99 TWriteMode GetWriteMode() { return WriteMode; };
102 void SetWriteTypeToDcmImplVR() { SetWriteType(WTYPE_EXPL_VR); };
103 void SetWriteTypeToDcmExplVR() { SetWriteType(WTYPE_EXPL_VR); };
104 void SetWriteTypeToAcr() { SetWriteType(WTYPE_ACR); };
105 void SetWriteType(TWriteType format) { WriteType = format; };
106 TWriteType GetWriteType() { return WriteType; };
109 bool WriteBase(std::string const& fileName, FileType type);
116 void RestoreFromLibido();
121 void SaveInitialValues(); // will belong to the future PixelData class
122 void RestoreInitialValues(); // will belong to the future PixelData class
123 void DeleteInitialValues(); // will belong to the future PixelData class
124 uint8_t* GetDecompressed();
125 int ComputeDecompressedPixelDataSizeFromHeader();
128 void SetPixelData(uint8_t* data);
130 // members variables:
132 /// Header to use to load the file
133 Header *HeaderInternal;
135 /// \brief Whether the underlying \ref Header was loaded by
136 /// the constructor or passed to the constructor. When false
137 /// the destructor is in charge of deletion.
140 /// Wether already parsed or not
143 /// Utility pixel converter
144 PixelConvert* PixelConverter;
146 // Utility header archive
147 DocEntryArchive *Archive;
150 TWriteMode WriteMode;
151 TWriteType WriteType;
154 // --------------- Will be moved to a PixelData class
157 /// \brief to hold the Pixels (when read)
158 uint8_t* Pixel_Data; // (was PixelData)
160 /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
161 /// represented in this file. This is used when the user DOESN'T want
162 /// the RGB pixels image when it's stored as a PALETTE COLOR image
163 size_t ImageDataSizeRaw;
165 /// \brief Size (in bytes) of requited memory to hold the the pixels
166 /// of this image in it's RGB convertion either from:
167 /// - Plane R, Plane G, Plane B
168 /// - Grey Plane + Palette Color
169 /// - YBR Pixels (or from RGB Pixels, as well)
170 size_t ImageDataSize;
172 /// \brief ==1 if GetImageDataRaw was used
173 /// ==0 if GetImageData was used
174 /// ==-1 if ImageData never read
177 /// \brief length of the last allocated area devoided to receive Pixels
178 /// ( to allow us not to (free + new) if un necessary )
179 size_t LastAllocatedPixelDataLength;
181 // Initial values of some fields that can be modified during reading process
182 // if user asked to transform gray level + LUT image into RGB image
184 /// \brief Samples Per Pixel (0x0028,0x0002), as found on disk
185 std::string InitialSpp;
186 /// \brief Photometric Interpretation (0x0028,0x0004), as found on disk
187 std::string InitialPhotInt;
188 /// \brief Planar Configuration (0x0028,0x0006), as found on disk
189 std::string InitialPlanConfig;
191 // Initial values of some fields that can be modified during reading process
192 // if the image was a 'strange' ACR-NEMA
193 // (Bits Allocated=12, High Bit not equal to Bits stored +1)
194 /// \brief Bits Allocated (0x0028,0x0100), as found on disk
195 std::string InitialBitsAllocated;
196 /// \brief High Bit (0x0028,0x0102), as found on disk
197 std::string InitialHighBit;
199 // some DocEntry that can be moved out of the H table during reading process
200 // if user asked to transform gray level + LUT image into RGB image
201 // We keep a pointer on them for a future use.
203 /// \brief Red Palette Color Lookup Table Descriptor 0028 1101 as read
204 DocEntry* InitialRedLUTDescr;
205 /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
206 DocEntry* InitialGreenLUTDescr;
207 /// \brief Blue Palette Color Lookup Table Descriptor 0028 1103 as read
208 DocEntry* InitialBlueLUTDescr;
210 /// \brief Red Palette Color Lookup Table Data 0028 1201 as read
211 DocEntry* InitialRedLUTData;
212 /// \brief Green Palette Color Lookup Table Data 0028 1202 as read
213 DocEntry* InitialGreenLUTData;
214 /// \brief Blue Palette Color Lookup Table Data 0028 1203 as read
215 DocEntry* InitialBlueLUTData;
218 // --------------- end of future PixelData class
222 } // end namespace gdcm
224 //-----------------------------------------------------------------------------