forked from JohnTasto/GIMP-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-seamless-by-mirroring.scm
117 lines (100 loc) · 4.25 KB
/
make-seamless-by-mirroring.scm
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
; make-seamless-by-mirroring.scm
; version 1.0
;
; This is Script-Fu program written for GIMP 2.8.
;
; It creates a tileable image in perhaps the simplest way possible: by mirroring
; the image in both the x and y direction, leaving an image that is twice the
; original width and height.
;
; Preview X tiles:
; Preview Y tiles:
; If either (or both) of these are greater than '1', it will create a preview
; tiled image. It will also create an additional undo point to easily go back
; to the untiled version without re-running the script.
;
;
; Copyright 2015 John Tasto
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
(define (script-fu-make-seamless-by-mirroring image
layerBase
tilesX
tilesY)
(let* (
(layerBasePosition (car (gimp-image-get-item-position image layerBase)))
(width (car (gimp-drawable-width layerBase)))
(height (car (gimp-drawable-height layerBase)))
(layerOriginal (car (gimp-layer-new-from-drawable layerBase image)))
(layerFloating 0)
(offsetX 0)
(offsetY 0)
)
(set! offsetX (/ width 2))
(set! offsetY (/ height 2))
(gimp-context-push)
(gimp-context-set-defaults)
(gimp-image-undo-group-start image)
(gimp-image-insert-layer image layerOriginal 0 layerBasePosition)
(gimp-image-resize image (* width 2) (* height 2) 0 0)
(gimp-layer-resize layerBase (* width 2) (* height 2) 0 0)
(gimp-context-set-antialias FALSE)
(gimp-context-set-feather FALSE)
(gimp-selection-none image)
(gimp-edit-copy layerOriginal)
(set! layerFloating (car (gimp-edit-paste layerBase FALSE)))
(gimp-item-transform-flip-simple layerFloating ORIENTATION-HORIZONTAL TRUE 0)
(gimp-layer-translate layerFloating (ceiling (+ 0 offsetX))
(ceiling (- 0 offsetY)))
(gimp-selection-none image)
(gimp-edit-copy layerOriginal)
(set! layerFloating (car (gimp-edit-paste layerBase FALSE)))
(gimp-item-transform-flip-simple layerFloating ORIENTATION-VERTICAL TRUE 0)
(gimp-layer-translate layerFloating (ceiling (- 0 offsetX))
(ceiling (+ 0 offsetY)))
(gimp-selection-none image)
(gimp-edit-copy layerOriginal)
(set! layerFloating (car (gimp-edit-paste layerBase FALSE)))
(gimp-item-transform-flip-simple layerFloating ORIENTATION-HORIZONTAL TRUE 0)
(gimp-item-transform-flip-simple layerFloating ORIENTATION-VERTICAL TRUE 0)
(gimp-layer-translate layerFloating (ceiling (+ 0 offsetX))
(ceiling (+ 0 offsetY)))
(gimp-floating-sel-anchor layerFloating)
(gimp-selection-none image)
(gimp-image-remove-layer image layerOriginal)
(if (or (not (= tilesX 1)) (not (= tilesY 1)))
(begin
(gimp-image-undo-group-end image)
(gimp-image-undo-group-start image)
(script-fu-tile-random-rotation image layerBase tilesX tilesY FALSE FALSE)
)
)
(gimp-image-undo-group-end image)
(gimp-displays-flush)
(gimp-context-pop)
)
)
(script-fu-register "script-fu-make-seamless-by-mirroring"
_"Make seamless by _mirroring..."
_"Make image seamless by mirroring it horizontally and vertically"
"John Tasto <[email protected]>"
"John Tasto"
"2015/09/03"
"RGB* GRAY* INDEXED*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT _"Preview X tiles" '(1 1 256 1 1 0 SF-SPINNER)
SF-ADJUSTMENT _"Preview Y tiles" '(1 1 256 1 1 0 SF-SPINNER)
)
(script-fu-menu-register "script-fu-make-seamless-by-mirroring"
"<Image>/Filters/Texture")