Program: gdcm
Module: $RCSfile: gdcmPixelConvert.cxx,v $
Language: C++
- Date: $Date: 2004/10/28 22:21:57 $
- Version: $Revision: 1.22 $
+ Date: $Date: 2004/11/24 10:23:47 $
+ Version: $Revision: 1.32 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDebug.h"
#include "gdcmPixelConvert.h"
#include <fstream>
+#include <stdio.h>
namespace gdcm
{
{
delete [] RGB;
}
+ RGB = 0;
+
if ( Decompressed )
{
delete [] Decompressed;
}
+ Decompressed = 0;
+
if ( LutRGBA )
{
delete [] LutRGBA;
}
+ LutRGBA = 0;
}
PixelConvert::~PixelConvert()
{
for ( unsigned int j = 0; j < PixelNumber; j++ )
{
- *(x++) = *(a++);
*(x++) = *(b++);
+ *(x++) = *(a++);
}
}
return false;
}
}
- else if ( BitsStored == 12)
+ else if ( BitsStored <= 12)
{
// Reading Fragment pixels
if ( ! gdcm_read_JPEG_file12 ( fp, localDecompressed ) )
return false;
}
}
- else if ( BitsStored == 16)
+ else if ( BitsStored <= 16)
{
// Reading Fragment pixels
if ( ! gdcm_read_JPEG_file16 ( fp, localDecompressed ) )
//// First stage: get our hands on the Pixel Data.
if ( !fp )
{
- dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
- "unavailable file pointer." );
+ dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
+ "unavailable file pointer." );
return false;
}
fp->seekg( PixelOffset, std::ios_base::beg );
if( fp->fail() || fp->eof()) //Fp->gcount() == 1
{
- dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
- "unable to find PixelOffset in file." );
+ dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
+ "unable to find PixelOffset in file." );
return false;
}
}
else if ( IsDecompressed )
{
- fp->read( (char*)Decompressed, PixelDataLength);
+ // This problem can be found when some obvious informations are found
+ // after the field containing the image datas. In this case, these
+ // bad datas are added to the size of the image (in the PixelDataLength
+ // variable). But DecompressedSize is the right size of the image !
+ if( PixelDataLength != DecompressedSize)
+ {
+ dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
+ "Mismatch between PixelConvert and DecompressedSize." );
+ }
+ if( PixelDataLength > DecompressedSize)
+ {
+ fp->read( (char*)Decompressed, DecompressedSize);
+ }
+ else
+ {
+ fp->read( (char*)Decompressed, PixelDataLength);
+ }
+
if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
{
// Just in case some access to a Header element requires disk access.
// Note: gdcmDocument::Fp is leaved open after OpenFile.
- std::ifstream* fp = header->OpenFile();
+ std::ifstream* fp = header->OpenFile();
// Number of Bits Allocated for storing a Pixel is defaulted to 16
// when absent from the header.
BitsAllocated = header->GetBitsAllocated();
IsDecompressed =
( ! header->IsDicomV3() )
|| ts == ImplicitVRLittleEndian
+ || ts == ImplicitVRLittleEndianDLXGE
|| ts == ExplicitVRLittleEndian
|| ts == ExplicitVRBigEndian
|| ts == DeflatedExplicitVRLittleEndian;
return;
}
}
-
+
////// Green round:
LutGreenData = (uint8_t*)header->GetEntryBinAreaByNumber(0x0028, 0x1202 );
if ( ! LutGreenData)
return;
}
}
-
+
////// Blue round:
LutBlueData = (uint8_t*)header->GetEntryBinAreaByNumber( 0x0028, 0x1203 );
if ( ! LutBlueData )
}
}
}
-
- header->CloseFile();
+
+ if(fp) header->CloseFile();
}
/**