2x faster
This commit is contained in:
parent
e67f257479
commit
49acd68ce9
2 changed files with 12 additions and 7 deletions
|
@ -172,14 +172,14 @@ proc flipVertical*(image: Image) {.raises: [].} =
|
||||||
|
|
||||||
proc rotate90*(image: Image) {.raises: [PixieError].} =
|
proc rotate90*(image: Image) {.raises: [PixieError].} =
|
||||||
## Rotates the image 90 degrees clockwise.
|
## Rotates the image 90 degrees clockwise.
|
||||||
let copy = newImage(image.height, image.width)
|
let rotated = newImage(image.height, image.width)
|
||||||
for y in 0 ..< copy.height:
|
for y in 0 ..< rotated.height:
|
||||||
for x in 0 ..< copy.width:
|
for x in 0 ..< rotated.width:
|
||||||
copy.data[copy.dataIndex(x, y)] =
|
rotated.data[rotated.dataIndex(x, y)] =
|
||||||
image.data[image.dataIndex(y, image.height - x - 1)]
|
image.data[image.dataIndex(y, image.height - x - 1)]
|
||||||
image.width = copy.width
|
image.width = rotated.width
|
||||||
image.height = copy.height
|
image.height = rotated.height
|
||||||
image.data = copy.data
|
image.data = move rotated.data
|
||||||
|
|
||||||
proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} =
|
proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} =
|
||||||
## Gets a sub image from this image.
|
## Gets a sub image from this image.
|
||||||
|
|
|
@ -63,6 +63,11 @@ timeIt "flipVertical":
|
||||||
|
|
||||||
reset()
|
reset()
|
||||||
|
|
||||||
|
timeIt "rotate90":
|
||||||
|
image.rotate90()
|
||||||
|
|
||||||
|
reset()
|
||||||
|
|
||||||
timeIt "invert":
|
timeIt "invert":
|
||||||
image.invert()
|
image.invert()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue