4 Gimp plugin "Fill with pattern seamless..."
5 Front end to the resynthesizer plugin to make a seamless fill.
7 Copyright 2011 lloyd konneker
13 During development, remember to make it executable!!!
14 And to remove older versions, both .scm and .py that might hide it.
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 The GNU Public License is available at
29 http://www.gnu.org/copyleft/gpl.html
35 gettext.install("resynthesizer", gimp.locale_directory, unicode=True);
39 def layer_from_pattern(image, pattern):
41 Create a new image and layer having the same size as a pattern.
43 new_basetype = pdb.gimp_image_base_type(image) # same as source
44 new_layertype = pdb.gimp_drawable_type(pdb.gimp_image_get_active_layer(image))
45 pattern_width, pattern_height, bpp = pdb.gimp_pattern_get_info(pattern)
46 new_image = pdb.gimp_image_new(pattern_width, pattern_height, new_basetype)
47 # !!! Note that gimp_layer_new wants a layer type, not an image basetype
48 new_drawable = pdb.gimp_layer_new(new_image, pattern_width, pattern_height,
49 new_layertype, "Texture", 100, NORMAL_MODE)
50 pdb.gimp_image_add_layer(new_image, new_drawable, 0)
51 return new_image, new_drawable
54 def guts(image, drawable, pattern):
55 ''' Crux of algorithm '''
57 # Make drawble from pattern
58 pattern_image, pattern_layer = layer_from_pattern(image, pattern)
60 # Fill it with pattern
61 # NOT pass pattern_layer.ID !!!
62 pdb.gimp_drawable_fill(pattern_layer, PATTERN_FILL)
65 gimp.Display(pattern_image)
68 # Resynthesize the selection from the pattern without using context
69 # 0,0,0: Not use_border (context), not tile horiz, not tile vert
70 # -1, -1, 0: No maps and no map weight
71 # DO pass pattern_layer.ID !!!
72 # Resynthesizer is an engine, never interactive
73 pdb.plug_in_resynthesizer(image, drawable, 0, 0, 0, pattern_layer.ID, -1, -1, 0, 0.05, 8, 300)
77 # Delete image that is displayed throws RuntimeError
78 pdb.gimp_image_delete(pattern_image)
81 def plugin_main(image, drawable, pattern):
83 Main: the usual user-friendly precondition checking, postcondition cleanup.
86 # User_friendly: if no selection, use entire image.
87 # But the resynthesizer does that for us.
89 # Save/restore the context since we change the pattern
90 pdb.gimp_context_push()
91 pdb.gimp_context_set_pattern(pattern)
92 guts(image, drawable, pattern)
93 pdb.gimp_context_pop()
99 "python_fu_fill_pattern_resynth",
100 N_("Seamlessly fill with a pattern using synthesis."),
101 "Requires separate resynthesizer plugin.",
103 "Copyright 2011 Lloyd Konneker",
105 N_("_Fill with pattern seamless..."),
108 (PF_IMAGE, "image", "Input image", None),
109 (PF_DRAWABLE, "drawable", "Input drawable", None),
110 (PF_PATTERN, "pattern", _("Pattern:"), 'Maple Leaves')
115 domain=("resynthesizer", gimp.locale_directory)