X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_png%2Fmptr_png.cpp;h=1b6c99bbceedc96f7625439c1f78dd0a91c297d9;hb=eef623cc49ddc319219d759e0472e54ce4b3f402;hp=ddf339dda2b2bed6557813f46f77318a21452ac3;hpb=5ddcf36f04cfbd10fabda4e3c5633cb27cdd4c0a;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 ddf339d..1b6c99b 100644 --- a/synfig-core/trunk/src/modules/mod_png/mptr_png.cpp +++ b/synfig-core/trunk/src/modules/mod_png/mptr_png.cpp @@ -1,9 +1,12 @@ -/*! ======================================================================== -** Synfig -** ppm Target Module -** $Id: mptr_png.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $ +/* === S Y N F I G ========================================================= */ +/*! \file mptr_png.cpp +** \brief ppm Target Module ** +** $Id$ +** +** \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 @@ -14,6 +17,7 @@ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** General Public License for more details. +** \endlegal ** ** === N O T E S =========================================================== ** @@ -59,12 +63,12 @@ SYNFIG_IMPORTER_INIT(png_mptr); SYNFIG_IMPORTER_SET_NAME(png_mptr,"png"); SYNFIG_IMPORTER_SET_EXT(png_mptr,"png"); SYNFIG_IMPORTER_SET_VERSION(png_mptr,"0.1"); -SYNFIG_IMPORTER_SET_CVS_ID(png_mptr,"$Id: mptr_png.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $"); +SYNFIG_IMPORTER_SET_CVS_ID(png_mptr,"$Id$"); /* === M E T H O D S ======================================================= */ void -png_mptr::png_out_error(png_struct *png_data,const char *msg) +png_mptr::png_out_error(png_struct */*png_data*/,const char *msg) { //png_mptr *me=(png_mptr*)png_data->error_ptr; synfig::error(strprintf("png_mptr: error: %s",msg)); @@ -72,7 +76,7 @@ png_mptr::png_out_error(png_struct *png_data,const char *msg) } void -png_mptr::png_out_warning(png_struct *png_data,const char *msg) +png_mptr::png_out_warning(png_struct */*png_data*/,const char *msg) { //png_mptr *me=(png_mptr*)png_data->error_ptr; synfig::warning(strprintf("png_mptr: warning: %s",msg)); @@ -80,7 +84,7 @@ png_mptr::png_out_warning(png_struct *png_data,const char *msg) } int -png_mptr::read_chunk_callback(png_struct *png_data, png_unknown_chunkp chunk) +png_mptr::read_chunk_callback(png_struct */*png_data*/, png_unknown_chunkp /*chunk*/) { /* The unknown chunk structure contains your chunk data: */ @@ -159,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)) { @@ -181,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); @@ -200,7 +224,6 @@ png_mptr::png_mptr(const char *file_name) switch(color_type) { case PNG_COLOR_TYPE_RGB: - DEBUGPOINT(); for(y=0;y