From 1571b2c08d840085220f854247c9123b918eda5e Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 4 Oct 2021 21:20:53 -0500 Subject: [PATCH 1/5] f --- src/pixie/images.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index e263dba..67c807b 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -198,7 +198,6 @@ proc flipVertical*(image: Image) {.raises: [].} = proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} = ## Gets a sub image from this image. - if x < 0 or x + w > image.width: raise newException( PixieError, From fe09ad82a88c71ebe61dafa2207e471a3d01cbd6 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 11 Oct 2021 00:47:32 -0500 Subject: [PATCH 2/5] updated req --- pixie.nimble | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pixie.nimble b/pixie.nimble index 6da11b5..3941636 100644 --- a/pixie.nimble +++ b/pixie.nimble @@ -5,7 +5,7 @@ license = "MIT" srcDir = "src" -requires "nim >= 1.2.6" +requires "nim >= 1.4.0" requires "vmath >= 1.0.11" requires "chroma >= 0.2.5" requires "zippy >= 0.6.2" @@ -13,9 +13,6 @@ requires "flatty >= 0.2.2" requires "nimsimd >= 1.0.0" requires "bumpy >= 1.0.3" -task docs, "Generate API documents": - exec "nim doc --index:on --project --out:docs --hints:off src/pixie.nim" - task bindings, "Generate bindings": proc compile(libName: string, flags = "") = From 68b2c52b85d36c3cc38844c0ec8ab0e9e4078ecf Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 11 Oct 2021 00:47:49 -0500 Subject: [PATCH 3/5] no need to be exported --- bindings/bindings.nim | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/bindings.nim b/bindings/bindings.nim index 2635b66..e161604 100644 --- a/bindings/bindings.nim +++ b/bindings/bindings.nim @@ -1,12 +1,12 @@ import genny, pixie, unicode -var lastError*: ref PixieError +var lastError: ref PixieError -proc takeError*(): string = +proc takeError(): string = result = lastError.msg lastError = nil -proc checkError*(): bool = +proc checkError(): bool = result = lastError != nil type @@ -16,37 +16,37 @@ type Matrix3* = object values*: array[9, float32] -proc matrix3*(): Matrix3 = +proc matrix3(): Matrix3 = cast[Matrix3](mat3()) -proc mul*(a, b: Matrix3): Matrix3 = +proc mul(a, b: Matrix3): Matrix3 = cast[Matrix3](cast[Mat3](a) * cast[Mat3](b)) -proc translate*(x, y: float32): Matrix3 = +proc translate(x, y: float32): Matrix3 = cast[Matrix3](translate(vec2(x, y))) -proc rotate*(angle: float32): Matrix3 = +proc rotate(angle: float32): Matrix3 = cast[Matrix3](rotate(angle)) -proc scale*(x, y: float32): Matrix3 = +proc scale(x, y: float32): Matrix3 = cast[Matrix3](scale(vec2(x, y))) -proc inverse*(m: Matrix3): Matrix3 = +proc inverse(m: Matrix3): Matrix3 = cast[Matrix3](inverse(cast[Mat3](m))) -proc parseColor*(s: string): Color {.raises: [PixieError]} = +proc parseColor(s: string): Color {.raises: [PixieError]} = try: result = parseHtmlColor(s) except: let e = getCurrentException() raise newException(PixieError, e.msg, e) -proc drawImage2*( +proc drawImage2( ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32 ) {.raises: [PixieError].} = ctx.drawImage(image, dx, dy, dWidth, dHeight) -proc drawImage3*( +proc drawImage3( ctx: Context, image: Image, sx, sy, sWidth, sHeight, From 89d1608a32e700b768f827db955f292691a54342 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 11 Oct 2021 19:17:31 -0500 Subject: [PATCH 4/5] magnifyBy2 10% faster --- src/pixie/images.nim | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 67c807b..bb7ff8c 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -309,15 +309,14 @@ proc minifyBy2*(image: Image, power = 1): Image {.raises: [PixieError].} = b = src.getRgbaUnsafe(x * 2 + 1, y * 2 + 0) c = src.getRgbaUnsafe(x * 2 + 1, y * 2 + 1) d = src.getRgbaUnsafe(x * 2 + 0, y * 2 + 1) + rgba = rgbx( + ((a.r.uint32 + b.r + c.r + d.r) div 4).uint8, + ((a.g.uint32 + b.g + c.g + d.g) div 4).uint8, + ((a.b.uint32 + b.b + c.b + d.b) div 4).uint8, + ((a.a.uint32 + b.a + c.a + d.a) div 4).uint8 + ) - let color = rgbx( - ((a.r.uint32 + b.r + c.r + d.r) div 4).uint8, - ((a.g.uint32 + b.g + c.g + d.g) div 4).uint8, - ((a.b.uint32 + b.b + c.b + d.b) div 4).uint8, - ((a.a.uint32 + b.a + c.a + d.a) div 4).uint8 - ) - - result.setRgbaUnsafe(x, y, color) + result.setRgbaUnsafe(x, y, rgba) # Set src as this result for if we do another power src = result @@ -333,10 +332,10 @@ proc magnifyBy2*(image: Image, power = 1): Image {.raises: [PixieError].} = for x in 0 ..< image.width: let rgba = image.getRgbaUnsafe(x, y div scale) - scaledX = x * scale - idx = result.dataIndex(scaledX, y) - for i in 0 ..< scale: - result.data[idx + i] = rgba + idx = result.dataIndex(x * scale, y) + for i in 0 ..< scale div 2: + result.data[idx + i * 2 + 0] = rgba + result.data[idx + i * 2 + 1] = rgba proc applyOpacity*(target: Image | Mask, opacity: float32) {.raises: [].} = ## Multiplies alpha of the image by opacity. From 703279505c22b0209ba61e0811100d3a83025258 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 11 Oct 2021 19:20:43 -0500 Subject: [PATCH 5/5] update benchmark --- tests/benchmark_images.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/benchmark_images.nim b/tests/benchmark_images.nim index d0955ac..ab35791 100644 --- a/tests/benchmark_images.nim +++ b/tests/benchmark_images.nim @@ -101,18 +101,18 @@ timeIt "blur": reset() -timeIt "lerp integers": +timeIt "mix integers": for i in 0 ..< 100000: let c = image[0, 0] var z: int for t in 0 .. 100: - z += lerp(c, c, t.float32 / 100).a.int + z += mix(c, c, t.float32 / 100).a.int doAssert z > 0 -timeIt "lerp floats": +timeIt "mix floats": for i in 0 ..< 100000: let c = image[0, 0] var z: int for t in 0 .. 100: - z += lerp(c.color, c.color, t.float32 / 100).rgba().a.int + z += mix(c.color, c.color, t.float32 / 100).rgba().a.int doAssert z > 0