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.5 by greg, Sat Mar 27 05:43:37 2004 UTC vs.
Revision 2.8 by greg, Sat Apr 10 02:54:44 2004 UTC

# Line 255 | Line 255 | BMPisGrayscale(const BMPHeader *hdr)
255                  return -1;
256          if (hdr->bpp > 8)               /* assume they had a reason for it */
257                  return 0;
258 <        for (rgbp = hdr->palette, n = hdr->impColors; n-- > 0; rgbp++)
258 >        for (rgbp = hdr->palette, n = hdr->nColors; n-- > 0; rgbp++)
259                  if (((rgbp->r != rgbp->g) | (rgbp->g != rgbp->b)))
260                          return 0;
261          return 1;                       /* all colors neutral in map */
# Line 279 | Line 279 | BMPreadScanline(BMPReader *br)
279           *
280           * Certain aspects of this scheme are completely insane, so
281           * we don't support them.  Fortunately, they rarely appear.
282 <         * One is the mid-file EOD (0x0001) and another is the insane
282 >         * One is the mid-file EOD (0x0001) and another is the ill-conceived
283           * "delta" (0x0002), which is like a "goto" statement for bitmaps.
284           * Whoever thought this up should be shot, then told why
285 <         * it's impossible to support in any reasonable way.
285 >         * it's impossible to support such a scheme in any reasonable way.
286           * Also, RLE4 mode allows runs to stop halfway through a byte,
287           * which is likewise uncodeable, so we don't even try.
288           * Finally, the scanline break is ambiguous -- we assume here that
# Line 291 | Line 291 | BMPreadScanline(BMPReader *br)
291           * the end of the scanline, assuming the next bit of data belongs
292           * the following scan.  If a break follows the last pixel, as it
293           * seems to in the files I've tested out of Photoshop, you end up
294 <         * painting every other line black.  BTW, I assume any skipped
294 >         * painting every other line black.  Also, I assume any skipped
295           * pixels are painted with color 0, which is often black.  Nowhere
296           * is it specified what we should assume for missing pixels.  This
297           * is undoubtedly the most brain-dead format I've ever encountered.
# Line 323 | Line 323 | BMPreadScanline(BMPReader *br)
323                  case 0:                 /* end of line */
324                          while (n--)
325                                  *sp++ = 0;
326 +                        /* leaves n == -1 as flag for test after loop */
327                          continue;
328                  case 1:                 /* end of bitmap */
329                  case 2:                 /* delta */
# Line 347 | Line 348 | BMPreadScanline(BMPReader *br)
348                          return BIR_TRUNCATED;
349          }
350                                          /* verify break at end of line */
351 <        if (rdbyte(n, br) != 0 || (rdbyte(n, br) != 0 &&
352 <                                (n != 1 || br->yscan != br->hdr->height-1)))
351 >        if (!n && (rdbyte(n, br) != 0 || (rdbyte(n, br) != 0 &&
352 >                                (n != 1 || br->yscan != br->hdr->height-1))))
353                  return BIR_RLERROR;
354          if (br->seek != NULL)           /* record next scanline position */
355                  br->scanpos[br->yscan + 1] = br->fpos;
# Line 599 | Line 600 | wrseek(uint32 pos, BMPWriter *bw)
600   {
601          if (pos == bw->fpos)
602                  return BIR_OK;
603 <        if (bw->seek == NULL) {
604 <                if (pos < bw->fpos)
604 <                        return BIR_SEEKERR;
605 <                while (bw->fpos < pos)
606 <                        wrbyte(0, bw);
607 <                return BIR_OK;
608 <        }
603 >        if (bw->seek == NULL)
604 >                return BIR_SEEKERR;
605          if ((*bw->seek)(pos, bw->c_data) != 0)
606                  return BIR_SEEKERR;
607          bw->fpos = pos;
# Line 752 | Line 748 | BMPwriteScanline(BMPWriter *bw)
748                          break;
749                  val = *sp;                      /* output run */
750                  for (cnt = 1; cnt < 255; cnt++)
751 <                        if (!--n | *++sp != val)
751 >                        if ((!--n) | (*++sp != val))
752                                  break;
753                  wrbyte(cnt, bw);
754                  wrbyte(val, bw);
# Line 760 | Line 756 | BMPwriteScanline(BMPWriter *bw)
756          bw->yscan++;                            /* write line break or EOD */
757          if (bw->yscan == bw->hdr->height) {
758                  wrbyte(0, bw); wrbyte(1, bw);   /* end of bitmap marker */
759 <                if (bw->seek == NULL || (*bw->seek)(2, bw->c_data) != 0)
759 >                if (wrseek(2, bw) != BIR_OK)
760                          return BIR_OK;          /* no one may care */
761 <                bw->fpos = 2;
762 <                wrint32(bw->flen-bw->fbmp, bw); /* output correct bitmap length */
761 >                wrint32(bw->flen, bw);          /* correct file length */
762 >                if (wrseek(34, bw) != BIR_OK)
763 >                        return BIR_OK;
764 >                wrint32(bw->flen-bw->fbmp, bw); /* correct bitmap length */
765          } else {
766                  wrbyte(0, bw); wrbyte(0, bw);   /* end of line marker */
767          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines