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