annotate 3rdparty/utils/viewgif/ReadMe @ 1986:9c683723c7aa

Added (with limitations) support for running on a CoCo 1/2/3
author afra
date Mon, 30 Jan 2006 23:09:57 +0000
parents aaae5eac20e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1188
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
1 The following is some discussion of just what's going on in viewgif, so that
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
2 future code maintainers and modifiers can have an easier time of it.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
3
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
4 Viewgif's main purpose is to decode GIF files and turn them into images that
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
5 can be displayed on the CoCo. The obstacles to such display are:
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
6
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
7 1. GIF images can contain up to 256 colors, which are specified in RGB-888
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
8 form (i.e. eight bits of resolution along each axis of RGB space, a 3-D
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
9 space for colors whose basis consists of {red, green, blue}). The CoCo
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
10 can display at most 16 colors out of the 64 colors that live in RGB-222.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
11
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
12 2. GIF images are compressed, using Lempel-Ziv compression (up to 12-bit
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
13 code length).
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
14
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
15 The second part is no big deal; in fact, the method used in viewgif is that
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
16 used in the early LZ compress program ported to OS-9/6809 a few years ago.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
17 The first part is the one of major interest here.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
18
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
19 Viewgif uses two methods to overcome the GIME's limitations:
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
20
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
21 1. Representing each color c[i] in the GIF image with a sum of two colors
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
22 c1[i] and c2[i], where c1[i] + c2[i] is approximately equal to c[i].
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
23 The c1[i] are displayed on one window and the c2[i] on another, and
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
24 viewgif alternates rapidly between the two windows. This gives us
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
25 additional resolution in RGB space.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
26
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
27 2. Dithering, adding random noise to the displayed image. It may seem odd
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
28 that adding noise to an image should improve it, but in fact it does,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
29 because it spreads out quantization error, and quantization error,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
30 the error induced by going from a continuous quantity to a discrete
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
31 representation or, in our case, cutting down the resolution available,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
32 is the big problem here. The easiest way to see it is to use a non-
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
33 dithering CoCo GIF viewer on an image with lots of shading--portraits
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
34 are best, because you know what color people are. (Starships could be
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
35 any color. :-) It will look like someone painted the person brick red
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
36 or yellow, or like whoever does the *USA Today* weather maps body painted
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
37 the person. Or maybe both!
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
38
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
39 The real guts of viewgif is that portion which determines what "dithering
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
40 factor" is the best for a given image. (You get to specify whether you
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
41 want one or two windows.) This is done in the function newwind(), in the
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
42 file viewgif.c, and the functions it calls (setmap() and approx1() and
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
43 approx2() in setmap.c). newwind() uses a binary search to find the largest
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
44 dithering factor less than or equal to the one given on the command line
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
45 (or the default, if you don't specify one) for which all the colors can
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
46 successfully be mapped to those available on the one or two windows available.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
47 The dithering factor is "extended" in the negative direction by interpreting
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
48 a negative dithering factor as increased sloppiness about what is considered
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
49 "successful" mapping, so that this search always "succeeds." Viewgif will
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
50 show a positive "color tolerance" in this case.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
51
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
52 (If you look at the function approx2(), the function that approximates the
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
53 the colors in the GIF CLUT (Color Look-Up Table) for the two-screen case,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
54 you'll note that not all pairs of colors are considered as possible sums;
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
55 instead, only those pairs that are "near" one another are tried. I can only
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
56 guess at the reason behind this, but I think that it is done to prevent the
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
57 change between windows from being excessively noticeable. If you know
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
58 of a reference that describes the algorithms used here, it would be nice
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
59 to add that in the program comments.)
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
60
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
61 Scattered throughout the original code were some numbers like 85, 42, and
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
62 21. These have to do with the conversion from RGB888 to RGB222. The
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
63 maximum value for a color component in RGB888 is 255, and in RGB222 is 3,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
64 so...to convert, one scales by a factor of 255 / 3 = 85. (For two screens,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
65 this program uses 85 / 2, or 42.) toler() and toler2(), the functions that
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
66 determine how "close" two colors are, do their comparison in RGB888 space,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
67 but consider all colors that would map to the goal color in the CoCo display
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
68 space equally close. (The upper bound on the dithering factor is the
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
69 "radius" of that neighborhood in RGB888 space.)
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
70
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
71 For those who saw the original viewgif, here are the changes I've made:
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
72
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
73 1. A header file, viewgif.h, has been added, with #defines that I hope will
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
74 give some idea where the magic values come from. We've also anticipated
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
75 attempts to port to OS-9/68000, though of course the low-level routines
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
76 are quite CoCo-specific.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
77
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
78 2. The data have been restructured. Most notably, the rgbcolor and
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
79 cocoscreen types are attempts to collect related data in an intelligible
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
80 fashion, to allow iteration over screens or color components, to let
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
81 the common outer loop in setmap() be actual common code, and to avoid
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
82 needless replication of code in the loop that tries to extend just
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
83 one CLUT in approx2(). We hope we are anticipating generalization to
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
84 three or more windows, though that way lies madness, more memory usage,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
85 and a combinatorial explosion in the approx3() function that one would
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
86 have to add.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
87
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
88 3. Scalar global variables have been explicitly put on the direct page
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
89 for speed. (This has been made conditional for possible porting.)
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
90 The assembly-language functions have been changed to reflect this
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
91 placement as well, since Vaughn Cato tried to pick time-critical
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
92 functions for conversion to assembly language. Speaking of which,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
93 we added comments showing addpixel() in C--not that it's tough to
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
94 figure out, but every little bit helps.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
95
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
96 4. Some judiciously-placed register declarations have been added, again
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
97 for speed.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
98
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
99 5. Subscripting has been turned into pointer arithmetic in various places.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
100
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
101 6. Some functions have been moved into what seems to me to be more
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
102 appropriate files, considering who calls them and the general purpose
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
103 of the functions in the file. (Some more of this should be done; in
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
104 particular, functions not related to window manipulation should be
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
105 moved out of gifwin.c.)
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
106
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
107 7. A bug in what was setmap2() but is now approx2() was corrected. The
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
108 original was not toggling the "mode" variable, so that it would never
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
109 look at possible sums extending the larger CLUT.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
110
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
111 8. approx2() (formerly setmap2()) has added an array in which we recall
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
112 the results of the nearcolor() function, rather than calling it lots
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
113 of times. (I think this is the big win for speeding up the analysis
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
114 phase.)
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
115
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
116 9. We added a -? option.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
117
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
118 10. We added a -z option, that overwrites the global color map after
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
119 replacing unused colors with some color that is used. CAUTION:
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
120 this overwrites the whole global color map, and said color map is
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
121 manipulated in other ways via the -g, -g2, and -b options. You
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
122 can lose information if you combine -z with those options, and
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
123 perhaps we should prevent them from being used together.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
124
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
125 There is still more that can be done to speed things up.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
126
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
127 1. It should be possible to speed up the decompression. Alas, the obvious
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
128 way, i.e. going with a hash table rather than a tree, may eat more memory
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
129 than we can afford; nevertheless, it is worth investigating.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
130
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
131 2. It may be worth trying putting two scan lines at a time instead of one,
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
132 to cut system call overhead. One would have to allocate get/put buffers
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
133 for each window to do this. It's not clear whether it would be a win
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
134 for interleaved images.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
135
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
136 3. This version of viewgif shares the problems of the program it is based
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
137 on. (Indeed, it would be surprising if it didn't!) Aside from smarter
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
138 mapping of colors, which I fear would require two passes over the GIF
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
139 file, the main one concerns smarter handling of aspect ratios. Most
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
140 likely, since the current GIF specification doesn't say beans about
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
141 aspect ratio, one will have to let the user tweak the aspect ratio
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
142 on the command line.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
143
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
144 4. The VEF files generated may not be quite correct; vefprt seems to emit
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
145 a few lines of junk before putting out the rest of the image properly.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
146 This behavior seems to be the same for the old and the new versions of
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
147 the program.
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
148
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
149 5. The code that waits for the user to type a character could be changed
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
150 to use the SS_SSIG setstat along with an intercept() routine, to cut
aaae5eac20e1 Provded by James Jones
boisy
parents:
diff changeset
151 system overhead.