summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--convert.c67
2 files changed, 22 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index 7f9cb95..3ba0187 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
CROSS=arm-linux-gnueabihf
-DEPLIBS=MagickCore libpng16 zlib
+DEPLIBS=MagickWand libpng16 zlib
PKG_CONFIG_PATH=./deps/lib/pkgconfig
CC=$(CROSS)-gcc
-CFLAGS=-Wall -Wextra -I. $$(PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags MagickCore)
+CFLAGS=-Wall -Wextra -I. $$(PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags MagickWand)
LDFLAGS=-lpthread $$(PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs-only-L $(DEPLIBS))
LDLIBS=$$(PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs-only-l $(DEPLIBS)) -lm
diff --git a/convert.c b/convert.c
index 1f81d8c..f64f7f6 100644
--- a/convert.c
+++ b/convert.c
@@ -1,65 +1,38 @@
#include <stdio.h>
#include <string.h>
-#define MAGICKCORE_QUANTUM_DEPTH 8
-#define MAGICKCORE_HDRI_ENABLE 0
-#include <MagickCore/MagickCore.h>
+#include <MagickWand/MagickWand.h>
int convert(const char *in, const char *out, int width, int height)
{
- if (!IsMagickCoreInstantiated()) {
- MagickCoreGenesis(NULL, MagickFalse);
- }
-
- printf("converting image %s\n", in);
+ static MagickWand *w = NULL;
+ static PixelWand *pixel = NULL;
- ExceptionInfo *exception = AcquireExceptionInfo();
+ if (!IsMagickWandInstantiated()) {
+ MagickWandGenesis();
+ w = NewMagickWand();
+ pixel = NewPixelWand();
+ }
- printf("reading original image\n");
- ImageInfo *info = CloneImageInfo((ImageInfo*)NULL);
- if (info == NULL) {
- printf("couldn't create new ImageInfo: ");
- CatchException(exception);
+ if (!MagickReadImage(w, in)) {
+ printf("couldn't read '%s'\n", in);
return 1;
}
- strcpy(info->filename, in);
- Image *original = ReadImage(info, exception);
- if (original == NULL) {
- printf("couldn't read original: ");
- CatchException(exception);
- return 0;
- }
- printf("resizing\n");
- Image *resized = ResizeImage(original, width, height, LanczosFilter, exception);
- DestroyImage(original);
- if (resized == NULL) {
- printf("couldn't resize: ");
- CatchException(exception);
- return 0;
+ if (!MagickAdaptiveResizeImage(w, width, height)) {
+ printf("couldn't resize image\n");
+ return 1;
}
- printf("rotating\n");
- Image *rotated = IntegralRotateImage(resized, 3, exception);
- DestroyImage(resized);
- if (rotated == NULL) {
- printf("couldn't rotate: ");
- CatchException(exception);
- return 0;
+ if (!MagickRotateImage(w, pixel, 270)) {
+ printf("couldn't rotate image\n");
+ return 1;
}
- printf("writing grayscale\n");
- strcpy(info->filename, out);
- if (!WriteImage(info, rotated, exception)) {
- printf("couldn't save converted image (%s): ", out);
- CatchException(exception);
- return 0;
+ if (!MagickWriteImage(w, out)) {
+ printf("couldn't write '%s'\n", out);
+ return 1;
}
- printf("cleaning up\n");
- DestroyImage(rotated);
- DestroyImageInfo(info);
- DestroyExceptionInfo(exception);
-
- return 1;
+ return 0;
}