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
|
############################################################################
#
# File: gif2geom.icn
#
# Subject: Program to analyze weaving patterns
#
# Author: Ralph E. Griswold
#
# Date: June 15, 1999
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program does a row analysis of a GIF image, labels each unique row,
# and then outputs a string of row labels for the image and the value of
# each as a string of palette characters.
#
# The following option is supported:
#
# -p s palette name, default "c1"
#
############################################################################
#
# Requires: Version 9 graphics
#
############################################################################
#
# Links: options, weavutil, wopen
#
############################################################################
link options
link weavutil
link wopen
procedure main(args)
local rows_diff, height, width, y, row, count, row_pattern, pixel, opts
local palette
opts := options(args, "p:")
palette := \opts["p"] | "c1" # need to check for valid palette
WOpen("image=" || args[1], "canvas=hidden") | stop("*** cannot open image")
rows_diff := table()
row_pattern := ""
height := WAttrib("height")
width := WAttrib("width")
count := 0
every y := 0 to height - 1 do {
row := ""
every pixel := Pixel(0, y, width, 1) do
row ||:= PaletteKey(palette, pixel)
if /rows_diff[row] then
rows_diff[row] := (count +:= 1)
row_pattern ||:= possym(rows_diff[row]) |
stop("*** too many different rows to label")
}
write(row_pattern)
rows_diff := sort(rows_diff, 3)
while write(get(rows_diff)) do
get(rows_diff)
end
|