changeset 100:16b8e1cc9bbf

Fix issue #30: Bad colorspace if using OpenSlide
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Jan 2017 13:15:05 +0100
parents 82357198e5e6
children be6000d032fb a9aa2a147303
files Framework/Inputs/OpenSlideLibrary.cpp NEWS Resources/Orthanc/Core/Images/ImageProcessing.cpp
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Inputs/OpenSlideLibrary.cpp	Wed Jan 04 17:02:38 2017 +0100
+++ b/Framework/Inputs/OpenSlideLibrary.cpp	Fri Jan 20 13:15:05 2017 +0100
@@ -191,7 +191,7 @@
     CheckLevel(level);
 
     // Create a new image, with minimal pitch so as to be compatible with OpenSlide API
-    std::auto_ptr<Orthanc::ImageAccessor> region(new Orthanc::Image(Orthanc::PixelFormat_RGBA32, width, height, true));
+    std::auto_ptr<Orthanc::ImageAccessor> region(new Orthanc::Image(Orthanc::PixelFormat_BGRA32, width, height, true));
 
     if (region->GetWidth() != 0 &&
         region->GetHeight() != 0)
--- a/NEWS	Wed Jan 04 17:02:38 2017 +0100
+++ b/NEWS	Fri Jan 20 13:15:05 2017 +0100
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Fix issue #30: Bad colorspace if using OpenSlide
+
 
 Version 0.3 (2016/12/23)
 ========================
--- a/Resources/Orthanc/Core/Images/ImageProcessing.cpp	Wed Jan 04 17:02:38 2017 +0100
+++ b/Resources/Orthanc/Core/Images/ImageProcessing.cpp	Fri Jan 20 13:15:05 2017 +0100
@@ -458,6 +458,26 @@
       return;
     }
 
+    if (target.GetFormat() == PixelFormat_RGB24 &&
+        source.GetFormat() == PixelFormat_BGRA32)
+    {
+      for (unsigned int y = 0; y < source.GetHeight(); y++)
+      {
+        const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
+        uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
+        for (unsigned int x = 0; x < source.GetWidth(); x++)
+        {
+          q[0] = p[2];
+          q[1] = p[1];
+          q[2] = p[0];
+          p += 4;
+          q += 3;
+        }
+      }
+
+      return;
+    }
+
     if (target.GetFormat() == PixelFormat_RGBA32 &&
         source.GetFormat() == PixelFormat_RGB24)
     {