commit
41ec280864
|
@ -116,6 +116,7 @@ exportRefObject Image:
|
|||
getColor
|
||||
setColor
|
||||
fill(Image, Color)
|
||||
fill(Image, Paint)
|
||||
flipHorizontal
|
||||
flipVertical
|
||||
subImage
|
||||
|
|
|
@ -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)
|
||||
|
|
BIN
tests/paths/fillImagePaint.png
Normal file
BIN
tests/paths/fillImagePaint.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
BIN
tests/paths/fillTiledImagePaint.png
Normal file
BIN
tests/paths/fillTiledImagePaint.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue