Merge pull request #473 from treeform/guzba

image.fill(paint)
This commit is contained in:
Andre von Houck 2022-07-23 18:44:57 -07:00 committed by GitHub
commit 41ec280864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 1 deletions

View file

@ -116,6 +116,7 @@ exportRefObject Image:
getColor
setColor
fill(Image, Color)
fill(Image, Paint)
flipHorizontal
flipVertical
subImage

View file

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -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)

View file

@ -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")