Skip to content

Commit

Permalink
Only set row order when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 9, 2024
1 parent 673eb9a commit 6c32032
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/PIL/PpmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ def decode(self, buffer):


def _save(im, fp, filename):
row_order = 1
if im.mode == "1":
rawmode, head = "1;I", b"P4"
elif im.mode == "L":
Expand All @@ -322,7 +321,6 @@ def _save(im, fp, filename):
rawmode, head = "RGB", b"P6"
elif im.mode == "F":
rawmode, head = "F;32F", b"Pf"
row_order = -1
else:
msg = f"cannot write mode {im.mode} as PPM"
raise OSError(msg)
Expand All @@ -336,6 +334,7 @@ def _save(im, fp, filename):
fp.write(b"65535\n")
elif head == b"Pf":
fp.write(b"-1.0\n")
row_order = -1 if im.mode == "F" else 1
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, 0, row_order))])


Expand Down

0 comments on commit 6c32032

Please sign in to comment.