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.4 by schorsch, Fri Mar 26 23:30:05 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 522 | Line 523 | BMPtruecolorHeader(int xr, int yr, int infolen)
523          return hdr;
524   }
525  
526 < /* allocate color-mapped header (defaults minimal grayscale) */
526 > /* allocate color-mapped header (defaults to minimal grayscale) */
527   BMPHeader *
528   BMPmappedHeader(int xr, int yr, int infolen, int ncolors)
529   {
# Line 549 | Line 550 | BMPmappedHeader(int xr, int yr, int infolen, int ncolo
550          hdr->height = yr;
551          hdr->yIsDown = 0;                       /* default to upwards order */
552          hdr->bpp = n;
553 <        hdr->compr = BI_UNCOMPR;
553 >        hdr->compr = BI_UNCOMPR;                /* compression needs seek */
554          hdr->hRes = hdr->vRes = 2835;           /* default to 72 ppi */
555          hdr->nColors = ncolors;
556          hdr->impColors = 0;                     /* says all colors important */
# 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 628 | Line 624 | BMPopenWriter(void (*cput)(int, void *), int (*seek)(u
624                  return NULL;
625          if ((hdr->bpp == 16) | (hdr->compr == BI_RLE4))
626                  return NULL;                    /* unsupported */
627 + /* no seek means we may have the wrong file length, but most app's don't care
628          if (seek == NULL && ((hdr->compr == BI_RLE8) | (hdr->compr == BI_RLE4)))
629                  return NULL;
630 + */
631                                                  /* compute sizes */
632          hdrSiz = 2 + 6*4 + 2*2 + 6*4;
633          if (hdr->compr == BI_BITFIELDS)
# Line 696 | Line 694 | findNextRun(const int8 *bp, int len)
694                          continue;
695                  cnt = 1;                        /* else let's try it */
696                  while (bp[cnt] == bp[0])
697 <                        if (++cnt >= 5)         /* long enough */
698 <                                return pos;
697 >                        if (++cnt >= 5)
698 >                                return pos;     /* long enough */
699          }
700          return pos;                             /* didn't find any */
701   }
# Line 749 | Line 747 | BMPwriteScanline(BMPWriter *bw)
747                  if (n <= 0)                     /* was that it? */
748                          break;
749                  val = *sp;                      /* output run */
750 <                for (cnt = 1; (--n > 0) & (*++sp == val); cnt++)
751 <                        ;
750 >                for (cnt = 1; cnt < 255; cnt++)
751 >                        if ((!--n) | (*++sp != val))
752 >                                break;
753                  wrbyte(cnt, bw);
754                  wrbyte(val, bw);
755          }
756 <        bw->yscan++;                            /* write file length at end */
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)
760 <                        return BIR_SEEKERR;
761 <                bw->fpos = 2;
762 <                wrint32(bw->flen, bw);          /* corrected file length */
759 >                if (wrseek(2, bw) != BIR_OK)
760 >                        return BIR_OK;          /* no one may care */
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