From d8afee9bf3283089b8a0e990513298372f176223 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Tue, 17 Aug 2021 15:15:35 -0500 Subject: [PATCH] superImage --- src/pixie/images.nim | 32 ++++++++------------------------ tests/images/superimage5.png | Bin 519 -> 520 bytes 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index cd4a4a3..0eb4a69 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -170,30 +170,6 @@ proc subImage*(image: Image, x, y, w, h: int): Image = w * 4 ) -proc superImage*(image: Image, x, y, w, h: int): Image = - ## Either cuts a sub image or returns a super image with padded transparency. - if x >= 0 and x + w <= image.width and y >= 0 and y + h <= image.height: - result = image.subImage(x, y, w, h) - elif abs(x) >= image.width or abs(y) >= image.height: - # Nothing to copy, just an empty new image - result = newImage(w, h) - else: - let - readOffsetX = max(x, 0) - readOffsetY = max(y, 0) - writeOffsetX = max(0 - x, 0) - writeOffsetY = max(0 - y, 0) - copyWidth = max(min(image.width, w) - abs(x), 0) - copyHeight = max(min(image.height, h) - abs(y), 0) - - result = newImage(w, h) - for y2 in 0 ..< copyHeight: - copyMem( - result.data[result.dataIndex(writeOffsetX, writeOffsetY + y2)].addr, - image.data[image.dataIndex(readOffsetX, readOffsetY + y2)].addr, - copyWidth * 4 - ) - proc diff*(master, image: Image): (float32, Image) = ## Compares the parameters and returns a score and image of the difference. let @@ -882,5 +858,13 @@ proc shadow*( result.fill(color) result.draw(shifted, blendMode = bmMask) +proc superImage*(image: Image, x, y, w, h: int): Image = + ## Either cuts a sub image or returns a super image with padded transparency. + if x >= 0 and x + w <= image.width and y >= 0 and y + h <= image.height: + result = image.subImage(x, y, w, h) + else: + result = newImage(w, h) + result.draw(image, translate(vec2(-x.float32, -y.float32)), bmOverwrite) + when defined(release): {.pop.} diff --git a/tests/images/superimage5.png b/tests/images/superimage5.png index 4ed0c8eddaa9c098efdaabda9c21c6abd02c39de..0c4423a92853d2558a8ca18075ec7ac98cc3e718 100644 GIT binary patch literal 520 zcmeAS@N?(olHy`uVBq!ia0vp^6(G#P1|%(0%q}r7FrN2xaSW+oe0ygj-ys7YmJ1$# zDtnYJI0w$g2sb*Y49@#Az|7;V=eq=W9cM>6*9y=O@SC-e&Y|-?e}5 z>f-o+@R%Q{)Y4>$5h!qPK7R2*6I;1Sg$%D=#-QiU={Ngfs977|&-UlD^+|VTyWtaSW+oe0%30SF?ct%LRw} znEiW>-V<-h4VS%Vd~mjtTCq=DcLo!m`hx-tqTKGm_p0@8f1a<7zrF39?f0$U;@|H6 z%qahm%_8jmJC-{N54za;FFs)7U6=7ef;aENpy$r;min_-vo`)do6XO^EYn$PVw(TA z9Q9N{^?UjB2J!zJ*C+ou_WDiwwo)E74vRSrhdHT4+)-tew>Q0hLh4V^|9N%{=ZuLr b_zt_gTe~DWM4fCb-}@