X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_imagemagick%2Fmptr_imagemagick.cpp;h=921557f7a242aa01581b0406bfd865116722d54a;hb=6542407861e99a0ed76bd1ba9d03ca164ec7269b;hp=2481d066768719a3e506980a56d4d7560dd8b810;hpb=83224f8cf1f9b7b15918a130759717a5a375be91;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 2481d06..921557f 100644 --- a/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp +++ b/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp @@ -34,6 +34,20 @@ #include #include "mptr_imagemagick.h" #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 #include @@ -47,6 +61,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); @@ -77,11 +97,6 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog //#define HAS_LIBPNG 1 #if 1 - if(file) - pclose(file); - - string command; - if(filename.empty()) { if(cb)cb->error(_("No file to load")); @@ -90,19 +105,51 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog } 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()); - synfig::info("command=%s",command.c_str()); - if(system(command.c_str())!=0) return false; - Importer::Handle importer(Importer::open(temp_file)); +#elif defined(UNIX_PIPE_TO_PROCESSES) - DEBUGPOINT(); + 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) + execlp("convert", "convert", filename.c_str(), "-flatten", output.c_str(), (const char *)NULL); + else + execlp("convert", "convert", filename.c_str(), output.c_str(), (const char *)NULL); + // We should never reach here unless the exec failed + return false; + } + + int status; + waitpid(pid, &status, 0); + if( (WIFEXITED(status) && WEXITSTATUS(status) != 0) || !WIFEXITED(status) ) + return false; + +#else + #error There are no known APIs for creating child processes +#endif + + Importer::Handle importer(Importer::open(temp_file)); if(!importer) { @@ -111,8 +158,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); @@ -153,9 +198,7 @@ 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