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); // A REMETTRE
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
187 // Je laisse le code integral, au cas ça puisse etre reutilise ailleurs
190 static void _Swap(void* im, int swap, int lgr, int nb) {
209 ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
210 | ((((unsigned short int*)im)[i])<<8);
214 printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
226 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 4321 */
227 fort =((unsigned long int*)im)[i]>>16;
228 fort= (fort>>8) | (fort<<8);
229 faible=(faible>>8) | (faible<<8);
231 ((unsigned long int*)im)[i]=(s32<<16)|fort;
237 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 2143 */
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)|faible;
248 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 3412 */
249 fort=((unsigned long int*)im)[i]>>16;
251 ((unsigned long int*)im)[i]=(s32<<16)|fort;
256 printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);