4 Gimp plugin "Heal transparency"
6 Copyright 2010 lloyd konneker (bootch at nc.rr.com)
9 1.0 lloyd konneker lkk 2010 Initial version in python.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 The GNU Public License is available at
24 http://www.gnu.org/copyleft/gpl.html
30 gettext.install("resynthesizer", gimp.locale_directory, unicode=True)
32 def heal_transparency(timg, tdrawable, samplingRadiusParam=50, orderParam=2):
34 # precondition should be enforced by Gimp according to image modes allowed.
35 if not pdb.gimp_drawable_has_alpha(tdrawable):
36 pdb.gimp_message("The active layer has no alpha channel to heal.")
39 pdb.gimp_image_undo_group_start(timg)
41 # save selection for later restoration.
42 # Saving selection channel makes it active, so we must save and restore the active layer
43 org_selection = pdb.gimp_selection_save(timg)
44 pdb.gimp_image_set_active_layer(timg, tdrawable)
47 pdb.gimp_image_select_item(timg, CHANNEL_OP_REPLACE, tdrawable)
48 # Want the transparent, not the opaque.
49 pdb.gimp_selection_invert(timg)
50 # Since transparency was probably anti-aliased (dithered with partial transpancy),
51 # grow the selection to get past the dithering.
52 pdb.gimp_selection_grow(timg, 1)
53 # Remove the alpha from this layer. IE compose with current background color (often white.)
54 # Resynthesizer won't heal transparent.
55 pdb.gimp_layer_flatten(tdrawable)
57 # Call heal selection (not the resynthesizer), which will create a proper corpus.
58 # 0 = sample from all around
59 pdb.python_fu_heal_selection(timg, tdrawable, samplingRadiusParam, 0, orderParam, run_mode=RUN_NONINTERACTIVE)
61 # Restore image to initial conditions of user, except for later cleanup.
64 pdb.gimp_image_select_item(timg, CHANNEL_OP_REPLACE, org_selection)
66 # Clean up (comment out to debug)
67 pdb.gimp_image_undo_group_end(timg)
71 "python_fu_heal_transparency",
72 N_("Removes alpha channel by synthesis. Fill outward for edges, inward for holes."),
73 "Requires separate resynthesizer plugin.",
75 "Copyright 2010 Lloyd Konneker",
77 N_("Heal transparency..."),
78 "RGBA, GRAYA", # !!! Requires an alpha channel to heal
80 (PF_IMAGE, "image", "Input image", None),
81 (PF_DRAWABLE, "drawable", "Input drawable", None),
82 (PF_INT, "samplingRadiusParam", _("Context sampling width (pixels):"), 50),
83 (PF_OPTION, "orderParam", _("Filling order:"), 2, [_("Random"),
84 _("Inwards towards center"), _("Outwards from center") ])
88 menu="<Image>/Filters/Enhance",
89 domain=("resynthesizer", gimp.locale_directory)