| 26 |
|
|
| 27 |
|
/* Allocated BMP header data */ |
| 28 |
|
typedef struct { |
| 29 |
< |
/* the following fields may be altered before open call */ |
| 29 |
> |
/* the following fields may be altered before the open call */ |
| 30 |
|
int yIsDown; /* scanlines proceed downward? */ |
| 31 |
|
int32 hRes; /* horizontal resolution pixels/meter */ |
| 32 |
|
int32 vRes; /* vertical resolution pixels/meter */ |
| 33 |
|
int nColors; /* total color palette size */ |
| 34 |
|
int impColors; /* number of colors actually used */ |
| 35 |
< |
/* the following fields should not be altered after allocation */ |
| 35 |
> |
int compr; /* compression */ |
| 36 |
|
int32 width; /* bitmap width (pixels) */ |
| 37 |
|
int32 height; /* bitmap height (pixels) */ |
| 38 |
+ |
/* the following fields must not be altered after allocation */ |
| 39 |
|
int bpp; /* bits per sample (1,4,8,16,24,32) */ |
| 39 |
– |
int compr; /* compression */ |
| 40 |
|
uint32 infoSiz; /* info buffer size (bytes) */ |
| 41 |
< |
/* the color table should be filled by writer before open call */ |
| 42 |
< |
RGBquad palette[2]; /* color palette (extends struct) */ |
| 41 |
> |
/* but the color table should be filled by writer before open call */ |
| 42 |
> |
RGBquad palette[3]; /* color palette (extends struct) */ |
| 43 |
|
} BMPHeader; |
| 44 |
+ |
|
| 45 |
+ |
/* access to bit field triple */ |
| 46 |
+ |
#define BMPbitField(h) ((uint32 *)(h)->palette) |
| 47 |
|
|
| 45 |
– |
/* color palette length */ |
| 46 |
– |
#define BMPpalLen(h) ((h)->bpp <= 8 ? 1<<(h)->bpp : 0) |
| 47 |
– |
|
| 48 |
|
/* info buffer access */ |
| 49 |
< |
#define BMPinfo(h) ((char *)((h)->palette + BMPpalLen(h))) |
| 49 |
> |
#define BMPinfo(h) ((char *)((h)->palette + (h)->nColors)) |
| 50 |
|
|
| 51 |
|
/* function return values */ |
| 52 |
|
#define BIR_OK 0 /* all is well */ |
| 53 |
|
#define BIR_EOF (-1) /* reached end of file */ |
| 54 |
|
#define BIR_TRUNCATED 1 /* unexpected EOF */ |
| 55 |
|
#define BIR_UNSUPPORTED 2 /* unsupported encoding */ |
| 56 |
< |
#define BIR_SEEKERR 3 /* could not seek */ |
| 56 |
> |
#define BIR_RLERROR 3 /* RLE error */ |
| 57 |
> |
#define BIR_SEEKERR 4 /* could not seek */ |
| 58 |
|
|
| 59 |
|
/* A BMP reader structure */ |
| 60 |
|
typedef struct BMPReader { |
| 75 |
|
typedef struct { |
| 76 |
|
/* the scanline data is filled in by caller before each write */ |
| 77 |
|
uint8 *scanline; /* caller-prepared scanline data */ |
| 78 |
+ |
/* modify yscan only if seek is defined & data is uncompressed */ |
| 79 |
|
int yscan; /* scanline for next write */ |
| 80 |
< |
/* the following fields should not be altered by the caller */ |
| 80 |
> |
/* the following fields should not be altered directly */ |
| 81 |
|
BMPHeader *hdr; /* allocated header */ |
| 82 |
|
uint32 fbmp; /* beginning of bitmap data */ |
| 83 |
|
uint32 fpos; /* current file position */ |
| 103 |
|
int BMPseekScanline(int y, BMPReader *br); |
| 104 |
|
|
| 105 |
|
/* get ith pixel from last scanline */ |
| 106 |
< |
RGBquad BMPdecodePixel(int i, BMPReader *br); |
| 106 |
> |
RGBquad BMPdecodePixel(int i, const BMPReader *br); |
| 107 |
|
|
| 108 |
|
/* free BMP reader resources */ |
| 109 |
|
void BMPfreeReader(BMPReader *br); |