From 9fbd37bb53f3417166e10c2a1066d624f0ca9c45 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 3 Dec 2020 21:49:11 -0600 Subject: [PATCH] use memset --- src/pixie/images.nim | 8 +++++--- tests/benchmark_images.nim | 12 ------------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 7c1c3d7..9607323 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -70,9 +70,11 @@ proc `[]=`*(image: Image, x, y: int, rgba: ColorRGBA) {.inline.} = proc fill*(image: Image, rgba: ColorRgba) = ## Fills the image with a solid color. - nimSetMem(image.data[0].addr, cast[int32](rgba), image.data.len) - # for c in image.data.mitems: - # c = rgba + if rgba.r == rgba.g and rgba.r == rgba.b and rgba.r == rgba.a: + nimSetMem(image.data[0].addr, rgba.r.cint, image.data.len * 4) + else: + for c in image.data.mitems: + c = rgba proc invert*(image: Image) = ## Inverts all of the colors and alpha. diff --git a/tests/benchmark_images.nim b/tests/benchmark_images.nim index 51c23c0..4d6c390 100644 --- a/tests/benchmark_images.nim +++ b/tests/benchmark_images.nim @@ -48,18 +48,6 @@ timeIt "fill": a.fill(rgba(255, 255, 255, 255)) doAssert a[0, 0] == rgba(255, 255, 255, 255) -timeIt "fillOriginal rgba(0, 0, 0, 0)": - var a = newImage(2560, 1440) - for i in 0 ..< iterations: - a.fillOriginal(rgba(0, 0, 0, 0)) - doAssert a[0, 0] == rgba(0, 0, 0, 0) - -timeIt "fill rgba(0, 0, 0, 0)": - var a = newImage(2560, 1440) - for i in 0 ..< iterations: - a.fill(rgba(0, 0, 0, 0)) - doAssert a[0, 0] == rgba(0, 0, 0, 0) - timeIt "invertOriginal": var a = newImage(2560, 1440) for i in 0 ..< iterations: