# HG changeset patch # User Sebastien Jodogne # Date 1729234133 -7200 # Node ID ae2d769215d2eacd0642a524f50b42730b8267a0 # Parent a57a107b9547518c19247a01ca50c3c01542f688 refactoring diff -r a57a107b9547 -r ae2d769215d2 Framework/Inputs/OpenSlidePyramid.cpp --- a/Framework/Inputs/OpenSlidePyramid.cpp Fri Oct 18 08:43:15 2024 +0200 +++ b/Framework/Inputs/OpenSlidePyramid.cpp Fri Oct 18 08:48:53 2024 +0200 @@ -35,6 +35,40 @@ namespace OrthancWSI { + // Test whether the full alpha channel (if any) equals 255 + static bool IsFullyTransparent(const Orthanc::ImageAccessor& source) + { + if (source.GetFormat() == Orthanc::PixelFormat_BGRA32 || + source.GetFormat() == Orthanc::PixelFormat_RGBA32) + { + const unsigned int width = source.GetWidth(); + const unsigned int height = source.GetHeight(); + + bool isEmpty = true; + + for (unsigned int yy = 0; yy < height && isEmpty; yy++) + { + const uint8_t* p = reinterpret_cast(source.GetConstRow(yy)); + for (unsigned int xx = 0; xx < width && isEmpty; xx++) + { + if (p[3] != 0) + { + isEmpty = false; + } + + p += 4; + } + } + + return isEmpty; + } + else + { + return false; + } + } + + void OpenSlidePyramid::ReadRegion(Orthanc::ImageAccessor& target, bool& isEmpty, unsigned int level, @@ -49,32 +83,11 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); } + isEmpty = IsFullyTransparent(*source); + const unsigned int width = source->GetWidth(); const unsigned int height = source->GetHeight(); - if (source->GetFormat() == Orthanc::PixelFormat_BGRA32) - { - isEmpty = true; - - for (unsigned int yy = 0; yy < height && isEmpty; yy++) - { - const uint8_t* p = reinterpret_cast(source->GetConstRow(yy)); - for (unsigned int xx = 0; xx < width && isEmpty; xx++) - { - if (p[3] != 0) - { - isEmpty = false; - } - - p += 4; - } - } - } - else - { - isEmpty = false; - } - if (target.GetFormat() == Orthanc::PixelFormat_RGB24 && source->GetFormat() == Orthanc::PixelFormat_BGRA32) {