Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add imagemagick support to Windows version emacs
--- ./lisp/loadup.el.orig 2018-01-09 05:23:57.000000000 +0900
+++ ./lisp/loadup.el 2018-04-10 23:10:38.764782700 +0900
@@ -284,6 +284,7 @@
(load "term/w32-win")
(load "disp-table")
(when (eq system-type 'windows-nt)
+ (load "image")
(load "w32-fns")
(load "ls-lisp")
(load "dos-w32"))))
--- ./lisp/term/w32-win.el.orig 2018-01-09 05:23:57.000000000 +0900
+++ ./lisp/term/w32-win.el 2018-04-10 23:10:38.774804800 +0900
@@ -271,6 +271,10 @@
'(gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
'(glib "libglib-2.0-0.dll")
'(gobject "libgobject-2.0-0.dll")
+ '(magickwand "libMagickWand-6.Q16HDRI-5.dll" "libMagickWand-6.Q16-5.dll"
+ "libMagickWand-6.Q16HDRI-2.dll" "libMagickWand-6.Q16-2.dll")
+ '(magickcore "libMagickCore-6.Q16HDRI-5.dll" "libMagickCore-6.Q16-5.dll"
+ "libMagickCore-6.Q16HDRI-2.dll" "libMagickCore-6.Q16-2.dll")
(if (>= libgnutls-version 30400)
'(gnutls "libgnutls-30.dll")
'(gnutls "libgnutls-28.dll" "libgnutls-26.dll"))
--- ./src/image.c.orig 2018-03-13 00:59:18.000000000 +0900
+++ ./src/image.c 2018-04-10 23:10:38.786831200 +0900
@@ -8280,6 +8280,231 @@
MagickPixelPacket *);
#endif
+#ifdef WINDOWSNT
+DEF_DLL_FN (MagickWand *, CloneMagickWand, (const MagickWand *));
+DEF_DLL_FN (MagickWand *, DestroyMagickWand, (MagickWand *));
+DEF_DLL_FN (MagickWand *, DestroyPixelIterator, (PixelIterator *));
+DEF_DLL_FN (PixelWand *, DestroyPixelWand, (PixelWand *));
+#ifdef HAVE_MAGICKAUTOORIENTIMAGE
+DEF_DLL_FN (MagickBooleanType, MagickAutoOrientImage, (MagickWand *));
+#endif
+DEF_DLL_FN (MagickBooleanType, MagickCropImage, (MagickWand *, const size_t, const size_t, const ssize_t, const ssize_t));
+#ifdef HAVE_MAGICKEXPORTIMAGEPIXELS
+DEF_DLL_FN (MagickBooleanType, MagickExportImagePixels, (MagickWand *, const ssize_t, const ssize_t, const size_t, const size_t, const char *, const StorageType, void *));
+#endif
+DEF_DLL_FN (char *, MagickGetException, (const MagickWand *, ExceptionType *));
+DEF_DLL_FN (MagickWand *, MagickGetImage, (MagickWand *));
+DEF_DLL_FN (DisposeType, MagickGetImageDelay, (MagickWand *));
+DEF_DLL_FN (DisposeType, MagickGetImageDispose, (MagickWand *));
+DEF_DLL_FN (size_t, MagickGetImageHeight, (MagickWand *));
+DEF_DLL_FN (MagickBooleanType, MagickGetImagePage, (MagickWand *, size_t *, size_t *, ssize_t *, ssize_t *));
+DEF_DLL_FN (char *, MagickGetImageSignature, (MagickWand *));
+DEF_DLL_FN (size_t, MagickGetImageWidth, (MagickWand *));
+DEF_DLL_FN (size_t, MagickGetNumberImages, (MagickWand *));
+#ifdef HAVE_MAGICKMERGEIMAGELAYERS
+DEF_DLL_FN (MagickWand *, MagickMergeImageLayers, (MagickWand *, const ImageLayerMethod));
+#else
+DEF_DLL_FN (MagickWand *, MagickFlattenImages, (MagickWand *));
+#endif
+DEF_DLL_FN (MagickBooleanType, MagickReadImage, (MagickWand *, const char *));
+DEF_DLL_FN (MagickBooleanType, MagickReadImageBlob, (MagickWand *, const void *, const size_t));
+DEF_DLL_FN (void *, MagickRelinquishMemory, (void *));
+DEF_DLL_FN (MagickBooleanType, MagickRotateImage, (MagickWand *, const PixelWand *, const double));
+DEF_DLL_FN (MagickBooleanType, MagickScaleImage, (MagickWand *, const size_t, const size_t));
+DEF_DLL_FN (MagickBooleanType, MagickSetDepth, (MagickWand *, const size_t));
+DEF_DLL_FN (MagickBooleanType, MagickSetFilename, (MagickWand *, const char *));
+DEF_DLL_FN (MagickBooleanType, MagickSetImageBackgroundColor, (MagickWand *, const PixelWand *));
+DEF_DLL_FN (MagickBooleanType, MagickSetIteratorIndex, (MagickWand *, const ssize_t));
+DEF_DLL_FN (MagickBooleanType, MagickSetSize, (MagickWand *, const size_t, const size_t));
+DEF_DLL_FN (void, MagickWandGenesis, (void));
+DEF_DLL_FN (void, MagickWandTerminus, (void));
+DEF_DLL_FN (MagickWand *, NewMagickWand, (void));
+DEF_DLL_FN (PixelIterator *, NewPixelIterator, (MagickWand *));
+DEF_DLL_FN (PixelWand *, NewPixelWand, (void));
+DEF_DLL_FN (double, PixelGetAlpha, (const PixelWand *));
+DEF_DLL_FN (void, PixelGetMagickColor, (const PixelWand *, MagickPixelPacket *));
+DEF_DLL_FN (PixelWand **, PixelGetNextIteratorRow, (PixelIterator *, size_t *));
+DEF_DLL_FN (MagickBooleanType, PixelSetIteratorRow, (PixelIterator *, const ssize_t));
+DEF_DLL_FN (void, PixelSetMagickColor, (PixelWand *, const MagickPixelPacket *));
+DEF_DLL_FN (void, PixelSetRed, (PixelWand *, const double));
+DEF_DLL_FN (void, PixelSetGreen, (PixelWand *, const double));
+DEF_DLL_FN (void, PixelSetBlue, (PixelWand *, const double));
+DEF_DLL_FN (MagickBooleanType, PixelSyncIterator, (PixelIterator *));
+
+DEF_DLL_FN (ExceptionInfo *, AcquireExceptionInfo, (void));
+DEF_DLL_FN (ExceptionInfo *, DestroyExceptionInfo, (ExceptionInfo *));
+DEF_DLL_FN (char *, DestroyString, (char *));
+DEF_DLL_FN (char **, GetMagickList, (const char *, size_t *, ExceptionInfo *));
+
+static bool
+init_imagemagick_functions (void)
+{
+ HMODULE magickwand, magickcore;
+
+ if (!(magickcore = w32_delayed_load (Qmagickcore))
+ || !(magickwand = w32_delayed_load (Qmagickwand)))
+ return 0;
+
+ LOAD_DLL_FN (magickwand, CloneMagickWand);
+ LOAD_DLL_FN (magickwand, DestroyMagickWand);
+ LOAD_DLL_FN (magickwand, DestroyPixelIterator);
+ LOAD_DLL_FN (magickwand, DestroyPixelWand);
+#ifdef HAVE_MAGICKAUTOORIENTIMAGE
+ LOAD_DLL_FN (magickwand, MagickAutoOrientImage);
+#endif
+ LOAD_DLL_FN (magickwand, MagickCropImage);
+#ifdef HAVE_MAGICKEXPORTIMAGEPIXELS
+ LOAD_DLL_FN (magickwand, MagickExportImagePixels);
+#endif
+ LOAD_DLL_FN (magickwand, MagickGetException);
+ LOAD_DLL_FN (magickwand, MagickGetImage);
+ LOAD_DLL_FN (magickwand, MagickGetImageDelay);
+ LOAD_DLL_FN (magickwand, MagickGetImageDispose);
+ LOAD_DLL_FN (magickwand, MagickGetImageHeight);
+ LOAD_DLL_FN (magickwand, MagickGetImagePage);
+ LOAD_DLL_FN (magickwand, MagickGetImageSignature);
+ LOAD_DLL_FN (magickwand, MagickGetImageWidth);
+ LOAD_DLL_FN (magickwand, MagickGetNumberImages);
+#ifdef HAVE_MAGICKMERGEIMAGELAYERS
+ LOAD_DLL_FN (magickwand, MagickMergeImageLayers);
+#else
+ LOAD_DLL_FN (magickwand, MagickFlattenImages);
+#endif
+ LOAD_DLL_FN (magickwand, MagickReadImage);
+ LOAD_DLL_FN (magickwand, MagickReadImageBlob);
+ LOAD_DLL_FN (magickwand, MagickRelinquishMemory);
+ LOAD_DLL_FN (magickwand, MagickRotateImage);
+ LOAD_DLL_FN (magickwand, MagickScaleImage);
+ LOAD_DLL_FN (magickwand, MagickSetDepth);
+ LOAD_DLL_FN (magickwand, MagickSetFilename);
+ LOAD_DLL_FN (magickwand, MagickSetImageBackgroundColor);
+ LOAD_DLL_FN (magickwand, MagickSetIteratorIndex);
+ LOAD_DLL_FN (magickwand, MagickSetSize);
+ LOAD_DLL_FN (magickwand, MagickWandGenesis);
+ LOAD_DLL_FN (magickwand, MagickWandTerminus);
+ LOAD_DLL_FN (magickwand, NewMagickWand);
+ LOAD_DLL_FN (magickwand, NewPixelIterator);
+ LOAD_DLL_FN (magickwand, NewPixelWand);
+ LOAD_DLL_FN (magickwand, PixelGetAlpha);
+ LOAD_DLL_FN (magickwand, PixelGetMagickColor);
+ LOAD_DLL_FN (magickwand, PixelGetNextIteratorRow);
+ LOAD_DLL_FN (magickwand, PixelSetIteratorRow);
+ LOAD_DLL_FN (magickwand, PixelSetMagickColor);
+ LOAD_DLL_FN (magickwand, PixelSetRed);
+ LOAD_DLL_FN (magickwand, PixelSetGreen);
+ LOAD_DLL_FN (magickwand, PixelSetBlue);
+ LOAD_DLL_FN (magickwand, PixelSyncIterator);
+
+ LOAD_DLL_FN (magickcore, AcquireExceptionInfo);
+ LOAD_DLL_FN (magickcore, DestroyExceptionInfo);
+ LOAD_DLL_FN (magickcore, DestroyString);
+ LOAD_DLL_FN (magickcore, GetMagickList);
+
+ return 1;
+}
+
+#undef CloneMagickWand
+#undef DestroyMagickWand
+#undef DestroyPixelIterator
+#undef DestroyPixelWand
+#undef MagickAutoOrientImage
+#undef MagickCropImage
+#undef MagickExportImagePixels
+#undef MagickGetException
+#undef MagickGetImage
+#undef MagickGetImageDelay
+#undef MagickGetImageDispose
+#undef MagickGetImageHeight
+#undef MagickGetImagePage
+#undef MagickGetImageSignature
+#undef MagickGetImageWidth
+#undef MagickGetNumberImages
+#ifdef HAVE_MAGICKMERGEIMAGELAYERS
+#undef MagickMergeImageLayers
+#else
+#undef MagickFlattenImages
+#endif
+#undef MagickReadImage
+#undef MagickReadImageBlob
+#undef MagickRelinquishMemory
+#undef MagickRotateImage
+#undef MagickScaleImage
+#undef MagickSetDepth
+#undef MagickSetFilename
+#undef MagickSetImageBackgroundColor
+#undef MagickSetIteratorIndex
+#undef MagickSetSize
+#undef MagickWandGenesis
+#undef MagickWandTerminus
+#undef NewMagickWand
+#undef NewPixelIterator
+#undef NewPixelWand
+#undef PixelGetAlpha
+#undef PixelGetMagickColor
+#undef PixelGetNextIteratorRow
+#undef PixelSetIteratorRow
+#undef PixelSetMagickColor
+#undef PixelSetRed
+#undef PixelSetGreen
+#undef PixelSetBlue
+#undef PixelSyncIterator
+#undef AcquireExceptionInfo
+#undef DestroyExceptionInfo
+#undef DestroyString
+#undef GetMagickList
+
+#define CloneMagickWand fn_CloneMagickWand
+#define DestroyMagickWand fn_DestroyMagickWand
+#define DestroyPixelIterator fn_DestroyPixelIterator
+#define DestroyPixelWand fn_DestroyPixelWand
+#define MagickAutoOrientImage fn_MagickAutoOrientImage
+#define MagickCropImage fn_MagickCropImage
+#define MagickExportImagePixels fn_MagickExportImagePixels
+#define MagickGetException fn_MagickGetException
+#define MagickGetImage fn_MagickGetImage
+#define MagickGetImageDelay fn_MagickGetImageDelay
+#define MagickGetImageDispose fn_MagickGetImageDispose
+#define MagickGetImageHeight fn_MagickGetImageHeight
+#define MagickGetImagePage fn_MagickGetImagePage
+#define MagickGetImageSignature fn_MagickGetImageSignature
+#define MagickGetImageWidth fn_MagickGetImageWidth
+#define MagickGetNumberImages fn_MagickGetNumberImages
+#ifdef HAVE_MAGICKMERGEIMAGELAYERS
+#define MagickMergeImageLayers fn_MagickMergeImageLayers
+#else
+#define MagickFlattenImages fn_MagickFlattenImages
+#endif
+#define MagickReadImage fn_MagickReadImage
+#define MagickReadImageBlob fn_MagickReadImageBlob
+#define MagickRelinquishMemory fn_MagickRelinquishMemory
+#define MagickRotateImage fn_MagickRotateImage
+#define MagickScaleImage fn_MagickScaleImage
+#define MagickSetDepth fn_MagickSetDepth
+#define MagickSetFilename fn_MagickSetFilename
+#define MagickSetImageBackgroundColor fn_MagickSetImageBackgroundColor
+#define MagickSetIteratorIndex fn_MagickSetIteratorIndex
+#define MagickSetSize fn_MagickSetSize
+#define MagickWandGenesis fn_MagickWandGenesis
+#define MagickWandTerminus fn_MagickWandTerminus
+#define NewMagickWand fn_NewMagickWand
+#define NewPixelIterator fn_NewPixelIterator
+#define NewPixelWand fn_NewPixelWand
+#define PixelGetAlpha fn_PixelGetAlpha
+#define PixelGetMagickColor fn_PixelGetMagickColor
+#define PixelGetNextIteratorRow fn_PixelGetNextIteratorRow
+#define PixelSetIteratorRow fn_PixelSetIteratorRow
+#define PixelSetMagickColor fn_PixelSetMagickColor
+#define PixelSetRed fn_PixelSetRed
+#define PixelSetGreen fn_PixelSetGreen
+#define PixelSetBlue fn_PixelSetBlue
+#define PixelSyncIterator fn_PixelSyncIterator
+#define AcquireExceptionInfo fn_AcquireExceptionInfo
+#define DestroyExceptionInfo fn_DestroyExceptionInfo
+#define DestroyString fn_DestroyString
+#define GetMagickList fn_GetMagickList
+
+#endif /* !WINDOWSNT */
+
/* Log ImageMagick error message.
Useful when an ImageMagick function returns the status `MagickFalse'. */
@@ -8945,6 +9170,11 @@
char **imtypes;
size_t i;
+#if WINDOWSNT
+ if (!init_imagemagick_functions ())
+ return Qnil;
+#endif
+
ex = AcquireExceptionInfo ();
imtypes = GetMagickList ("*", &numf, ex);
DestroyExceptionInfo (ex);
@@ -9959,6 +10189,10 @@
#if defined (HAVE_IMAGEMAGICK)
DEFSYM (Qimagemagick, "imagemagick");
ADD_IMAGE_TYPE (Qimagemagick);
+#if defined HAVE_NTGUI && !defined CYGWIN
+ DEFSYM (Qmagickwand, "magickwand");
+ DEFSYM (Qmagickcore, "magickcore");
+#endif /* HAVE_NTGUI */
#endif
#if defined (HAVE_RSVG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.