--- ray/src/common/bmpfile.c 2004/03/27 16:33:31 2.6 +++ ray/src/common/bmpfile.c 2004/04/29 14:36:49 2.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bmpfile.c,v 2.6 2004/03/27 16:33:31 greg Exp $"; +static const char RCSid[] = "$Id: bmpfile.c,v 2.9 2004/04/29 14:36:49 greg Exp $"; #endif /* * Windows and OS/2 BMP file support @@ -10,6 +10,11 @@ static const char RCSid[] = "$Id: bmpfile.c,v 2.6 2004 #include #include "bmpfile.h" +#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ +#define getc getc_unlocked +#define putc putc_unlocked +#endif + /* get corresponding error message */ const char * BMPerrorMessage(int ec) @@ -600,13 +605,8 @@ wrseek(uint32 pos, BMPWriter *bw) { if (pos == bw->fpos) return BIR_OK; - if (bw->seek == NULL) { - if (pos < bw->fpos) - return BIR_SEEKERR; - while (bw->fpos < pos) - wrbyte(0, bw); - return BIR_OK; - } + if (bw->seek == NULL) + return BIR_SEEKERR; if ((*bw->seek)(pos, bw->c_data) != 0) return BIR_SEEKERR; bw->fpos = pos; @@ -753,7 +753,7 @@ BMPwriteScanline(BMPWriter *bw) break; val = *sp; /* output run */ for (cnt = 1; cnt < 255; cnt++) - if (!--n | *++sp != val) + if ((!--n) | (*++sp != val)) break; wrbyte(cnt, bw); wrbyte(val, bw); @@ -761,9 +761,11 @@ BMPwriteScanline(BMPWriter *bw) bw->yscan++; /* write line break or EOD */ if (bw->yscan == bw->hdr->height) { wrbyte(0, bw); wrbyte(1, bw); /* end of bitmap marker */ - if (bw->seek == NULL || (*bw->seek)(2, bw->c_data) != 0) + if (wrseek(2, bw) != BIR_OK) return BIR_OK; /* no one may care */ - bw->fpos = 2; + wrint32(bw->flen, bw); /* correct file length */ + if (wrseek(34, bw) != BIR_OK) + return BIR_OK; wrint32(bw->flen-bw->fbmp, bw); /* correct bitmap length */ } else { wrbyte(0, bw); wrbyte(0, bw); /* end of line marker */