-
Notifications
You must be signed in to change notification settings - Fork 2
/
gimp-source.c
179 lines (142 loc) · 4.92 KB
/
gimp-source.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* This file is an image processing operation for GEGL
*
* GEGL is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* GEGL 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#ifdef GEGL_CHANT_PROPERTIES
// Declare property of node, i.e. parameter to operation
// Int ... min, max, default, blurb
gegl_chant_int(drawableID, _("Drawable ID"), 0, 1000000, 0,
_("ID of GIMP Drawable to move in GEGL pipeline"))
/*
gegl_chant_pointer(drawableID, _("Drawable *"),
_("GIMP Drawable to move in GEGL pipeline"))
*/
#else
// Configure gegl-chant.h
#define GEGL_CHANT_TYPE_SOURCE
#define GEGL_CHANT_C_FILE "gimp-source.c"
// This generates boilerplate e.g. structs, set_property(), etc.
#include "gegl-chant.h"
/*
Depends on GIMP libgimp.
If this file is in gegl/operations/external,
modify gegl/configure.ac and gegl/operations/external/Makefile.am
to check presence of GIMP-2.0 directory and specify GIMP_CFLAGS, GIMP_LIBS make variables.
*/
#include <gimp-2.0/libgimp/gimp.h>
static GeglRectangle
get_bounding_box (GeglOperation *operation)
{
GeglRectangle result = {0,0,0,0};
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
if (o->drawableID)
{
g_printf("Bounds\n");
result.x = 0;
result.y = 0;
result.width = gimp_drawable_width (o->drawableID);
result.height = gimp_drawable_height (o->drawableID);
/*
result.width = ((GimpDrawable*) o->drawableID)->width;
result.height = ((GimpDrawable*) o->drawableID)->height;
*/
}
return result;
}
static void
prepare (GeglOperation *operation)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
if (o->drawableID)
{
const Babl *format;
GimpDrawable * drawable;
guint bpp;
// GEGL_MARK()
g_printf("Prepare\n");
drawable = gimp_drawable_get(o->drawableID);
// drawable = (GimpDrawable*) o->drawableID;
bpp = drawable->bpp;
// defined in app/gegl/gegl-utils.c
/*
if (self->linear)
format = gimp_bpp_to_babl_format_linear (bpp);
else
format = gimp_bpp_to_babl_format (bpp);
*/
// format = gimp_bpp_to_babl_format (bpp);
format = babl_format ("RGBA u8");
gegl_operation_set_format (operation, "output", format);
}
}
// !!! Note GIMP abbreviates Rgn instead of region, and gimp_ prefix to functions
// Compare to plug-ins/pygimp/pygimp-tile.c
static gboolean
process (GeglOperation *operation,
GeglBuffer *data,
const GeglRectangle *result)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
g_printf("Process\n");
if (! o->drawableID)
return FALSE;
else
{
GimpDrawable *drawable;
const Babl *format;
GimpPixelRgn io_pixel_region;
gpointer pr;
g_printf("result width %d\n", result->width);
drawable = gimp_drawable_get(o->drawableID);
// drawable = o->drawableID;
// format = gegl_operation_get_format (operation, "output");
format = babl_format ("RGBA u8");
gimp_pixel_rgn_init (&io_pixel_region, drawable,
result->x, result->y,
result->width, result->height,
FALSE, FALSE);
for (pr = gimp_pixel_rgns_register (1, &io_pixel_region);
pr;
pr = gimp_pixel_rgns_process (pr))
{
GeglRectangle rect = { io_pixel_region.x, io_pixel_region.y, io_pixel_region.w, io_pixel_region.h };
gegl_buffer_set (data, &rect, format, io_pixel_region.data, io_pixel_region.rowstride);
}
return TRUE;
}
}
static void
gegl_chant_class_init (GeglChantClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationSourceClass *source_class;
// cast
operation_class = GEGL_OPERATION_CLASS (klass);
source_class = GEGL_OPERATION_SOURCE_CLASS (klass);
// make object method attributes refer to reimplemented virtual (or default) methods
source_class->process = process;
operation_class->get_bounding_box = get_bounding_box;
operation_class->prepare = prepare;
operation_class->name = "gegl:gimp-source";
operation_class->compat_name = "gegl:load-drawable";
operation_class->categories = "programming:input";
operation_class->description =
_("Source from a GIMP Drawable, for use by GIMP plug-ins.");
/* operation_class->no_cache = TRUE; */
}
#endif