From 662c79e0fbd761f01f52e6cfde1ffec81ab57fba Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 8 Feb 2021 16:43:22 -0600 Subject: [PATCH] draw mask --- src/pixie/images.nim | 14 +++++++++++--- tests/test_images.nim | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 2524046..191d12d 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -263,7 +263,13 @@ proc toStraightAlpha*(image: Image) = c.g = ((c.g.uint32 * multiplier) div 255).uint8 c.b = ((c.b.uint32 * multiplier) div 255).uint8 -proc maskCorrect*(image: Image, mask: Mask, mat = mat3()) = +proc drawCorrect*(image: Image, mask: Mask, mat = mat3(), blendMode = bmMask) = + if blendMode notin {bmMask}: + raise newException( + PixieError, + "Blend mode " & $blendMode & " not supported for masks" + ) + var matInv = mat.inverse() mask = mask @@ -294,8 +300,10 @@ proc maskCorrect*(image: Image, mask: Mask, mat = mat3()) = ) image.setRgbaUnsafe(x, y, blended) -proc mask*(image: Image, mask: Mask, pos = vec2(0, 0)) {.inline.} = - image.maskCorrect(mask, translate(pos)) +proc draw*( + image: Image, mask: Mask, pos = vec2(0, 0), blendMode = bmMask +) {.inline.} = + image.drawCorrect(mask, translate(pos), blendMode) when defined(release): {.pop.} diff --git a/tests/test_images.nim b/tests/test_images.nim index 829f6dd..6f02f09 100644 --- a/tests/test_images.nim +++ b/tests/test_images.nim @@ -102,6 +102,6 @@ block: let mask = newMask(image.width, image.height) mask.fillPath(path) - image.mask(mask) + image.draw(mask) image.toStraightAlpha() image.writeFile("tests/images/circleMask.png")