Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added orientation, compression and id_section as TGA save keyword arguments #3327

Merged
merged 3 commits into from
Sep 8, 2018

Conversation

radarhere
Copy link
Member

Resolves #3226

@radarhere radarhere changed the title Added orientation, compression and id_section as TGA saving keyword arguments Added orientation, compression and id_section as TGA save keyword arguments Sep 1, 2018
if orientation > 0:
flags = flags | 0x20

fp.write(b"\000" +
fp.write(o8(idlen) +
Copy link
Contributor

@danpla danpla Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small problem: o8 is bytes((i & 255,)), which will not raise an exception like struct.pack(), making it possible for fp.write() below to write id_section bigger than the written idlen, resulting in a broken image.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've added a commit to trim id_section.

@@ -151,11 +151,19 @@ def _save(im, fp, filename):
except KeyError:
raise IOError("cannot write mode %s as TGA" % im.mode)

rle = im.encoderinfo.get("rle", False)

if "rle" in im.encoderinfo:
Copy link
Contributor

@danpla danpla Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safe to remove the "rle" keyword in favor of "compression".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I'm just not keen to break the backwards compatibility of this one. If this PR is merged, you're welcome to submit a separate PR for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds sensible to keep it, we've no idea what code might be using im.encoderinfo["rle"].

We'd need deprecation warnings first before removing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TGA-specifc flags are not currently documented, so it's unlikely that anyone uses them.

im.info.get("id_section", ""))
idlen = len(id_section)
if idlen > 255:
idlen = 255
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's snake_case this variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've added a commit. Note that the commit also changes the idlen variable in _open, for consistency.

@@ -151,11 +151,19 @@ def _save(im, fp, filename):
except KeyError:
raise IOError("cannot write mode %s as TGA" % im.mode)

rle = im.encoderinfo.get("rle", False)

if "rle" in im.encoderinfo:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds sensible to keep it, we've no idea what code might be using im.encoderinfo["rle"].

We'd need deprecation warnings first before removing.

@hugovk hugovk merged commit 7955208 into python-pillow:master Sep 8, 2018
@radarhere radarhere deleted the tga branch September 8, 2018 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants