-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Delegate Image mode and size to ImagingCore #7271
Changes from all commits
919dbbe
b879ada
0a88b5b
555420b
06aa04a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,9 @@ def get_format_mimetype(self): | |
if self.format is not None: | ||
return Image.MIME.get(self.format.upper()) | ||
|
||
def _use_im_values(self): | ||
return self.tile is None and self.im is not None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @radarhere proposed that change for |
||
|
||
def __setstate__(self, state): | ||
self.tile = [] | ||
super().__setstate__(state) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3646,11 +3646,49 @@ | |
return PyUnicode_FromString(self->image->mode); | ||
} | ||
|
||
static int | ||
_setattr_mode(ImagingObject *self, PyObject *value, void *closure) { | ||
if (value == NULL) { | ||
self->image->mode[0] = '\0'; | ||
return 0; | ||
} | ||
|
||
const char *mode = PyUnicode_AsUTF8(value); | ||
if (mode == NULL) { | ||
return -1; | ||
} | ||
if (strlen(mode) >= IMAGING_MODE_LENGTH) { | ||
PyErr_SetString(PyExc_ValueError, "given mode name is too long"); | ||
return -1; | ||
} | ||
|
||
strcpy(self->image->mode, mode); | ||
return 0; | ||
} | ||
|
||
static PyObject * | ||
_getattr_size(ImagingObject *self, void *closure) { | ||
return Py_BuildValue("ii", self->image->xsize, self->image->ysize); | ||
} | ||
|
||
static int | ||
_setattr_size(ImagingObject *self, PyObject *value, void *closure) { | ||
if (value == NULL) { | ||
self->image->xsize = 0; | ||
self->image->ysize = 0; | ||
return 0; | ||
} | ||
|
||
int xsize, ysize; | ||
if (!PyArg_ParseTuple(value, "ii", &xsize, &ysize)) { | ||
return -1; | ||
} | ||
|
||
self->image->xsize = xsize; | ||
self->image->ysize = ysize; | ||
Comment on lines
+3687
to
+3688
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we want to do this? It will just break image There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that if |
||
return 0; | ||
} | ||
|
||
static PyObject * | ||
_getattr_bands(ImagingObject *self, void *closure) { | ||
return PyLong_FromLong(self->image->bands); | ||
|
@@ -3679,13 +3717,14 @@ | |
}; | ||
|
||
static struct PyGetSetDef getsetters[] = { | ||
{"mode", (getter)_getattr_mode}, | ||
{"size", (getter)_getattr_size}, | ||
{"mode", (getter)_getattr_mode, (setter)_setattr_mode}, | ||
{"size", (getter)_getattr_size, (setter)_setattr_size}, | ||
{"bands", (getter)_getattr_bands}, | ||
{"id", (getter)_getattr_id}, | ||
{"ptr", (getter)_getattr_ptr}, | ||
{"unsafe_ptrs", (getter)_getattr_unsafe_ptrs}, | ||
{NULL}}; | ||
{NULL} | ||
}; | ||
|
||
/* basic sequence semantics */ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this can't be just in
size
property?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
_size
getter is actually used in quite a few places, so that would have to be changed to use thesize
getter first. It would save three lines if the_size
getter was removed though:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More important that this saves one indirect method call (width → size → _size) on each attribute getter.