Disable fill optimization for now.

This commit is contained in:
treeform 2022-01-30 12:15:13 -08:00
parent 3a590eea1e
commit 2da986d0fe
4 changed files with 50 additions and 29 deletions

View file

@ -595,7 +595,7 @@ proc getRgbaSmooth*(
topMix
proc drawCorrect(
a, b: Image | Mask, transform = mat3(), tiled = false, blendMode = bmNormal
a, b: Image | Mask, transform = mat3(), blendMode = bmNormal, tiled = false
) {.raises: [PixieError].} =
## Draws one image onto another using matrix with color blending.
@ -792,15 +792,16 @@ proc drawUber(
sy = srcPos.y.int
var sx = srcPos.x.int
when type(a) is Image and type(b) is Image:
if blendMode in {bmNormal, bmOverwrite} and
isOpaque(b.data, b.dataIndex(xStart, y), xStop - xStart):
copyMem(
a.data[a.dataIndex(x, y)].addr,
b.data[b.dataIndex(sx, sy)].addr,
(xStop - xStart) * 4
)
continue
# TODO Fix
# when type(a) is Image and type(b) is Image:
# if blendMode in {bmNormal, bmOverwrite} and
# isOpaque(b.data, b.dataIndex(sx, sy), xStop - sx):
# copyMem(
# a.data[a.dataIndex(x, y)].addr,
# b.data[b.dataIndex(sx, sy)].addr,
# (xStop - xStart) * 4
# )
# continue
when defined(amd64) and not defined(pixieNoSimd):
case blendMode:
@ -1142,7 +1143,7 @@ proc draw*(
proc drawTiled*(
dst, src: Image, mat: Mat3, blendMode = bmNormal
) {.raises: [PixieError].} =
dst.drawCorrect(src, mat, true, blendMode)
dst.drawCorrect(src, mat, blendMode, true)
proc resize*(srcImage: Image, width, height: int): Image {.raises: [PixieError].} =
## Resize an image to a given height and width.

View file

@ -139,25 +139,26 @@ proc toPremultipliedAlpha*(data: var seq[ColorRGBA | ColorRGBX]) {.raises: [].}
proc isOpaque*(data: var seq[ColorRGBX], start, len: int): bool =
result = true
var i: int
when defined(amd64) and not defined(pixieNoSimd):
let
vec255 = mm_set1_epi32(cast[int32](uint32.high))
colorMask = mm_set1_epi32(cast[int32]([255.uint8, 255, 255, 0]))
for _ in 0 ..< len div 16:
let
values0 = mm_loadu_si128(data[i + 0].addr)
values1 = mm_loadu_si128(data[i + 4].addr)
values2 = mm_loadu_si128(data[i + 8].addr)
values3 = mm_loadu_si128(data[i + 12].addr)
values01 = mm_and_si128(values0, values1)
values23 = mm_and_si128(values2, values3)
values = mm_or_si128(mm_and_si128(values01, values23), colorMask)
if mm_movemask_epi8(mm_cmpeq_epi8(values, vec255)) != 0xffff:
return false
i += 16
var i: int = start
# TODO FIX:
# when defined(amd64) and not defined(pixieNoSimd):
# let
# vec255 = mm_set1_epi32(cast[int32](uint32.high))
# colorMask = mm_set1_epi32(cast[int32]([255.uint8, 255, 255, 0]))
# for _ in start div 16 ..< (start + len) div 16:
# let
# values0 = mm_loadu_si128(data[i + 0].addr)
# values1 = mm_loadu_si128(data[i + 4].addr)
# values2 = mm_loadu_si128(data[i + 8].addr)
# values3 = mm_loadu_si128(data[i + 12].addr)
# values01 = mm_and_si128(values0, values1)
# values23 = mm_and_si128(values2, values3)
# values = mm_or_si128(mm_and_si128(values01, values23), colorMask)
# if mm_movemask_epi8(mm_cmpeq_epi8(values, vec255)) != 0xffff:
# return false
# i += 16
for j in i ..< len:
for j in i ..< start + len:
if data[j].a != 255:
return false

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

View file

@ -1,5 +1,24 @@
import chroma, pixie, pixie/fileformats/png, strformat
block:
let pathStr = """
M 0 0
L 20 0
L 20 20
L 0 20
z
"""
let
image = newImage(20, 20)
strokeImage = newImage(20, 20)
image.fillPath(pathStr, color(1.0, 0.5, 0.25, 1.0))
strokeImage.strokePath(pathStr, color(1, 1, 1, 1), strokeWidth = 4)
image.draw(strokeImage)
image.writeFile("tests/paths/fillOptimization.png")
doAssert image[10, 10] == rgbx(255, 127, 63, 255)
block:
let pathStr = """
m 1 2 3 4 5 6