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 <ae@cy.md> 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 /// Invoke ImageMagick's `convert` program to parse the given data. 22 auto parseViaIMConvert(COLOR)(const(void)[] data) 23 { 24 string[] convertFlags; 25 static if (is(COLOR : BGR)) 26 { 27 // convertFlags ~= ["-colorspace", "rgb"]; 28 // convertFlags ~= ["-depth", "24"]; 29 convertFlags ~= ["-type", "TrueColor"]; 30 convertFlags ~= ["-alpha", "off"]; 31 } 32 else 33 static if (is(COLOR : BGRA)) 34 { 35 convertFlags ~= ["-type", "TrueColorAlpha"]; 36 convertFlags ~= ["-alpha", "on"]; 37 } 38 return pipe(["convert".imageMagickBinary()] ~ convertFlags ~ ["-[0]", "bmp:-"], data).viewBMP!COLOR(); 39 } 40 41 /// ditto 42 auto parseViaIMConvert(C = TargetColor, TARGET)(const(void)[] data, auto ref TARGET target) 43 if (isWritableView!TARGET && isTargetColor!(C, TARGET)) 44 { 45 return data.parseViaIMConvert!(ViewColor!TARGET)().copy(target); 46 } 47 48 unittest 49 { 50 if (false) 51 { 52 void[] data; 53 parseViaIMConvert!BGR(data); 54 55 Image!BGR i; 56 parseViaIMConvert!BGR(data, i); 57 } 58 }