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.6 by greg, Sat Mar 27 16:33:31 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 628 | Line 629 | BMPopenWriter(void (*cput)(int, void *), int (*seek)(u
629                  return NULL;
630          if ((hdr->bpp == 16) | (hdr->compr == BI_RLE4))
631                  return NULL;                    /* unsupported */
632 + /* no seek means we may have the wrong file length, but most app's don't care
633          if (seek == NULL && ((hdr->compr == BI_RLE8) | (hdr->compr == BI_RLE4)))
634                  return NULL;
635 + */
636                                                  /* compute sizes */
637          hdrSiz = 2 + 6*4 + 2*2 + 6*4;
638          if (hdr->compr == BI_BITFIELDS)
# Line 696 | Line 699 | findNextRun(const int8 *bp, int len)
699                          continue;
700                  cnt = 1;                        /* else let's try it */
701                  while (bp[cnt] == bp[0])
702 <                        if (++cnt >= 5)         /* long enough */
703 <                                return pos;
702 >                        if (++cnt >= 5)
703 >                                return pos;     /* long enough */
704          }
705          return pos;                             /* didn't find any */
706   }
# Line 749 | Line 752 | BMPwriteScanline(BMPWriter *bw)
752                  if (n <= 0)                     /* was that it? */
753                          break;
754                  val = *sp;                      /* output run */
755 <                for (cnt = 1; (--n > 0) & (*++sp == val); cnt++)
756 <                        ;
755 >                for (cnt = 1; cnt < 255; cnt++)
756 >                        if (!--n | *++sp != val)
757 >                                break;
758                  wrbyte(cnt, bw);
759                  wrbyte(val, bw);
760          }
761 <        bw->yscan++;                            /* write file length at end */
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)
765 <                        return BIR_SEEKERR;
765 >                        return BIR_OK;          /* no one may care */
766                  bw->fpos = 2;
767 <                wrint32(bw->flen, bw);          /* corrected file length */
767 >                wrint32(bw->flen-bw->fbmp, bw); /* correct bitmap length */
768          } else {
769                  wrbyte(0, bw); wrbyte(0, bw);   /* end of line marker */
770          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines