// This macro converts a 26x26 8-bit image to a tool macro icon // string. Ideally, the image should have no more than 16 colors. // Includes seven examples that, with the exception of the // "Lena Tool", were created by converting website favicons // (http://en.wikipedia.org/wiki/Favicon). // v1.0 : 4 April 2006 // v1.1 : 17 January 2021 : works with 26x26px images. macro "Convert 26x26 Image to Tool Icon..." { requires("1.35r"); var r,g,b; if (bitDepth!=8 || getWidth>26 || getHeight>26) exit("This macro requires 26x26 8-bit image"); Dialog.create("Image 2 Tool"); Dialog.addString("Tool name", "myTool"); Dialog.addCheckbox("Transparent Color", false); Dialog.addNumber("Value", 0); Dialog.show(); mytool = Dialog.getString(); allPixels = !Dialog.getCheckbox(); transparent = Dialog.getNumber(); getLut(r,g,b); getRawStatistics(area, mean, min, max); ts='macro "'+mytool+' Tool - '; ts=ts+"N66"; ts=ts+ getQuadrant(0,15,0,15); ts=ts+"Bf0"; ts=ts+ getQuadrant(15,26,0,15); ts=ts+"B0f"; ts=ts+ getQuadrant(15,26,15,26); ts=ts+"Nf0"; ts=ts+ getQuadrant(0,15,15,26); ts=ts+'"{\n\n}'; macrodir = getDirectory("macros"); if (!endsWith(mytool,".txt")) mytool = mytool+".txt"; f = File.open(macrodir+mytool); print (f, ts); File.close(f); open(macrodir+mytool); } function getQuadrant(xmin,xmax,ymin,ymax) { quadrant =""; for (i=0; i<=max; i++) { if (allPixels || i!=transparent) { r2=floor(r[i]/256*16); g2=floor(g[i]/256*16); b2=floor(b[i]/256*16); color = "C"+toHex(r2)+toHex(g2)+toHex(b2); if (!endsWith(quadrant, color)) quadrant=quadrant+color; for (x=xmin; x