10 |
|
#include "copyright.h" |
11 |
|
|
12 |
|
#include <stdio.h> |
13 |
– |
|
13 |
|
#include <stdlib.h> |
15 |
– |
|
14 |
|
#include <math.h> |
17 |
– |
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
|
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
19 |
|
#undef putc |
20 |
|
#define getc getc_unlocked |
21 |
|
#define putc putc_unlocked |
22 |
+ |
#define ferror ferror_unlocked |
23 |
|
#endif |
24 |
|
|
25 |
|
#define MINELEN 8 /* minimum scanline length for encoding */ |
28 |
|
|
29 |
|
|
30 |
|
char * |
31 |
< |
tempbuffer(len) /* get a temporary buffer */ |
32 |
< |
unsigned int len; |
31 |
> |
tempbuffer( /* get a temporary buffer */ |
32 |
> |
unsigned int len |
33 |
> |
) |
34 |
|
{ |
35 |
|
static char *tempbuf = NULL; |
36 |
|
static unsigned tempbuflen = 0; |
47 |
|
|
48 |
|
|
49 |
|
int |
50 |
< |
fwritecolrs(scanline, len, fp) /* write out a colr scanline */ |
51 |
< |
register COLR *scanline; |
52 |
< |
int len; |
53 |
< |
register FILE *fp; |
50 |
> |
fwritecolrs( /* write out a colr scanline */ |
51 |
> |
COLR *scanline, |
52 |
> |
int len, |
53 |
> |
FILE *fp |
54 |
> |
) |
55 |
|
{ |
56 |
< |
register int i, j, beg, cnt = 1; |
56 |
> |
int i, j, beg, cnt = 1; |
57 |
|
int c2; |
58 |
|
|
59 |
|
if ((len < MINELEN) | (len > MAXELEN)) /* OOBs, write out flat */ |
101 |
|
|
102 |
|
|
103 |
|
static int |
104 |
< |
oldreadcolrs(scanline, len, fp) /* read in an old colr scanline */ |
105 |
< |
register COLR *scanline; |
106 |
< |
int len; |
107 |
< |
register FILE *fp; |
104 |
> |
oldreadcolrs( /* read in an old colr scanline */ |
105 |
> |
COLR *scanline, |
106 |
> |
int len, |
107 |
> |
FILE *fp |
108 |
> |
) |
109 |
|
{ |
110 |
< |
int rshift; |
111 |
< |
register int i; |
110 |
> |
int rshift = 0; |
111 |
> |
int i; |
112 |
|
|
112 |
– |
rshift = 0; |
113 |
– |
|
113 |
|
while (len > 0) { |
114 |
|
scanline[0][RED] = getc(fp); |
115 |
|
scanline[0][GRN] = getc(fp); |
116 |
|
scanline[0][BLU] = getc(fp); |
117 |
< |
scanline[0][EXP] = getc(fp); |
118 |
< |
if (feof(fp) || ferror(fp)) |
117 |
> |
scanline[0][EXP] = i = getc(fp); |
118 |
> |
if (i == EOF) |
119 |
|
return(-1); |
120 |
|
if (scanline[0][RED] == 1 && |
121 |
|
scanline[0][GRN] == 1 && |
137 |
|
|
138 |
|
|
139 |
|
int |
140 |
< |
freadcolrs(scanline, len, fp) /* read in an encoded colr scanline */ |
141 |
< |
register COLR *scanline; |
142 |
< |
int len; |
143 |
< |
register FILE *fp; |
140 |
> |
freadcolrs( /* read in an encoded colr scanline */ |
141 |
> |
COLR *scanline, |
142 |
> |
int len, |
143 |
> |
FILE *fp |
144 |
> |
) |
145 |
|
{ |
146 |
< |
register int i, j; |
146 |
> |
int i, j; |
147 |
|
int code, val; |
148 |
|
/* determine scanline type */ |
149 |
|
if ((len < MINELEN) | (len > MAXELEN)) |
193 |
|
|
194 |
|
|
195 |
|
int |
196 |
< |
fwritescan(scanline, len, fp) /* write out a scanline */ |
197 |
< |
register COLOR *scanline; |
198 |
< |
int len; |
199 |
< |
FILE *fp; |
196 |
> |
fwritescan( /* write out a scanline */ |
197 |
> |
COLOR *scanline, |
198 |
> |
int len, |
199 |
> |
FILE *fp |
200 |
> |
) |
201 |
|
{ |
202 |
|
COLR *clrscan; |
203 |
|
int n; |
204 |
< |
register COLR *sp; |
204 |
> |
COLR *sp; |
205 |
|
/* get scanline buffer */ |
206 |
|
if ((sp = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL) |
207 |
|
return(-1); |
220 |
|
|
221 |
|
|
222 |
|
int |
223 |
< |
freadscan(scanline, len, fp) /* read in a scanline */ |
224 |
< |
register COLOR *scanline; |
225 |
< |
int len; |
226 |
< |
FILE *fp; |
223 |
> |
freadscan( /* read in a scanline */ |
224 |
> |
COLOR *scanline, |
225 |
> |
int len, |
226 |
> |
FILE *fp |
227 |
> |
) |
228 |
|
{ |
229 |
< |
register COLR *clrscan; |
229 |
> |
COLR *clrscan; |
230 |
|
|
231 |
|
if ((clrscan = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL) |
232 |
|
return(-1); |
249 |
|
|
250 |
|
|
251 |
|
void |
252 |
< |
setcolr(clr, r, g, b) /* assign a short color value */ |
253 |
< |
register COLR clr; |
254 |
< |
double r, g, b; |
252 |
> |
setcolr( /* assign a short color value */ |
253 |
> |
COLR clr, |
254 |
> |
double r, |
255 |
> |
double g, |
256 |
> |
double b |
257 |
> |
) |
258 |
|
{ |
259 |
|
double d; |
260 |
|
int e; |
288 |
|
|
289 |
|
|
290 |
|
void |
291 |
< |
colr_color(col, clr) /* convert short to float color */ |
292 |
< |
register COLOR col; |
293 |
< |
register COLR clr; |
291 |
> |
colr_color( /* convert short to float color */ |
292 |
> |
COLOR col, |
293 |
> |
COLR clr |
294 |
> |
) |
295 |
|
{ |
296 |
|
double f; |
297 |
|
|
307 |
|
|
308 |
|
|
309 |
|
int |
310 |
< |
bigdiff(c1, c2, md) /* c1 delta c2 > md? */ |
311 |
< |
register COLOR c1, c2; |
312 |
< |
double md; |
310 |
> |
bigdiff( /* c1 delta c2 > md? */ |
311 |
> |
COLOR c1, |
312 |
> |
COLOR c2, |
313 |
> |
double md |
314 |
> |
) |
315 |
|
{ |
316 |
< |
register int i; |
316 |
> |
int i; |
317 |
|
|
318 |
|
for (i = 0; i < 3; i++) |
319 |
|
if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) || |