From: frog Date: Wed, 20 Oct 2004 22:31:51 +0000 (+0000) Subject: * src/gdcmDocument.cxx: wrong type on return fixed (thanks dashboard) X-Git-Tag: Version0.6.bp~49 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f5028f34faa657dc1722331963f97c7734ee2d2a;p=gdcm.git * src/gdcmDocument.cxx: wrong type on return fixed (thanks dashboard) * CLEANUP_ROUND (14) for gdcmPixelConvert - PixelConvert::GetLutRGBA(FILE*) is now GetLutRGBA() (no fp needed) - PixelConvert::BuildRGBImage()(FILE*) is now BuildRGBImage() (no fp needed) - File::GetImageDataIntoVector() doesn't need unnecessary OpenFile() and CloseFile() anymore. - File::GetImageDataRaw() doesn't call GetImageDataIntoVectorRaw() anymore and hence avoids storing a copy of PixelConvert::Decompressed into File::Pixel_Data. --- diff --git a/ChangeLog b/ChangeLog index a27a533d..4ccb8201 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-10-21 Eric Boix + * src/gdcmDocument.cxx: wrong type on return fixed (thanks dashboard) + * CLEANUP_ROUND (14) for gdcmPixelConvert + - PixelConvert::GetLutRGBA(FILE*) is now GetLutRGBA() (no fp needed) + - PixelConvert::BuildRGBImage()(FILE*) is now BuildRGBImage() (no fp needed) + - File::GetImageDataIntoVector() doesn't need unnecessary OpenFile() and + CloseFile() anymore. + - File::GetImageDataRaw() doesn't call GetImageDataIntoVectorRaw() + anymore and hence avoids storing a copy of PixelConvert::Decompressed + into File::Pixel_Data. + 2004-10-20 Eric Boix * src/gdcmDocument.cxx ftell() return properly stored in a long (i.e. no longer depends on's programmers PMS = Preposterous Mood Swings ;). diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index a8b15697..d8bdf65b 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/10/20 14:30:40 $ - Version: $Revision: 1.106 $ + Date: $Date: 2004/10/20 22:31:52 $ + Version: $Revision: 1.107 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -554,7 +554,14 @@ bool Document::CloseFile() int closed = fclose(Fp); Fp = 0; - return closed; + if ( ! closed ) + { + return false; + } + else + { + return true; + } } /** diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index b565a3a4..6909a643 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/10/20 14:30:40 $ - Version: $Revision: 1.146 $ + Date: $Date: 2004/10/20 22:31:52 $ + Version: $Revision: 1.147 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -362,8 +362,7 @@ size_t File::GetImageDataIntoVector (void* destination, size_t maxSize) return ImageDataSize; } - FILE* fp = HeaderInternal->OpenFile(); - if ( PixelConverter->BuildRGBImage( fp ) ) + if ( PixelConverter->BuildRGBImage() ) { memmove( destination, (void*)PixelConverter->GetRGB(), @@ -395,7 +394,6 @@ size_t File::GetImageDataIntoVector (void* destination, size_t maxSize) std::string photomInterp = "MONOCHROME1 "; // Photometric Interpretation HeaderInternal->SetEntryByNumber(photomInterp,0x0028,0x0004); } - HeaderInternal->CloseFile(); /// \todo Drop Palette Color out of the Header? return ImageDataSize; @@ -412,40 +410,59 @@ size_t File::GetImageDataIntoVector (void* destination, size_t maxSize) */ uint8_t* File::GetImageDataRaw () { - size_t imgDataSize; - if ( HeaderInternal->HasLUT() ) - /// \todo Let Header user a chance to get the right value - imgDataSize = ImageDataSizeRaw; - else - imgDataSize = ImageDataSize; - - // FIXME (Mathieu) - // I need to deallocate Pixel_Data before doing any allocation: - - if ( Pixel_Data ) - if ( LastAllocatedPixelDataLength != imgDataSize ) - free(Pixel_Data); - if ( !Pixel_Data ) - Pixel_Data = new uint8_t[imgDataSize]; + uint8_t* decompressed = PixelConverter->GetDecompressed(); + if ( ! decompressed ) + { + // The decompressed image migth not be loaded yet: + FILE* fp = HeaderInternal->OpenFile(); + PixelConverter->ReadAndDecompressPixelData( fp ); + HeaderInternal->CloseFile(); + if ( ! decompressed ) + { + dbg.Verbose(0, "File::GetImageDataRaw: read/decompress of " + "pixel data apparently went wrong."); + return 0; + } + } - if ( Pixel_Data ) +// PIXELCONVERT CLEANME + // Restore the header in a disk-consistent state + // (if user asks twice to get the pixels from disk) + if ( PixelRead != -1 ) // File was "read" before { - LastAllocatedPixelDataLength = imgDataSize; - - // we load the pixels ( grey level or RGB, but NO transformation) - GetImageDataIntoVectorRaw(Pixel_Data, imgDataSize); + RestoreInitialValues(); + } + if ( PixelConverter->IsDecompressedRGB() ) + { + /////////////////////////////////////////////////// + // now, it's an RGB image + // Lets's write it in the Header + // Droping Palette Color out of the Header + // has been moved to the Write process. + // TODO : move 'values' modification to the write process + // : save also (in order to be able to restore) + // : 'high bit' -when not equal to 'bits stored' + 1 + // : 'bits allocated', when it's equal to 12 ?! + std::string spp = "3"; // Samples Per Pixel + std::string photInt = "RGB "; // Photometric Interpretation + std::string planConfig = "0"; // Planar Configuration + HeaderInternal->SetEntryByNumber(spp,0x0028,0x0002); + HeaderInternal->SetEntryByNumber(photInt,0x0028,0x0004); + HeaderInternal->SetEntryByNumber(planConfig,0x0028,0x0006); + } - // We say the value *is* loaded. - GetHeader()->SetEntryByNumber( GDCM_BINLOADED, - GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); + // We say the value *is* loaded. + GetHeader()->SetEntryByNumber( GDCM_BINLOADED, + GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); + + // will be 7fe0, 0010 in standard cases + GetHeader()->SetEntryBinAreaByNumber( decompressed, + GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); - // will be 7fe0, 0010 in standard cases - GetHeader()->SetEntryBinAreaByNumber(Pixel_Data, - GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); - } PixelRead = 1; // PixelRaw +// END PIXELCONVERT CLEANME - return Pixel_Data; + return decompressed; } /** diff --git a/src/gdcmPixelConvert.cxx b/src/gdcmPixelConvert.cxx index 962088f4..d8955050 100644 --- a/src/gdcmPixelConvert.cxx +++ b/src/gdcmPixelConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelConvert.cxx,v $ Language: C++ - Date: $Date: 2004/10/20 14:30:40 $ - Version: $Revision: 1.16 $ + Date: $Date: 2004/10/20 22:31:52 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -900,7 +900,7 @@ void PixelConvert::GrabInformationsFromHeader( Header* header ) * no known Dicom reader deals with them :-( * @return a RGBA Lookup Table */ -void PixelConvert::BuildLUTRGBA( FILE* fp ) +void PixelConvert::BuildLUTRGBA() { if ( LutRGBA ) { @@ -1023,10 +1023,10 @@ void PixelConvert::BuildLUTRGBA( FILE* fp ) /** * \brief Build the RGB image from the Decompressed imagage and the LUTs. */ -bool PixelConvert::BuildRGBImage( FILE* fp ) +bool PixelConvert::BuildRGBImage() { - BuildLUTRGBA( fp ); - if ( ! LutRGBA ) + BuildLUTRGBA(); + if ( ( ! LutRGBA ) || ( ! Decompressed ) ) { return false; } diff --git a/src/gdcmPixelConvert.h b/src/gdcmPixelConvert.h index 74a01d1e..4de45555 100644 --- a/src/gdcmPixelConvert.h +++ b/src/gdcmPixelConvert.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelConvert.h,v $ Language: C++ - Date: $Date: 2004/10/20 14:30:40 $ - Version: $Revision: 1.11 $ + Date: $Date: 2004/10/20 22:31:52 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -54,7 +54,7 @@ public: void GrabInformationsFromHeader( Header* header ); bool ReadAndDecompressPixelData( FILE* fp ); void Squeeze(); - bool BuildRGBImage( FILE* fp ); + bool BuildRGBImage(); private: // Use the fp: @@ -66,10 +66,10 @@ private: void ReadAndDecompress12BitsTo16Bits( FILE* fp ) throw ( FormatError ); bool ReadAndDecompressRLEFile( FILE* fp ); bool ReadAndDecompressJPEGFile( FILE* fp ); - void BuildLUTRGBA( FILE* fp ); // In place (within Decompressed and with no fp access) decompression // or convertion: + void BuildLUTRGBA(); bool DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames ); void ConvertSwapZone(); void ConvertReorderEndianity();