5 #include "jpeg/ljpg/jpegless.h"
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).
20 * @param filename file to be opened for parsing
25 gdcmFile::gdcmFile(std::string & filename)
26 :gdcmHeader(filename.c_str())
29 SetPixelDataSizeFromHeader();
32 gdcmFile::gdcmFile(const char * filename)
36 SetPixelDataSizeFromHeader();
41 * \brief calcule la longueur (in bytes) A ALLOUER pour recevoir les
42 * pixels de l'image ou DES images dans le cas d'un multiframe
44 * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels
45 * (dans le cas d'images compressees, elle n'a pas de sens).
47 * @return longueur a allouer
49 void gdcmFile::SetPixelDataSizeFromHeader(void) {
52 str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
53 if (str_nb == GDCM_UNFOUND ) {
56 nb = atoi(str_nb.c_str() );
59 lgrTotale = lgrTotaleRaw = GetXSize() * GetYSize() * GetZSize()
60 * (nb/8)* GetSamplesPerPixel();
61 std::string str_PhotometricInterpretation =
62 gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
64 /*if ( str_PhotometricInterpretation == "PALETTE COLOR " )*/
65 // pb when undealt Segmented Palette Color
72 // see PS 3.3-2003 : C.7.6.3.2.1
82 // YBR_FULL_422 (no LUT, no Palette)
88 // ex : gdcm-US-ALOKA-16.dcm
89 // 0028|1221 [OW] [Segmented Red Palette Color Lookup Table Data]
90 // 0028|1222 [OW] [Segmented Green Palette Color Lookup Table Data]
91 // 0028|1223 [OW] [Segmented Blue Palette Color Lookup Table Data]
93 // ex : OT-PAL-8-face.dcm
94 // 0028|1201 [US] [Red Palette Color Lookup Table Data]
95 // 0028|1202 [US] [Green Palette Color Lookup Table Data]
96 // 0028|1203 [US] [Blue Palette Color Lookup Table Data]
99 /////////////////////////////////////////////////////////////////
102 * \brief Returns the size (in bytes) of required memory to hold
103 * \ the pixel data represented in this file, when user DOESN'T want
104 * \ to get RGB pixels image when it's stored as a PALETTE COLOR image
105 * \ - the (vtk) user is supposed to know how deal with LUTs -
106 * \ warning to be used with GetImagePixelsRaw()
107 * @return The size of pixel data in bytes.
110 size_t gdcmFile::GetImageDataSizeRaw(void) {
111 return (lgrTotaleRaw);
114 /////////////////////////////////////////////////////////////////
117 * \brief Returns the size (in bytes) of required memory to hold
118 * the pixel data represented in this file.
119 * @return The size of pixel data in bytes.
122 size_t gdcmFile::GetImageDataSize(void) {
127 /////////////////////////////////////////////////////////////////
130 * \brief Read pixel data from disk (optionaly decompressing) into the
131 * caller specified memory location.
132 * @param destination where the pixel data should be stored.
135 bool gdcmFile::ReadPixelData(void* destination) {
140 if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) {
146 // ---------------------- Compacted File (12 Bits Per Pixel)
148 /* unpack 12 Bits pixels into 16 Bits pixels */
149 /* 2 pixels 12bit = [0xABCDEF] */
150 /* 2 pixels 16bit = [0x0ABD] + [0x0FCE] */
152 if (GetBitsAllocated()==12) {
153 int nbPixels = GetXSize()*GetYSize();
154 unsigned char b0, b1, b2;
156 unsigned short int* pdestination = (unsigned short int*)destination;
157 for(int p=0;p<nbPixels;p+=2) {
161 //Two steps is necessary to please VC++
162 *pdestination++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f);
163 /* A */ /* B */ /* D */
164 *pdestination++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4);
165 /* F */ /* C */ /* E */
167 // Troubles expected on Big-Endian processors ?
172 // ---------------------- Uncompressed File
175 IsImplicitVRLittleEndianTransferSyntax() ||
176 IsExplicitVRLittleEndianTransferSyntax() ||
177 IsExplicitVRBigEndianTransferSyntax() ||
178 IsDeflatedExplicitVRLittleEndianTransferSyntax() ) {
180 size_t ItemRead = fread(destination, GetPixelAreaLength(), 1, fp);
182 if ( ItemRead != 1 ) {
191 // ---------------------- Run Length Encoding
193 if (gdcmHeader::IsRLELossLessTransferSyntax()) {
194 int res = (bool)gdcm_read_RLE_file (destination);
198 // --------------- SingleFrame/Multiframe JPEG Lossless/Lossy/2000
201 std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
202 if (str_nb == GDCM_UNFOUND ) {
205 nb = atoi(str_nb.c_str() );
206 if (nb == 12) nb =16; // ?? 12 should be ACR-NEMA only ?
210 int taille = GetXSize() * GetYSize() * GetSamplesPerPixel();
211 long fragmentBegining; // for ftell, fseek
213 bool jpg2000 = IsJPEG2000();
214 bool jpgLossless = IsJPEGLossless();
217 guint16 ItemTagGr,ItemTagEl;
220 // Position on begining of Jpeg Pixels
222 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
223 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
225 ItemTagGr=SwapShort(ItemTagGr);
226 ItemTagEl=SwapShort(ItemTagEl);
230 ln=SwapLong(ln); // Basic Offset Table Item length
233 // What is it used for ?!?
234 char *BasicOffsetTableItemValue = (char *)malloc(ln+1);
235 fread(BasicOffsetTableItemValue,ln,1,fp);
238 // first Fragment initialisation
239 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
240 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
242 ItemTagGr=SwapShort(ItemTagGr);
243 ItemTagEl=SwapShort(ItemTagEl);
246 // parsing fragments until Sequence Delim. Tag found
248 while ( ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) {
250 // --- for each Fragment
254 ln=SwapLong(ln); // Fragment Item length
256 fragmentBegining=ftell(fp);
258 if (jpg2000) { // JPEG 2000 : call to ???
260 res = (bool)gdcm_read_JPEG2000_file (destination); // Not Yet written
262 } // ------------------------------------- endif (JPEG2000)
264 else if (jpgLossless) { // JPEG LossLess : call to xmedcom JPEG
266 JPEGLosslessDecodeImage (fp, // Reading Fragment pixels
267 (unsigned short *)destination,
268 GetPixelSize()*8* GetSamplesPerPixel(),
270 res=1; // in order not to break the loop
272 } // ------------------------------------- endif (JPEGLossless)
274 else { // JPEG Lossy : call to IJG 6b
276 if (GetBitsStored() == 8) {
277 res = (bool)gdcm_read_JPEG_file (destination); // Reading Fragment pixels
279 res = (bool)gdcm_read_JPEG_file12 (destination);// Reading Fragment pixels
281 } // ------------------------------------- endif (JPEGLossy)
285 destination = (char *)destination + taille * nBytes; // location in user's memory
286 // for next fragment (if any)
288 fseek(fp,fragmentBegining,SEEK_SET); // To be sure we start
289 fseek(fp,ln,SEEK_CUR); // at the begining of next fragment
291 ItemTagGr = ItemTagEl =0;
292 fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr
293 fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El
295 ItemTagGr=SwapShort(ItemTagGr);
296 ItemTagEl=SwapShort(ItemTagEl);
299 } // endWhile parsing fragments until Sequence Delim. Tag found
306 * \brief Allocates necessary memory, copies the pixel data
307 * (image[s]/volume[s]) to newly allocated zone.
308 * Transforms YBR pixels into RGB pixels if any
309 Transforms 3 planes R, G, B into a single RGB Plane
310 Transforms single Grey plane + 3 Palettes into a RGB Plane
311 * @return Pointer to newly allocated pixel data.
312 * \ NULL if alloc fails
314 void * gdcmFile::GetImageData (void) {
315 PixelData = (void *) malloc(lgrTotale);
317 GetImageDataIntoVector(PixelData, lgrTotale);
323 * \brief Allocates necessary memory, copies the pixel data
324 * (image[s]/volume[s]) to newly allocated zone.
325 * Transforms YBR pixels into RGB pixels if any
326 Transforms 3 planes R, G, B into a single RGB Plane
327 DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
328 * @return Pointer to newly allocated pixel data.
329 * \ NULL if alloc fails
331 void * gdcmFile::GetImageDataRaw (void) {
333 lgrTotale /= 3; // TODO Let gdcmHeadar user a chance
334 // to get the right value
335 // Create a member lgrTotaleRaw ???
336 PixelData = (void *) malloc(lgrTotale);
338 GetImageDataIntoVectorRaw(PixelData, lgrTotale);
344 * \brief Copies at most MaxSize bytes of pixel data to caller's
346 * \warning This function was designed to avoid people that want to build
347 * a volume from an image stack to need first to get the image pixels
348 * and then move them to the volume area.
349 * It's absolutely useless for any VTK user since vtk chooses
350 * to invert the lines of an image, that is the last line comes first
351 * (for some axis related reasons?). Hence he will have
352 * to load the image line by line, starting from the end.
353 * VTK users have to call GetImageData
355 * @param destination Address (in caller's memory space) at which the
356 * pixel data should be copied
357 * @param MaxSize Maximum number of bytes to be copied. When MaxSize
358 * is not sufficient to hold the pixel data the copy is not
359 * executed (i.e. no partial copy).
360 * @return On success, the number of bytes actually copied. Zero on
361 * failure e.g. MaxSize is lower than necessary.
364 size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
366 size_t l = GetImageDataIntoVectorRaw (destination, MaxSize);
371 // from Lut R + Lut G + Lut B
373 unsigned char * newDest = (unsigned char *)malloc(lgrTotale);
374 unsigned char * a = (unsigned char *)destination;
375 unsigned char * lutRGBA = GetLUTRGBA();
377 int l = lgrTotaleRaw;
378 memmove(newDest, destination, l);// move Gray pixels to temp area
380 for (int i=0;i<l; i++) { // Build RGB Pixels
388 // now, it's an RGB image
389 // Lets's write it in the Header
391 // CreateOrReplaceIfExist ?
393 std::string spp = "3"; // Samples Per Pixel
394 gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
395 std::string rgb= "RGB "; // Photometric Interpretation
396 gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
397 std::string planConfig = "0"; // Planar Configuration
398 gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
402 // need to make RGB Pixels (?)
403 // from grey Pixels (?!)
404 // and Gray Lut (!?!)
405 // or Segmented xxx Palette Color Lookup Table Data and so on
407 // Well . I'll wait till I find such an image
409 // Oops! I get one (gdcm-US-ALOKA-16.dcm)
410 // No idea how to manage it
411 // It seems that *no Dicom Viewer* has any idea :-(
412 // Segmented xxx Palette Color are *more* than 65535 long ?!?
414 std::string rgb= "MONOCHROME1 "; // Photometric Interpretation
415 gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
419 // TODO : Drop Palette Color out of the Header?
427 * \brief Copies at most MaxSize bytes of pixel data to caller's
429 * \warning This function was designed to avoid people that want to build
430 * a volume from an image stack to need first to get the image pixels
431 * and then move them to the volume area.
432 * It's absolutely useless for any VTK user since vtk chooses
433 * to invert the lines of an image, that is the last line comes first
434 * (for some axis related reasons?). Hence he will have
435 * to load the image line by line, starting from the end.
436 * VTK users hace to call GetImageData
437 * \warning DOES NOT transform the Grey Plane + Palette Color (if any)
438 * into a single RGB Pixels Plane
439 * the (VTK) user will manage the palettes
441 * @param destination Address (in caller's memory space) at which the
442 * pixel data should be copied
443 * @param MaxSize Maximum number of bytes to be copied. When MaxSize
444 * is not sufficient to hold the pixel data the copy is not
445 * executed (i.e. no partial copy).
446 * @return On success, the number of bytes actually copied. Zero on
447 * failure e.g. MaxSize is lower than necessary.
450 size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
452 int nb, nbu, highBit, signe;
453 std::string str_nbFrames, str_nb, str_nbu, str_highBit, str_signe;
455 if ( lgrTotale > MaxSize ) {
456 dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: pixel data bigger"
457 "than caller's expected MaxSize");
461 (void)ReadPixelData(destination);
463 // Nombre de Bits Alloues pour le stockage d'un Pixel
464 str_nb = GetPubElValByNumber(0x0028,0x0100);
465 if (str_nb == GDCM_UNFOUND ) {
468 nb = atoi(str_nb.c_str() );
471 // Nombre de Bits Utilises
472 str_nbu=GetPubElValByNumber(0x0028,0x0101);
473 if (str_nbu == GDCM_UNFOUND ) {
476 nbu = atoi(str_nbu.c_str() );
479 // Position du Bit de Poids Fort
480 str_highBit=GetPubElValByNumber(0x0028,0x0102);
481 if (str_highBit == GDCM_UNFOUND ) {
484 highBit = atoi(str_highBit.c_str() );
489 str_signe=GetPubElValByNumber(0x0028,0x0103);
490 if (str_signe == GDCM_UNFOUND ) {
491 signe = 0; // default is unsigned
493 signe = atoi(str_signe.c_str() );
496 // re arange bytes inside the integer
498 SwapZone(destination, GetSwapCode(), lgrTotale, nb);
500 // to avoid pb with some xmedcon breakers images
501 if (nb==16 && nbu<nb && signe==0) {
502 int l = (int)lgrTotale / (nb/8);
503 guint16 *deb = (guint16 *)destination;
504 for(int i = 0; i<l; i++) {
511 // re arange bits inside the bytes
513 int l = (int)lgrTotale / (nb/8);
515 guint16 mask = 0xffff;
516 mask = mask >> (nb-nbu);
517 guint16 *deb = (guint16 *)destination;
518 for(int i = 0; i<l; i++) {
519 *deb = (*deb >> (nbu-highBit-1)) & mask;
522 } else if (nb == 32 ) {
523 guint32 mask = 0xffffffff;
524 mask = mask >> (nb-nbu);
525 guint32 *deb = (guint32 *)destination;
526 for(int i = 0; i<l; i++) {
527 *deb = (*deb >> (nbu-highBit-1)) & mask;
531 dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: wierd image");
536 // Just to 'see' what was actually read on disk :-(
537 // Some troubles expected
539 // f2 = fopen("SpuriousFile.raw","wb");
540 // fwrite(destination,lgrTotale,1,f2);
543 // Deal with the color
544 // -------------------
546 std::string str_PhotometricInterpretation =
547 gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
549 if ( (str_PhotometricInterpretation == "MONOCHROME1 ")
550 || (str_PhotometricInterpretation == "MONOCHROME2 ") ) {
554 // Planar configuration = 0 : Pixels are already RGB
555 // Planar configuration = 1 : 3 planes : R, G, B
556 // Planar configuration = 2 : 1 gray Plane + 3 LUT
558 // Well ... supposed to be !
559 // See US-PAL-8-10x-echo.dcm: PlanarConfiguration=0,
560 // PhotometricInterpretation=PALETTE COLOR
561 // and heuristic has to be found :-(
563 int planConf=GetPlanarConfiguration(); // 0028,0006
565 // Whatever Planar Configuration is,
566 // "PALETTE COLOR " implies that we deal with the palette.
567 if (str_PhotometricInterpretation == "PALETTE COLOR ")
572 // Pixels are already RGB
578 if (str_PhotometricInterpretation == "YBR_FULL") {
580 // Warning : YBR_FULL_422 acts as RGB
581 // : we need to make RGB Pixels from Planes Y,cB,cR
582 // see http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
583 // for code optimisation
585 // to see the tricks about YBR_FULL, YBR_FULL_422,
586 // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
587 // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
588 // and be *very* affraid
590 int l = GetXSize()*GetYSize();
591 int nbFrames = GetZSize();
593 unsigned char * newDest = (unsigned char*) malloc(lgrTotale);
594 unsigned char *x = newDest;
595 unsigned char * a = (unsigned char *)destination;
596 unsigned char * b = a + l;
597 unsigned char * c = b + l;
601 // TODO : Replace by the 'well known'
602 // integer computation counterpart
603 for (int i=0;i<nbFrames;i++) {
604 for (int j=0;j<l; j++) {
605 R= 1.164 *(*a-16) + 1.596 *(*c -128) + 0.5;
606 G= 1.164 *(*a-16) - 0.813 *(*c -128) - 0.392 *(*b -128) + 0.5;
607 B= 1.164 *(*a-16) + 2.017 *(*b -128) + 0.5;
612 if (R>255.0) R=255.0;
613 if (G>255.0) G=255.0;
614 if (B>255.0) B=255.0;
616 *(x++) = (unsigned char)R;
617 *(x++) = (unsigned char)G;
618 *(x++) = (unsigned char)B;
622 memmove(destination,newDest,lgrTotale);
627 // need to make RGB Pixels from R,G,B Planes
628 // (all the Frames at a time)
630 int l = GetXSize()*GetYSize()*GetZSize();
632 char * newDest = (char*) malloc(lgrTotale);
634 char * a = (char *)destination;
638 for (int j=0;j<l; j++) {
644 memmove(destination,newDest,lgrTotale);
652 // Palettes were found
653 // Let the user deal with them !
656 // now, it's an RGB image
657 // Lets's write it in the Header
659 // CreateOrReplaceIfExist ?
663 std::string spp = "3"; // Samples Per Pixel
664 gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
665 std::string rgb="RGB "; // Photometric Interpretation
666 gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
668 std::string planConfig = "0"; // Planar Configuration
669 gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
671 // TODO : Drop Palette Color out of the Header?
680 * \brief Swap the bytes, according to swap code.
681 * \warning not end user intended
682 * @param im area to deal with
683 * @param swap swap code
684 * @param lgr Area Length
685 * @param nb Pixels Bit number
688 void gdcmFile::SwapZone(void* im, int swap, int lgr, int nb) {
706 ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
707 | ((((unsigned short int*)im)[i])<<8);
711 printf("valeur de SWAP (16 bits) not allowed : %d\n", swap);
722 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 4321 */
723 fort =((unsigned long int*)im)[i]>>16;
724 fort= (fort>>8) | (fort<<8);
725 faible=(faible>>8) | (faible<<8);
727 ((unsigned long int*)im)[i]=(s32<<16)|fort;
733 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 2143 */
734 fort=((unsigned long int*)im)[i]>>16;
735 fort= (fort>>8) | (fort<<8);
736 faible=(faible>>8) | (faible<<8);
738 ((unsigned long int*)im)[i]=(s32<<16)|faible;
744 faible= ((unsigned long int*)im)[i]&0x0000ffff; /* 3412 */
745 fort=((unsigned long int*)im)[i]>>16;
747 ((unsigned long int*)im)[i]=(s32<<16)|fort;
752 printf(" SWAP value (32 bits) not allowed : %d\n", swap);
757 /////////////////////////////////////////////////////////////////
761 * \warning doit-etre etre publique ?
762 * TODO : y a-t-il un inconvenient à fusioner ces 2 fonctions
765 * @param ExpectedSize
767 * @return integer acts as a boolean
769 int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) {
770 SetImageDataSize(ExpectedSize);
772 lgrTotale = ExpectedSize;
777 /////////////////////////////////////////////////////////////////
780 * \brief Sets the Pixel Area size in the Header
781 * --> not-for-rats function
783 * \warning WARNING doit-etre etre publique ?
784 * TODO : y aurait il un inconvenient à fusionner ces 2 fonctions
786 * @param ImageDataSize new Pixel Area Size
787 * warning : nothing else is checked
790 void gdcmFile::SetImageDataSize(size_t ImageDataSize) {
791 std::string content1;
793 // Assumes ElValue (0x7fe0, 0x0010) exists ...
794 sprintf(car,"%d",ImageDataSize);
796 gdcmElValue*a = GetElValueByNumber(0x7fe0, 0x0010);
797 a->SetLength(ImageDataSize);
800 sprintf(car,"%d",ImageDataSize);
802 SetPubElValByNumber(content1, 0x7fe0, 0x0000);
806 /////////////////////////////////////////////////////////////////
809 * \brief Ecrit sur disque les pixels d'UNE image
810 * Aucun test n'est fait sur l'"Endiannerie" du processeur.
811 * Ca sera à l'utilisateur d'appeler son Reader correctement
812 * (Equivalent a IdImaWriteRawFile)
818 int gdcmFile::WriteRawData (std::string fileName) {
820 fp1 = fopen(fileName.c_str(),"wb");
822 printf("Echec ouverture (ecriture) Fichier [%s] \n",fileName.c_str());
825 fwrite (PixelData,lgrTotale, 1, fp1);
830 /////////////////////////////////////////////////////////////////
833 * \brief Ecrit sur disque UNE image Dicom
834 * Aucun test n'est fait sur l'"Endiannerie" du processeur.
835 * Ca fonctionnera correctement (?) sur processeur Intel
836 * (Equivalent a IdDcmWrite)
839 * @return int acts as a boolean
842 int gdcmFile::WriteDcmImplVR (std::string fileName) {
843 return WriteBase(fileName, ImplicitVR);
846 /////////////////////////////////////////////////////////////////
851 * @return int acts as a boolean
854 int gdcmFile::WriteDcmImplVR (const char* fileName) {
855 return WriteDcmImplVR (std::string (fileName));
858 /////////////////////////////////////////////////////////////////
863 * @return int acts as a boolean
866 int gdcmFile::WriteDcmExplVR (std::string fileName) {
867 return WriteBase(fileName, ExplicitVR);
870 /////////////////////////////////////////////////////////////////
873 * \brief Ecrit au format ACR-NEMA sur disque l'entete et les pixels
874 * (a l'attention des logiciels cliniques
875 * qui ne prennent en entrée QUE des images ACR ...
876 * \warning si un header DICOM est fourni en entree,
877 * les groupes < 0x0008 et les groupes impairs sont ignores)
878 * \warning Aucun test n'est fait sur l'"Endiannerie" du processeur.
879 * Ca fonctionnera correctement (?) sur processeur Intel
880 * (Equivalent a IdDcmWrite)
883 * @return int acts as a boolean
886 int gdcmFile::WriteAcr (std::string fileName) {
887 return WriteBase(fileName, ACR);
890 /////////////////////////////////////////////////////////////////
897 * @return int acts as a boolean
899 int gdcmFile::WriteBase (std::string FileName, FileType type) {
902 fp1 = fopen(FileName.c_str(),"wb");
904 printf("Echec ouverture (ecriture) Fichier [%s] \n",FileName.c_str());
908 if ( (type == ImplicitVR) || (type == ExplicitVR) ) {
910 // writing Dicom File Preamble
911 filePreamble=(char*)calloc(128,1);
912 fwrite(filePreamble,128,1,fp1);
913 fwrite("DICM",4,1,fp1);
916 // --------------------------------------------------------------
917 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
919 // if recognition code tells us we dealt with a LibIDO image
920 // we reproduce on disk the switch between lineNumber and columnNumber
921 // just before writting ...
923 std::string rows, columns;
924 if ( filetype == ACR_LIBIDO){
925 rows = GetPubElValByNumber(0x0028, 0x0010);
926 columns = GetPubElValByNumber(0x0028, 0x0011);
927 SetPubElValByNumber(columns, 0x0028, 0x0010);
928 SetPubElValByNumber(rows , 0x0028, 0x0011);
930 // ----------------- End of Special Patch ----------------
932 gdcmHeader::Write(fp1, type);
934 // --------------------------------------------------------------
935 // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
937 // ...and we restore the Header to be Dicom Compliant again
938 // just after writting
940 if (filetype == ACR_LIBIDO){
941 SetPubElValByNumber(rows , 0x0028, 0x0010);
942 SetPubElValByNumber(columns, 0x0028, 0x0011);
944 // ----------------- End of Special Patch ----------------
946 fwrite(PixelData, lgrTotale, 1, fp1);