4 Gimp plugin "Sharpen by resynthesis"
5 Requires resynthesizer plug_in (v2).
8 lloyd konneker (bootch at nc.rr.com)
9 Based on smart_enlarge.scm 2000 by Paul Harrison.
12 1.0 lloyd konneker lkk 2010 Initial version in python.
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 The GNU Public License is available at
28 http://www.gnu.org/copyleft/gpl.html
34 gettext.install("resynthesizer", gimp.locale_directory, unicode=True)
36 def plugin_main(image, drawable, scale_factor):
41 corpus = smaller image
42 in map = smaller image but scaled up and down to blur
43 out map = original image
47 original did not accept an alpha channel
51 temp_image1 = pdb.gimp_image_duplicate(image) # duplicate for in map
53 raise RuntimeError, "Failed duplicate image"
54 temp_image2 = pdb.gimp_image_duplicate(image) # duplicate for corpus
56 raise RuntimeError, "Failed duplicate image"
57 temp_layer1 = pdb.gimp_image_get_active_layer(temp_image1)
59 raise RuntimeError, "Failed get active layer"
60 temp_layer2 = pdb.gimp_image_get_active_layer(temp_image2)
62 raise RuntimeError, "Failed get active layer"
65 width = pdb.gimp_drawable_width(drawable)
66 height = pdb.gimp_drawable_height(drawable)
69 # scale input image down, for corpus map
70 pdb.gimp_image_scale(temp_image2, width/scale_factor, height/scale_factor)
72 # scale input image way down, then back up to, to blur, for corpus
73 # Final size is same size as corpus map.
74 pdb.gimp_image_scale(temp_image1, width / (2 * scale_factor), height / (2 * scale_factor) )
75 pdb.gimp_image_scale(temp_image1, width/scale_factor, height/scale_factor)
77 # Resynthesize to restore details.
78 # Note there should not be a selection. TODO
79 pdb.plug_in_resynthesizer(
83 temp_layer2.ID, # corpus is smaller original
84 temp_layer1.ID, # input map is blurred smaller original
85 drawable.ID, # output map is original itself
88 pdb.gimp_image_delete(temp_image1)
89 pdb.gimp_image_delete(temp_image2)
93 "python_fu_sharpen_resynthesized",
94 N_("Sharpen image by synthesis."),
95 "Requires separate resynthesizer plugin.",
97 "Copyright 2000 Paul Harrison, 2010 Lloyd Konneker",
99 N_("Sharpen by synthesis..."),
101 [ (PF_IMAGE, "image", "Input image", None),
102 (PF_DRAWABLE, "drawable", "Input drawable", None),
103 (PF_ADJUSTMENT, "sharpen_factor", _("Sharpening:"), 2, (1, 32, 0.1)),
107 menu="<Image>/Filters/Enhance",
108 domain=("resynthesizer", gimp.locale_directory)