PyObject * pygimp_param_to_tuple(int nparams, const GimpParam *params) { PyObject *args, *tmp; int i, j, n; args = PyTuple_New(nparams); for (i = 0; i < nparams && params[i].type != GIMP_PDB_END; i++) { PyObject *value = NULL; switch(params[i].type) { case GIMP_PDB_INT32: value = PyInt_FromLong(params[i].data.d_int32); break; case GIMP_PDB_INT16: value = PyInt_FromLong(params[i].data.d_int16); break; case GIMP_PDB_INT8: value = PyInt_FromLong(params[i].data.d_int8); break; case GIMP_PDB_FLOAT: value = PyFloat_FromDouble(params[i].data.d_float); break; case GIMP_PDB_STRING: if (params[i].data.d_string == NULL) { Py_INCREF(Py_None); value = Py_None; } else value = PyString_FromString(params[i].data.d_string); break; /* For these to work, the previous argument must have * been an integer */ case GIMP_PDB_INT32ARRAY: if (params[i].data.d_int32array == NULL) { value = PyTuple_New(0); break; } if ((tmp=PyTuple_GetItem(args, i-1)) == NULL) { Py_DECREF(args); return NULL; } if (!PyInt_Check(tmp)) { PyErr_SetString(PyExc_TypeError, "count type must be integer"); Py_DECREF(args); return NULL; } n = PyInt_AsLong(tmp); value = PyTuple_New(n); for (j = 0; j < n; j++) PyTuple_SetItem(value, j, PyInt_FromLong(params[i].data.d_int32array[j])); break; case GIMP_PDB_INT16ARRAY: if (params[i].data.d_int16array == NULL) { value = PyTuple_New(0); break; } if ((tmp=PyTuple_GetItem(args, i-1)) == NULL) { Py_DECREF(args); return NULL; } if (!PyInt_Check(tmp)) { PyErr_SetString(PyExc_TypeError, "count type must be integer"); Py_DECREF(args); return NULL; } n = PyInt_AsLong(tmp); value = PyTuple_New(n); for (j = 0; j < n; j++) PyTuple_SetItem(value, j, PyInt_FromLong(params[i].data.d_int16array[j])); break; case GIMP_PDB_INT8ARRAY: if (params[i].data.d_int8array == NULL) { value = PyTuple_New(0); break; } if ((tmp=PyTuple_GetItem(args, i-1)) == NULL) { Py_DECREF(args); return NULL; } if (!PyInt_Check(tmp)) { PyErr_SetString(PyExc_TypeError, "count type must be integer"); Py_DECREF(args); return NULL; } n = PyInt_AsLong(tmp); value = PyTuple_New(n); for (j = 0; j < n; j++) PyTuple_SetItem(value, j, PyInt_FromLong(params[i].data.d_int8array[j])); break; case GIMP_PDB_FLOATARRAY: if (params[i].data.d_floatarray == NULL) { value = PyTuple_New(0); break; } if ((tmp=PyTuple_GetItem(args, i-1)) == NULL) { Py_DECREF(args); return NULL; } if (!PyInt_Check(tmp)) { PyErr_SetString(PyExc_TypeError, "count type must be integer"); Py_DECREF(args); return NULL; } n = PyInt_AsLong(tmp); value = PyTuple_New(n); for (j = 0; j < n; j++) PyTuple_SetItem(value, j, PyFloat_FromDouble(params[i].data.d_floatarray[j])); break; case GIMP_PDB_STRINGARRAY: if (params[i].data.d_stringarray == NULL) { value = PyTuple_New(0); break; } if ((tmp=PyTuple_GetItem(args, i-1)) == NULL) { Py_DECREF(args); return NULL; } if (!PyInt_Check(tmp)) { PyErr_SetString(PyExc_TypeError, "count type must be integer"); Py_DECREF(args); return NULL; } n = PyInt_AsLong(tmp); value = PyTuple_New(n); for (j = 0; j < n; j++) PyTuple_SetItem(value, j, params[i].data.d_stringarray[j] ? PyString_FromString(params[i].data.d_stringarray[j]) : PyString_FromString("")); break; case GIMP_PDB_COLOR: value = pygimp_rgb_new(¶ms[i].data.d_color); break; case GIMP_PDB_REGION: value = Py_BuildValue("(iiii)", (int) params[i].data.d_region.x, (int) params[i].data.d_region.y, (int) params[i].data.d_region.width, (int) params[i].data.d_region.height); break; case GIMP_PDB_DISPLAY: value = pygimp_display_new(params[i].data.d_display); break; case GIMP_PDB_IMAGE: value = pygimp_image_new(params[i].data.d_image); break; case GIMP_PDB_LAYER: value = pygimp_layer_new(params[i].data.d_layer); break; case GIMP_PDB_CHANNEL: value = pygimp_channel_new(params[i].data.d_channel); break; case GIMP_PDB_DRAWABLE: value = pygimp_drawable_new(NULL, params[i].data.d_drawable); break; case GIMP_PDB_SELECTION: value = pygimp_layer_new(params[i].data.d_selection); break; case GIMP_PDB_BOUNDARY: value = PyInt_FromLong(params[i].data.d_boundary); break; case GIMP_PDB_VECTORS: value = pygimp_vectors_new(params[i].data.d_vectors); break; case GIMP_PDB_PARASITE: value = pygimp_parasite_new(gimp_parasite_copy( &(params[i].data.d_parasite))); break; case GIMP_PDB_STATUS: value = PyInt_FromLong(params[i].data.d_status); break; case GIMP_PDB_END: break; } PyTuple_SetItem(args, i, value); } return args; }
static PyObject * vectors_get_image(PyGimpVectors *self, void *closure) { return pygimp_image_new(gimp_item_get_image(self->ID)); }