- uint16_t group;
- uint16_t elem;
- try
- {
- group = ReadInt16();
- elem = ReadInt16();
- }
- catch ( FormatError )
- {
- throw FormatError("Unexpected end of file encountered during ",
- "Document::FindDocEntryLengthOBOrOW()");
- }
-
- // We have to decount the group and element we just read
- totalLength += 4;
-
- if ( group != 0xfffe || ( ( elem != 0xe0dd ) && ( elem != 0xe000 ) ) )
- {
- long filePosition = Fp->tellg();
- gdcmVerboseMacro( "Neither an Item tag nor a Sequence delimiter tag on :"
- << std::hex << group << " , " << elem
- << ") -before- position x(" << filePosition << ")" );
-
- Fp->seekg(positionOnEntry, std::ios::beg);
- throw FormatUnexpected( "Neither an Item tag nor a Sequence delimiter tag.");
- }
-
- if ( elem == 0xe0dd )
- {
- foundSequenceDelimiter = true;
- }
-
- uint32_t itemLength = ReadInt32();
- // We add 4 bytes since we just read the ItemLength with ReadInt32
- totalLength += itemLength + 4;
- SkipBytes(itemLength);
-
- if ( foundSequenceDelimiter )
- {
- break;
- }
- }
- Fp->seekg( positionOnEntry, std::ios::beg);
- return totalLength;
-}
-
-/**
- * \brief Reads a supposed to be 16 Bits integer
- * (swaps it depending on processor endianity)
- * @return read value
- */
-uint16_t Document::ReadInt16()
- throw( FormatError )
-{
- uint16_t g;
- Fp->read ((char*)&g, (size_t)2);
- if ( Fp->fail() )
- {
- throw FormatError( "Document::ReadInt16()", " file error." );
- }
- if( Fp->eof() )
- {
- throw FormatError( "Document::ReadInt16()", "EOF." );
- }
- g = SwapShort(g);
- return g;
-}
-
-/**
- * \brief Reads a supposed to be 32 Bits integer
- * (swaps it depending on processor endianity)
- * @return read value
- */
-uint32_t Document::ReadInt32()
- throw( FormatError )
-{
- uint32_t g;
- Fp->read ((char*)&g, (size_t)4);
- if ( Fp->fail() )
- {
- throw FormatError( "Document::ReadInt32()", " file error." );
- }
- if( Fp->eof() )
- {
- throw FormatError( "Document::ReadInt32()", "EOF." );
- }
- g = SwapLong(g);
- return g;
-}
-
-/**
- * \brief skips bytes inside the source file
- * \warning NOT end user intended method !
- * @return
- */
-void Document::SkipBytes(uint32_t nBytes)
-{
- //FIXME don't dump the returned value
- Fp->seekg((long)nBytes, std::ios::cur);
-}
-
-/**
- * \brief Loads all the needed Dictionaries
- * \warning NOT end user intended method !
- */
-void Document::Initialize()
-{
- RefPubDict = Global::GetDicts()->GetDefaultPubDict();
- RefShaDict = NULL;
- Filetype = Unknown;
-}
-
-/**
- * \brief Discover what the swap code is (among little endian, big endian,
- * bad little endian, bad big endian).
- * sw is set
- * @return false when we are absolutely sure
- * it's neither ACR-NEMA nor DICOM
- * true when we hope ours assuptions are OK
- */
-bool Document::CheckSwap()
-{
- // The only guaranted way of finding the swap code is to find a
- // group tag since we know it's length has to be of four bytes i.e.
- // 0x00000004. Finding the swap code in then straigthforward. Trouble
- // occurs when we can't find such group...
-
- uint32_t x = 4; // x : for ntohs
- bool net2host; // true when HostByteOrder is the same as NetworkByteOrder
- uint32_t s32;
- uint16_t s16;
-
- char deb[256];
-
- // First, compare HostByteOrder and NetworkByteOrder in order to
- // determine if we shall need to swap bytes (i.e. the Endian type).
- if ( x == ntohs(x) )
- {
- net2host = true;
- }
- else
- {
- net2host = false;
- }
-
- // The easiest case is the one of a 'true' DICOM header, we just have
- // to look for the string "DICM" inside the file preamble.
- Fp->read(deb, 256);
-
- char *entCur = deb + 128;
- if( memcmp(entCur, "DICM", (size_t)4) == 0 )
- {
- gdcmVerboseMacro( "Looks like DICOM Version3 (preamble + DCM)" );