X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmPixelReadConvert.cxx;h=78075ab2a940da5e70cb2ff968c48d7e95d2e5b9;hb=0068e5861800986e33ee5eeac99863c4e01e3512;hp=35d29222c50ae044182c4c986f82939e233d3959;hpb=25531920a24515b24ddaec0aff11b976d1a4a7cf;p=gdcm.git diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 35d29222..78075ab2 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/02 16:34:55 $ - Version: $Revision: 1.45 $ + Date: $Date: 2005/02/05 01:37:09 $ + Version: $Revision: 1.49 $ 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(); @@ -55,7 +57,7 @@ PixelReadConvert::~PixelReadConvert() //----------------------------------------------------------------------------- // Public /** - * \brief Predicate to know wether the image[s] (once Raw) is RGB. + * \brief Predicate to know whether the image[s] (once Raw) is RGB. * \note See comments of \ref ConvertHandleColor */ bool PixelReadConvert::IsRawRGB() @@ -68,7 +70,10 @@ bool PixelReadConvert::IsRawRGB() } return true; } - +/** + * \brief Gets various usefull informations from the file header + * @param file gdcm::File pointer + */ void PixelReadConvert::GrabInformationsFromFile( File *file ) { // Number of Bits Allocated for storing a Pixel is defaulted to 16 @@ -94,14 +99,14 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) HighBitPosition = BitsAllocated - 1; } - XSize = file->GetXSize(); - YSize = file->GetYSize(); - ZSize = file->GetZSize(); + XSize = file->GetXSize(); + YSize = file->GetYSize(); + ZSize = file->GetZSize(); SamplesPerPixel = file->GetSamplesPerPixel(); - PixelSize = file->GetPixelSize(); - PixelSign = file->IsSignedPixelData(); - SwapCode = file->GetSwapCode(); - std::string ts = file->GetTransferSyntax(); + PixelSize = file->GetPixelSize(); + PixelSign = file->IsSignedPixelData(); + SwapCode = file->GetSwapCode(); + std::string ts = file->GetTransferSyntax(); IsRaw = ( ! file->IsDicomV3() ) || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian @@ -142,42 +147,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 @@ -189,14 +195,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; } @@ -216,7 +222,8 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) // variable). But RawSize is the right size of the image ! if( PixelDataLength != RawSize) { - gdcmVerboseMacro( "Mismatch between PixelReadConvert and RawSize." ); + gdcmWarningMacro( "Mismatch between PixelReadConvert : " + << PixelDataLength << " and RawSize : " << RawSize ); } if( PixelDataLength > RawSize) { @@ -229,7 +236,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; } } @@ -237,7 +244,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; } } @@ -246,7 +253,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; } } @@ -260,6 +267,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) return true; } +/// Deletes Pixels Area void PixelReadConvert::Squeeze() { if ( RGB ) @@ -375,7 +383,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; @@ -383,7 +391,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; @@ -444,7 +452,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 @@ -455,7 +463,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 @@ -466,7 +474,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthB, &debB, &nbitsB ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong Blue LUT descriptor" ); + gdcmWarningMacro( "Wrong Blue LUT descriptor" ); } //////////////////////////////////////////////////////// @@ -555,7 +563,7 @@ void PixelReadConvert::ConvertSwapZone() } break; default: - gdcmVerboseMacro("SwapCode value (16 bits) not allowed."); + gdcmWarningMacro("SwapCode value (16 bits) not allowed."); } } else if( BitsAllocated == 32 ) @@ -600,7 +608,7 @@ void PixelReadConvert::ConvertSwapZone() } break; default: - gdcmVerboseMacro("SwapCode value (32 bits) not allowed." ); + gdcmWarningMacro("SwapCode value (32 bits) not allowed." ); } } } @@ -666,7 +674,7 @@ bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError ) } else { - gdcmVerboseMacro("Weird image"); + gdcmWarningMacro("Weird image"); throw FormatError( "Weird image !?" ); } } @@ -752,6 +760,11 @@ void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels() delete[] copyRaw; } +/// \brief Deals with the color decoding i.e. handle: +/// - R, G, B planes (as opposed to RGB pixels) +/// - YBR (various) encodings. +/// - LUT[s] (or "PALETTE COLOR"). + void PixelReadConvert::ConvertHandleColor() { ////////////////////////////////// @@ -822,6 +835,7 @@ void PixelReadConvert::ConvertHandleColor() // In *normal *case, when planarConf is 0, pixels are already in RGB } +/// Computes the Pixels Size void PixelReadConvert::ComputeRawAndRGBSizes() { int bitsAllocated = BitsAllocated; @@ -846,6 +860,7 @@ void PixelReadConvert::ComputeRawAndRGBSizes() } } +/// Allocates room for RGB Pixels void PixelReadConvert::AllocateRGB() { if ( RGB ) @@ -853,6 +868,7 @@ void PixelReadConvert::AllocateRGB() RGB = new uint8_t[RGBSize]; } +/// Allocates room for RAW Pixels void PixelReadConvert::AllocateRaw() { if ( Raw ) @@ -887,7 +903,7 @@ void PixelReadConvert::Print( std::ostream &os, std::string const &indent ) } else { - gdcmVerboseMacro("Set as RLE file but NO RLEinfo present."); + gdcmWarningMacro("Set as RLE file but NO RLEinfo present."); } } @@ -899,7 +915,7 @@ void PixelReadConvert::Print( std::ostream &os, std::string const &indent ) } else { - gdcmVerboseMacro("Set as JPEG file but NO JPEGinfo present."); + gdcmWarningMacro("Set as JPEG file but NO JPEGinfo present."); } } }