-/**
- * \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;
- 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 '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)" );
-
- // Group 0002 should always be VR, and the first element 0000
- // Let's be carefull (so many wrong headers ...)
- // and 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.
- // 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;
-
- // group 0x0002 *is always* Explicit VR Sometimes ,
- // even if elem 0002,0010 (Transfer Syntax) tells us the file is
- // *Implicit* VR (see former 'gdcmData/icone.dcm')
-
- 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;
- gdcmVerboseMacro( "Group 0002 : Explicit Value Representation");
- }
- else
- {
- Filetype = ImplicitVR;
- gdcmVerboseMacro( "Group 0002 :Not an explicit Value Representation;"
- << "Looks like a bugged Header!");
- }
-
- if ( net2host )
- {
- SwapCode = 4321;
- gdcmVerboseMacro( "HostByteOrder != NetworkByteOrder");
- }
- else
- {
- SwapCode = 1234;
- gdcmVerboseMacro( "HostByteOrder = NetworkByteOrder");
- }
-
- // Position the file position indicator at first tag
- // (i.e. after the file preamble and the "DICM" string).
- Fp->seekg(0, std::ios::beg);