Removed a bunch more DEBUGPOINT()s.
[synfig.git] / synfig-core / trunk / src / modules / mod_imagemagick / mptr_imagemagick.cpp
index 4d7ca20..4bcf1f8 100644 (file)
 #include "mptr_imagemagick.h"
 #include <stdio.h>
 #include <sys/types.h>
-#include <sys/wait.h>
+#if HAVE_SYS_WAIT_H
+ #include <sys/wait.h>
+#endif
+#if HAVE_IO_H
+ #include <io.h>
+#endif
+#if HAVE_PROCESS_H
+ #include <process.h>
+#endif
+#if HAVE_FCNTL_H
+ #include <fcntl.h>
+#endif
 #include <unistd.h>
 #include <algorithm>
 #include <functional>
@@ -50,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
+#elif defined(HAVE__SPAWNLP) && defined(HAVE__PIPE) && defined(HAVE_CWAIT)
+ #define WIN32_PIPE_TO_PROCESSES
+#endif
+
 /* === G L O B A L S ======================================================= */
 
 SYNFIG_IMPORTER_INIT(imagemagick_mptr);
@@ -89,6 +106,15 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::Prog
        string temp_file="/tmp/deleteme.png";
        string output="png32:"+temp_file;
 
+#if defined(WIN32_PIPE_TO_PROCESSES)
+
+       if(filename.find("psd")!=String::npos)
+               _spawnlp(_P_WAIT, "convert", "convert", filename.c_str(), "-flatten", output.c_str(), (const char *)NULL);
+       else
+               _spawnlp(_P_WAIT, "convert", "convert", filename.c_str(), output.c_str(), (const char *)NULL);
+
+#elif defined(UNIX_PIPE_TO_PROCESSES)
+
        pid_t pid = fork();
   
        if (pid == -1) {
@@ -110,9 +136,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 +149,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,9 +189,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