aboutsummaryrefslogtreecommitdiffstats
path: root/src/png.c
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-22 01:34:45 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-22 01:34:45 -0700
commit292cf3ee0494b14e6f82df755ae02b2f078afc35 (patch)
tree624dd892b6d44e85131a5a192eb3093ebc1e0428 /src/png.c
parent12fe3f62f2931f296beb130840c091542647319b (diff)
downloadmirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.tar.gz
mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.tar.bz2
mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.zip
cleanup
Diffstat (limited to 'src/png.c')
-rw-r--r--src/png.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/png.c b/src/png.c
index bd461c5..f10ba64 100644
--- a/src/png.c
+++ b/src/png.c
@@ -13,8 +13,23 @@ struct png_t{
int numpasses;
};
+static unsigned char png_head[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
+
+static int ispng(FILE *f){
+ unsigned char buf[8];
+ if(fread(buf, 1, 8, f) != 8)
+ return 0;
+ return !memcmp(buf, png_head, 8);
+}
+
struct image *png_open(FILE *f){
- struct png_t *p = malloc(sizeof(struct png_t));
+ struct png_t *p;
+
+ rewind(f);
+ if(!ispng(f))
+ return NULL;
+
+ p = malloc(sizeof(struct png_t));
if((p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)) == NULL){
free(p);
return NULL;
@@ -68,15 +83,16 @@ struct image *png_open(FILE *f){
}
int png_read(struct image *img){
+ unsigned int y;
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 y;
while(p->numpasses--){
- for(y = 0; y < img->height; y++)
- png_read_row(p->png_ptr, &img->buf[y * (img->width) * 3], NULL);
+ for(y = 0; y < img->height; y++){
+ png_read_row(p->png_ptr, &img->buf[y * img->width * 3], NULL);
+ }
}
png_destroy_read_struct(&p->png_ptr, &p->info_ptr, &p->end_info);
return 0;