@@ -3646,11 +3646,49 @@ _getattr_mode(ImagingObject *self, void *closure) {
36463646 return PyUnicode_FromString (self -> image -> mode );
36473647}
36483648
3649+ static int
3650+ _setattr_mode (ImagingObject * self , PyObject * value , void * closure ) {
3651+ if (value == NULL ) {
3652+ self -> image -> mode [0 ] = '\0' ;
3653+ return 0 ;
3654+ }
3655+
3656+ const char * mode = PyUnicode_AsUTF8 (value );
3657+ if (mode == NULL ) {
3658+ return -1 ;
3659+ }
3660+ if (strlen (mode ) >= IMAGING_MODE_LENGTH ) {
3661+ PyErr_SetString (PyExc_ValueError , "given mode name is too long" );
3662+ return -1 ;
3663+ }
3664+
3665+ strcpy (self -> image -> mode , mode );
3666+ return 0 ;
3667+ }
3668+
36493669static PyObject *
36503670_getattr_size (ImagingObject * self , void * closure ) {
36513671 return Py_BuildValue ("ii" , self -> image -> xsize , self -> image -> ysize );
36523672}
36533673
3674+ static int
3675+ _setattr_size (ImagingObject * self , PyObject * value , void * closure ) {
3676+ if (value == NULL ) {
3677+ self -> image -> xsize = 0 ;
3678+ self -> image -> ysize = 0 ;
3679+ return 0 ;
3680+ }
3681+
3682+ int xsize , ysize ;
3683+ if (!PyArg_ParseTuple (value , "ii" , & xsize , & ysize )) {
3684+ return -1 ;
3685+ }
3686+
3687+ self -> image -> xsize = xsize ;
3688+ self -> image -> ysize = ysize ;
3689+ return 0 ;
3690+ }
3691+
36543692static PyObject *
36553693_getattr_bands (ImagingObject * self , void * closure ) {
36563694 return PyLong_FromLong (self -> image -> bands );
@@ -3679,13 +3717,14 @@ _getattr_unsafe_ptrs(ImagingObject *self, void *closure) {
36793717};
36803718
36813719static struct PyGetSetDef getsetters [] = {
3682- {"mode" , (getter )_getattr_mode },
3683- {"size" , (getter )_getattr_size },
3720+ {"mode" , (getter )_getattr_mode , ( setter ) _setattr_mode },
3721+ {"size" , (getter )_getattr_size , ( setter ) _setattr_size },
36843722 {"bands" , (getter )_getattr_bands },
36853723 {"id" , (getter )_getattr_id },
36863724 {"ptr" , (getter )_getattr_ptr },
36873725 {"unsafe_ptrs" , (getter )_getattr_unsafe_ptrs },
3688- {NULL }};
3726+ {NULL }
3727+ };
36893728
36903729/* basic sequence semantics */
36913730
0 commit comments