3 //This is needed when compiling in debug mode
5 // 'type' : forcing value to bool 'true' or 'false' (performance warning)
6 //#pragma warning ( disable : 4800 )
7 // 'identifier' : class 'type' needs to have dll-interface to be used by
8 // clients of class 'type2'
9 #pragma warning ( disable : 4251 )
10 // 'identifier' : identifier was truncated to 'number' characters in the
12 #pragma warning ( disable : 4786 )
17 #include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess
19 #define str2num(str, typeNum) *((typeNum *)(str))
21 /////////////////////////////////////////////////////////////////
24 * \brief Constructor dedicated to writing a new DICOMV3 part10 compliant
25 * file (see SetFileName, SetDcmTag and Write)
26 * Opens (in read only and when possible) an existing file and checks
27 * for DICOM compliance. Returns NULL on failure.
28 * \Note the in-memory representation of all available tags found in
29 * the DICOM header is post-poned to first header information access.
30 * This avoid a double parsing of public part of the header when
31 * one sets an a posteriori shadow dictionary (efficiency can be
32 * seen as a side effect).
34 * @param filename file to be opened for parsing
39 gdcmFile::gdcmFile(std::string & filename)
40 :gdcmHeader(filename.c_str())
42 SetPixelDataSizeFromHeader();
45 gdcmFile::gdcmFile(const char * filename)
48 SetPixelDataSizeFromHeader();
53 * \brief calcule la longueur (in bytes) A ALLOUER pour recevoir les
55 * ou DES images dans le cas d'un multiframe
56 * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels
57 * (dans le cas d'images compressees, elle n'a pas de sens).
59 * @return longueur a allouer
61 void gdcmFile::SetPixelDataSizeFromHeader(void) {
65 str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
66 if (str_nb == GDCM_UNFOUND ) {
69 nb = atoi(str_nb.c_str() );
72 lgrTotale = GetXSize() * GetYSize() * GetZSize() * (nb/8)* GetSamplesPerPixel();
74 std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
75 if ( str_PhotometricInterpretation == "PALETTE COLOR "
76 || str_PhotometricInterpretation == "YBR_FULL") { // --> some more to be added !!
80 // remaining to check :
81 // str_PhotometricInterpretation == "YBR_FULL"
82 // str_PhotometricInterpretation == "YBR_FULL_422" (no LUT, no Palette)
83 // -->and some more !!
86 /////////////////////////////////////////////////////////////////
89 * \brief Returns the size (in bytes) of required memory to hold
90 * the pixel data represented in this file.
91 * @return The size of pixel data in bytes.
93 size_t gdcmFile::GetImageDataSize(void) {
98 /////////////////////////////////////////////////////////////////
101 * \brief Parse pixel data from disk and *prints* the result
102 * \ For multi-fragment Jpeg/Rle files checking purpose *only*
103 * \ Allows to 'see' if the file *does* conform
104 * \ (some of them do not)
105 * \ with Dicom Part 3, Annex A (PS 3.5-2003, page 58, page 85)
108 bool gdcmFile::ParsePixelData(void) {
113 if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
119 IsImplicitVRLittleEndianTransferSyntax() ||
120 IsExplicitVRLittleEndianTransferSyntax() ||
121 IsExplicitVRBigEndianTransferSyntax() ||
122 IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
124 printf ("gdcmFile::ParsePixelData : non JPEG/RLE File\n");
129 std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
130 if (str_nb == GDCM_UNFOUND ) {
133 nb = atoi(str_nb.c_str() );
134 if (nb == 12) nb =16;
138 //int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel();
139 int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
141 printf ("Checking the Dicom-Jpeg/RLE Pixels\n");
143 guint16 ItemTagGr,ItemTagEl;
146 char * destination = NULL;
148 // ------------------------------- for Parsing : Position on begining of Jpeg/RLE Pixels
150 if( !IsRLELossLessTransferSyntax()) {
154 std::cout << "JPEG image" << std::endl;
156 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Basic Offset Table Item Tag Gr
157 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Basic Offset Table Item Tag El
159 ItemTagGr=SwapShort(ItemTagGr);
160 ItemTagEl=SwapShort(ItemTagEl);
162 printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
163 ftellRes,ItemTagGr,ItemTagEl );
167 ln=SwapLong(ln); // Basic Offset Table Item Lentgh
168 printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n",
171 // What is it used for ??
172 char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
173 fread(BasicOffsetTableItemValue,ln,1,fp);
175 for (int i=0;i<ln;i+=4){
176 a=str2num(&BasicOffsetTableItemValue[i],guint32);
177 printf(" x(%08x) %d\n",a,a);
182 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
183 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
185 ItemTagGr=SwapShort(ItemTagGr);
186 ItemTagEl=SwapShort(ItemTagEl);
188 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
189 ftellRes,ItemTagGr,ItemTagEl );
191 while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) { // Parse fragments
196 ln=SwapLong(ln); // length
197 printf(" at %x : fragment length %d x(%08x)\n",
200 // destination += taille * nBytes; // location in user's memory
201 //printf (" Destination will be x(%x) = %d \n",
202 // destination,destination );
204 // ------------------------
205 fseek(fp,ln,SEEK_CUR); // skipping (not reading) fragment pixels
206 // ------------------------
209 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
210 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
212 ItemTagGr=SwapShort(ItemTagGr);
213 ItemTagEl=SwapShort(ItemTagEl);
215 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
216 ftellRes,ItemTagGr,ItemTagEl );
223 std::cout << "RLE image" << std::endl;
224 long RleSegmentLength[15],fragmentLength;
225 guint32 nbRleSegments;
226 guint32 RleSegmentOffsetTable[15];
228 // Basic Offset Table with Item Value
230 fread(&ItemTagGr,2,1,fp); // Reading (fffe):Basic Offset Table Item Tag Gr
231 fread(&ItemTagEl,2,1,fp); // Reading (e000):Basic Offset Table Item Tag El
233 ItemTagGr=SwapShort(ItemTagGr);
234 ItemTagEl=SwapShort(ItemTagEl);
236 printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n",
237 ftellRes,ItemTagGr,ItemTagEl );
242 ln=SwapLong(ln); // Basic Offset Table Item Lentgh
243 printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n",
246 // What is it used for ??
247 char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
248 fread(BasicOffsetTableItemValue,ln,1,fp);
250 for (int i=0;i<ln;i+=4){
251 a=str2num(&BasicOffsetTableItemValue[i],guint32);
252 printf(" x(%08x) %d\n",a,a);
257 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
258 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
260 ItemTagGr=SwapShort(ItemTagGr);
261 ItemTagEl=SwapShort(ItemTagEl);
263 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
264 ftellRes,ItemTagGr,ItemTagEl );
266 // while 'Sequence Delimiter Item' (fffe,e0dd) not found
267 while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
268 // Parse fragments of the current Fragment (Frame)
270 fread(&fragmentLength,4,1,fp);
272 fragmentLength=SwapLong(fragmentLength); // length
273 printf(" at %x : 'fragment' length %d x(%08x)\n",
274 ftellRes, fragmentLength,fragmentLength);
276 // destination += taille * nBytes; // location in user's memory
277 // printf (" Destination will be x(%x) = %d \n",
278 // destination,destination );
280 //------------------ scanning (not reading) fragment pixels
282 fread(&nbRleSegments,4,1,fp); // Reading : Number of RLE Segments
284 nbRleSegments=SwapLong(nbRleSegments);
285 printf(" Nb of RLE Segments : %d\n",nbRleSegments);
287 for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
289 fread(&RleSegmentOffsetTable[k],4,1,fp);
291 RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
292 printf(" at : %x Offset Segment %d : %d (%x)\n",
293 ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
295 if (nbRleSegments>1) {
296 for(int k=1; k<=nbRleSegments-1; k++) { // skipping (not reading) RLE Segments
297 RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k];
299 printf (" Segment %d : Length = %d Start at %x\n",
300 k,RleSegmentLength[k], ftellRes);
301 fseek(fp,RleSegmentLength[k],SEEK_CUR);
304 RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments] ;
305 // TODO : Check the value
307 printf (" Segment %d : Length = %d Start at %x\n",
308 nbRleSegments,RleSegmentLength[nbRleSegments],ftellRes);
310 fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR);
312 // ------------------ end of scanning fragment pixels
315 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
316 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
318 ItemTagGr=SwapShort(ItemTagGr);
319 ItemTagEl=SwapShort(ItemTagEl);
321 printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n",
322 ftellRes,ItemTagGr,ItemTagEl );
328 /////////////////////////////////////////////////////////////////
331 * \brief Read pixel data from disk (optionaly decompressing) into the
332 * caller specified memory location.
333 * @param destination where the pixel data should be stored.
336 bool gdcmFile::ReadPixelData(void* destination) {
341 if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
346 // ------------------------- Uncompressed File
349 IsImplicitVRLittleEndianTransferSyntax() ||
350 IsExplicitVRLittleEndianTransferSyntax() ||
351 IsExplicitVRBigEndianTransferSyntax() ||
352 IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
354 size_t ItemRead = fread(destination, lgrTotale, 1, fp);
355 if ( ItemRead != 1 ) {
364 // ------------------------ Compressed File .
367 std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
368 if (str_nb == GDCM_UNFOUND ) {
371 nb = atoi(str_nb.c_str() );
372 if (nb == 12) nb =16;
376 //int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel();
377 int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
380 // ------------------------------- JPEG LossLess : call to Jpeg Libido
382 if (IsJPEGLossless() && GetZSize() == 1) {
384 int ln; // Position on begining of Jpeg Pixels
385 fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : Basic Offset Table Item
388 ln=SwapLong(ln); // Item length
389 fseek(fp,ln,SEEK_CUR); // skipping Basic Offset Table ('ln' bytes)
390 fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : First fragment Item Tag
391 fread(&ln,4,1,fp); // First fragment length (just to know)
395 ClbJpeg* jpg = _IdDcmJpegRead(fp); // TODO : find a 'full' one.
396 // (We use the LibIDO one :-(
401 int * dataJpg = jpg->DataImg;
406 unsigned short *dest = (unsigned short *)destination;
407 for (int i=0; i<taille; i++) {
408 *((unsigned char *)dest+i) = *(dataJpg +i);
415 unsigned short *dest = (unsigned short *)destination;
416 for (int i=0; i<taille; i++) {
417 *((unsigned short *)dest+i) = *(dataJpg +i);
422 _IdDcmJpegFree (jpg);
426 // ------------------------------- RLE
428 if (gdcmHeader::IsRLELossLessTransferSyntax()) {
429 int res = (bool)gdcm_read_RLE_file (destination);
433 // ------------------------------- JPEG Lossy : call to IJG 6b
435 long fragmentBegining; // for ftell, fseek
436 bool b = gdcmHeader::IsJPEG2000();
439 guint16 ItemTagGr,ItemTagEl;
440 int ln; // Position on begining of Jpeg Pixels
442 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
443 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
445 ItemTagGr=SwapShort(ItemTagGr);
446 ItemTagEl=SwapShort(ItemTagEl);
450 ln=SwapLong(ln); // Basic Offset Table Item length
453 // What is it used for ?!?
454 char *BasicOffsetTableItemValue = (char *)malloc(ln+1);
455 fread(BasicOffsetTableItemValue,ln,1,fp);
458 // first Fragment initialisation
459 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
460 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
462 ItemTagGr=SwapShort(ItemTagGr);
463 ItemTagEl=SwapShort(ItemTagEl);
466 // parsing fragments until Sequence Delim. Tag found
467 //unsigned short *dest = (unsigned short *)destination;
469 while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
472 ln=SwapLong(ln); // Fragment Item length
474 // FIXME : multi fragments
475 fragmentBegining=ftell(fp);
479 res = (bool)gdcm_read_JPEG2000_file (destination); // Reading Fragment pixels
481 else if (IsJPEGLossless()) { // ------------- call to LibIDO Jpeg for each Frame/fragment
483 // Warning : Works only if there is one fragment per frame
484 // (Or a single fragment for the multiframe file)
485 ClbJpeg* jpg = _IdDcmJpegRead(fp); // TODO : find a 'full' one.
486 // (We use the LibIDO one :-(
491 int * dataJpg = jpg->DataImg;
492 unsigned short *dest = (unsigned short *)destination;
496 for (int i=0; i<taille; i++) {
497 *((unsigned char *)dest+i) = *(dataJpg +i);
504 for (int i=0; i<taille; i++) {
505 *((unsigned short *)dest+i) = *(dataJpg +i);
510 _IdDcmJpegFree (jpg);
512 } // ------------------------------------- endif (IsJPEGLossless())
515 if (GetBitsStored() == 8) {
516 res = (bool)gdcm_read_JPEG_file (destination); // Reading Fragment pixels
518 res = (bool)gdcm_read_JPEG_file12 (destination);// Reading Fragment pixels
523 // FIXME : will work only when each fragment corresponds to a Frame :-(
525 destination = (char *)destination + taille * nBytes; // location in user's memory
526 // for next fragment (if any)
527 // TODO : find a suitable file (multifragment/single Frame Jpeg file) to check
529 fseek(fp,fragmentBegining,SEEK_SET); // To be sure we start
530 fseek(fp,ln,SEEK_CUR); // at the begining of next fragment
532 ItemTagGr = ItemTagEl =0;
533 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
534 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
536 ItemTagGr=SwapShort(ItemTagGr);
537 ItemTagEl=SwapShort(ItemTagEl);
540 //(char *) destination += taille * nBytes;
541 //std::cout << "destination" << destination << std::endl;
549 * \brief Allocates necessary memory, copies the pixel data
550 * (image[s]/volume[s]) to newly allocated zone.
551 * @return Pointer to newly allocated pixel data.
552 * \ NULL if alloc fails
554 void * gdcmFile::GetImageData (void) {
555 PixelData = (void *) malloc(lgrTotale);
557 GetImageDataIntoVector(PixelData, lgrTotale);
563 * \brief Copies at most MaxSize bytes of pixel data to caller's
565 * @param destination Address (in caller's memory space) at which the
566 * pixel data should be copied
567 * @param MaxSize Maximum number of bytes to be copied. When MaxSize
568 * is not sufficient to hold the pixel data the copy is not
569 * executed (i.e. no partial copy).
570 * @return On success, the number of bytes actually copied. Zero on
571 * failure e.g. MaxSize is lower than necessary.
574 size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
576 int nb, nbu, highBit, signe;
577 std::string str_nbFrames, str_nb, str_nbu, str_highBit, str_signe;
579 if ( lgrTotale > MaxSize ) {
580 dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: pixel data bigger"
581 "than caller's expected MaxSize");
585 (void)ReadPixelData(destination);
587 // Nombre de Bits Alloues pour le stockage d'un Pixel
588 str_nb = GetPubElValByNumber(0x0028,0x0100);
589 if (str_nb == GDCM_UNFOUND ) {
592 nb = atoi(str_nb.c_str() );
595 // Nombre de Bits Utilises
596 str_nbu=GetPubElValByNumber(0x0028,0x0101);
597 if (str_nbu == GDCM_UNFOUND ) {
600 nbu = atoi(str_nbu.c_str() );
603 // Position du Bit de Poids Fort
604 str_highBit=GetPubElValByNumber(0x0028,0x0102);
605 if (str_highBit == GDCM_UNFOUND ) {
608 highBit = atoi(str_highBit.c_str() );
612 str_signe=GetPubElValByNumber(0x0028,0x0103);
613 if (str_signe == GDCM_UNFOUND ) {
616 signe = atoi(str_signe.c_str() );
619 // re arange bytes inside the integer
621 SwapZone(destination, GetSwapCode(), lgrTotale, nb);
623 // re arange bits inside the bytes
625 int l = (int)lgrTotale / (nb/8);
627 guint16 mask = 0xffff;
628 mask = mask >> (nb-nbu);
629 guint16 *deb = (guint16 *)destination;
630 for(int i = 0; i<l; i++) {
631 *deb = (*deb >> (nbu-highBit-1)) & mask;
634 } else if (nb == 32 ) {
635 guint32 mask = 0xffffffff;
636 mask = mask >> (nb-nbu);
637 guint32 *deb = (guint32 *)destination;
638 for(int i = 0; i<l; i++) {
639 *deb = (*deb >> (nbu-highBit-1)) & mask;
643 dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: wierd image");
648 // Try to deal with the color
649 // --------------------------
651 std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
653 if ( (str_PhotometricInterpretation == "MONOCHROME1 ")
654 || (str_PhotometricInterpretation == "MONOCHROME2 ")
655 || (str_PhotometricInterpretation == "RGB")) {
659 switch ( GetPlanarConfiguration() ) {
661 // Pixels are already RGB
665 // need to make RGB Pixels from Planes R,G,B
667 int l = lgrTotale/3 ;
669 char * a = (char *)destination;
672 char * newDest = (char*) malloc(lgrTotale);
674 // any trick not to have to allocate temporary buffer is welcome ...
676 for (int j=0;j<l; j++) {
681 memmove(destination,newDest,lgrTotale);
683 // now, it's an RGB image
684 std::string spp = "3";
685 gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
686 std::string rgb="RGB";
687 gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
692 // from Lut R + Lut G + Lut B
694 // we no longer use gdcmHeader::GetLUTRGB
695 // since a lot of images have wrong info
696 // in the Lookup Table Descriptors (0028,1101),...
698 unsigned char *lutR =(unsigned char *)GetPubElValVoidAreaByNumber(0x0028,0x1201);
699 unsigned char *lutG =(unsigned char *)GetPubElValVoidAreaByNumber(0x0028,0x1202);
700 unsigned char *lutB =(unsigned char *)GetPubElValVoidAreaByNumber(0x0028,0x1203);
702 if (lutR && lutG && lutB ) { // need to make RGB Pixels
704 // and Lut R,Lut G,Lut B
705 unsigned char * newDest = (unsigned char*) malloc(lgrTotale);
707 memmove(newDest, destination, l);// move Gray pixels to temp area
709 unsigned char * x = newDest;
710 unsigned char * a = (unsigned char *)destination;
712 for (int i=0;i<l; i++) {
713 j=newDest[i]*2; // Who can explain *why* we have to skip bytes
720 // now, it's an RGB image
721 std::string spp = "3";
722 gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
723 std::string rgb="RGB";
724 gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
726 } else { // need to make RGB Pixels (?)
727 // from grey Pixels (?!)
728 // and Gray Lut (!?!)
729 unsigned char *lutGray =(unsigned char *)GetPubElValVoidAreaByNumber(0x0028,0x1200);
730 // Well . I'll wait till I find such an image
740 // Je laisse le code integral, au cas ça puisse etre reutilise ailleurs
745 * \brief Swap the bytes, according to swap code.
746 * \warning not end user intended
747 * @param im area to deal with
748 * @param swap swap code
749 * @param lgr Area Length
750 * @param nb Pixels Bit number
753 void gdcmFile::SwapZone(void* im, int swap, int lgr, int nb) {
771 ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
772 | ((((unsigned short int*)im)[i])<<8);
776 printf("valeur de SWAP (16 bits) not allowed : %d\n", swap);
787 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 4321 */
788 fort =((unsigned long int*)im)[i]>>16;
789 fort= (fort>>8) | (fort<<8);
790 faible=(faible>>8) | (faible<<8);
792 ((unsigned long int*)im)[i]=(s32<<16)|fort;
798 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 2143 */
799 fort=((unsigned long int*)im)[i]>>16;
800 fort= (fort>>8) | (fort<<8);
801 faible=(faible>>8) | (faible<<8);
803 ((unsigned long int*)im)[i]=(s32<<16)|faible;
809 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 3412 */
810 fort=((unsigned long int*)im)[i]>>16;
812 ((unsigned long int*)im)[i]=(s32<<16)|fort;
817 printf(" SWAP value (32 bits) not allowed : %d\n", swap);
822 /////////////////////////////////////////////////////////////////
826 * \warning doit-etre etre publique ?
827 * TODO : y a-t-il un inconvenient à fusioner ces 2 fonctions
830 * @param ExpectedSize
832 * @return integer acts as a boolean
834 int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) {
835 SetImageDataSize(ExpectedSize);
837 lgrTotale = ExpectedSize;
842 /////////////////////////////////////////////////////////////////
845 * \brief Sets the Pixel Area size in the Header
846 * --> not-for-rats function
848 * \warning WARNING doit-etre etre publique ?
849 * TODO : y aurait il un inconvenient à fusionner ces 2 fonctions
851 * @param ImageDataSize new Pixel Area Size
852 * warning : nothing else is checked
855 void gdcmFile::SetImageDataSize(size_t ImageDataSize) {
856 std::string content1;
858 // Assumes ElValue (0x7fe0, 0x0010) exists ...
859 sprintf(car,"%d",ImageDataSize);
861 gdcmElValue*a = GetElValueByNumber(0x7fe0, 0x0010);
862 a->SetLength(ImageDataSize);
865 sprintf(car,"%d",ImageDataSize);
867 SetPubElValByNumber(content1, 0x7fe0, 0x0000);
871 /////////////////////////////////////////////////////////////////
874 * \brief Ecrit sur disque les pixels d'UNE image
875 * Aucun test n'est fait sur l'"Endiannerie" du processeur.
876 * Ca sera à l'utilisateur d'appeler son Reader correctement
877 * (Equivalent a IdImaWriteRawFile)
883 int gdcmFile::WriteRawData (std::string fileName) {
885 fp1 = fopen(fileName.c_str(),"wb");
887 printf("Echec ouverture (ecriture) Fichier [%s] \n",fileName.c_str());
890 fwrite (PixelData,lgrTotale, 1, fp1);
895 /////////////////////////////////////////////////////////////////
898 * \brief Ecrit sur disque UNE image Dicom
899 * Aucun test n'est fait sur l'"Endiannerie" du processeur.
900 * Ca fonctionnera correctement (?) sur processeur Intel
901 * (Equivalent a IdDcmWrite)
904 * @return int acts as a boolean
907 int gdcmFile::WriteDcmImplVR (std::string fileName) {
908 return WriteBase(fileName, ImplicitVR);
911 /////////////////////////////////////////////////////////////////
916 * @return int acts as a boolean
919 int gdcmFile::WriteDcmImplVR (const char* fileName) {
920 return WriteDcmImplVR (std::string (fileName));
923 /////////////////////////////////////////////////////////////////
928 * @return int acts as a boolean
931 int gdcmFile::WriteDcmExplVR (std::string fileName) {
932 return WriteBase(fileName, ExplicitVR);
935 /////////////////////////////////////////////////////////////////
938 * \brief Ecrit au format ACR-NEMA sur disque l'entete et les pixels
939 * (a l'attention des logiciels cliniques
940 * qui ne prennent en entrée QUE des images ACR ...
941 * \warning si un header DICOM est fourni en entree,
942 * les groupes < 0x0008 et les groupes impairs sont ignores)
943 * \warning Aucun test n'est fait sur l'"Endiannerie" du processeur.
944 * Ca fonctionnera correctement (?) sur processeur Intel
945 * (Equivalent a IdDcmWrite)
948 * @return int acts as a boolean
951 int gdcmFile::WriteAcr (std::string fileName) {
952 return WriteBase(fileName, ACR);
955 /////////////////////////////////////////////////////////////////
962 * @return int acts as a boolean
964 int gdcmFile::WriteBase (std::string FileName, FileType type) {
967 fp1 = fopen(FileName.c_str(),"wb");
969 printf("Echec ouverture (ecriture) Fichier [%s] \n",FileName.c_str());
973 if ( (type == ImplicitVR) || (type == ExplicitVR) ) {
975 // writing Dicom File Preamble
976 filePreamble=(char*)calloc(128,1);
977 fwrite(filePreamble,128,1,fp1);
978 fwrite("DICM",4,1,fp1);
981 // --------------------------------------------------------------
982 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
984 // if recognition code tells us we dealt with a LibIDO image
985 // we reproduce on disk the switch between lineNumber and columnNumber
986 // just before writting ...
988 std::string rows, columns;
989 if ( filetype == ACR_LIBIDO){
990 rows = GetPubElValByNumber(0x0028, 0x0010);
991 columns = GetPubElValByNumber(0x0028, 0x0011);
992 SetPubElValByNumber(columns, 0x0028, 0x0010);
993 SetPubElValByNumber(rows , 0x0028, 0x0011);
995 // ----------------- End of Special Patch ----------------
997 gdcmHeader::Write(fp1, type);
999 // --------------------------------------------------------------
1000 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
1002 // ...and we restore the Header to be Dicom Compliant again
1003 // just after writting
1005 if (filetype == ACR_LIBIDO){
1006 SetPubElValByNumber(rows , 0x0028, 0x0010);
1007 SetPubElValByNumber(columns, 0x0028, 0x0011);
1009 // ----------------- End of Special Patch ----------------
1011 fwrite(PixelData, lgrTotale, 1, fp1);