|
| 1 | +/* This file is an image processing operation for GEGL |
| 2 | + * |
| 3 | + * GEGL is free software; you can redistribute it and/or |
| 4 | + * modify it under the terms of the GNU Lesser General Public |
| 5 | + * License as published by the Free Software Foundation; either |
| 6 | + * version 3 of the License, or (at your option) any later version. |
| 7 | + * |
| 8 | + * GEGL is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | + * Lesser General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU Lesser General Public |
| 14 | + * License along with GEGL; if not, see <https://www.gnu.org/licenses/>. |
| 15 | + * |
| 16 | + * Copyright 2006 Øyvind Kolås <pippin@gimp.org> |
| 17 | + * GEGL Shiny Text for GEGL Effects CE- Beaver 2023 |
| 18 | + */ |
| 19 | + |
| 20 | +#include "config.h" |
| 21 | +#include <glib/gi18n-lib.h> |
| 22 | + |
| 23 | +#ifdef GEGL_PROPERTIES |
| 24 | + |
| 25 | +/* |
| 26 | +Search through GEGL's source code in /operations/common to find templates. |
| 27 | +
|
| 28 | +Example Templates below that call gaussian blur and hsl color overlay together' |
| 29 | + */ |
| 30 | + |
| 31 | +property_double (opacity, _("Opacity of Gloss Shine"), 1) |
| 32 | + description (_("Global opacity value that is always used on top of the optional auxiliary input buffer.")) |
| 33 | + value_range (0.100, 1) |
| 34 | + ui_range (0.1, 1) |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +property_double (x_scale, _("X Scale of Gloss Shine"), 28.00) |
| 39 | + description (_("Scale value for x axis")) |
| 40 | + value_range (15, 60.0) |
| 41 | + ui_range (15, 60.0) |
| 42 | + ui_meta ("unit", "pixel-distance") |
| 43 | + ui_meta ("axis", "x") |
| 44 | + |
| 45 | +property_double (y_scale, _("Y Scale of Gloss Shine"), 56.0) |
| 46 | + description (_("Scale value for y axis")) |
| 47 | + value_range (15, 150.0) |
| 48 | + ui_range (15, 150.0) |
| 49 | + ui_meta ("unit", "pixel-distance") |
| 50 | + ui_meta ("axis", "y") |
| 51 | + |
| 52 | +property_double (complexity, _("Complexity of Gloss Shine"), 0.8) |
| 53 | + description (_("Complexity factor")) |
| 54 | + value_range (0.1, 0.8) |
| 55 | + |
| 56 | +property_seed (seed, _("Random seed"), rand) |
| 57 | + |
| 58 | +property_boolean (tiling, _("Force tiling"), TRUE) |
| 59 | + description (_("If set, the pattern generated will tile")) |
| 60 | + ui_meta ("role", "output-extent") |
| 61 | + |
| 62 | +property_boolean (perturbation, _("Distorted"), TRUE) |
| 63 | + description (_("If set, the pattern will be a little more distorted")) |
| 64 | + ui_meta ("role", "output-extent") |
| 65 | + |
| 66 | +property_color (color1, _("Color 1"), "#ffffff") |
| 67 | + ui_meta ("role", "output-extent") |
| 68 | + |
| 69 | +property_color (color2, _("Color 2"), "#000000") |
| 70 | + ui_meta ("role", "output-extent") |
| 71 | + |
| 72 | +enum_start (gegl_sinus_gloss) |
| 73 | + enum_value (GEGL_SINUS_BLEND_LINEAR , "linear", N_("Linear")) |
| 74 | + enum_value (GEGL_SINUS_BLEND_BILINEAR , "bilinear", N_("Bilinear")) |
| 75 | + enum_value (GEGL_SINUS_BLEND_SINUSOIDAL, "sinusoidal", N_("Sinusoidal")) |
| 76 | +enum_end (GeglSinusgloss) |
| 77 | + |
| 78 | + |
| 79 | +enum_start (gegl_blend_mode_typeshineg) |
| 80 | + enum_value (GEGL_BLEND_MODE_TYPE_GRAINMERGE, "GrainMerge", |
| 81 | + N_("GrainMerge")) |
| 82 | + enum_value (GEGL_BLEND_MODE_TYPE_HARDLIGHT, "Hardlight", |
| 83 | + N_("Hardlight")) |
| 84 | + enum_value (GEGL_BLEND_MODE_TYPE_ADDITION, "Addition", |
| 85 | + N_("Addition")) |
| 86 | + enum_value (GEGL_BLEND_MODE_TYPE_REPLACE, "Replace", |
| 87 | + N_("Replace")) |
| 88 | +enum_end (GeglBlendModeTypeshineg) |
| 89 | + |
| 90 | +property_enum (blendmode, _("Blend Mode of Shine"), |
| 91 | + GeglBlendModeTypeshineg, gegl_blend_mode_typeshineg, |
| 92 | + GEGL_BLEND_MODE_TYPE_REPLACE) |
| 93 | + |
| 94 | +property_boolean (enable, _("Disable Shine for GEGL Effects"), FALSE) |
| 95 | + description (_("This option is only for GEGL Effects")) |
| 96 | + ui_meta ("role", "output-extent") |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +property_enum (sinusmode, _("Sinus Mode"), |
| 102 | + GeglSinusgloss, gegl_sinus_gloss, |
| 103 | + GEGL_SINUS_BLEND_LINEAR) |
| 104 | + ui_meta ("role", "output-extent") |
| 105 | + |
| 106 | +property_double (blend_power, _("Dark to light intensity"), -0.6) |
| 107 | + description (_("Intensity of the Gloss Shine Effect")) |
| 108 | + value_range (-0.9, 0.0) |
| 109 | + |
| 110 | + |
| 111 | +property_int (width, _("Width"), 1024) |
| 112 | + description (_("Width of the generated buffer")) |
| 113 | + value_range (0, G_MAXINT) |
| 114 | + ui_range (0, 4096) |
| 115 | + ui_meta ("unit", "pixel-distance") |
| 116 | + ui_meta ("axis", "x") |
| 117 | + ui_meta ("role", "output-extent") |
| 118 | + |
| 119 | +property_int (height, _("Height"), 768) |
| 120 | + description (_("Height of the generated buffer")) |
| 121 | + value_range (0, G_MAXINT) |
| 122 | + ui_range (0, 4096) |
| 123 | + ui_meta ("unit", "pixel-distance") |
| 124 | + ui_meta ("axis", "y") |
| 125 | + ui_meta ("role", "output-extent") |
| 126 | + |
| 127 | + |
| 128 | +#else |
| 129 | + |
| 130 | +#define GEGL_OP_META |
| 131 | +#define GEGL_OP_NAME shinytext |
| 132 | +#define GEGL_OP_C_SOURCE shinytext.c |
| 133 | + |
| 134 | +#include "gegl-op.h" |
| 135 | + |
| 136 | + |
| 137 | +typedef struct |
| 138 | +{ |
| 139 | + GeglNode *input; |
| 140 | + GeglNode *opacity; |
| 141 | + GeglNode *nop0; |
| 142 | + GeglNode *nop; |
| 143 | + GeglNode *blend; |
| 144 | + GeglNode *sinus; |
| 145 | + GeglNode *addition; |
| 146 | + GeglNode *hardlight; |
| 147 | + GeglNode *grainmerge; |
| 148 | + GeglNode *replace; |
| 149 | + GeglNode *output; |
| 150 | +}State; |
| 151 | + |
| 152 | +static void |
| 153 | +update_graph (GeglOperation *operation) |
| 154 | +{ |
| 155 | + GeglProperties *o = GEGL_PROPERTIES (operation); |
| 156 | + State *state = o->user_data; |
| 157 | + if (!state) return; |
| 158 | + |
| 159 | + GeglNode *blendchoice = state->replace; /* the default */ |
| 160 | + switch (o->blendmode) { |
| 161 | + case GEGL_BLEND_MODE_TYPE_GRAINMERGE: blendchoice = state->grainmerge; break; |
| 162 | + case GEGL_BLEND_MODE_TYPE_HARDLIGHT: blendchoice = state->hardlight; break; |
| 163 | + case GEGL_BLEND_MODE_TYPE_ADDITION: blendchoice = state->addition; break; |
| 164 | + case GEGL_BLEND_MODE_TYPE_REPLACE: blendchoice = state->replace; break; |
| 165 | +default: blendchoice = state->replace; |
| 166 | + |
| 167 | +} |
| 168 | + if (o->enable) |
| 169 | + { |
| 170 | + gegl_node_link_many (state->input, blendchoice, state->output, NULL); |
| 171 | + gegl_node_link_many (state->sinus, state->opacity, NULL); |
| 172 | + gegl_node_connect_from (blendchoice, "aux", state->opacity, "output"); |
| 173 | + } |
| 174 | +else |
| 175 | + gegl_node_link_many (state->input, state->output, NULL); |
| 176 | +} |
| 177 | + |
| 178 | + |
| 179 | +static void attach (GeglOperation *operation) |
| 180 | +{ |
| 181 | +GeglProperties *o = GEGL_PROPERTIES (operation); |
| 182 | + GeglNode *gegl = operation->node; |
| 183 | + GeglNode *input, *output, *sinus, *replace, *addition, *grainmerge, *blend, *nop0, *nop, *hardlight, *opacity; |
| 184 | + |
| 185 | + |
| 186 | + input = gegl_node_get_input_proxy (gegl, "input"); |
| 187 | + output = gegl_node_get_output_proxy (gegl, "output"); |
| 188 | + |
| 189 | + |
| 190 | + opacity = gegl_node_new_child (gegl, |
| 191 | + "operation", "gegl:opacity", |
| 192 | + NULL); |
| 193 | + |
| 194 | + |
| 195 | + sinus = gegl_node_new_child (gegl, |
| 196 | + "operation", "gegl:sinus", |
| 197 | + NULL); |
| 198 | + |
| 199 | + nop = gegl_node_new_child (gegl, |
| 200 | + "operation", "gegl:nop", |
| 201 | + NULL); |
| 202 | + |
| 203 | + nop0 = gegl_node_new_child (gegl, |
| 204 | + "operation", "gegl:nop", |
| 205 | + NULL); |
| 206 | + |
| 207 | + |
| 208 | + replace = gegl_node_new_child (gegl, |
| 209 | + "operation", "gegl:src-atop", |
| 210 | + NULL); |
| 211 | + |
| 212 | +hardlight = gegl_node_new_child (gegl, |
| 213 | + "operation", "gimp:layer-mode", "layer-mode", 44, "composite-mode", 0, "blend-space", 0, NULL); |
| 214 | + |
| 215 | + |
| 216 | +addition = gegl_node_new_child (gegl, |
| 217 | + "operation", "gimp:layer-mode", "layer-mode", 33, "composite-mode", 0, NULL); |
| 218 | + |
| 219 | +grainmerge = gegl_node_new_child (gegl, |
| 220 | + "operation", "gimp:layer-mode", "layer-mode", 47, "composite-mode", 0, NULL); |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + blend = gegl_node_new_child (gegl, |
| 225 | + "operation", "gegl:plus", |
| 226 | + NULL); |
| 227 | + |
| 228 | + gegl_operation_meta_redirect (operation, "opacity", opacity, "value"); |
| 229 | + gegl_operation_meta_redirect (operation, "seed", sinus, "seed"); |
| 230 | + gegl_operation_meta_redirect (operation, "complexity", sinus, "complexity"); |
| 231 | + gegl_operation_meta_redirect (operation, "x_scale", sinus, "x-scale"); |
| 232 | + gegl_operation_meta_redirect (operation, "y_scale", sinus, "y-scale"); |
| 233 | + gegl_operation_meta_redirect (operation, "color1", sinus, "color1"); |
| 234 | + gegl_operation_meta_redirect (operation, "color2", sinus, "color2"); |
| 235 | + gegl_operation_meta_redirect (operation, "blend_power", sinus, "blend-power"); |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | + /* now save references to the gegl nodes so we can use them |
| 243 | + * later, when update_graph() is called |
| 244 | + */ |
| 245 | + State *state = g_malloc0 (sizeof (State)); |
| 246 | + state->input = input; |
| 247 | + state->opacity = opacity; |
| 248 | + state->addition = addition; |
| 249 | + state->hardlight = hardlight; |
| 250 | + state->grainmerge = grainmerge; |
| 251 | + state->replace = replace; |
| 252 | + state->sinus = sinus; |
| 253 | + state->nop = nop; |
| 254 | + state->nop = nop0; |
| 255 | + state->blend = blend; |
| 256 | + state->output = output; |
| 257 | + |
| 258 | + o->user_data = state; |
| 259 | + |
| 260 | +} |
| 261 | + |
| 262 | + |
| 263 | +static void |
| 264 | +gegl_op_class_init (GeglOpClass *klass) |
| 265 | +{ |
| 266 | + GeglOperationClass *operation_class; |
| 267 | +GeglOperationMetaClass *operation_meta_class = GEGL_OPERATION_META_CLASS (klass); |
| 268 | + operation_class = GEGL_OPERATION_CLASS (klass); |
| 269 | + |
| 270 | + operation_class->attach = attach; |
| 271 | + operation_meta_class->update = update_graph; |
| 272 | + |
| 273 | + gegl_operation_class_set_keys (operation_class, |
| 274 | + "name", "gegl:shinytext", |
| 275 | + "title", _("Shiny Text"), |
| 276 | + "categories", "hidden", |
| 277 | + "reference-hash", "sglosa28a5125700fc254001b2ac", |
| 278 | + "description", _("GEGL renders a shiny effect on text. This won't work on normal images. Only Text! Users are specified to use Gimp/GEGL blend modes and opacity slider with this"), |
| 279 | + NULL); |
| 280 | +} |
| 281 | + |
| 282 | +#endif |
0 commit comments