1 /* -*- Mode: C; c-basic-offset: 4 -*- 2 * Gimp-Python - allows the writing of Gimp plugins in Python. 3 * Copyright (C) 2005-2006 Manish Singh <yosh@gimp.org> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef _PYGIMPCOLOR_API_H_ 20 #define _PYGIMPCOLOR_API_H_ 21 22 #include <Python.h> 23 24 #include <libgimpcolor/gimpcolor.h> 25 26 struct _PyGimpColor_Functions { 27 PyTypeObject *RGB_Type; 28 PyObject *(* rgb_new)(const GimpRGB *rgb); 29 PyTypeObject *HSV_Type; 30 PyObject *(* hsv_new)(const GimpHSV *hsv); 31 PyTypeObject *HSL_Type; 32 PyObject *(* hsl_new)(const GimpHSL *hsl); 33 PyTypeObject *CMYK_Type; 34 PyObject *(* cmyk_new)(const GimpCMYK *cmyk); 35 int (* rgb_from_pyobject)(PyObject *object, GimpRGB *color); 36 }; 37 38 #ifndef _INSIDE_PYGIMPCOLOR_ 39 40 #if defined(NO_IMPORT) || defined(NO_IMPORT_PYGIMPCOLOR) 41 extern struct _PyGimpColor_Functions *_PyGimpColor_API; 42 #else 43 struct _PyGimpColor_Functions *_PyGimpColor_API; 44 #endif 45 46 #define PyGimpRGB_Type (_PyGimpColor_API->RGB_Type) 47 #define PyGimpHSV_Type (_PyGimpColor_API->HSV_Type) 48 #define PyGimpHSL_Type (_PyGimpColor_API->HSL_Type) 49 #define PyGimpCMYK_Type (_PyGimpColor_API->CMYK_Type) 50 51 #define pygimp_rgb_check(v) (pyg_boxed_check((v), GIMP_TYPE_RGB)) 52 #define pygimp_hsv_check(v) (pyg_boxed_check((v), GIMP_TYPE_HSV)) 53 #define pygimp_hsl_check(v) (pyg_boxed_check((v), GIMP_TYPE_HSL)) 54 #define pygimp_cmyk_check(v) (pyg_boxed_check((v), GIMP_TYPE_CMYK)) 55 56 #define pygimp_rgb_new (_PyGimpColor_API->rgb_new) 57 #define pygimp_hsv_new (_PyGimpColor_API->hsv_new) 58 #define pygimp_hsl_new (_PyGimpColor_API->hsl_new) 59 #define pygimp_cmyk_new (_PyGimpColor_API->cmyk_new) 60 61 #define pygimp_rgb_from_pyobject (_PyGimpColor_API->rgb_from_pyobject) 62 63 #define init_pygimpcolor() G_STMT_START { \ 64 PyObject *gimpcolormodule = PyImport_ImportModule("gimpcolor"); \ 65 if (gimpcolormodule != NULL) { \ 66 PyObject *mdict = PyModule_GetDict(gimpcolormodule); \ 67 PyObject *cobject = PyDict_GetItemString(mdict, "_PyGimpColor_API"); \ 68 if (PyCObject_Check(cobject)) \ 69 _PyGimpColor_API = PyCObject_AsVoidPtr(cobject); \ 70 else { \ 71 PyErr_SetString(PyExc_RuntimeError, \ 72 "could not find _PyGimpColor_API object"); \ 73 return; \ 74 } \ 75 } else { \ 76 PyErr_SetString(PyExc_ImportError, \ 77 "could not import gimpcolor"); \ 78 return; \ 79 } \ 80 } G_STMT_END 81 82 #endif /* ! _INSIDE_PYGIMPCOLOR_ */ 83 84 #endif /* _PYGIMPCOLOR_API_H_ */ 85