This commit is contained in:
Ryan Oldenburg 2022-07-31 13:32:12 -05:00
parent dd7bf9f210
commit 6582f7c4ca
2 changed files with 12 additions and 12 deletions

View file

@ -436,26 +436,26 @@ proc drawCorrect(
blended = blender(backdrop, sample) blended = blender(backdrop, sample)
a.unsafe[x, y] = blended a.unsafe[x, y] = blended
proc blitLine( proc blendLine(
a, b: ptr UncheckedArray[ColorRGBX], len: int, blender: Blender a, b: ptr UncheckedArray[ColorRGBX], len: int, blender: Blender
) {.inline.} = ) {.inline.} =
for i in 0 ..< len: for i in 0 ..< len:
a[i] = blender(a[i], b[i]) a[i] = blender(a[i], b[i])
proc blitLineOverwrite( proc blendLineOverwrite(
a, b: ptr UncheckedArray[ColorRGBX], len: int a, b: ptr UncheckedArray[ColorRGBX], len: int
) {.inline.} = ) {.inline.} =
copyMem(a[0].addr, b[0].addr, len * 4) copyMem(a[0].addr, b[0].addr, len * 4)
proc blitLineNormal(a, b: ptr UncheckedArray[ColorRGBX], len: int) {.hasSimd.} = proc blendLineNormal(a, b: ptr UncheckedArray[ColorRGBX], len: int) {.hasSimd.} =
for i in 0 ..< len: for i in 0 ..< len:
a[i] = blendNormal(a[i], b[i]) a[i] = blendNormal(a[i], b[i])
proc blitLineMask(a, b: ptr UncheckedArray[ColorRGBX], len: int) {.hasSimd.} = proc blendLineMask(a, b: ptr UncheckedArray[ColorRGBX], len: int) {.hasSimd.} =
for i in 0 ..< len: for i in 0 ..< len:
a[i] = blendMask(a[i], b[i]) a[i] = blendMask(a[i], b[i])
proc blitRect(a, b: Image, pos: Ivec2, blendMode: BlendMode) = proc blendRect(a, b: Image, pos: Ivec2, blendMode: BlendMode) =
let let
px = pos.x.int px = pos.x.int
py = pos.y.int py = pos.y.int
@ -474,14 +474,14 @@ proc blitRect(a, b: Image, pos: Ivec2, blendMode: BlendMode) =
case blendMode: case blendMode:
of NormalBlend: of NormalBlend:
for y in yStart ..< yEnd: for y in yStart ..< yEnd:
blitLineNormal( blendLineNormal(
a.getUncheckedArray(xStart + px, y + py), a.getUncheckedArray(xStart + px, y + py),
b.getUncheckedArray(xStart, y), b.getUncheckedArray(xStart, y),
xEnd - xStart xEnd - xStart
) )
of OverwriteBlend: of OverwriteBlend:
for y in yStart ..< yEnd: for y in yStart ..< yEnd:
blitLineOverwrite( blendLineOverwrite(
a.getUncheckedArray(xStart + px, y + py), a.getUncheckedArray(xStart + px, y + py),
b.getUncheckedArray(xStart, y), b.getUncheckedArray(xStart, y),
xEnd - xStart xEnd - xStart
@ -493,7 +493,7 @@ proc blitRect(a, b: Image, pos: Ivec2, blendMode: BlendMode) =
for y in yStart ..< yEnd: for y in yStart ..< yEnd:
if xStart + px > 0: if xStart + px > 0:
zeroMem(a.data[a.dataIndex(0, y + py)].addr, (xStart + px) * 4) zeroMem(a.data[a.dataIndex(0, y + py)].addr, (xStart + px) * 4)
blitLineMask( blendLineMask(
a.getUncheckedArray(xStart + px, y + py), a.getUncheckedArray(xStart + px, y + py),
b.getUncheckedArray(xStart, y), b.getUncheckedArray(xStart, y),
xEnd - xStart xEnd - xStart
@ -511,7 +511,7 @@ proc blitRect(a, b: Image, pos: Ivec2, blendMode: BlendMode) =
else: else:
let blender = blendMode.blender() let blender = blendMode.blender()
for y in yStart ..< yEnd: for y in yStart ..< yEnd:
blitLine( blendLine(
a.getUncheckedArray(xStart + px, y + py), a.getUncheckedArray(xStart + px, y + py),
b.getUncheckedArray(xStart, y), b.getUncheckedArray(xStart, y),
xEnd - xStart, xEnd - xStart,
@ -559,7 +559,7 @@ proc draw*(
if hasRotationOrScaling or smooth: if hasRotationOrScaling or smooth:
a.drawCorrect(b, inverseTransform.inverse(), blendMode, false) a.drawCorrect(b, inverseTransform.inverse(), blendMode, false)
else: else:
a.blitRect(b, ivec2(transform[2, 0].int32, transform[2, 1].int32), blendMode) a.blendRect(b, ivec2(transform[2, 0].int32, transform[2, 1].int32), blendMode)
proc drawTiled*( proc drawTiled*(
dst, src: Image, mat: Mat3, blendMode = NormalBlend dst, src: Image, mat: Mat3, blendMode = NormalBlend

View file

@ -568,7 +568,7 @@ proc blendLineNormalSse2*(
for i in i ..< len: for i in i ..< len:
line[i] = blendNormal(line[i], rgbx) line[i] = blendNormal(line[i], rgbx)
proc blitLineNormalSse2*( proc blendLineNormalSse2*(
a, b: ptr UncheckedArray[ColorRGBX], len: int a, b: ptr UncheckedArray[ColorRGBX], len: int
) {.simd.} = ) {.simd.} =
var i: int var i: int
@ -653,7 +653,7 @@ proc blendLineMaskSse2*(
for i in i ..< len: for i in i ..< len:
line[i] = blendMask(line[i], rgbx) line[i] = blendMask(line[i], rgbx)
proc blitLineMaskSse2*( proc blendLineMaskSse2*(
a, b: ptr UncheckedArray[ColorRGBX], len: int a, b: ptr UncheckedArray[ColorRGBX], len: int
) {.simd.} = ) {.simd.} =
var i: int var i: int