Skip to content

Commit

Permalink
switch to #z for comment parameter
Browse files Browse the repository at this point in the history
* means `comment=None` can be passed directly
* no need to conditionally run `str.encode()`
* clean up checking of whether a comment is passed
  • Loading branch information
smason committed Dec 5, 2022
1 parent 399975f commit eddc9bd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,7 @@ def validate_qtables(qtables):
)
i += 1

comment = info.get("comment", im.info.get("comment")) or b""
if isinstance(comment, str):
comment = comment.encode()
comment = info.get("comment", im.info.get("comment"))

# "progressive" is the official name, but older documentation
# says "progression"
Expand Down
2 changes: 1 addition & 1 deletion src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {

if (!PyArg_ParseTuple(
args,
"ss|nnnnnnnnOy#y#y#",
"ss|nnnnnnnnOz#y#y#",
&mode,
&rawmode,
&quality,
Expand Down
2 changes: 1 addition & 1 deletion src/libImaging/JpegEncode.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {

case 4:

if (context->comment_size > 0) {
if (context->comment) {
jpeg_write_marker(&context->cinfo, JPEG_COM, (unsigned char *)context->comment, context->comment_size);
}
state->state++;
Expand Down

0 comments on commit eddc9bd

Please sign in to comment.