2x faster

This commit is contained in:
Ryan Oldenburg 2022-05-25 18:54:13 -05:00
parent e67f257479
commit 49acd68ce9
2 changed files with 12 additions and 7 deletions

View file

@ -172,14 +172,14 @@ proc flipVertical*(image: Image) {.raises: [].} =
proc rotate90*(image: Image) {.raises: [PixieError].} =
## Rotates the image 90 degrees clockwise.
let copy = newImage(image.height, image.width)
for y in 0 ..< copy.height:
for x in 0 ..< copy.width:
copy.data[copy.dataIndex(x, y)] =
let rotated = newImage(image.height, image.width)
for y in 0 ..< rotated.height:
for x in 0 ..< rotated.width:
rotated.data[rotated.dataIndex(x, y)] =
image.data[image.dataIndex(y, image.height - x - 1)]
image.width = copy.width
image.height = copy.height
image.data = copy.data
image.width = rotated.width
image.height = rotated.height
image.data = move rotated.data
proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} =
## Gets a sub image from this image.

View file

@ -63,6 +63,11 @@ timeIt "flipVertical":
reset()
timeIt "rotate90":
image.rotate90()
reset()
timeIt "invert":
image.invert()