X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_imagemagick%2Fmptr_imagemagick.cpp;h=2860c1f97434413f6e4689fce916294cff52aa4f;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=4d7ca2063f8ad7c795520f7060e79279afdacd03;hpb=37aab4b94303b25f08338f1f2bb40395a487bf02;p=synfig.git diff --git a/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp b/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp index 4d7ca20..2860c1f 100644 --- a/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp +++ b/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.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 @@ -35,7 +36,18 @@ #include "mptr_imagemagick.h" #include #include -#include +#if HAVE_SYS_WAIT_H + #include +#endif +#if HAVE_IO_H + #include +#endif +#if HAVE_PROCESS_H + #include +#endif +#if HAVE_FCNTL_H + #include +#endif #include #include #include @@ -50,6 +62,12 @@ using namespace synfig; using namespace std; using namespace etl; +#if defined(HAVE_FORK) && defined(HAVE_PIPE) && defined(HAVE_WAITPID) + #define UNIX_PIPE_TO_PROCESSES +#else + #define WIN32_PIPE_TO_PROCESSES +#endif + /* === G L O B A L S ======================================================= */ SYNFIG_IMPORTER_INIT(imagemagick_mptr); @@ -87,14 +105,32 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog return false; } string temp_file="/tmp/deleteme.png"; + +#if defined(WIN32_PIPE_TO_PROCESSES) + + if(file) + pclose(file); + + string command; + + if(filename.find("psd")!=String::npos) + command=strprintf("convert \"%s\" -flatten \"png32:%s\"\n",filename.c_str(),temp_file.c_str()); + else + command=strprintf("convert \"%s\" \"png32:%s\"\n",filename.c_str(),temp_file.c_str()); + + if(system(command.c_str())!=0) + return false; + +#elif defined(UNIX_PIPE_TO_PROCESSES) + string output="png32:"+temp_file; pid_t pid = fork(); - + if (pid == -1) { return false; } - + if (pid == 0){ // Child process if(filename.find("psd")!=String::npos) @@ -110,9 +146,11 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog if( (WIFEXITED(status) && WEXITSTATUS(status) != 0) || !WIFEXITED(status) ) return false; - Importer::Handle importer(Importer::open(temp_file)); +#else + #error There are no known APIs for creating child processes +#endif - DEBUGPOINT(); + Importer::Handle importer(Importer::open(temp_file)); if(!importer) { @@ -121,8 +159,6 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog return false; } - DEBUGPOINT(); - if(!importer->get_frame(surface,0,cb)) { if(cb)cb->error(_("Unable to get frame from ")+temp_file); @@ -163,15 +199,13 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog Surface bleh(surface); surface=bleh; - //remove(temp_file.c_str()); - DEBUGPOINT(); return true; #else - + #error This code contains tempfile and arbitrary shell command execution vulnerabilities - + if(file) pclose(file);