diff --git a/bindings/bindings.nim b/bindings/bindings.nim index b47c7f6..5e1cb3d 100644 --- a/bindings/bindings.nim +++ b/bindings/bindings.nim @@ -116,6 +116,7 @@ exportRefObject Image: getColor setColor fill(Image, Color) + fill(Image, Paint) flipHorizontal flipVertical subImage diff --git a/src/pixie.nim b/src/pixie.nim index 9a38c79..bb7ad28 100644 --- a/src/pixie.nim +++ b/src/pixie.nim @@ -1,7 +1,7 @@ import bumpy, chroma, flatty/binny, os, pixie/common, pixie/contexts, pixie/fileformats/bmp, pixie/fileformats/gif, pixie/fileformats/jpeg, pixie/fileformats/png, pixie/fileformats/ppm, pixie/fileformats/qoi, - pixie/fileformats/svg, pixie/fonts, pixie/images, pixie/masks, pixie/paints, + pixie/fileformats/svg, pixie/fonts, pixie/images, pixie/internal, pixie/masks, pixie/paints, pixie/paths, strutils, vmath export bumpy, chroma, common, contexts, fonts, images, masks, paints, paths, vmath @@ -142,3 +142,16 @@ proc writeFile*(mask: Mask, filePath: string) {.raises: [PixieError].} = writeFile(filePath, mask.encodeMask(fileFormat)) except IOError as e: raise newException(PixieError, e.msg, e) + +proc fill*(image: Image, paint: Paint) {.raises: [PixieError].} = + ## Fills the image with the paint. + case paint.kind: + of SolidPaint: + fillUnsafe(image.data, paint.color, 0, image.data.len) + of ImagePaint, TiledImagePaint: + fillUnsafe(image.data, rgbx(0, 0, 0, 0), 0, image.data.len) + let path = newPath() + path.rect(0, 0, image.width.float32, image.height.float32) + image.fillPath(path, paint) + of LinearGradientPaint, RadialGradientPaint, AngularGradientPaint: + image.fillGradient(paint) diff --git a/src/pixie/paints.nim b/src/pixie/paints.nim index 1c7d312..4f76b32 100644 --- a/src/pixie/paints.nim +++ b/src/pixie/paints.nim @@ -1,4 +1,4 @@ -import chroma, common, images, simd, vmath +import chroma, common, images, internal, simd, vmath type PaintKind* = enum diff --git a/tests/test_images.nim b/tests/test_images.nim index 1405b5c..90ee301 100644 --- a/tests/test_images.nim +++ b/tests/test_images.nim @@ -252,3 +252,8 @@ block: for i in 0 ..< premultiplied.len: doAssert premultiplied[i] == converted[i] doAssert colors[i].rgbx == converted[i] + +block: + let image = newImage(100, 100) + image.fill("white") + doAssert image[10, 10] == rgba(255, 255, 255, 255)