diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 6a69db1..0065b11 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -179,22 +179,20 @@ proc flipHorizontal*(image: Image) {.raises: [].} = let w = image.width div 2 for y in 0 ..< image.height: for x in 0 ..< w: - let - rgba1 = image.getRgbaUnsafe(x, y) - rgba2 = image.getRgbaUnsafe(image.width - x - 1, y) - image.setRgbaUnsafe(image.width - x - 1, y, rgba1) - image.setRgbaUnsafe(x, y, rgba2) + swap( + image.data[image.dataIndex(x, y)], + image.data[image.dataIndex(image.width - x - 1, y)] + ) proc flipVertical*(image: Image) {.raises: [].} = ## Flips the image around the X axis. let h = image.height div 2 for y in 0 ..< h: for x in 0 ..< image.width: - let - rgba1 = image.getRgbaUnsafe(x, y) - rgba2 = image.getRgbaUnsafe(x, image.height - y - 1) - image.setRgbaUnsafe(x, image.height - y - 1, rgba1) - image.setRgbaUnsafe(x, y, rgba2) + swap( + image.data[image.dataIndex(x, y)], + image.data[image.dataIndex(x, image.height - y - 1)] + ) proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} = ## Gets a sub image from this image. diff --git a/tests/benchmark_images.nim b/tests/benchmark_images.nim index ab35791..728397b 100644 --- a/tests/benchmark_images.nim +++ b/tests/benchmark_images.nim @@ -49,6 +49,16 @@ timeIt "magnifyBy2": reset() +timeIt "flipHorizontal": + image.flipHorizontal() + +reset() + +timeIt "flipVertical": + image.flipVertical() + +reset() + timeIt "invert": image.invert()