X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelReadConvert.cxx;h=d30ba99576c2a1bfd0cd38c19768f91af0835858;hb=6cf34d5df01e8ec0572bcef6c6b91be58212ef77;hp=38955fe7b2438ef2f2df9635ff42847c973e0879;hpb=2329c3cbf7cc86aa2c8410756927f0dcf3941441;p=gdcm.git diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 38955fe7..d30ba995 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/05/22 18:38:52 $ - Version: $Revision: 1.57 $ + Date: $Date: 2005/05/30 01:30:39 $ + Version: $Revision: 1.63 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,11 +16,11 @@ =========================================================================*/ +#include "gdcmPixelReadConvert.h" #include "gdcmDebug.h" #include "gdcmFile.h" #include "gdcmGlobal.h" #include "gdcmTS.h" -#include "gdcmPixelReadConvert.h" #include "gdcmDocEntry.h" #include "gdcmRLEFramesInfo.h" #include "gdcmJPEGFragmentsInfo.h" @@ -31,8 +31,9 @@ namespace gdcm { -bool ReadMPEGFile (std::ifstream *fp, void *image_buffer); -bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* raw, size_t inputlength); +//bool ReadMPEGFile (std::ifstream *fp, void *image_buffer, size_t lenght); +bool gdcm_read_JPEG2000_file (void* raw, + char *inputdata, size_t inputlength); //----------------------------------------------------------------------------- #define str2num(str, typeNum) *((typeNum *)(str)) @@ -258,7 +259,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) { //gdcmWarningMacro( "Sorry, MPEG not yet taken into account" ); //return false; - ReadMPEGFile(fp, Raw); // fp has already been seek to start of mpeg +// ReadMPEGFile(fp, Raw, PixelDataLength); // fp has already been seek to start of mpeg return true; } else @@ -397,27 +398,61 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp ) { if ( IsJPEG2000 ) { -// gdcmWarningMacro( "Sorry, JPEG2000 not yet taken into account" ); - fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg); - if ( ! gdcm_read_JPEG2000_file( fp,Raw, JPEGInfo->GetFirstFragment()->GetLength() ) ) - return false; + // FIXME this is really ugly but it seems I have to load the complete + // jpeg2000 stream to use jasper: + // I don't think we'll ever be able to deal with multiple fragments properly + + unsigned long inputlength = 0; + JPEGFragment *jpegfrag = JPEGInfo->GetFirstFragment(); + while( jpegfrag ) + { + inputlength += jpegfrag->GetLength(); + jpegfrag = JPEGInfo->GetNextFragment(); + } + gdcmAssertMacro( inputlength != 0); + uint8_t *inputdata = new uint8_t[inputlength]; + char *pinputdata = (char*)inputdata; + jpegfrag = JPEGInfo->GetFirstFragment(); + while( jpegfrag ) + { + fp->seekg( jpegfrag->GetOffset(), std::ios::beg); + fp->read(pinputdata, jpegfrag->GetLength()); + pinputdata += jpegfrag->GetLength(); + jpegfrag = JPEGInfo->GetNextFragment(); + } + // Warning the inputdata buffer is delete in the function + if ( ! gdcm_read_JPEG2000_file( Raw, + (char*)inputdata, inputlength ) ) + { + return true; + } } if ( IsJPEGLS ) { + // WARNING : JPEG-LS is NOT the 'classical' Jpeg Lossless : + // [JPEG-LS is the basis for new lossless/near-lossless compression + // standard for continuous-tone images intended for JPEG2000. The standard + // is based on the LOCO-I algorithm (LOw COmplexity LOssless COmpression + // for Images) developed at Hewlett-Packard Laboratories] + // + // see http://datacompression.info/JPEGLS.shtml + // + gdcmWarningMacro( "Sorry, JPEG-LS not yet taken into account" ); fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg); // if ( ! gdcm_read_JPEGLS_file( fp,Raw ) ) return false; } - - // else ?? - // Precompute the offset localRaw will be shifted with - int length = XSize * YSize * SamplesPerPixel; - int numberBytes = BitsAllocated / 8; - - JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length ); - return true; + else + { + // Precompute the offset localRaw will be shifted with + int length = XSize * YSize * SamplesPerPixel; + int numberBytes = BitsAllocated / 8; + + JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length ); + return true; + } } /**