From 0fea0679c6061128104e6a357d20653baa274884 Mon Sep 17 00:00:00 2001 From: frog Date: Mon, 7 Oct 2002 20:08:03 +0000 Subject: [PATCH] * src/gdcmHeader now contains_IdDcmCheckSwap, _IdDcmRecupLgr, and _IdDcmSWAP_LONG. --- Frog --- ChangeLog | 4 + TODO | 8 + src/Makefile | 2 +- src/gdcmHeader.cxx | 610 +++++++++++++++++++++++---------------------- src/gdcmlib.h | 38 +-- 5 files changed, 349 insertions(+), 313 deletions(-) diff --git a/ChangeLog b/ChangeLog index e02ed15c..66dcea83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2002-10-07 Eric Boix + * src/gdcmHeader now contains_IdDcmCheckSwap, _IdDcmRecupLgr, + and _IdDcmSWAP_LONG. + 2002-09-12 Eric Boix * This corresponds to all the changes decided at the meeting of May 23 2002. Needless to say we are running late... diff --git a/TODO b/TODO index aca64a52..9fc1484d 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,11 @@ +GetPubElValByNumber doit faire la difference entre chaine vide +et chaine pas touve''. Eventuellement raiser une exception ? + +gdcmHeader::_IdDcmRecupLgr : le d'elements dans la table de type DICOM_VR + est hard code' (a 26). FIX ME. + +grep str2num *.c: c'est une macro sans doute proprifiable + gdcmHeader::CheckSwap() dans le cas ACR pas propre, degager tout de suite si on a deduit que c'en est pas... diff --git a/src/Makefile b/src/Makefile index 1d4bade6..f47fa5c0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ PYTHON_PREFIX =`$(PYTHON) -c "import sys; print sys.exec_prefix"` PYTHON_VERSION =`$(PYTHON) -c "import sys; print sys.version[:3]"` PYTHON_INCLUDES="-I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)" -CXXFLAGS=$(PYTHON_INCLUDES) +CXXFLAGS=$(PYTHON_INCLUDES) `glib-config --cflags` %.o : %.cxx $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 79aa0139..6899e505 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -1,340 +1,360 @@ #include "gdcmlib.h" +extern "C" { +#include "glib.h" +} +#include +// For nthos: +#ifdef _MSC_VER +#include +#else +#include +#endif -/* ======================================================================= - - _IdDcmCheckSwap - La seule maniere sure que l'on aie pour determiner - si on est en LITTLE_ENDIAN, BIG-ENDIAN, - BAD-LITTLE-ENDIAN, BAD-BIG-ENDIAN - est de trouver l'element qui donne la longueur d'un 'GROUP' - (on sait que la longueur de cet element vaut 0x00000004) - et de regarder comment cette longueur est codee en memoire - - Le probleme vient de ce que parfois, il n'y en a pas ... - - On fait alors le pari qu'on a a faire a du LITTLE_ENDIAN propre. - (Ce qui est la norme -pas respectee- depuis ACR-NEMA) - Si ce n'est pas le cas, on ne peut rien faire. - - (il faudrait avoir des fonctions auxquelles - on passe le code Swap en parametre, pour faire des essais 'manuels') +#define LGR_ENTETE_A_LIRE 256 // on ne lit plus que le debut +#define DEBUG 1 - ======================================================================= */ +//FIXME: this looks dirty to me... +#define str2num(str, typeNum) *((typeNum *)(str)) -EndianType gdcmHeader::gdcmHeader() +/** + * \ingroup gdcmHeader + * \brief La seule maniere sure que l'on aie pour determiner + * si on est en LITTLE_ENDIAN, BIG-ENDIAN, + * BAD-LITTLE-ENDIAN, BAD-BIG-ENDIAN + * est de trouver l'element qui donne la longueur d'un 'GROUP' + * (on sait que la longueur de cet element vaut 0x00000004) + * et de regarder comment cette longueur est codee en memoire + * + * Le probleme vient de ce que parfois, il n'y en a pas ... + * + * On fait alors le pari qu'on a a faire a du LITTLE_ENDIAN propre. + * (Ce qui est la norme -pas respectee- depuis ACR-NEMA) + * Si ce n'est pas le cas, on ne peut rien faire. + * + * (il faudrait avoir des fonctions auxquelles + * on passe le code Swap en parametre, pour faire des essais 'manuels') + */ +void gdcmHeader::CheckSwap() { - //guint32 s; + guint32 s; guint32 x=4; // x : pour ntohs bool net2host; // true when HostByteOrder is the same as NetworkByteOrder - - int sw; + int lgrLue; char * entCur; char deb[LGR_ENTETE_A_LIRE]; - + // On teste le processeur if (x==ntohs(x)) { - net2host = true; - } else { - net2host = false; - } - + net2host = true; + } else { + net2host = false; + } + // On commence par verifier si c'est du DICOM 'actuel' // ------------- + lgrLue = fread(deb,1,LGR_ENTETE_A_LIRE, fp); + + entCur = deb+128; + if(memcmp(entCur, "DICM", (size_t)4) == 0) { + filetype = TrueDicom; + if (DEBUG) printf ("_IdDcmCheckSwap : C est du DICOM actuel \n"); + } else { + filetype = Unknown; + if (DEBUG) printf ("_IdDcmCheckSwap : Ce n'est PAS du DICOM actuel\n"); + } - lgrLue = fread(deb,1,LGR_ENTETE_A_LIRE,e->fp); - - entCur = deb+128; - if(memcmp(entCur, "DICM", (size_t)4) == 0) { - filetype = TrueDicom; - if (DEBUG) printf ("_IdDcmCheckSwap : C est du DICOM actuel \n"); - } else { - filetype = Unknown; - if (DEBUG) printf ("_IdDcmCheckSwap : Ce n'est PAS du DICOM actuel\n"); - } - - if(filetype == TrueDicom) { - // on saute le File Preamble (souvent a ZERO) : 128 Octets - // + le DICM (4), et le (0002, 0000) soit 4 (136 = 128 + 4 + 4) - entCur = deb+136; - if(memcmp(entCur, "UL", (size_t)2) == 0) { - // les 2 premiers octets de la lgr peuvent valoir UL --> Explicit VR - filetype = ExplicitVR; - if (DEBUG) printf ("_IdDcmCheckSwap : Explicit VR\n"); - } else { - filetype = ImplicitVR; - if (DEBUG) printf ("_IdDcmCheckSwap : PAS Explicit VR\n"); - } - - if (net2host) { // HostByteOrder is different from NetworkByteOrder - sw = 0; // on est sur PC ou DEC --> LITTLE-ENDIAN -> Rien a faire - if (DEBUG) printf("HostByteOrder = NetworkByteOrder\n"); - - } else { /* on est sur une Sun ou une SGI */ - sw = 4321; - if (DEBUG) printf("HostByteOrder != NetworkByteOrder\n"); - } - - rewind(e->fp); - fseek (e->fp, 132L, SEEK_SET); //On se positionne sur le debut des info - e->offsetCourant=132; - return sw; - - } /* fin TrueDicom */ + if(filetype == TrueDicom) { + // on saute le File Preamble (souvent a ZERO) : 128 Octets + // + le DICM (4), et le (0002, 0000) soit 4 (136 = 128 + 4 + 4) + entCur = deb+136; + if(memcmp(entCur, "UL", (size_t)2) == 0) { + // les 2 premiers octets de la lgr peuvent valoir UL --> Explicit VR + filetype = ExplicitVR; + if (DEBUG) printf ("_IdDcmCheckSwap : Explicit VR\n"); + } else { + filetype = ImplicitVR; + if (DEBUG) printf ("_IdDcmCheckSwap : PAS Explicit VR\n"); + } + + if (net2host) { // HostByteOrder is different from NetworkByteOrder + sw = 0; // on est sur PC ou DEC --> LITTLE-ENDIAN -> Rien a faire + if (DEBUG) printf("HostByteOrder = NetworkByteOrder\n"); + } else { /* on est sur une Sun ou une SGI */ + sw = 4321; + if (DEBUG) printf("HostByteOrder != NetworkByteOrder\n"); + } + + rewind(fp); + fseek (fp, 132L, SEEK_SET); //On se positionne sur le debut des info + offsetCourant=132; + } // End of TrueDicom // Pas du TrueDicom : permiere hypothese c'est de l'ACR 'propre', auquel // cas la lgr du premier element du groupe est FORCEMENT 4 - - entCur=deb + 4; - s=str2num(entCur,int); - - switch (s) { - case 0x00040000 : - sw=3412; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); - filetype = ACR; - break; - case 0x04000000 : - sw=4321; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); - filetype = ACR; - break; - case 0x00000400 : - sw=2143; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); - filetype = ACR; - break; - case 0x00000004 : - sw=0; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); + entCur=deb + 4; + s=str2num(entCur,int); + + switch (s) { + case 0x00040000 : + sw=3412; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); + filetype = ACR; + break; + case 0x04000000 : + sw=4321; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); + filetype = ACR; + break; + case 0x00000400 : + sw=2143; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); filetype = ACR; - break; - default : - sw = -1; - if (DEBUG) printf (" Pas trouve l info de Swap; On va parier\n"); + break; + case 0x00000004 : + sw=0; if(DEBUG) printf("s : %08x sw : %d\n",s,sw); + filetype = ACR; + break; + default : + sw = -1; + if (DEBUG) printf (" Pas trouve l info de Swap; On va parier\n"); + } + if(sw!=-1) { + rewind(fp); // les info commencent au debut + offsetCourant=0; + return; } // Deuxieme hypothese : c'est de l'ACR 'pas propre' i.e. il manque // la lgr du groupe - - if(sw==-1) { - /* On n'a pas trouve l'info de swap 28/11/2000 JPR */ - // Si c'est du VRAI ACR NEMA si on est sur une DEC ou un PC swap=0, - // SUN ou SGI SWAP=4321 - /* si c'est du RAW, ca degagera + tard */ - - if (DEBUG) printf("On force la chance \n"); - - if (x!=ntohs(x)) // HostByteOrder is different from NetworkByteOrder - sw = 0; // on est sur PC ou DEC --> LITTLE-ENDIAN -> Rien a faire - else - sw = 4321; // on est sur Sun ou SGI - } - - rewind(e->fp); // les info commencent au debut - e->offsetCourant=0; - return (sw); -} - -void gdcmHeader::_setAcrLibido() { - - _ID_DCM_ELEM * ple; - PLIST_ELEMENT plelem; - PLIST pl; - - // Positionnement ACR_LIBIDO - if(DEBUG) printf("Entree ds _setAcrLibido\n"); - - filetype = ACR_LIBIDO = 0; - if ( filetype != TrueDicom) { - // Recognition Code --> n'existe plus en DICOM V3 ... - - pl = e->plist; - plelem = IdLstFirst(pl); - while (plelem) { - ple= IdLstPtrObj(plelem); - if(DEBUG) printf("gr %04x Num %04x\n", ple->Gr, ple->Num); - if(ple->Gr > 0x0008) break; // On a depasse - if(ple->Gr == 0x0008) { - if(ple->Num > 0x0010) break; // On a depasse - if(ple->Num == 0x0010) { - if ( (memcmp(ple->valeurElem,"ACRNEMA_LIBIDO",14)==0) - // si c'est egal - || (memcmp(ple->valeurElem,"CANRME_AILIBOD",14)==0)) { - // en cas d'objet ACRLibido fait sr 1 autre machine) - e->ACR_LIBIDO =1; - } // fin if memcmp - break; - } // fin if ple->Num==0x0010 - } // fin ple->Gr==0x0008 - plelem = IdLstNext(plelem); - } // fin while - } // fin if TrueDicom - - return; + + // On n'a pas trouve l'info de swap. + // Si c'est du VRAI ACR NEMA et + // * si on est sur une DEC ou un PC alors swap=0, + // * si on est sur SUN ou SGI, alors swap=4321 + // Si c'est du RAW, ca degagera + tard + if (DEBUG) printf("On force la chance \n"); + + if (x!=ntohs(x)) // HostByteOrder is different from NetworkByteOrder + // on est sur PC ou DEC --> LITTLE-ENDIAN -> Rien a faire + sw = 0; + else + // on est sur Sun ou SGI + sw = 4321; + rewind(fp); // les info commencent au debut + offsetCourant=0; + return; } -/* ======================================================================= -* _IdDcmRecupLgr -* -* ACR-NEMA : On a toujours -* GroupNumber (2 Octets) -* ElementNumber (2 Octets) -* ElementSize (4 Octets) -* -* -* DICOM : On peut avoir (implicit Value Representation) -* GroupNumber (2 Octets) -* ElementNumber (2 Octets) -* ElementSize (4 Octets) -* -* On peut avoir (explicit Value Representation) -* GroupNumber (2 Octets) -* ElementNumber (2 Octets) -* ValueRepresentation (2 Octets) -* ElementSize (2 Octets) -* -* ATTENTION : dans le cas ou ValueRepresentation = OB, OW, SQ, UN -* GroupNumber (2 Octets) -* ElementNumber (2 Octets) -* ValueRepresentation (2 Octets) -* zone reservee (2 Octets) -* ElementSize (4 Octets) -* -* -* ======================================================================= */ /** - * \ingroup dcm - * \brief recupere la longueur d'un champ DICOM. - * (le fichier doit deja avoir ete ouvert, - * _IdAcrCheckSwap(ID_DCM_HDR *e) avoir ete appele) - * et la partie 'group' ainsi que la partie 'elem' - * de l'acr_element doivent avoir ete lues. - * @param sw code swap - * @param skippedLength pointeur sur nombre d'octets que l'on a saute qd la lecture est finie - * @param longueurLue pointeur sur longueur (en nombre d'octets) effectivement lue - - * @return longueur retenue pour le champ + * \ingroup gdcmHeader + * \brief Pour les fichiers non TrueDicom, si le recognition + * code (0008,0010) s'avere etre "ACR_LIBIDO", alors + * valide la reconnaissance du fichier en positionnant + * filetype. */ - -static guint32 _IdDcmRecupLgr(ID_DCM_HDR *e, int sw, int *skippedLength, int *longueurLue) { -guint32 l_gr; -unsigned short int l_gr_2; -int i, trouve; -char VR[5]; -int lgrLue; - -/* - * ATTENTION : -*/ - -int nbCode=26; // nombre d'elements dans la table de type DICOM_VR definie dans dicom.c - -/* ================ */ - -// ID_DCM_HDR *e sert uniquement de passe-plat pour __ExplicitVR - - -if (e->__ExplicitVR == 1) { - lgrLue=fread (&VR, (size_t)2,(size_t)1, e->fp); - VR[2]=0; - - // ATTENTION : - // Ce n'est pas parce qu'on a trouve UL la premiere fois qu'on respecte - // Explicit VR tout le temps - // (cf e=film ...) - - for(i=0,trouve=0;ipleCourant)->VR=_ID_dicom_vr[i].dicom_VR; - trouve=1; - break; - } +void gdcmHeader::setAcrLibido() { + string RecCode; + + if ( filetype != TrueDicom) { + printf("_setAcrLibido expects a presumably ACR file\n"); + // Recognition Code --> n'existe plus en DICOM V3 ... + RecCode = GetPubElValByNumber(0x0008, 0x0010); + // FIXME NOW + if (RecCode == "ACRNEMA_LIBIDO" || + RecCode == "CANRME_AILIBOD" ) + filetype = ACR_LIBIDO; + else + filetype = ACR; } + return; +} - if ( trouve == 0) { +/** + * \ingroup gdcmHeader + * \brief recupere la longueur d'un champ DICOM. + * Preconditions: + * 1/ le fichier doit deja avoir ete ouvert, + * 2/ CheckSwap() doit avoir ete appele + * 3/ la partie 'group' ainsi que la partie 'elem' + * de l'acr_element doivent avoir ete lues. + * + * ACR-NEMA : we allways get + * GroupNumber (2 Octets) + * ElementNumber (2 Octets) + * ElementSize (4 Octets) + * DICOM en implicit Value Representation : + * GroupNumber (2 Octets) + * ElementNumber (2 Octets) + * ElementSize (4 Octets) + * + * DICOM en explicit Value Representation : + * GroupNumber (2 Octets) + * ElementNumber (2 Octets) + * ValueRepresentation (2 Octets) + * ElementSize (2 Octets) + * + * ATTENTION : dans le cas ou ValueRepresentation = OB, OW, SQ, UN + * GroupNumber (2 Octets) + * ElementNumber (2 Octets) + * ValueRepresentation (2 Octets) + * zone reservee (2 Octets) + * ElementSize (4 Octets) + * + * @param sw code swap + * @param skippedLength pointeur sur nombre d'octets que l'on a saute qd + * la lecture est finie + * @param longueurLue pointeur sur longueur (en nombre d'octets) + * effectivement lue + * @return longueur retenue pour le champ + */ - // On est mal : implicit VR repere - // mais ce n'est pas un code connu ... - // On reconstitue la longueur +// FIXME sw n'est plus un argument necessaire +long int gdcmHeader::RecupLgr( + _ID_DCM_ELEM *pleCourant, int sw, int *skippedLength, int *longueurLue) +{ + guint32 l_gr; + unsigned short int l_gr_2; + int i, trouve; + char VR[5]; + int lgrLue; + + // FIX ME + // ATTENTION : nbCode correspond au nombre d'elements dans la table + // de type DICOM_VR. A nettoyer. + // + int nbCode=26; + + if (filetype == ExplicitVR) { + lgrLue=fread (&VR, (size_t)2,(size_t)1, fp); + VR[2]=0; - if(DEBUG) printf("IdDcmRecupLgr : Explicit VR, mais pas trouve de code connu\n"); - memcpy(&l_gr, VR,(size_t)2); - - lgrLue=fread ( ((char*)&l_gr)+2, (size_t)2, (size_t)1, e->fp); - - if(sw) l_gr = _IdDcmSWAP_LONG(((guint32)l_gr),sw); + // ATTENTION : + // Ce n'est pas parce qu'on a trouve UL la premiere fois qu'on respecte + // Explicit VR tout le temps (cf e=film ...) - if(DEBUG) printf("IdDcmRecupLgr : lgr deduite : %08x , %d\n",l_gr,l_gr); + for(i=0,trouve=0;iVR=_ID_dicom_vr[i].dicom_VR; + trouve=1; + break; + } + } - *longueurLue=l_gr; - if ( (int)l_gr == -1) { - l_gr=0; + if ( trouve == 0) { + + // On est mal : implicit VR repere + // mais ce n'est pas un code connu ... + // On reconstitue la longueur + + if(DEBUG) + printf("IdDcmRecupLgr : Explicit VR, mais pas de code connu\n"); + memcpy(&l_gr, VR,(size_t)2); + + lgrLue=fread ( ((char*)&l_gr)+2, (size_t)2, (size_t)1, fp); + + l_gr = SWAP_LONG((guint32)l_gr); + + if(DEBUG) + printf("IdDcmRecupLgr : lgr deduite : %08x , %d\n",l_gr,l_gr); + + *longueurLue=l_gr; + if ( (int)l_gr == -1) + l_gr=0; + + *skippedLength = 4; + if (DEBUG) + printf(" 1 : lgr %08x (%d )skippedLength %d\n", + l_gr,l_gr, *skippedLength); + return(l_gr); } - *skippedLength = 4; - if (DEBUG) printf(" 1 : lgr %08x (%d )skippedLength %d\n",l_gr,l_gr, *skippedLength); - return(l_gr); - } - - // On repart dans la sequence 'sensee' - - if(DEBUG) printf("VR : [%01x , %01x] (%c%c) en position %d du tableau\n", VR[0],VR[1],VR[0],VR[1],i); - //printf(" %d , %s\n", i,_ID_dicom_vr[i].dicom_VR); - - if ( - (!memcmp( VR,"OB",(size_t)2 )) || - (!memcmp( VR,"OW",(size_t)2 )) || - (!memcmp( VR,"SQ",(size_t)2 )) || - (!memcmp( VR,"UN",(size_t)2 )) ) { - - // les 2 octets suivants sont reserves - - if(DEBUG) printf("IdDcmRecupLgr : les 2 octets suivants sont reserves\n"); - //on les saute - fseek(e->fp, 2L,SEEK_CUR); - //on lit la lgr sur QUATRE octets - - lgrLue=fread (&l_gr, (size_t)4,(size_t)1, e->fp); - - if(sw) l_gr = _IdDcmSWAP_LONG(((guint32)l_gr),sw); - *skippedLength = 8; - - } else { - //on lit la lgr sur DEUX octets - - lgrLue=fread (&l_gr_2, (size_t)2,(size_t)1, e->fp); - - if(sw) l_gr_2 = _IdDcmSWAP_SHORT((unsigned short)l_gr_2,sw); + // On repart dans la sequence 'sensee' - *longueurLue=l_gr_2; - + if(DEBUG) + printf("VR : [%01x , %01x] (%c%c) en position %d du tableau\n", + VR[0],VR[1],VR[0],VR[1],i); + + if ( (!memcmp( VR,"OB",(size_t)2 )) || + (!memcmp( VR,"OW",(size_t)2 )) || + (!memcmp( VR,"SQ",(size_t)2 )) || + (!memcmp( VR,"UN",(size_t)2 )) ) { + + // les 2 octets suivants sont reserves: on les saute + if(DEBUG) + printf("IdDcmRecupLgr : les 2 octets suivants sont reserves\n"); + fseek(fp, 2L,SEEK_CUR); + + //on lit la lgr sur QUATRE octets + lgrLue=fread (&l_gr, (size_t)4,(size_t)1, fp); + l_gr = SWAP_LONG((guint32)l_gr); + *skippedLength = 8; - if ( l_gr_2 == 0xffff) { - l_gr = 0; } else { - l_gr = l_gr_2; + //on lit la lgr sur DEUX octets + lgrLue=fread (&l_gr_2, (size_t)2,(size_t)1, fp); + + if(sw) l_gr_2 = _IdDcmSWAP_SHORT((unsigned short)l_gr_2,sw); + + *longueurLue=l_gr_2; + + + if ( l_gr_2 == 0xffff) { + l_gr = 0; + } else { + l_gr = l_gr_2; + } + *skippedLength = 4; } + } else { + // Explicit VR = 0 + //on lit la lgr sur QUATRE octets + + lgrLue=fread (&l_gr, (size_t)4,(size_t)1, fp); + + l_gr= SWAP_LONG((long)l_gr); *skippedLength = 4; - } - } else { // Explicit VR = 0 + } + + *longueurLue=l_gr; + + // Traitement des curiosites sur la longueur + + if ( (int)l_gr == 0xffffffff) + l_gr=0; + + if(!memcmp( VR,"SQ",(size_t)2 )) { // ca annonce une SEQUENCE d'items ?! + l_gr=0; // on lira donc les items de la sequence + if (DEBUG) printf(" SQ trouve : lgr %d \n",l_gr); + } + + if (DEBUG) + printf(" 2 : lgr %08x (%d) skippedLength %d\n",l_gr,l_gr, *skippedLength); + return(l_gr); +} - //on lit la lgr sur QUATRE octets +/** + * \ingroup gdcmHeader + * \brief remet les octets dans un ordre compatible avec celui du processeur - lgrLue=fread (&l_gr, (size_t)4,(size_t)1, e->fp); + * @return longueur retenue pour le champ + */ - if(sw)l_gr=_IdDcmSWAP_LONG(((long)l_gr),sw); - *skippedLength = 4; - } - - *longueurLue=l_gr; - - // Traitement des curiosites sur la longueur - - if ( (int)l_gr == 0xffffffff) - l_gr=0; +guint32 gdcmHeader::SWAP_LONG(guint32 a) { + // FIXME: il pourrait y avoir un pb pour les entiers negatifs ... + switch (sw) { + 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; - if(!memcmp( VR,"SQ",(size_t)2 )) { // ca annonce une SEQUENCE d'items ?! - l_gr=0; // on lira donc les items de la sequence - if (DEBUG) printf(" SQ trouve : lgr %d \n",l_gr); - } - -if (DEBUG) printf(" 2 : lgr %08x (%d) skippedLength %d\n",l_gr,l_gr, *skippedLength); - return(l_gr); + case 2143 : + a=( ((a<<8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) ); + break; + default : + printf("\n\n\n *******\n erreur code swap ?!?\n\n\n"); + a=0; + } + return(a); } diff --git a/src/gdcmlib.h b/src/gdcmlib.h index 2afa1d17..beb8530c 100644 --- a/src/gdcmlib.h +++ b/src/gdcmlib.h @@ -10,6 +10,8 @@ #include #include // For size_t +#include +#include // The requirement for the hash table (or map) that we shall use: // 1/ First, next, last (iterators) @@ -30,8 +32,6 @@ typedef string TagKey; typedef map TagHT; -// Dummy declaration for the time being -typedef int guint16; // We shall need glib.h ! class DictEntry { private: @@ -113,7 +113,7 @@ class ElValSet { // We need both accesses with a TagKey and the Dicentry.Name ////// QUESTION: this leads to a double storage of a single ElValue map tagHt; - map NameHt; + map NameHt; public: int Add(ElValue); }; @@ -126,12 +126,13 @@ public: // Notes: // * the gdcmHeader::Set*Tag* family members cannot be defined as protected // (Swig limitations for as Has_a dependency between gdcmFile and gdcmHeader) +typedef int _ID_DCM_ELEM; class gdcmHeader { - enum EndianType { - LittleEndian, - BadLittleEndian, - BigEndian, - BadBigEndian}; + //enum EndianType { + //LittleEndian, + //BadLittleEndian, + //BigEndian, + //BadBigEndian}; enum FileType { Unknown = 0, TrueDicom, @@ -140,17 +141,20 @@ class gdcmHeader { ACR, ACR_LIBIDO}; private: - static DictSet* Dicts; // Global dictionary container - Dict* RefPubDict; // Public Dictionary - Dict* RefShaDict; // Shadow Dictionary (optional) - int swapcode; - ElValSet PubElVals; // Element Values parsed with Public Dictionary - ElValSet ShaElVals; // Element Values parsed with Shadow Dictionary + static DictSet* Dicts; // Global dictionary container + Dict* RefPubDict; // Public Dictionary + Dict* RefShaDict; // Shadow Dictionary (optional) + ElValSet PubElVals; // Element Values parsed with Public Dictionary + ElValSet ShaElVals; // Element Values parsed with Shadow Dictionary FileType filetype; + FILE * fp; + long int offsetCourant; int sw; - EndianType CheckSwap(); - void _setAcrLibido(); - guint32 _IdDcmRecupLgr(ID_DCM_HDR *e, int sw, int *skippedLength, int *longueurLue); + void CheckSwap(void); + void setAcrLibido(void); + long int RecupLgr(_ID_DCM_ELEM *pleCourant, int sw, + int *skippedLength, int *longueurLue); + guint32 SWAP_LONG(guint32); protected: ///// QUESTION: Maybe Print is a better name than write !? int write(ostream&); -- 2.45.1