5 static void _Swap(void* im, int swap, int lgr, int nb);
7 /////////////////////////////////////////////////////////////////
10 * \brief Constructor dedicated to writing a new DICOMV3 part10 compliant
11 * \file (see SetFileName, SetDcmTag and Write)
12 * \Opens (in read only and when possible) an existing file and checks
13 * \for DICOM compliance. Returns NULL on failure.
14 * \Note: the in-memory representation of all available tags found in
15 * \the DICOM header is post-poned to first header information access.
16 * \This avoid a double parsing of public part of the header when
17 * \one sets an a posteriori shadow dictionary (efficiency can be
18 * \seen as a side effect).
25 /////////////////////////////////////////////////////////////////
36 gdcmFile::gdcmFile(string & filename)
37 :gdcmHeader(filename.c_str())
42 /////////////////////////////////////////////////////////////////
45 * \brief Renvoie la longueur A ALLOUER pour recevoir les pixels de l'image
46 * \ ou DES images dans le cas d'un multiframe
47 * \ ATTENTION : il ne s'agit PAS de la lgr du groupe des Pixels
48 * \ (dans le cas d'images compressees, elle n'a pas de sens).
50 * @param void Rien en entree
52 * @return longueur a allouer
55 size_t gdcmFile::GetImageDataSize(void) {
56 int nbLignes, nbCol, nbFrames, nb;
57 string str_nbFrames, str_nb;
59 nbLignes=atoi(gdcmHeader::GetPubElValByNumber(0x0028,0x0010).c_str());
61 nbCol =atoi(gdcmHeader::GetPubElValByNumber(0x0028,0x0011).c_str());
64 str_nbFrames=gdcmHeader::GetPubElValByNumber(0x0028,0x0008);
66 if (str_nbFrames == "UNFOUND" ) {
69 nbFrames = atoi(str_nbFrames.c_str() );
72 // Nombre de Bits Alloues pour le stockage d'un Pixel
73 str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
75 if (str_nb == "UNFOUND" ) {
78 nb = atoi(str_nb.c_str() );
81 size_t lgrTotale = nbFrames*nbLignes*nbCol*(nb/8);
86 /////////////////////////////////////////////////////////////////
89 * \brief amene en mémoire les Pixels d'une image NON COMPRESSEE
90 * \Aucun test n'est fait pour le moment sur le caractere compresse ou non de l'image
94 * @return Pointeur sur la zone mémoire contenant les Pixels lus
97 void * gdcmFile::GetImageData (void) {
102 int nbFrames, nb, nbu, highBit, signe;
103 string str_nbFrames, str_nb, str_nbu, str_highBit, str_signe;
105 unsigned short int mask = 0xffff;
108 nbLignes=atoi(GetPubElValByNumber(0x0028,0x0010).c_str());
109 // Nombre de Colonnes
110 nbCol =atoi(GetPubElValByNumber(0x0028,0x0011).c_str());
113 str_nbFrames=GetPubElValByNumber(0x0028,0x0008);
116 if (str_nbFrames == "UNFOUND" ) {
119 nbFrames = atoi(str_nbFrames.c_str() );
122 // Nombre de Bits Alloues
123 str_nb=GetPubElValByNumber(0x0028,0x0100);
125 if (str_nb == "UNFOUND" ) {
128 nb = atoi(str_nb.c_str() );
131 // Nombre de Bits Utilises
132 str_nbu=GetPubElValByNumber(0x0028,0x0101);
134 if (str_nbu == "UNFOUND" ) {
137 nbu = atoi(str_nbu.c_str() );
140 // Position du Bit de Poids Fort
141 str_highBit=GetPubElValByNumber(0x0028,0x0102);
143 if (str_highBit == "UNFOUND" ) {
146 highBit = atoi(str_highBit.c_str() );
150 str_signe=GetPubElValByNumber(0x0028,0x0103);
152 if (str_signe == "UNFOUND" ) {
155 signe = atoi(str_signe.c_str() );
158 // Longueur en Octets des Pixels a lire
159 size_t lgrTotale = nbFrames*nbLignes*nbCol*(nb/8);
161 //Pixels = (char *) g_malloc(lgrTotale);
162 Pixels = (char *) malloc(lgrTotale);
164 GetPixels(lgrTotale, Pixels);
166 // On remet les Octets dans le bon ordre si besoin est
168 //int sw = GetSwapCode();
170 // _Swap (Pixels, sw, lgrTotale, nb); // A REMETTRE
173 // On remet les Bits des Octets dans le bon ordre si besoin est
175 // ATTENTION : Jamais confronté a des pixels stockes sur 32 bits
176 // avec moins de 32 bits utilises
177 // et dont le bit de poids fort ne serait pas la ou on l'attend ...
178 // --> ne marchera pas dans ce cas
180 mask = mask >> (nb-nbu);
181 int l=(int)lgrTotale/(nb/8);
182 unsigned short *deb = (unsigned short *)Pixels;
183 for(int i=0;i<l;i++) {
184 *deb = (*deb >> (nbu-highBit-1)) & mask;
189 printf ("on est sorti\n");
191 // VOIR s'il ne faudrait pas l'affecter à un champ du dcmHeader
198 // Je laisse le code integral, au cas ça puisse etre reutilise ailleurs
201 static void _Swap(void* im, int swap, int lgr, int nb) {
220 ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
221 | ((((unsigned short int*)im)[i])<<8);
225 printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
237 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 4321 */
238 fort =((unsigned long int*)im)[i]>>16;
239 fort= (fort>>8) | (fort<<8);
240 faible=(faible>>8) | (faible<<8);
242 ((unsigned long int*)im)[i]=(s32<<16)|fort;
248 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 2143 */
249 fort=((unsigned long int*)im)[i]>>16;
250 fort= (fort>>8) | (fort<<8);
251 faible=(faible>>8) | (faible<<8);
253 ((unsigned long int*)im)[i]=(s32<<16)|faible;
259 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 3412 */
260 fort=((unsigned long int*)im)[i]>>16;
262 ((unsigned long int*)im)[i]=(s32<<16)|fort;
267 printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);