image.subImage(Rect)

This commit is contained in:
treeform 2022-08-01 20:36:10 -07:00
parent 4effe38236
commit 19ec00c81b
2 changed files with 7 additions and 1 deletions

View file

@ -129,6 +129,12 @@ proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} =
w * 4
)
proc subImage*(image: Image, rect: Rect): Image {.raises: [PixieError].} =
## Gets a sub image from this image via rectangle.
## Rectangle is snapped/expanded to whole pixels first.
let r = rect.snapToPixels()
image.subImage(r.x.int, r.y.int, r.w.int, r.h.int)
proc diff*(master, image: Image): (float32, Image) {.raises: [PixieError].} =
## Compares the parameters and returns a score and image of the difference.
let

View file

@ -259,5 +259,5 @@ block:
)
let rect = image.opaqueBounds()
doAssert rect == rect(6.0, 6.0, 48.0, 48.0)
let trimmedImage = image.subImage(rect.x.int, rect.y.int, rect.w.int, rect.h.int)
let trimmedImage = image.subImage(rect)
trimmedImage.xray("tests/images/opaqueBounds.png")