X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_png%2Fmptr_png.cpp;h=a0b021a7a5d68dbc35bf0888c709d957e1a48a80;hb=7d00f13f8a31e4a329736180412bf76af666f4f5;hp=94c036c89b0907cc8dda177b03842c9c4009620e;hpb=0b7b0f0bcd16daf2d31a1bdec0e76c132bda801f;p=synfig.git diff --git a/synfig-core/trunk/src/modules/mod_png/mptr_png.cpp b/synfig-core/trunk/src/modules/mod_png/mptr_png.cpp index 94c036c..a0b021a 100644 --- a/synfig-core/trunk/src/modules/mod_png/mptr_png.cpp +++ b/synfig-core/trunk/src/modules/mod_png/mptr_png.cpp @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -162,6 +163,21 @@ png_mptr::png_mptr(const char *file_name) png_init_io(png_ptr, file); png_set_sig_bytes(png_ptr,PNG_CHECK_BYTES); + png_read_info(png_ptr, info_ptr); + + int bit_depth,color_type,interlace_type, compression_type,filter_method; + png_uint_32 width,height; + + png_get_IHDR(png_ptr, info_ptr, &width, &height, + &bit_depth, &color_type, &interlace_type, + &compression_type, &filter_method); + + if (bit_depth == 16) + png_set_strip_16(png_ptr); + + if (bit_depth < 8) + png_set_packing(png_ptr); + double fgamma; if (png_get_gAMA(png_ptr, info_ptr, &fgamma)) { @@ -184,18 +200,23 @@ png_mptr::png_mptr(const char *file_name) png_set_read_user_chunk_fn(png_ptr, this, &png_mptr::read_chunk_callback); + // man libpng tells me: + // You must use png_transforms and not call any + // png_set_transform() functions when you use png_read_png(). + // but we used png_set_gamma(), which may be why we were seeing a crash at the end + // png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_PACKING|PNG_TRANSFORM_STRIP_16, NULL); - png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_PACKING|PNG_TRANSFORM_STRIP_16, NULL); + png_read_update_info(png_ptr, info_ptr); + png_uint_32 rowbytes = png_get_rowbytes(png_ptr, info_ptr); - int bit_depth,color_type,interlace_type, compression_type,filter_method; - png_uint_32 width,height; + // allocate buffer to read image data into + png_bytep *row_pointers=new png_bytep[height]; + png_byte *data = new png_byte[rowbytes*height]; + for (png_uint_32 i = 0; i < height; i++) + row_pointers[i] = &(data[rowbytes*i]); - png_get_IHDR(png_ptr, info_ptr, &width, &height, - &bit_depth, &color_type, &interlace_type, - &compression_type, &filter_method); + png_read_image(png_ptr, row_pointers); - png_bytep *row_pointers=new png_bytep[height]; - row_pointers = png_get_rows(png_ptr, info_ptr); int x; int y; surface_buffer.set_wh(width,height); @@ -203,7 +224,6 @@ png_mptr::png_mptr(const char *file_name) switch(color_type) { case PNG_COLOR_TYPE_RGB: - DEBUGPOINT(); for(y=0;y