-
Notifications
You must be signed in to change notification settings - Fork 0
/
retro-filter.c
222 lines (180 loc) · 6.26 KB
/
retro-filter.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/* 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 2015, 2016 Red Hat, Inc.
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#ifdef GEGL_PROPERTIES
enum_start (gegl_retro_filter_preset)
enum_value (GEGL_RETRO_FILTER_PRESET_NONE, "none", "None")
enum_value (GEGL_RETRO_FILTER_PRESET_1977, "prog", "Prog")
enum_value (GEGL_RETRO_FILTER_PRESET_BRANNAN, "indie", "Indie")
enum_value (GEGL_RETRO_FILTER_PRESET_GOTHAM, "batcave", "Batcave")
enum_value (GEGL_RETRO_FILTER_PRESET_NASHVILLE, "country", "Country")
enum_end (GeglRetroFilterPreset)
property_enum (preset, _("Preset"),
GeglRetroFilterPreset, gegl_retro_filter_preset,
GEGL_RETRO_FILTER_PRESET_NONE)
description (_("Which filter to apply"))
#else
#ifndef GEGL_OP_C_FILE
#define GEGL_OP_C_SOURCE retro-filter.c
#endif
#ifndef GEGL_OP_NAME
#define GEGL_OP_NAME imgfloextra_retro_filter
#endif
#include "gegl-plugin.h"
struct _GeglOp
{
GeglOperationMeta parent_instance;
gpointer properties;
GeglNode *input;
GeglNode *output;
GList *nodes;
};
typedef struct
{
GeglOperationMetaClass parent_class;
} GeglOpClass;
#include "gegl-op.h"
GEGL_DEFINE_DYNAMIC_OPERATION(GEGL_TYPE_OPERATION_META)
static void
do_setup (GeglOperation *operation)
{
GeglOp *self = GEGL_OP (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglNode *node;
GList *l;
g_list_free_full (self->nodes, g_object_unref);
self->nodes = NULL;
switch (o->preset)
{
case GEGL_RETRO_FILTER_PRESET_NONE:
node = gegl_node_new_child (operation->node,
"operation", "gegl:nop",
NULL);
self->nodes = g_list_prepend (self->nodes, node);
break;
case GEGL_RETRO_FILTER_PRESET_1977:
node = gegl_node_new_child (operation->node,
"operation", "imgfloextra:retro-curve",
"preset", o->preset,
NULL);
self->nodes = g_list_prepend (self->nodes, node);
break;
case GEGL_RETRO_FILTER_PRESET_BRANNAN:
node = gegl_node_new_child (operation->node,
"operation", "imgfloextra:retro-curve",
"preset", o->preset,
NULL);
self->nodes = g_list_prepend (self->nodes, node);
break;
case GEGL_RETRO_FILTER_PRESET_GOTHAM:
node = gegl_node_new_child (operation->node,
"operation", "imgfloextra:retro-curve",
"preset", o->preset,
NULL);
self->nodes = g_list_prepend (self->nodes, node);
node = gegl_node_new_child (operation->node,
"operation", "imgfloextra:gray",
NULL);
self->nodes = g_list_prepend (self->nodes, node);
break;
case GEGL_RETRO_FILTER_PRESET_NASHVILLE:
node = gegl_node_new_child (operation->node,
"operation", "imgfloextra:retro-curve",
"preset", o->preset,
NULL);
self->nodes = g_list_prepend (self->nodes, node);
break;
default:
break;
}
node = GEGL_NODE (self->nodes->data);
gegl_node_link (self->input, node);
for (l = self->nodes; l != NULL && l->next != NULL; l = l->next)
{
GeglNode *sink = GEGL_NODE (l->next->data);
GeglNode *source = GEGL_NODE (l->data);
gegl_node_link (source, sink);
gegl_operation_meta_watch_node (operation, source);
}
node = GEGL_NODE (l->data);
gegl_node_link (node, self->output);
gegl_operation_meta_watch_node (operation, node);
}
static void
attach (GeglOperation *operation)
{
GeglOp *self = GEGL_OP (operation);
self->input = gegl_node_get_output_proxy (operation->node, "input");
self->output = gegl_node_get_output_proxy (operation->node, "output");
do_setup (operation);
}
static GeglNode *
detect (GeglOperation *operation,
gint x,
gint y)
{
GeglOp *self = GEGL_OP (operation);
GeglNode *output = self->output;
GeglRectangle bounds;
bounds = gegl_node_get_bounding_box (output);
if (x >= bounds.x &&
y >= bounds.y &&
x < bounds.x + bounds.width &&
y < bounds.y + bounds.height)
return operation->node;
return NULL;
}
static void
finalize (GObject *object)
{
GeglOp *self = GEGL_OP (object);
g_list_free (self->nodes);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
static void
my_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GeglOperation *operation = GEGL_OPERATION (object);
GeglOp *self = GEGL_OP (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglRetroFilterPreset old_preset = o->preset;
set_property (object, property_id, value, pspec);
if (self->input != NULL && o->preset != old_preset)
do_setup (operation);
}
static void
gegl_op_class_init (GeglOpClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
object_class->finalize = finalize;
object_class->set_property = my_set_property;
operation_class->attach = attach;
operation_class->detect = detect;
gegl_operation_class_set_keys (operation_class,
"name", "imgfloextra:retro-filter",
"title", _("Retro Filter"),
"categories", "meta:color",
"description", _("Apply a preset filter to an image"),
NULL);
}
#endif