From: David Maciejak <david.macie...@gmail.com>

It uses to provide some missing common image format
like SVG, BMP, PICT, ...
---
 configure.ac          | 40 ++++++++++++++++++++++
 m4/wm_imgfmt_check.m4 | 21 ++++++++++++
 src/dialog.c          |  4 +++
 src/main.c            |  1 +
 wrlib/Makefile.am     |  9 +++--
 wrlib/imgformat.h     |  6 ++++
 wrlib/libwraster.map  |  1 +
 wrlib/load.c          |  8 +++++
 wrlib/load_magick.c   | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++
 wrlib/misc.c          | 12 +++++++
 wrlib/wraster.h       |  5 +++
 11 files changed, 197 insertions(+), 2 deletions(-)
 create mode 100644 wrlib/load_magick.c

diff --git a/configure.ac b/configure.ac
index f0bebec..0d895fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -322,6 +322,13 @@ dnl ==========
 dnl AC_ARG_VAR(PKGCONFIG, [pkg-config command])
 AC_CHECK_PROG(PKGCONFIG, pkg-config, pkg-config) 
 
+
+dnl MagickWand-config
+dnl ==========
+dnl AC_ARG_VAR(MAGICKWCONFIG, [MagickWand-config command])
+AC_CHECK_PROG(MAGICKWCONFIG, MagickWand-config, MagickWand-config)
+
+
 dnl gettext
 dnl =======
 
@@ -560,6 +567,28 @@ fi
 AC_SUBST(FCLIBS)
 
 
+dnl
+dnl libMagickWand
+dnl
+AC_MSG_CHECKING([for libmagickwand header])
+MAGICKFLAGS=`$MAGICKWCONFIG --cflags`
+if test "x$MAGICKFLAGS" = "x" ; then
+        AC_MSG_RESULT([not found])
+else
+        AC_MSG_RESULT([found])
+fi
+AC_SUBST([MAGICKFLAGS])
+
+AC_MSG_CHECKING([for libmagickwand library])
+MAGICKLIBS=`$MAGICKWCONFIG --ldflags`
+if test "x$MAGICKLIBS" = "x" ; then
+        AC_MSG_RESULT([not found])
+else
+        AC_MSG_RESULT([found])
+fi
+AC_SUBST([MAGICKLIBS])
+
+
 dnl Xft2 antialiased font support
 dnl =============================
 
@@ -690,6 +719,17 @@ AC_ARG_ENABLE([webp],
 WM_IMGFMT_CHECK_WEBP
 
 
+dnl MAGICK Support
+dnl ===========
+AC_ARG_ENABLE([magick],
+    [AS_HELP_STRING([--disable-magick], [disable MAGICK support through 
libMagickWand])],
+    [AS_CASE(["$enableval"],
+        [yes|no], [],
+        [AC_MSG_ERROR([bad value $enableval for --enable-magick])] )],
+    [enable_magick=auto])
+WM_IMGFMT_CHECK_MAGICK
+
+
 dnl PPM Support
 dnl ===========
 # The PPM format is always enabled because we have built-in support for the 
format
diff --git a/m4/wm_imgfmt_check.m4 b/m4/wm_imgfmt_check.m4
index ad37993..5ba246a 100644
--- a/m4/wm_imgfmt_check.m4
+++ b/m4/wm_imgfmt_check.m4
@@ -244,3 +244,24 @@ AS_IF([test "x$enable_xpm" = "xno"],
     ])
 AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl
 ]) dnl AC_DEFUN
+
+
+# WM_IMGFMT_CHECK_MAGICK
+# -------------------
+#
+# Check for MAGICK file support through 'libMagickWand'
+# The check depends on variable 'enable_magick' being either:
+#   yes  - detect, fail if not found
+#   no   - do not detect, disable support
+#   auto - detect, disable if not found
+#
+# When not found, append info to variable 'unsupported'
+AC_DEFUN_ONCE([WM_IMGFMT_CHECK_MAGICK],
+[WM_LIB_CHECK([MAGICK], ["$IMLIBS"], [MagickGetImagePixels], [$XLFLAGS $XLIBS],
+    [wm_save_CFLAGS="$CFLAGS $IMFLAGS"
+     AS_IF([wm_fn_lib_try_compile "wand/magick_wand.h" "" "return 0" ""],
+         [],
+         [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header 
- are you missing libmagickwand package?])])
+     CFLAGS="$wm_save_CFLAGS"],
+    [supported_gfx], [GFXLIBS])dnl
+]) dnl AC_DEFUN
diff --git a/src/dialog.c b/src/dialog.c
index 637032c..dc46263 100644
--- a/src/dialog.c
+++ b/src/dialog.c
@@ -1305,6 +1305,10 @@ void wShowInfoPanel(WScreen *scr)
        strbuf = wstrappend(strbuf, ", MWM");
 #endif
 
+#ifdef USE_MAGICK
+       strbuf = wstrappend(strbuf, ", ImageMagick");
+#endif
+
 #ifdef USE_XINERAMA
        strbuf = wstrappend(strbuf, _("\n"));
 #ifdef SOLARIS_XINERAMA
diff --git a/src/main.c b/src/main.c
index a21290e..bc14721 100644
--- a/src/main.c
+++ b/src/main.c
@@ -201,6 +201,7 @@ noreturn void Exit(int status)
        if (dpy)
                XCloseDisplay(dpy);
 
+       RShutdown(); /* wrlib clean exit */
        wutil_shutdown();  /* WUtil clean-up */
 
        exit(status);
diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am
index 48af352..d88ecc6 100644
--- a/wrlib/Makefile.am
+++ b/wrlib/Makefile.am
@@ -64,9 +64,14 @@ if USE_WEBP
 libwraster_la_SOURCES += load_webp.c
 endif
 
+if USE_MAGICK
+libwraster_la_SOURCES += load_magick.c
+endif
+
+AM_CFLAGS = @MAGICKFLAGS@
 AM_CPPFLAGS = $(DFLAGS) @HEADER_SEARCH_PATH@
 
-libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @XLIBS@ @LIBXMU@ -lm
+libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @MAGICKLIBS@ @XLIBS@ 
@LIBXMU@ -lm
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = wrlib.pc
@@ -79,7 +84,7 @@ wrlib.pc: Makefile
        @echo 'Description: Image manipulation and conversion library' >> $@
        @echo 'Version: $(VERSION)' >> $@
        @echo 'Libs: $(lib_search_path) -lwraster' >> $@
-       @echo 'Libs.private: $(GFXLIBS) $(XLIBS) -lm' >> $@
+       @echo 'Libs.private: $(GFXLIBS) $(MAGICKLIBS) $(XLIBS) -lm' >> $@
        @echo 'Cflags: $(inc_search_path)' >> $@
 
 get-wraster-flags: get-wraster-flags.in Makefile
diff --git a/wrlib/imgformat.h b/wrlib/imgformat.h
index 43df3ec..004da30 100644
--- a/wrlib/imgformat.h
+++ b/wrlib/imgformat.h
@@ -73,6 +73,12 @@ RImage *RLoadGIF(const char *file, int index);
 RImage *RLoadWEBP(const char *file);
 #endif
 
+#ifdef USE_MAGICK
+RImage *RLoadMagick(const char *file_name);
+
+void RReleaseMagick(void);
+#endif
+
 /*
  * Function for Saving in a specific format
  */
diff --git a/wrlib/libwraster.map b/wrlib/libwraster.map
index 6282e2c..6e165ef 100644
--- a/wrlib/libwraster.map
+++ b/wrlib/libwraster.map
@@ -72,6 +72,7 @@ LIBWRASTER3
     RRotateImage;
     RSaveImage;
     RScaleImage;
+    RShutdown;
     RSmoothScaleImage;
     RSupportedFileFormats;
 
diff --git a/wrlib/load.c b/wrlib/load.c
index 641cfae..4475070 100644
--- a/wrlib/load.c
+++ b/wrlib/load.c
@@ -165,8 +165,16 @@ RImage *RLoadImage(RContext * context, const char *file, 
int index)
                return NULL;
 
        case IM_UNKNOWN:
