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
|
############################################################################
#
# File: poller.icn
#
# Subject: Program to record image as pixel coordinates
#
# Author: Ralph E. Griswold
#
# Date: December 30, 1998
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program reads an image whose name is given on the command line and
# writes it out as an Icon list of pixels in the form of an include file.
# See the documentation below for details.
#
############################################################################
#
# Requires: Version 9 graphics
#
############################################################################
#
# Links: lists, wopen
#
############################################################################
link lists
link wopen
procedure main(args)
local colors, width, height, x, y, c
WOpen("image=" || args[1]) | stop("*** cannot open image")
colors := table()
width := WAttrib("width")
height := WAttrib("height")
x := y := 0
# Build table of argument lists for colors
every c := Pixel() do {
x +:= 1
if x % width = 0 then {
x := 0
y +:= 1
}
/colors[c] := [] # new color
put(colors[c], x, y)
}
# Write Icon code for an include file. A list of argument lists
# is assigned to "pixels". Each argument list consists of the
# color followed by the pixel coordinates at which that color
# occurs
#
# The last element of the list is a three-element list giving the
# width, height, and number of colors in the image. Note that this
# is an easily accessible location and that it "solves" the problem
# that all previous lines are termianted by commas, so without it
# either there would be a trailing empty element in "pixels"
# or some painful code would be necessary to avoid it.
write("pixels:=[")
every c := key(colors) do {
push(colors[c], c)
write(limage(colors[c]), ",")
}
write("[", width, ",", height, ",", *colors, "]")
write("]")
end
|