- guint32 length = tag->GetLength();
-
- if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(tag) )
- {
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
- if(length%2==1) {
- ValEntry->SetValue(ValEntry->GetValue()+"\0");
- ValEntry->SetLength(ValEntry->GetReadLength()+1);
- }
- WriteEntryTagVRLength(ValEntry, _fp, type);
- WriteEntryValue(ValEntry, _fp, type);
- return true;
- }
-
- if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) )
- {
- /// \todo FIXME : when voidArea belong to gdcmBinEntry only, fix
- /// voidArea length
- //
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
-/*
- if(length%2==1) {
- tag->SetValue(tag->GetValue()+"\0");
- tag->SetLength(tag->GetReadLength()+1);
- }
-*/
- WriteEntryTagVRLength(tag, _fp, type);
- WriteEntryValue(tag, _fp, type);
- return true;
- }
-}
-
-/**
- * \brief writes on disc according to the requested format
- * (ACR-NEMA, ExplicitVR, ImplicitVR) the image
- * using the Chained List
- * \warning does NOT add the missing elements in the header :
- * it's up to the user doing it !
- * (function CheckHeaderCoherence to be written)
- * \warning DON'T try, right now, to write a DICOM image
- * from an ACR Header (meta elements will be missing!)
- * @param type type of the File to be written
- * (ACR-NEMA, ExplicitVR, ImplicitVR)
- * @param _fp already open file pointer
- */
-
-bool gdcmDocument::WriteEntries(FILE *_fp,FileType type)
-{
- /// \todo FIXME : explore recursively the whole structure...
- /// \todo (?) check write failures (after *each* fwrite)
-
- dbg.Verbose(0, "gdcmDocument::WriteEntries: entering.");
- for (TagDocEntryHT::iterator it = tagHT.begin(); it != tagHT.end(); ++it )
- {
- gdcmDocEntry * entry = it->second;
-
- if ( type == gdcmACR ){
- if (entry->GetGroup() < 0x0008)
- // Ignore pure DICOM V3 groups
- continue;
- if (entry->GetGroup() %2)
- // Ignore the "shadow" groups
- continue;
- if (entry->GetVR() == "SQ" ) // ignore Sequences
- continue;
- }
- if (! WriteEntry(entry, _fp, type) ) {
- dbg.Verbose(0, "gdcmDocument::WriteEntries: write failure.");
- return false;
- }
- }
- return true;
-}
-
-
-/**
- * \brief Swaps back the bytes of 4-byte long integer accordingly to
- * processor order.
- * @return The properly swaped 32 bits integer.
- */
-guint32 gdcmDocument::SwapLong(guint32 a) {
- switch (sw) {
- case 0 :
- break;
- case 4321 :
- a=( ((a<<24) & 0xff000000) | ((a<<8) & 0x00ff0000) |
- ((a>>8) & 0x0000ff00) | ((a>>24) & 0x000000ff) );
- break;
-
- case 3412 :
- a=( ((a<<16) & 0xffff0000) | ((a>>16) & 0x0000ffff) );
- break;
-
- case 2143 :
- a=( ((a<<8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) );
- break;
- default :
- std::cout << "swapCode= " << sw << std::endl;
- dbg.Error(" gdcmDocument::SwapLong : unset swap code");
- a=0;
- }
- return(a);
-}
-
-/**
- * \brief Unswaps back the bytes of 4-byte long integer accordingly to
- * processor order.
- * @return The properly unswaped 32 bits integer.
- */
-guint32 gdcmDocument::UnswapLong(guint32 a) {
- return (SwapLong(a));
-}
-
-/**
- * \brief Swaps the bytes so they agree with the processor order
- * @return The properly swaped 16 bits integer.
- */
-guint16 gdcmDocument::SwapShort(guint16 a) {
- if ( (sw==4321) || (sw==2143) )
- a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
- return (a);
-}
-
-/**
- * \brief Unswaps the bytes so they agree with the processor order
- * @return The properly unswaped 16 bits integer.
- */
-guint16 gdcmDocument::UnswapShort(guint16 a) {
- return (SwapShort(a));
-}