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.12 by greg, Tue Sep 14 02:53:50 2004 UTC vs.
Revision 2.13 by greg, Fri Mar 18 21:04:05 2005 UTC

# Line 71 | Line 71 | BMPheaderOK(const BMPHeader *hdr)
71          if (hdr->compr == BI_BITFIELDS && (BMPbitField(hdr)[0] &
72                                  BMPbitField(hdr)[1] & BMPbitField(hdr)[2]))
73                  return 0;
74 <        if ((hdr->nColors < 0) | (hdr->impColors < 0))
75 <                return 0;
76 <        if (hdr->impColors > hdr->nColors)
77 <                return 0;
78 <        if (hdr->nColors > BMPpalLen(hdr))
79 <                return 0;
74 >        if (hdr->bpp > 8) {
75 >                if (hdr->nColors != 0)
76 >                        return 0;
77 >        } else {
78 >                if ((hdr->nColors < 0) | (hdr->nColors > 1<<hdr->bpp))
79 >                        return 0;
80 >                if ((hdr->impColors < 0) | (hdr->impColors > hdr->nColors))
81 >                        return 0;
82 >        }
83          return 1;
84   }
85  
# Line 143 | Line 146 | BMPReader *
146   BMPopenReader(int (*cget)(void *), int (*seek)(uint32, void *), void *c_data)
147   {
148          BMPReader       *br;
149 <        uint32          bmPos, hdrSiz;
150 <        int             palLen;
148 <        int     magic[2];               /* check magic number */
149 >        uint32          bmPos, hdrSiz, palSiz;
150 >        int             magic[2];               /* check magic number */
151  
152          if (cget == NULL)
153                  return NULL;
# Line 191 | Line 193 | BMPopenReader(int (*cget)(void *), int (*seek)(uint32,
193                  goto err;                       /* catch premature EOF */
194          if (!BMPheaderOK(br->hdr))
195                  goto err;
196 <        palLen = BMPpalLen(br->hdr);
197 <        if (br->hdr->bpp <= 8) {                /* normalize color counts */
198 <                if (br->hdr->nColors <= 0)
197 <                        br->hdr->nColors = palLen;
198 <                if (br->hdr->impColors <= 0)
199 <                        br->hdr->impColors = br->hdr->nColors;
200 <        }
196 >        palSiz = sizeof(RGBquad)*br->hdr->nColors;
197 >        if (br->hdr->impColors <= 0)
198 >                br->hdr->impColors = br->hdr->nColors;
199                                                  /* extend header */
200 <        if (bmPos < hdrSiz + sizeof(RGBquad)*palLen)
200 >        if (bmPos < hdrSiz + palSiz)
201                  goto err;
202 <        br->hdr->infoSiz = bmPos - (hdrSiz + sizeof(RGBquad)*palLen);
203 <        if (palLen > 0 || br->hdr->infoSiz > 0) {
202 >        br->hdr->infoSiz = bmPos - (hdrSiz + palSiz);
203 >        if (br->hdr->nColors > 0 || br->hdr->infoSiz > 0) {
204                  br->hdr = (BMPHeader *)realloc((void *)br->hdr,
205                                          sizeof(BMPHeader) +
206 <                                        sizeof(RGBquad)*palLen +
209 <                                        br->hdr->infoSiz);
206 >                                        palSiz + br->hdr->infoSiz);
207                  if (br->hdr == NULL)
208                          goto err;
209          }
# Line 215 | Line 212 | BMPopenReader(int (*cget)(void *), int (*seek)(uint32,
212                  BMPbitField(br->hdr)[0] = (uint32)rdint32(br);
213                  BMPbitField(br->hdr)[1] = (uint32)rdint32(br);
214                  BMPbitField(br->hdr)[2] = (uint32)rdint32(br);
215 <        } else if (rdbytes((char *)br->hdr->palette,
219 <                        sizeof(RGBquad)*palLen, br) != BIR_OK)
215 >        } else if (rdbytes((char *)br->hdr->palette, palSiz, br) != BIR_OK)
216                  goto err;
217                                                  /* read add'l information */
218          if (rdbytes(BMPinfo(br->hdr), br->hdr->infoSiz, br) != BIR_OK)
# Line 642 | Line 638 | BMPopenWriter(void (*cput)(int, void *), int (*seek)(u
638          hdrSiz = 2 + 6*4 + 2*2 + 6*4;
639          if (hdr->compr == BI_BITFIELDS)
640                  hdrSiz += sizeof(uint32)*3;
641 <        palSiz = sizeof(RGBquad)*BMPpalLen(hdr);
641 >        palSiz = sizeof(RGBquad)*hdr->nColors;
642          scanSiz = getScanSiz(hdr);
643          bmSiz = hdr->height*scanSiz;            /* wrong if compressed */
644                                                  /* initialize writer */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines