|
| 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 | + * 2022 Beaver (GEGL Bevel) |
| 18 | + */ |
| 19 | + |
| 20 | +/*GEGL Bevel is a stand alone plugin but it is also part of GEGL Effects. The stand alone version does more then the GEGL Effects implementation of it. */ |
| 21 | + |
| 22 | +#include "config.h" |
| 23 | +#include <glib/gi18n-lib.h> |
| 24 | + |
| 25 | +#ifdef GEGL_PROPERTIES |
| 26 | + |
| 27 | +property_boolean (effectsswitchbevel, _("Enable Bevel (FOR GEGL EFFECTS ONLY)"), TRUE) |
| 28 | + description (_("This switch exist for GEGL Effects testing. You won't find it in stand alone bevel. Or even in current *June 7th 2023 GEGL Effects.'")) |
| 29 | + ui_meta ("role", "output-extent") |
| 30 | + |
| 31 | +property_boolean (embossmode, _("Emboss Mode (use Gimp's layer Grain Merge blend mode)"), FALSE) |
| 32 | + description (_("Make an embossed bevel'")) |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +property_double (radius1, _("Radius Normal Bevel"), 7.0) |
| 37 | + value_range (0.5, 40.0) |
| 38 | + ui_range (1.0, 9.0) |
| 39 | + ui_gamma (1.5) |
| 40 | + |
| 41 | +property_int (radius2, _("Radius Sharp Bevel"), 0) |
| 42 | + description(_("Box Blur -0 means disabled by default")) |
| 43 | + value_range (0, 10.0) |
| 44 | + ui_range (0, 9.0) |
| 45 | + ui_gamma (1.5) |
| 46 | + |
| 47 | + |
| 48 | +property_double (bevel1, _("Depth Angle"), 90.0) |
| 49 | + description (_("Elevation angle (degrees)")) |
| 50 | + value_range (0, 180) |
| 51 | + ui_meta ("unit", "degree") |
| 52 | + |
| 53 | +property_int (bevel2, _("Depth"), 40) |
| 54 | + description (_("Filter width")) |
| 55 | + value_range (1, 100) |
| 56 | + |
| 57 | + |
| 58 | +property_double (th, _("Bevel's coverage threshold. Lower covers more."), 0.100) |
| 59 | + value_range (0.0, 1.0) |
| 60 | + ui_range (0.0, 0.5) |
| 61 | + ui_meta ("sensitive", "! embossmode") |
| 62 | + |
| 63 | +property_double (azimuth, _("Rotate Lighting"), 40.0) |
| 64 | + description (_("Light angle (degrees)")) |
| 65 | + value_range (0, 350) |
| 66 | + ui_meta ("unit", "degree") |
| 67 | + ui_meta ("direction", "ccw") |
| 68 | + |
| 69 | + |
| 70 | +property_double (slideupblack, _("Slide up if Bevel is very dark or black. "), 0.00) |
| 71 | + description (_("GEGL Bevel works on black Bevels when using blend modes like Grain Merge and Hardlight. All you have to do is select those blend modes for black text and then move this slider up.")) |
| 72 | + value_range (0.00, 0.999) |
| 73 | + ui_steps (0.01, 0.50) |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +#else |
| 78 | + |
| 79 | +#define GEGL_OP_META |
| 80 | +#define GEGL_OP_NAME bevel |
| 81 | +#define GEGL_OP_C_SOURCE bevel.c |
| 82 | + |
| 83 | +#include "gegl-op.h" |
| 84 | + |
| 85 | + |
| 86 | +typedef struct |
| 87 | +{ |
| 88 | + GeglNode *input; |
| 89 | + GeglNode *blur; |
| 90 | + GeglNode *boxblur; |
| 91 | + GeglNode *emb; |
| 92 | + GeglNode *th; |
| 93 | + GeglNode *whitecolor; |
| 94 | + GeglNode *normallayer; |
| 95 | + GeglNode *slideupblack; |
| 96 | + GeglNode *fix; |
| 97 | + GeglNode *output; |
| 98 | +} State; |
| 99 | + |
| 100 | + |
| 101 | +static void attach (GeglOperation *operation) |
| 102 | +{ |
| 103 | + GeglNode *gegl = operation->node; |
| 104 | + GeglProperties *o = GEGL_PROPERTIES (operation); |
| 105 | + GeglNode *input, *output, *boxblur, *blur, *emb, *th, *fix, *whitecolor, *normallayer, *slideupblack; |
| 106 | + GeglColor *white_color = gegl_color_new ("#ffffff"); |
| 107 | + |
| 108 | + input = gegl_node_get_input_proxy (gegl, "input"); |
| 109 | + output = gegl_node_get_output_proxy (gegl, "output"); |
| 110 | + |
| 111 | + blur = gegl_node_new_child (gegl, |
| 112 | + "operation", "gegl:gaussian-blur", |
| 113 | + NULL); |
| 114 | + |
| 115 | + boxblur = gegl_node_new_child (gegl, |
| 116 | + "operation", "gegl:box-blur", |
| 117 | + NULL); |
| 118 | + |
| 119 | + emb = gegl_node_new_child (gegl, |
| 120 | + "operation", "gegl:emboss", |
| 121 | + NULL); |
| 122 | + |
| 123 | + th = gegl_node_new_child (gegl, |
| 124 | + "operation", "gimp:threshold-alpha", |
| 125 | + NULL); |
| 126 | + |
| 127 | + |
| 128 | + whitecolor = gegl_node_new_child (gegl, |
| 129 | + "operation", "gegl:color-overlay", |
| 130 | + "value", white_color, NULL); |
| 131 | + |
| 132 | + |
| 133 | +normallayer = gegl_node_new_child (gegl, |
| 134 | + "operation", "gimp:layer-mode", "layer-mode", 28, "composite-mode", 2, NULL); |
| 135 | + |
| 136 | + |
| 137 | + slideupblack = gegl_node_new_child (gegl, |
| 138 | + "operation", "gegl:opacity", |
| 139 | + NULL); |
| 140 | + |
| 141 | + fix = gegl_node_new_child (gegl, |
| 142 | + "operation", "gegl:crop", |
| 143 | + NULL); |
| 144 | + |
| 145 | + gegl_operation_meta_redirect (operation, "radius1", blur, "std-dev-x"); |
| 146 | + gegl_operation_meta_redirect (operation, "radius1", blur, "std-dev-y"); |
| 147 | + gegl_operation_meta_redirect (operation, "bevel1", emb, "elevation"); |
| 148 | + gegl_operation_meta_redirect (operation, "bevel2", emb, "depth"); |
| 149 | + gegl_operation_meta_redirect (operation, "azimuth", emb, "azimuth"); |
| 150 | + gegl_operation_meta_redirect (operation, "radius2", boxblur, "radius"); |
| 151 | + gegl_operation_meta_redirect (operation, "th", th, "value"); |
| 152 | + gegl_operation_meta_redirect (operation, "slideupblack", slideupblack, "value"); |
| 153 | + |
| 154 | + |
| 155 | + /* Now save points to the various gegl nodes so we can rewire them in |
| 156 | + * update_graph() later |
| 157 | + */ |
| 158 | + State *state = g_malloc0 (sizeof (State)); |
| 159 | + state->input = input; |
| 160 | + state->blur = blur; |
| 161 | + state->boxblur = boxblur; |
| 162 | + state->emb = emb; |
| 163 | + state->th = th; |
| 164 | + state->whitecolor = whitecolor; |
| 165 | + state->normallayer = normallayer; |
| 166 | + state->slideupblack = slideupblack; |
| 167 | + state->fix = fix; |
| 168 | + state->output = output; |
| 169 | + o->user_data = state; |
| 170 | +} |
| 171 | + |
| 172 | +static void |
| 173 | +update_graph (GeglOperation *operation) |
| 174 | +{ |
| 175 | + GeglProperties *o = GEGL_PROPERTIES (operation); |
| 176 | + State *state = o->user_data; |
| 177 | + if (!state) return; |
| 178 | + |
| 179 | + if (o->effectsswitchbevel) |
| 180 | + if (o->embossmode) |
| 181 | + { |
| 182 | + gegl_node_link_many (state->input, state->normallayer, state->blur, state->boxblur, state->emb, state->fix, state->output, NULL); |
| 183 | + gegl_node_link_many (state->input, state->whitecolor, state->slideupblack, NULL); |
| 184 | + gegl_node_connect_from (state->normallayer, "aux", state->slideupblack, "output"); |
| 185 | + } |
| 186 | +else |
| 187 | + { |
| 188 | + gegl_node_link_many (state->input, state->normallayer, state->blur, state->boxblur, state->emb, state->th, state->fix, state->output, NULL); |
| 189 | + gegl_node_link_many (state->input, state->whitecolor, state->slideupblack, NULL); |
| 190 | + gegl_node_connect_from (state->normallayer, "aux", state->slideupblack, "output"); |
| 191 | + } |
| 192 | +else |
| 193 | + { |
| 194 | + gegl_node_link_many (state->input, state->output, NULL); |
| 195 | + } |
| 196 | +} |
| 197 | + |
| 198 | + |
| 199 | +static void |
| 200 | +gegl_op_class_init (GeglOpClass *klass) |
| 201 | +{ |
| 202 | + GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass); |
| 203 | + GeglOperationMetaClass *operation_meta_class = GEGL_OPERATION_META_CLASS (klass); |
| 204 | + |
| 205 | + operation_class->attach = attach; |
| 206 | + operation_meta_class->update = update_graph; |
| 207 | + |
| 208 | + gegl_operation_class_set_keys (operation_class, |
| 209 | + "name", "gegl:bevel", |
| 210 | + "title", _("Bevel"), |
| 211 | + "categories", "Aristic", |
| 212 | + "reference-hash", "45ed5656a28a512570f0f25sb2ac", |
| 213 | + "description", _("You are expected to use GEGL or Gimp blend modes with this plugin. Works best with blend modes multiply and grain merge. Emboss mode requires non-GEGL Gimp blend modes" |
| 214 | + ""), |
| 215 | + NULL); |
| 216 | +} |
| 217 | + |
| 218 | +#endif |
0 commit comments