[Bf-blender-cvs] [2ea47057d33] master: Compositor: Fix pixels being wrapped outside buffer area

Manuel Castilla noreply at git.blender.org
Tue Jul 13 22:50:11 CEST 2021


Commit: 2ea47057d33ebfa4ef5dfe687adc66464430e8f8
Author: Manuel Castilla
Date:   Tue Jul 13 20:30:07 2021 +0200
Branches: master
https://developer.blender.org/rB2ea47057d33ebfa4ef5dfe687adc66464430e8f8

Compositor: Fix pixels being wrapped outside buffer area

Not causing issues in current master because all buffer areas are at
(0, 0) position and `Extend` is not used. But areas may be at any
position in future developments and it will crash.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D11784

===================================================================

M	source/blender/compositor/intern/COM_MemoryBuffer.h

===================================================================

diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h
index 89068a7b734..4ad0872b0b7 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.h
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.h
@@ -264,11 +264,14 @@ class MemoryBuffer {
           x = 0;
         }
         if (x >= w) {
-          x = w;
+          x = w - 1;
         }
         break;
       case MemoryBufferExtend::Repeat:
-        x = (x >= 0.0f ? (x % w) : (x % w) + w);
+        x %= w;
+        if (x < 0) {
+          x += w;
+        }
         break;
     }
 
@@ -280,13 +283,19 @@ class MemoryBuffer {
           y = 0;
         }
         if (y >= h) {
-          y = h;
+          y = h - 1;
         }
         break;
       case MemoryBufferExtend::Repeat:
-        y = (y >= 0.0f ? (y % h) : (y % h) + h);
+        y %= h;
+        if (y < 0) {
+          y += h;
+        }
         break;
     }
+
+    x = x + m_rect.xmin;
+    y = y + m_rect.ymin;
   }
 
   inline void wrap_pixel(float &x,
@@ -307,11 +316,14 @@ class MemoryBuffer {
           x = 0.0f;
         }
         if (x >= w) {
-          x = w;
+          x = w - 1;
         }
         break;
       case MemoryBufferExtend::Repeat:
         x = fmodf(x, w);
+        if (x < 0.0f) {
+          x += w;
+        }
         break;
     }
 
@@ -323,13 +335,19 @@ class MemoryBuffer {
           y = 0.0f;
         }
         if (y >= h) {
-          y = h;
+          y = h - 1;
         }
         break;
       case MemoryBufferExtend::Repeat:
         y = fmodf(y, h);
+        if (y < 0.0f) {
+          y += h;
+        }
         break;
     }
+
+    x = x + m_rect.xmin;
+    y = y + m_rect.ymin;
   }
 
   inline void read(float *result,



More information about the Bf-blender-cvs mailing list