1 /*=========================================================================
4 Module: $RCSfile: gdcmFile.cxx,v $
6 Date: $Date: 2005/06/30 14:49:02 $
7 Version: $Revision: 1.245 $
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 =========================================================================*/
20 // -------------- Remember ! ----------------------------------
22 // Image Position Patient (0020,0032):
23 // If not found (ACR_NEMA) we try Image Position (0020,0030)
24 // If not found (ACR-NEMA), we consider Slice Location (0020,1041)
25 // or Location (0020,0050)
26 // as the Z coordinate,
27 // 0. for all the coordinates if nothing is found
29 // ---------------------------------------------------------------
32 #include "gdcmGlobal.h"
34 #include "gdcmDebug.h"
36 #include "gdcmValEntry.h"
37 #include "gdcmBinEntry.h"
38 #include "gdcmSeqEntry.h"
39 #include "gdcmRLEFramesInfo.h"
40 #include "gdcmJPEGFragmentsInfo.h"
42 #include <stdio.h> //sscanf
47 //-----------------------------------------------------------------------------
48 // Constructor / Destructor
51 * \brief Constructor used when we want to generate dicom files from scratch
56 RLEInfo = new RLEFramesInfo;
57 JPEGInfo = new JPEGFragmentsInfo;
58 GrPixel = 0x7fe0; // to avoid further troubles
64 * @param filename name of the file whose header we want to analyze
66 File::File( std::string const &filename )
69 RLEInfo = new RLEFramesInfo;
70 JPEGInfo = new JPEGFragmentsInfo;
76 * \brief Canonical destructor.
86 //-----------------------------------------------------------------------------
91 * @param fileName file to be open for parsing
92 * @return false if file cannot be open or no swap info was found,
93 * or no tag was found.
95 bool File::Load( std::string const &fileName )
97 this->Document::Load( fileName );
99 // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010
100 // We may encounter the 'RETired' (0x0028, 0x0200) tag
101 // (Image Location") . This entry contains the number of
102 // the group that contains the pixel data (hence the "Pixel Data"
103 // is found by indirection through the "Image Location").
104 // Inside the group pointed by "Image Location" the searched element
105 // is conventionally the element 0x0010 (when the norm is respected).
106 // When the "Image Location" is missing we default to group 0x7fe0.
107 // Note: this IS the right place for the code
110 const std::string &imgLocation = GetEntryValue(0x0028, 0x0200);
111 if ( imgLocation == GDCM_UNFOUND )
118 GrPixel = (uint16_t) atoi( imgLocation.c_str() );
121 // sometimes Image Location value doesn't follow
122 // the supposed processor endianness.
123 // see gdcmData/cr172241.dcm
124 if ( GrPixel == 0xe07f )
129 if ( GrPixel != 0x7fe0 )
131 // This is a kludge for old dirty Philips imager.
139 // Now, we know GrPixel and NumPixel.
140 // Let's create a VirtualDictEntry to allow a further VR modification
141 // and force VR to match with BitsAllocated.
142 DocEntry *entry = GetDocEntry(GrPixel, NumPixel);
145 // Compute the RLE or JPEG info
147 const std::string &ts = GetTransferSyntax();
148 Fp->seekg( entry->GetOffset(), std::ios::beg );
149 if ( Global::GetTS()->IsRLELossless(ts) )
151 else if ( Global::GetTS()->IsJPEG(ts) )
152 ComputeJPEGFragmentInfo();
155 // Create a new BinEntry to change the DictEntry
156 // The changed DictEntry will have
157 // - a correct PixelVR OB or OW)
158 // - the name to "Pixel Data"
159 BinEntry *oldEntry = dynamic_cast<BinEntry *>(entry);
163 // 8 bits allocated is a 'O Bytes' , as well as 24 (old ACR-NEMA RGB)
164 // more than 8 (i.e 12, 16) is a 'O Words'
165 if ( GetBitsAllocated() == 8 || GetBitsAllocated() == 24 )
170 // Change only made if usefull
171 if ( PixelVR != oldEntry->GetVR() )
173 DictEntry* newDict = NewVirtualDictEntry(GrPixel,NumPixel,
174 PixelVR,"1","Pixel Data");
176 BinEntry *newEntry = new BinEntry(newDict);
177 newEntry->Copy(entry);
178 newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea());
179 oldEntry->SetSelfArea(false);
181 RemoveEntry(oldEntry);
189 * \brief This predicate, based on hopefully reasonable heuristics,
190 * decides whether or not the current File was properly parsed
191 * and contains the mandatory information for being considered as
192 * a well formed and usable Dicom/Acr File.
193 * @return true when File is the one of a reasonable Dicom/Acr file,
196 bool File::IsReadable()
198 if ( !Document::IsReadable() )
203 const std::string &res = GetEntryValue(0x0028, 0x0005);
204 if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
206 gdcmWarningMacro("Wrong Image Dimensions" << res);
207 return false; // Image Dimensions
209 bool b0028_0100 = true;
210 if ( !GetDocEntry(0x0028, 0x0100) )
212 gdcmWarningMacro("Bits Allocated (0028|0100) not found");
213 //return false; // "Bits Allocated"
216 bool b0028_0101 = true;
217 if ( !GetDocEntry(0x0028, 0x0101) )
219 gdcmWarningMacro("Bits Stored (0028|0101) not found");
220 //return false; // "Bits Stored"
223 bool b0028_0102 = true;
224 if ( !GetDocEntry(0x0028, 0x0102) )
226 gdcmWarningMacro("Hight Bit (0028|0102) not found");
227 //return false; // "High Bit"
230 bool b0028_0103 = true;
231 if ( !GetDocEntry(0x0028, 0x0103) )
233 gdcmWarningMacro("Pixel Representation (0028|0103) not found");
234 //return false; // "Pixel Representation" i.e. 'Sign' ( 0 : unsigned, 1 : signed)
238 if ( !b0028_0100 && !b0028_0101 && !b0028_0102 && !b0028_0103)
240 gdcmWarningMacro("Too much mandatory Tags missing !");
244 if ( !GetDocEntry(GrPixel, NumPixel) )
246 gdcmWarningMacro("Pixel Dicom Element " << std::hex <<
247 GrPixel << "|" << NumPixel << "not found");
248 return false; // Pixel Dicom Element not found :-(
254 * \brief gets the info from 0020,0013 : Image Number else 0.
255 * @return image number
257 int File::GetImageNumber()
259 //0020 0013 : Image Number
260 std::string strImNumber = GetEntryValue(0x0020,0x0013);
261 if ( strImNumber != GDCM_UNFOUND )
263 return atoi( strImNumber.c_str() );
269 * \brief gets the info from 0008,0060 : Modality
270 * @return Modality Type
272 ModalityType File::GetModality()
274 // 0008 0060 : Modality
275 std::string strModality = GetEntryValue(0x0008,0x0060);
276 if ( strModality != GDCM_UNFOUND )
278 if ( strModality.find("AU") < strModality.length()) return AU;
279 else if ( strModality.find("AS") < strModality.length()) return AS;
280 else if ( strModality.find("BI") < strModality.length()) return BI;
281 else if ( strModality.find("CF") < strModality.length()) return CF;
282 else if ( strModality.find("CP") < strModality.length()) return CP;
283 else if ( strModality.find("CR") < strModality.length()) return CR;
284 else if ( strModality.find("CT") < strModality.length()) return CT;
285 else if ( strModality.find("CS") < strModality.length()) return CS;
286 else if ( strModality.find("DD") < strModality.length()) return DD;
287 else if ( strModality.find("DF") < strModality.length()) return DF;
288 else if ( strModality.find("DG") < strModality.length()) return DG;
289 else if ( strModality.find("DM") < strModality.length()) return DM;
290 else if ( strModality.find("DS") < strModality.length()) return DS;
291 else if ( strModality.find("DX") < strModality.length()) return DX;
292 else if ( strModality.find("ECG") < strModality.length()) return ECG;
293 else if ( strModality.find("EPS") < strModality.length()) return EPS;
294 else if ( strModality.find("FA") < strModality.length()) return FA;
295 else if ( strModality.find("FS") < strModality.length()) return FS;
296 else if ( strModality.find("HC") < strModality.length()) return HC;
297 else if ( strModality.find("HD") < strModality.length()) return HD;
298 else if ( strModality.find("LP") < strModality.length()) return LP;
299 else if ( strModality.find("LS") < strModality.length()) return LS;
300 else if ( strModality.find("MA") < strModality.length()) return MA;
301 else if ( strModality.find("MR") < strModality.length()) return MR;
302 else if ( strModality.find("NM") < strModality.length()) return NM;
303 else if ( strModality.find("OT") < strModality.length()) return OT;
304 else if ( strModality.find("PT") < strModality.length()) return PT;
305 else if ( strModality.find("RF") < strModality.length()) return RF;
306 else if ( strModality.find("RG") < strModality.length()) return RG;
307 else if ( strModality.find("RTDOSE")
308 < strModality.length()) return RTDOSE;
309 else if ( strModality.find("RTIMAGE")
310 < strModality.length()) return RTIMAGE;
311 else if ( strModality.find("RTPLAN")
312 < strModality.length()) return RTPLAN;
313 else if ( strModality.find("RTSTRUCT")
314 < strModality.length()) return RTSTRUCT;
315 else if ( strModality.find("SM") < strModality.length()) return SM;
316 else if ( strModality.find("ST") < strModality.length()) return ST;
317 else if ( strModality.find("TG") < strModality.length()) return TG;
318 else if ( strModality.find("US") < strModality.length()) return US;
319 else if ( strModality.find("VF") < strModality.length()) return VF;
320 else if ( strModality.find("XA") < strModality.length()) return XA;
321 else if ( strModality.find("XC") < strModality.length()) return XC;
325 /// \todo throw error return value ???
326 /// specified <> unknown in our database
334 * \brief Retrieve the number of columns of image.
335 * @return The encountered size when found, 0 by default.
336 * 0 means the file is NOT USABLE. The caller will have to check
340 const std::string &strSize = GetEntryValue(0x0028,0x0011);
341 if ( strSize == GDCM_UNFOUND )
345 return atoi( strSize.c_str() );
349 * \brief Retrieve the number of lines of image.
350 * \warning The defaulted value is 1 as opposed to File::GetXSize()
351 * @return The encountered size when found, 1 by default
352 * (The ACR-NEMA file contains a Signal, not an Image).
356 const std::string &strSize = GetEntryValue(0x0028,0x0010);
357 if ( strSize != GDCM_UNFOUND )
359 return atoi( strSize.c_str() );
366 // The Rows (0028,0010) entry was optional for ACR/NEMA.
367 // (at least some images didn't have it.)
368 // It might hence be a signal (1D image). So we default to 1:
373 * \brief Retrieve the number of planes of volume or the number
374 * of frames of a multiframe.
375 * \warning When present we consider the "Number of Frames" as the third
376 * dimension. When missing we consider the third dimension as
377 * being the ACR-NEMA "Planes" tag content.
378 * @return The encountered size when found, 1 by default (single image).
382 // Both DicomV3 and ACR/Nema consider the "Number of Frames"
383 // as the third dimension.
384 const std::string &strSize = GetEntryValue(0x0028,0x0008);
385 if ( strSize != GDCM_UNFOUND )
387 return atoi( strSize.c_str() );
390 // We then consider the "Planes" entry as the third dimension
391 const std::string &strSize2 = GetEntryValue(0x0028,0x0012);
392 if ( strSize2 != GDCM_UNFOUND )
394 return atoi( strSize2.c_str() );
400 * \brief gets the info from 0018,1164 : ImagerPixelSpacing
401 * then 0028,0030 : Pixel Spacing
403 * @return X dimension of a pixel
405 float File::GetXSpacing()
407 float xspacing = 1.0;
408 float yspacing = 1.0;
411 // To follow David Clunie's advice, we first check ImagerPixelSpacing
413 const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
414 if ( strImagerPixelSpacing != GDCM_UNFOUND )
416 if ( ( nbValues = sscanf( strImagerPixelSpacing.c_str(),
417 "%f\\%f", &yspacing, &xspacing)) != 2 )
419 // if no values, xspacing is set to 1.0
422 // if single value is found, xspacing is defaulted to yspacing
426 if ( xspacing == 0.0 )
433 const std::string &strSpacing = GetEntryValue(0x0028,0x0030);
435 if ( strSpacing == GDCM_UNFOUND )
437 gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" );
441 if ( ( nbValues = sscanf( strSpacing.c_str(),
442 "%f \\%f ", &yspacing, &xspacing)) != 2 )
444 // if no values, xspacing is set to 1.0
447 // if single value is found, xspacing is defaulted to yspacing
451 if ( xspacing == 0.0 )
457 // to avoid troubles with David Clunie's-like images (at least one)
458 if ( xspacing == 0. && yspacing == 0.)
463 gdcmWarningMacro("gdcmData/CT-MONO2-8-abdo.dcm-like problem");
464 // seems to be a bug in the header ...
465 nbValues = sscanf( strSpacing.c_str(), "%f \\0\\%f ", &yspacing, &xspacing);
466 gdcmAssertMacro( nbValues == 2 );
473 * \brief gets the info from 0018,1164 : ImagerPixelSpacing
474 * then from 0028,0030 : Pixel Spacing
476 * @return Y dimension of a pixel
478 float File::GetYSpacing()
482 // To follow David Clunie's advice, we first check ImagerPixelSpacing
484 const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
485 if ( strImagerPixelSpacing != GDCM_UNFOUND )
487 nbValues = sscanf( strImagerPixelSpacing.c_str(), "%f", &yspacing);
489 // if sscanf cannot read any float value, it won't affect yspacing
493 if ( yspacing == 0.0 )
499 std::string strSpacing = GetEntryValue(0x0028,0x0030);
500 if ( strSpacing == GDCM_UNFOUND )
502 gdcmWarningMacro("Unfound Pixel Spacing (0028,0030)");
506 // if sscanf cannot read any float value, it won't affect yspacing
507 nbValues = sscanf( strSpacing.c_str(), "%f", &yspacing);
509 // if no values, yspacing is set to 1.0
513 if ( yspacing == 0.0 )
520 * \brief gets the info from 0018,0088 : Space Between Slices
521 * else from 0018,0050 : Slice Thickness
523 * @return Z dimension of a voxel-to be
525 float File::GetZSpacing()
527 // Spacing Between Slices : distance between the middle of 2 slices
529 // jointives (Spacing between Slices = Slice Thickness)
530 // overlapping (Spacing between Slices < Slice Thickness)
531 // disjointes (Spacing between Slices > Slice Thickness)
532 // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
533 // It only concerns the MRI guys, not people wanting to visualize volumes
534 // If Spacing Between Slices is missing,
535 // we suppose slices joint together
537 const std::string &strSpacingBSlices = GetEntryValue(0x0018,0x0088);
539 if ( strSpacingBSlices == GDCM_UNFOUND )
541 gdcmWarningMacro("Unfound Spacing Between Slices (0018,0088)");
542 const std::string &strSliceThickness = GetEntryValue(0x0018,0x0050);
543 if ( strSliceThickness == GDCM_UNFOUND )
545 gdcmWarningMacro("Unfound Slice Thickness (0018,0050)");
550 // if no 'Spacing Between Slices' is found,
551 // we assume slices join together
552 // (no overlapping, no interslice gap)
553 // if they don't, we're fucked up
554 return (float)atof( strSliceThickness.c_str() );
558 return (float)atof( strSpacingBSlices.c_str() );
562 * \brief gets the info from 0020,0032 : Image Position Patient
563 * else from 0020,0030 : Image Position (RET)
565 * @return up-left image corner X position
567 float File::GetXOrigin()
569 float xImPos, yImPos, zImPos;
570 std::string strImPos = GetEntryValue(0x0020,0x0032);
572 if ( strImPos == GDCM_UNFOUND )
574 gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
575 strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
576 if ( strImPos == GDCM_UNFOUND )
578 gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
583 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3 )
592 * \brief gets the info from 0020,0032 : Image Position Patient
593 * else from 0020,0030 : Image Position (RET)
595 * @return up-left image corner Y position
597 float File::GetYOrigin()
599 float xImPos, yImPos, zImPos;
600 std::string strImPos = GetEntryValue(0x0020,0x0032);
602 if ( strImPos == GDCM_UNFOUND)
604 gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
605 strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
606 if ( strImPos == GDCM_UNFOUND )
608 gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
613 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3 )
622 * \brief gets the info from 0020,0032 : Image Position Patient
623 * else from 0020,0030 : Image Position (RET)
624 * else from 0020,1041 : Slice Location
625 * else from 0020,0050 : Location
627 * @return up-left image corner Z position
629 float File::GetZOrigin()
631 float xImPos, yImPos, zImPos;
632 std::string strImPos = GetEntryValue(0x0020,0x0032);
634 if ( strImPos != GDCM_UNFOUND )
636 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3)
638 gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)");
639 return 0.; // bug in the element 0x0020,0x0032
647 strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
648 if ( strImPos != GDCM_UNFOUND )
650 if ( sscanf( strImPos.c_str(),
651 "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos ) != 3 )
653 gdcmWarningMacro( "Wrong Image Position (RET) (0020,0030)");
654 return 0.; // bug in the element 0x0020,0x0032
662 // for *very* old ACR-NEMA images
663 std::string strSliceLocation = GetEntryValue(0x0020,0x1041);
664 if ( strSliceLocation != GDCM_UNFOUND )
666 if ( sscanf( strSliceLocation.c_str(), "%f ", &zImPos) != 1)
668 gdcmWarningMacro( "Wrong Slice Location (0020,1041)");
669 return 0.; // bug in the element 0x0020,0x1041
676 gdcmWarningMacro( "Unfound Slice Location (0020,1041)");
678 std::string strLocation = GetEntryValue(0x0020,0x0050);
679 if ( strLocation != GDCM_UNFOUND )
681 if ( sscanf( strLocation.c_str(), "%f ", &zImPos) != 1 )
683 gdcmWarningMacro( "Wrong Location (0020,0050)");
684 return 0.; // bug in the element 0x0020,0x0050
691 gdcmWarningMacro( "Unfound Location (0020,0050)");
693 return 0.; // Hopeless
697 * \brief gets the info from 0020,0037 : Image Orientation Patient
698 * (needed to organize DICOM files based on their x,y,z position)
699 * @param iop adress of the (6)float array to receive values
700 * @return cosines of image orientation patient
702 void File::GetImageOrientationPatient( float iop[6] )
704 std::string strImOriPat;
705 //iop is supposed to be float[6]
706 iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.;
708 // 0020 0037 DS REL Image Orientation (Patient)
709 if ( (strImOriPat = GetEntryValue(0x0020,0x0037)) != GDCM_UNFOUND )
711 if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ",
712 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
714 gdcmWarningMacro( "Wrong Image Orientation Patient (0020,0037). Less than 6 values were found." );
718 // 0020 0035 DS REL Image Orientation (RET)
719 else if ( (strImOriPat = GetEntryValue(0x0020,0x0035)) != GDCM_UNFOUND )
721 if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ",
722 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
724 gdcmWarningMacro( "wrong Image Orientation Patient (0020,0035). Less than 6 values were found." );
730 * \brief Retrieve the number of Bits Stored (actually used)
731 * (as opposed to number of Bits Allocated)
732 * @return The encountered number of Bits Stored, 0 by default.
733 * 0 means the file is NOT USABLE. The caller has to check it !
735 int File::GetBitsStored()
737 std::string strSize = GetEntryValue( 0x0028, 0x0101 );
738 if ( strSize == GDCM_UNFOUND )
740 gdcmWarningMacro("(0028,0101) is supposed to be mandatory");
741 return 0; // It's supposed to be mandatory
742 // the caller will have to check
744 return atoi( strSize.c_str() );
748 * \brief Retrieve the number of Bits Allocated
749 * (8, 12 -compacted ACR-NEMA files-, 16, ...)
750 * @return The encountered number of Bits Allocated, 0 by default.
751 * 0 means the file is NOT USABLE. The caller has to check it !
753 int File::GetBitsAllocated()
755 std::string strSize = GetEntryValue(0x0028,0x0100);
756 if ( strSize == GDCM_UNFOUND )
758 gdcmWarningMacro( "(0028,0100) is supposed to be mandatory");
759 return 0; // It's supposed to be mandatory
760 // the caller will have to check
762 return atoi( strSize.c_str() );
766 * \brief Retrieve the high bit position.
767 * \warning The method defaults to 0 when information is missing.
768 * The responsability of checking this value is left to the caller.
769 * @return The high bit position when present. 0 when missing.
771 int File::GetHighBitPosition()
773 std::string strSize = GetEntryValue( 0x0028, 0x0102 );
774 if ( strSize == GDCM_UNFOUND )
776 gdcmWarningMacro( "(0028,0102) is supposed to be mandatory");
779 return atoi( strSize.c_str() );
783 * \brief Retrieve the number of Samples Per Pixel
784 * (1 : gray level, 3 : RGB/YBR -1 or 3 Planes-)
785 * @return The encountered number of Samples Per Pixel, 1 by default.
786 * (we assume Gray level Pixels)
788 int File::GetSamplesPerPixel()
790 const std::string &strSize = GetEntryValue(0x0028,0x0002);
791 if ( strSize == GDCM_UNFOUND )
793 gdcmWarningMacro( "(0028,0002) is supposed to be mandatory");
794 return 1; // Well, it's supposed to be mandatory ...
795 // but sometimes it's missing : *we* assume Gray pixels
797 return atoi( strSize.c_str() );
801 * \brief Retrieve the Planar Configuration for RGB images
802 * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
803 * @return The encountered Planar Configuration, 0 by default.
805 int File::GetPlanarConfiguration()
807 std::string strSize = GetEntryValue(0x0028,0x0006);
808 if ( strSize == GDCM_UNFOUND )
810 gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)");
813 return atoi( strSize.c_str() );
817 * \brief Return the size (in bytes) of a single pixel of data.
818 * @return The size in bytes of a single pixel of data; 0 by default
819 * 0 means the file is NOT USABLE; the caller will have to check
821 int File::GetPixelSize()
823 // 0028 0100 US IMG Bits Allocated
824 // (in order no to be messed up by old ACR-NEMA RGB images)
825 // if (File::GetEntryValue(0x0028,0x0100) == "24")
828 std::string pixelType = GetPixelType();
829 if ( pixelType == "8U" || pixelType == "8S" )
833 if ( pixelType == "16U" || pixelType == "16S")
837 if ( pixelType == "32U" || pixelType == "32S")
841 if ( pixelType == "FD" )
845 gdcmWarningMacro( "Unknown pixel type");
850 * \brief Build the Pixel Type of the image.
851 * Possible values are:
852 * - 8U unsigned 8 bit,
854 * - 16U unsigned 16 bit,
855 * - 16S signed 16 bit,
856 * - 32U unsigned 32 bit,
857 * - 32S signed 32 bit,
858 * - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
859 * \warning 12 bit images appear as 16 bit.
860 * 24 bit images appear as 8 bit + photochromatic interp ="RGB "
861 * + Planar Configuration = 0
862 * @return 0S if nothing found. NOT USABLE file. The caller has to check
864 std::string File::GetPixelType()
866 std::string bitsAlloc = GetEntryValue(0x0028, 0x0100); // Bits Allocated
867 if ( bitsAlloc == GDCM_UNFOUND )
869 gdcmWarningMacro( "Missing Bits Allocated (0028,0100)");
870 bitsAlloc = "16"; // default and arbitrary value, not to polute the output
873 if ( bitsAlloc == "64" )
877 else if ( bitsAlloc == "12" )
879 // It will be unpacked
882 else if ( bitsAlloc == "24" )
884 // (in order no to be messed up
885 bitsAlloc = "8"; // by old RGB images)
888 std::string sign = GetEntryValue(0x0028, 0x0103);//"Pixel Representation"
890 if (sign == GDCM_UNFOUND )
892 gdcmWarningMacro( "Missing Pixel Representation (0028,0103)");
893 sign = "U"; // default and arbitrary value, not to polute the output
895 else if ( sign == "0" )
903 return bitsAlloc + sign;
907 * \brief Check whether the pixels are signed (1) or UNsigned (0) data.
908 * \warning The method defaults to false (UNsigned) when tag 0028|0103
910 * The responsability of checking this value is left to the caller
911 * (NO transformation is performed on the pixels to make then >0)
912 * @return True when signed, false when UNsigned
914 bool File::IsSignedPixelData()
916 std::string strSign = GetEntryValue( 0x0028, 0x0103 );
917 if ( strSign == GDCM_UNFOUND )
919 gdcmWarningMacro( "(0028,0103) is supposed to be mandatory");
922 int sign = atoi( strSign.c_str() );
931 * \brief Check whether this a monochrome picture (gray levels) or not,
932 * using "Photometric Interpretation" tag (0x0028,0x0004).
933 * @return true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
935 bool File::IsMonochrome()
937 const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
938 if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1")
939 || Util::DicomStringEqual(PhotometricInterp, "MONOCHROME2") )
943 if ( PhotometricInterp == GDCM_UNFOUND )
945 gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
951 * \brief Check whether this a MONOCHROME1 picture (high values = dark)
952 * or not using "Photometric Interpretation" tag (0x0028,0x0004).
953 * @return true when "MONOCHROME1" . False otherwise.
955 bool File::IsMonochrome1()
957 const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
958 if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
962 if ( PhotometricInterp == GDCM_UNFOUND )
964 gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
970 * \brief Check whether this a "PALETTE COLOR" picture or not by accessing
971 * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
972 * @return true when "PALETTE COLOR". False otherwise.
974 bool File::IsPaletteColor()
976 std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
977 if ( PhotometricInterp == "PALETTE COLOR " )
981 if ( PhotometricInterp == GDCM_UNFOUND )
983 gdcmWarningMacro( "Not found : Palette color (0028,0004)");
989 * \brief Check whether this a "YBR_FULL" color picture or not by accessing
990 * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
991 * @return true when "YBR_FULL". False otherwise.
993 bool File::IsYBRFull()
995 std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
996 if ( PhotometricInterp == "YBR_FULL" )
1000 if ( PhotometricInterp == GDCM_UNFOUND )
1002 gdcmWarningMacro( "Not found : YBR Full (0028,0004)");
1008 * \brief tells us if LUT are used
1009 * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
1010 * are NOT considered as LUT, since nobody knows
1011 * how to deal with them
1012 * Please warn me if you know sbdy that *does* know ... jprx
1013 * @return true if LUT Descriptors and LUT Tables were found
1017 // Check the presence of the LUT Descriptors, and LUT Tables
1019 if ( !GetDocEntry(0x0028,0x1101) )
1023 // LutDescriptorGreen
1024 if ( !GetDocEntry(0x0028,0x1102) )
1028 // LutDescriptorBlue
1029 if ( !GetDocEntry(0x0028,0x1103) )
1033 // Red Palette Color Lookup Table Data
1034 if ( !GetDocEntry(0x0028,0x1201) )
1038 // Green Palette Color Lookup Table Data
1039 if ( !GetDocEntry(0x0028,0x1202) )
1043 // Blue Palette Color Lookup Table Data
1044 if ( !GetDocEntry(0x0028,0x1203) )
1049 // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
1050 // NOT taken into account, but we don't know how to use it ...
1055 * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
1057 * @return Lookup Table number of Bits , 0 by default
1058 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1059 * @ return bit number of each LUT item
1061 int File::GetLUTNbits()
1063 std::vector<std::string> tokens;
1066 //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red
1067 // = Lookup Table Desc-Blue
1068 // Consistency already checked in GetLUTLength
1069 std::string lutDescription = GetEntryValue(0x0028,0x1101);
1070 if ( lutDescription == GDCM_UNFOUND )
1075 tokens.clear(); // clean any previous value
1076 Util::Tokenize ( lutDescription, tokens, "\\" );
1077 //LutLength=atoi(tokens[0].c_str());
1078 //LutDepth=atoi(tokens[1].c_str());
1080 lutNbits = atoi( tokens[2].c_str() );
1087 *\brief gets the info from 0028,1052 : Rescale Intercept
1088 * @return Rescale Intercept
1090 float File::GetRescaleIntercept()
1092 float resInter = 0.;
1093 /// 0028 1052 DS IMG Rescale Intercept
1094 const std::string &strRescInter = GetEntryValue(0x0028,0x1052);
1095 if ( strRescInter != GDCM_UNFOUND )
1097 if ( sscanf( strRescInter.c_str(), "%f ", &resInter) != 1 )
1099 // bug in the element 0x0028,0x1052
1100 gdcmWarningMacro( "Rescale Intercept (0028,1052) is empty." );
1108 *\brief gets the info from 0028,1053 : Rescale Slope
1109 * @return Rescale Slope
1111 float File::GetRescaleSlope()
1113 float resSlope = 1.;
1114 //0028 1053 DS IMG Rescale Slope
1115 std::string strRescSlope = GetEntryValue(0x0028,0x1053);
1116 if ( strRescSlope != GDCM_UNFOUND )
1118 if ( sscanf( strRescSlope.c_str(), "%f ", &resSlope) != 1 )
1120 // bug in the element 0x0028,0x1053
1121 gdcmWarningMacro( "Rescale Slope (0028,1053) is empty.");
1129 * \brief This function is intended to user who doesn't want
1130 * to have to manage a LUT and expects to get an RBG Pixel image
1131 * (or a monochrome one ...)
1132 * \warning to be used with GetImagePixels()
1133 * @return 1 if Gray level, 3 if Color (RGB, YBR, *or PALETTE COLOR*)
1135 int File::GetNumberOfScalarComponents()
1137 if ( GetSamplesPerPixel() == 3 )
1142 // 0028 0100 US IMG Bits Allocated
1143 // (in order no to be messed up by old RGB images)
1144 if ( GetEntryValue(0x0028,0x0100) == "24" )
1149 std::string strPhotometricInterpretation = GetEntryValue(0x0028,0x0004);
1151 if ( ( strPhotometricInterpretation == "PALETTE COLOR ") )
1153 if ( HasLUT() )// PALETTE COLOR is NOT enough
1163 // beware of trailing space at end of string
1164 // DICOM tags are never of odd length
1165 if ( strPhotometricInterpretation == GDCM_UNFOUND ||
1166 Util::DicomStringEqual(strPhotometricInterpretation, "MONOCHROME1") ||
1167 Util::DicomStringEqual(strPhotometricInterpretation, "MONOCHROME2") )
1173 // we assume that *all* kinds of YBR are dealt with
1179 * \brief This function is intended to user that DOESN'T want
1180 * to get RGB pixels image when it's stored as a PALETTE COLOR image
1181 * - the (vtk) user is supposed to know how deal with LUTs -
1182 * \warning to be used with GetImagePixelsRaw()
1183 * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
1185 int File::GetNumberOfScalarComponentsRaw()
1187 // 0028 0100 US IMG Bits Allocated
1188 // (in order no to be messed up by old RGB images)
1189 if ( File::GetEntryValue(0x0028,0x0100) == "24" )
1194 // we assume that *all* kinds of YBR are dealt with
1195 return GetSamplesPerPixel();
1199 * \brief Recover the offset (from the beginning of the file)
1200 * of *image* pixels (not *icone image* pixels, if any !)
1201 * @return Pixel Offset
1203 size_t File::GetPixelOffset()
1205 DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel);
1208 return pxlElement->GetOffset();
1212 gdcmDebugMacro( "Big trouble : Pixel Element ("
1213 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" );
1219 * \brief Recover the pixel area length (in Bytes)
1220 * @return Pixel Element Length, as stored in the header
1221 * (NOT the memory space necessary to hold the Pixels
1222 * -in case of embeded compressed image-)
1223 * 0 : NOT USABLE file. The caller has to check.
1225 size_t File::GetPixelAreaLength()
1227 DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel);
1230 return pxlElement->GetLength();
1234 gdcmDebugMacro( "Big trouble : Pixel Element ("
1235 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" );
1241 * \brief Adds the characteristics of a new element we want to anonymize
1242 * @param group Group number of the target tag.
1243 * @param elem Element number of the target tag.
1244 * @param value new value (string) to substitute with
1246 void File::AddAnonymizeElement (uint16_t group, uint16_t elem,
1247 std::string const &value)
1253 AnonymizeList.push_back(el);
1257 * \brief Overwrites in the file the values of the DicomElements
1260 void File::AnonymizeNoLoad()
1262 std::fstream *fp = new std::fstream(Filename.c_str(),
1263 std::ios::in | std::ios::out | std::ios::binary);
1267 uint32_t valLgth = 0;
1268 std::string *spaces;
1269 for (ListElements::iterator it = AnonymizeList.begin();
1270 it != AnonymizeList.end();
1273 d = GetDocEntry( (*it).Group, (*it).Elem);
1278 if ( dynamic_cast<BinEntry *>(d)
1279 || dynamic_cast<SeqEntry *>(d) )
1282 offset = d->GetOffset();
1283 lgth = d->GetLength();
1286 spaces = new std::string( lgth-valLgth, ' ');
1287 (*it).Value = (*it).Value + *spaces;
1290 fp->seekp( offset, std::ios::beg );
1291 fp->write( (*it).Value.c_str(), lgth );
1299 * \brief anonymize a File (remove Patient's personal info passed with
1300 * AddAnonymizeElement()
1302 bool File::AnonymizeFile()
1304 // If Anonymisation list is empty, let's perform some basic anonymization
1305 if ( AnonymizeList.begin() == AnonymizeList.end() )
1307 // If exist, replace by spaces
1308 SetValEntry (" ",0x0010, 0x2154); // Telephone
1309 SetValEntry (" ",0x0010, 0x1040); // Adress
1310 SetValEntry (" ",0x0010, 0x0020); // Patient ID
1312 DocEntry* patientNameHE = GetDocEntry (0x0010, 0x0010);
1314 if ( patientNameHE ) // we replace it by Study Instance UID (why not ?)
1316 std::string studyInstanceUID = GetEntryValue (0x0020, 0x000d);
1317 if ( studyInstanceUID != GDCM_UNFOUND )
1319 SetValEntry(studyInstanceUID, 0x0010, 0x0010);
1323 SetValEntry("anonymised", 0x0010, 0x0010);
1330 for (ListElements::iterator it = AnonymizeList.begin();
1331 it != AnonymizeList.end();
1334 d = GetDocEntry( (*it).Group, (*it).Elem);
1339 if ( dynamic_cast<BinEntry *>(d)
1340 || dynamic_cast<SeqEntry *>(d) )
1343 SetValEntry ((*it).Value, (*it).Group, (*it).Elem);
1347 // In order to make definitively impossible any further identification
1348 // remove or replace all the stuff that contains a Date
1350 //0008 0012 DA ID Instance Creation Date
1351 //0008 0020 DA ID Study Date
1352 //0008 0021 DA ID Series Date
1353 //0008 0022 DA ID Acquisition Date
1354 //0008 0023 DA ID Content Date
1355 //0008 0024 DA ID Overlay Date
1356 //0008 0025 DA ID Curve Date
1357 //0008 002a DT ID Acquisition Datetime
1358 //0018 9074 DT ACQ Frame Acquisition Datetime
1359 //0018 9151 DT ACQ Frame Reference Datetime
1360 //0018 a002 DT ACQ Contribution Date Time
1361 //0020 3403 SH REL Modified Image Date (RET)
1362 //0032 0032 DA SDY Study Verified Date
1363 //0032 0034 DA SDY Study Read Date
1364 //0032 1000 DA SDY Scheduled Study Start Date
1365 //0032 1010 DA SDY Scheduled Study Stop Date
1366 //0032 1040 DA SDY Study Arrival Date
1367 //0032 1050 DA SDY Study Completion Date
1368 //0038 001a DA VIS Scheduled Admission Date
1369 //0038 001c DA VIS Scheduled Discharge Date
1370 //0038 0020 DA VIS Admitting Date
1371 //0038 0030 DA VIS Discharge Date
1372 //0040 0002 DA PRC Scheduled Procedure Step Start Date
1373 //0040 0004 DA PRC Scheduled Procedure Step End Date
1374 //0040 0244 DA PRC Performed Procedure Step Start Date
1375 //0040 0250 DA PRC Performed Procedure Step End Date
1376 //0040 2004 DA PRC Issue Date of Imaging Service Request
1377 //0040 4005 DT PRC Scheduled Procedure Step Start Date and Time
1378 //0040 4011 DT PRC Expected Completion Date and Time
1379 //0040 a030 DT PRC Verification Date Time
1380 //0040 a032 DT PRC Observation Date Time
1381 //0040 a120 DT PRC DateTime
1382 //0040 a121 DA PRC Date
1383 //0040 a13a DT PRC Referenced Datetime
1384 //0070 0082 DA ??? Presentation Creation Date
1385 //0100 0420 DT ??? SOP Autorization Date and Time
1386 //0400 0105 DT ??? Digital Signature DateTime
1387 //2100 0040 DA PJ Creation Date
1388 //3006 0008 DA SSET Structure Set Date
1389 //3008 0024 DA ??? Treatment Control Point Date
1390 //3008 0054 DA ??? First Treatment Date
1391 //3008 0056 DA ??? Most Recent Treatment Date
1392 //3008 0162 DA ??? Safe Position Exit Date
1393 //3008 0166 DA ??? Safe Position Return Date
1394 //3008 0250 DA ??? Treatment Date
1395 //300a 0006 DA RT RT Plan Date
1396 //300a 022c DA RT Air Kerma Rate Reference Date
1397 //300e 0004 DA RT Review Date
1403 * \brief Performs some consistency checking on various 'File related'
1404 * (as opposed to 'DicomDir related') entries
1405 * then writes in a file all the (Dicom Elements) included the Pixels
1406 * @param fileName file name to write to
1407 * @param writetype type of the file to be written
1408 * (ACR, ExplicitVR, ImplicitVR)
1410 bool File::Write(std::string fileName, FileType writetype)
1412 std::ofstream *fp = new std::ofstream(fileName.c_str(),
1413 std::ios::out | std::ios::binary);
1416 gdcmWarningMacro("Failed to open (write) File: " << fileName.c_str());
1420 // Entry : 0002|0000 = group length -> recalculated
1421 ValEntry*e0000 = GetValEntry(0x0002,0x0000);
1424 std::ostringstream sLen;
1425 sLen << ComputeGroup0002Length(writetype);
1426 e0000->SetValue(sLen.str());
1429 int i_lgPix = GetEntryLength(GrPixel, NumPixel);
1432 // no (GrPixel, NumPixel) element
1433 std::string s_lgPix = Util::Format("%d", i_lgPix+12);
1434 s_lgPix = Util::DicomString( s_lgPix.c_str() );
1435 InsertValEntry(s_lgPix,GrPixel, 0x0000);
1438 Document::WriteContent(fp, writetype);
1446 //-----------------------------------------------------------------------------
1450 //-----------------------------------------------------------------------------
1453 * \brief Parse pixel data from disk of [multi-]fragment RLE encoding.
1454 * Compute the RLE extra information and store it in \ref RLEInfo
1455 * for later pixel retrieval usage.
1457 void File::ComputeRLEInfo()
1459 std::string ts = GetTransferSyntax();
1460 if ( !Global::GetTS()->IsRLELossless(ts) )
1465 // Encoded pixel data: for the time being we are only concerned with
1466 // Jpeg or RLE Pixel data encodings.
1467 // As stated in PS 3.5-2003, section 8.2 p44:
1468 // "If sent in Encapsulated Format (i.e. other than the Native Format) the
1469 // value representation OB is used".
1470 // Hence we expect an OB value representation. Concerning OB VR,
1471 // the section PS 3.5-2003, section A.4.c p 58-59, states:
1472 // "For the Value Representations OB and OW, the encoding shall meet the
1473 // following specifications depending on the Data element tag:"
1475 // - the first item in the sequence of items before the encoded pixel
1476 // data stream shall be basic offset table item. The basic offset table
1477 // item value, however, is not required to be present"
1478 ReadAndSkipEncapsulatedBasicOffsetTable();
1480 // Encapsulated RLE Compressed Images (see PS 3.5-2003, Annex G)
1481 // Loop on the individual frame[s] and store the information
1482 // on the RLE fragments in a RLEFramesInfo.
1483 // Note: - when only a single frame is present, this is a
1485 // - when more than one frame are present, then we are in
1486 // the case of a multi-frame image.
1488 while ( (frameLength = ReadTagLength(0xfffe, 0xe000)) != 0 )
1490 // Parse the RLE Header and store the corresponding RLE Segment
1491 // Offset Table information on fragments of this current Frame.
1492 // Note that the fragment pixels themselves are not loaded
1493 // (but just skipped).
1494 long frameOffset = Fp->tellg();
1496 uint32_t nbRleSegments = ReadInt32();
1497 if ( nbRleSegments > 16 )
1499 // There should be at most 15 segments (refer to RLEFrame class)
1500 gdcmWarningMacro( "Too many segments.");
1503 uint32_t rleSegmentOffsetTable[16];
1504 for( int k = 1; k <= 15; k++ )
1506 rleSegmentOffsetTable[k] = ReadInt32();
1509 // Deduce from both RLE Header and frameLength
1510 // the fragment length, and again store this info
1511 // in a RLEFramesInfo.
1512 long rleSegmentLength[15];
1513 // skipping (not reading) RLE Segments
1514 if ( nbRleSegments > 1)
1516 for(unsigned int k = 1; k <= nbRleSegments-1; k++)
1518 rleSegmentLength[k] = rleSegmentOffsetTable[k+1]
1519 - rleSegmentOffsetTable[k];
1520 SkipBytes(rleSegmentLength[k]);
1524 rleSegmentLength[nbRleSegments] = frameLength
1525 - rleSegmentOffsetTable[nbRleSegments];
1526 SkipBytes(rleSegmentLength[nbRleSegments]);
1528 // Store the collected info
1529 RLEFrame *newFrame = new RLEFrame;
1530 newFrame->SetNumberOfFragments(nbRleSegments);
1531 for( unsigned int uk = 1; uk <= nbRleSegments; uk++ )
1533 newFrame->SetOffset(uk,frameOffset + rleSegmentOffsetTable[uk]);
1534 newFrame->SetLength(uk,rleSegmentLength[uk]);
1536 RLEInfo->AddFrame(newFrame);
1539 // Make sure that we encounter a 'Sequence Delimiter Item'
1540 // at the end of the item :
1541 if ( !ReadTag(0xfffe, 0xe0dd) )
1543 gdcmWarningMacro( "No sequence delimiter item at end of RLE item sequence");
1548 * \brief Parse pixel data from disk of [multi-]fragment Jpeg encoding.
1549 * Compute the jpeg extra information (fragment[s] offset[s] and
1550 * length) and store it[them] in \ref JPEGInfo for later pixel
1553 void File::ComputeJPEGFragmentInfo()
1555 // If you need to, look for comments of ComputeRLEInfo().
1556 std::string ts = GetTransferSyntax();
1557 if ( ! Global::GetTS()->IsJPEG(ts) )
1562 ReadAndSkipEncapsulatedBasicOffsetTable();
1564 // Loop on the fragments[s] and store the parsed information in a
1566 long fragmentLength;
1567 while ( (fragmentLength = ReadTagLength(0xfffe, 0xe000)) != 0 )
1569 long fragmentOffset = Fp->tellg();
1571 // Store the collected info
1572 JPEGFragment *newFragment = new JPEGFragment;
1573 newFragment->SetOffset(fragmentOffset);
1574 newFragment->SetLength(fragmentLength);
1575 JPEGInfo->AddFragment(newFragment);
1577 SkipBytes(fragmentLength);
1580 // Make sure that we encounter a 'Sequence Delimiter Item'
1581 // at the end of the item :
1582 if ( !ReadTag(0xfffe, 0xe0dd) )
1584 gdcmWarningMacro( "No sequence delimiter item at end of JPEG item sequence");
1589 * \brief Assuming the internal file pointer \ref Document::Fp
1590 * is placed at the beginning of a tag check whether this
1591 * tag is (TestGroup, TestElem).
1592 * \warning On success the internal file pointer \ref Document::Fp
1593 * is modified to point after the tag.
1594 * On failure (i.e. when the tag wasn't the expected tag
1595 * (TestGroup, TestElem) the internal file pointer
1596 * \ref Document::Fp is restored to it's original position.
1597 * @param testGroup The expected group of the tag.
1598 * @param testElem The expected Element of the tag.
1599 * @return True on success, false otherwise.
1601 bool File::ReadTag(uint16_t testGroup, uint16_t testElem)
1603 long positionOnEntry = Fp->tellg();
1604 long currentPosition = Fp->tellg(); // On debugging purposes
1606 // Read the Item Tag group and element, and make
1607 // sure they are what we expected:
1608 uint16_t itemTagGroup;
1609 uint16_t itemTagElem;
1612 itemTagGroup = ReadInt16();
1613 itemTagElem = ReadInt16();
1615 catch ( FormatError e )
1617 //std::cerr << e << std::endl;
1620 if ( itemTagGroup != testGroup || itemTagElem != testElem )
1622 gdcmWarningMacro( "Wrong Item Tag found:"
1623 << " We should have found tag ("
1624 << std::hex << testGroup << "," << testElem << ")" << std::endl
1625 << " but instead we encountered tag ("
1626 << std::hex << itemTagGroup << "," << itemTagElem << ")"
1627 << " at address: " << " 0x(" << (unsigned int)currentPosition << ")"
1629 Fp->seekg(positionOnEntry, std::ios::beg);
1637 * \brief Assuming the internal file pointer \ref Document::Fp
1638 * is placed at the beginning of a tag (TestGroup, TestElement),
1639 * read the length associated to the Tag.
1640 * \warning On success the internal file pointer \ref Document::Fp
1641 * is modified to point after the tag and it's length.
1642 * On failure (i.e. when the tag wasn't the expected tag
1643 * (TestGroup, TestElement) the internal file pointer
1644 * \ref Document::Fp is restored to it's original position.
1645 * @param testGroup The expected Group of the tag.
1646 * @param testElem The expected Element of the tag.
1647 * @return On success returns the length associated to the tag. On failure
1650 uint32_t File::ReadTagLength(uint16_t testGroup, uint16_t testElem)
1653 if ( !ReadTag(testGroup, testElem) )
1658 //// Then read the associated Item Length
1659 long currentPosition = Fp->tellg();
1660 uint32_t itemLength = ReadInt32();
1662 gdcmWarningMacro( "Basic Item Length is: "
1663 << itemLength << std::endl
1664 << " at address: " << std::hex << (unsigned int)currentPosition);
1670 * \brief When parsing the Pixel Data of an encapsulated file, read
1671 * the basic offset table (when present, and BTW dump it).
1673 void File::ReadAndSkipEncapsulatedBasicOffsetTable()
1675 //// Read the Basic Offset Table Item Tag length...
1676 uint32_t itemLength = ReadTagLength(0xfffe, 0xe000);
1678 // When present, read the basic offset table itself.
1679 // Notes: - since the presence of this basic offset table is optional
1680 // we can't rely on it for the implementation, and we will simply
1681 // trash it's content (when present).
1682 // - still, when present, we could add some further checks on the
1683 // lengths, but we won't bother with such fuses for the time being.
1684 if ( itemLength != 0 )
1686 char *basicOffsetTableItemValue = new char[itemLength + 1];
1687 Fp->read(basicOffsetTableItemValue, itemLength);
1690 for (unsigned int i=0; i < itemLength; i += 4 )
1692 uint32_t individualLength = str2num( &basicOffsetTableItemValue[i],
1694 gdcmWarningMacro( "Read one length: " <<
1695 std::hex << individualLength );
1699 delete[] basicOffsetTableItemValue;
1703 //-----------------------------------------------------------------------------
1706 //-----------------------------------------------------------------------------
1707 } // end namespace gdcm