Fix rotations.

This commit is contained in:
treeform 2022-05-18 19:31:46 -07:00
parent 759f8e3082
commit 6ebd493f94
2 changed files with 5 additions and 4 deletions

View file

@ -988,16 +988,16 @@ proc buildImage(state: var DecoderState): Image =
result.flipVertical()
of 5:
result.rotate90()
result.flipHorizontal()
of 6:
result.rotate90()
result.flipHorizontal()
of 7:
result.rotate90()
result.flipVertical()
result.flipHorizontal()
of 8:
result.rotate90()
result.flipVertical()
result.flipHorizontal()
else:
failInvalid("invalid orientation")

View file

@ -171,11 +171,12 @@ proc flipVertical*(image: Image) {.raises: [].} =
)
proc rotate90*(image: Image) {.raises: [PixieError].} =
## Rotates the image 90 degrees.
## Rotates the image 90 degrees clockwise.
var copy = newImage(image.height, image.width)
for y in 0 ..< copy.height:
for x in 0 ..< copy.width:
copy.data[copy.dataIndex(x, y)] = image.data[image.dataIndex(y, x)]
copy.data[copy.dataIndex(x, y)] =
image.data[image.dataIndex(y, image.height - x - 1)]
image.width = copy.width
image.height = copy.height
image.data = copy.data