no need to use a temporary in tuple translation, and clamp the result.
2008-01-26 Manish Singh <yosh@gimp.org> * 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. svn path=/trunk/; revision=24716
This commit is contained in:

committed by
Manish Singh

parent
2ca4dcf882
commit
feff2c6b6d
@ -1,3 +1,12 @@
|
||||
2008-01-26 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* 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 <gwidion@mpc.com.br>
|
||||
|
||||
* plug-ins/pygimp/pygimp-colors.c (pygimp_rgb_from_pyobject): fix
|
||||
|
@ -837,31 +837,13 @@ 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);
|
||||
if (!pygimp_rgb_from_pyobject(args, &rgb))
|
||||
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);
|
||||
}
|
||||
|
||||
gimp_context_set_background(&rgb);
|
||||
|
||||
@ -876,31 +858,13 @@ 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);
|
||||
if (!pygimp_rgb_from_pyobject(args, &rgb))
|
||||
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);
|
||||
}
|
||||
|
||||
gimp_context_set_foreground(&rgb);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user