- FILE * fp1;
- char* filePreamble;
- fp1 = fopen(nomFichier.c_str(),"wb");
- if (fp1 == NULL) {
- printf("Echec ouverture (ecriture) Fichier [%s] \n",nomFichier.c_str());
- return (0);
- }
-
- // Ecriture Dicom File Preamble
- filePreamble=(char*)calloc(128,1);
- fwrite(filePreamble,128,1,fp1);
- fwrite("DICM",4,1,fp1);
-
- // un accesseur de + est obligatoire ???
- // pourtant le gdcmElValSet contenu dans le gdcmHeader
- // ne devrait pas être visible par l'utilisateur final (?)
-
- GetPubElVals().Write(fp1);
+ if ( (type == ImplicitVR) || (type == ExplicitVR) ) {
+ char * filePreamble;
+ // writing Dicom File Preamble
+ filePreamble=new char[128];
+ fwrite(filePreamble,128,1,fp1);
+ fwrite("DICM",4,1,fp1);
+ delete[] filePreamble;
+ }
+
+ // --------------------------------------------------------------
+ // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
+ //
+ // if recognition code tells us we dealt with a LibIDO image
+ // we reproduce on disk the switch between lineNumber and columnNumber
+ // just before writting ...
+
+ /// \todo the best trick would be *change* the recognition code
+ /// but pb expected if user deals with, e.g. COMPLEX images
+
+ std::string rows, columns;
+ if ( Header->GetFileType() == ACR_LIBIDO){
+ rows = Header->GetEntryByNumber(0x0028, 0x0010);
+ columns = Header->GetEntryByNumber(0x0028, 0x0011);
+ Header->SetEntryByNumber(columns, 0x0028, 0x0010);
+ Header->SetEntryByNumber(rows , 0x0028, 0x0011);
+ }
+ // ----------------- End of Special Patch ----------------
+
+ /// \todo get the grPixel, numPixel values (for some ACR-NEMA images only)
+
+ guint16 grPixel =Header->GetGrPixel();
+ guint16 numPixel=Header->GetNumPixel();;
+
+ // Update Pixel Data Length
+ // the *last* of the (GrPixel, NumPixel), if many.
+
+ TagKey key = gdcmDictEntry::TranslateToKey(grPixel, numPixel);
+ TagHeaderEntryHT::iterator p2;
+ gdcmHeaderEntry * PixelElement;
+
+ IterHT it= Header->GetEntry().equal_range(key); // get a pair of iterators first-last synonym
+
+ if (Header->GetEntry().count(key) == 1) // only the first is significant
+ p2=it.first; // iterator on the first (unique) synonym
+ else
+ p2=it.second;// iterator on the last synonym
+
+ PixelElement=p2->second; // H Table target column (2-nd col)
+ // PixelElement->SetPrintLevel(2);
+ // PixelElement->Print();
+
+ if (PixelRead==1)
+ PixelElement->SetLength(lgrTotaleRaw);
+ else if (PixelRead==0)
+ PixelElement->SetLength(lgrTotale);
+
+ //PixelElement->SetPrintLevel(2);
+ //PixelElement->Print();
+ Header->Write(fp1, type);
+
+ // --------------------------------------------------------------
+ // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
+ //
+ // ...and we restore the Header to be Dicom Compliant again
+ // just after writting
+
+ if (Header->GetFileType() == ACR_LIBIDO){
+ Header->SetEntryByNumber(rows , 0x0028, 0x0010);
+ Header->SetEntryByNumber(columns, 0x0028, 0x0011);
+ }
+ // ----------------- End of Special Patch ----------------
+
+ fwrite(PixelData, lgrTotale, 1, fp1);
+ fclose (fp1);
+ return(true);
+}
+
+//-----------------------------------------------------------------------------
+// Private
+/**
+ * \ingroup gdcmFile
+ * \brief Swap the bytes, according to swap code.
+ * \warning not end user intended
+ * @param im area to deal with
+ * @param swap swap code
+ * @param lgr Area Length
+ * @param nb Pixels Bit number
+ */
+void gdcmFile::SwapZone(void* im, int swap, int lgr, int nb) {
+guint32 s32;
+guint16 fort,faible;
+int i;
+
+if(nb == 16)
+ switch(swap) {
+ case 0:
+ case 12:
+ case 1234:
+ break;