- }
- return UINT32_MAX;
-}
-
-/**
- * \brief Assuming the internal file pointer \ref gdcmDocument::Fp
- * is placed at the beginning of a tag check whether this
- * tag is (TestGroup, TestElement).
- * \warning On success the internal file pointer \ref gdcmDocument::Fp
- * is modified to point after the tag.
- * On failure (i.e. when the tag wasn't the expected tag
- * (TestGroup, TestElement) the internal file pointer
- * \ref gdcmDocument::Fp is restored to it's original position.
- * @param testGroup The expected group of the tag.
- * @param testElement The expected Element of the tag.
- * @return True on success, false otherwise.
- */
-bool gdcmDocument::ReadTag(uint16_t testGroup, uint16_t testElement)
-{
- long positionOnEntry = ftell(Fp);
- long currentPosition = ftell(Fp); // On debugging purposes
-
- //// Read the Item Tag group and element, and make
- // sure they are what we expected:
- uint16_t itemTagGroup = ReadInt16();
- uint16_t itemTagElement = ReadInt16();
- if ( itemTagGroup != testGroup || itemTagElement != testElement )
- {
- std::ostringstream s;
- s << " We should have found tag (";
- s << std::hex << testGroup << "," << testElement << ")" << std::endl;
- s << " but instead we encountered tag (";
- s << std::hex << itemTagGroup << "," << itemTagElement << ")"
- << std::endl;
- s << " at address: " << (unsigned)currentPosition << std::endl;
- dbg.Verbose(0, "gdcmDocument::ReadItemTagLength: wrong Item Tag found:");
- dbg.Verbose(0, s.str().c_str());
- fseek(Fp, positionOnEntry, SEEK_SET);
-
- return false;
- }
- return true;
-}
-
-/**
- * \brief Assuming the internal file pointer \ref gdcmDocument::Fp
- * is placed at the beginning of a tag (TestGroup, TestElement),
- * read the length associated to the Tag.
- * \warning On success the internal file pointer \ref gdcmDocument::Fp
- * is modified to point after the tag and it's length.
- * On failure (i.e. when the tag wasn't the expected tag
- * (TestGroup, TestElement) the internal file pointer
- * \ref gdcmDocument::Fp is restored to it's original position.
- * @param testGroup The expected group of the tag.
- * @param testElement The expected Element of the tag.
- * @return On success returns the length associated to the tag. On failure
- * returns 0.
- */
-uint32_t gdcmDocument::ReadTagLength(uint16_t testGroup, uint16_t testElement)
-{
- long positionOnEntry = ftell(Fp);
- (void)positionOnEntry;
-
- if ( !ReadTag(testGroup, testElement) )
- {
- return 0;
- }
-
- //// Then read the associated Item Length
- long currentPosition = ftell(Fp);
- uint32_t itemLength = ReadInt32();
- {
- std::ostringstream s;
- s << "Basic Item Length is: "
- << itemLength << std::endl;
- s << " at address: " << (unsigned)currentPosition << std::endl;
- dbg.Verbose(0, "gdcmDocument::ReadItemTagLength: ", s.str().c_str());
- }
- return itemLength;
-}
-
-/**
- * \brief When parsing the Pixel Data of an encapsulated file, read
- * the basic offset table (when present, and BTW dump it).
- */
-void gdcmDocument::ReadAndSkipEncapsulatedBasicOffsetTable()
-{
- //// Read the Basic Offset Table Item Tag length...
- uint32_t itemLength = ReadTagLength(0xfffe, 0xe000);
-
- // When present, read the basic offset table itself.
- // Notes: - since the presence of this basic offset table is optional
- // we can't rely on it for the implementation, and we will simply
- // trash it's content (when present).
- // - still, when present, we could add some further checks on the
- // lengths, but we won't bother with such fuses for the time being.
- if ( itemLength != 0 )
- {
- char* basicOffsetTableItemValue = new char[itemLength + 1];
- fread(basicOffsetTableItemValue, itemLength, 1, Fp);
-
-#ifdef GDCM_DEBUG
- for (unsigned int i=0; i < itemLength; i += 4 )