Skip to content

Instantly share code, notes, and snippets.

@mutterer
Forked from lannybroo/Image_to_Tool_Icon_24.ijm
Created January 19, 2021 18:02
Show Gist options
  • Save mutterer/80a043952b1cbfcfda09bcccf4cb57a6 to your computer and use it in GitHub Desktop.
Save mutterer/80a043952b1cbfcfda09bcccf4cb57a6 to your computer and use it in GitHub Desktop.
A version of the ImageJ Image to Tool Icon macro that works with 24x24 images
// This macro converts a 24x24 8-bit image to a tool macro icon
// string. Ideally, the image should have no more than 16 colors.
// Includes a few examples.
macro "Convert Image to Tool Icon 24..." {
requires("1.53c"); // for the extended hex feature
if (bitDepth==24) // convert RGB to 16-color 8-bit
run("8-bit Color", "number=16");
if (bitDepth!=8 || getWidth>24 || getHeight>24)
exit("This macro requires an 8-bit 24x24 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);
if (getWidth>16 && getHeight>16) {
// use Nxy notation to offset the origin for larger icons
shiftX = floor(getWidth/2) - 8;
shiftY = floor(getHeight/2) - 8;
shiftStr = 'N'+shiftX+''+shiftY;
} else {
shiftStr = '';
}
ts='macro "'+mytool+' Action Tool - ' + shiftStr;
// N44 shifts the base to -4,-4, ~centering the 24x24 icon
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(ts, color)) ts=ts+color;
for (x=0; x<getWidth; x++) {
for (y=0; y<getHeight; y++) {
if (getPixel(x,y)==i)
ts=ts+"D"+toExtHex(x)+toExtHex(y);
}
}
}
}
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 toExtHex(n) {
// thanks to Animated Action Tool by Jerome Mutterer
if (n>15) return fromCharCode(0x66+n-15);
else return toHex(n);
}
// 16x16 Examples
macro "Cube Action Tool - CfffCfc9D25D26D27D28D29D2aD2bD34D36D37D38D39D3aD3bD3cD44D46D47D48D49D4aD4bD4cD53D54D55D57D58D59D5aD5bD5cD5dD63D64D65D67D68D69D6aD6bD6cD6dD73D74D75D76D83D84D85D93D94D95Da4Db4C000D15D16D17D18D19D1aD1bD24D2cD33D35D3dD43D45D4dD52D56D5eD62D66D6eD72D77D78D79D7aD7bD7cD7dD7eD82D86D8eD92D96D9eDa3Da5DadDb3Db5DbdDc4DccDd5Dd6Dd7Dd8Dd9DdaDdbCc96D87D88D89D8aD8bD8cD8dD97D98D99D9aD9bD9cD9dDa6Da7Da8Da9DaaDabDacDb6Db7Db8Db9DbaDbbDbcDc5Dc6Dc7Dc8Dc9DcaDcbCbbbDaeDbeDcdDceDdcDddDdeDebDecDedDeeDfcDfd"{
}
macro "Lena Action Tool - C313DceDcfDdcDddDdeDdfDeaDebDecDedDeeDf3Df4Df7Df8Df9DfaCc77D35D3fD41D44D45D50D55D64D69D6dD76DafDbdDc4Dc6DcaCb55D04D0fD1fD2fD6eD72D73D74D79D88D89D9aD9bD9eDdaDe6De7Cd99D10D11D56D60D65D95D9cDabDb5Db6Db7Db8Db9DbaDd3Dd4C634D13D22D33D43D61D62D63D71Db3Dc2De9Df1Df2DfdDfeDffCd87D16D17D29D39D3aD3bD4aD4bD4cD5aD5bD5cD67D68D6bD77D7fD96D97Dc7Cc66D05D06D14D31D34D51D75D78D83D84D85D99Dc5Dd6Dd8Dd9CdbaD00D01D03D12D20D30D90D9dDa1Da9DaaDadDb1Db2Dc1C413D23D32D42D52Dc3Dd2De2De3De4DefDf0Df5Df6DfbDfcCd77D15D18D19D25D2aD2bD2cD3cD3eD4dD5dD6cD7cD7dDbcDc8Dc9Cd65D07D09D0aD0bD0cD0dD0eD1dD1eD5fD6fD7aD7bD87D8bCe99D26D27D36D37D38D46D47D48D57D70D80D81D8dD8fD91D94D9fCa45D24D40D4eD5eD7eD8eDaeDb4DbfDcdDd1Dd5DdbDe1De5De8Cd98D28D49D58D59D66D8cD92D93DbbDe0Cd66D08D1aD1bD1cD2dD2eD3dD4fD6aD82D86D8aD98DbeDcbDccDd7CedcD02D21D53D54Da0Da2Da3Da4Da5Da6Da7Da8DacDb0Dc0Dd0"{
}
// 24x24 Examples
macro "Lenna24 Action Tool - N44C403D0eD3fD64C856D2fC713D4eCc88D1gDnfDngC514D17D51DkgCe56D7iDdlC923D98Cda9D78De1C602D89Cc56Da7C725Da9Ce88DffC524D3eCe77DejCc44DbkCdbaDj0C503DmiDmjCb66D1eD5bC724DhkDj9DkjCb99D3dC614D15D24D27D35D52Cd67DidCa45D4iCea9Di7C613D1jCc66D01C736D45D90Ce98D58C724DmfCe78DekCd55Dd9DefCecaD2eD4bC413DhmCa67Dl0Dm9DndC824Dj8Cd88D84Dc5C614D25Ce66D8hD8iD8jD9iDalDe9DifCb34D5cCcaaD96C613D1kD2nD99DjkDjnDkeDlcDldDmgDmkCd56D6dD6eD6fD8lDdfDdhDebC735Db0Ce98D8cD9eDaeDbdDdnC615D72Ce77D8bD8eD9fD9gDahDaiDbgDbiDbnDcdDdiDdmDe8DemDflCc55D7lCfbaDg8C514D1cDijDl6Cb77Dm7C924D5lCd98D1fDb1C624DimDkhCd77DcmDfmDgjDhgCa45D88DihCebaD59C713D6nDkbDkdDmlCc66Dj7C846Di9Cda9D77C625D36Ce87DagDbfDbhCd56DdbCfcbDfaDh4Dh5Dh6C503Dk4Cb56DfnC724DmnCb88Dk0C514D08D13D19D26D29D32D47Cd57DdkCa34Dc8CdaaD86Db3Dd1De0Df3Dg2C603Dk5Cd66DbjDcjDdjDehDj4C835D03D12Ce98Dm2C624D04D62Cd77DccDciDhcDheDhfCc45DjeCebaD3cDeiDf5Dg4Dg5Dg6C513D0bD0jD0kD14D1aD28D3gDilDlaDlbDn5Cc67D20C834D4kCd98Dd4Dg9C614D2mD3kDn6Ce67D7eDelDieC956DnaCea9D85C613D2iD3jD3mD3nD4nDleCd66D6cD9bD9mDdcDeaDfgDicC946DmdCe99De4DghDgiC625D05D33D71Dl5Cd87D75DfjDhdCd55D6gD6hD6iD6jD7jD7kD8mDblCecbD69C404D38Ca68Dl3C824D4fDb8Dc9Cd98D76C614D0mD0nD1lD1mD1nD3hD3iDk3Ce76D9kCa45D8aCdbaD87Dh0Cd66D7hD8kD9jDigC935D4jCe99D9cDacDbcDfeC525Da0Cd45DeeCfbbDbaDfbDh3Cc77DgaC934DjaCda9Da3Db4Dd2C724D2kD5nCe77D7dD8fD8gD9hDchDhhCb55DibCfbaDf9Di3C723D2jD5mDlfCc76Dn0C737D54Cea9D9dDe6C626D31D37D44CfcbDi4C403D0dD1bDhlCa56DncC723DlgDmmCc88Da6Dc0C514D0lD39DjjCd66D9lDamDceDddDgkC934D4gCdaaDa4Da5Dg1C603Dk9DkaCd56D9nDcfDcgDdeC736D23D42D53D61Ce88D8dDbeDj5C515D46Ce77D7bCc45D5dD5eD5hD5iDdaDdgCebaDfcDg3Dh2C503Dh9Dn4Cb56DhjC824DkmCc99Dc3De3Cd67DanDbmDhbDhiC946D79DhaCea9De5Df8C613DjlDjmCd66DcaC736D22D40D80Ce98Dc6De7C724D0fD4lDiiDkiDn7Cd78Db6DcbCd55DajDjdCdcbD5aDi0C513D0cD2hDgnDikDkfCa67D4cDm8C824DlhDliDljDlkCd88DbbCc44D5jDegCdbaDc2Df0Dg0C845D0iD74Dn9C625D07D41D50Cc55D6bD7aDd8DjcCebbDgcCb77Dm6DneDnhC834Da8DlmCd99Db5De2Df1C624D2lD3lD4mDinDjgCb45Db7CebaDb2Cd67D10DabC846Dk1Dk2Dl4Cda9D4aC625D06D18D34C503D1iD63D73Dl7Dl8Dl9Ca66DmaDniC823D7nDi8Dk8Cc89D0hD94Ca35D4hDjfC603D4dDmhCe88DcnDenC624D1hCb67D6aDm4C835D65Dj1DmeCca9Dd3Df2C714DgmCd67DfkCa47D30Cea9Df7DfdDj6C946DnkDnlDnmDnnCe99DadDd6Ce78D7cCecbDgeC414DjhDjiCa68Db9Dl1Dl2Cd88DfhDi2Cc44D5gD6lD7mD8nC835D21D48C526D55D82D91Cd55D6kDakCb78Da2DaaDiaC835Dj2DknC724D2bCa46D02D11CfbaDh7Cc77D49D66C747D70D81D92Cea9D0gCfdcDi5Di6C403D2aDn3C956DnbC713Dk7DkcCe66D7fD7gCa34D6mDjbCda9Dd0C726D43D60Ce88DafDd5C624D0aD16D56Cc45D5fCebaD68Dc1Dh1Cc98Dc4Di1Ca45D9aCfa8Dn1Cf98Dm1Cd55DclDecDedC724DkkDklCd88D3bD97Dd7Cb44Dj3C836D83C834DllCb55Dc7DglDm0CebaDf4Df6Dg7DggCea9D2dD67C503D2gCb66D2cD57Ca34D5kCb67Dm3C735Dn8C956D3aDmcDnjCeaaDgbCecbDfiDgdC969D93C945Dn2C625D09Cd45DckCb78Dm5C834DlnCc77Dh8C847Da1CfccDgfCa57DmbC813Dk6C514DhnCc66D00C734D1dCc99D95"{
}
macro "Raw FPA Action Tool - N44C222D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD0gD0hD0iD0jD0kD0lD0mD0nD10D1nD20D2nD30D3nD40D4nD50D5nD60D6nD70D7nD80D8nD90D9nDa0DanDb0DbnDc0DcnDd0DdnDe0DenDf0DfnDg0DgnDh0DhnDi0DinDj0DjnDk0DknDl0DlnDm0DmnDn0Dn1Dn2Dn3Dn4Dn5Dn6Dn7Dn8Dn9DnaDnbDncDndDneDnfDngDnhDniDnjDnkDnlDnmDnnCdddD11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD1fD1gD1hD1iD1jD1kD1lD1mD21D22D23D24D25D26D27D28D29D2aD2bD2cD2dD2eD2fD2gD2hD2iD2jD2kD2lD2mD31D32D33D34D35D36D37D38D39D3aD3bD3cD3dD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kbDkcDkdDkeDkfDkgDkhDkiDkjDkkDklDkmDl1Dl2Dl3Dl4Dl5Dl6Dl7Dl8Dl9DlaDlbDlcDldDleDlfDlgDlhDliDljDlkDllDlmDm1Dm2Dm3Dm4Dm5Dm6Dm7Dm8Dm9DmaDmbDmcDmdDmeDmfDmgDmhDmiDmjDmkDmlDmmC10bD6dD7dD8dDa9DaaDabDafDagDahDcdDddDed"{
}
macro "Rotated Action Tool - N44C222D00D01D02D03D04D05D06D07D08D09D0iD0jD0kD0lD0mD0nD10D11D12D13D14D15D16D17D1jD1kD1lD1mD1nD20D21D22D23D24D25D2jD2kD2lD2mD2nD30D31D32D33D34D3kD3lD3mD3nD40D41D42D4kD4lD4mD4nD50D5lD5mD5nD6mD6nD7mD7nD8nD9nDe0Df0Dg0Dg1Dh0Dh1Di0Di1Di2DinDj0Dj1Dj2Dj3DjlDjmDjnDk0Dk1Dk2Dk3DkjDkkDklDkmDknDl0Dl1Dl2Dl3Dl4DliDljDlkDllDlmDlnDm0Dm1Dm2Dm3Dm4DmgDmhDmiDmjDmkDmlDmmDmnDn0Dn1Dn2Dn3Dn4Dn5DneDnfDngDnhDniDnjDnkDnlDnmDnnCdddD0aD0bD0cD0dD0eD0fD0gD0hD18D19D1aD1bD1cD1dD1eD1fD1gD1hD1iD26D27D28D29D2aD2bD2cD2dD2eD2fD2gD2hD2iD35D36D37D38D39D3aD3bD3cD3dD3eD3fD3gD3hD3iD3jD43D44D45D46D47D48D49D4aD4bD4cD4dD4eD4fD4gD4hD4iD4jD51D52D53D54D55D56D57D58D59D5aD5bD5cD5dD5eD5fD5gD5hD5iD5jD5kD60D61D62D63D64D65D66D67D68D69D6aD6bD6cD6dD6eD6fD6gD6hD6iD6jD6kD6lD70D71D72D73D74D75D76D77D78D79D7aD7bD7dD7eD7fD7gD7hD7iD7jD7kD7lD80D81D82D83D84D85D86D87D88D89D8aD8bD8dD8eD8fD8gD8hD8iD8jD8kD8lD8mD90D91D92D93D94D95D96D97D98D99D9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9lDamDbmDcmDd2De7De8Cda6D7aD7eD7kD98Dc3Dc6Dc7Dc8Df2Df6Df7Cb71D7fD9aD9iD9jDc9DcaDd3De3De5DeaDfaCfedD6fD6lD6nD79Da8DabDacDadDb9DbeDbiDccDcdDceDciDfbDfjDgaDgkDhfDhgDhmDhnC752DahDbfDcjDdbDdfDdlDefDegDelDffDflCc96D7nD88D8nDaaDagDakDc2DcgDedDf9DgnCb60D7lD8hD8iD8jD8kD8mD9bD9cD9dDe2DgmCdcbD6mD78DbgDbhDbkDc0Dc4DdhDeeDehDf4C961D8aD9eD9gDalDclDd5DddDdkDdmDe6DebDgfCdb8D7bD7cD7dD7gD99DaiDc5DcbDf3Df5Df8Cb84D89DanDblDbnDcnDd0Dd4DdnDecDekDen"{
}
macro "IJ2 Action Tool - N44C000D8mD9mDajDamDbjDbmDcfDcjDdfDdlDe9DefDeiDelDfkDgkC876D7dD8dD93D9lDb3DbhDc9DciDd7DdaDfgDfiC222D8eD95D96D97D98DaeDagDbeDceDdgDdmDehDflDgjCbaaD7jD7kD83D89D8gD8lDahDanDbnDc4DfhDgaDhlC111Da5Da7Da9Db4DbgDd8DdkDe7DejDfjCca4DaaDabDadDb5Db6Db9Dc5Dc6Dc8Dd5Dd6De4C555D6fDaiDalDbdDbiDcdDckDdeDeaDf9DgeDglCfedD5cD6bD6cD6gD7cD7lD82D8iD90D91D92Da0Da1Db0Db1Db2DccDd3Dd4De3Df3DgfDikC001D8fD8jD9fDa4Da8DafDbfDcmDd9DdjDe8DekDfaDfeDgcDgdDhkC888D6eD7nD9gD9kD9nDakDbkDdhDeeDemDfcDhjC443D7eD99D9bD9eDa3DblDdiDe6DegDgbCdddD6dD7gD84D85D86D87D88D9iDchDcnDddDhcDhdC221D7fD94Da6DclDe5DffCcb7D7aD7bD9aD9cD9dDa2DacDb7Db8DbaDc7DcaDf4C666D7mD8aD8bD8kD8nD9jDcgDf5Df6Df7Df8DfbDfd"{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment