made imaging optional
authorkramm <kramm>
Wed, 12 Dec 2007 10:58:22 +0000 (10:58 +0000)
committerkramm <kramm>
Wed, 12 Dec 2007 10:58:22 +0000 (10:58 +0000)
lib/python/image.c
m4/python.m4

index f178255..5b125e6 100644 (file)
@@ -1,6 +1,12 @@
 #include <Python.h>
+#ifdef HAVE_STAT
+#undef HAVE_STAT
+#endif
 //#include "/usr/include/python2.3/Imaging.h"
+#include "../../config.h"
+#ifdef HAVE_PYTHON_IMAGING
 #include <Imaging.h>
+#endif
 #include "pyutils.h"
 #undef HAVE_STAT
 #include "../rfxswf.h"
 /* there should be a better way to do this... */
 typedef struct {
     PyObject_HEAD
+#ifdef HAVE_PYTHON_IMAGING
     Imaging image;
+#endif
 } ImagingObject;
 
 int image_getWidth(PyObject*_image) {
+#ifdef HAVE_PYTHON_IMAGING
     if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
        PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
        return 0;
     }
     ImagingObject*image = (ImagingObject*)_image;
     return image->image->xsize;
+#else
+    PyErr_SetString(PyExc_Exception, "imaging not compiled in");
+    return 0;
+#endif
 }
 
 int image_getHeight(PyObject*_image) {
+#ifdef HAVE_PYTHON_IMAGING
     if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
        PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
        return 0;
     }
     ImagingObject*image = (ImagingObject*)_image;
     return image->image->ysize;
+#else
+    PyErr_SetString(PyExc_Exception, "imaging not compiled in");
+    return 0;
+#endif
 }
 
 int image_getBPP(PyObject*_image) {
+#ifdef HAVE_PYTHON_IMAGING
     if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
        PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
        return 0;
@@ -53,10 +72,15 @@ int image_getBPP(PyObject*_image) {
     }
     PyErr_SetString(PyExc_Exception, setError("Unknown image format (%s).", image->image->mode));
     return 0;
+#else
+    PyErr_SetString(PyExc_Exception, "imaging not compiled in");
+    return 0;
+#endif
 }
 
 RGBA* image_toRGBA(PyObject*_image) 
 {
+#ifdef HAVE_PYTHON_IMAGING
     if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
        PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
        return 0;
@@ -92,13 +116,19 @@ RGBA* image_toRGBA(PyObject*_image)
     }
        
     PyErr_SetString(PyExc_Exception, setError("Unsupported image format: %s (try .convert(\"RGBA\")", image->image->mode));
+#else
+    PyErr_SetString(PyExc_Exception, "imaging not compiled in");
+#endif
     return 0;
 }
 
+#ifdef HAVE_PYTHON_IMAGING
 extern PyObject*PyImagingNew(Imaging imOut);
+#endif
 
 PyObject* rgba_to_image(RGBA*rgba, int width, int height)
 {
+#ifdef HAVE_PYTHON_IMAGING
 #ifndef WIN32
     Imaging img = ImagingNew("RGBA", width, height);
     int y;
@@ -123,4 +153,8 @@ PyObject* rgba_to_image(RGBA*rgba, int width, int height)
     fprintf(stderr, "This image extraction is not yet supported on non-linux systems\n");
     return 0;
 #endif
+#else
+    PyErr_SetString(PyExc_Exception, "imaging not compiled in");
+    return 0;
+#endif
 }
