safeguards

Fri, 27 Dec 2019 20:59:44 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 27 Dec 2019 20:59:44 +0200
changeset 29
05b11c96ef45
parent 28
d1f40f6654cb
child 30
0b25d9ef7af9

safeguards

src/ImFilter.jl file | annotate | diff | comparison | revisions
src/Translate.jl file | annotate | diff | comparison | revisions
--- a/src/ImFilter.jl	Wed Dec 25 17:42:32 2019 +0200
+++ b/src/ImFilter.jl	Fri Dec 27 20:59:44 2019 +0200
@@ -43,12 +43,12 @@
             tmp = 0.0
             it₁ = inside(i, a₁, b₁, 1, n)
             it₂ = inside(j, a₂, b₂, 1, m)
-            for p=it₁
+            @inbounds for p=it₁
                 @simd for q=it₂
-                    tmp += @inbounds(kp[p-o₁, q-o₂]*b[i+p,j+q])
+                    tmp += kp[p-o₁, q-o₂]*b[i+p,j+q]
                 end
             end
-            res[i, j] = tmp
+            @inbounds res[i, j] = tmp
         end
     end
 
--- a/src/Translate.jl	Wed Dec 25 17:42:32 2019 +0200
+++ b/src/Translate.jl	Fri Dec 27 20:59:44 2019 +0200
@@ -132,18 +132,18 @@
     vyʹ = (imy-by)/2 - v[2]
 
     # Target image indices within source image
-    px = max(ceil(Int, max(1, vxʹ + 1) - vxʹ), 1)
-    py = max(ceil(Int, max(1, vyʹ + 1) - vyʹ), 1)
-    qx = min(floor(Int, min(imx, vxʹ + bx) - vxʹ), bx)
-    qy = min(floor(Int, min(imy, vyʹ + by) - vyʹ), by)
+    px = min(max(ceil(Int, max(1, vxʹ + 1) - vxʹ), 1), bx)
+    py = min(max(ceil(Int, max(1, vyʹ + 1) - vyʹ), 1), by)
+    qx = max(min(floor(Int, min(imx, vxʹ + bx) - vxʹ), bx), 1)
+    qy = max(min(floor(Int, min(imy, vyʹ + by) - vyʹ), by), 1)
     
     @inbounds begin
         b[1:px-1, :] .= 0
-        b[qx+1:end, :] .= 0
+        b[qx+1:bx, :] .= 0
 
         Threads.@threads for i=px:qx
             b[i, 1:py-1] .= 0
-            b[i, qy+1:end] .= 0
+            b[i, qy+1:by] .= 0
             @simd for j=py:qy
                 b[i, j] = interpolate2d_quadrants(im, (i+vxʹ, j+vyʹ))
             end

mercurial