@@ -733,13 +733,13 @@ _convert(ImagingObject* self, PyObject* args)
733733 return NULL ;
734734 if (paletteimage != NULL ) {
735735 if (!PyImaging_Check (paletteimage )) {
736- PyObject_Print ((PyObject * )paletteimage , stderr , 0 );
737- PyErr_SetString (PyExc_ValueError , "palette argument must be image with mode 'P'" );
738- return NULL ;
736+ PyObject_Print ((PyObject * )paletteimage , stderr , 0 );
737+ PyErr_SetString (PyExc_ValueError , "palette argument must be image with mode 'P'" );
738+ return NULL ;
739739 }
740740 if (paletteimage -> image -> palette == NULL ) {
741- PyErr_SetString (PyExc_ValueError , "null palette" );
742- return NULL ;
741+ PyErr_SetString (PyExc_ValueError , "null palette" );
742+ return NULL ;
743743 }
744744 }
745745
@@ -1407,7 +1407,9 @@ _putpalettealpha(ImagingObject* self, PyObject* args)
14071407{
14081408 int index ;
14091409 int alpha = 0 ;
1410- if (!PyArg_ParseTuple (args , "i|i" , & index , & alpha ))
1410+ char * tpalette = NULL ;
1411+ int tpaletteSize = 0 ;
1412+ if (!PyArg_ParseTuple (args , "i|i" PY_ARG_BYTES_LENGTH , & index , & alpha , & tpalette , & tpaletteSize ))
14111413 return NULL ;
14121414
14131415 if (!self -> image -> palette ) {
@@ -1419,9 +1421,17 @@ _putpalettealpha(ImagingObject* self, PyObject* args)
14191421 PyErr_SetString (PyExc_ValueError , outside_palette );
14201422 return NULL ;
14211423 }
1422-
1424+
14231425 strcpy (self -> image -> palette -> mode , "RGBA" );
1424- self -> image -> palette -> palette [index * 4 + 3 ] = (UINT8 ) alpha ;
1426+
1427+ if (tpaletteSize > 0 ) {
1428+ for (index = 0 ; index < tpaletteSize ; index ++ ) {
1429+ self -> image -> palette -> palette [index * 4 + 3 ] = (UINT8 ) tpalette [index ];
1430+ }
1431+ }
1432+ else {
1433+ self -> image -> palette -> palette [index * 4 + 3 ] = (UINT8 ) alpha ;
1434+ }
14251435
14261436 Py_INCREF (Py_None );
14271437 return Py_None ;
@@ -3391,3 +3401,4 @@ init_imaging(void)
33913401}
33923402#endif
33933403
3404+
0 commit comments