aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-18 16:26:41 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-18 16:26:41 -0700
commit12fe3f62f2931f296beb130840c091542647319b (patch)
tree7e9ba353323e821a4fe819461c11fdf17ee75a21
parent6b71109ebaf8d9b5734e14303a53782f70d955e8 (diff)
downloadmirror-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.c22
1 files changed, 19 insertions, 3 deletions
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;