Commit e8c7a7a4 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh
Browse files

plug-ins/pygimp/pygimp-api.h export our API to other modules in a saner

2005-06-03  Manish Singh  <yosh@gimp.org>

        * plug-ins/pygimp/pygimp-api.h
        * plug-ins/pygimp/gimpmodule.c: export our API to other modules
        in a saner fashion. Also add checks_get_shades method.

        * plug-ins/pygimp/procbrowser.c: Use new export API.

        * plug-ins/pygimp/pygimp-drawable.c (drw_mask_intersect):
        use Py_BuildValue to build the tuple.

        * plug-ins/pygimp/pygimp-image.c (img_repr): capitalization fix.

        * plug-ins/pygimp/pygimp-rgb.c
        * plug-ins/pygimp/pygimpcolor.h
        * plug-ins/pygimp/gimpcolormodule.c: beginnings of a wrapper to
        libgimpcolor.

        * plug-ins/pygimp/gimpfu.py
        * plug-ins/pygimp/gimpenums.py
        * plug-ins/pygimp/gimpenumsmodule.c: use gimp enum API to find out
        our enums.

        * plug-ins/pygimp/Makefile.am: hook in all of the above.
parent 5c160d19
2005-06-03 Manish Singh <yosh@gimp.org>
* plug-ins/pygimp/pygimp-api.h
* plug-ins/pygimp/gimpmodule.c: export our API to other modules
in a saner fashion. Also add checks_get_shades method.
* plug-ins/pygimp/procbrowser.c: Use new export API.
* plug-ins/pygimp/pygimp-drawable.c (drw_mask_intersect):
use Py_BuildValue to build the tuple.
* plug-ins/pygimp/pygimp-image.c (img_repr): capitalization fix.
* plug-ins/pygimp/pygimp-rgb.c
* plug-ins/pygimp/pygimpcolor.h
* plug-ins/pygimp/gimpcolormodule.c: beginnings of a wrapper to
libgimpcolor.
* plug-ins/pygimp/gimpfu.py
* plug-ins/pygimp/gimpenums.py
* plug-ins/pygimp/gimpenumsmodule.c: use gimp enum API to find out
our enums.
* plug-ins/pygimp/Makefile.am: hook in all of the above.
2005-06-03 Manish Singh <yosh@gimp.org>
* configure.in: build pygimp by default.
......
......@@ -21,17 +21,19 @@ INCLUDES = -I$(top_srcdir) $(PYTHON_INCLUDES) $(PYGTK_CFLAGS) $(GTK_CFLAGS)
pygimpdir = $(gimpplugindir)/python
pygimp_LTLIBRARIES = gimpmodule.la gimpprocbrowsermodule.la
pygimp_LTLIBRARIES = gimpmodule.la _gimpenumsmodule.la gimpcolormodule.la \
gimpprocbrowsermodule.la
gimpmodule_la_SOURCES = \
gimpmodule.c \
pygimp-image.c \
pygimp-drawable.c \
pygimp-tile.c \
pygimp-display.c \
pygimp-drawable.c \
pygimp-image.c \
pygimp-parasite.c \
pygimp-pdb.c \
pygimp.h
pygimp-tile.c \
pygimp.h \
pygimp-api.h
gimpmodule_la_LDFLAGS = -module -avoid-version $(no_undefined) \
-export-symbols-regex initgimp
......@@ -43,6 +45,31 @@ gimpmodule_la_LIBADD = \
$(GLIB_LIBS) \
$(RT_LIBS)
_gimpenumsmodule_la_SOURCES = \
gimpenumsmodule.c
_gimpenumsmodule_la_LDFLAGS = -module -avoid-version \
-export-symbols-regex init_gimpenums
_gimpenumsmodule_la_LIBADD = \
$(libgimp) \
$(libgimpcolor) \
$(libgimpbase) \
$(GLIB_LIBS) \
$(RT_LIBS)
gimpcolormodule_la_SOURCES = \
gimpcolormodule.c \
pygimp-rgb.c \
pygimpcolor.h
gimpcolormodule_la_LDFLAGS = -module -avoid-version \
-export-symbols-regex initgimpcolor
gimpcolormodule_la_LIBADD = \
$(libgimpcolor) \
$(GLIB_LIBS)
gimpprocbrowsermodule_la_SOURCES = \
procbrowser.c
......
/* -*- Mode: C; c-basic-offset: 4 -*-
Gimp-Python - allows the writing of Gimp plugins in Python.
Copyright (C) 2005 Manish Singh <yosh@gimp.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "pygimpcolor.h"
#if PY_VERSION_HEX >= 0x2030000
#define ARG_UINTARRAY_FORMAT "(IIII)"
#else
#define ARG_UINTARRAY_FORMAT "(iiii)"
#endif
static PyObject *
pygimp_rgb_parse_name(PyObject *self, PyObject *args, PyObject *kwargs)
{
char *name;
int len;
GimpRGB rgb;
gboolean success;
static char *kwlist[] = { "name", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#:rgb_parse_name", kwlist,
&name, &len))
return NULL;
rgb.a = 1.0;
success = gimp_rgb_parse_name(&rgb, name, len);
PyMem_Free(name);
if (!success) {
PyErr_SetString(PyExc_ValueError, "unable to parse color name");
return NULL;
}
return pygimp_rgb_new(&rgb);
}
static PyObject *
pygimp_rgb_parse_hex(PyObject *self, PyObject *args, PyObject *kwargs)
{
char *hex;
int len;
GimpRGB rgb;
gboolean success;
static char *kwlist[] = { "hex", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#:rgb_parse_hex", kwlist,
&hex, &len))
return NULL;
rgb.a = 1.0;
success = gimp_rgb_parse_hex(&rgb, hex, len);
PyMem_Free(hex);
if (!success) {
PyErr_SetString(PyExc_ValueError, "unable to parse hex value");
return NULL;
}
return pygimp_rgb_new(&rgb);
}
static PyObject *
pygimp_rgb_parse_css(PyObject *self, PyObject *args, PyObject *kwargs)
{
char *css;
int len;
GimpRGB rgb;
gboolean success, with_alpha = FALSE;
static char *kwlist[] = { "css", "with_alpha", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"s#|i:rgb_parse_css", kwlist,
&css, &len, &with_alpha))
return NULL;
if (with_alpha)
success = gimp_rgba_parse_css(&rgb, css, len);
else {
rgb.a = 1.0;
success = gimp_rgb_parse_css(&rgb, css, len);
}
if (!success) {
PyErr_SetString(PyExc_ValueError, "unable to parse CSS color");
return NULL;
}
return pygimp_rgb_new(&rgb);
}
static PyObject *
pygimp_rgb_list_names(PyObject *self)
{
int num_names, i;
const char **names;
GimpRGB *colors;
PyObject *dict, *color;
num_names = gimp_rgb_list_names(&names, &colors);
dict = PyDict_New();
if (!dict)
goto cleanup;
for (i = 0; i < num_names; i++) {
color = pygimp_rgb_new(&colors[i]);
if (!color)
goto bail;
if (PyDict_SetItemString(dict, names[i], color) < 0)
{
Py_DECREF(color);
goto bail;
}
Py_DECREF(color);
}
goto cleanup;
bail:
Py_DECREF(dict);
dict = NULL;
cleanup:
g_free(names);
g_free(colors);
return dict;
}
#if 0
static PyObject *
pygimp_bilinear(PyObject *self, PyObject *args, PyObject *kwargs)
{
gdouble x, y;
gdouble values[4];
static char *kwlist[] = { "x", "y", "values", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"dd(dddd):bilinear", kwlist,
&x, &y,
&values[0], &values[1],
&values[2], &values[3]))
return NULL;
return PyFloat_FromDouble(gimp_bilinear(x, y, values));
}
static PyObject *
pygimp_bilinear_8(PyObject *self, PyObject *args, PyObject *kwargs)
{
gdouble x, y;
char *values;
int len;
guchar r;
static char *kwlist[] = { "x", "y", "values", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"dds#:bilinear_8", kwlist,
&x, &y, &values, &len))
return NULL;
if (len != 4) {
PyErr_SetString(PyExc_ValueError,
"string must be exactly 4 bytes long");
return NULL;
}
r = gimp_bilinear_8(x, y, values);
return PyString_FromStringAndSize(&r, 1);
}
static PyObject *
pygimp_bilinear_32(PyObject *self, PyObject *args, PyObject *kwargs)
{
gdouble x, y;
guint32 values[4];
static char *kwlist[] = { "x", "y", "values", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"dd" ARG_UINTARRAY_FORMAT ":bilinear_32",
kwlist,
&x, &y,
&values[0], &values[1],
&values[2], &values[3]))
return NULL;
return PyInt_FromLong(gimp_bilinear_32(x, y, values));
}
static PyObject *
pygimp_bilinear_pixels_8(PyObject *self, PyObject *args, PyObject *kwargs)
{
Py_INCREF(Py_None);
return Py_None;
}
typedef struct
{
PyObject *func;
PyObject *data;
} ProxyData;
static void
proxy_render(gdouble x, gdouble y, GimpRGB *color, gpointer pdata)
{
ProxyData *data = pdata;
if (data->data)
PyObject_CallFunction(data->func, "ddO&O", x, y, pygimp_rgb_new, color,
data->data);
else
PyObject_CallFunction(data->func, "ddO&", x, y, pygimp_rgb_new, color);
}
static void
proxy_put_pixel(gint x, gint y, GimpRGB *color, gpointer pdata)
{
ProxyData *data = pdata;
if (data->data)
PyObject_CallFunction(data->func, "iiO&O", x, y, pygimp_rgb_new, color,
data->data);
else
PyObject_CallFunction(data->func, "iiO&", x, y, pygimp_rgb_new, color);
}
static void
proxy_progress(gint min, gint max, gint current, gpointer pdata)
{
ProxyData *data = pdata;
if (data->data)
PyObject_CallFunction(data->func, "iiiO", min, max, current,
data->data);
else
PyObject_CallFunction(data->func, "iii", min, max, current);
}
static PyObject *
pygimp_adaptive_supersample_area(PyObject *self, PyObject *args, PyObject *kwargs)
{
gulong r;
gint x1, y1, x2, y2, max_depth;
gdouble threshold;
PyObject *py_func_render = NULL, *py_data_render = NULL;
PyObject *py_func_put_pixel = NULL, *py_data_put_pixel = NULL;
PyObject *py_func_progress = NULL, *py_data_progress = NULL;
GimpRenderFunc proxy_func_render = NULL;
GimpPutPixelFunc proxy_func_put_pixel = NULL;
GimpProgressFunc proxy_func_progress = NULL;
ProxyData proxy_data_render, proxy_data_put_pixel, proxy_data_progress;
static char *kwlist[] = {
"x1", "y1", "x2", "y2", "max_depth", "threshold",
"render_func", "render_data",
"put_pixel_func", "put_pixel_data",
"progress_func", "progress_data",
NULL
};
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"iiiiid|OOOOOO"
":adaptive_supersample_area",
kwlist,
&x1, &y1, &x2, &y2, &max_depth, &threshold,
&py_func_render, &py_data_render,
&py_func_put_pixel, &py_data_put_pixel,
&py_func_progress, &py_data_progress))
return NULL;
#define PROCESS_FUNC(n) G_STMT_START { \
if (py_func_##n != NULL) { \
if (!PyCallable_Check(py_func_##n)) { \
PyErr_SetString(PyExc_TypeError, #n "_func " \
"must be callable"); \
return NULL; \
} \
\
proxy_func_##n = proxy_##n; \
\
proxy_data_##n.func = py_func_##n; \
proxy_data_##n.data = py_data_##n; \
} \
} G_STMT_END
PROCESS_FUNC(render);
PROCESS_FUNC(put_pixel);
PROCESS_FUNC(progress);
#undef PROCESS_FUNC
#define PASS_FUNC(n) proxy_func_##n, &proxy_data_##n
r = gimp_adaptive_supersample_area (x1, y1, x2, y2, max_depth, threshold,
PASS_FUNC(render),
PASS_FUNC(put_pixel),
PASS_FUNC(progress));
#undef PASS_FUNC
return PyInt_FromLong(r);
}
#endif
/* List of methods defined in the module */
static struct PyMethodDef gimpcolor_methods[] = {
{"rgb_parse_name", (PyCFunction)pygimp_rgb_parse_name, METH_VARARGS | METH_KEYWORDS},
{"rgb_parse_hex", (PyCFunction)pygimp_rgb_parse_hex, METH_VARARGS | METH_KEYWORDS},
{"rgb_parse_css", (PyCFunction)pygimp_rgb_parse_css, METH_VARARGS | METH_KEYWORDS},
{"rgb_names", (PyCFunction)pygimp_rgb_list_names, METH_NOARGS},
#if 0
{"bilinear", (PyCFunction)pygimp_bilinear, METH_VARARGS | METH_KEYWORDS},
{"bilinear_8", (PyCFunction)pygimp_bilinear_8, METH_VARARGS | METH_KEYWORDS},
{"bilinear_32", (PyCFunction)pygimp_bilinear_32, METH_VARARGS | METH_KEYWORDS},
//{"bilinear_pixels_8", (PyCFunction)pygimp_bilinear_pixels_8, METH_VARARGS | METH_KEYWORDS},
{"adaptive_supersample_area", (PyCFunction)pygimp_adaptive_supersample_area, METH_VARARGS | METH_KEYWORDS},
#endif
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
};
/* Initialization function for the module (*must* be called initgimpcolor) */
static char gimpcolor_doc[] =
"This module provides interfaces to allow you to write gimp plugins"
;
DL_EXPORT(void)
initgimpcolor(void)
{
PyObject *m, *d;
init_pygobject();
/* Create the module and add the functions */
m = Py_InitModule3("gimpcolor", gimpcolor_methods, gimpcolor_doc);
d = PyModule_GetDict(m);
pyg_register_boxed(d, "RGB", GIMP_TYPE_RGB, &PyGimpRGB_Type);
PyModule_AddObject(m, "RGB_COMPOSITE_NONE",
PyInt_FromLong(GIMP_RGB_COMPOSITE_NONE));
PyModule_AddObject(m, "RGB_COMPOSITE_NORMAL",
PyInt_FromLong(GIMP_RGB_COMPOSITE_NORMAL));
PyModule_AddObject(m, "RGB_COMPOSITE_BEHIND",
PyInt_FromLong(GIMP_RGB_COMPOSITE_BEHIND));
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module gimpcolor");
}
# Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997-2003 James Henstridge <james@daa.com.au>
# Copyright (C) 2005 Manish Singh <yosh@gimp.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -17,312 +17,47 @@
# gimpenums.py -- constants for use with the gimp module
#
# this file contains constants that are useful for use in
# this file pulls in constants that are useful for use in
# gimp plugins. Just add 'from gimpenums import *' to the top
# of the script
# NOTE: This file is autogenerated by enumcode-py.pl.
from _gimpenums import *
# TRUE and FALSE constants ...
import __builtin__
if not hasattr(__builtin__, 'True'):
__builtin__.True = (1 == 1)
__builtin__.False = (1 != 1)
del __builtin__
# This is from pygtk/gtk/__init__.py
# Copyright (C) 1998-2003 James Henstridge
FALSE = False
TRUE = True
from warnings import warn as _warn
# Parasite Flags
PARASITE_PERSISTENT = 1
PARASITE_UNDOABLE = 2
PARASITE_ATTACH_PARENT = (0x80 << 8)
PARASITE_PARENT_PERSISTENT = (PARASITE_PERSISTENT << 8)
PARASITE_PARENT_UNDOABLE = (PARASITE_UNDOABLE << 8)
PARASITE_ATTACH_GRANDPARENT = (0x80 << 16)
PARASITE_GRANDPARENT_PERSISTENT = (PARASITE_PERSISTENT << 16)
PARASITE_GRANDPARENT_UNDOABLE = (PARASITE_UNDOABLE << 16)
class _DeprecatedConstant:
def __init__(self, value, name, suggestion):
self._v = value
self._name = name
self._suggestion = suggestion
# GimpAddMaskType
ADD_WHITE_MASK = 0
ADD_BLACK_MASK = 1
ADD_ALPHA_MASK = 2
ADD_ALPHA_TRANSFER_MASK = 3
ADD_SELECTION_MASK = 4
ADD_COPY_MASK = 5
def _deprecated(self, value):
message = '%s is deprecated, use %s instead' % (self._name,
self._suggestion)
_warn(message, DeprecationWarning, 3)
return value
# GimpBlendMode
FG_BG_RGB_MODE = 0
FG_BG_HSV_MODE = 1
FG_TRANSPARENT_MODE = 2
CUSTOM_MODE = 3
__nonzero__ = lambda self: self._deprecated(self._v == True)
__int__ = lambda self: self._deprecated(int(self._v))
__str__ = lambda self: self._deprecated(str(self._v))
__repr__ = lambda self: self._deprecated(repr(self._v))
__cmp__ = lambda self, other: self._deprecated(cmp(self._v, other))
# GimpBrushApplicationMode
BRUSH_HARD = 0
BRUSH_SOFT = 1
TRUE = _DeprecatedConstant(True, 'gimpenums.TRUE', 'True')
FALSE = _DeprecatedConstant(False, 'gimpenums.FALSE', 'False')
# GimpBucketFillMode
FG_BUCKET_FILL = 0
BG_BUCKET_FILL = 1
PATTERN_BUCKET_FILL = 2
del _DeprecatedConstant
# GimpChannelOps
CHANNEL_OP_ADD = 0
CHANNEL_OP_SUBTRACT = 1
CHANNEL_OP_REPLACE = 2
CHANNEL_OP_INTERSECT = 3
# GimpChannelType
RED_CHANNEL = 0
GREEN_CHANNEL = 1
BLUE_CHANNEL = 2
GRAY_CHANNEL = 3
INDEXED_CHANNEL = 4
ALPHA_CHANNEL = 5
# GimpCloneType
IMAGE_CLONE = 0
PATTERN_CLONE = 1
# GimpConvertDitherType
NO_DITHER = 0
FS_DITHER = 1
FSLOWBLEED_DITHER = 2
FIXED_DITHER = 3
# GimpConvertPaletteType
MAKE_PALETTE = 0
REUSE_PALETTE = 1
WEB_PALETTE = 2
MONO_PALETTE = 3
CUSTOM_PALETTE = 4
# GimpConvolutionType
NORMAL_CONVOL = 0
ABSOLUTE_CONVOL = 1
NEGATIVE_CONVOL = 2
# GimpConvolveType
BLUR_CONVOLVE = 0
SHARPEN_CONVOLVE = 1
# GimpDesaturateMode
DESATURATE_LIGHTNESS = 0
DESATURATE_LUMINOSITY = 1
DESATURATE_AVERAGE = 2
# GimpDodgeBurnType
DODGE = 0
BURN = 1
# GimpFillType
FOREGROUND_FILL = 0
BACKGROUND_FILL = 1
WHITE_FILL = 2
TRANSPARENT_FILL = 3
PATTERN_FILL = 4
# GimpGradientSegmentColor
GRADIENT_SEGMENT_RGB = 0
GRADIENT_SEGMENT_HSV_CCW = 1
GRADIENT_SEGMENT_HSV_CW = 2
# GimpGradientSegmentType
GRADIENT_SEGMENT_LINEAR = 0
GRADIENT_SEGMENT_CURVED = 1
GRADIENT_SEGMENT_SINE = 2
GRADIENT_SEGMENT_SPHERE_INCREASING = 3
GRADIENT_SEGMENT_SPHERE_DECREASING = 4
# GimpGradientType
GRADIENT_LINEAR = 0
GRADIENT_BILINEAR = 1
GRADIENT_RADIAL = 2
GRADIENT_SQUARE = 3
GRADIENT_CONICAL_SYMMETRIC = 4
GRADIENT_CONICAL_ASYMMETRIC = 5
GRADIENT_SHAPEBURST_ANGULAR = 6
GRADIENT_SHAPEBURST_SPHERICAL = 7