X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelReadConvert.cxx;h=b94a76a82cb57149e26450a1673bafd2d0dd37bb;hb=ab3dc69a71af640fa49cbd917272d9ff7d1651b6;hp=b147cf3be6dbc30ac16ffa820d8afa5cd2761b26;hpb=d5e16925a7d3c8dbd0e71b1989629ca0f619b119;p=gdcm.git diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index b147cf3b..b94a76a8 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/01/17 01:14:33 $ - Version: $Revision: 1.29 $ + Date: $Date: 2005/01/26 11:42:02 $ + Version: $Revision: 1.35 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,14 +16,8 @@ =========================================================================*/ -////////////////// TEMPORARY NOTE -// look for "fixMem" and convert that to a member of this class -// Removing the prefix fixMem and dealing with allocations should do the trick -// -// grep PixelReadConvert everywhere and clean up ! - #include "gdcmDebug.h" -#include "gdcmHeader.h" +#include "gdcmFile.h" #include "gdcmGlobal.h" #include "gdcmTS.h" #include "gdcmPixelReadConvert.h" @@ -186,8 +180,8 @@ bool PixelReadConvert::DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames ) /** * \brief Implementation of the RLE decoding algorithm for decompressing * a RLE fragment. [refer to PS 3.5-2003, section G.3.2 p 86] - * @param subRaw Sub region of \ref Raw where the de - * decoded fragment should be placed. + * @param subRaw Sub region of \ref Raw where the decoded fragment + * should be placed. * @param fragmentSize The length of the binary fragment as found on the disk. * @param RawSegmentSize The expected length of the fragment ONCE * Raw. @@ -263,11 +257,11 @@ bool PixelReadConvert::ReadAndDecompressRLEFile( std::ifstream *fp ) ++it ) { // Loop on the fragments - for( unsigned int k = 1; k <= (*it)->NumberFragments; k++ ) + for( unsigned int k = 1; k <= (*it)->GetNumberOfFragments(); k++ ) { - fp->seekg( (*it)->Offset[k] , std::ios::beg ); + fp->seekg( (*it)->GetOffset(k) , std::ios::beg ); (void)ReadAndDecompressRLEFragment( subRaw, - (*it)->Length[k], + (*it)->GetLength(k), RawSegmentSize, fp ); subRaw += RawSegmentSize; @@ -357,7 +351,7 @@ void PixelReadConvert::ConvertSwapZone() } /** - * \brief Deal with endianity i.e. re-arange bytes inside the integer + * \brief Deal with endianness i.e. re-arange bytes inside the integer */ void PixelReadConvert::ConvertReorderEndianity() { @@ -367,9 +361,9 @@ void PixelReadConvert::ConvertReorderEndianity() } // Special kludge in order to deal with xmedcon broken images: - if ( ( BitsAllocated == 16 ) - && ( BitsStored < BitsAllocated ) - && ( ! PixelSign ) ) + if ( BitsAllocated == 16 + && BitsStored < BitsAllocated + && !PixelSign ) { int l = (int)( RawSize / ( BitsAllocated / 8 ) ); uint16_t *deb = (uint16_t *)Raw; @@ -394,24 +388,27 @@ void PixelReadConvert::ConvertReorderEndianity() */ bool PixelReadConvert::ReadAndDecompressJPEGFramesFromFile( std::ifstream *fp ) { - uint8_t *localRaw = Raw; - // Loop on the fragment[s] - for( JPEGFragmentsInfo::JPEGFragmentsList::iterator - it = JPEGInfo->Fragments.begin(); - it != JPEGInfo->Fragments.end(); - ++it ) - { - fp->seekg( (*it)->Offset, std::ios::beg); - - (*it)->DecompressJPEGFramesFromFile(fp, localRaw, BitsStored ); - - // Advance to next free location in Raw - // for next fragment decompression (if any) - int length = XSize * YSize * SamplesPerPixel; - int numberBytes = BitsAllocated / 8; - - localRaw += length * numberBytes; - } + // Pointer to the Raw image + //uint8_t *localRaw = Raw; + + // Precompute the offset localRaw will be shifted with + int length = XSize * YSize * SamplesPerPixel; + int numberBytes = BitsAllocated / 8; + +// // Loop on the fragment[s] +// for( JPEGFragmentsInfo::JPEGFragmentsList::iterator +// it = JPEGInfo->Fragments.begin(); +// it != JPEGInfo->Fragments.end(); +// ++it ) +// { +// (*it)->DecompressJPEGFramesFromFile(fp, localRaw, BitsStored ); +// +// // Advance to next free location in Raw +// // for next fragment decompression (if any) +// +// localRaw += length * numberBytes; +// } + JPEGInfo->DecompressJPEGFramesFromFile(fp, Raw, BitsStored, numberBytes, length ); return true; } @@ -428,30 +425,15 @@ bool PixelReadConvert:: ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream *fp ) { // Loop on the fragment[s] to get total length - size_t totalLength = 0; - JPEGFragmentsInfo::JPEGFragmentsList::iterator it; - for( it = JPEGInfo->Fragments.begin(); - it != JPEGInfo->Fragments.end(); - ++it ) - { - totalLength += (*it)->Length; - } + size_t totalLength = JPEGInfo->GetFragmentsLength(); // Concatenate the jpeg fragments into a local buffer JOCTET *buffer = new JOCTET [totalLength]; - JOCTET *p = buffer; - - // Loop on the fragment[s] - for( it = JPEGInfo->Fragments.begin(); - it != JPEGInfo->Fragments.end(); - ++it ) - { - fp->seekg( (*it)->Offset, std::ios::beg); - size_t len = (*it)->Length; - fp->read((char *)p,len); - p += len; - } + // Fill in the buffer: + JPEGInfo->ReadAllFragments(fp, buffer); + // kludge: // FIXME + JPEGFragmentsInfo::JPEGFragmentsList::const_iterator it = JPEGInfo->Fragments.begin(); (*it)->DecompressJPEGSingleFrameFragmentsFromFile(buffer, totalLength, Raw, BitsStored); // free local buffer @@ -473,39 +455,23 @@ bool PixelReadConvert:: ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp ) { // Loop on the fragment[s] to get total length - size_t totalLength = 0; - JPEGFragmentsInfo::JPEGFragmentsList::iterator it; - for( it = JPEGInfo->Fragments.begin(); - it != JPEGInfo->Fragments.end(); - ++it ) - { - totalLength += (*it)->Length; - } + size_t totalLength = JPEGInfo->GetFragmentsLength(); // Concatenate the jpeg fragments into a local buffer JOCTET *buffer = new JOCTET [totalLength]; - JOCTET *p = buffer; - - // Loop on the fragment[s] - for( it = JPEGInfo->Fragments.begin(); - it != JPEGInfo->Fragments.end(); - ++it ) - { - fp->seekg( (*it)->Offset, std::ios::beg); - size_t len = (*it)->Length; - fp->read((char *)p,len); - p+=len; - } + // Fill in the buffer: + JPEGInfo->ReadAllFragments(fp, buffer); size_t howManyRead = 0; size_t howManyWritten = 0; size_t fragmentLength = 0; + JPEGFragmentsInfo::JPEGFragmentsList::const_iterator it; for( it = JPEGInfo->Fragments.begin() ; (it != JPEGInfo->Fragments.end()) && (howManyRead < totalLength); ++it ) { - fragmentLength += (*it)->Length; + fragmentLength += (*it)->GetLength(); if (howManyRead > fragmentLength) continue; @@ -531,9 +497,19 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp ) { if ( IsJPEG2000 ) { - fp->seekg( (*JPEGInfo->Fragments.begin())->Offset, std::ios::beg); -// if ( ! gdcm_read_JPEG2000_file( fp,Raw ) ) -// return false; + gdcmVerboseMacro( "Sorry, JPEG2000 not yet taken into account" ); + fp->seekg( (*JPEGInfo->Fragments.begin())->GetOffset(), std::ios::beg); +// if ( ! gdcm_read_JPEG2000_file( fp,Raw ) ) + gdcmVerboseMacro( "Wrong Blue LUT descriptor" ); + return false; + } + + if ( IsJPEGLS ) + { + gdcmVerboseMacro( "Sorry, JPEG-LS not yet taken into account" ); + fp->seekg( (*JPEGInfo->Fragments.begin())->GetOffset(), std::ios::beg); +// if ( ! gdcm_read_JPEGLS_file( fp,Raw ) ) + return false; } if ( ( ZSize == 1 ) && ( JPEGInfo->Fragments.size() > 1 ) ) @@ -545,15 +521,25 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp ) } else if (JPEGInfo->Fragments.size() == (size_t)ZSize) { + } +// if ( ( ZSize == 1 ) && ( JPEGInfo->Fragments.size() > 1 ) ) +// { +// // we have one frame split into several fragments +// // we will pack those fragments into a single buffer and +// // read from it +// return ReadAndDecompressJPEGSingleFrameFragmentsFromFile( fp ); +// } +// else if (JPEGInfo->Fragments.size() == (size_t)ZSize) +// { // suppose each fragment is a frame return ReadAndDecompressJPEGFramesFromFile( fp ); - } - else - { - // The dicom image contains frames containing fragments of images - // a more complex algorithm :-) - return ReadAndDecompressJPEGFragmentedFramesFromFile( fp ); - } +// } +// else +// { +// // The dicom image contains frames containing fragments of images +// // a more complex algorithm :-) +// return ReadAndDecompressJPEGFragmentedFramesFromFile( fp ); +// } } /** @@ -597,7 +583,7 @@ bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError ) } /** - * \brief Convert (Y plane, cB plane, cR plane) to RGB pixels + * \brief Convert (cY plane, cB plane, cR plane) to RGB pixels * \warning Works on all the frames at a time */ void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels() @@ -708,8 +694,8 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) else if ( IsRaw ) { // 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 + // after the field containing the image data. In this case, these + // bad data are added to the size of the image (in the PixelDataLength // variable). But RawSize is the right size of the image ! if( PixelDataLength != RawSize) { @@ -866,7 +852,7 @@ void PixelReadConvert::ComputeRawAndRGBSizes() } } -void PixelReadConvert::GrabInformationsFromHeader( Header *header ) +void PixelReadConvert::GrabInformationsFromHeader( File *header ) { // Number of Bits Allocated for storing a Pixel is defaulted to 16 // when absent from the header. @@ -876,7 +862,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) BitsAllocated = 16; } - // Number of "Bits Stored" defaulted to number of "Bits Allocated" + // Number of "Bits Stored", defaulted to number of "Bits Allocated" // when absent from the header. BitsStored = header->GetBitsStored(); if ( BitsStored == 0 ) @@ -884,7 +870,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) BitsStored = BitsAllocated; } - // High Bit Position + // High Bit Position, defaulted to "Bits Allocated" - 1 HighBitPosition = header->GetHighBitPosition(); if ( HighBitPosition == 0 ) { @@ -906,9 +892,13 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian; - IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts); - IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts); - IsRLELossless = Global::GetTS()->IsRLELossless(ts); + + IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts); + IsJPEGLS = Global::GetTS()->IsJPEGLS(ts); + IsJPEGLossy = Global::GetTS()->IsJPEGLossy(ts); + IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts); + IsRLELossless = Global::GetTS()->IsRLELossless(ts); + PixelOffset = header->GetPixelOffset(); PixelDataLength = header->GetPixelAreaLength(); RLEInfo = header->GetRLEInfo(); @@ -924,17 +914,17 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) HasLUT = header->HasLUT(); if ( HasLUT ) { - // Just in case some access to a Header element requires disk access. - LutRedDescriptor = header->GetEntry( 0x0028, 0x1101 ); - LutGreenDescriptor = header->GetEntry( 0x0028, 0x1102 ); - LutBlueDescriptor = header->GetEntry( 0x0028, 0x1103 ); + // Just in case some access to a File element requires disk access. + LutRedDescriptor = header->GetEntryValue( 0x0028, 0x1101 ); + LutGreenDescriptor = header->GetEntryValue( 0x0028, 0x1102 ); + LutBlueDescriptor = header->GetEntryValue( 0x0028, 0x1103 ); // Depending on the value of Document::MAX_SIZE_LOAD_ELEMENT_VALUE // [ refer to invocation of Document::SetMaxSizeLoadEntry() in // Document::Document() ], the loading of the value (content) of a // [Bin|Val]Entry occurence migth have been hindered (read simply NOT - // loaded). Hence, we first try to obtain the LUTs data from the header - // and when this fails we read the LUTs data directely from disk. + // loaded). Hence, we first try to obtain the LUTs data from the file + // and when this fails we read the LUTs data directly from disk. /// \TODO Reading a [Bin|Val]Entry directly from disk is a kludge. /// We should NOT bypass the [Bin|Val]Entry class. Instead /// an access to an UNLOADED content of a [Bin|Val]Entry occurence @@ -972,7 +962,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) } /** - * \brief Build Red/Green/Blue/Alpha LUT from Header + * \brief Build Red/Green/Blue/Alpha LUT from File * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ] * and (0028,1101),(0028,1102),(0028,1102) * - xxx Palette Color Lookup Table Descriptor - are found @@ -1172,7 +1162,7 @@ void PixelReadConvert::Print( std::ostream &os, std::string const & indent ) } } - if ( IsJPEG2000 || IsJPEGLossless ) + if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS ) { if ( JPEGInfo ) {