1 /*=========================================================================
4 Module: $RCSfile: gdcmFile.cxx,v $
6 Date: $Date: 2005/06/24 10:50:20 $
7 Version: $Revision: 1.244 $
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 if ( !GetDocEntry(0x0028, 0x0100) )
211 gdcmWarningMacro("Bits Allocated (0028|0100) not found");
212 return false; // "Bits Allocated"
214 if ( !GetDocEntry(0x0028, 0x0101) )
216 gdcmWarningMacro("Bits Stored (0028|0101) not found");
217 return false; // "Bits Stored"
219 if ( !GetDocEntry(0x0028, 0x0102) )
221 gdcmWarningMacro("Hight Bit (0028|0102) not found");
222 return false; // "High Bit"
224 if ( !GetDocEntry(0x0028, 0x0103) )
226 gdcmWarningMacro("Pixel Representation (0028|0103) not found");
227 return false; // "Pixel Representation" i.e. 'Sign' ( 0 : unsigned, 1 : signed)
229 if ( !GetDocEntry(GrPixel, NumPixel) )
231 gdcmWarningMacro("Pixel Dicom Element " << std::hex <<
232 GrPixel << "|" << NumPixel << "not found");
233 return false; // Pixel Dicom Element not found :-(
239 * \brief gets the info from 0020,0013 : Image Number else 0.
240 * @return image number
242 int File::GetImageNumber()
244 //0020 0013 : Image Number
245 std::string strImNumber = GetEntryValue(0x0020,0x0013);
246 if ( strImNumber != GDCM_UNFOUND )
248 return atoi( strImNumber.c_str() );
254 * \brief gets the info from 0008,0060 : Modality
255 * @return Modality Type
257 ModalityType File::GetModality()
259 // 0008 0060 : Modality
260 std::string strModality = GetEntryValue(0x0008,0x0060);
261 if ( strModality != GDCM_UNFOUND )
263 if ( strModality.find("AU") < strModality.length()) return AU;
264 else if ( strModality.find("AS") < strModality.length()) return AS;
265 else if ( strModality.find("BI") < strModality.length()) return BI;
266 else if ( strModality.find("CF") < strModality.length()) return CF;
267 else if ( strModality.find("CP") < strModality.length()) return CP;
268 else if ( strModality.find("CR") < strModality.length()) return CR;
269 else if ( strModality.find("CT") < strModality.length()) return CT;
270 else if ( strModality.find("CS") < strModality.length()) return CS;
271 else if ( strModality.find("DD") < strModality.length()) return DD;
272 else if ( strModality.find("DF") < strModality.length()) return DF;
273 else if ( strModality.find("DG") < strModality.length()) return DG;
274 else if ( strModality.find("DM") < strModality.length()) return DM;
275 else if ( strModality.find("DS") < strModality.length()) return DS;
276 else if ( strModality.find("DX") < strModality.length()) return DX;
277 else if ( strModality.find("ECG") < strModality.length()) return ECG;
278 else if ( strModality.find("EPS") < strModality.length()) return EPS;
279 else if ( strModality.find("FA") < strModality.length()) return FA;
280 else if ( strModality.find("FS") < strModality.length()) return FS;
281 else if ( strModality.find("HC") < strModality.length()) return HC;
282 else if ( strModality.find("HD") < strModality.length()) return HD;
283 else if ( strModality.find("LP") < strModality.length()) return LP;
284 else if ( strModality.find("LS") < strModality.length()) return LS;
285 else if ( strModality.find("MA") < strModality.length()) return MA;
286 else if ( strModality.find("MR") < strModality.length()) return MR;
287 else if ( strModality.find("NM") < strModality.length()) return NM;
288 else if ( strModality.find("OT") < strModality.length()) return OT;
289 else if ( strModality.find("PT") < strModality.length()) return PT;
290 else if ( strModality.find("RF") < strModality.length()) return RF;
291 else if ( strModality.find("RG") < strModality.length()) return RG;
292 else if ( strModality.find("RTDOSE")
293 < strModality.length()) return RTDOSE;
294 else if ( strModality.find("RTIMAGE")
295 < strModality.length()) return RTIMAGE;
296 else if ( strModality.find("RTPLAN")
297 < strModality.length()) return RTPLAN;
298 else if ( strModality.find("RTSTRUCT")
299 < strModality.length()) return RTSTRUCT;
300 else if ( strModality.find("SM") < strModality.length()) return SM;
301 else if ( strModality.find("ST") < strModality.length()) return ST;
302 else if ( strModality.find("TG") < strModality.length()) return TG;
303 else if ( strModality.find("US") < strModality.length()) return US;
304 else if ( strModality.find("VF") < strModality.length()) return VF;
305 else if ( strModality.find("XA") < strModality.length()) return XA;
306 else if ( strModality.find("XC") < strModality.length()) return XC;
310 /// \todo throw error return value ???
311 /// specified <> unknown in our database
319 * \brief Retrieve the number of columns of image.
320 * @return The encountered size when found, 0 by default.
321 * 0 means the file is NOT USABLE. The caller will have to check
325 const std::string &strSize = GetEntryValue(0x0028,0x0011);
326 if ( strSize == GDCM_UNFOUND )
330 return atoi( strSize.c_str() );
334 * \brief Retrieve the number of lines of image.
335 * \warning The defaulted value is 1 as opposed to File::GetXSize()
336 * @return The encountered size when found, 1 by default
337 * (The ACR-NEMA file contains a Signal, not an Image).
341 const std::string &strSize = GetEntryValue(0x0028,0x0010);
342 if ( strSize != GDCM_UNFOUND )
344 return atoi( strSize.c_str() );
351 // The Rows (0028,0010) entry was optional for ACR/NEMA.
352 // (at least some images didn't have it.)
353 // It might hence be a signal (1D image). So we default to 1:
358 * \brief Retrieve the number of planes of volume or the number
359 * of frames of a multiframe.
360 * \warning When present we consider the "Number of Frames" as the third
361 * dimension. When missing we consider the third dimension as
362 * being the ACR-NEMA "Planes" tag content.
363 * @return The encountered size when found, 1 by default (single image).
367 // Both DicomV3 and ACR/Nema consider the "Number of Frames"
368 // as the third dimension.
369 const std::string &strSize = GetEntryValue(0x0028,0x0008);
370 if ( strSize != GDCM_UNFOUND )
372 return atoi( strSize.c_str() );
375 // We then consider the "Planes" entry as the third dimension
376 const std::string &strSize2 = GetEntryValue(0x0028,0x0012);
377 if ( strSize2 != GDCM_UNFOUND )
379 return atoi( strSize2.c_str() );
385 * \brief gets the info from 0018,1164 : ImagerPixelSpacing
386 * then 0028,0030 : Pixel Spacing
388 * @return X dimension of a pixel
390 float File::GetXSpacing()
392 float xspacing = 1.0;
393 float yspacing = 1.0;
396 // To follow David Clunie's advice, we first check ImagerPixelSpacing
398 const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
399 if ( strImagerPixelSpacing != GDCM_UNFOUND )
401 if ( ( nbValues = sscanf( strImagerPixelSpacing.c_str(),
402 "%f\\%f", &yspacing, &xspacing)) != 2 )
404 // if no values, xspacing is set to 1.0
407 // if single value is found, xspacing is defaulted to yspacing
411 if ( xspacing == 0.0 )
418 const std::string &strSpacing = GetEntryValue(0x0028,0x0030);
420 if ( strSpacing == GDCM_UNFOUND )
422 gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" );
426 if ( ( nbValues = sscanf( strSpacing.c_str(),
427 "%f \\%f ", &yspacing, &xspacing)) != 2 )
429 // if no values, xspacing is set to 1.0
432 // if single value is found, xspacing is defaulted to yspacing
436 if ( xspacing == 0.0 )
442 // to avoid troubles with David Clunie's-like images (at least one)
443 if ( xspacing == 0. && yspacing == 0.)
448 gdcmWarningMacro("gdcmData/CT-MONO2-8-abdo.dcm-like problem");
449 // seems to be a bug in the header ...
450 nbValues = sscanf( strSpacing.c_str(), "%f \\0\\%f ", &yspacing, &xspacing);
451 gdcmAssertMacro( nbValues == 2 );
458 * \brief gets the info from 0018,1164 : ImagerPixelSpacing
459 * then from 0028,0030 : Pixel Spacing
461 * @return Y dimension of a pixel
463 float File::GetYSpacing()
467 // To follow David Clunie's advice, we first check ImagerPixelSpacing
469 const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
470 if ( strImagerPixelSpacing != GDCM_UNFOUND )
472 nbValues = sscanf( strImagerPixelSpacing.c_str(), "%f", &yspacing);
474 // if sscanf cannot read any float value, it won't affect yspacing
478 if ( yspacing == 0.0 )
484 std::string strSpacing = GetEntryValue(0x0028,0x0030);
485 if ( strSpacing == GDCM_UNFOUND )
487 gdcmWarningMacro("Unfound Pixel Spacing (0028,0030)");
491 // if sscanf cannot read any float value, it won't affect yspacing
492 nbValues = sscanf( strSpacing.c_str(), "%f", &yspacing);
494 // if no values, yspacing is set to 1.0
498 if ( yspacing == 0.0 )
505 * \brief gets the info from 0018,0088 : Space Between Slices
506 * else from 0018,0050 : Slice Thickness
508 * @return Z dimension of a voxel-to be
510 float File::GetZSpacing()
512 // Spacing Between Slices : distance between the middle of 2 slices
514 // jointives (Spacing between Slices = Slice Thickness)
515 // overlapping (Spacing between Slices < Slice Thickness)
516 // disjointes (Spacing between Slices > Slice Thickness)
517 // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
518 // It only concerns the MRI guys, not people wanting to visualize volumes
519 // If Spacing Between Slices is missing,
520 // we suppose slices joint together
522 const std::string &strSpacingBSlices = GetEntryValue(0x0018,0x0088);
524 if ( strSpacingBSlices == GDCM_UNFOUND )
526 gdcmWarningMacro("Unfound Spacing Between Slices (0018,0088)");
527 const std::string &strSliceThickness = GetEntryValue(0x0018,0x0050);
528 if ( strSliceThickness == GDCM_UNFOUND )
530 gdcmWarningMacro("Unfound Slice Thickness (0018,0050)");
535 // if no 'Spacing Between Slices' is found,
536 // we assume slices join together
537 // (no overlapping, no interslice gap)
538 // if they don't, we're fucked up
539 return (float)atof( strSliceThickness.c_str() );
543 return (float)atof( strSpacingBSlices.c_str() );
547 * \brief gets the info from 0020,0032 : Image Position Patient
548 * else from 0020,0030 : Image Position (RET)
550 * @return up-left image corner X position
552 float File::GetXOrigin()
554 float xImPos, yImPos, zImPos;
555 std::string strImPos = GetEntryValue(0x0020,0x0032);
557 if ( strImPos == GDCM_UNFOUND )
559 gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
560 strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
561 if ( strImPos == GDCM_UNFOUND )
563 gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
568 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3 )
577 * \brief gets the info from 0020,0032 : Image Position Patient
578 * else from 0020,0030 : Image Position (RET)
580 * @return up-left image corner Y position
582 float File::GetYOrigin()
584 float xImPos, yImPos, zImPos;
585 std::string strImPos = GetEntryValue(0x0020,0x0032);
587 if ( strImPos == GDCM_UNFOUND)
589 gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
590 strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
591 if ( strImPos == GDCM_UNFOUND )
593 gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
598 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3 )
607 * \brief gets the info from 0020,0032 : Image Position Patient
608 * else from 0020,0030 : Image Position (RET)
609 * else from 0020,1041 : Slice Location
610 * else from 0020,0050 : Location
612 * @return up-left image corner Z position
614 float File::GetZOrigin()
616 float xImPos, yImPos, zImPos;
617 std::string strImPos = GetEntryValue(0x0020,0x0032);
619 if ( strImPos != GDCM_UNFOUND )
621 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3)
623 gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)");
624 return 0.; // bug in the element 0x0020,0x0032
632 strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
633 if ( strImPos != GDCM_UNFOUND )
635 if ( sscanf( strImPos.c_str(),
636 "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos ) != 3 )
638 gdcmWarningMacro( "Wrong Image Position (RET) (0020,0030)");
639 return 0.; // bug in the element 0x0020,0x0032
647 // for *very* old ACR-NEMA images
648 std::string strSliceLocation = GetEntryValue(0x0020,0x1041);
649 if ( strSliceLocation != GDCM_UNFOUND )
651 if ( sscanf( strSliceLocation.c_str(), "%f ", &zImPos) != 1)
653 gdcmWarningMacro( "Wrong Slice Location (0020,1041)");
654 return 0.; // bug in the element 0x0020,0x1041
661 gdcmWarningMacro( "Unfound Slice Location (0020,1041)");
663 std::string strLocation = GetEntryValue(0x0020,0x0050);
664 if ( strLocation != GDCM_UNFOUND )
666 if ( sscanf( strLocation.c_str(), "%f ", &zImPos) != 1 )
668 gdcmWarningMacro( "Wrong Location (0020,0050)");
669 return 0.; // bug in the element 0x0020,0x0050
676 gdcmWarningMacro( "Unfound Location (0020,0050)");
678 return 0.; // Hopeless
682 * \brief gets the info from 0020,0037 : Image Orientation Patient
683 * (needed to organize DICOM files based on their x,y,z position)
684 * @param iop adress of the (6)float array to receive values
685 * @return cosines of image orientation patient
687 void File::GetImageOrientationPatient( float iop[6] )
689 std::string strImOriPat;
690 //iop is supposed to be float[6]
691 iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.;
693 // 0020 0037 DS REL Image Orientation (Patient)
694 if ( (strImOriPat = GetEntryValue(0x0020,0x0037)) != GDCM_UNFOUND )
696 if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ",
697 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
699 gdcmWarningMacro( "Wrong Image Orientation Patient (0020,0037). Less than 6 values were found." );
703 // 0020 0035 DS REL Image Orientation (RET)
704 else if ( (strImOriPat = GetEntryValue(0x0020,0x0035)) != GDCM_UNFOUND )
706 if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ",
707 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
709 gdcmWarningMacro( "wrong Image Orientation Patient (0020,0035). Less than 6 values were found." );
715 * \brief Retrieve the number of Bits Stored (actually used)
716 * (as opposed to number of Bits Allocated)
717 * @return The encountered number of Bits Stored, 0 by default.
718 * 0 means the file is NOT USABLE. The caller has to check it !
720 int File::GetBitsStored()
722 std::string strSize = GetEntryValue( 0x0028, 0x0101 );
723 if ( strSize == GDCM_UNFOUND )
725 gdcmWarningMacro("(0028,0101) is supposed to be mandatory");
726 return 0; // It's supposed to be mandatory
727 // the caller will have to check
729 return atoi( strSize.c_str() );
733 * \brief Retrieve the number of Bits Allocated
734 * (8, 12 -compacted ACR-NEMA files-, 16, ...)
735 * @return The encountered number of Bits Allocated, 0 by default.
736 * 0 means the file is NOT USABLE. The caller has to check it !
738 int File::GetBitsAllocated()
740 std::string strSize = GetEntryValue(0x0028,0x0100);
741 if ( strSize == GDCM_UNFOUND )
743 gdcmWarningMacro( "(0028,0100) is supposed to be mandatory");
744 return 0; // It's supposed to be mandatory
745 // the caller will have to check
747 return atoi( strSize.c_str() );
751 * \brief Retrieve the high bit position.
752 * \warning The method defaults to 0 when information is missing.
753 * The responsability of checking this value is left to the caller.
754 * @return The high bit position when present. 0 when missing.
756 int File::GetHighBitPosition()
758 std::string strSize = GetEntryValue( 0x0028, 0x0102 );
759 if ( strSize == GDCM_UNFOUND )
761 gdcmWarningMacro( "(0028,0102) is supposed to be mandatory");
764 return atoi( strSize.c_str() );
768 * \brief Retrieve the number of Samples Per Pixel
769 * (1 : gray level, 3 : RGB/YBR -1 or 3 Planes-)
770 * @return The encountered number of Samples Per Pixel, 1 by default.
771 * (we assume Gray level Pixels)
773 int File::GetSamplesPerPixel()
775 const std::string &strSize = GetEntryValue(0x0028,0x0002);
776 if ( strSize == GDCM_UNFOUND )
778 gdcmWarningMacro( "(0028,0002) is supposed to be mandatory");
779 return 1; // Well, it's supposed to be mandatory ...
780 // but sometimes it's missing : *we* assume Gray pixels
782 return atoi( strSize.c_str() );
786 * \brief Retrieve the Planar Configuration for RGB images
787 * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
788 * @return The encountered Planar Configuration, 0 by default.
790 int File::GetPlanarConfiguration()
792 std::string strSize = GetEntryValue(0x0028,0x0006);
793 if ( strSize == GDCM_UNFOUND )
795 gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)");
798 return atoi( strSize.c_str() );
802 * \brief Return the size (in bytes) of a single pixel of data.
803 * @return The size in bytes of a single pixel of data; 0 by default
804 * 0 means the file is NOT USABLE; the caller will have to check
806 int File::GetPixelSize()
808 // 0028 0100 US IMG Bits Allocated
809 // (in order no to be messed up by old ACR-NEMA RGB images)
810 // if (File::GetEntryValue(0x0028,0x0100) == "24")
813 std::string pixelType = GetPixelType();
814 if ( pixelType == "8U" || pixelType == "8S" )
818 if ( pixelType == "16U" || pixelType == "16S")
822 if ( pixelType == "32U" || pixelType == "32S")
826 if ( pixelType == "FD" )
830 gdcmWarningMacro( "Unknown pixel type");
835 * \brief Build the Pixel Type of the image.
836 * Possible values are:
837 * - 8U unsigned 8 bit,
839 * - 16U unsigned 16 bit,
840 * - 16S signed 16 bit,
841 * - 32U unsigned 32 bit,
842 * - 32S signed 32 bit,
843 * - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
844 * \warning 12 bit images appear as 16 bit.
845 * 24 bit images appear as 8 bit + photochromatic interp ="RGB "
846 * + Planar Configuration = 0
847 * @return 0S if nothing found. NOT USABLE file. The caller has to check
849 std::string File::GetPixelType()
851 std::string bitsAlloc = GetEntryValue(0x0028, 0x0100); // Bits Allocated
852 if ( bitsAlloc == GDCM_UNFOUND )
854 gdcmWarningMacro( "Missing Bits Allocated (0028,0100)");
855 bitsAlloc = "16"; // default and arbitrary value, not to polute the output
858 if ( bitsAlloc == "64" )
862 else if ( bitsAlloc == "12" )
864 // It will be unpacked
867 else if ( bitsAlloc == "24" )
869 // (in order no to be messed up
870 bitsAlloc = "8"; // by old RGB images)
873 std::string sign = GetEntryValue(0x0028, 0x0103);//"Pixel Representation"
875 if (sign == GDCM_UNFOUND )
877 gdcmWarningMacro( "Missing Pixel Representation (0028,0103)");
878 sign = "U"; // default and arbitrary value, not to polute the output
880 else if ( sign == "0" )
888 return bitsAlloc + sign;
892 * \brief Check whether the pixels are signed (1) or UNsigned (0) data.
893 * \warning The method defaults to false (UNsigned) when tag 0028|0103
895 * The responsability of checking this value is left to the caller
896 * (NO transformation is performed on the pixels to make then >0)
897 * @return True when signed, false when UNsigned
899 bool File::IsSignedPixelData()
901 std::string strSign = GetEntryValue( 0x0028, 0x0103 );
902 if ( strSign == GDCM_UNFOUND )
904 gdcmWarningMacro( "(0028,0103) is supposed to be mandatory");
907 int sign = atoi( strSign.c_str() );
916 * \brief Check whether this a monochrome picture (gray levels) or not,
917 * using "Photometric Interpretation" tag (0x0028,0x0004).
918 * @return true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
920 bool File::IsMonochrome()
922 const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
923 if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1")
924 || Util::DicomStringEqual(PhotometricInterp, "MONOCHROME2") )
928 if ( PhotometricInterp == GDCM_UNFOUND )
930 gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
936 * \brief Check whether this a MONOCHROME1 picture (high values = dark)
937 * or not using "Photometric Interpretation" tag (0x0028,0x0004).
938 * @return true when "MONOCHROME1" . False otherwise.
940 bool File::IsMonochrome1()
942 const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
943 if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
947 if ( PhotometricInterp == GDCM_UNFOUND )
949 gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
955 * \brief Check whether this a "PALETTE COLOR" picture or not by accessing
956 * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
957 * @return true when "PALETTE COLOR". False otherwise.
959 bool File::IsPaletteColor()
961 std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
962 if ( PhotometricInterp == "PALETTE COLOR " )
966 if ( PhotometricInterp == GDCM_UNFOUND )
968 gdcmWarningMacro( "Not found : Palette color (0028,0004)");
974 * \brief Check whether this a "YBR_FULL" color picture or not by accessing
975 * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
976 * @return true when "YBR_FULL". False otherwise.
978 bool File::IsYBRFull()
980 std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
981 if ( PhotometricInterp == "YBR_FULL" )
985 if ( PhotometricInterp == GDCM_UNFOUND )
987 gdcmWarningMacro( "Not found : YBR Full (0028,0004)");
993 * \brief tells us if LUT are used
994 * \warning Right now, 'Segmented xxx Palette Color Lookup Table Data'
995 * are NOT considered as LUT, since nobody knows
996 * how to deal with them
997 * Please warn me if you know sbdy that *does* know ... jprx
998 * @return true if LUT Descriptors and LUT Tables were found
1002 // Check the presence of the LUT Descriptors, and LUT Tables
1004 if ( !GetDocEntry(0x0028,0x1101) )
1008 // LutDescriptorGreen
1009 if ( !GetDocEntry(0x0028,0x1102) )
1013 // LutDescriptorBlue
1014 if ( !GetDocEntry(0x0028,0x1103) )
1018 // Red Palette Color Lookup Table Data
1019 if ( !GetDocEntry(0x0028,0x1201) )
1023 // Green Palette Color Lookup Table Data
1024 if ( !GetDocEntry(0x0028,0x1202) )
1028 // Blue Palette Color Lookup Table Data
1029 if ( !GetDocEntry(0x0028,0x1203) )
1034 // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
1035 // NOT taken into account, but we don't know how to use it ...
1040 * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
1042 * @return Lookup Table number of Bits , 0 by default
1043 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
1044 * @ return bit number of each LUT item
1046 int File::GetLUTNbits()
1048 std::vector<std::string> tokens;
1051 //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red
1052 // = Lookup Table Desc-Blue
1053 // Consistency already checked in GetLUTLength
1054 std::string lutDescription = GetEntryValue(0x0028,0x1101);
1055 if ( lutDescription == GDCM_UNFOUND )
1060 tokens.clear(); // clean any previous value
1061 Util::Tokenize ( lutDescription, tokens, "\\" );
1062 //LutLength=atoi(tokens[0].c_str());
1063 //LutDepth=atoi(tokens[1].c_str());
1065 lutNbits = atoi( tokens[2].c_str() );
1072 *\brief gets the info from 0028,1052 : Rescale Intercept
1073 * @return Rescale Intercept
1075 float File::GetRescaleIntercept()
1077 float resInter = 0.;
1078 /// 0028 1052 DS IMG Rescale Intercept
1079 const std::string &strRescInter = GetEntryValue(0x0028,0x1052);
1080 if ( strRescInter != GDCM_UNFOUND )
1082 if ( sscanf( strRescInter.c_str(), "%f ", &resInter) != 1 )
1084 // bug in the element 0x0028,0x1052
1085 gdcmWarningMacro( "Rescale Intercept (0028,1052) is empty." );
1093 *\brief gets the info from 0028,1053 : Rescale Slope
1094 * @return Rescale Slope
1096 float File::GetRescaleSlope()
1098 float resSlope = 1.;
1099 //0028 1053 DS IMG Rescale Slope
1100 std::string strRescSlope = GetEntryValue(0x0028,0x1053);
1101 if ( strRescSlope != GDCM_UNFOUND )
1103 if ( sscanf( strRescSlope.c_str(), "%f ", &resSlope) != 1 )
1105 // bug in the element 0x0028,0x1053
1106 gdcmWarningMacro( "Rescale Slope (0028,1053) is empty.");
1114 * \brief This function is intended to user who doesn't want
1115 * to have to manage a LUT and expects to get an RBG Pixel image
1116 * (or a monochrome one ...)
1117 * \warning to be used with GetImagePixels()
1118 * @return 1 if Gray level, 3 if Color (RGB, YBR, *or PALETTE COLOR*)
1120 int File::GetNumberOfScalarComponents()
1122 if ( GetSamplesPerPixel() == 3 )
1127 // 0028 0100 US IMG Bits Allocated
1128 // (in order no to be messed up by old RGB images)
1129 if ( GetEntryValue(0x0028,0x0100) == "24" )
1134 std::string strPhotometricInterpretation = GetEntryValue(0x0028,0x0004);
1136 if ( ( strPhotometricInterpretation == "PALETTE COLOR ") )
1138 if ( HasLUT() )// PALETTE COLOR is NOT enough
1148 // beware of trailing space at end of string
1149 // DICOM tags are never of odd length
1150 if ( strPhotometricInterpretation == GDCM_UNFOUND ||
1151 Util::DicomStringEqual(strPhotometricInterpretation, "MONOCHROME1") ||
1152 Util::DicomStringEqual(strPhotometricInterpretation, "MONOCHROME2") )
1158 // we assume that *all* kinds of YBR are dealt with
1164 * \brief This function is intended to user that DOESN'T want
1165 * to get RGB pixels image when it's stored as a PALETTE COLOR image
1166 * - the (vtk) user is supposed to know how deal with LUTs -
1167 * \warning to be used with GetImagePixelsRaw()
1168 * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
1170 int File::GetNumberOfScalarComponentsRaw()
1172 // 0028 0100 US IMG Bits Allocated
1173 // (in order no to be messed up by old RGB images)
1174 if ( File::GetEntryValue(0x0028,0x0100) == "24" )
1179 // we assume that *all* kinds of YBR are dealt with
1180 return GetSamplesPerPixel();
1184 * \brief Recover the offset (from the beginning of the file)
1185 * of *image* pixels (not *icone image* pixels, if any !)
1186 * @return Pixel Offset
1188 size_t File::GetPixelOffset()
1190 DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel);
1193 return pxlElement->GetOffset();
1197 gdcmDebugMacro( "Big trouble : Pixel Element ("
1198 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" );
1204 * \brief Recover the pixel area length (in Bytes)
1205 * @return Pixel Element Length, as stored in the header
1206 * (NOT the memory space necessary to hold the Pixels
1207 * -in case of embeded compressed image-)
1208 * 0 : NOT USABLE file. The caller has to check.
1210 size_t File::GetPixelAreaLength()
1212 DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel);
1215 return pxlElement->GetLength();
1219 gdcmDebugMacro( "Big trouble : Pixel Element ("
1220 << std::hex << GrPixel<<","<< NumPixel<< ") NOT found" );
1226 * \brief Adds the characteristics of a new element we want to anonymize
1227 * @param group Group number of the target tag.
1228 * @param elem Element number of the target tag.
1229 * @param value new value (string) to substitute with
1231 void File::AddAnonymizeElement (uint16_t group, uint16_t elem,
1232 std::string const &value)
1238 AnonymizeList.push_back(el);
1242 * \brief Overwrites in the file the values of the DicomElements
1245 void File::AnonymizeNoLoad()
1247 std::fstream *fp = new std::fstream(Filename.c_str(),
1248 std::ios::in | std::ios::out | std::ios::binary);
1252 uint32_t valLgth = 0;
1253 std::string *spaces;
1254 for (ListElements::iterator it = AnonymizeList.begin();
1255 it != AnonymizeList.end();
1258 d = GetDocEntry( (*it).Group, (*it).Elem);
1263 if ( dynamic_cast<BinEntry *>(d)
1264 || dynamic_cast<SeqEntry *>(d) )
1267 offset = d->GetOffset();
1268 lgth = d->GetLength();
1271 spaces = new std::string( lgth-valLgth, ' ');
1272 (*it).Value = (*it).Value + *spaces;
1275 fp->seekp( offset, std::ios::beg );
1276 fp->write( (*it).Value.c_str(), lgth );
1284 * \brief anonymize a File (remove Patient's personal info passed with
1285 * AddAnonymizeElement()
1287 bool File::AnonymizeFile()
1289 // If Anonymisation list is empty, let's perform some basic anonymization
1290 if ( AnonymizeList.begin() == AnonymizeList.end() )
1292 // If exist, replace by spaces
1293 SetValEntry (" ",0x0010, 0x2154); // Telephone
1294 SetValEntry (" ",0x0010, 0x1040); // Adress
1295 SetValEntry (" ",0x0010, 0x0020); // Patient ID
1297 DocEntry* patientNameHE = GetDocEntry (0x0010, 0x0010);
1299 if ( patientNameHE ) // we replace it by Study Instance UID (why not ?)
1301 std::string studyInstanceUID = GetEntryValue (0x0020, 0x000d);
1302 if ( studyInstanceUID != GDCM_UNFOUND )
1304 SetValEntry(studyInstanceUID, 0x0010, 0x0010);
1308 SetValEntry("anonymised", 0x0010, 0x0010);
1315 for (ListElements::iterator it = AnonymizeList.begin();
1316 it != AnonymizeList.end();
1319 d = GetDocEntry( (*it).Group, (*it).Elem);
1324 if ( dynamic_cast<BinEntry *>(d)
1325 || dynamic_cast<SeqEntry *>(d) )
1328 SetValEntry ((*it).Value, (*it).Group, (*it).Elem);
1332 // In order to make definitively impossible any further identification
1333 // remove or replace all the stuff that contains a Date
1335 //0008 0012 DA ID Instance Creation Date
1336 //0008 0020 DA ID Study Date
1337 //0008 0021 DA ID Series Date
1338 //0008 0022 DA ID Acquisition Date
1339 //0008 0023 DA ID Content Date
1340 //0008 0024 DA ID Overlay Date
1341 //0008 0025 DA ID Curve Date
1342 //0008 002a DT ID Acquisition Datetime
1343 //0018 9074 DT ACQ Frame Acquisition Datetime
1344 //0018 9151 DT ACQ Frame Reference Datetime
1345 //0018 a002 DT ACQ Contribution Date Time
1346 //0020 3403 SH REL Modified Image Date (RET)
1347 //0032 0032 DA SDY Study Verified Date
1348 //0032 0034 DA SDY Study Read Date
1349 //0032 1000 DA SDY Scheduled Study Start Date
1350 //0032 1010 DA SDY Scheduled Study Stop Date
1351 //0032 1040 DA SDY Study Arrival Date
1352 //0032 1050 DA SDY Study Completion Date
1353 //0038 001a DA VIS Scheduled Admission Date
1354 //0038 001c DA VIS Scheduled Discharge Date
1355 //0038 0020 DA VIS Admitting Date
1356 //0038 0030 DA VIS Discharge Date
1357 //0040 0002 DA PRC Scheduled Procedure Step Start Date
1358 //0040 0004 DA PRC Scheduled Procedure Step End Date
1359 //0040 0244 DA PRC Performed Procedure Step Start Date
1360 //0040 0250 DA PRC Performed Procedure Step End Date
1361 //0040 2004 DA PRC Issue Date of Imaging Service Request
1362 //0040 4005 DT PRC Scheduled Procedure Step Start Date and Time
1363 //0040 4011 DT PRC Expected Completion Date and Time
1364 //0040 a030 DT PRC Verification Date Time
1365 //0040 a032 DT PRC Observation Date Time
1366 //0040 a120 DT PRC DateTime
1367 //0040 a121 DA PRC Date
1368 //0040 a13a DT PRC Referenced Datetime
1369 //0070 0082 DA ??? Presentation Creation Date
1370 //0100 0420 DT ??? SOP Autorization Date and Time
1371 //0400 0105 DT ??? Digital Signature DateTime
1372 //2100 0040 DA PJ Creation Date
1373 //3006 0008 DA SSET Structure Set Date
1374 //3008 0024 DA ??? Treatment Control Point Date
1375 //3008 0054 DA ??? First Treatment Date
1376 //3008 0056 DA ??? Most Recent Treatment Date
1377 //3008 0162 DA ??? Safe Position Exit Date
1378 //3008 0166 DA ??? Safe Position Return Date
1379 //3008 0250 DA ??? Treatment Date
1380 //300a 0006 DA RT RT Plan Date
1381 //300a 022c DA RT Air Kerma Rate Reference Date
1382 //300e 0004 DA RT Review Date
1388 * \brief Performs some consistency checking on various 'File related'
1389 * (as opposed to 'DicomDir related') entries
1390 * then writes in a file all the (Dicom Elements) included the Pixels
1391 * @param fileName file name to write to
1392 * @param writetype type of the file to be written
1393 * (ACR, ExplicitVR, ImplicitVR)
1395 bool File::Write(std::string fileName, FileType writetype)
1397 std::ofstream *fp = new std::ofstream(fileName.c_str(),
1398 std::ios::out | std::ios::binary);
1401 gdcmWarningMacro("Failed to open (write) File: " << fileName.c_str());
1405 // Entry : 0002|0000 = group length -> recalculated
1406 ValEntry*e0000 = GetValEntry(0x0002,0x0000);
1409 std::ostringstream sLen;
1410 sLen << ComputeGroup0002Length(writetype);
1411 e0000->SetValue(sLen.str());
1414 int i_lgPix = GetEntryLength(GrPixel, NumPixel);
1417 // no (GrPixel, NumPixel) element
1418 std::string s_lgPix = Util::Format("%d", i_lgPix+12);
1419 s_lgPix = Util::DicomString( s_lgPix.c_str() );
1420 InsertValEntry(s_lgPix,GrPixel, 0x0000);
1423 Document::WriteContent(fp, writetype);
1431 //-----------------------------------------------------------------------------
1435 //-----------------------------------------------------------------------------
1438 * \brief Parse pixel data from disk of [multi-]fragment RLE encoding.
1439 * Compute the RLE extra information and store it in \ref RLEInfo
1440 * for later pixel retrieval usage.
1442 void File::ComputeRLEInfo()
1444 std::string ts = GetTransferSyntax();
1445 if ( !Global::GetTS()->IsRLELossless(ts) )
1450 // Encoded pixel data: for the time being we are only concerned with
1451 // Jpeg or RLE Pixel data encodings.
1452 // As stated in PS 3.5-2003, section 8.2 p44:
1453 // "If sent in Encapsulated Format (i.e. other than the Native Format) the
1454 // value representation OB is used".
1455 // Hence we expect an OB value representation. Concerning OB VR,
1456 // the section PS 3.5-2003, section A.4.c p 58-59, states:
1457 // "For the Value Representations OB and OW, the encoding shall meet the
1458 // following specifications depending on the Data element tag:"
1460 // - the first item in the sequence of items before the encoded pixel
1461 // data stream shall be basic offset table item. The basic offset table
1462 // item value, however, is not required to be present"
1463 ReadAndSkipEncapsulatedBasicOffsetTable();
1465 // Encapsulated RLE Compressed Images (see PS 3.5-2003, Annex G)
1466 // Loop on the individual frame[s] and store the information
1467 // on the RLE fragments in a RLEFramesInfo.
1468 // Note: - when only a single frame is present, this is a
1470 // - when more than one frame are present, then we are in
1471 // the case of a multi-frame image.
1473 while ( (frameLength = ReadTagLength(0xfffe, 0xe000)) != 0 )
1475 // Parse the RLE Header and store the corresponding RLE Segment
1476 // Offset Table information on fragments of this current Frame.
1477 // Note that the fragment pixels themselves are not loaded
1478 // (but just skipped).
1479 long frameOffset = Fp->tellg();
1481 uint32_t nbRleSegments = ReadInt32();
1482 if ( nbRleSegments > 16 )
1484 // There should be at most 15 segments (refer to RLEFrame class)
1485 gdcmWarningMacro( "Too many segments.");
1488 uint32_t rleSegmentOffsetTable[16];
1489 for( int k = 1; k <= 15; k++ )
1491 rleSegmentOffsetTable[k] = ReadInt32();
1494 // Deduce from both RLE Header and frameLength
1495 // the fragment length, and again store this info
1496 // in a RLEFramesInfo.
1497 long rleSegmentLength[15];
1498 // skipping (not reading) RLE Segments
1499 if ( nbRleSegments > 1)
1501 for(unsigned int k = 1; k <= nbRleSegments-1; k++)
1503 rleSegmentLength[k] = rleSegmentOffsetTable[k+1]
1504 - rleSegmentOffsetTable[k];
1505 SkipBytes(rleSegmentLength[k]);
1509 rleSegmentLength[nbRleSegments] = frameLength
1510 - rleSegmentOffsetTable[nbRleSegments];
1511 SkipBytes(rleSegmentLength[nbRleSegments]);
1513 // Store the collected info
1514 RLEFrame *newFrame = new RLEFrame;
1515 newFrame->SetNumberOfFragments(nbRleSegments);
1516 for( unsigned int uk = 1; uk <= nbRleSegments; uk++ )
1518 newFrame->SetOffset(uk,frameOffset + rleSegmentOffsetTable[uk]);
1519 newFrame->SetLength(uk,rleSegmentLength[uk]);
1521 RLEInfo->AddFrame(newFrame);
1524 // Make sure that we encounter a 'Sequence Delimiter Item'
1525 // at the end of the item :
1526 if ( !ReadTag(0xfffe, 0xe0dd) )
1528 gdcmWarningMacro( "No sequence delimiter item at end of RLE item sequence");
1533 * \brief Parse pixel data from disk of [multi-]fragment Jpeg encoding.
1534 * Compute the jpeg extra information (fragment[s] offset[s] and
1535 * length) and store it[them] in \ref JPEGInfo for later pixel
1538 void File::ComputeJPEGFragmentInfo()
1540 // If you need to, look for comments of ComputeRLEInfo().
1541 std::string ts = GetTransferSyntax();
1542 if ( ! Global::GetTS()->IsJPEG(ts) )
1547 ReadAndSkipEncapsulatedBasicOffsetTable();
1549 // Loop on the fragments[s] and store the parsed information in a
1551 long fragmentLength;
1552 while ( (fragmentLength = ReadTagLength(0xfffe, 0xe000)) != 0 )
1554 long fragmentOffset = Fp->tellg();
1556 // Store the collected info
1557 JPEGFragment *newFragment = new JPEGFragment;
1558 newFragment->SetOffset(fragmentOffset);
1559 newFragment->SetLength(fragmentLength);
1560 JPEGInfo->AddFragment(newFragment);
1562 SkipBytes(fragmentLength);
1565 // Make sure that we encounter a 'Sequence Delimiter Item'
1566 // at the end of the item :
1567 if ( !ReadTag(0xfffe, 0xe0dd) )
1569 gdcmWarningMacro( "No sequence delimiter item at end of JPEG item sequence");
1574 * \brief Assuming the internal file pointer \ref Document::Fp
1575 * is placed at the beginning of a tag check whether this
1576 * tag is (TestGroup, TestElem).
1577 * \warning On success the internal file pointer \ref Document::Fp
1578 * is modified to point after the tag.
1579 * On failure (i.e. when the tag wasn't the expected tag
1580 * (TestGroup, TestElem) the internal file pointer
1581 * \ref Document::Fp is restored to it's original position.
1582 * @param testGroup The expected group of the tag.
1583 * @param testElem The expected Element of the tag.
1584 * @return True on success, false otherwise.
1586 bool File::ReadTag(uint16_t testGroup, uint16_t testElem)
1588 long positionOnEntry = Fp->tellg();
1589 long currentPosition = Fp->tellg(); // On debugging purposes
1591 // Read the Item Tag group and element, and make
1592 // sure they are what we expected:
1593 uint16_t itemTagGroup;
1594 uint16_t itemTagElem;
1597 itemTagGroup = ReadInt16();
1598 itemTagElem = ReadInt16();
1600 catch ( FormatError e )
1602 //std::cerr << e << std::endl;
1605 if ( itemTagGroup != testGroup || itemTagElem != testElem )
1607 gdcmWarningMacro( "Wrong Item Tag found:"
1608 << " We should have found tag ("
1609 << std::hex << testGroup << "," << testElem << ")" << std::endl
1610 << " but instead we encountered tag ("
1611 << std::hex << itemTagGroup << "," << itemTagElem << ")"
1612 << " at address: " << " 0x(" << (unsigned int)currentPosition << ")"
1614 Fp->seekg(positionOnEntry, std::ios::beg);
1622 * \brief Assuming the internal file pointer \ref Document::Fp
1623 * is placed at the beginning of a tag (TestGroup, TestElement),
1624 * read the length associated to the Tag.
1625 * \warning On success the internal file pointer \ref Document::Fp
1626 * is modified to point after the tag and it's length.
1627 * On failure (i.e. when the tag wasn't the expected tag
1628 * (TestGroup, TestElement) the internal file pointer
1629 * \ref Document::Fp is restored to it's original position.
1630 * @param testGroup The expected Group of the tag.
1631 * @param testElem The expected Element of the tag.
1632 * @return On success returns the length associated to the tag. On failure
1635 uint32_t File::ReadTagLength(uint16_t testGroup, uint16_t testElem)
1638 if ( !ReadTag(testGroup, testElem) )
1643 //// Then read the associated Item Length
1644 long currentPosition = Fp->tellg();
1645 uint32_t itemLength = ReadInt32();
1647 gdcmWarningMacro( "Basic Item Length is: "
1648 << itemLength << std::endl
1649 << " at address: " << std::hex << (unsigned int)currentPosition);
1655 * \brief When parsing the Pixel Data of an encapsulated file, read
1656 * the basic offset table (when present, and BTW dump it).
1658 void File::ReadAndSkipEncapsulatedBasicOffsetTable()
1660 //// Read the Basic Offset Table Item Tag length...
1661 uint32_t itemLength = ReadTagLength(0xfffe, 0xe000);
1663 // When present, read the basic offset table itself.
1664 // Notes: - since the presence of this basic offset table is optional
1665 // we can't rely on it for the implementation, and we will simply
1666 // trash it's content (when present).
1667 // - still, when present, we could add some further checks on the
1668 // lengths, but we won't bother with such fuses for the time being.
1669 if ( itemLength != 0 )
1671 char *basicOffsetTableItemValue = new char[itemLength + 1];
1672 Fp->read(basicOffsetTableItemValue, itemLength);
1675 for (unsigned int i=0; i < itemLength; i += 4 )
1677 uint32_t individualLength = str2num( &basicOffsetTableItemValue[i],
1679 gdcmWarningMacro( "Read one length: " <<
1680 std::hex << individualLength );
1684 delete[] basicOffsetTableItemValue;
1688 //-----------------------------------------------------------------------------
1691 //-----------------------------------------------------------------------------
1692 } // end namespace gdcm