image.subImage(Rect)
This commit is contained in:
parent
4effe38236
commit
19ec00c81b
2 changed files with 7 additions and 1 deletions
|
@ -129,6 +129,12 @@ proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} =
|
||||||
w * 4
|
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].} =
|
proc diff*(master, image: Image): (float32, Image) {.raises: [PixieError].} =
|
||||||
## Compares the parameters and returns a score and image of the difference.
|
## Compares the parameters and returns a score and image of the difference.
|
||||||
let
|
let
|
||||||
|
|
|
@ -259,5 +259,5 @@ block:
|
||||||
)
|
)
|
||||||
let rect = image.opaqueBounds()
|
let rect = image.opaqueBounds()
|
||||||
doAssert rect == rect(6.0, 6.0, 48.0, 48.0)
|
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")
|
trimmedImage.xray("tests/images/opaqueBounds.png")
|
||||||
|
|
Loading…
Reference in a new issue