+//-----------------------------------------------------------------------------
+// Protected
+/**
+ * \brief NOT a end user inteded function
+ * (used by WriteDcmExplVR, WriteDcmImplVR, WriteAcr, etc)
+ * @param fileName name of the file to be created
+ * (any already existing file is overwritten)
+ * @param type file type (ExplicitVR, ImplicitVR, ...)
+ * @return false if write fails
+ */
+bool File::WriteBase (std::string const & fileName, FileType type)
+{
+ if ( PixelRead == -1 && type != ExplicitVR)
+ {
+ return false;
+ }
+
+ std::ofstream* fp1 = new std::ofstream(fileName.c_str(),
+ std::ios::out | std::ios::binary);
+ if (fp1 == NULL)
+ {
+ printf("Failed to open (write) File [%s] \n", fileName.c_str());
+ return false;
+ }
+
+ if ( type == ImplicitVR || type == ExplicitVR )
+ {
+ // writing Dicom File Preamble
+ uint8_t filePreamble[128];
+ memset(filePreamble, 0, 128);
+ fp1->write((char*)filePreamble, 128);
+ fp1->write("DICM", 4);
+ }
+
+ // --------------------------------------------------------------
+ // 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 ( HeaderInternal->GetFileType() == ACR_LIBIDO)
+ {
+ rows = HeaderInternal->GetEntryByNumber(0x0028, 0x0010);
+ columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011);
+
+ HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0010);
+ HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0011);
+ }
+ // ----------------- End of Special Patch ----------------
+
+ uint16_t grPixel = HeaderInternal->GetGrPixel();
+ uint16_t numPixel = HeaderInternal->GetNumPixel();;
+
+ DocEntry* PixelElement =
+ GetHeader()->GetDocEntryByNumber(grPixel, numPixel);
+
+ if ( PixelRead == 1 )
+ {
+ // we read pixel 'as is' (no tranformation LUT -> RGB)
+ PixelElement->SetLength( ImageDataSizeRaw );
+ }
+ else if ( PixelRead == 0 )
+ {
+ // we tranformed GrayLevel pixels + LUT into RGB Pixel
+ PixelElement->SetLength( ImageDataSize );
+ }
+
+ HeaderInternal->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 ( HeaderInternal->GetFileType() == ACR_LIBIDO )
+ {
+ HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0010);
+ HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011);
+ }
+ // ----------------- End of Special Patch ----------------
+ fp1->close ();
+
+ return true;
+}