diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-23 20:17:11 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-23 20:17:11 -0700 |
commit | 97c9966422d672c28aac39bb0ef6e5fb1c3fd3e1 (patch) | |
tree | e2a2ca5fe9c024919ce1f27c889585a2d11d2962 /src | |
parent | 292cf3ee0494b14e6f82df755ae02b2f078afc35 (diff) | |
download | mirror-meh-97c9966422d672c28aac39bb0ef6e5fb1c3fd3e1.tar.gz mirror-meh-97c9966422d672c28aac39bb0ef6e5fb1c3fd3e1.tar.bz2 mirror-meh-97c9966422d672c28aac39bb0ef6e5fb1c3fd3e1.zip |
fixed png
Diffstat (limited to 'src')
-rw-r--r-- | src/png.c | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -13,13 +13,11 @@ 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); + return png_check_sig(buf, 8); } struct image *png_open(FILE *f){ @@ -56,19 +54,19 @@ struct image *png_open(FILE *f){ png_read_info(p->png_ptr, p->info_ptr); { - png_byte color_type = png_get_color_type(p->png_ptr, p->info_ptr); - if(color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(p->png_ptr); - if(color_type == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(p->png_ptr, p->info_ptr) < 8) - png_set_gray_1_2_4_to_8(p->png_ptr); + 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); + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(p->png_ptr); + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand(p->png_ptr); if (png_get_valid(p->png_ptr, p->info_ptr, PNG_INFO_tRNS)) - png_set_tRNS_to_alpha(p->png_ptr); - if (png_get_bit_depth(p->png_ptr, p->info_ptr) == 16) + png_set_expand(p->png_ptr); + if (bit_depth == 16) png_set_strip_16(p->png_ptr); - if(color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(p->png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(p->png_ptr); + png_set_strip_alpha(p->png_ptr); if(png_get_interlace_type(p->png_ptr, p->info_ptr) == PNG_INTERLACE_ADAM7) p->numpasses = png_set_interlace_handling(p->png_ptr); else @@ -84,16 +82,20 @@ struct image *png_open(FILE *f){ 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; } - while(p->numpasses--){ - for(y = 0; y < img->height; y++){ - png_read_row(p->png_ptr, &img->buf[y * img->width * 3], NULL); - } - } + + 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; + + png_read_image(p->png_ptr, row_pointers); + png_destroy_read_struct(&p->png_ptr, &p->info_ptr, &p->end_info); return 0; } |