Fix #372 - Add negative spread.
This commit is contained in:
parent
d3c727198b
commit
42bedda0a7
5 changed files with 20 additions and 2 deletions
|
@ -234,14 +234,21 @@ proc getValueSmooth*(mask: Mask, x, y: float32): uint8 {.raises: [].} =
|
||||||
else:
|
else:
|
||||||
topMix
|
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].} =
|
proc spread*(mask: Mask, spread: float32) {.raises: [PixieError].} =
|
||||||
## Grows the mask by spread.
|
## Grows the mask by spread.
|
||||||
let spread = round(spread).int
|
let spread = round(spread).int
|
||||||
if spread == 0:
|
if spread == 0:
|
||||||
return
|
return
|
||||||
if spread < 0:
|
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.
|
# Spread in the X direction. Store with dimensions swapped for reading later.
|
||||||
let spreadX = newMask(mask.height, mask.width)
|
let spreadX = newMask(mask.height, mask.width)
|
||||||
for y in 0 ..< mask.height:
|
for y in 0 ..< mask.height:
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 853 B After Width: | Height: | Size: 737 B |
BIN
tests/masks/negativeSpread.png
Normal file
BIN
tests/masks/negativeSpread.png
Normal file
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 |
|
@ -92,6 +92,17 @@ block:
|
||||||
|
|
||||||
a.writeFile("tests/masks/spread.png")
|
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:
|
block:
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue