Giant blob of minor changes
[dotfiles/.git] / .config / GIMP / 2.10 / plug-ins / plugin-resynth-sharpen.py
1 #!/usr/bin/env python
2
3 '''
4 Gimp plugin "Sharpen by resynthesis"
5 Requires resynthesizer plug_in (v2).
6
7 Author:
8 lloyd konneker (bootch at nc.rr.com)
9 Based on smart_enlarge.scm 2000 by Paul Harrison.
10
11 Version:
12 1.0 lloyd konneker lkk 2010 Initial version in python.
13
14
15 License:
16
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.
21
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.
26
27 The GNU Public License is available at
28 http://www.gnu.org/copyleft/gpl.html
29
30 '''
31
32 from gimpfu import *
33
34 gettext.install("resynthesizer", gimp.locale_directory, unicode=True)
35
36 def plugin_main(image, drawable, scale_factor):
37   '''
38   Algorithm:
39   
40   Resynthesize with:
41     corpus = smaller image
42     in map = smaller image but scaled up and down to blur
43     out map = original image
44   
45   TODO undo
46   
47   original did not accept an alpha channel
48   '''
49
50   
51   temp_image1 = pdb.gimp_image_duplicate(image)  # duplicate for in map
52   if not temp_image1:
53     raise RuntimeError, "Failed duplicate image"
54   temp_image2 = pdb.gimp_image_duplicate(image)  # duplicate for corpus
55   if not temp_image2:
56     raise RuntimeError, "Failed duplicate image"
57   temp_layer1 = pdb.gimp_image_get_active_layer(temp_image1)
58   if not temp_layer1:
59     raise RuntimeError, "Failed get active layer"
60   temp_layer2 = pdb.gimp_image_get_active_layer(temp_image2)
61   if not temp_layer2:
62     raise RuntimeError, "Failed get active layer"
63
64   
65   width = pdb.gimp_drawable_width(drawable)
66   height = pdb.gimp_drawable_height(drawable)
67   
68   
69   # scale input image down, for corpus map
70   pdb.gimp_image_scale(temp_image2, width/scale_factor, height/scale_factor)
71     
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)
76
77   # Resynthesize to restore details.
78   # Note there should not be a selection. TODO
79   pdb.plug_in_resynthesizer(
80       image,
81       drawable,
82       0, 0, 0,
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
86       1.0, 0.117, 8, 500) 
87
88   pdb.gimp_image_delete(temp_image1)
89   pdb.gimp_image_delete(temp_image2)
90
91
92 register(
93   "python_fu_sharpen_resynthesized",
94   N_("Sharpen image by synthesis."),
95   "Requires separate resynthesizer plugin.",
96   "Lloyd Konneker",
97   "Copyright 2000 Paul Harrison, 2010 Lloyd Konneker",
98   "2010",
99   N_("Sharpen by synthesis..."),
100   "RGB*, GRAY*",
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)),
104   ],
105   [],
106   plugin_main,
107   menu="<Image>/Filters/Enhance",
108   domain=("resynthesizer", gimp.locale_directory)
109   )
110
111 main()
112
113