summaryrefslogtreecommitdiff
path: root/convert.c
blob: 333d79dac8ccbb9a7dfaec6ff570efb4c9e5f0f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <string.h>

#define MAGICKCORE_QUANTUM_DEPTH 8
#define MAGICKCORE_HDRI_ENABLE 0
#include <MagickCore/MagickCore.h>

int convert(const char *in, const char *out, int width, int height)
{
	if (!IsMagickCoreInstantiated()) {
		MagickCoreGenesis(NULL, MagickFalse);
	}

	printf("converting image %s\n", in);

	ExceptionInfo *exception = AcquireExceptionInfo();

	printf("reading original image\n");
	ImageInfo *info = CloneImageInfo((ImageInfo*)NULL);
	if (info == NULL) {
		printf("couldn't create new ImageInfo\n");
		return 1;
	}
	strcpy(info->filename, in);
	Image *original = ReadImage(info, exception);
	if (original == NULL) {
		printf("couldn't read original\n");
		return 0;
	}

	printf("resizing\n");
	Image *resized = ResizeImage(original, width, height, LanczosFilter, exception);
	DestroyImage(original);
	if (resized == NULL) {
		printf("couldn't resize\n");
		return 0;
	}

	printf("rotating\n");
	Image *rotated = IntegralRotateImage(resized, 3, exception);
	DestroyImage(resized);
	if (rotated == NULL) {
		printf("couldn't rotate\n");
		return 0;
	}

	printf("writing grayscale\n");
	strcpy(info->filename, out);
	WriteImage(info, rotated, exception);

	printf("cleaning up\n");
	DestroyImage(rotated);
	DestroyImageInfo(info);
	DestroyExceptionInfo(exception);

	return 1;
}