| 237 |
|
sizeof(br->scanpos[0])*br->hdr->height); |
| 238 |
|
} |
| 239 |
|
br->scanpos[0] = br->fpos; |
| 240 |
< |
if (BMPreadScanline(br) != BIR_OK) |
| 241 |
< |
goto err; |
| 242 |
< |
return br; |
| 240 |
> |
if (BMPreadScanline(br) == BIR_OK) |
| 241 |
> |
return br; |
| 242 |
|
err: |
| 243 |
|
if (br->hdr != NULL) |
| 244 |
|
free((void *)br->hdr); |
| 279 |
|
if (br->hdr->compr == BI_UNCOMPR || br->hdr->compr == BI_BITFIELDS) |
| 280 |
|
return rdbytes((char *)br->scanline, n, br); |
| 281 |
|
/* |
| 282 |
< |
* RLE/RLE8 Decoding |
| 282 |
> |
* RLE4/RLE8 Decoding |
| 283 |
|
* |
| 284 |
|
* Certain aspects of this scheme are completely insane, so |
| 285 |
|
* we don't support them. Fortunately, they rarely appear. |
| 286 |
|
* One is the mid-file EOD (0x0001) and another is the ill-conceived |
| 287 |
|
* "delta" (0x0002), which is like a "goto" statement for bitmaps. |
| 288 |
< |
* Whoever thought this up should be shot, then told why |
| 289 |
< |
* it's impossible to support such a scheme in any reasonable way. |
| 288 |
> |
* Whoever thought this up should be wrestled to the ground and told |
| 289 |
> |
* why it's impossible to support such a scheme in any reasonable way. |
| 290 |
|
* Also, RLE4 mode allows runs to stop halfway through a byte, |
| 291 |
|
* which is likewise uncodeable, so we don't even try. |
| 292 |
|
* Finally, the scanline break is ambiguous -- we assume here that |
| 301 |
|
* is undoubtedly the most brain-dead format I've ever encountered. |
| 302 |
|
*/ |
| 303 |
|
sp = br->scanline; |
| 304 |
+ |
n = br->hdr->width; |
| 305 |
+ |
if (br->hdr->compr == BI_RLE4) |
| 306 |
+ |
n = (n + 1) >> 1; |
| 307 |
|
while (n > 0) { |
| 308 |
|
int skipOdd, len, val; |
| 309 |
|
|
| 324 |
|
*sp++ = val; |
| 325 |
|
continue; |
| 326 |
|
} |
| 327 |
+ |
/* check for escape */ |
| 328 |
|
switch (rdbyte(len, br)) { |
| 329 |
|
case EOF: |
| 330 |
|
return BIR_TRUNCATED; |
| 740 |
|
n = bw->hdr->width; |
| 741 |
|
while (n > 0) { |
| 742 |
|
int cnt, val; |
| 740 |
– |
|
| 743 |
|
cnt = findNextRun(sp, n); /* 0-255 < n */ |
| 744 |
< |
if (cnt >= 3) { /* output non-run */ |
| 744 |
> |
if (cnt >= 3) { /* output absolute */ |
| 745 |
|
int skipOdd = cnt & 1; |
| 746 |
|
wrbyte(0, bw); |
| 747 |
|
wrbyte(cnt, bw); |
| 754 |
|
if (n <= 0) /* was that it? */ |
| 755 |
|
break; |
| 756 |
|
val = *sp; /* output run */ |
| 757 |
< |
for (cnt = 1; cnt < 255; cnt++) |
| 758 |
< |
if ((!--n) | (*++sp != val)) |
| 757 |
> |
for (cnt = 1; --n && cnt < 255; cnt++) |
| 758 |
> |
if (*++sp != val) |
| 759 |
|
break; |
| 760 |
|
wrbyte(cnt, bw); |
| 761 |
|
wrbyte(val, bw); |