1 /* -*- Mode: C; c-basic-offset: 4 -*- 2 * Gimp-Python - allows the writing of Gimp plugins in Python. 3 * Copyright (C) 2005 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 _PYGIMP_API_H_ 20 #define _PYGIMP_API_H_ 21 22 #include <Python.h> 23 24 #include <libgimp/gimp.h> 25 26 typedef struct { 27 PyObject_HEAD 28 gint32 ID; 29 } PyGimpImage, PyGimpItem; 30 31 typedef struct { 32 PyObject_HEAD 33 gint32 ID; 34 } PyGimpDisplay; 35 36 typedef struct { 37 PyObject_HEAD 38 gint32 ID; 39 GimpDrawable *drawable; 40 } PyGimpDrawable, PyGimpLayer, PyGimpGroupLayer, PyGimpChannel; 41 42 typedef struct { 43 PyObject_HEAD 44 gint32 ID; 45 } PyGimpVectors; 46 47 struct _PyGimp_Functions { 48 PyTypeObject *Image_Type; 49 PyObject *(* image_new)(gint32 ID); 50 51 PyTypeObject *Display_Type; 52 PyObject *(* display_new)(gint32 ID); 53 54 PyTypeObject *Item_Type; 55 PyObject *(* item_new)(gint32 ID); 56 57 PyTypeObject *Drawable_Type; 58 PyObject *(* drawable_new)(GimpDrawable *drawable, gint32 ID); 59 60 PyTypeObject *Layer_Type; 61 PyObject *(* layer_new)(gint32 ID); 62 63 PyTypeObject *GroupLayer_Type; 64 PyObject *(* group_layer_new)(gint32 ID); 65 66 PyTypeObject *Channel_Type; 67 PyObject *(* channel_new)(gint32 ID); 68 69 PyTypeObject *Vectors_Type; 70 PyObject *(* vectors_new)(gint32 ID); 71 72 PyObject *pygimp_error; 73 }; 74 75 #ifndef _INSIDE_PYGIMP_ 76 77 #if defined(NO_IMPORT) || defined(NO_IMPORT_PYGIMP) 78 extern struct _PyGimp_Functions *_PyGimp_API; 79 #else 80 struct _PyGimp_Functions *_PyGimp_API; 81 #endif 82 83 #define PyGimpImage_Type (_PyGimp_API->Image_Type) 84 #define pygimp_image_new (_PyGimp_API->image_new) 85 #define PyGimpDisplay_Type (_PyGimp_API->Display_Type) 86 #define pygimp_display_new (_PyGimp_API->display_new) 87 #define PyGimpItem_Type (_PyGimp_API->Item_Type) 88 #define pygimp_item_new (_PyGimp_API->item_new) 89 #define PyGimpDrawable_Type (_PyGimp_API->Drawable_Type) 90 #define pygimp_drawable_new (_PyGimp_API->drawable_new) 91 #define PyGimpLayer_Type (_PyGimp_API->Layer_Type) 92 #define pygimp_layer_new (_PyGimp_API->layer_new) 93 #define PyGimpGroupLayer_Type (_PyGimp_API->GroupLayer_Type) 94 #define pygimp_group_layer_new (_PyGimp_API->group_layer_new) 95 #define PyGimpChannel_Type (_PyGimp_API->Channel_Type) 96 #define pygimp_channel_new (_PyGimp_API->channel_new) 97 #define PyGimpVectors_Type (_PyGimp_API->Vectors_Type) 98 #define pygimp_vectors_new (_PyGimp_API->vectors_new) 99 #define pygimp_error (_PyGimp_API->pygimp_error) 100 101 #define init_pygimp() G_STMT_START { \ 102 PyObject *gimpmodule = PyImport_ImportModule("gimp"); \ 103 if (gimpmodule != NULL) { \ 104 PyObject *mdict = PyModule_GetDict(gimpmodule); \ 105 PyObject *cobject = PyDict_GetItemString(mdict, "_PyGimp_API"); \ 106 if (PyCObject_Check(cobject)) \ 107 _PyGimp_API = PyCObject_AsVoidPtr(cobject); \ 108 else { \ 109 PyErr_SetString(PyExc_RuntimeError, \ 110 "could not find _PyGimp_API object"); \ 111 return; \ 112 } \ 113 } else { \ 114 PyErr_SetString(PyExc_ImportError, \ 115 "could not import gimp"); \ 116 return; \ 117 } \ 118 } G_STMT_END 119 120 #endif /* ! _INSIDE_PYGIMP_ */ 121 122 #endif /* _PYGIMP_API_H_ */ 123