mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-12 01:02:39 +03:00
Allow new-style buffer interfaces to be read/write when mapped that way
This commit is contained in:
parent
9174a4596c
commit
d4c443ef68
|
@ -2639,7 +2639,7 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
|
||||||
if args[0] in _MAPMODES:
|
if args[0] in _MAPMODES:
|
||||||
im = new(mode, (1, 1))
|
im = new(mode, (1, 1))
|
||||||
im = im._new(core.map_buffer(data, size, decoder_name, 0, args))
|
im = im._new(core.map_buffer(data, size, decoder_name, 0, args))
|
||||||
im.readonly = 1
|
im.readonly = im.im.readonly
|
||||||
return im
|
return im
|
||||||
|
|
||||||
return frombytes(mode, size, data, decoder_name, args)
|
return frombytes(mode, size, data, decoder_name, args)
|
||||||
|
|
|
@ -196,7 +196,7 @@ class ImageFile(Image.Image):
|
||||||
self.im = Image.core.map_buffer(
|
self.im = Image.core.map_buffer(
|
||||||
self.map, self.size, decoder_name, offset, args
|
self.map, self.size, decoder_name, offset, args
|
||||||
)
|
)
|
||||||
readonly = 1
|
readonly = self.im.readonly
|
||||||
# After trashing self.im,
|
# After trashing self.im,
|
||||||
# we might need to reload the palette data.
|
# we might need to reload the palette data.
|
||||||
if self.palette:
|
if self.palette:
|
||||||
|
|
|
@ -3391,6 +3391,11 @@ _getattr_unsafe_ptrs(ImagingObject* self, void* closure)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
_getattr_readonly(ImagingObject* self, void* closure)
|
||||||
|
{
|
||||||
|
return PyInt_FromLong(self->image->readonly);
|
||||||
|
}
|
||||||
|
|
||||||
static struct PyGetSetDef getsetters[] = {
|
static struct PyGetSetDef getsetters[] = {
|
||||||
{ "mode", (getter) _getattr_mode },
|
{ "mode", (getter) _getattr_mode },
|
||||||
|
@ -3399,6 +3404,7 @@ static struct PyGetSetDef getsetters[] = {
|
||||||
{ "id", (getter) _getattr_id },
|
{ "id", (getter) _getattr_id },
|
||||||
{ "ptr", (getter) _getattr_ptr },
|
{ "ptr", (getter) _getattr_ptr },
|
||||||
{ "unsafe_ptrs", (getter) _getattr_unsafe_ptrs },
|
{ "unsafe_ptrs", (getter) _getattr_unsafe_ptrs },
|
||||||
|
{ "readonly", (getter) _getattr_readonly },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ struct ImagingMemoryInstance {
|
||||||
int bands; /* Number of bands (1, 2, 3, or 4) */
|
int bands; /* Number of bands (1, 2, 3, or 4) */
|
||||||
int xsize; /* Image dimension. */
|
int xsize; /* Image dimension. */
|
||||||
int ysize;
|
int ysize;
|
||||||
|
int readonly;
|
||||||
|
|
||||||
/* Colour palette (for "P" images only) */
|
/* Colour palette (for "P" images only) */
|
||||||
ImagingPalette palette;
|
ImagingPalette palette;
|
||||||
|
|
|
@ -64,6 +64,7 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size)
|
||||||
im->xsize = xsize;
|
im->xsize = xsize;
|
||||||
im->ysize = ysize;
|
im->ysize = ysize;
|
||||||
|
|
||||||
|
im->readonly = 0;
|
||||||
im->type = IMAGING_TYPE_UINT8;
|
im->type = IMAGING_TYPE_UINT8;
|
||||||
|
|
||||||
if (strcmp(mode, "1") == 0) {
|
if (strcmp(mode, "1") == 0) {
|
||||||
|
|
|
@ -217,6 +217,7 @@ mapping_readimage(ImagingMapperObject* mapper, PyObject* args)
|
||||||
if (!im)
|
if (!im)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
im->readonly = 1;
|
||||||
/* setup file pointers */
|
/* setup file pointers */
|
||||||
if (orientation > 0)
|
if (orientation > 0)
|
||||||
for (y = 0; y < ysize; y++)
|
for (y = 0; y < ysize; y++)
|
||||||
|
@ -366,6 +367,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
|
||||||
if (!im)
|
if (!im)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
im->readonly = view.readonly;
|
||||||
/* setup file pointers */
|
/* setup file pointers */
|
||||||
if (ystep > 0)
|
if (ystep > 0)
|
||||||
for (y = 0; y < ysize; y++)
|
for (y = 0; y < ysize; y++)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user