1 
2 /*
3  * This software is copyrighted as noted below.  It may be freely copied,
4  * modified, and redistributed, provided that the copyright notice is
5  * preserved on all copies.
6  *
7  * There is no warranty or other guarantee of fitness for this software,
8  * it is provided solely "as is".  Bug reports or fixes may be sent
9  * to the author, who may or may not act on them as he desires.
10  *
11  * You may not include this software in a program or other software product
12  * without supplying the source, or without informing the end-user that the
13  * source is available for no extra charge.
14  *
15  * If you modify this software, you should include a notice giving the
16  * name of the person performing the modification, the date of modification,
17  * and the reason for such modification.
18  */
19 /*
20  * svfb_global.h - externally visible variables for svfb.
21  *
22  * Author:	Todd W. Fuqua
23  * 		Computer Science Dept.
24  * 		University of Utah
25  * Date:	Sun Jul 29 1984
26  * Copyright (c) 1984 Todd W. Fuqua
27  *
28  * Added optimised dither square size globals
29  * 88/07/13 Graeme W. Gill
30  */
31 
32 #ifndef __RLE_H__
33 #define __RLE_H__
34 
35 enum sv_dispatch {
36     RUN_DISPATCH
37 };
38 
39 /* some compilers have problems converting unsigned bytes to float */
40 #define BYTEBUG
41 
42 /* On BIGENDIAN machines swap the bytes. Everything but vax's and
43  * pdp-11's (not sure if it's pdp11 or PDP11 ??)
44  * are considered BIGENDIAN machines.
45  */
46 
47 #define SWAB(val) (val= memToValLSB((byte *)&val, sizeof(val)))
48 
49 /* ****************************************************************
50  * TAG( rle_pixel rle_map )
51  *
52  * Typedef for 8-bit (or less) pixel data.
53  *
54  * Typedef for 16-bit color map data.
55  */
56 typedef unsigned char rle_pixel;
57 typedef unsigned short rle_map;
58 
59 /*
60  * Defines for traditional channel numbers
61  */
62 #define	SV_RED	    0		/* red channel traditionally here */
63 #define SV_GREEN    1		/* green channel traditionally here */
64 #define	SV_BLUE	    2		/* blue channel traditionally here */
65 #define SV_ALPHA    -1		/* Alpha channel here */
66 
67 /*
68  * Return values from rle_get_setup
69  */
70 #define	RLE_SUCCESS	0
71 #define	RLE_NOT_RLE	-1
72 #define	RLE_NO_SPACE	-2
73 #define	RLE_EMPTY	-3
74 #define	RLE_EOF		-4
75 
76 /*
77  * TAG( sv_globals )
78  *
79  * Definition of "globals" structure used by RLE routines
80  */
81 
82 extern struct sv_globals {
83     enum sv_dispatch sv_dispatch; /* type of file to create */
84     int	    sv_ncolors,		/* number of color channels */
85 	  * sv_bg_color,	/* pointer to bg color vector */
86 	    sv_alpha,		/* if !0, save alpha channel */
87 	    sv_background,	/* (background) 0->just save pixels, */
88 				/* 1->overlay, 2->clear to bg first */
89 	    sv_xmin,		/* lower X bound (left) */
90 	    sv_xmax,		/* upper X bound (right) */
91 	    sv_ymin,		/* lower Y bound (bottom) */
92 	    sv_ymax,		/* upper Y bound (top) */
93 	    sv_ncmap,		/* number of color channels in color map */
94 				/* map only saved if != 0 */
95 	    sv_cmaplen;		/* log2 of color map length */
96     rle_map * sv_cmap;	/* pointer to color map array */
97     char    ** sv_comments;	/* pointer to array of pointers to comments */
98     ZFILE  * svfb_fd;		/* output file */
99     /*
100      * Bit map of channels to read/save.  Indexed by (channel mod 256).
101      * Alpha channel sets bit 255.
102      *
103      * Indexing (0 <= c <= 255):
104      *	    sv_bits[c/8] & (1 << (c%8))
105      */
106 #define SV_SET_BIT(glob,bit) \
107      ((glob).sv_bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))
108 #define SV_CLR_BIT(glob,bit) \
109 	((glob).sv_bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7)))
110 #define SV_BIT(glob,bit) \
111 	((glob).sv_bits[((bit)&0xff)/8] & (1<<((bit)&0x7)))
112     char    sv_bits[256/8];
113     /*
114      * Local storage for rle_getrow & sv_putrow.
115      * rle_getrow has
116      *	    scan_y	int	    current Y scanline
117      *	    vert_skip	int	    number of lines to skip
118      * sv_putrow has
119      *	    nblank	int	    number of blank lines
120      *	    brun	short(*)[2] Array of background runs.
121      *	    fileptr	long	    Position in output file.
122      */
123      union {
124 	struct {
125 	    int	scan_y,
126 		vert_skip;
127 	    char is_eof,	/* Set when EOF or EofOp encountered */
128 		is_seek;	/* If true, can seek input file */
129 	} get;
130 	struct {
131 	    int	nblank;
132 	    short (*brun)[2];
133 	    long fileptr;
134 	} put;
135      } sv_private;
136 } sv_globals;
137 
138 
139 /*
140  * buildmap - build a more usable colormap from data in globals struct.
141  */
142 extern rle_pixel **
143 buildmap();
144 /* ( globals, minmap, gamma )
145  * struct sv_globals * globals;
146  * int minmap;
147  * double gamma;
148  */
149 
150 /*
151  * rle_getcom - get a specific comment from the image comments.
152  */
153 extern char *
154 rle_getcom();
155 /* ( name, globals )
156  * char * name;
157  * struct sv_globals * globals;
158  */
159 
160 /*
161  * rle_putcom - put (or replace) a comment into the image comments.
162  */
163 extern char *
164 rle_putcom();
165 /* ( value, globals )
166  * char * value;
167  * struct sv_globals * globals;
168  */
169 
170 /*
171  * rle_delcom - delete a specific comment from the image comments.
172  */
173 extern char *
174 rle_delcom();
175 /* ( name, globals )
176  * char * name;
177  * struct sv_globals * globals;
178  */
179 
180 /*
181  * dither globals
182  */
183 
184 extern int dith_levels;	/* target effective number of levels, default = 128 */
185 extern int dith_np2;	/* set non-zero to use non-power_of_2 matrix size */
186 extern int dith_size;	/* effective size of the dither matrix chosen */
187 
188 void bw_m_line (unsigned char *dp, int number);
189 void c_m_line(unsigned char *dp, int number, int line);
190 
191 #endif /* __RLE_H__ */
192