39 |
|
|
40 |
|
fwritecolrs(scanline, len, fp) /* write out a colr scanline */ |
41 |
|
register COLR *scanline; |
42 |
< |
int len; |
42 |
> |
unsigned len; |
43 |
|
register FILE *fp; |
44 |
|
{ |
45 |
|
register int i, j, beg, cnt; |
46 |
|
int c2; |
47 |
|
|
48 |
< |
if (len < MINELEN) /* too small to encode */ |
48 |
> |
if (len < MINELEN | len > 0x7fff) /* OOBs, write out flat */ |
49 |
|
return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len); |
50 |
< |
if (len > 32767) /* too big! */ |
51 |
< |
return(-1); |
52 |
< |
putc(2, fp); /* put magic header */ |
50 |
> |
/* put magic header */ |
51 |
|
putc(2, fp); |
52 |
+ |
putc(2, fp); |
53 |
|
putc(len>>8, fp); |
54 |
|
putc(len&255, fp); |
55 |
|
/* put components seperately */ |
62 |
|
if (cnt >= MINRUN) |
63 |
|
break; /* long enough */ |
64 |
|
} |
65 |
< |
while (j < beg) { /* write out non-run(s) */ |
65 |
> |
if (beg-j > 1 && beg-j < MINRUN) { |
66 |
> |
c2 = j+1; |
67 |
> |
while (scanline[c2++][i] == scanline[j][i]) |
68 |
> |
if (c2 == beg) { /* short run */ |
69 |
> |
putc(128+beg-j, fp); |
70 |
> |
putc(scanline[j][i], fp); |
71 |
> |
j = beg; |
72 |
> |
break; |
73 |
> |
} |
74 |
> |
} |
75 |
> |
while (j < beg) { /* write out non-run */ |
76 |
|
if ((c2 = beg-j) > 128) c2 = 128; |
77 |
|
putc(c2, fp); |
78 |
|
while (c2--) |
97 |
|
register int i, j; |
98 |
|
int code; |
99 |
|
/* determine scanline type */ |
100 |
< |
if (len < MINELEN) |
100 |
> |
if (len < MINELEN | len > 0x7fff) |
101 |
|
return(oldreadcolrs(scanline, len, fp)); |
102 |
|
if ((i = getc(fp)) == EOF) |
103 |
|
return(-1); |