Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3182,7 +3182,7 @@ def frombuffer(
from . import ImagePalette

im.palette = ImagePalette.ImagePalette("RGB", im.im.getpalette("RGB"))
im.readonly = 1
im.readonly = im.im.readonly
return im

return frombytes(mode, size, data, decoder_name, args)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def load(self):
self.im = Image.core.map_buffer(
self.map, self.size, decoder_name, offset, args
)
readonly = 1
readonly = self.im.readonly
# After trashing self.im,
# we might need to reload the palette data.
if self.palette:
Expand Down
6 changes: 6 additions & 0 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -3791,13 +3791,19 @@ _getattr_unsafe_ptrs(ImagingObject *self, void *closure) {
);
}

static PyObject *
_getattr_readonly(ImagingObject *self, void *closure) {
return PyLong_FromLong(self->image->readonly);
}

static struct PyGetSetDef getsetters[] = {
{"mode", (getter)_getattr_mode},
{"size", (getter)_getattr_size},
{"bands", (getter)_getattr_bands},
{"id", (getter)_getattr_id},
{"ptr", (getter)_getattr_ptr},
{"unsafe_ptrs", (getter)_getattr_unsafe_ptrs},
{"readonly", (getter)_getattr_readonly},
{NULL}
};

Expand Down
1 change: 1 addition & 0 deletions src/libImaging/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct ImagingMemoryInstance {
int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */
int ysize;
int readonly;

/* Colour palette (for "P" images only) */
ImagingPalette palette;
Expand Down
1 change: 1 addition & 0 deletions src/libImaging/Storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
im->xsize = xsize;
im->ysize = ysize;

im->readonly = 0;
im->type = IMAGING_TYPE_UINT8;

if (strcmp(mode, "1") == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
return NULL;
}

im->readonly = view.readonly;
/* setup file pointers */
if (ystep > 0) {
for (y = 0; y < ysize; y++) {
Expand Down