4 Gimp plugin "Enlarge and resynthesize"
8 Based on smart_enlarge.scm 2000 by Paul Harrison.
11 1.0 lloyd konneker lkk 2010 Initial version in python.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 The GNU Public License is available at
26 http://www.gnu.org/copyleft/gpl.html
31 gettext.install("resynthesizer", gimp.locale_directory, unicode=True)
33 def plugin_main(image, drawable, scale_factor):
39 corpus = original size image
40 in map = original size image but scaled up and down to blur
41 out map = scaled up image
43 This restores the detail that scaling up looses.
44 It maintains the aspect ratio of all image features.
46 Unlike the original smart-enlarge.scm, this alters the original image.
48 original did not accept an alpha channel
52 temp_image1 = pdb.gimp_image_duplicate(image) # duplicate for in map
54 raise RuntimeError, "Failed duplicate image"
55 temp_image2 = pdb.gimp_image_duplicate(image) # duplicate for corpus
57 raise RuntimeError, "Failed duplicate image"
58 temp_layer1 = pdb.gimp_image_get_active_layer(temp_image1)
60 raise RuntimeError, "Failed get active layer"
61 temp_layer2 = pdb.gimp_image_get_active_layer(temp_image2)
63 raise RuntimeError, "Failed get active layer"
65 # scale input map down and back, to blur
66 width = pdb.gimp_drawable_width(drawable)
67 height = pdb.gimp_drawable_height(drawable)
68 pdb.gimp_image_scale(temp_image1, width/scale_factor, height/scale_factor)
69 pdb.gimp_image_scale(temp_image1, width, height)
72 pdb.gimp_image_scale(image, width * scale_factor, height*scale_factor)
74 # Resynthesize to restore details.
75 # Note there should not be a selection. TODO
76 pdb.plug_in_resynthesizer(
80 temp_layer2.ID, # corpus
81 temp_layer1.ID, # input map
82 drawable.ID, # output map is scaled up original itself
85 pdb.gimp_image_delete(temp_image1)
86 pdb.gimp_image_delete(temp_image2)
89 if __name__ == "__main__" :
91 "python_fu_enlarge_resynthesized",
92 N_("Enlarge image and synthesize to sharpen."),
93 "Requires separate resynthesizer plugin",
95 "Copyright 2000 Paul Harrison, 2010 Lloyd Konneker",
97 N_("Enlarge & sharpen..."),
100 (PF_IMAGE, "image", "Input image", None),
101 (PF_DRAWABLE, "drawable", "Input drawable", None),
102 (PF_ADJUSTMENT, "scale_factor", _("Scale by:"), 2, (1, 32, 0.1))
106 menu="<Image>/Filters/Enhance",
107 domain=("resynthesizer", gimp.locale_directory)