--- ray/src/common/bmpfile.h 2004/03/26 03:11:50 2.1 +++ ray/src/common/bmpfile.h 2008/05/31 19:38:36 2.6 @@ -1,4 +1,4 @@ -/* RCSid $Id: bmpfile.h,v 2.1 2004/03/26 03:11:50 greg Exp $ */ +/* RCSid $Id: bmpfile.h,v 2.6 2008/05/31 19:38:36 greg Exp $ */ /* * Windows and OS/2 BMP file support */ @@ -6,7 +6,7 @@ #ifndef _RAD_BMPFILE_H_ #define _RAD_BMPFILE_H_ -#include "tifftypes.h" +#include "tiff.h" /* needed for int32, etc. */ #ifdef __cplusplus extern "C" { @@ -26,34 +26,35 @@ typedef struct { /* Allocated BMP header data */ typedef struct { - /* the following fields may be altered before open call */ + /* the following fields may be altered before the open call */ int yIsDown; /* scanlines proceed downward? */ int32 hRes; /* horizontal resolution pixels/meter */ int32 vRes; /* vertical resolution pixels/meter */ int nColors; /* total color palette size */ int impColors; /* number of colors actually used */ - /* the following fields should not be altered after allocation */ + int compr; /* compression */ int32 width; /* bitmap width (pixels) */ int32 height; /* bitmap height (pixels) */ + /* the following fields must not be altered after allocation */ int bpp; /* bits per sample (1,4,8,16,24,32) */ - int compr; /* compression */ uint32 infoSiz; /* info buffer size (bytes) */ - /* the color table should be filled by writer before open call */ - RGBquad palette[2]; /* color palette (extends struct) */ + /* but the color table should be filled by writer before open call */ + RGBquad palette[3]; /* color palette (extends struct) */ } BMPHeader; + + /* access to bit field triple */ +#define BMPbitField(h) ((uint32 *)(h)->palette) - /* color palette length */ -#define BMPpalLen(h) ((h)->bpp <= 8 ? 1<<(h)->bpp : 0) - /* info buffer access */ -#define BMPinfo(h) ((char *)((h)->palette + BMPpalLen(h))) +#define BMPinfo(h) ((char *)((h)->palette + (h)->nColors)) /* function return values */ #define BIR_OK 0 /* all is well */ #define BIR_EOF (-1) /* reached end of file */ #define BIR_TRUNCATED 1 /* unexpected EOF */ #define BIR_UNSUPPORTED 2 /* unsupported encoding */ -#define BIR_SEEKERR 3 /* could not seek */ +#define BIR_RLERROR 3 /* RLE error */ +#define BIR_SEEKERR 4 /* could not seek */ /* A BMP reader structure */ typedef struct BMPReader { @@ -74,8 +75,9 @@ typedef struct BMPReader { typedef struct { /* the scanline data is filled in by caller before each write */ uint8 *scanline; /* caller-prepared scanline data */ + /* modify yscan only if seek is defined & data is uncompressed */ int yscan; /* scanline for next write */ - /* the following fields should not be altered by the caller */ + /* the following fields should not be altered directly */ BMPHeader *hdr; /* allocated header */ uint32 fbmp; /* beginning of bitmap data */ uint32 fpos; /* current file position */ @@ -101,7 +103,7 @@ int BMPreadScanline(BMPReader *br); int BMPseekScanline(int y, BMPReader *br); /* get ith pixel from last scanline */ -RGBquad BMPdecodePixel(int i, BMPReader *br); +RGBquad BMPdecodePixel(int i, const BMPReader *br); /* free BMP reader resources */ void BMPfreeReader(BMPReader *br); @@ -136,7 +138,7 @@ int stdio_fseek(uint32 pos, void *p); /* open input file */ #define BMPopenInputFile(fn) BMPopenReader(&stdio_getc, &stdio_fseek, \ - (void *)fopen(fn, "r")) + (void *)fopen(fn, "rb")) /* close stdio input file or stream */ #define BMPcloseInput(br) ( fclose((FILE *)(br)->c_data), \ @@ -149,7 +151,7 @@ int stdio_fseek(uint32 pos, void *p); /* open stdio output file */ #define BMPopenOutputFile(fn,hdr) \ BMPopenWriter(&stdio_putc, &stdio_fseek, \ - (void *)fopen(fn, "w"), hdr) + (void *)fopen(fn, "wb"), hdr) /* close stdio output file or stream */ #define BMPcloseOutput(bw) ( fclose((FILE *)(bw)->c_data), \