"Fossies" - the Fresh Open Source Software Archive 
Member "xearth-1.1/gif.c" (7 Nov 1999, 3286 Bytes) of package /linux/misc/old/xearth-1.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * gif.c
3 * kirk johnson
4 * july 1993
5 *
6 * Copyright (C) 1989, 1990, 1993-1995, 1999 Kirk Lauritz Johnson
7 *
8 * Parts of the source code (as marked) are:
9 * Copyright (C) 1989, 1990, 1991 by Jim Frost
10 * Copyright (C) 1992 by Jamie Zawinski <jwz@lucid.com>
11 *
12 * Permission to use, copy, modify and freely distribute xearth for
13 * non-commercial and not-for-profit purposes is hereby granted
14 * without fee, provided that both the above copyright notice and this
15 * permission notice appear in all copies and in supporting
16 * documentation.
17 *
18 * Unisys Corporation holds worldwide patent rights on the Lempel Zev
19 * Welch (LZW) compression technique employed in the CompuServe GIF
20 * image file format as well as in other formats. Unisys has made it
21 * clear, however, that it does not require licensing or fees to be
22 * paid for freely distributed, non-commercial applications (such as
23 * xearth) that employ LZW/GIF technology. Those wishing further
24 * information about licensing the LZW patent should contact Unisys
25 * directly at (lzw_info@unisys.com) or by writing to
26 *
27 * Unisys Corporation
28 * Welch Licensing Department
29 * M/S-C1SW19
30 * P.O. Box 500
31 * Blue Bell, PA 19424
32 *
33 * The author makes no representations about the suitability of this
34 * software for any purpose. It is provided "as is" without express or
35 * implied warranty.
36 *
37 * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
38 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
39 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
40 * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
41 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
42 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
43 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44 */
45
46 #include "xearth.h"
47 #include "giflib.h"
48 #include "kljcpyrt.h"
49
50 static void gif_setup _P((FILE *));
51 static int gif_row _P((u_char *));
52 static void gif_cleanup _P((void));
53
54 static u16or32 *dith;
55
56
57 void gif_output()
58 {
59 compute_positions();
60 scan_map();
61 do_dots();
62 gif_setup(stdout);
63 render(gif_row);
64 gif_cleanup();
65 }
66
67
68 static void gif_setup(s)
69 FILE *s;
70 {
71 int i;
72 int rtn;
73 BYTE cmap[3][256];
74
75 if (num_colors > 256)
76 fatal("number of colors must be <= 256 with GIF output");
77
78 dither_setup(num_colors);
79 dith = (u16or32 *) malloc((unsigned) sizeof(u16or32) * wdth);
80 assert(dith != NULL);
81
82 for (i=0; i<dither_ncolors; i++)
83 {
84 cmap[0][i] = dither_colormap[i*3+0];
85 cmap[1][i] = dither_colormap[i*3+1];
86 cmap[2][i] = dither_colormap[i*3+2];
87 }
88
89 rtn = gifout_open_file(s, wdth, hght, dither_ncolors, cmap, 0);
90 assert(rtn == GIFLIB_SUCCESS);
91
92 rtn = gifout_open_image(0, 0, wdth, hght);
93 assert(rtn == GIFLIB_SUCCESS);
94 }
95
96
97 static int gif_row(row)
98 u_char *row;
99 {
100 int i, i_lim;
101 u16or32 *tmp;
102
103 tmp = dith;
104 dither_row(row, tmp);
105
106 /* use i_lim to encourage compilers to register loop limit
107 */
108 i_lim = wdth;
109 for (i=0; i<i_lim; i++)
110 gifout_put_pixel((int) tmp[i]);
111
112 return 0;
113 }
114
115
116 static void gif_cleanup()
117 {
118 int rtn;
119
120 rtn = gifout_close_image();
121 assert(rtn == GIFLIB_SUCCESS);
122
123 rtn = gifout_close_file();
124 assert(rtn == GIFLIB_SUCCESS);
125
126 dither_cleanup();
127 free(dith);
128 }