+#ifdef USE_MAGICK
+               /* generic file format support using ImageMagick
+                * BMP, PCX, PICT, SVG, ...
+                */
+               image = RLoadMagick(file);
+               break;
+#else
                RErrorCode = RERR_BADFORMAT;
                return NULL;
+#endif
 
        case IM_XPM:
                image = RLoadXPM(context, file);
diff --git a/wrlib/load_magick.c b/wrlib/load_magick.c
new file mode 100644
index 0000000..e3f325c
--- /dev/null
+++ b/wrlib/load_magick.c
@@ -0,0 +1,92 @@
+/* load_magick.c - load image file using ImageMagick
+ *
+ * Raster graphics library
+ *
+ * Copyright (c) 2014 Window Maker Team
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <wand/MagickWand.h>
+
+#include "wraster.h"
+#include "imgformat.h"
+
+
+RImage *RLoadMagick(const char *file_name)
+{
+       RImage *image = NULL;
+       unsigned char *ptr;
+       unsigned long w,h;
+       MagickWand *m_wand = NULL;
+       MagickBooleanType mrc;
+       MagickBooleanType hasAlfa;
+       PixelWand *bg_wand = NULL;
+
+       MagickWandGenesis();
+
+       /* Create a wand */
+       m_wand = NewMagickWand();
+
+       /* set the default background as transparent */
+       bg_wand = NewPixelWand();
+       PixelSetColor(bg_wand, "none");
+       MagickSetBackgroundColor(m_wand, bg_wand);
+
+       /* Read the input image */
+       if (!MagickReadImage(m_wand, file_name)) {
+               RErrorCode = RERR_BADIMAGEFILE;
+               goto bye;
+       }
+
+       w = MagickGetImageWidth(m_wand);
+       h = MagickGetImageHeight(m_wand);
+
+       hasAlfa = MagickGetImageAlphaChannel(m_wand);
+
+       image = RCreateImage(w, h, (unsigned int) hasAlfa);
+       if (!image) {
+               RErrorCode = RERR_NOMEMORY;
+               goto bye;
+       }
+
+       ptr = image->data;
+       if (hasAlfa == MagickFalse)
+               mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, 
(size_t)h, "RGB", CharPixel, ptr);
+       else
+               mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, 
(size_t)h, "RGBA", CharPixel, ptr);
+
+       if (mrc == MagickFalse) {
+               RErrorCode = RERR_BADIMAGEFILE;
+               RReleaseImage(image);
+               image = NULL;
+               goto bye;
+       }
+
+bye:
+       /* Tidy up */
+       MagickClearException(m_wand);
+       m_wand = DestroyMagickWand(m_wand);
+
+       return image;
+}
+
+void RReleaseMagick(void)
+{
+       MagickWandTerminus();
+}
diff --git a/wrlib/misc.c b/wrlib/misc.c
index 4a7c065..00a7c57 100644
--- a/wrlib/misc.c
+++ b/wrlib/misc.c
@@ -26,6 +26,8 @@
 #include <X11/Xlib.h>
 
 #include "wraster.h"
+#include "imgformat.h"
+
 
 void RBevelImage(RImage * image, int bevel_type)
 {
@@ -240,3 +242,13 @@ const char *RMessageForError(int errorCode)
                return "internal error";
        }
 }
+
+/*
+ * cleaning third-party libs at shutdown
+ */
+void RShutdown(void)
+{
+#ifdef USE_MAGICK
+       RReleaseMagick();
+#endif
+}
diff --git a/wrlib/wraster.h b/wrlib/wraster.h
index 25e39e7..88f3a72 100644
--- a/wrlib/wraster.h
+++ b/wrlib/wraster.h
@@ -290,6 +290,11 @@ enum {
 
 
 /*
+ * Cleaning before application exit
+ */
+void RShutdown(void);
+
+/*
  * Returns a NULL terminated array of strings containing the
  * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
  * Do not free the returned data.
-- 
1.9.1


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to