/
seamless_advanced_v1.16.py_0.txt
259 lines (217 loc) · 9.04 KB
/
seamless_advanced_v1.16.py_0.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# Make Seamless Advanced v1.16
# (copyLEFT) 2013 Andrey "Efenstor" Pivovarov. No rights reserved
# Copy freely, modify freely, spread the word and remeber me in your prayers
# Using the "Manual overlap" function:
# 1. Set "Horizontal overlap" to the value you need and "Vertical overlap" to 0
# 2. (optionally) Turn on "Hi-pass pre-filter"
# 3. Click OK
# 4. Edit the overlap to make it seamless. Don't worry about the top and bottom
# edge correspondence - this corner will be covered by the vertical overlap.
# 5. Merge down
# 6. Start the plugin again
# 7. Now set "Vertical overlap" to the value you need and "Horizontal overlap"
# to 0
# 8. (optionally) Turn off "Hi-pass pre-filter"
# 9. Click OK
# 10. Edit the overlap to make it seamless. This time you MUST care about left
# and right edge correspondence; in the most cases it has no need be very
# precise.
# 11. Merge down
# New in the version 1.16:
# * Fixed crash if the hi-pass was on and any of the overlap values was 0
# (which is vital for the manual overlap mode)
# New in the version 1.15:
# * Greatly improved hi-pass filter (now on by default)
# * Now overlap values are checked against the image dimensions, if larger the
# maximum recommended value is displayed
# New in the version 1.11:
# * Manual overlap mode with both horizontal and vertical overlaps specified
# simultaneously is now explicitly disallowed (a warning message will be
# given)
# New in the version 1.1:
# * Hi-pass pre-filter added (thanks to RPG for the idea)
# * Another fuzziness anti-aliasing method (now only a toggle)
#!/usr/bin/env python
import math
from gimpfu import *
def msa_deinit(img):
# Deinitialize the plugin
pdb.gimp_undo_push_group_end(img)
pdb.gimp_progress_end()
pdb.gimp_displays_flush()
def msa_proc(img, ovr, ovr_mask, off, gcontr, gfuzzy, gradtype):
# Shift and crop
ovr.translate(img.width-off, 0)
pdb.gimp_image_crop(img, img.width-off, img.height, off, 0)
# Gradient
if gradtype==0:
# Simple gradient
pdb.gimp_context_set_default_colors()
pdb.gimp_edit_blend(ovr_mask, 0, 0, 0, 100, .5, 0, FALSE, FALSE, 5, 0, TRUE, 0, 0, off, 0)
else:
# Intelligent gradient
pdb.gimp_context_set_default_colors()
pdb.gimp_edit_blend(ovr_mask, 2, 0, 0, 100, .5, 0, FALSE, FALSE, 5, 0, TRUE, 0, 0, off/2, 0)
pdb.gimp_context_swap_colors()
pdb.gimp_edit_blend(ovr_mask, 2, 0, 0, 100, .5, 0, FALSE, FALSE, 5, 0, TRUE, off, 0, (off/2)+1, 0)
# Gradient contrast
if gcontr>0:
gc = int((gcontr/100)*127+.5)
pdb.gimp_brightness_contrast(ovr_mask, 0, gc)
# Gradient fuzziness
if gfuzzy>0:
pdb.gimp_layer_resize_to_image_size(ovr)
pdb.plug_in_spread(img, ovr_mask, gfuzzy, gfuzzy)
pdb.plug_in_blur(img, ovr_mask)
def make_seamless_advanced(img, layer, ho, vo, gcontr, gfuzzy, gradtype, hipass, hpblur, manual, flatten):
# Check the initial requirements
if ho>img.width/2 or vo>img.height/2:
# Overlap should be smaller than half the image dimension
if ho>img.width/2:
pdb.gimp_message("Horizontal overlap should be no larger than "+str(img.width/2)+" px for this image. Please decrease it.")
if vo>img.height/2:
pdb.gimp_message("Vertical overlap should be no larger than "+str(img.height/2)+" px for this image. Please decrease it.")
return
if manual and ho>0 and vo>0:
# Both horizontal and vertical are not allowed in the manual mode
pdb.gimp_message("When using the manual overlap mode please set one of the overlap values (either vertical or horizontal) to zero.\n\nFor detailed instructions on how to use the manual mode visit http://registry.gimp.org/node/28112 or open the plugin file (seamless_advanced_v1.16.py) in a text editor.")
return
# Initialization
gimp.progress_init("Preparing...")
pdb.gimp_undo_push_group_start(img)
# Hi-pass pre-filter
if hipass>0:
# Add the subtraction layer
hps = layer.copy()
hps.name = "Subtraction"
img.active_layer = layer # Mind its correct position
img.add_layer(hps, -1)
hps.mode = 20 # GRAIN-EXTRACT-MODE
# Process it
pdb.gimp_desaturate_full(hps, 1)
if hpblur==0:
if ho==0 or vo==0:
if ho>0: gaua = ho
elif vo>0: gaua = vo
elif img.width<img.height: gaua = img.width*.25
else: gaua = img.height*.25
elif ho<vo: gaua = ho
else: gaua = vo
elif img.width<img.height: gaua = img.width*(hpblur/100)
else: gaua = img.height*(hpblur/100)
pdb.plug_in_gauss(img, hps, gaua, gaua, 1)
# Add a layer to merge down on
bkcp = layer.copy()
bkcp.name = "Background copy"
img.active_layer = layer # Mind its correct position
img.add_layer(bkcp, -1)
# Merge down
hp1 = pdb.gimp_image_merge_down(img, hps, 1)
hp1.name = "Hi-pass stage 1"
# Add the equalization layer
hpe = layer.copy()
hpe.name = "Equalization"
img.active_layer = hp1 # Mind its correct position
img.add_layer(hpe, -1)
hpe.mode = 5 # OVERLAY-MODE
# Process it
pdb.plug_in_pixelize2(img, hpe, img.width, img.height)
pdb.gimp_desaturate_full(hpe, 0)
# Merge down and strip off alpha
layer = pdb.gimp_image_merge_down(img, hpe, 1)
layer.name = "Hi-pass"
pdb.gimp_layer_flatten(layer)
# Manual
if manual:
if ho>0:
hor = layer.copy()
hor.name = "Horizontal overlap"
img.add_layer(hor, -1)
hor_mask = hor.create_mask(0)
hor.add_mask(hor_mask)
hor.translate(img.width-ho, 0)
pdb.gimp_image_crop(img, img.width-ho, img.height, ho, 0)
if vo>0:
ver = layer.copy()
ver.name = "Vertical overlap"
img.add_layer(ver, -1)
ver_mask = ver.create_mask(0)
ver.add_mask(ver_mask)
ver.translate(0, img.height-vo)
pdb.gimp_image_crop(img, img.width, img.height-vo, 0, vo)
msa_deinit(img)
return
if ho>0:
# Make the horizonal overlap layer
hor = layer.copy()
hor.name = "Horizontal overlap"
img.active_layer = layer # Mind its correct position
img.add_layer(hor, -1)
if gradtype==1: hor_mask = hor.create_mask(5)
else: hor_mask = hor.create_mask(0)
hor.add_mask(hor_mask)
# Do horizontal tiling (actually it always will be horizontal :)
msa_proc(img, hor, hor_mask, ho, gcontr, gfuzzy, gradtype)
if vo>0:
# Copy the background
bkcp = layer.copy()
bkcp.name = "Background copy"
img.active_layer = hor # Mind its correct position
img.add_layer(bkcp, -1)
# Copy the horizontal overlap layer
horcp = hor.copy()
horcp.name = "Horizontal overlap copy"
img.active_layer = bkcp # Mind its correct position
img.add_layer(horcp, -1)
# Merge down, strip alpha and add the mask
ver = pdb.gimp_image_merge_down(img, horcp, 0)
ver.name = "Vertical overlap"
pdb.gimp_layer_flatten(ver)
if gradtype==1: ver_mask = ver.create_mask(5)
else: ver_mask = ver.create_mask(0)
ver.add_mask(ver_mask)
# Now we have the vertical overlap layer with the corner already made
elif vo>0:
# Make the vertical overlap layer
ver = layer.copy()
ver.name = "Vertical overlap"
img.active_layer = layer # Mind its correct position
img.add_layer(ver, -1)
if gradtype==1: ver_mask = ver.create_mask(5)
else: ver_mask = ver.create_mask(0)
ver.add_mask(ver_mask)
else:
# Nothing to do
msa_deinit(img)
return
if vo>0:
# Rotate and do the vertical tiling
pdb.gimp_image_rotate(img, 2)
msa_proc(img, ver, ver_mask, vo, gcontr, gfuzzy, gradtype)
pdb.gimp_image_rotate(img, 0)
# Deinitialize
if flatten: img.flatten()
msa_deinit(img)
register(
"make_seamless_advanced",
"Makes seamless textures with some advanced options",
"",
"Efenstor",
"(copyLEFT) Andrey \"Efenstor\" Pivovarov",
"2013",
"<Image>/Filters/Map/Make Seamless Advanced...",
"RGB*, GRAY*",
[
(PF_INT, "ho", "Horizontal overlap (px)", 100),
(PF_INT, "vo", "Vertical overlap (px)", 100),
(PF_SLIDER, "gcontr", "Gradient contrast", 0, (0, 100, 1)),
(PF_INT, "gfuzzy", "Gradient fuzziness (px)", 0),
(PF_RADIO, "gradtype", "Gradient type", 1, (("Simple", 0), ("Intelligent", 1))),
(PF_TOGGLE, "hipass", "Hi-pass pre-filter", 1),
(PF_SLIDER, "hpblur", "Hi-pass smoothness\n(0 = auto)", 0, (0, 100, 1)),
(PF_TOGGLE, "manual", "Manual overlap (only shift and crop)", 0),
(PF_TOGGLE, "flatten", "Flatten", 1)
],
[],
make_seamless_advanced)
main()