Skip to content

Commit ed177f6

Browse files
committed
Simplified code
1 parent e2b87a0 commit ed177f6

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

src/PIL/Image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def tobytes(self, encoder_name: str = "raw", *args: Any) -> bytes:
784784

785785
# unpack data
786786
e = _getencoder(self.mode, encoder_name, encoder_args)
787-
e.setimage(self.im)
787+
e.setimage(self.im, (0, 0) + self.size)
788788

789789
from . import ImageFile
790790

src/encode.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
232232
x0 = y0 = x1 = y1 = 0;
233233

234234
/* FIXME: should publish the ImagingType descriptor */
235-
if (!PyArg_ParseTuple(args, "O|(nnnn)", &op, &x0, &y0, &x1, &y1)) {
235+
if (!PyArg_ParseTuple(args, "O(nnnn)", &op, &x0, &y0, &x1, &y1)) {
236236
return NULL;
237237
}
238238
im = PyImaging_AsImaging(op);
@@ -244,15 +244,10 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
244244

245245
state = &encoder->state;
246246

247-
if (x0 == 0 && x1 == 0) {
248-
state->xsize = im->xsize;
249-
state->ysize = im->ysize;
250-
} else {
251-
state->xoff = x0;
252-
state->yoff = y0;
253-
state->xsize = x1 - x0;
254-
state->ysize = y1 - y0;
255-
}
247+
state->xoff = x0;
248+
state->yoff = y0;
249+
state->xsize = x1 - x0;
250+
state->ysize = y1 - y0;
256251

257252
if (state->xsize <= 0 || state->xsize + state->xoff > im->xsize ||
258253
state->ysize <= 0 || state->ysize + state->yoff > im->ysize) {

0 commit comments

Comments
 (0)