Merge pull request #335 from guzba/master

faster non-simd path here
This commit is contained in:
treeform 2021-12-04 17:27:21 -08:00 committed by GitHub
commit 44f3bcfa98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 9 deletions

View file

@ -95,7 +95,7 @@ proc setColor*(image: Image, x, y: int, color: Color) {.inline, raises: [].} =
proc fillUnsafe*(
data: var seq[ColorRGBX], color: SomeColor, start, len: int
) {.raises: [].} =
## Fills the image data with the parameter color starting at index start and
## Fills the image data with the color starting at index start and
## continuing for len indices.
let rgbx = color.asRgbx()
@ -126,7 +126,7 @@ proc fillUnsafe*(
data[j] = rgbx
proc fill*(image: Image, color: SomeColor) {.inline, raises: [].} =
## Fills the image with the parameter color.
## Fills the image with the color.
fillUnsafe(image.data, color, 0, image.data.len)
proc isOneColor*(image: Image): bool {.raises: [].} =
@ -565,7 +565,7 @@ proc blur*(
image.setRgbaUnsafe(x, y, rgbx(values))
proc newMask*(image: Image): Mask {.raises: [PixieError].} =
## Returns a new mask using the alpha values of the parameter image.
## Returns a new mask using the alpha values of the image.
result = newMask(image.width, image.height)
var i: int

View file

@ -172,12 +172,12 @@ proc magnifyBy2*(mask: Mask, power = 1): Mask {.raises: [PixieError].} =
proc fillUnsafe*(
data: var seq[uint8], value: uint8, start, len: int
) {.raises: [].} =
## Fills the mask data with the parameter value starting at index start and
## Fills the mask data with the value starting at index start and
## continuing for len indices.
nimSetMem(data[start].addr, value.cint, len)
proc fill*(mask: Mask, value: uint8) {.inline, raises: [].} =
## Fills the mask with the parameter value.
## Fills the mask with the value.
fillUnsafe(mask.data, value, 0, mask.data.len)
proc getValueSmooth*(mask: Mask, x, y: float32): uint8 {.raises: [].} =

View file

@ -2555,10 +2555,13 @@ proc fillImage(
let channels = [rgbx.r.uint32, rgbx.g.uint32, rgbx.b.uint32, rgbx.a.uint32]
for i in i ..< result.data.len:
let coverage = mask.data[i]
result.data[i].r = ((channels[0] * coverage) div 255).uint8
result.data[i].g = ((channels[1] * coverage) div 255).uint8
result.data[i].b = ((channels[2] * coverage) div 255).uint8
result.data[i].a = ((channels[3] * coverage) div 255).uint8
if coverage == 255:
result.data[i] = rgbx
elif coverage != 0:
result.data[i].r = ((channels[0] * coverage) div 255).uint8
result.data[i].g = ((channels[1] * coverage) div 255).uint8
result.data[i].b = ((channels[2] * coverage) div 255).uint8
result.data[i].a = ((channels[3] * coverage) div 255).uint8
proc fillImage*(
path: SomePath, width, height: int, color: SomeColor, windingRule = wrNonZero

BIN
tests/paths/pathHeart2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -131,6 +131,16 @@ block:
)
image.writeFile("tests/paths/pathHeart.png")
block:
let image = """
M 10,30
A 20,20 0,0,1 50,30
A 20,20 0,0,1 90,30
Q 90,60 50,90
Q 10,60 10,30 z
""".fillImage(100, 100, parseHtmlColor("#FC427B").rgba)
image.writeFile("tests/paths/pathHeart2.png")
block:
let image = newImage(100, 100)
image.fillPath(