Fix #372 - Add negative spread.

This commit is contained in:
treeform 2022-03-18 19:24:56 -07:00
parent d3c727198b
commit 42bedda0a7
5 changed files with 20 additions and 2 deletions

View file

@ -234,14 +234,21 @@ proc getValueSmooth*(mask: Mask, x, y: float32): uint8 {.raises: [].} =
else:
topMix
proc invert(mask: Mask) {.raises: [].} =
## Makes inverts all values - creates a negative of the mask.
for i in 0 ..< mask.data.len:
mask.data[i] = 255 - mask.data[i]
proc spread*(mask: Mask, spread: float32) {.raises: [PixieError].} =
## Grows the mask by spread.
let spread = round(spread).int
if spread == 0:
return
if spread < 0:
raise newException(PixieError, "Cannot apply negative spread")
mask.invert()
spread(mask, -spread.float32)
mask.invert()
return
# Spread in the X direction. Store with dimensions swapped for reading later.
let spreadX = newMask(mask.height, mask.width)
for y in 0 ..< mask.height:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 853 B

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -92,6 +92,17 @@ block:
a.writeFile("tests/masks/spread.png")
block:
let path = newPath()
path.rect(40, 40, 20, 20)
let a = newMask(100, 100)
a.fillPath(path)
a.spread(-5)
a.writeFile("tests/masks/negativeSpread.png")
block:
let mask = newMask(100, 100)