diff options
-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; |