15 |
|
#include "color.h" |
16 |
|
|
17 |
|
#define MINELEN 8 /* minimum scanline length for encoding */ |
18 |
+ |
#define MAXELEN 0x7fff /* maximum scanline length for encoding */ |
19 |
|
#define MINRUN 4 /* minimum run length */ |
20 |
|
|
21 |
+ |
#ifndef frexp |
22 |
+ |
extern double frexp(); |
23 |
+ |
#endif |
24 |
|
|
25 |
+ |
|
26 |
|
char * |
27 |
|
tempbuffer(len) /* get a temporary buffer */ |
28 |
|
unsigned len; |
29 |
|
{ |
30 |
|
extern char *malloc(), *realloc(); |
31 |
|
static char *tempbuf = NULL; |
32 |
< |
static int tempbuflen = 0; |
32 |
> |
static unsigned tempbuflen = 0; |
33 |
|
|
34 |
|
if (len > tempbuflen) { |
35 |
|
if (tempbuflen > 0) |
44 |
|
|
45 |
|
fwritecolrs(scanline, len, fp) /* write out a colr scanline */ |
46 |
|
register COLR *scanline; |
47 |
< |
int len; |
47 |
> |
unsigned len; |
48 |
|
register FILE *fp; |
49 |
|
{ |
50 |
|
register int i, j, beg, cnt; |
51 |
|
int c2; |
52 |
|
|
53 |
< |
if (len < MINELEN) /* too small to encode */ |
53 |
> |
if (len < MINELEN | len > MAXELEN) /* OOBs, write out flat */ |
54 |
|
return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len); |
55 |
< |
if (len > 32767) /* too big! */ |
51 |
< |
return(-1); |
52 |
< |
putc(2, fp); /* put magic header */ |
55 |
> |
/* put magic header */ |
56 |
|
putc(2, fp); |
57 |
+ |
putc(2, fp); |
58 |
|
putc(len>>8, fp); |
59 |
|
putc(len&255, fp); |
60 |
|
/* put components seperately */ |
100 |
|
register FILE *fp; |
101 |
|
{ |
102 |
|
register int i, j; |
103 |
< |
int code; |
103 |
> |
int code, val; |
104 |
|
/* determine scanline type */ |
105 |
< |
if (len < MINELEN) |
105 |
> |
if (len < MINELEN | len > MAXELEN) |
106 |
|
return(oldreadcolrs(scanline, len, fp)); |
107 |
|
if ((i = getc(fp)) == EOF) |
108 |
|
return(-1); |
127 |
|
if ((code = getc(fp)) == EOF) |
128 |
|
return(-1); |
129 |
|
if (code > 128) { /* run */ |
130 |
< |
scanline[j++][i] = getc(fp); |
131 |
< |
for (code &= 127; --code; j++) |
132 |
< |
scanline[j][i] = scanline[j-1][i]; |
130 |
> |
code &= 127; |
131 |
> |
val = getc(fp); |
132 |
> |
while (code--) |
133 |
> |
scanline[j++][i] = val; |
134 |
|
} else /* non-run */ |
135 |
|
while (code--) |
136 |
|
scanline[j++][i] = getc(fp); |
231 |
|
register COLR clr; |
232 |
|
double r, g, b; |
233 |
|
{ |
229 |
– |
double frexp(); |
234 |
|
double d; |
235 |
|
int e; |
236 |
|
|