-
Notifications
You must be signed in to change notification settings - Fork 0
/
displaceComposite.c
117 lines (78 loc) · 3.75 KB
/
displaceComposite.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>
void ThrowWandException(MagickWand *wand) {
char *description;
ExceptionType severity;
description = MagickGetException(wand, &severity);
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description);
description=(char *) MagickRelinquishMemory(description);
exit(-1);
}
PixelWand *makePixelWand(char *string) {
PixelWand *pixel_wand;
pixel_wand = NewPixelWand();
if (PixelSetColor (pixel_wand, string) == MagickFalse) {
printf("Failed to set color");
exit(-1);
}
return pixel_wand;
}
int main(int argc,char **argv) {
MagickBooleanType status;
PixelWand *pixelWand;
MagickWand *magick_wand_a;
MagickWand *magick_wand_b;
//MagickWand *magick_wand_c;
MagickWandGenesis();
// $a = new Imagick('../a.png');
// $b = new Imagick('../b.png');
// $c = new Imagick('../c.png');
magick_wand_a = NewMagickWand();
status = MagickReadImage(magick_wand_a, "./displaceCompositeA.png");
if (status == MagickFalse) {
ThrowWandException(magick_wand_a);
}
magick_wand_b = NewMagickWand();
status = MagickReadImage(magick_wand_b, "./displaceCompositeB.png");
if (status == MagickFalse) {
ThrowWandException(magick_wand_b);
}
// magick_wand_c = NewMagickWand();
// status = MagickReadImage(magick_wand_c, "./displaceCompositeC.png");
// if (status == MagickFalse) {
// ThrowWandException(magick_wand_c);
// }
// $a->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
MagickSetImageVirtualPixelMethod(magick_wand_a, TransparentVirtualPixelMethod);
// $a->setImageBackgroundColor(new ImagickPixel('none'));
pixelWand = makePixelWand("none");
status = MagickSetImageBackgroundColor(magick_wand_a, pixelWand);
// $a->setOption('compose:args', '300x53.033');
MagickSetOption(magick_wand_a, "compose:args", "300x53.033");
// $a->compositeImage($c, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
// "COMPOSITE_DSTIN", DstInCompositeOp);
// status = MagickCompositeImageChannel(magick_wand_a, AlphaChannel, magick_wand_c, DstInCompositeOp, 0, 0);
// if (status == MagickFalse) {
// printf("Failed to composite image b");
// exit(-1);
// }
// $a->compositeImage($b, Imagick::COMPOSITE_DISPLACE, 0, 0);
// "COMPOSITE_DISPLACE", DisplaceCompositeOp);
status = MagickCompositeImage(magick_wand_a, magick_wand_b, DisplaceCompositeOp, 0, 0);
if (status == MagickFalse) {
printf("Failed to composite image b");
exit(-1);
}
status = MagickWriteImages(magick_wand_a, "displaceOutput.png", MagickTrue);
// magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
printf("Finished - please compare displaceOutput.png with the result of:\n\n");
// printf("convert ./displaceCompositeA.png ./displaceCompositeB.png ./displaceCompositeC.png -virtual-pixel transparent -channel rgba -alpha on -background transparent -define compose:args=300x53.033 -compose displace -composite ./displaceFinal.png\n");
// printf("convert ./displaceCompositeA.png ./displaceCompositeB.png ./displaceCompositeC.png -virtual-pixel transparent -channel rgba -alpha on -background transparent -define compose:args=300x53.033 -compose displace ./displaceFinal2.png\n");
//
//convert displaceCompositeB.png displaceCompositeC.png +clone -combine displaceMask.png
convert displaceCompositeA.png displaceMask.png -virtual-pixel transparent -channel rgba -alpha on -background transparent -define compose:args=300x53.033 -compose displace -composite displaceMerged.png
return(0);
}