From 07e510dd35cfa682d29dfdbaf02bdf5f31073f2c Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 24 Jun 2008 19:22:56 -0700 Subject: cleanup --- src/bmp.c | 36 ++++++++++++++++++------------------ src/main.c | 4 ++-- src/png.c | 33 +++++++++++++++++---------------- 3 files changed, 37 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/bmp.c b/src/bmp.c index 89d9310..e071c15 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -4,22 +4,6 @@ #include "meh.h" -unsigned short getshort(FILE *f){ - unsigned short ret; - ret = getc(f); - ret = ret | (getc(f) << 8); - return ret; -} - -unsigned long getlong(FILE *f){ - unsigned short ret; - ret = getc(f); - ret = ret | (getc(f) << 8); - ret = ret | (getc(f) << 16); - ret = ret | (getc(f) << 24); - return ret; -} - struct rgb_t{ unsigned char r, g, b; }; @@ -34,6 +18,22 @@ struct bmp_t{ unsigned int rowwidth; }; +static unsigned short getshort(FILE *f){ + unsigned short ret; + ret = getc(f); + ret = ret | (getc(f) << 8); + return ret; +} + +static unsigned long getlong(FILE *f){ + unsigned short ret; + ret = getc(f); + ret = ret | (getc(f) << 8); + ret = ret | (getc(f) << 16); + ret = ret | (getc(f) << 24); + return ret; +} + struct image *bmp_open(FILE *f){ struct bmp_t *b; unsigned long headersize; @@ -103,7 +103,7 @@ struct image *bmp_open(FILE *f){ return (struct image *)b; } -void rgb16(unsigned char *buf, unsigned short c){ +static void rgb16(unsigned char *buf, unsigned short c){ int i; for(i = 0; i < 3; i++){ *buf++ = ((c >> (i * 5)) & 0x1f) << 3; @@ -170,7 +170,7 @@ int bmp_read(struct image *img){ return 0; } -struct imageformat gif = { +struct imageformat bmp = { bmp_open, bmp_read }; diff --git a/src/main.c b/src/main.c index 29df176..9a45508 100644 --- a/src/main.c +++ b/src/main.c @@ -17,10 +17,10 @@ extern Display *display; extern struct imageformat libjpeg; extern struct imageformat giflib; extern struct imageformat libpng; -extern struct imageformat gif; +extern struct imageformat bmp; struct imageformat *formats[] = { &libjpeg, - &gif, + &bmp, &libpng, &giflib, /* HACK! make gif last (uses read()) */ NULL diff --git a/src/png.c b/src/png.c index 47e4f0e..659e935 100644 --- a/src/png.c +++ b/src/png.c @@ -53,6 +53,23 @@ struct image *png_open(FILE *f){ png_init_io(p->png_ptr, f); png_read_info(p->png_ptr, p->info_ptr); + + p->img.width = png_get_image_width(p->png_ptr, p->info_ptr); + p->img.height = png_get_image_height(p->png_ptr, p->info_ptr); + + return (struct image *)p; +} + +int png_read(struct image *img){ + unsigned int y; + png_bytepp row_pointers; + struct png_t *p = (struct png_t *)img; + + if(setjmp(png_jmpbuf(p->png_ptr))){ + png_destroy_read_struct(&p->png_ptr, &p->info_ptr, &p->end_info); + return 1; + } + { int color_type = png_get_color_type(p->png_ptr, p->info_ptr); int bit_depth = png_get_bit_depth(p->png_ptr, p->info_ptr); @@ -74,22 +91,6 @@ struct image *png_open(FILE *f){ png_read_update_info(p->png_ptr, p->info_ptr); } - p->img.width = png_get_image_width(p->png_ptr, p->info_ptr); - p->img.height = png_get_image_height(p->png_ptr, p->info_ptr); - - return (struct image *)p; -} - -int png_read(struct image *img){ - unsigned int y; - png_bytepp row_pointers; - - struct png_t *p = (struct png_t *)img; - if(setjmp(png_jmpbuf(p->png_ptr))){ - png_destroy_read_struct(&p->png_ptr, &p->info_ptr, &p->end_info); - return 1; - } - row_pointers = (png_bytepp)malloc(img->height * sizeof(png_bytep)); for(y = 0; y < img->height; y++) row_pointers[y] = img->buf + y * img->width * 3; -- cgit v1.2.3