+ RestoreWrite();
+
+
+ fp1->close ();
+ delete fp1;
+
+ return true;
+}
+
+/**
+ * \brief Access to the underlying \ref PixelConverter RGBA LUT
+ */
+uint8_t* File::GetLutRGBA()
+{
+ return PixelConverter->GetLutRGBA();
+}
+
+//-----------------------------------------------------------------------------
+// Private
+/**
+ * \brief Set the pixel datas in the good entry of the Header
+ */
+void File::SetPixelData(uint8_t* data)
+{
+ GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
+ GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
+
+ // Will be 7fe0, 0010 in standard case
+ DocEntry* currentEntry = GetHeader()->GetDocEntryByNumber(GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
+ if ( currentEntry )
+ {
+ if ( BinEntry* binEntry = dynamic_cast<BinEntry *>(currentEntry) )
+ // Flag is to false because datas are kept in the gdcmPixelConvert
+ binEntry->SetBinArea( data, false );
+ }
+}
+
+void File::SetWriteToNative()
+{
+// Nothing to do
+}
+
+void File::SetWriteToDecompressed()
+{
+// if (( !HeaderInternal->HasLUT() ) || (!PixelConverter->BuildRGBImage()))
+ if(HeaderInternal->HasLUT() && PixelConverter->BuildRGBImage())
+ {
+ SetWriteToRGB();
+ }
+ else
+ {
+ ValEntry* photInt = CopyValEntry(0x0028,0x0004);
+ photInt->SetValue("MONOCHROME1 ");
+ photInt->SetLength(12);
+
+ BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+ pixel->SetValue(GDCM_BINLOADED);
+ pixel->SetBinArea(PixelConverter->GetDecompressed(),false);
+ pixel->SetLength(PixelConverter->GetDecompressedSize());
+
+ Archive->Push(photInt);
+ Archive->Push(pixel);
+ }
+/* else
+ {
+ SetWriteToRGB();
+ } */
+}
+
+void File::SetWriteToRGB()
+{
+ if(PixelConverter->BuildRGBImage())
+ {
+ ValEntry* spp = CopyValEntry(0x0028,0x0002);
+ spp->SetValue("3 ");
+ spp->SetLength(2);
+
+ ValEntry* photInt = CopyValEntry(0x0028,0x0004);
+ photInt->SetValue("RGB ");
+ photInt->SetLength(4);
+
+ ValEntry* planConfig = CopyValEntry(0x0028,0x0006);
+ planConfig->SetValue("0 ");
+ planConfig->SetLength(2);
+
+ BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+ pixel->SetValue(GDCM_BINLOADED);
+ pixel->SetBinArea(PixelConverter->GetRGB(),false);
+ pixel->SetLength(PixelConverter->GetRGBSize());
+
+ Archive->Push(spp);
+ Archive->Push(photInt);
+ Archive->Push(planConfig);
+ Archive->Push(pixel);
+ }
+ else
+ {
+ SetWriteToDecompressed();
+ }
+}
+
+void File::RestoreWrite()
+{
+ Archive->Restore(0x0028,0x0002);
+ Archive->Restore(0x0028,0x0004);
+ Archive->Restore(0x0028,0x0006);
+ Archive->Restore(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+}
+
+void File::SetWriteToLibido()
+{
+ ValEntry *oldRow = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010));
+ ValEntry *oldCol = dynamic_cast<ValEntry *>(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011));
+
+ if( oldRow && oldCol )
+ {
+ std::string rows, columns;
+
+ ValEntry *newRow=new ValEntry(oldRow->GetDictEntry());
+ ValEntry *newCol=new ValEntry(oldCol->GetDictEntry());
+
+ newRow->Copy(oldCol);
+ newCol->Copy(oldRow);
+
+ newRow->SetValue(oldCol->GetValue());
+ newCol->SetValue(oldRow->GetValue());
+
+ Archive->Push(newRow);
+ Archive->Push(newCol);
+ }
+}
+
+void File::RestoreWriteFromLibido()
+{
+ Archive->Restore(0x0028,0x0010);
+ Archive->Restore(0x0028,0x0011);
+}
+
+ValEntry* File::CopyValEntry(uint16_t group,uint16_t element)
+{
+ DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element);
+ ValEntry* newE;
+
+ if(oldE)
+ {
+ newE = new ValEntry(oldE->GetDictEntry());
+ newE->Copy(oldE);
+ }
+ else
+ {
+ newE = GetHeader()->NewValEntryByNumber(group,element);
+ }
+
+ return(newE);