17 |
|
#define MINELEN 8 /* minimum scanline length for encoding */ |
18 |
|
#define MINRUN 4 /* minimum run length */ |
19 |
|
|
20 |
+ |
#ifndef frexp |
21 |
+ |
extern double frexp(); |
22 |
+ |
#endif |
23 |
|
|
24 |
+ |
|
25 |
|
char * |
26 |
|
tempbuffer(len) /* get a temporary buffer */ |
27 |
|
unsigned len; |
43 |
|
|
44 |
|
fwritecolrs(scanline, len, fp) /* write out a colr scanline */ |
45 |
|
register COLR *scanline; |
46 |
< |
int len; |
46 |
> |
unsigned len; |
47 |
|
register FILE *fp; |
48 |
|
{ |
49 |
|
register int i, j, beg, cnt; |
50 |
|
int c2; |
51 |
|
|
52 |
< |
if (len < MINELEN) /* too small to encode */ |
52 |
> |
if (len < MINELEN | len > 0x7fff) /* OOBs, write out flat */ |
53 |
|
return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len); |
54 |
< |
if (len > 32767) /* too big! */ |
51 |
< |
return(-1); |
52 |
< |
putc(2, fp); /* put magic header */ |
54 |
> |
/* put magic header */ |
55 |
|
putc(2, fp); |
56 |
+ |
putc(2, fp); |
57 |
|
putc(len>>8, fp); |
58 |
|
putc(len&255, fp); |
59 |
|
/* put components seperately */ |
66 |
|
if (cnt >= MINRUN) |
67 |
|
break; /* long enough */ |
68 |
|
} |
69 |
< |
while (j < beg) { /* write out non-run(s) */ |
69 |
> |
if (beg-j > 1 && beg-j < MINRUN) { |
70 |
> |
c2 = j+1; |
71 |
> |
while (scanline[c2++][i] == scanline[j][i]) |
72 |
> |
if (c2 == beg) { /* short run */ |
73 |
> |
putc(128+beg-j, fp); |
74 |
> |
putc(scanline[j][i], fp); |
75 |
> |
j = beg; |
76 |
> |
break; |
77 |
> |
} |
78 |
> |
} |
79 |
> |
while (j < beg) { /* write out non-run */ |
80 |
|
if ((c2 = beg-j) > 128) c2 = 128; |
81 |
|
putc(c2, fp); |
82 |
|
while (c2--) |
101 |
|
register int i, j; |
102 |
|
int code; |
103 |
|
/* determine scanline type */ |
104 |
< |
if (len < MINELEN) |
104 |
> |
if (len < MINELEN | len > 0x7fff) |
105 |
|
return(oldreadcolrs(scanline, len, fp)); |
106 |
|
if ((i = getc(fp)) == EOF) |
107 |
|
return(-1); |
229 |
|
register COLR clr; |
230 |
|
double r, g, b; |
231 |
|
{ |
219 |
– |
double frexp(); |
232 |
|
double d; |
233 |
|
int e; |
234 |
|
|