- 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::Initialise()
-{
- RefPubDict = Global::GetDicts()->GetDefaultPubDict();
- RefShaDict = NULL;
- RLEInfo = new RLEFramesInfo;
- JPEGInfo = new JPEGFragmentsInfo;
- 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 DICOM header, since it possesses a
- // file preamble where it suffice to look for the string "DICM".
- Fp->read(deb, 256);
-
- char *entCur = deb + 128;
- if( memcmp(entCur, "DICM", (size_t)4) == 0 )
- {
- dbg.Verbose(1, "Document::CheckSwap:", "looks like DICOM Version3");
-
- // Next, determine the value representation (VR). Let's skip to the
- // first element (0002, 0000) and check there if we find "UL"
- // - or "OB" if the 1st one is (0002,0001) -,
- // in which case we (almost) know it is explicit VR.
- // WARNING: if it happens to be implicit VR then what we will read
- // is the length of the group. If this ascii representation of this
- // length happens to be "UL" then we shall believe it is explicit VR.
- // FIXME: in order to fix the above warning, we could read the next
- // element value (or a couple of elements values) in order to make
- // sure we are not commiting a big mistake.
- // We need to skip :
- // * the 128 bytes of File Preamble (often padded with zeroes),
- // * the 4 bytes of "DICM" string,
- // * the 4 bytes of the first tag (0002, 0000),or (0002, 0001)
- // i.e. a total of 136 bytes.
- entCur = deb + 136;
-
- // FIXME : FIXME:
- // Sometimes (see : gdcmData/icone.dcm) group 0x0002 *is* Explicit VR,
- // but elem 0002,0010 (Transfert Syntax) tells us the file is
- // *Implicit* VR. -and it is !-
-
- if( memcmp(entCur, "UL", (size_t)2) == 0 ||
- memcmp(entCur, "OB", (size_t)2) == 0 ||
- memcmp(entCur, "UI", (size_t)2) == 0 ||
- memcmp(entCur, "CS", (size_t)2) == 0 ) // CS, to remove later
- // when Write DCM *adds*
- // FIXME
- // Use Document::dicom_vr to test all the possibilities
- // instead of just checking for UL, OB and UI !? group 0000
- {
- Filetype = ExplicitVR;
- dbg.Verbose(1, "Document::CheckSwap:",
- "explicit Value Representation");
- }
- else
- {
- Filetype = ImplicitVR;
- dbg.Verbose(1, "Document::CheckSwap:",
- "not an explicit Value Representation");
- }
-
- if ( net2host )
- {