Merge pull request #496 from treeform/guzba
faster draw smooth using line gather then blend
This commit is contained in:
commit
5022a8afe7
2 changed files with 38 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
||||||
version = "4.4.0"
|
version = "5.0.0"
|
||||||
author = "Andre von Houck and Ryan Oldenburg"
|
author = "Andre von Houck and Ryan Oldenburg"
|
||||||
description = "Full-featured 2d graphics library for Nim."
|
description = "Full-featured 2d graphics library for Nim."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -561,7 +561,7 @@ proc drawSmooth(a, b: Image, transform: Mat3, blendMode: BlendMode) =
|
||||||
if blendMode == MaskBlend and yStart > 0:
|
if blendMode == MaskBlend and yStart > 0:
|
||||||
zeroMem(a.data[0].addr, yStart * a.width * 4)
|
zeroMem(a.data[0].addr, yStart * a.width * 4)
|
||||||
|
|
||||||
let blender = blendMode.blender()
|
var sampleLine = newSeq[ColorRGBX](a.width)
|
||||||
for y in yStart ..< yEnd:
|
for y in yStart ..< yEnd:
|
||||||
# Determine where we should start and stop drawing in the x dimension
|
# Determine where we should start and stop drawing in the x dimension
|
||||||
var
|
var
|
||||||
|
@ -582,21 +582,47 @@ proc drawSmooth(a, b: Image, transform: Mat3, blendMode: BlendMode) =
|
||||||
xStart = clamp(xMin.floor.int, 0, a.width)
|
xStart = clamp(xMin.floor.int, 0, a.width)
|
||||||
xEnd = clamp(xMax.ceil.int, 0, a.width)
|
xEnd = clamp(xMax.ceil.int, 0, a.width)
|
||||||
|
|
||||||
if blendMode == MaskBlend and xStart > 0:
|
|
||||||
zeroMem(a.data[a.dataIndex(0, y)].addr, xStart * 4)
|
|
||||||
|
|
||||||
var srcPos = p + dx * xStart.float32 + dy * y.float32
|
var srcPos = p + dx * xStart.float32 + dy * y.float32
|
||||||
srcPos = vec2(srcPos.x - h, srcPos.y - h)
|
srcPos = vec2(srcPos.x - h, srcPos.y - h)
|
||||||
for x in xStart ..< xEnd:
|
for x in xStart ..< xEnd:
|
||||||
let
|
sampleLine[x] = b.getRgbaSmooth(srcPos.x, srcPos.y)
|
||||||
backdrop = a.unsafe[x, y]
|
|
||||||
sample = b.getRgbaSmooth(srcPos.x, srcPos.y)
|
|
||||||
blended = blender(backdrop, sample)
|
|
||||||
a.unsafe[x, y] = blended
|
|
||||||
srcPos += dx
|
srcPos += dx
|
||||||
|
|
||||||
if blendMode == MaskBlend and a.width - xEnd > 0:
|
case blendMode:
|
||||||
zeroMem(a.data[a.dataIndex(xEnd, y)].addr, (a.width - xEnd) * 4)
|
of NormalBlend:
|
||||||
|
blendLineNormal(
|
||||||
|
a.getUncheckedArray(xStart, y),
|
||||||
|
cast[ptr UncheckedArray[ColorRGBX]](sampleLine[xStart].addr),
|
||||||
|
xEnd - xStart
|
||||||
|
)
|
||||||
|
|
||||||
|
of OverwriteBlend:
|
||||||
|
blendLineOverwrite(
|
||||||
|
a.getUncheckedArray(xStart, y),
|
||||||
|
cast[ptr UncheckedArray[ColorRGBX]](sampleLine[xStart].addr),
|
||||||
|
xEnd - xStart
|
||||||
|
)
|
||||||
|
|
||||||
|
of MaskBlend:
|
||||||
|
{.linearScanEnd.}
|
||||||
|
if blendMode == MaskBlend and xStart > 0:
|
||||||
|
zeroMem(a.data[a.dataIndex(0, y)].addr, xStart * 4)
|
||||||
|
|
||||||
|
blendLineMask(
|
||||||
|
a.getUncheckedArray(xStart, y),
|
||||||
|
cast[ptr UncheckedArray[ColorRGBX]](sampleLine[xStart].addr),
|
||||||
|
xEnd - xStart
|
||||||
|
)
|
||||||
|
|
||||||
|
if blendMode == MaskBlend and a.width - xEnd > 0:
|
||||||
|
zeroMem(a.data[a.dataIndex(xEnd, y)].addr, (a.width - xEnd) * 4)
|
||||||
|
else:
|
||||||
|
blendLine(
|
||||||
|
a.getUncheckedArray(xStart, y),
|
||||||
|
cast[ptr UncheckedArray[ColorRGBX]](sampleLine[xStart].addr),
|
||||||
|
xEnd - xStart,
|
||||||
|
blendMode.blender()
|
||||||
|
)
|
||||||
|
|
||||||
if blendMode == MaskBlend and a.height - yEnd > 0:
|
if blendMode == MaskBlend and a.height - yEnd > 0:
|
||||||
zeroMem(
|
zeroMem(
|
||||||
|
|
Loading…
Reference in a new issue