switch to #z for comment parameter

* means `comment=None` can be passed directly
* no need to conditionally run `str.encode()`
* clean up checking of whether a comment is passed
This commit is contained in:
Sam Mason 2022-12-05 17:46:54 +00:00
parent 399975f1d9
commit eddc9bdcec
No known key found for this signature in database
GPG Key ID: 0D059A3A7ECA31DA
3 changed files with 3 additions and 5 deletions

View File

@ -736,9 +736,7 @@ def _save(im, fp, filename):
) )
i += 1 i += 1
comment = info.get("comment", im.info.get("comment")) or b"" comment = info.get("comment", im.info.get("comment"))
if isinstance(comment, str):
comment = comment.encode()
# "progressive" is the official name, but older documentation # "progressive" is the official name, but older documentation
# says "progression" # says "progression"

View File

@ -1057,7 +1057,7 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
if (!PyArg_ParseTuple( if (!PyArg_ParseTuple(
args, args,
"ss|nnnnnnnnOy#y#y#", "ss|nnnnnnnnOz#y#y#",
&mode, &mode,
&rawmode, &rawmode,
&quality, &quality,

View File

@ -278,7 +278,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
case 4: case 4:
if (context->comment_size > 0) { if (context->comment) {
jpeg_write_marker(&context->cinfo, JPEG_COM, (unsigned char *)context->comment, context->comment_size); jpeg_write_marker(&context->cinfo, JPEG_COM, (unsigned char *)context->comment, context->comment_size);
} }
state->state++; state->state++;