changeset 416:88c79f1537de captain

compatibility of captain branch with framework 1.4.2
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 15 Nov 2018 10:44:32 +0100
parents 70823cb5ec9e
children
files Framework/Volumes/ImageBuffer3D.cpp Framework/Widgets/LayoutWidget.cpp
diffstat 2 files changed, 54 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Volumes/ImageBuffer3D.cpp	Mon Nov 05 08:55:04 2018 +0100
+++ b/Framework/Volumes/ImageBuffer3D.cpp	Thu Nov 15 10:44:32 2018 +0100
@@ -363,7 +363,11 @@
 
       case VolumeProjection_Sagittal:
         sagittal_.reset(that.ExtractSagittalSlice(slice));
-        sagittal_->GetReadOnlyAccessor(accessor_);
+        accessor_.AssignReadOnly(sagittal_->GetFormat(),
+                                 sagittal_->GetWidth(),
+                                 sagittal_->GetHeight(),
+                                 sagittal_->GetPitch(),
+                                 sagittal_->GetBuffer());        
         break;
 
       default:
@@ -407,7 +411,11 @@
 
       case VolumeProjection_Sagittal:
         sagittal_.reset(that.ExtractSagittalSlice(slice));
-        sagittal_->GetWriteableAccessor(accessor_);
+        accessor_.AssignWritable(sagittal_->GetFormat(),
+                                 sagittal_->GetWidth(),
+                                 sagittal_->GetHeight(),
+                                 sagittal_->GetPitch(),
+                                 sagittal_->GetBuffer());
         break;
 
       default:
--- a/Framework/Widgets/LayoutWidget.cpp	Mon Nov 05 08:55:04 2018 +0100
+++ b/Framework/Widgets/LayoutWidget.cpp	Thu Nov 15 10:44:32 2018 +0100
@@ -28,6 +28,46 @@
 
 namespace OrthancStone
 {
+  // This is a compatibility reimplementation of
+  // "ImageAcessor::GetRegion()" to use Orthanc <= 1.4.2 together with
+  // Stone.
+  static void GetRegionCompatibility(Orthanc::ImageAccessor& target,
+                                     const Orthanc::ImageAccessor& source,
+                                     unsigned int x,
+                                     unsigned int y,
+                                     unsigned int width,
+                                     unsigned int height)
+  {
+    if (x + width > source.GetWidth() ||
+        y + height > source.GetHeight())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+    
+    if (width == 0 ||
+        height == 0)
+    {
+      target.AssignWritable(source.GetFormat(), 0, 0, 0, NULL);
+    }
+    else if (source.IsReadOnly())
+    {
+      const uint8_t* p = (reinterpret_cast<const uint8_t*>(source.GetBuffer()) + 
+                          y * source.GetPitch() + 
+                          x * source.GetBytesPerPixel());
+
+      target.AssignReadOnly(source.GetFormat(), width, height, source.GetPitch(), p);
+    }
+    else
+    {
+      uint8_t* p = (reinterpret_cast<uint8_t*>(source.GetBuffer()) + 
+                    y * source.GetPitch() + 
+                    x * source.GetBytesPerPixel());
+        
+      target.AssignWritable(source.GetFormat(), width, height, source.GetPitch(), p);
+    }
+  }
+
+
   class LayoutWidget::LayoutMouseTracker : public IMouseTracker
   {
   private:
@@ -36,7 +76,7 @@
     int                            top_;
     unsigned int                   width_;
     unsigned int                   height_;
-
+    
   public:
     LayoutMouseTracker(IMouseTracker* tracker,
                        int left,
@@ -58,7 +98,7 @@
     virtual void Render(Orthanc::ImageAccessor& surface)
     {
       Orthanc::ImageAccessor accessor;
-      surface.GetRegion(accessor, left_, top_, width_, height_);
+      GetRegionCompatibility(accessor, surface, left_, top_, width_, height_);
       tracker_->Render(accessor);
     }
 
@@ -144,7 +184,7 @@
       else 
       {
         Orthanc::ImageAccessor accessor;
-        target.GetRegion(accessor, left_, top_, width_, height_);
+        GetRegionCompatibility(accessor, target, left_, top_, width_, height_);
         return widget_->Render(accessor);
       }
     }
@@ -176,7 +216,7 @@
       if (Contains(x, y))
       {
         Orthanc::ImageAccessor accessor;
-        target.GetRegion(accessor, left_, top_, width_, height_);
+        GetRegionCompatibility(accessor, target, left_, top_, width_, height_);
 
         widget_->RenderMouseOver(accessor, x - left_, y - top_);
       }