X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_png%2Fmptr_png.cpp;h=19f82f35880b1edb0b9203134103fbfd1bb82d47;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=b36266b9ac6d90690d2f0c8d9eb6f58857be0bde;hpb=27ef4606cc033aa4790395079ed4a6f44de567f0;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 b36266b..19f82f3 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 @@ -216,16 +217,14 @@ png_mptr::png_mptr(const char *file_name) png_read_image(png_ptr, row_pointers); - int x; - int y; + png_uint_32 x, y; surface_buffer.set_wh(width,height); switch(color_type) { case PNG_COLOR_TYPE_RGB: - DEBUGPOINT(); - for(y=0;ypalette[row_pointers[y][x]].red); float g=gamma().g_U8_to_F32((unsigned char)png_ptr->palette[row_pointers[y][x]].green); float b=gamma().b_U8_to_F32((unsigned char)png_ptr->palette[row_pointers[y][x]].blue); + float a=1.0; + if(info_ptr->valid & PNG_INFO_tRNS) + a = (float)(unsigned char)png_ptr->trans[row_pointers[y][x]]*(1.0/255.0); surface_buffer[y][x]=Color( r, g, b, - 1.0 + a ); } break; @@ -325,29 +325,107 @@ png_mptr::png_mptr(const char *file_name) return; } - DEBUGPOINT(); - - // \fixme These shouldn't be uncommented, but for some - // reason, they crash the program. I will have to look into this - // later. This is a memory leak, but it shouldn't be too bad. - png_read_end(png_ptr, end_info); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(file); delete [] row_pointers; delete [] data; + + trim = false; + + if (getenv("SYNFIG_DISABLE_CROP_IMPORTED_IMAGES")) + return; + + switch(color_type) + { + case PNG_COLOR_TYPE_RGB_ALPHA: + case PNG_COLOR_TYPE_GRAY_ALPHA: + case PNG_COLOR_TYPE_PALETTE: + for(y=0;yBORDER) min_y = y-BORDER; else min_y = 0; + + for(y=height-1;y>0;y--) + { + for(x=0;xBORDER) min_x = x-BORDER; else min_x = 0; + + for(x=width-1;x>0;x--) + { + for(y=0;y