drawCorrect knows smooth or not

This commit is contained in:
Ryan Oldenburg 2020-12-09 02:28:49 -06:00
parent c83b3215d0
commit cdadfd1cdd
2 changed files with 21 additions and 3 deletions

View file

@ -406,13 +406,22 @@ proc drawCorrect*(a, b: Image, mat: Mat3, blendMode: BlendMode) =
minFilterBy2 /= 2
matInv = matInv * scale(vec2(0.5, 0.5))
let smooth = not(dx.length == 1.0 and dy.length == 1.0 and
mat[2, 0].fractional == 0.0 and mat[2, 1].fractional == 0.0)
let mixer = blendMode.mixer()
for y in 0 ..< a.height:
for x in 0 ..< a.width:
let
srcPos = matInv * vec2(x.float32 + h, y.float32 + h)
xFloat = srcPos.x - h
yFloat = srcPos.y - h
rgba = a.getRgbaUnsafe(x, y)
rgba2 = b.getRgbaSmooth(srcPos.x - h, srcPos.y - h)
rgba2 =
if smooth:
b.getRgbaSmooth(xFloat, yFloat)
else:
b[xFloat.round.int, yFloat.round.int]
a.setRgbaUnsafe(x, y, mixer(rgba, rgba2))
const h = 0.5.float32
@ -489,7 +498,7 @@ proc draw*(a, b: Image, mat: Mat3, blendMode: BlendMode) =
var
matInv = mat.inverse()
# compute movement vectors
# Compute movement vectors
p = matInv * vec2(0 + h, 0 + h)
dx = matInv * vec2(1 + h, 0 + h) - p
dy = matInv * vec2(0 + h, 1 + h) - p

View file

@ -1,7 +1,6 @@
import pixie, chroma, vmath, benchy
block:
var c: Image
var a = newImage(1000, 1000)
a.fill(rgba(255, 0, 0, 255))
var b = newImage(500, 500)
@ -21,6 +20,16 @@ block:
a.draw(b, translate(vec2(25, 25)), bmNormal)
keep(b)
block:
var a = newImage(1000, 1000)
a.fill(rgba(255, 0, 0, 255))
var b = newImage(500, 500)
b.fill(rgba(0, 255, 0, 255))
timeIt "drawCorrect Smooth bmNormal":
a.drawCorrect(b, translate(vec2(25.2, 25.2)), bmNormal)
keep(b)
block:
var a = newImage(1000, 1000)
a.fill(rgba(255, 0, 0, 255))