Pull readonly in from the C level

This commit is contained in:
wiredfool 2025-01-25 16:21:15 +00:00
parent 55f5351e3d
commit ad492ee4d8
3 changed files with 22 additions and 0 deletions

View File

@ -147,3 +147,11 @@ def test_release_array():
array, schema = img.__arrow_c_array__()
del(array)
del(schema)
def test_readonly():
img = hopper('L')
reloaded = Image.fromarrow(img, img.mode, img.size)
assert reloaded.readonly == 1
reloaded._readonly = 0
assert reloaded.readonly == 1

View File

@ -584,6 +584,14 @@ class Image:
def mode(self) -> str:
return self._mode
@property
def readonly(self) -> int:
return (self._im and self._im.readonly) or self._readonly
@readonly.setter
def readonly(self, readonly: int) -> None:
self._readonly = readonly
def _new(self, im: core.ImagingCore) -> Image:
new = Image()
new.im = im

View File

@ -3821,6 +3821,11 @@ _getattr_unsafe_ptrs(ImagingObject *self, void *closure) {
);
}
static PyObject *
_getattr_readonly(ImagingObject *self, void *closure) {
return PyLong_FromLong(self->image->read_only);
}
static struct PyGetSetDef getsetters[] = {
{"mode", (getter)_getattr_mode},
{"size", (getter)_getattr_size},
@ -3828,6 +3833,7 @@ static struct PyGetSetDef getsetters[] = {
{"id", (getter)_getattr_id},
{"ptr", (getter)_getattr_ptr},
{"unsafe_ptrs", (getter)_getattr_unsafe_ptrs},
{"readonly", (getter)_getattr_readonly},
{NULL}
};