X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelReadConvert.cxx;h=d30ba99576c2a1bfd0cd38c19768f91af0835858;hb=6cf34d5df01e8ec0572bcef6c6b91be58212ef77;hp=a909e8d31d3ba0006933bf27c6a744426266eed5;hpb=5ed11e15d9604baf77336c7769b636f6bd49677e;p=gdcm.git diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index a909e8d3..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/02/16 10:19:19 $ - Version: $Revision: 1.51 $ + 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" @@ -30,6 +30,10 @@ namespace gdcm { + +//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)) @@ -115,6 +119,7 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian; + IsMPEG = Global::GetTS()->IsMPEG(ts); IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts); IsJPEGLS = Global::GetTS()->IsJPEGLS(ts); IsJPEGLossy = Global::GetTS()->IsJPEGLossy(ts); @@ -250,6 +255,13 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) return false; } } + else if ( IsMPEG ) + { + //gdcmWarningMacro( "Sorry, MPEG not yet taken into account" ); + //return false; +// ReadMPEGFile(fp, Raw, PixelDataLength); // fp has already been seek to start of mpeg + return true; + } else { // Default case concerns JPEG family @@ -386,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 ) ) - 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; + } } /** @@ -644,8 +690,6 @@ void PixelReadConvert::ConvertReorderEndianity() } } - - /** * \brief Deal with Grey levels i.e. re-arange them * to have low values = dark, high values = bright @@ -655,7 +699,8 @@ void PixelReadConvert::ConvertFixGreyLevels() if (!IsMonochrome1) return; - int i; // to please M$VC6 + uint32_t i; // to please M$VC6 + int16_t j; if (!PixelSign) { @@ -673,8 +718,7 @@ void PixelReadConvert::ConvertFixGreyLevels() if ( BitsAllocated == 16 ) { uint16_t mask =1; - int bitStored = 12; - for (i=0; i 255.0) R = 255.0; - if (G > 255.0) G = 255.0; - if (B > 255.0) B = 255.0; + R = 38142 *(*a-16) + 52298 *(*c -128); + G = 38142 *(*a-16) - 26640 *(*c -128) - 12845 *(*b -128); + B = 38142 *(*a-16) + 66093 *(*b -128); + + R = (R+16384)>>15; + G = (G+16384)>>15; + B = (B+16384)>>15; + + if (R < 0) R = 0; + if (G < 0) G = 0; + if (B < 0) B = 0; + if (R > 255) R = 255; + if (G > 255) G = 255; + if (B > 255) B = 255; *(localRaw++) = (uint8_t)R; *(localRaw++) = (uint8_t)G;