Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/10/28 03:10:58 $
- Version: $Revision: 1.150 $
+ Date: $Date: 2004/11/16 16:20:23 $
+ Version: $Revision: 1.157 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmFile.h"
#include "gdcmDebug.h"
+#include "gdcmUtil.h"
+#include "gdcmBinEntry.h"
#include <fstream>
namespace gdcm
*/
void File::Initialise()
{
+ PixelConverter = NULL; //just in case
if ( HeaderInternal->IsReadable() )
{
ImageDataSizeRaw = ComputeDecompressedPixelDataSizeFromHeader();
HeaderInternal = 0;
DeleteInitialValues();
+ if( PixelConverter )
+ {
+ delete PixelConverter;
+ }
}
/**
InitialRedLUTData = 0;
InitialGreenLUTData = 0;
InitialBlueLUTData = 0;
-
+
if ( HeaderInternal->IsReadable() )
{
// the following values *may* be modified
*/
void File::DeleteInitialValues()
{
-
// InitialLutDescriptors and InitialLutData
// will have to be deleted if the don't belong any longer
// to the Header H table when the header is deleted...
- if ( InitialRedLUTDescr )
+// FIXME
+// We don't know if the InitialLutData are still in the header or not !
+/* if ( InitialRedLUTDescr )
delete InitialRedLUTDescr;
if ( InitialGreenLUTDescr )
delete InitialGreenLUTDescr;
- if ( InitialBlueLUTDescr )
- delete InitialBlueLUTDescr;
+ if ( InitialBlueLUTDescr )
+ delete InitialBlueLUTDescr;
- if ( InitialRedLUTData )
+ if ( InitialRedLUTData )
delete InitialRedLUTData;
- if ( InitialGreenLUTData != NULL)
+ if ( InitialGreenLUTData )
delete InitialGreenLUTData;
- if ( InitialBlueLUTData != NULL)
- delete InitialBlueLUTData;
+ if ( InitialBlueLUTData )
+ delete InitialBlueLUTData;*/
}
//-----------------------------------------------------------------------------
if ( HeaderInternal->HasLUT() )
{
// The LUT interpretation failed
- std::string photometricInterpretation = "MONOCHROME1 ";
+ std::string photometricInterpretation = Util::DicomString("MONOCHROME1");
HeaderInternal->SetEntryByNumber( photometricInterpretation,
0x0028, 0x0004 );
PixelRead = 0; // no PixelRaw
}
// We say the value *is* loaded.
- GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
-
- // Will be 7fe0, 0010 in standard case
- GetHeader()->SetEntryBinAreaByNumber( pixelData,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
+ SetPixelData(pixelData);
// END PIXELCONVERT CLEANME
return pixelData;
"than caller's expected MaxSize");
return 0;
}
- memmove( destination,
- (void*)PixelConverter->GetRGB(),
- PixelConverter->GetRGBSize() );
+ memcpy( destination,
+ (void*)PixelConverter->GetRGB(),
+ PixelConverter->GetRGBSize() );
return PixelConverter->GetRGBSize();
}
"than caller's expected MaxSize");
return 0;
}
- memmove( destination,
- (void*)PixelConverter->GetDecompressed(),
- PixelConverter->GetDecompressedSize() );
+ memcpy( destination,
+ (void*)PixelConverter->GetDecompressed(),
+ PixelConverter->GetDecompressedSize() );
return PixelConverter->GetDecompressedSize();
}
}
// We say the value *is* loaded.
- GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
+/* GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
// will be 7fe0, 0010 in standard cases
GetHeader()->SetEntryBinAreaByNumber( decompressed,
- GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
+ GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());*/
+ SetPixelData(decompressed);
PixelRead = 1; // PixelRaw
// END PIXELCONVERT CLEANME
// The decompressed image migth not be loaded yet:
std::ifstream* fp = HeaderInternal->OpenFile();
PixelConverter->ReadAndDecompressPixelData( fp );
- HeaderInternal->CloseFile();
+ if(fp) HeaderInternal->CloseFile();
decompressed = PixelConverter->GetDecompressed();
if ( ! decompressed )
{
std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
if (!fp1)
{
- printf("Fail to open (write) file [%s] \n", fileName.c_str());
+ dbg.Verbose(2, "Fail to open (write) file:", fileName.c_str());
return false;
}
fp1.write((char*)Pixel_Data, ImageDataSize);
std::ios::out | std::ios::binary);
if (fp1 == NULL)
{
- printf("Failed to open (write) File [%s] \n", fileName.c_str());
+ dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
return false;
}
if ( type == ImplicitVR || type == ExplicitVR )
{
// writing Dicom File Preamble
- uint8_t filePreamble[128];
+ char filePreamble[128];
memset(filePreamble, 0, 128);
- fp1->write((char*)filePreamble, 128);
+ fp1->write(filePreamble, 128);
fp1->write("DICM", 4);
}
}
// ----------------- End of Special Patch ----------------
fp1->close ();
+ delete fp1;
return true;
}
return PixelConverter->GetLutRGBA();
}
+//-----------------------------------------------------------------------------
+// Private
+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 );
+ }
+}
+
+//-----------------------------------------------------------------------------
} // end namespace gdcm