diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-18 16:26:41 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-18 16:26:41 -0700 |
commit | 12fe3f62f2931f296beb130840c091542647319b (patch) | |
tree | 7e9ba353323e821a4fe819461c11fdf17ee75a21 | |
parent | 6b71109ebaf8d9b5734e14303a53782f70d955e8 (diff) | |
download | mirror-meh-12fe3f62f2931f296beb130840c091542647319b.tar.gz mirror-meh-12fe3f62f2931f296beb130840c091542647319b.tar.bz2 mirror-meh-12fe3f62f2931f296beb130840c091542647319b.zip |
support for 16 and 32 bit bitmaps
-rw-r--r-- | src/bmp.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -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; |