From 5dc6844c90eb38e6af687af8e922b4695f4e35b5 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Tue, 7 May 2024 19:31:45 +0200 Subject: Support both versions of ImageMagick: 6 and 7 --- src/libimage/Makefile.am | 9 +++++--- src/libimage/img.c | 53 +++++++++++++++++++++++++++++++++++++++++------- src/tv/Makefile.am | 9 ++------ 3 files changed, 54 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/libimage/Makefile.am b/src/libimage/Makefile.am index fbbe316..3e91308 100644 --- a/src/libimage/Makefile.am +++ b/src/libimage/Makefile.am @@ -1,12 +1,15 @@ AM_CPPFLAGS = -Wall -Wextra -Wmissing-prototypes -g $(all_includes) \ - $(IMAGEMAGICK_CFLAGS) + $(IMAGEMAGICK6_CFLAGS) $(IMAGEMAGICK7_CFLAGS) noinst_LIBRARIES = libimage.a libimage_a_SOURCES = \ img.c -if HAVE_MAGICK -AM_CPPFLAGS += -DHAVE_MAGICK +if HAVE_MAGICK6 +AM_CPPFLAGS += -DHAVE_MAGICK6 +endif +if HAVE_MAGICK7 +AM_CPPFLAGS += -DHAVE_MAGICK7 endif diff --git a/src/libimage/img.c b/src/libimage/img.c index 42f2c43..f59586a 100755 --- a/src/libimage/img.c +++ b/src/libimage/img.c @@ -5,25 +5,46 @@ int save_depth = 16; -#ifdef HAVE_MAGICK +#if defined(HAVE_MAGICK6) || (HAVE_MAGICK7) + +#if defined(HAVE_MAGICK6) +#include +#endif +#if defined(HAVE_MAGICK7) #include +#endif /* load given image to memory. return short RGB values */ unsigned short *load_img(int *width, int *height, const char *filename, int index) { Image *image = NULL; ImageInfo *imageinfo = NULL; +#if defined(HAVE_MAGICK6) + ExceptionInfo exception; +#endif +#if defined(HAVE_MAGICK7) ExceptionInfo *exception; +#endif unsigned short *img = NULL; MagickCoreGenesis(NULL, MagickFalse); // InitializeMagick(NULL); imageinfo = CloneImageInfo(0); +#if defined(HAVE_MAGICK6) + GetExceptionInfo(&exception); +#endif +#if defined(HAVE_MAGICK7) exception = AcquireExceptionInfo(); +#endif sprintf(imageinfo->filename, filename, index); +#if defined(HAVE_MAGICK6) + image = ReadImage(imageinfo, &exception); +#endif +#if defined(HAVE_MAGICK7) image = ReadImage(imageinfo, exception); +#endif if (!image) { // printf("failed to read image '%s' via *magick\n", filename); goto exit; @@ -48,8 +69,10 @@ exit: if (imageinfo) DestroyImageInfo(imageinfo); +#if defined(HAVE_MAGICK7) if (exception) DestroyExceptionInfo(exception); +#endif MagickCoreTerminus(); // DestroyMagick(); @@ -63,18 +86,33 @@ int save_img(unsigned short *img, int width, int height, int alpha, const char * int rc = -1; Image *image = NULL; ImageInfo *imageinfo = NULL; +#if defined(HAVE_MAGICK6) + ExceptionInfo exception; +#endif +#if defined(HAVE_MAGICK7) ExceptionInfo *exception; +#endif MagickCoreGenesis(NULL, MagickFalse); // InitializeMagick(NULL); imageinfo = CloneImageInfo(0); +#if defined(HAVE_MAGICK6) + GetExceptionInfo(&exception); +#endif +#if defined(HAVE_MAGICK7) exception = AcquireExceptionInfo(); +#endif imageinfo->quality = 100; if (strlen(filename) >= 4 && !strcmp(filename + strlen(filename) - 4, ".png")) imageinfo->quality = 1; +#if defined(HAVE_MAGICK6) + image=ConstituteImage(width, height, (alpha)?"RGBA":"RGB", ShortPixel, img, &exception); +#endif +#if defined(HAVE_MAGICK7) image=ConstituteImage(width, height, (alpha)?"RGBA":"RGB", ShortPixel, img, exception); +#endif if (!image) { printf("%s:failed to prepare to write image\n", __func__); goto exit; @@ -84,7 +122,12 @@ int save_img(unsigned short *img, int width, int height, int alpha, const char * image->depth = save_depth; sprintf(image->filename, filename, index); /* ACHTUNG: nicht imageinfo!!! */ +#if defined(HAVE_MAGICK6) + if (!WriteImage(imageinfo, image)) { +#endif +#if defined(HAVE_MAGICK7) if (!WriteImage(imageinfo, image, exception)) { +#endif printf("%s:failed to write image\n", __func__); goto exit; } @@ -98,8 +141,10 @@ exit: if (imageinfo) DestroyImageInfo(imageinfo); +#if defined(HAVE_MAGICK7) if (exception) DestroyExceptionInfo(exception); +#endif MagickCoreTerminus(); // DestroyMagick(); @@ -262,12 +307,6 @@ int save_img_array(double *array, int width, int height, int alpha, const char * unsigned short *img = NULL; int components; -#ifndef HAVE_MAGICK - if (alpha) { - printf("%s:warning, cannot save alpha component with PPM support only\n", __func__); - alpha = 0; - } -#endif components = (alpha) ? 4 : 3; img = (unsigned short *)malloc(width * height * components * 2); diff --git a/src/tv/Makefile.am b/src/tv/Makefile.am index 8297bf8..1d8bb22 100644 --- a/src/tv/Makefile.am +++ b/src/tv/Makefile.am @@ -1,5 +1,4 @@ -AM_CPPFLAGS = -Wall -Wextra -Wmissing-prototypes -g $(all_includes) \ - $(IMAGEMAGICK_CFLAGS) +AM_CPPFLAGS = -Wall -Wextra -Wmissing-prototypes -g $(all_includes) bin_PROGRAMS = \ osmotv @@ -28,7 +27,7 @@ osmotv_LDADD = \ $(top_builddir)/src/liblogging/liblogging.a \ $(LIBOSMOCORE_LIBS) \ $(ALSA_LIBS) \ - $(IMAGEMAGICK_LIBS) \ + $(IMAGEMAGICK6_LIBS) $(IMAGEMAGICK7_LIBS) \ -lm if HAVE_SDR @@ -51,7 +50,3 @@ if HAVE_SDR AM_CPPFLAGS += -DHAVE_SDR endif -if HAVE_MAGICK -AM_CPPFLAGS += -DHAVE_MAGICK -endif - -- cgit v1.2.3