From: Christophe CURIS <christophe.cu...@free.fr> - renamed compilation flags variable with a name less prone to clash
- fixed Makefile to use these flags for compilation+link - removed IM_MAGICK from the internal list of image formats: it is not a file format, and in the current implementation it is anyway used for IM_UNKNOWN - fixed the prototype for RShutdown (and moved it closed to the beginning of the file (better visibility to increase chance for the function to be seen by wrlib users, until we have a doc someday) - moved the RShutdown to the more generic file 'misc.c' because the function could do more things someday, not related to loading - fixed potential crash, if loading with Magick fails it could return a pointer to a de-allocated area - changed a comparison to 'MagickTrue' because its value does not allow a compiler optimisation that would be expected in present case - changed header used for MagickWand to the one specified in the online documentation and a few minor code aspect changes --- configure.ac | 18 ++++++++++++------ m4/wm_imgfmt_check.m4 | 1 + wrlib/Makefile.am | 5 +++-- wrlib/imgformat.h | 9 +++++---- wrlib/load.c | 9 +-------- wrlib/load_magick.c | 25 ++++++++++++++----------- wrlib/misc.c | 12 ++++++++++++ wrlib/wraster.h | 9 +++++---- 8 files changed, 53 insertions(+), 35 deletions(-) diff --git a/configure.ac b/configure.ac index b55ea85..0d895fb 100644 --- a/configure.ac +++ b/configure.ac @@ -322,11 +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 ======= @@ -564,26 +566,28 @@ else fi AC_SUBST(FCLIBS) + dnl dnl libMagickWand dnl AC_MSG_CHECKING([for libmagickwand header]) -IMFLAGS=`$MAGICKWCONFIG --cflags` -if test "x$IMFLAGS" = "x" ; then +MAGICKFLAGS=`$MAGICKWCONFIG --cflags` +if test "x$MAGICKFLAGS" = "x" ; then AC_MSG_RESULT([not found]) else AC_MSG_RESULT([found]) fi -AC_SUBST(IMFLAGS) +AC_SUBST([MAGICKFLAGS]) AC_MSG_CHECKING([for libmagickwand library]) -IMLIBS=`$MAGICKWCONFIG --ldflags` -if test "x$IMLIBS" = "x" ; then +MAGICKLIBS=`$MAGICKWCONFIG --ldflags` +if test "x$MAGICKLIBS" = "x" ; then AC_MSG_RESULT([not found]) else AC_MSG_RESULT([found]) fi -AC_SUBST(IMLIBS) +AC_SUBST([MAGICKLIBS]) + dnl Xft2 antialiased font support dnl ============================= @@ -714,6 +718,7 @@ AC_ARG_ENABLE([webp], [enable_webp=auto]) WM_IMGFMT_CHECK_WEBP + dnl MAGICK Support dnl =========== AC_ARG_ENABLE([magick], @@ -724,6 +729,7 @@ AC_ARG_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 535a1c5..5ba246a 100644 --- a/m4/wm_imgfmt_check.m4 +++ b/m4/wm_imgfmt_check.m4 @@ -245,6 +245,7 @@ AS_IF([test "x$enable_xpm" = "xno"], AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl ]) dnl AC_DEFUN + # WM_IMGFMT_CHECK_MAGICK # ------------------- # diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am index daf4a1f..d88ecc6 100644 --- a/wrlib/Makefile.am +++ b/wrlib/Makefile.am @@ -68,9 +68,10 @@ 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 @@ -83,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 0a44009..004da30 100644 --- a/wrlib/imgformat.h +++ b/wrlib/imgformat.h @@ -39,13 +39,12 @@ typedef enum { IM_PPM = 4, IM_JPEG = 5, IM_GIF = 6, - IM_WEBP = 7, - IM_MAGICK = 8 + IM_WEBP = 7 } WRImgFormat; /* How many image types we have. */ /* Increase this when adding new image types! */ -#define IM_TYPES 8 +#define IM_TYPES 7 /* * Function for Loading in a specific format @@ -76,7 +75,9 @@ RImage *RLoadWEBP(const char *file); #ifdef USE_MAGICK RImage *RLoadMagick(const char *file_name); - #endif + +void RReleaseMagick(void); +#endif /* * Function for Saving in a specific format diff --git a/wrlib/load.c b/wrlib/load.c index 477e92d..4475070 100644 --- a/wrlib/load.c +++ b/wrlib/load.c @@ -103,13 +103,6 @@ char **RSupportedFileFormats(void) return tmp; } -/* cleaning third-party libs at shutdown */ -void RShutdown() { -#ifdef USE_MAGICK - MagickWandTerminus(); -#endif -} - static void init_cache(void) { char *tmp; @@ -175,7 +168,7 @@ RImage *RLoadImage(RContext * context, const char *file, int index) #ifdef USE_MAGICK /* generic file format support using ImageMagick * BMP, PCX, PICT, SVG, ... - */ + */ image = RLoadMagick(file); break; #else diff --git a/wrlib/load_magick.c b/wrlib/load_magick.c index d9ecb2d..e3f325c 100644 --- a/wrlib/load_magick.c +++ b/wrlib/load_magick.c @@ -20,15 +20,15 @@ * MA 02110-1301, USA. */ -#include <config.h> -#include <X11/Xlib.h> +#include "config.h" -#include <wand/magick_wand.h> +#include <wand/MagickWand.h> #include "wraster.h" #include "imgformat.h" -RImage * RLoadMagick(const char *file_name) + +RImage *RLoadMagick(const char *file_name) { RImage *image = NULL; unsigned char *ptr; @@ -44,7 +44,7 @@ RImage * RLoadMagick(const char *file_name) m_wand = NewMagickWand(); /* set the default background as transparent */ - bg_wand = NewPixelWand (); + bg_wand = NewPixelWand(); PixelSetColor(bg_wand, "none"); MagickSetBackgroundColor(m_wand, bg_wand); @@ -56,7 +56,6 @@ RImage * RLoadMagick(const char *file_name) w = MagickGetImageWidth(m_wand); h = MagickGetImageHeight(m_wand); - //fprintf(stderr, "%lu x %lu\n", w,h); hasAlfa = MagickGetImageAlphaChannel(m_wand); @@ -67,14 +66,15 @@ RImage * RLoadMagick(const char *file_name) } ptr = image->data; - if (hasAlfa == MagickTrue) - mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, (size_t)h, "RGBA", CharPixel, ptr); - else + 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; } @@ -82,8 +82,11 @@ bye: /* Tidy up */ MagickClearException(m_wand); m_wand = DestroyMagickWand(m_wand); - /* destroy is called when exiting wmaker */ - /* MagickWandTerminus(); */ 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 c4ed231..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. @@ -431,11 +436,7 @@ RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, RImage *RRenderInterwovenGradient(unsigned width, unsigned height, RColor colors1[2], int thickness1, RColor colors2[2], int thickness2); -/* - * Cleaning - */ -void RShutdown(); /* * Convertion into X Pixmaps -- 1.9.1 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.