X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelReadConvert.cxx;h=d3dfec5b671e7b81d405601c1fdff1fb8490829a;hb=d2d88279289bcafbeca8a41934d514d58141376d;hp=596367c7304fd72b31104f5151babb61ddbe6a52;hpb=96cc99e8e141ceaf026104699c3273ad5fc88a1f;p=gdcm.git diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 596367c7..d3dfec5b 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/03 10:03:07 $ - Version: $Revision: 1.46 $ + Date: $Date: 2005/02/23 09:54:59 $ + Version: $Revision: 1.53 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -35,6 +35,7 @@ namespace gdcm //----------------------------------------------------------------------------- // Constructor / Destructor +/// Constructor PixelReadConvert::PixelReadConvert() { RGB = 0; @@ -47,6 +48,7 @@ PixelReadConvert::PixelReadConvert() LutBlueData = 0; } +/// Canonical Destructor PixelReadConvert::~PixelReadConvert() { Squeeze(); @@ -121,13 +123,15 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) PixelOffset = file->GetPixelOffset(); PixelDataLength = file->GetPixelAreaLength(); - RLEInfo = file->GetRLEInfo(); - JPEGInfo = file->GetJPEGInfo(); + RLEInfo = file->GetRLEInfo(); + JPEGInfo = file->GetJPEGInfo(); + + IsMonochrome = file->IsMonochrome(); + IsMonochrome1 = file->IsMonochrome1(); + IsPaletteColor = file->IsPaletteColor(); + IsYBRFull = file->IsYBRFull(); PlanarConfiguration = file->GetPlanarConfiguration(); - IsMonochrome = file->IsMonochrome(); - IsPaletteColor = file->IsPaletteColor(); - IsYBRFull = file->IsYBRFull(); ///////////////////////////////////////////////////////////////// // LUT section: @@ -145,42 +149,43 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) // [Bin|Val]Entry occurence migth have been hindered (read simply NOT // 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 - /// (e.g. BinEntry::GetBinArea()) should force disk access from - /// within the [Bin|Val]Entry class itself. The only problem - /// is that the [Bin|Val]Entry is unaware of the FILE* is was - /// parsed from. Fix that. FIXME. + // \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 + // (e.g. BinEntry::GetBinArea()) should force disk access from + // within the [Bin|Val]Entry class itself. The only problem + // is that the [Bin|Val]Entry is unaware of the FILE* is was + // parsed from. Fix that. FIXME. - ////// Red round + // //// Red round file->LoadEntryBinArea(0x0028, 0x1201); LutRedData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1201 ); if ( ! LutRedData ) { - gdcmVerboseMacro( "Unable to read Red LUT data" ); + gdcmWarningMacro( "Unable to read Red LUT data" ); } - ////// Green round: + // //// Green round: file->LoadEntryBinArea(0x0028, 0x1202); LutGreenData = (uint8_t*)file->GetEntryBinArea(0x0028, 0x1202 ); if ( ! LutGreenData) { - gdcmVerboseMacro( "Unable to read Green LUT data" ); + gdcmWarningMacro( "Unable to read Green LUT data" ); } - ////// Blue round: + // //// Blue round: file->LoadEntryBinArea(0x0028, 0x1203); LutBlueData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1203 ); if ( ! LutBlueData ) { - gdcmVerboseMacro( "Unable to read Blue LUT data" ); + gdcmWarningMacro( "Unable to read Blue LUT data" ); } } ComputeRawAndRGBSizes(); } +/// \brief Reads from disk and decompresses Pixels bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) { // ComputeRawAndRGBSizes is already made by @@ -192,14 +197,14 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) //// First stage: get our hands on the Pixel Data. if ( !fp ) { - gdcmVerboseMacro( "Unavailable file pointer." ); + gdcmWarningMacro( "Unavailable file pointer." ); return false; } fp->seekg( PixelOffset, std::ios::beg ); if( fp->fail() || fp->eof()) { - gdcmVerboseMacro( "Unable to find PixelOffset in file." ); + gdcmWarningMacro( "Unable to find PixelOffset in file." ); return false; } @@ -219,7 +224,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) // variable). But RawSize is the right size of the image ! if( PixelDataLength != RawSize) { - gdcmVerboseMacro( "Mismatch between PixelReadConvert : " + gdcmWarningMacro( "Mismatch between PixelReadConvert : " << PixelDataLength << " and RawSize : " << RawSize ); } if( PixelDataLength > RawSize) @@ -233,7 +238,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) if ( fp->fail() || fp->eof()) { - gdcmVerboseMacro( "Reading of Raw pixel data failed." ); + gdcmWarningMacro( "Reading of Raw pixel data failed." ); return false; } } @@ -241,7 +246,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) { if ( ! RLEInfo->DecompressRLEFile( fp, Raw, XSize, YSize, ZSize, BitsAllocated ) ) { - gdcmVerboseMacro( "RLE decompressor failed." ); + gdcmWarningMacro( "RLE decompressor failed." ); return false; } } @@ -250,7 +255,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) // Default case concerns JPEG family if ( ! ReadAndDecompressJPEGFile( fp ) ) { - gdcmVerboseMacro( "JPEG decompressor failed." ); + gdcmWarningMacro( "JPEG decompressor failed." ); return false; } } @@ -259,11 +264,13 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) //// Third stage: twigle the bytes and bits. ConvertReorderEndianity(); ConvertReArrangeBits(); + ConvertFixGreyLevels(); ConvertHandleColor(); return true; } +/// Deletes Pixels Area void PixelReadConvert::Squeeze() { if ( RGB ) @@ -379,7 +386,7 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp ) { if ( IsJPEG2000 ) { - gdcmVerboseMacro( "Sorry, JPEG2000 not yet taken into account" ); + 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; @@ -387,7 +394,7 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp ) if ( IsJPEGLS ) { - gdcmVerboseMacro( "Sorry, JPEG-LS not yet taken into account" ); + 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; @@ -448,7 +455,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthR, &debR, &nbitsR ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong Red LUT descriptor" ); + gdcmWarningMacro( "Wrong Red LUT descriptor" ); } int lengthG; // Green LUT length in Bytes @@ -459,7 +466,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthG, &debG, &nbitsG ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong Green LUT descriptor" ); + gdcmWarningMacro( "Wrong Green LUT descriptor" ); } int lengthB; // Blue LUT length in Bytes @@ -470,7 +477,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthB, &debB, &nbitsB ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong Blue LUT descriptor" ); + gdcmWarningMacro( "Wrong Blue LUT descriptor" ); } //////////////////////////////////////////////////////// @@ -559,7 +566,7 @@ void PixelReadConvert::ConvertSwapZone() } break; default: - gdcmVerboseMacro("SwapCode value (16 bits) not allowed."); + gdcmWarningMacro("SwapCode value (16 bits) not allowed."); } } else if( BitsAllocated == 32 ) @@ -604,7 +611,7 @@ void PixelReadConvert::ConvertSwapZone() } break; default: - gdcmVerboseMacro("SwapCode value (32 bits) not allowed." ); + gdcmWarningMacro("SwapCode value (32 bits) not allowed." ); } } } @@ -637,9 +644,78 @@ void PixelReadConvert::ConvertReorderEndianity() } } +/** + * \brief Deal with Grey levels i.e. re-arange them + * to have low values = dark, high values = bright + */ +void PixelReadConvert::ConvertFixGreyLevels() +{ + if (!IsMonochrome1) + return; + + uint32_t i; // to please M$VC6 + int16_t j; + + if (!PixelSign) + { + if ( BitsAllocated == 8 ) + { + uint8_t *deb = (uint8_t *)Raw; + for (i=0; i