diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index ea7b718..465dd86 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -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: diff --git a/tests/masks/drawPolygon.png b/tests/masks/drawPolygon.png index abd187e..c16c400 100644 Binary files a/tests/masks/drawPolygon.png and b/tests/masks/drawPolygon.png differ diff --git a/tests/masks/negativeSpread.png b/tests/masks/negativeSpread.png new file mode 100644 index 0000000..0dcc9f3 Binary files /dev/null and b/tests/masks/negativeSpread.png differ diff --git a/tests/masks/strokePolygon.png b/tests/masks/strokePolygon.png index c647585..3ba0712 100644 Binary files a/tests/masks/strokePolygon.png and b/tests/masks/strokePolygon.png differ diff --git a/tests/test_masks.nim b/tests/test_masks.nim index f0ae841..0b9d105 100644 --- a/tests/test_masks.nim +++ b/tests/test_masks.nim @@ -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)