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.9 by greg, Thu Apr 29 14:36:49 2004 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include <string.h>
11   #include "bmpfile.h"
12  
13 + #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
14 + #define getc    getc_unlocked
15 + #define putc    putc_unlocked
16 + #endif
17 +
18   /* get corresponding error message */
19   const char *
20   BMPerrorMessage(int ec)
# Line 255 | Line 260 | BMPisGrayscale(const BMPHeader *hdr)
260                  return -1;
261          if (hdr->bpp > 8)               /* assume they had a reason for it */
262                  return 0;
263 <        for (rgbp = hdr->palette, n = hdr->impColors; n-- > 0; rgbp++)
263 >        for (rgbp = hdr->palette, n = hdr->nColors; n-- > 0; rgbp++)
264                  if (((rgbp->r != rgbp->g) | (rgbp->g != rgbp->b)))
265                          return 0;
266          return 1;                       /* all colors neutral in map */
# Line 279 | Line 284 | BMPreadScanline(BMPReader *br)
284           *
285           * Certain aspects of this scheme are completely insane, so
286           * we don't support them.  Fortunately, they rarely appear.
287 <         * One is the mid-file EOD (0x0001) and another is the insane
287 >         * One is the mid-file EOD (0x0001) and another is the ill-conceived
288           * "delta" (0x0002), which is like a "goto" statement for bitmaps.
289           * Whoever thought this up should be shot, then told why
290 <         * it's impossible to support in any reasonable way.
290 >         * it's impossible to support such a scheme in any reasonable way.
291           * Also, RLE4 mode allows runs to stop halfway through a byte,
292           * which is likewise uncodeable, so we don't even try.
293           * Finally, the scanline break is ambiguous -- we assume here that
# Line 291 | Line 296 | BMPreadScanline(BMPReader *br)
296           * the end of the scanline, assuming the next bit of data belongs
297           * the following scan.  If a break follows the last pixel, as it
298           * seems to in the files I've tested out of Photoshop, you end up
299 <         * painting every other line black.  BTW, I assume any skipped
299 >         * painting every other line black.  Also, I assume any skipped
300           * pixels are painted with color 0, which is often black.  Nowhere
301           * is it specified what we should assume for missing pixels.  This
302           * is undoubtedly the most brain-dead format I've ever encountered.
# Line 323 | Line 328 | BMPreadScanline(BMPReader *br)
328                  case 0:                 /* end of line */
329                          while (n--)
330                                  *sp++ = 0;
331 +                        /* leaves n == -1 as flag for test after loop */
332                          continue;
333                  case 1:                 /* end of bitmap */
334                  case 2:                 /* delta */
# Line 347 | Line 353 | BMPreadScanline(BMPReader *br)
353                          return BIR_TRUNCATED;
354          }
355                                          /* verify break at end of line */
356 <        if (rdbyte(n, br) != 0 || (rdbyte(n, br) != 0 &&
357 <                                (n != 1 || br->yscan != br->hdr->height-1)))
356 >        if (!n && (rdbyte(n, br) != 0 || (rdbyte(n, br) != 0 &&
357 >                                (n != 1 || br->yscan != br->hdr->height-1))))
358                  return BIR_RLERROR;
359          if (br->seek != NULL)           /* record next scanline position */
360                  br->scanpos[br->yscan + 1] = br->fpos;
# Line 599 | Line 605 | wrseek(uint32 pos, BMPWriter *bw)
605   {
606          if (pos == bw->fpos)
607                  return BIR_OK;
608 <        if (bw->seek == NULL) {
609 <                if (pos < bw->fpos)
604 <                        return BIR_SEEKERR;
605 <                while (bw->fpos < pos)
606 <                        wrbyte(0, bw);
607 <                return BIR_OK;
608 <        }
608 >        if (bw->seek == NULL)
609 >                return BIR_SEEKERR;
610          if ((*bw->seek)(pos, bw->c_data) != 0)
611                  return BIR_SEEKERR;
612          bw->fpos = pos;
# Line 752 | Line 753 | BMPwriteScanline(BMPWriter *bw)
753                          break;
754                  val = *sp;                      /* output run */
755                  for (cnt = 1; cnt < 255; cnt++)
756 <                        if (!--n | *++sp != val)
756 >                        if ((!--n) | (*++sp != val))
757                                  break;
758                  wrbyte(cnt, bw);
759                  wrbyte(val, bw);
# Line 760 | Line 761 | BMPwriteScanline(BMPWriter *bw)
761          bw->yscan++;                            /* write line break or EOD */
762          if (bw->yscan == bw->hdr->height) {
763                  wrbyte(0, bw); wrbyte(1, bw);   /* end of bitmap marker */
764 <                if (bw->seek == NULL || (*bw->seek)(2, bw->c_data) != 0)
764 >                if (wrseek(2, bw) != BIR_OK)
765                          return BIR_OK;          /* no one may care */
766 <                bw->fpos = 2;
767 <                wrint32(bw->flen-bw->fbmp, bw); /* output correct bitmap length */
766 >                wrint32(bw->flen, bw);          /* correct file length */
767 >                if (wrseek(34, bw) != BIR_OK)
768 >                        return BIR_OK;
769 >                wrint32(bw->flen-bw->fbmp, bw); /* correct bitmap length */
770          } else {
771                  wrbyte(0, bw); wrbyte(0, bw);   /* end of line marker */
772          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines