# HG changeset patch # User Sebastien Jodogne # Date 1689655544 -7200 # Node ID 559499b80da84da909fff8b28411d4cf9b6eaed0 # Parent 92b88fa3e631a68eb6bf97312cab69e27db63bbb refactoring diff -r 92b88fa3e631 -r 559499b80da8 Framework/Inputs/HierarchicalTiff.cpp --- a/Framework/Inputs/HierarchicalTiff.cpp Thu Jul 13 18:18:21 2023 +0200 +++ b/Framework/Inputs/HierarchicalTiff.cpp Tue Jul 18 06:45:44 2023 +0200 @@ -99,10 +99,13 @@ } - bool HierarchicalTiff::GetCurrentCompression(ImageCompression& compression) + bool HierarchicalTiff::GetCurrentDirectoryInformation(TIFF* tiff, + ImageCompression& compression, + Orthanc::PixelFormat& pixelFormat, + Orthanc::PhotometricInterpretation& photometric) { uint16_t c; - if (!TIFFGetField(tiff_, TIFFTAG_COMPRESSION, &c)) + if (!TIFFGetField(tiff, TIFFTAG_COMPRESSION, &c)) { return false; } @@ -111,30 +114,24 @@ { case COMPRESSION_NONE: compression = ImageCompression_None; - return true; + break; case COMPRESSION_JPEG: compression = ImageCompression_Jpeg; - return true; + break; default: return false; } - } - - bool HierarchicalTiff::GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat, - Orthanc::PhotometricInterpretation& photometric, - ImageCompression compression) - { // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html uint16_t channels, photometricTiff, bpp, planar; - if (!TIFFGetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, &channels) || + if (!TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &channels) || channels == 0 || - !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometricTiff) || - !TIFFGetField(tiff_, TIFFTAG_BITSPERSAMPLE, &bpp) || - !TIFFGetField(tiff_, TIFFTAG_PLANARCONFIG, &planar)) + !TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometricTiff) || + !TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bpp) || + !TIFFGetField(tiff, TIFFTAG_PLANARCONFIG, &planar)) { return false; } @@ -161,6 +158,15 @@ return false; } } + else if (compression == ImageCompression_None && + channels == 3 && // This is a color image + bpp == 8 && + planar == PLANARCONFIG_CONTIG) // This is interleaved RGB + { + pixelFormat = Orthanc::PixelFormat_RGB24; + photometric = Orthanc::PhotometricInterpretation_RGB; + return true; + } else if (compression == ImageCompression_Jpeg && channels == 1 && // This is a grayscale image bpp == 8) @@ -198,8 +204,7 @@ h > 0 && tw > 0 && th > 0 && - GetCurrentCompression(compression) && - GetCurrentPixelFormat(pixelFormat, photometric, compression)) + GetCurrentDirectoryInformation(tiff_, compression, pixelFormat, photometric)) { if (first) { diff -r 92b88fa3e631 -r 559499b80da8 Framework/Inputs/HierarchicalTiff.h --- a/Framework/Inputs/HierarchicalTiff.h Thu Jul 13 18:18:21 2023 +0200 +++ b/Framework/Inputs/HierarchicalTiff.h Tue Jul 18 06:45:44 2023 +0200 @@ -62,12 +62,6 @@ void CheckLevel(unsigned int level) const; - bool GetCurrentCompression(ImageCompression& compression); - - bool GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat, - Orthanc::PhotometricInterpretation& photometric, - ImageCompression compression); - bool Initialize(); public: @@ -117,5 +111,10 @@ { return compression_; } + + static bool GetCurrentDirectoryInformation(TIFF* tiff, + ImageCompression& compression, + Orthanc::PixelFormat& pixelFormat, + Orthanc::PhotometricInterpretation& photometric); }; }