From 12fe3f62f2931f296beb130840c091542647319b Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Wed, 18 Jun 2008 16:26:41 -0700 Subject: support for 16 and 32 bit bitmaps --- src/bmp.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bmp.c b/src/bmp.c index b641563..4c5dd20 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -103,7 +103,14 @@ struct image *bmp_open(FILE *f){ return (struct image *)b; } -static void readrow(struct image *img, unsigned char *row, unsigned char *buf){ +void rgb16(unsigned char *buf, unsigned short c){ + int i; + for(i = 0; i < 3; i++){ + *buf++ = ((c >> (i * 5)) & 0x1f) << 3; + } +} + +static int readrow(struct image *img, unsigned char *row, unsigned char *buf){ struct bmp_t *b = (struct bmp_t *)img; int x; int i = 0; @@ -115,6 +122,13 @@ static void readrow(struct image *img, unsigned char *row, unsigned char *buf){ if(b->bpp == 32) i++; } + }else if(b->bpp == 16){ + for(x = 0; x < img->width * 3; x+=3){ + unsigned short c; + c = row[i++]; + c |= row[i++] << 8; + rgb16(&buf[x], c); + } }else if(b->bpp <= 8){ int mask; int pixelsperbit = 8 / b->bpp; @@ -128,8 +142,9 @@ static void readrow(struct image *img, unsigned char *row, unsigned char *buf){ } }else{ fprintf(stderr, "bad bpp %i\n", b->bpp); - return; + return 1; } + return 0; } int bmp_read(struct image *img){ @@ -145,7 +160,8 @@ int bmp_read(struct image *img){ i -= dy; if(fread(row, 1, b->rowwidth, f) != b->rowwidth) return 1; - readrow(img, row, &img->buf[i]); + if(readrow(img, row, &img->buf[i])) + return 1; } return 0; -- cgit v1.2.3