diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index 847f4d4..9eafd92 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -153,6 +153,22 @@ proc minifyBy2*(mask: Mask, power = 1): Mask {.raises: [PixieError].} = # Set src as this result for if we do another power src = result +proc magnifyBy2*(mask: Mask, power = 1): Mask {.raises: [PixieError].} = + ## Scales mask up by 2 ^ power. + if power < 0: + raise newException(PixieError, "Cannot magnifyBy2 with negative power") + + let scale = 2 ^ power + result = newMask(mask.width * scale, mask.height * scale) + for y in 0 ..< result.height: + for x in 0 ..< mask.width: + let + value = mask.getValueUnsafe(x, y div scale) + scaledX = x * scale + idx = result.dataIndex(scaledX, y) + for i in 0 ..< scale: + result.data[idx + i] = value + proc fillUnsafe*( data: var seq[uint8], value: uint8, start, len: int ) {.raises: [].} = diff --git a/tests/images/masks/maskMagnified.png b/tests/images/masks/maskMagnified.png new file mode 100644 index 0000000..d2c9e78 Binary files /dev/null and b/tests/images/masks/maskMagnified.png differ diff --git a/tests/test_masks.nim b/tests/test_masks.nim index 54e2737..416b196 100644 --- a/tests/test_masks.nim +++ b/tests/test_masks.nim @@ -36,6 +36,12 @@ block: writeFile("tests/images/masks/maskMinified.png", minified.encodePng()) +block: + let + a = readImage("tests/images/masks/maskMinified.png") + b = a.magnifyBy2() + b.writeFile("tests/images/masks/maskMagnified.png") + block: let image = newImage(100, 100) image.fill(rgba(255, 100, 100, 255))