summaryrefslogtreecommitdiff
path: root/ipl/gprogs/seamcut.icn
blob: f75e6c4c73db506ad088af6bdf2aa18e51f72853 (plain)
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
############################################################################
#
#	File:     seamcut.icn
#
#	Subject:  Program to cut image for seamless tiling
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program takes image file names and does top/bottom separation and
#  reordering, follows by the same for left and right.  The result is an
#  image that tiles seamlessly, although the center part may be a mess.
#
#  The technique is described in Painter 2.0 Companion.
#
#  Files are expected to have the suffix .gif.  The corresponding files
#  are given the suffix _s.gif.
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################
#
#  Links:  basename, wopen
#
############################################################################

link basename
link wopen

procedure main(args)
   local name, base, width, height, half_width, half_height, win1, win2

   every name := !args do {
      base := basename(name, ".gif") | {
         write(&errout, "*** unexpected file extension ", name)
         next
         }
      win1 := WOpen("canvas=hidden", "image=" || name) | {
         write(&errout, "*** cannot open ", name)
         next
         }

      width := WAttrib(win1, "width")
      height := WAttrib(win1, "height")
      half_width := width / 2
      half_height := height / 2

      win2 := WOpen("canvas=hidden", "width=" || width, "height=" || height) |
         stop("*** cannot open target window")

      CopyArea(win1, win2, 0, 0, half_width, height, half_width, 0)
      CopyArea(win1, win2, half_width, 0, half_width, height, 0, 0)
      EraseArea(win1)
      CopyArea(win2, win1, 0, 0, width, half_height, 0, half_height)
      CopyArea(win2, win1, 0, half_height, width, half_height, 0, 0)
      WriteImage(win1, base || "_s.gif")
      WClose(win1)
      WClose(win2)
      }

end