diff Framework/Inputs/OpenSlidePyramid.cpp @ 329:ae2d769215d2

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Oct 2024 08:48:53 +0200
parents 0c34b6625c67
children
line wrap: on
line diff
--- 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<const uint8_t*>(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<const uint8_t*>(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)
     {