index 23deed7..c697728 100644 (file)
@@ -1,6 +1,6 @@
 AC_DEFUN(RFX_CHECK_PYTHON,
 [
-AC_MSG_CHECKING([for Python.h and PIL])
+AC_MSG_CHECKING([for Python.h])
 
 if test "x$PYTHON_LIB" '!=' "x" -a "x$PYTHON_INCLUDES" '!=' "x";then
     PY_VERSION=unknown
@@ -11,9 +11,15 @@ else
     # iterate through version 2.2 to 2.5
     for v in 2 3 4 5; do
         # Linux
-        if test -f "/usr/lib/python2.$v/site-packages/PIL/_imaging.so" -a -f "/usr/include/python2.$v/Python.h";then
+        if test -f "/usr/include/python2.$v/Python.h";then
             PY_VERSION=2.$v
-           PYTHON_LIB="-lpython$PY_VERSION /usr/lib/python$PY_VERSION/site-packages/PIL/_imaging.so"
+           PYTHON_LIB="-lpython$PY_VERSION"
+            if test -f "/usr/lib/python2.$v/site-packages/PIL/_imaging.so";then 
+                PYTHON_LIB2="$PYTHON_LIB /usr/lib/python2.$v/site-packages/PIL/_imaging.so"
+                HAVE_PYTHON_IMAGING_LIB=1
+            else
+                PYTHON_LIB2="$PYTHON_LIB"
+            fi
            PYTHON_INCLUDES="-I/usr/include/python$PY_VERSION"
         # Mac OS X
         elif test -f "/System/Library/Frameworks/Python.framework/Versions/2.$v/include/python2.$v/Python.h";then
@@ -22,6 +28,7 @@ else
             PYTHON_LIB="-framework Python" 
             if test -f "/Library/Python/2.$v/PIL/_imaging.so";then
                 PYTHON_LIB2="$PYTHON_LIB /Library/Python/2.$v/PIL/_imaging.so"
+                HAVE_PYTHON_IMAGING_LIB=1
             else
                 PYTHON_LIB2="$PYTHON_LIB"
             fi
@@ -31,10 +38,15 @@ else
                   -o -f "/sw/lib/python2.$v/config/libpython2.$v.a" \
                   -o -f "/sw/lib/python2.$v/config/libpython2.$v.so" \
                  ")" \
-              -a -f "/sw/include/python2.$v/Python.h" \
-               -a -f "/sw/lib/python2.$v/site-packages/PIL/_imaging.so";then
+              -a -f "/sw/include/python2.$v/Python.h"; then
             PY_VERSION=2.$v
             PYTHON_LIB="-L /sw/lib/python2.$v/config/ -lpython$PY_VERSION /sw/lib/python2.$v/site-packages/PIL/_imaging.so"
+            if test -f "/sw/lib/python2.$v/site-packages/PIL/_imaging.so";then
+                PYTHON_LIB2="$PYTHON_LIB /sw/lib/python2.$v/site-packages/PIL/_imaging.so"
+                HAVE_PYTHON_IMAGING_LIB=1
+            else
+                PYTHON_LIB2="$PYTHON_LIB"
+            fi
             PYTHON_INCLUDES="-I /sw/include/python2.$v/"
         fi
     done
@@ -49,7 +61,6 @@ if test "x$PY_VERSION" "!=" "x"; then
     
     cat > conftest.c << EOF
 #include <Python.h>
-#include <Imaging.h>
 
 int main()
 {
@@ -59,19 +70,45 @@ int main()
     return ret;
 }
 EOF
+    
     ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS $PYTHON_LIB $LIBS -o conftest${ac_exeext}'
     if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
        AC_MSG_RESULT(yes)
        PYTHON_OK=yes
     else
-        ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS ${PYTHON_LIB2} $LIBS -o conftest${ac_exeext}'
-        if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-            AC_MSG_RESULT(yes)
-            PYTHON_LIB="${PYTHON_LIB2}"
-            PYTHON_OK=yes
+        echo "configure: failed program was:" >&5
+        cat conftest.c >&5
+        AC_MSG_RESULT(no)
+    fi
+    rm -f conftest*
+    if test "x$PYTHON_OK" = "xyes";then
+        AC_MSG_CHECKING([for Python-Imaging])
+    cat > conftest.c << EOF
+#include <Python.h>
+#include <Imaging.h>
+
+int main()
+{
+    Py_Main(0, 0);
+    return 0;
+}
+EOF
+        if test "$HAVE_PYTHON_IMAGING_LIB"; then
+            ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS ${PYTHON_LIB2} $LIBS -o conftest${ac_exeext}'
+            if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+                PYTHON_LIB="${PYTHON_LIB2}"
+                AC_DEFINE_UNQUOTED(HAVE_PYTHON_IMAGING, 1)
+                HAVE_PYTHON_IMAGING=yes
+                export HAVE_PYTHON_IMAGING
+                AC_SUBST(HAVE_PYTHON_IMAGING)
+                AC_MSG_RESULT(yes)
+            else
+                echo "configure: failed program was:" >&5
+                cat conftest.c >&5
+                AC_MSG_RESULT(no)
+            fi
         else
-            echo "configure: failed program was:" >&5
-            cat conftest.c >&5
+            echo "(didn't find the Python-Imaging libraries)" >&5
             AC_MSG_RESULT(no)
         fi
     fi