diff --git a/ChangeLog b/ChangeLog index a17d65c3c7..887b0aeed0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,13 @@ -2008-01-26 Joao S. O. Bueno +2008-01-26 Manish Singh + + * plug-ins/pygimp/pygimp-colors.c (pygimp_rgb_from_pyobject): no + need to use a temporary in tuple translation, and clamp the result. + + * plug-ins/pygimp/gimpmodule.c (pygimp_set_background, + pygimp_set_foreground): restore support for passing in 3 args for + color components, for backward compatibility. + +2008-01-26 Joao S. O. Bueno * plug-ins/pygimp/pygimp-colors.c (pygimp_rgb_from_pyobject): fix subsequent error (calculated parameters where not used) diff --git a/plug-ins/pygimp/gimpmodule.c b/plug-ins/pygimp/gimpmodule.c index fe57515138..a3d01204d0 100644 --- a/plug-ins/pygimp/gimpmodule.c +++ b/plug-ins/pygimp/gimpmodule.c @@ -837,30 +837,12 @@ pygimp_set_background(PyObject *self, PyObject *args) GimpRGB rgb; if (PyArg_ParseTuple(args, "O:set_background", &color)) { - if (! pygimp_rgb_from_pyobject (color, &rgb)) { - PyErr_Clear(); - PyArg_ParseTuple(args, "O!:set_background", PyGimpRGB_Type, &color); + if (!pygimp_rgb_from_pyobject(color, &rgb)) return NULL; - } } else { - int r, g, b; - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "(iii):set_background", &r, &g, &b)) { - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "iii:set_background", &r, &g, &b)) { - PyErr_Clear(); - PyArg_ParseTuple(args, "O!:set_background", - PyGimpRGB_Type, &color); - return NULL; - } - } - - r = CLAMP(r, 0, 255); - g = CLAMP(g, 0, 255); - b = CLAMP(b, 0, 255); - - gimp_rgba_set_uchar(&rgb, r, g, b, 255); + if (!pygimp_rgb_from_pyobject(args, &rgb)) + return NULL; } gimp_context_set_background(&rgb); @@ -876,30 +858,12 @@ pygimp_set_foreground(PyObject *self, PyObject *args) GimpRGB rgb; if (PyArg_ParseTuple(args, "O:set_foreground", &color)) { - if (! pygimp_rgb_from_pyobject (color, &rgb)) { - PyErr_Clear(); - PyArg_ParseTuple(args, "O!:set_foreground", PyGimpRGB_Type, &color); + if (!pygimp_rgb_from_pyobject(color, &rgb)) return NULL; - } } else { - int r, g, b; - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "(iii):set_foreground", &r, &g, &b)) { - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "iii:set_foreground", &r, &g, &b)) { - PyErr_Clear(); - PyArg_ParseTuple(args, "O!:set_foreground", - PyGimpRGB_Type, &color); - return NULL; - } - } - - r = CLAMP(r, 0, 255); - g = CLAMP(g, 0, 255); - b = CLAMP(b, 0, 255); - - gimp_rgba_set_uchar(&rgb, r, g, b, 255); + if (!pygimp_rgb_from_pyobject(args, &rgb)) + return NULL; } gimp_context_set_foreground(&rgb); diff --git a/plug-ins/pygimp/pygimp-colors.c b/plug-ins/pygimp/pygimp-colors.c index cbe83c7071..8aa8d32184 100644 --- a/plug-ins/pygimp/pygimp-colors.c +++ b/plug-ins/pygimp/pygimp-colors.c @@ -2372,7 +2372,6 @@ pygimp_rgb_from_pyobject(PyObject *object, GimpRGB *color) return 0; } } else if (PySequence_Check(object)) { - GimpRGB rgb; PyObject *r, *g, *b, *a = NULL; if (!PyArg_ParseTuple(object, "OOO|O", &r, &g, &b, &a)) @@ -2380,9 +2379,9 @@ pygimp_rgb_from_pyobject(PyObject *object, GimpRGB *color) #define SET_MEMBER(m) G_STMT_START { \ if (PyInt_Check(m)) \ - rgb.m = (double) PyInt_AS_LONG(m) / 255.0; \ + color->m = (double) PyInt_AS_LONG(m) / 255.0; \ else if (PyFloat_Check(m)) \ - rgb.m = PyFloat_AS_DOUBLE(m); \ + color->m = PyFloat_AS_DOUBLE(m); \ else { \ PyErr_SetString(PyExc_TypeError, \ #m " must be an int or a float"); \ @@ -2397,11 +2396,9 @@ pygimp_rgb_from_pyobject(PyObject *object, GimpRGB *color) if (a) SET_MEMBER(a); else - rgb.a = 1.0; - color->r = rgb.r; - color->g = rgb.g; - color->b = rgb.b; - color->a = rgb.a; + color->a = 1.0; + + gimp_rgb_clamp(color); return 1; }