From ea1aef7bd20dbb3660f0f6352095ae3e9102de7e Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sun, 3 Oct 2021 15:31:39 -0500 Subject: [PATCH] mask magnifyBy2 --- src/pixie/masks.nim | 16 ++++++++++++++++ tests/images/masks/maskMagnified.png | Bin 0 -> 944 bytes tests/test_masks.nim | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/images/masks/maskMagnified.png diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index 847f4d4..9eafd92 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -153,6 +153,22 @@ proc minifyBy2*(mask: Mask, power = 1): Mask {.raises: [PixieError].} = # Set src as this result for if we do another power src = result +proc magnifyBy2*(mask: Mask, power = 1): Mask {.raises: [PixieError].} = + ## Scales mask up by 2 ^ power. + if power < 0: + raise newException(PixieError, "Cannot magnifyBy2 with negative power") + + let scale = 2 ^ power + result = newMask(mask.width * scale, mask.height * scale) + for y in 0 ..< result.height: + for x in 0 ..< mask.width: + let + value = mask.getValueUnsafe(x, y div scale) + scaledX = x * scale + idx = result.dataIndex(scaledX, y) + for i in 0 ..< scale: + result.data[idx + i] = value + proc fillUnsafe*( data: var seq[uint8], value: uint8, start, len: int ) {.raises: [].} = diff --git a/tests/images/masks/maskMagnified.png b/tests/images/masks/maskMagnified.png new file mode 100644 index 0000000000000000000000000000000000000000..d2c9e78d549c8f8877ff40b3916468c95e6a63dd GIT binary patch literal 944 zcmeAS@N?(olHy`uVBq!ia0vp^DImdvRYV#LBJN!u9Ld%gW2sn-4z7c=YPkss7!UUslL1()hGT#dDH(X`bQ)##?XAq*hq@XU~q!I=jqwdGPD+zsu_C^3v1O^&Z_wVURIq zvUEt;>JYc>_S)x}TcZ|68?c9Sq%^EC@>(i1uWSCBvL9=&8g*p3!0Ro)=qn#X*d7(C%IiMtl=Kp(ig}us)_DbUp?hy%A>hl;-7x}cyVoGy2r7) z3Cc%Kp6q;{Yc~6>e2Q3{;@v#)ziTgMRA?XScznZJOz+9RfA{or3tbfttqfZ|Z~Mmz z854~P{)5x)6cpPx#;vb)cj^nr%L~&u_uyml3m;UCS`} z5W@25)2Bz3v(KhEDmS&3?2i5Kz-ifI(FY2IMH-u)7G>^@J72bY?o=<;`5rZAj~{P; zzViP2>U)z^e(rj#&l2vjH}3nw84MmL<{$LrR-4Q@>rv|ggQVSeZzXNq5Vrd1WUn*n zn@;W6yZ5V&t-XEqJtxj}6ME7%zvRFDcH4HLPczpT6