diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-22 01:34:45 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-22 01:34:45 -0700 |
commit | 292cf3ee0494b14e6f82df755ae02b2f078afc35 (patch) | |
tree | 624dd892b6d44e85131a5a192eb3093ebc1e0428 /src/bmp.c | |
parent | 12fe3f62f2931f296beb130840c091542647319b (diff) | |
download | mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.tar.gz mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.tar.bz2 mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.zip |
cleanup
Diffstat (limited to 'src/bmp.c')
-rw-r--r-- | src/bmp.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -112,8 +112,7 @@ void rgb16(unsigned char *buf, unsigned short c){ 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; + unsigned int x, i = 0; if(b->bpp == 24 || b->bpp == 32){ for(x = 0; x < img->width * 3; x+=3){ buf[x + 2] = row[i++]; @@ -149,21 +148,25 @@ static int readrow(struct image *img, unsigned char *row, unsigned char *buf){ int bmp_read(struct image *img){ struct bmp_t *b = (struct bmp_t *)img; + unsigned int i, y; + unsigned int dy; + unsigned char *row; FILE *f = img->f; - fseek(f, b->bitmapoffset, SEEK_SET); - int i, y; - int dy = img->width * 3; + row = malloc(b->rowwidth); + dy = img->width * 3; i = img->height * dy; - unsigned char row[b->rowwidth]; + + fseek(f, b->bitmapoffset, SEEK_SET); for(y = img->height; y; y--){ i -= dy; - if(fread(row, 1, b->rowwidth, f) != b->rowwidth) - return 1; - if(readrow(img, row, &img->buf[i])) + if(fread(row, 1, b->rowwidth, f) != b->rowwidth || readrow(img, row, &img->buf[i])){ + free(row); return 1; + } } + free(row); return 0; } |