X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelReadConvert.cxx;h=c98ffa17f632c49770815037bb06820321c00056;hb=a98b52385287bd4c6855758bdaa1d1ce2b7333be;hp=116a3a92c73987ecc71a9c2d352affeab60bbb27;hpb=fcd272971675f79db23fff3747dea7b216c3138e;p=gdcm.git diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 116a3a92..c98ffa17 100644 --- a/src/gdcmPixelReadConvert.cxx +++ b/src/gdcmPixelReadConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.cxx,v $ Language: C++ - Date: $Date: 2005/11/28 10:32:05 $ - Version: $Revision: 1.102 $ + Date: $Date: 2005/11/30 11:44:38 $ + 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 @@ -82,7 +82,8 @@ bool PixelReadConvert::IsRawRGB() * \brief Gets various usefull informations from the file header * @param file gdcm::File pointer */ -void PixelReadConvert::GrabInformationsFromFile( File *file ) +void PixelReadConvert::GrabInformationsFromFile( File *file, + FileHelper *fileHelper ) { // Number of Bits Allocated for storing a Pixel is defaulted to 16 // when absent from the file. @@ -227,7 +228,7 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) } } FileInternal = file; - + FH = fileHelper; ComputeRawAndRGBSizes(); } @@ -257,8 +258,18 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) AllocateRaw(); ////////////////////////////////////////////////// + + CallStartMethod(); // for progress bar + unsigned int count = 0; + unsigned int frameSize; + unsigned int bitsAllocated = BitsAllocated; + if(bitsAllocated == 12) + bitsAllocated = 16; + frameSize = XSize*YSize*SamplesPerPixel*bitsAllocated/8; + //// Second stage: read from disk and decompress. - if ( BitsAllocated == 12 ) + + if ( BitsAllocated == 12 ) // We suppose 'BitsAllocated' = 12 only exist for uncompressed files { ReadAndDecompress12BitsTo16Bits( fp); } @@ -271,16 +282,42 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) if ( PixelDataLength != RawSize ) { gdcmWarningMacro( "Mismatch between PixelReadConvert : " - << PixelDataLength << " and RawSize : " << RawSize ); + << PixelDataLength << " and RawSize : " << RawSize ); } + + //todo : is it the right patch? + char *raw = (char*)Raw; + uint32_t remainingLength; + unsigned int i; + unsigned int lengthToRead; + if ( PixelDataLength > RawSize ) - { - fp->read( (char*)Raw, RawSize); - } + lengthToRead = RawSize; else + lengthToRead = PixelDataLength; + + // perform a frame by frame reading + remainingLength = lengthToRead; + unsigned int nbFrames = lengthToRead / frameSize; + for (i=0;iread( (char*)Raw, PixelDataLength); + Progress = (float)(count+1)/(float)nbFrames; + fp->read( raw, frameSize); + raw += frameSize; + remainingLength -= frameSize; + count++; } + if (remainingLength !=0 ) + fp->read( raw, remainingLength); + + //if ( PixelDataLength > RawSize ) + //{ + // fp->read( (char*)Raw, RawSize); // Read all the frames with a single fread + //} + //else + //{ + // fp->read( (char*)Raw, PixelDataLength); // Read all the frames with a single fread + //} if ( fp->fail() || fp->eof()) { @@ -311,7 +348,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) if ( ! ReadAndDecompressJPEGFile( fp ) ) { gdcmWarningMacro( "JPEG decompressor ( ReadAndDecompressJPEGFile()" - << " method ) failed." ); + << " method ) failed." ); return false; } } @@ -640,11 +677,11 @@ void PixelReadConvert::BuildLUTRGBA() } gdcmDebugMacro(" lengthR " << lengthR << " debR " - << debR << " nbitsR " << nbitsR); + << debR << " nbitsR " << nbitsR); gdcmDebugMacro(" lengthG " << lengthG << " debG " - << debG << " nbitsG " << nbitsG); + << debG << " nbitsG " << nbitsG); gdcmDebugMacro(" lengthB " << lengthB << " debB " - << debB << " nbitsB " << nbitsB); + << debB << " nbitsB " << nbitsB); if ( !lengthR ) // if = 2^16, this shall be 0 see : CP-143 lengthR=65536; @@ -1246,7 +1283,7 @@ void PixelReadConvert::ConvertHandleColor() // - [Planar 2] OR [Photo D] requires LUT intervention. gdcmDebugMacro("--> ConvertHandleColor " - << "Planar Configuration " << PlanarConfiguration ); + << "Planar Configuration " << PlanarConfiguration ); if ( ! IsRawRGB() ) { @@ -1369,6 +1406,34 @@ void PixelReadConvert::Print( std::ostream &os, std::string const &indent ) } } +/** + * \brief CallStartMethod + */ +void PixelReadConvert::CallStartMethod() +{ + Progress = 0.0f; + Abort = false; + CommandManager::ExecuteCommand(FH,CMD_STARTPROGRESS); +} + +/** + * \brief CallProgressMethod + */ +void PixelReadConvert::CallProgressMethod() +{ + CommandManager::ExecuteCommand(FH,CMD_PROGRESS); +} + +/** + * \brief CallEndMethod + */ +void PixelReadConvert::CallEndMethod() +{ + Progress = 1.0f; + CommandManager::ExecuteCommand(FH,CMD_ENDPROGRESS); +} + + //----------------------------------------------------------------------------- } // end namespace gdcm