- if ( (type == ImplicitVR) || (type == ExplicitVR) )
- UpdateGroupLength(false,type);
- if ( type == ACR)
- UpdateGroupLength(true,ACR);
-
- WriteEntries(type, fp);
- return(true);
- }
-
-/**
- * \ingroup gdcmFile
- * \brief Sets the Pixel Area size in the Header
- * --> not-for-rats function
- *
- * \warning WARNING doit-etre etre publique ?
- * TODO : y aurait il un inconvenient à fusionner ces 2 fonctions
- *
- * @param ImageDataSize new Pixel Area Size
- * warning : nothing else is checked
- */
-void gdcmHeader::SetImageDataSize(size_t ImageDataSize) {
- std::string content1;
- char car[20];
- // Assumes HeaderEntry (0x7fe0, 0x0010) exists ...
- sprintf(car,"%d",ImageDataSize);
-
- gdcmHeaderEntry *a = GetHeaderEntryByNumber(0x7fe0, 0x0010);
- a->SetLength(ImageDataSize);
-
- ImageDataSize+=8;
- sprintf(car,"%d",ImageDataSize);
- content1=car;
- SetPubEntryByNumber(content1, 0x7fe0, 0x0000);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Modifies the value of a given Header Entry (Dicom Element)
- * if it exists; Creates it with the given value if it doesn't
- * @param Value passed as a std::string
- * @param Group
- * @param Elem
- * \return boolean
- */
-bool gdcmHeader::ReplaceOrCreateByNumber(std::string Value,
- guint16 Group, guint16 Elem ) {
-
- if (CheckIfExistByNumber(Group, Elem) == 0) {
- gdcmHeaderEntry* a =NewHeaderEntryByNumber(Group, Elem);
- if (a == NULL)
- return false;
- Add(a);
- }
- SetPubEntryByNumber(Value, Group, Elem);
- return(true);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Modifies the value of a given Header Entry (Dicom Element)
- * if it exists; Creates it with the given value if it doesn't
- * @param Value passed as a char*
- * @param Group
- * @param Elem
- * \return boolean
- *
- */
-bool gdcmHeader::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
-
- gdcmHeaderEntry* nvHeaderEntry=NewHeaderEntryByNumber(Group, Elem);
- // TODO : check if fails
- Add(nvHeaderEntry);
- std::string v = Value;
- SetEntryByNumber(v, Group, Elem);
- return(true);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Set a new value if the invoked element exists
- * Seems to be useless !!!
- * @param Value
- * @param Group
- * @param Elem
- * \return boolean
- */
-bool gdcmHeader::ReplaceIfExistByNumber(char* Value, guint16 Group, guint16 Elem ) {
-
- std::string v = Value;
- SetEntryByNumber(v, Group, Elem);
- return true;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Swaps back the bytes of 4-byte long integer accordingly to
- * processor order.
- * @return The properly swaped 32 bits integer.
- */
-guint32 gdcmHeader::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 :
- dbg.Error(" gdcmHeader::SwapLong : unset swap code");
- a=0;
- }
- return(a);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Swaps the bytes so they agree with the processor order
- * @return The properly swaped 16 bits integer.
- */
-guint16 gdcmHeader::SwapShort(guint16 a) {
- if ( (sw==4321) || (sw==2143) )
- a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
- return (a);
-}
-
-//-----------------------------------------------------------------------------
-// Protected
-
-/**
- * \ingroup gdcmHeader
- * \brief retrieves a Dicom Element (the first one) using (group, element)
- * \ warning (group, element) IS NOT an identifier inside the Dicom Header
- * if you think it's NOT UNIQUE, check the count number
- * and use iterators to retrieve ALL the Dicoms Elements within
- * a given couple (group, element)
- * @param group Group number of the searched Dicom Element
- * @param element Element number of the searched Dicom Element
- * @return
- */
-gdcmHeaderEntry* gdcmHeader::GetHeaderEntryByNumber(guint16 group, guint16 element) {
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHT.count(key))
- return NULL;
- return tagHT.find(key)->second;
-}
-
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within the Header Entries for a Dicom Element of
- * a given tag.
- * @param tagName name of the searched Dicom Element.
- * @return Corresponding Dicom Element when it exists, and NULL
- * otherwise.
- */
- gdcmHeaderEntry *gdcmHeader::GetHeaderEntryByName(std::string tagName) {
- gdcmDictEntry *dictEntry = RefPubDict->GetTagByName(tagName);
- if( dictEntry == NULL)
- return NULL;
-
- return(GetHeaderEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()));
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Checks if a given Dicom Element exists
- * \ within the H table
- * @param group Group number of the searched Dicom Element
- * @param element Element number of the searched Dicom Element
- * @return number of occurences
- */
-int gdcmHeader::CheckIfExistByNumber(guint16 group, guint16 element ) {
- std::string key = gdcmDictEntry::TranslateToKey(group, element );
- return (tagHT.count(key));