get smooth a bit smarter (faster in solid color case)
This commit is contained in:
parent
68d29bf5a9
commit
32c3072e0a
3 changed files with 60 additions and 7 deletions
|
@ -535,11 +535,18 @@ proc getRgbaSmooth*(image: Image, x, y: float32, wrapped = false): ColorRGBX =
|
||||||
x0y1 = image[x0, y1]
|
x0y1 = image[x0, y1]
|
||||||
x1y1 = image[x1, y1]
|
x1y1 = image[x1, y1]
|
||||||
|
|
||||||
let
|
var topMix = x0y0
|
||||||
|
if xFractional > 0 and x0y0 != x1y0:
|
||||||
topMix = lerp(x0y0, x1y0, xFractional)
|
topMix = lerp(x0y0, x1y0, xFractional)
|
||||||
|
|
||||||
|
var bottomMix = x0y1
|
||||||
|
if xFractional > 0 and x0y1 != x1y1:
|
||||||
bottomMix = lerp(x0y1, x1y1, xFractional)
|
bottomMix = lerp(x0y1, x1y1, xFractional)
|
||||||
|
|
||||||
lerp(topMix, bottomMix, yFractional)
|
if yFractional != 0 and topMix != bottomMix:
|
||||||
|
lerp(topMix, bottomMix, yFractional)
|
||||||
|
else:
|
||||||
|
topMix
|
||||||
|
|
||||||
proc drawCorrect(
|
proc drawCorrect(
|
||||||
a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal
|
a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal
|
||||||
|
@ -678,9 +685,11 @@ proc drawUber(a, b: Image | Mask, mat = mat3(), blendMode = bmNormal) =
|
||||||
zeroMem(a.data[a.dataIndex(0, y)].addr, 4 * xMin)
|
zeroMem(a.data[a.dataIndex(0, y)].addr, 4 * xMin)
|
||||||
|
|
||||||
if smooth:
|
if smooth:
|
||||||
|
var srcPos = p + dx * xMin.float32 + dy * y.float32
|
||||||
|
srcPos = vec2(max(0, srcPos.x), max(0, srcPos.y))
|
||||||
|
|
||||||
for x in xMin ..< xMax:
|
for x in xMin ..< xMax:
|
||||||
let
|
let
|
||||||
srcPos = p + dx * x.float32 + dy * y.float32
|
|
||||||
xFloat = srcPos.x - h
|
xFloat = srcPos.x - h
|
||||||
yFloat = srcPos.y - h
|
yFloat = srcPos.y - h
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
|
@ -701,6 +710,9 @@ proc drawUber(a, b: Image | Mask, mat = mat3(), blendMode = bmNormal) =
|
||||||
else: # b is a Mask
|
else: # b is a Mask
|
||||||
let sample = b.getValueSmooth(xFloat, yFloat)
|
let sample = b.getValueSmooth(xFloat, yFloat)
|
||||||
a.setValueUnsafe(x, y, masker(backdrop, sample))
|
a.setValueUnsafe(x, y, masker(backdrop, sample))
|
||||||
|
|
||||||
|
srcPos += dx
|
||||||
|
|
||||||
else:
|
else:
|
||||||
var x = xMin
|
var x = xMin
|
||||||
when defined(amd64) and not defined(pixieNoSimd):
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
|
|
|
@ -173,10 +173,18 @@ proc getValueSmooth*(mask: Mask, x, y: float32): uint8 =
|
||||||
x0y1 = mask[x0, y1]
|
x0y1 = mask[x0, y1]
|
||||||
x1y1 = mask[x1, y1]
|
x1y1 = mask[x1, y1]
|
||||||
|
|
||||||
|
var topMix = x0y0
|
||||||
|
if xFractional > 0 and x0y0 != x1y0:
|
||||||
topMix = lerp(x0y0, x1y0, xFractional)
|
topMix = lerp(x0y0, x1y0, xFractional)
|
||||||
|
|
||||||
|
var bottomMix = x0y1
|
||||||
|
if xFractional > 0 and x0y1 != x1y1:
|
||||||
bottomMix = lerp(x0y1, x1y1, xFractional)
|
bottomMix = lerp(x0y1, x1y1, xFractional)
|
||||||
|
|
||||||
lerp(topMix, bottomMix, yFractional)
|
if yFractional != 0 and topMix != bottomMix:
|
||||||
|
lerp(topMix, bottomMix, yFractional)
|
||||||
|
else:
|
||||||
|
topMix
|
||||||
|
|
||||||
proc spread*(mask: Mask, spread: float32) =
|
proc spread*(mask: Mask, spread: float32) =
|
||||||
## Grows the mask by spread.
|
## Grows the mask by spread.
|
||||||
|
|
|
@ -40,7 +40,40 @@ block:
|
||||||
a.fill(rgba(255, 0, 0, 255))
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw big-on-bigger Smooth bmNormal":
|
timeIt "draw [scale 0.5]":
|
||||||
|
a.draw(b, translate(vec2(25, 25)) * scale(vec2(0.5, 0.5)), bmNormal)
|
||||||
|
keep(b)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let
|
||||||
|
a = newImage(1000, 1000)
|
||||||
|
b = newImage(500, 500)
|
||||||
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
|
timeIt "draw Smooth [x translate]":
|
||||||
|
a.draw(b, translate(vec2(25.2, 0)), bmNormal)
|
||||||
|
keep(b)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let
|
||||||
|
a = newImage(1000, 1000)
|
||||||
|
b = newImage(500, 500)
|
||||||
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
|
timeIt "draw Smooth [y translate]":
|
||||||
|
a.draw(b, translate(vec2(0, 25.2)), bmNormal)
|
||||||
|
keep(b)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let
|
||||||
|
a = newImage(1000, 1000)
|
||||||
|
b = newImage(500, 500)
|
||||||
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
|
timeIt "draw Smooth [x + y translate]":
|
||||||
a.draw(b, translate(vec2(25.2, 25.2)), bmNormal)
|
a.draw(b, translate(vec2(25.2, 25.2)), bmNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
|
@ -51,8 +84,8 @@ block:
|
||||||
a.fill(rgba(255, 0, 0, 255))
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw big-on-bigger bmNormal scale(0.5)":
|
timeIt "draw Smooth [rotate 45 deg]":
|
||||||
a.draw(b, translate(vec2(25, 25)) * scale(vec2(0.5, 0.5)), bmNormal)
|
a.draw(b, translate(vec2(0, 500)) * rotate(toRadians(45)), bmNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
|
Loading…
Reference in a new issue