1 /**
2  * ImageMagick "convert" program wrapper
3  *
4  * License:
5  *   This Source Code Form is subject to the terms of
6  *   the Mozilla Public License, v. 2.0. If a copy of
7  *   the MPL was not distributed with this file, You
8  *   can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * Authors:
11  *   Vladimir Panteleev <vladimir@thecybershadow.net>
12  */
13 
14 module ae.utils.graphics.im_convert;
15 
16 import ae.sys.cmd;
17 import ae.sys.imagemagick;
18 import ae.utils.graphics.color;
19 import ae.utils.graphics.image;
20 
21 auto parseViaIMConvert(COLOR)(const(void)[] data)
22 {
23 	string[] convertFlags;
24 	static if (is(COLOR : BGR))
25 	{
26 	//	convertFlags ~= ["-colorspace", "rgb"];
27 	//	convertFlags ~= ["-depth", "24"];
28 		convertFlags ~= ["-type", "TrueColor"];
29 		convertFlags ~= ["-alpha", "off"];
30 	}
31 	else
32 	static if (is(COLOR : BGRA))
33 	{
34 		convertFlags ~= ["-type", "TrueColorAlpha"];
35 		convertFlags ~= ["-alpha", "on"];
36 	}
37 	return pipe(["convert".imageMagickBinary()] ~ convertFlags ~ ["-[0]", "bmp:-"], data).viewBMP!COLOR();
38 }
39 
40 auto parseViaIMConvert(C = TargetColor, TARGET)(const(void)[] data, auto ref TARGET target)
41 	if (isWritableView!TARGET && isTargetColor!(C, TARGET))
42 {
43 	return data.parseViaIMConvert!(ViewColor!TARGET)().copy(target);
44 }
45 
46 unittest
47 {
48 	if (false)
49 	{
50 		void[] data;
51 		parseViaIMConvert!BGR(data);
52 
53 		Image!BGR i;
54 		parseViaIMConvert!BGR(data, i);
55 	}
56 }