Support both versions of ImageMagick: 6 and 7
This commit is contained in:
committed by
Andreas Eversberg
parent
7b0168c713
commit
5dc6844c90
@@ -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
|
||||
|
||||
|
@@ -5,25 +5,46 @@
|
||||
|
||||
int save_depth = 16;
|
||||
|
||||
#ifdef HAVE_MAGICK
|
||||
#if defined(HAVE_MAGICK6) || (HAVE_MAGICK7)
|
||||
|
||||
#if defined(HAVE_MAGICK6)
|
||||
#include <magick/MagickCore.h>
|
||||
#endif
|
||||
#if defined(HAVE_MAGICK7)
|
||||
#include <MagickCore/MagickCore.h>
|
||||
#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);
|
||||
|
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user