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 gdcmFile::gdcmFile(string & filename)
26 :gdcmHeader(filename.c_str())
31 /////////////////////////////////////////////////////////////////
34 * \brief Renvoie la longueur A ALLOUER pour recevoir les pixels de l'image
35 * \ ou DES images dans le cas d'un multiframe
36 * \ ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels
37 * \ (dans le cas d'images compressees, elle n'a pas de sens).
39 * @param void Rien en entree
41 * @return longueur a allouer
44 size_t gdcmFile::GetImageDataSize(void) {
45 int nbLignes, nbCol, nbFrames, nb;
46 string str_nbFrames, str_nb;
48 nbLignes=atoi(gdcmHeader::GetPubElValByNumber(0x0028,0x0010).c_str());
50 nbCol =atoi(gdcmHeader::GetPubElValByNumber(0x0028,0x0011).c_str());
53 str_nbFrames=gdcmHeader::GetPubElValByNumber(0x0028,0x0008);
55 if (str_nbFrames == "UNFOUND" ) {
58 nbFrames = atoi(str_nbFrames.c_str() );
61 // Nombre de Bits Alloues pour le stockage d'un Pixel
62 str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
64 if (str_nb == "UNFOUND" ) {
67 nb = atoi(str_nb.c_str() );
70 size_t lgrTotale = nbFrames*nbLignes*nbCol*(nb/8);
75 /////////////////////////////////////////////////////////////////
78 * \brief amene en mémoire les Pixels d'une image NON COMPRESSEE
79 * \Aucun test n'est fait pour le moment sur le caractere compresse ou non de l'image
83 * @return Pointeur sur la zone mémoire contenant les Pixels lus
86 void * gdcmFile::GetImageData (void) {
91 int nbFrames, nb, nbu, highBit, signe;
92 string str_nbFrames, str_nb, str_nbu, str_highBit, str_signe;
94 unsigned short int mask = 0xffff;
97 nbLignes=atoi(GetPubElValByNumber(0x0028,0x0010).c_str());
99 nbCol =atoi(GetPubElValByNumber(0x0028,0x0011).c_str());
102 str_nbFrames=GetPubElValByNumber(0x0028,0x0008);
105 if (str_nbFrames == "UNFOUND" ) {
108 nbFrames = atoi(str_nbFrames.c_str() );
111 // Nombre de Bits Alloues
112 str_nb=GetPubElValByNumber(0x0028,0x0100);
114 if (str_nb == "UNFOUND" ) {
117 nb = atoi(str_nb.c_str() );
120 // Nombre de Bits Utilises
121 str_nbu=GetPubElValByNumber(0x0028,0x0101);
123 if (str_nbu == "UNFOUND" ) {
126 nbu = atoi(str_nbu.c_str() );
129 // Position du Bit de Poids Fort
130 str_highBit=GetPubElValByNumber(0x0028,0x0102);
132 if (str_highBit == "UNFOUND" ) {
135 highBit = atoi(str_highBit.c_str() );
139 str_signe=GetPubElValByNumber(0x0028,0x0103);
141 if (str_signe == "UNFOUND" ) {
144 signe = atoi(str_signe.c_str() );
147 // Longueur en Octets des Pixels a lire
148 size_t lgrTotale = nbFrames*nbLignes*nbCol*(nb/8);
150 //Pixels = (char *) g_malloc(lgrTotale);
151 Pixels = (char *) malloc(lgrTotale);
153 GetPixels(lgrTotale, Pixels);
155 // On remet les Octets dans le bon ordre si besoin est
157 int _sw = GetSwapCode();
159 _Swap (Pixels, _sw, lgrTotale, nb);
162 // On remet les Bits des Octets dans le bon ordre si besoin est
164 // ATTENTION : Jamais confronté a des pixels stockes sur 32 bits
165 // avec moins de 32 bits utilises
166 // et dont le bit de poids fort ne serait pas la ou on l'attend ...
167 // --> ne marchera pas dans ce cas
169 mask = mask >> (nb-nbu);
170 int l=(int)lgrTotale/(nb/8);
171 unsigned short *deb = (unsigned short *)Pixels;
172 for(int i=0;i<l;i++) {
173 *deb = (*deb >> (nbu-highBit-1)) & mask;
178 printf ("on est sorti\n");
180 // VOIR s'il ne faudrait pas l'affecter à un champ du dcmHeader
186 /////////////////////////////////////////////////////////////////
189 * \brief amene en mémoire dans une zone précisee par l'utilisateur
190 * \les Pixels d'une image NON COMPRESSEE
191 * \Aucun test n'est fait pour le moment sur le caractere compresse ou non de l'image
198 int gdcmFile::PutImageDataHere (void* destination, size_t MaxSize) {
200 void * Pixels = destination; // pour garder le code identique avec GetImageData
203 int nbFrames, nb, nbu, highBit, signe;
204 string str_nbFrames, str_nb, str_nbu, str_highBit, str_signe;
206 unsigned short int mask = 0xffff;
209 nbLignes=atoi(GetPubElValByNumber(0x0028,0x0010).c_str());
210 // Nombre de Colonnes
211 nbCol =atoi(GetPubElValByNumber(0x0028,0x0011).c_str());
214 str_nbFrames=GetPubElValByNumber(0x0028,0x0008);
217 if (str_nbFrames == "UNFOUND" ) {
220 nbFrames = atoi(str_nbFrames.c_str() );
223 // Nombre de Bits Alloues
224 str_nb=GetPubElValByNumber(0x0028,0x0100);
226 if (str_nb == "UNFOUND" ) {
229 nb = atoi(str_nb.c_str() );
232 // Nombre de Bits Utilises
233 str_nbu=GetPubElValByNumber(0x0028,0x0101);
235 if (str_nbu == "UNFOUND" ) {
238 nbu = atoi(str_nbu.c_str() );
241 // Position du Bit de Poids Fort
242 str_highBit=GetPubElValByNumber(0x0028,0x0102);
244 if (str_highBit == "UNFOUND" ) {
247 highBit = atoi(str_highBit.c_str() );
251 str_signe=GetPubElValByNumber(0x0028,0x0103);
253 if (str_signe == "UNFOUND" ) {
256 signe = atoi(str_signe.c_str() );
259 // Longueur en Octets des Pixels a lire
260 size_t lgrTotale = nbFrames*nbLignes*nbCol*(nb/8);
262 // si lgrTotale < MaxSize ==> Gros pb . A VOIR
264 lgrTotale = MaxSize; // pour garder le code identique avec GetImageData
265 //Pixels = (char *) malloc(lgrTotale); // pour garder le code identique avec GetImageData
267 GetPixels(lgrTotale, Pixels);
269 // On remet les Octets dans le bon ordre si besoin est
271 int _sw = GetSwapCode();
273 _Swap (Pixels, _sw, lgrTotale, nb);
276 // On remet les Bits des Octets dans le bon ordre si besoin est
278 // ATTENTION : Jamais confronté a des pixels stockes sur 32 bits
279 // avec moins de 32 bits utilises
280 // et dont le bit de poids fort ne serait pas la ou on l'attend ...
281 // --> ne marchera pas dans ce cas
283 mask = mask >> (nb-nbu);
284 int l=(int)lgrTotale/(nb/8);
285 unsigned short *deb = (unsigned short *)Pixels;
286 for(int i=0;i<l;i++) {
287 *deb = (*deb >> (nbu-highBit-1)) & mask;
292 printf ("on est sorti\n");
294 // VOIR s'il ne faudrait pas l'affecter à un champ du dcmHeader
296 //return (Pixels); // pour garder le code identique avec GetImageData
301 // Je laisse le code integral, au cas ça puisse etre reutilise ailleurs
304 static void _Swap(void* im, int swap, int lgr, int nb) {
323 ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
324 | ((((unsigned short int*)im)[i])<<8);
328 printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
340 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 4321 */
341 fort =((unsigned long int*)im)[i]>>16;
342 fort= (fort>>8) | (fort<<8);
343 faible=(faible>>8) | (faible<<8);
345 ((unsigned long int*)im)[i]=(s32<<16)|fort;
351 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 2143 */
352 fort=((unsigned long int*)im)[i]>>16;
353 fort= (fort>>8) | (fort<<8);
354 faible=(faible>>8) | (faible<<8);
356 ((unsigned long int*)im)[i]=(s32<<16)|faible;
362 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 3412 */
363 fort=((unsigned long int*)im)[i]>>16;
365 ((unsigned long int*)im)[i]=(s32<<16)|fort;
370 printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);