ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/bmpfile.c
(Generate patch)

Comparing ray/src/common/bmpfile.c (file contents):
Revision 2.9 by greg, Thu Apr 29 14:36:49 2004 UTC vs.
Revision 2.10 by greg, Fri Apr 30 17:00:29 2004 UTC

# Line 237 | Line 237 | BMPopenReader(int (*cget)(void *), int (*seek)(uint32,
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);
# Line 280 | Line 279 | BMPreadScanline(BMPReader *br)
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
# Line 302 | Line 301 | BMPreadScanline(BMPReader *br)
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  
# Line 322 | Line 324 | BMPreadScanline(BMPReader *br)
324                                  *sp++ = val;
325                          continue;
326                  }
327 +                                        /* check for escape */
328                  switch (rdbyte(len, br)) {
329                  case EOF:
330                          return BIR_TRUNCATED;
# Line 737 | Line 740 | BMPwriteScanline(BMPWriter *bw)
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);
# Line 752 | Line 754 | BMPwriteScanline(BMPWriter *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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines