diff --git a/synfig-core/src/modules/mod_png/mptr_png.cpp b/synfig-core/src/modules/mod_png/mptr_png.cpp index 7248518..e87e738 100644 --- a/synfig-core/src/modules/mod_png/mptr_png.cpp +++ b/synfig-core/src/modules/mod_png/mptr_png.cpp @@ -69,6 +69,16 @@ SYNFIG_IMPORTER_SET_SUPPORTS_FILE_SYSTEM_WRAPPER(png_mptr, true); /* === M E T H O D S ======================================================= */ +namespace { + inline unsigned short get_channel(png_bytep *rows, int bit_depth, int row, int col) { + unsigned int x = bit_depth > 8 + ? ((unsigned short*)(rows[row]))[col] + : rows[row] [col]; + unsigned int max = (1 << bit_depth) - 1; + return (x*65536u - 1u)/max; + } +} + void png_mptr::png_out_error(png_struct */*png_data*/,const char *msg) { @@ -175,8 +185,11 @@ png_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); - if (bit_depth == 16) - png_set_strip_16(png_ptr); + if (bit_depth > 16) { + synfig::error("png_mptr: error: bit depth not supported: %d", bit_depth); + throw etl::strprintf("png_mptr: error: bit depth not supported: %d", bit_depth); + return false; + } if (bit_depth < 8) png_set_packing(png_ptr); @@ -227,23 +240,10 @@ png_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc for(y=0;y 8) { + synfig::error("png_mptr: error: bit depth with palette not supported: %d", bit_depth); + throw etl::strprintf("png_mptr: error: bit depth with palette not supported: %d", bit_depth); + return false; + } + png_colorp palette; + int num_palette; + png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); + png_bytep trans_alpha = NULL; + int num_trans = 0; + bool has_alpha = png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, NULL) + & PNG_INFO_tRNS; for(y=0;y