Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/bindings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ exportRefObject Image:
getColor
setColor
fill(Image, Color)
fill(Image, Paint)
flipHorizontal
flipVertical
subImage
Expand Down
15 changes: 14 additions & 1 deletion src/pixie.nim
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Binary file added tests/paths/fillImagePaint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/paths/fillTiledImagePaint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/test_images.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 22 additions & 0 deletions tests/test_paints.nim
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,25 @@ block:
let image = newImage(100, 100)
image.fillPath(heartShape, paint)
image.xray("tests/paths/gradientAngularOpacity.png")

block:
let paint = newPaint(ImagePaint)
paint.image = readImage("tests/fileformats/png/mandrill.png")
paint.imageMat = scale(vec2(0.2, 0.2))
paint.opacity = 0.5

let image = newImage(128, 128)
image.fill(rgbx(0, 255, 0, 255))
image.fill(paint)
image.xray("tests/paths/fillImagePaint.png")

block:
let paint = newPaint(TiledImagePaint)
paint.image = readImage("tests/fileformats/png/mandrill.png")
paint.imageMat = scale(vec2(0.1, 0.1))
paint.opacity = 0.5

let image = newImage(128, 128)
image.fill(rgbx(0, 255, 0, 255))
image.fill(paint)
image.xray("tests/paths/fillTiledImagePaint.png")