Professional Documents
Culture Documents
txt
// First version: 17/11/2006
// Description:
// The "Luts Macros and Tools Updater" tool set perfoms a live-updating/restorin
g of the following ImageJ macros repertories:
// - /macros
// - /macros/tools
// - /macros/toolsets
// - /luts
// For a routine use of installed macros and tools, a plugin shortcut can be ins
talled using the MacroPluginShortcutsTool.txt
// Author : Gilles Carpentier
// Faculte des Sciences et Technologies,
// Universite Paris 12 Val de Marne, France.
var distantmacrosrep = "http://rsb.info.nih.gov/ij/macros/";
var distanttoolsrep = "http://rsb.info.nih.gov/ij/macros/tools/";
var distanttoolsetsrep = "http://rsb.info.nih.gov/ij/macros/toolsets/";
var urllist="http://image.bio.methods.free.fr/ij/ijupdatetest/ListOfMacros.txt";
distantmacrolink = "";
var KindOfMacro=0,report=0,updates=0,nMacroinL=0,nToolinL=0,nToolsetsinL=0,TheRe
port="";
var onlinedoclink = "http://image.bio.methods.free.fr/ijmacrolutupdater.html";
var distantlutsrep = "http://image.bio.methods.free.fr/ij/luts/"; distantmacroli
nk = ""; nLutsinL=0;
var urllistoflut="http://image.bio.methods.free.fr/ij/ijupdatetest/ListOfLUTs.tx
t";distantmacrolink = "";
var demoimagename = "blobs.gif",non=0;
var xx = requires138b(); // check version at install time
function requires138b() {requires("1.38b"); return 0; }
function GetTheListofAvailableMacros () {
showMessageWithCancel ("Get on line available macros list?");
if (File.openUrlAsString(urllist) == "") exit("You need an internet acce
ss to run this function.");
run("URL...", "url=["+urllist+"]");
}
// lut part
function LUTsUpdater () {
distantmacrolink = urllistoflut;
message="The updater allows to visualize the LUTs on a\"ramp\",\nor thei
r effects onto an image.";
Dialog.create("Lut Updater User Options");
Dialog.addMessage(message);
Dialog.addChoice("->",newArray("Ramp","Image","No Visualize"));
Dialog.addCheckbox("Update report?", 1);
Dialog.show();
visuchoice=Dialog.getChoice();
lutreport= Dialog.getCheckbox();
if (File.openUrlAsString(distantmacrolink) == "") exit ("You need an int
ernet access to run this function.");
showStatus("Internet link...");
luttextnih =File.openUrlAsString(distantmacrolink);
showStatus("");
lines=split(luttextnih,"\n");nLuts=GetnLUTs (lines);
lLuts = newArray(nLuts);lLuts=llutPlace (lines,lLuts);
if (getDirectory("startup") == 0) exit ("Unable to find the startup dire
ctory, something wrong in the ImageJ folder.\nTry again after restarting Image."
);
ijpath = getDirectory("startup");lutpath=ijpath+"luts/";
if (File.isDirectory(lutpath) == 0) {
LutDir = lutpath +File.separator;
File.makeDirectory(LutDir);
if (!File.exists(LutDir)) exit ("Unable to create the \" luts \"
directory, something wrong in the ImageJ folder.\nTry again after restarting Im
age.");
}
listoflut = getFileList(lutpath);nlocallut=GetnLUTs (listoflut);
llocalLuts = newArray(nlocallut);llocalLuts=llutPlace (listoflut,llocalL
uts);
nbNewLut= (nLuts - nbThings(lLuts,llocalLuts));lNewlut=newArray(nbNewLut
);
lNewlut=PlaceNewThings (lLuts,llocalLuts,lNewlut);
if (lNewlut.length >0) {
message="Number of new available LUT(s): " + lNewlut.length + ".
Perform the installation? ";
if (visuchoice != "No Visualize") message = message+ "\n(The sca
n of new installed LUTs can be interrupted by clicking \nonto the visualisation
image window).";
showMessageWithCancel (message);
}
instalmacro(lNewlut,distantlutsrep,lutpath);
if (lNewlut.length >0) {
if (lutreport == 1 ) { lutRapport (lutpath,lNewlut);}
if (visuchoice != "No Visualize") {
if (visuchoice == "Image") OpenImageLink(0);
if (visuchoice == "Ramp") makeRamp();
}
if (visuchoice != "No Visualize") {
if (lNewlut.length>0) {
show=1;
showNewLuts(lutpath,lNewlut,show);
message="Result of the LUT update process: "+lNe
wlut.length+" new LUTs has been";
message=message+"\ninstalled. Use the \"Last Ins
talled Luts Menu Tool\" to see";
message=message+"\nagain a particular LUT.";
message=message+"\n \n(Restart ImageJ to make th
e LUTs available from the";
message=message+"\n\ÓImage -> Lookup Tables\" me
nu).";
showMessage (message);
UpdateLutList();
}
}
} else { showMessage ("No new lut available. Your \"luts\" folder is up
to date.");}
}
function lastInstalledLutVisu() {
lutlistfile = getDirectory("startup")+"luts"+File.separator+ " LUTs Upda
te Reports"+File.separator+"Last New Installed Luts.txt";
if (!File.exists(lutlistfile)) return newArray ("No last luts installed
list file found"); list = newArray("No last luts installed list file found"
);listOfCommands = newArray("no commands");
lastlutlist =File.openAsString(lutlistfile);
lines=split(lastlutlist,"\n");
listOfCommands=newArray(lines.length+2);
listOfCommands[0]="List of new installed LUTs:";listOfCommands[1]="-";
for (i=0; i<lines.length; i++) {listOfCommands[i+2]=lines[i];}
return listOfCommands;
}
function GetthelistofavailableLUTs () {
if (File.openUrlAsString(urllistoflut) == "") exit("You need an internet
access to run this function.");
showMessageWithCancel ("Get on line available LUTs list?");
run("URL...", "url=["+urllistoflut +"]");
}
function UpdateLutList() {
kind="tools";macroname="Luts Macros and Tools Updater.txt";
macropath=getDirectory("macros") + kind + File.separator+ macroname;
if (!File.exists(macropath)) exit ("Record this tool into the \"tools\"
folder with the name \"" +macroname+ "\",\nto use this menu tool.");
run("Install...", "install=["+macropath+"]");
}
macro "About Luts Macros and Tools Updater Action Tool - C000D84Cb9fD25De7CaaaD1
4D2dDa0DafDecDfaCedfD49D4aD4bD4cD58D68D9bDb9DbaDbbDbcC889D2cDebCddfD52CcccD0bD22
CeeeD00D03D0cD0fD10D1fD20D2fD30D40Dc0Dd0DdfDe0DefDf0Df1Df2Df3DfcDfeDffC666D07D70
CdcfD34D35Dc4CbacD86D91CfefD6bD6dD7cD8cD8dD8eD9cD9dDadC97aDd3De5CedfD99CeeeD01D0
2D04D0dD0eD11D12D1eD21D3fDcfDd1De1De2DeeDf4DfdCfefD7dC545D94Da5CdbeDa4Da7CbabD05
D50DaeCfefD7eC98aD32Da1CecfD39D3aD3bD46D48D57D67Da8Db6Db8Dc9DcaDcbDccCdcdD81C878
D1bD60D65CdcfD29D36D38D47D77Db7Dc8Dd9DdaCcbcD7aDbfDc1De3C98bD16D24D75DeaCedfD56D
66D73D76D83D93Da3C212D7bD88D96D97CcaeD26D3cDdbCaaaD3eD5fCfdfD59C889D15D1aD78Dc2C
dcfD45Db4Db5Dc6CdddD13D31D4fDdeDedDfbC777D09D7fD85D90Df7CeceDbdCbadD18D55Db2De9C
a9aD5eDcdDceDdcC656D08D64D80D87D8bCdbfD28D2aD37Dc7Dd8CbbbD1cD42Dd2Df5CfdfD5aD5bD
5cD5dD69D6aD6cD9aDa9DabDacC999D0aD41DddDf6CdddD1dD2eD9eDb0C888D06D4eD6fD9fDf9Ccb
dD54D71D98Dc3Ca9dD17D19Dd4De6C000D74D79D95CcafDd5Dd6De8CedfD62D72D92C889D51Db1Db
eCedfD53D63Da2CdcdD6eC777D8fDf8CdcfD43D44Db3Dc5CbadD2bD33C99aD23De4C545D89Da6Ccb
fD27Dd7CbabD61CedfD82DaaC98aD3dCdceD4dD8a" {
about1();
}
// ---- functions ----- //
// Function giving the number (NumberOfMacro) of macros and tools contained a li
st (lmacros).
function getMacroNumber (lmacros) {
NumberOfMacro=0;
for (i=0; i<lmacros.length; i++) {
showProgress(i,lmacros.length);
if (endsWith(lmacros[i], ".txt") || endsWith(lmacros[i], ".ijm")
) NumberOfMacro ++; }
return NumberOfMacro;
}
// Function giving the macros number (nMacroinL) and the tools number (nToolinL)
containened in an array (lmacros).
// macros are sorted according .txt or .img and 'Macro' or 'Tool' prefixes.
function getMandTNumber (lmacros) {
nMacroinL=0;nToolinL=0;nToolsetsinL=0;
for (i=0; i<lmacros.length; i++) {
showProgress(i,lmacros.length);
if (endsWith(lmacros[i], ".txt") || endsWith(lmacros[i], ".ijm")
) {
if (startsWith(lmacros[i], "Macro ")) nMacroinL ++;
if (startsWith(lmacros[i], "Tool ")) nToolinL ++;
if (startsWith(lmacros[i], "Toolset ")) nToolsetsinL ++;
}
}
}
// Function giving the list of macros (Lele) with the prefix (kind) contained in
the list (lmacros).
function lPlace (lmacros,Lele,kind) {
compteur=0;
for (i=0; i<lmacros.length; i++) {
showProgress(i,lmacros.length);
if (endsWith(lmacros[i], ".txt") || endsWith(lmacros[i], ".ijm")
) {
if (startsWith(lmacros[i], kind)) {
Lele[compteur]=substring(lmacros[i],lengthOf(kin
d),lengthOf(lmacros[i]));
compteur ++;
}
}
}
return Lele;
}
// Function setting in the report (TheReport) the contents of the list (tab), a
dding the prefix (prefix).
function listit (tab,prefix) {
for (i=0; i<tab.length; i++) {
TheReport=TheReport + "\n"+ prefix+tab[i];
}
}
// Function giving the number of elements contained in the first list (liste1) a
nd in the second list (liste2).
function nbThings(liste1,liste2) {
compteur=0;
for (i=0; i<liste1.length; i++) {
showProgress(i,liste1.length);
for (j=0; j<liste2.length; j++) {
if (liste1[i]==liste2[j]) compteur ++;
}
}
return compteur;
}
// Function giving the list of elements (New) contained in the first list (liste
1) and in the second list (liste2).
function PlaceNewThings (liste1,liste2,New) {
newcompteur=0;
test=0;
for (i=0; i<liste1.length; i++) {
showProgress(i,liste1.length);
for (j=0; j<liste2.length; j++) {
if (liste1[i]==liste2[j]) test ++;
}
if (test==0) {
New[newcompteur]=liste1[i];
newcompteur ++;
}
test=0;
}
return New;
}
// Function sorting the number of elements (compteur) which are macros and tools
, and can be updated (sorted [n], if n=1 the macro is updatable).
function Nbmacroupdates (macrolocalist,macrodistlist,urlrep,localrep,sorted) {
compteur=0;
for (i=0; i<macrolocalist.length; i++) {
showProgress(i,macrolocalist.length);
for (j=0; j<macrodistlist.length; j++) {
if (macrolocalist[i]==macrodistlist[j]) {
macrotextnih=getdistantmacro (macrodistlist[j],u
rlrep); macropath = localrep + macrolocalist[i];
if (File.exists(macropath)) {
thelocalmacro = File.openAsString(macrop
ath);
if (thelocalmacro != macrotextnih) {
if (macrolocalist[i] != "Startup
Macros.txt") {
compteur=compteur+1;
sorted[i]=1;
}
}
}
}
}
}
return compteur;
}
// Function giving the list (listupdate) of macros and tools which can be update
d.
function placeUpdatemacro(listupdate,locallist,Sorted) {
compteur=0;
for (i=0; i<Sorted.length; i++) {
if (Sorted[i] == 1) {
listupdate[compteur]=locallist[i];
compteur++;
}
}
return listupdate;
}
// Function archiving the old macros.
function archmacros(list,localrep,foldername){
// Create an Archived Tools directory in tools repertory
if (list.length > 0) {
ArchDir = localrep+ " " + foldername+File.separator;
File.makeDirectory(ArchDir);
if (!File.exists(ArchDir)) exit("Unable to create the "+folderna
me+" directory, something wrong in the ImageJ folder");
}
for (i=0; i<list.length; i++) {
if (File.exists(localrep+list[i])) {
thelocalmacro = File.openAsString(localrep+list[i]);
f= File.open(ArchDir + list[i]);
print (f,thelocalmacro);
File.close(f);
}
}
}
// Function installing a list (list) of distant macro located at (urlrep), into
the local folder (localrep).
function instalmacro(list,urlrep,localrep){
for (i=0; i<list.length; i++) {
showProgress(i,list.length);
macrotextnih= getdistantmacro (list[i],urlrep);
f= File.open(localrep + list[i]);
print (f,macrotextnih);
File.close(f);
}
showProgress(1.0);
}
// Function giving the content of a distant macro (name) located at the distant
repertory (urlrep).
function getdistantmacro (name,urlrep) {
distantmacrolink = urlrep + name;
if (indexOf(distantmacrolink, " ") > -1) {
while (indexOf(distantmacrolink, " ") > -1) {
distantmacrolink=substring(distantmacrolink, 0, (indexOf
(distantmacrolink, " ")))+"%20"+substring(distantmacrolink, (indexOf(distantmacr
olink, " ")+1),lengthOf(distantmacrolink) );
}
}
showStatus("Internet link...");
macrotextnih =File.openUrlAsString(distantmacrolink);
showStatus("");
return macrotextnih;
}
// Function making a detailed report of every list obtained.
function rapport (FMacros,FTools,FToolsets,lMacro,lTool,lToolsets,NewMacros,NewT
ools,NewToolsets,UpdatedMacro,UpdatedTool,UpdatedToolsets,localrep,foldername) {
TheReport="";
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second,
msec);
reportname= ""+dayOfMonth+"-"+(month+1) +"-"+year+" at "+hour+"."+minut
e+"."+second+"";
TheReport=TheReport + "Installation report for the update performed on:
"+reportname;
if ((NewMacros.length+NewTools.length +NewToolsets.length)>0) {
TheReport=TheReport +"\n\n--- The following new Macros, Tools an
d Toolsets have been installed: ";
TheReport=TheReport + "("+(NewMacros.length+NewTools.length+NewT
oolsets.length)+" Macros: "+NewMacros.length+ " \"macros\" , "+NewTools.length+"
\"tools\" & "+NewToolsets.length+" \"toolsets\" ):";
listit (NewMacros,"Macro ");
if (NewTools.length > 0) TheReport=TheReport + "\n--------";
listit (NewTools,"Tool ");
if (NewToolsets.length > 0) TheReport=TheReport + "\n--------";
listit (NewToolsets,"Toolset ");
}
if(updates==1) {
TheReport=TheReport + "\n\n--- The following Macros, Tools and T
oolsets update have been performed: ";
TheReport=TheReport +"("+(UpdatedMacro.length+UpdatedTool.length
+UpdatedToolsets.length)+" Macros: "+UpdatedMacro.length+ " \"macros\" , "+Updat
edTool.length+" \"tools\" & "+UpdatedToolsets.length+" \"toolsets\"):";
listit (UpdatedMacro,"Macro ");
if (UpdatedTool.length > 0) TheReport=TheReport + "\n--------";
listit (UpdatedTool,"Tool ");
if (UpdatedToolsets.length > 0) TheReport=TheReport + "\n-------
-"; listit (UpdatedToolsets,"Toolset ");
}
if (updates==0) TheReport=TheReport + "\n\n--- The Macros, Tools and Too
lsets updated have not been queried.";
TheReport=TheReport + "\n\n--- Note: the list of macros, tools and tools
ets installed onto you computer before this update ---";
TheReport=TheReport + "\n ("+(FMacros.length+FTools.length+ FToolse
ts.length)+" Macros: "+ FMacros.length + " \"macros\" , "+FTools.length+" \"tool
s\" & "+ FToolsets.length+" \"toolsets\"):";
listit (FMacros,"Macro ");TheReport=TheReport +"\n--------";listit (FToo
ls,"Tool ");TheReport=TheReport +"\n--------";listit (FToolsets,"Toolset ");
TheReport=TheReport +"\n\n--- Note: the list of macros, tools and toolse
ts available at the ImageJ web site ---";
TheReport=TheReport + "\n ("+(lMacro.length+lTool.length+ lToolsets
.length)+" Macros: "+ lMacro.length + " \"macros\" , "+lTool.length+" \"tools\"
& "+ lToolsets.length +" \"toolsets\"):";
listit (lMacro,"Macro "); TheReport=TheReport +"\n--------"; listit (lTo
ol,"Tool ");TheReport=TheReport +"\n--------"; listit (lToolsets,"Toolset ");
UpdateReports = localrep+ " " + foldername+File.separator;
File.makeDirectory(UpdateReports);
if (!File.exists(UpdateReports)) exit("Unable to create the "+foldername
+" directory, something wrong in the ImageJ folder");
f= File.open(UpdateReports + reportname+".txt" ); print (f,TheRepo
rt);
File.close(f);
if (File.exists(UpdateReports + reportname+".txt")) open(UpdateReports +
reportname+".txt");
}
function about1() {
about="";
about=about + "The \"Luts Macro and Tools Updater\" ImageJ tool bar icon
s allow to perfom a live";
about=about + "\nupdate of the ImageJ macros and luts repertories.";
about=about + "\n \n\"Macro, Tools and Toolsets Updater Menu Tool\" Imag
eJ tool bar icon:";
about=about + "\n - \"Macro, Tools and Toolsets Updater\" looks for n
ew and updated macros,";
about=about + "\n Tools and Toolsets and installs them.";
about=about + "\n \n\"LUTs Updater Menu Tool\" ImageJ tool bar icon:";
about=about + "\n - \"LUTs Updater\" looks for new luts and installs
them.";
about=about + "\n \n\"Last Installed Luts Menu Tool\" ImageJ tool bar ic
on:";
about=about + "\n - Gives a menu of last new installed LUTs, allowing
to test them on images or";
about=about + "\n ramps.";
about=about + "\n \n- Click on the \"On Line Documentation\" ImageJ tool
bar icon for more details.";
about=about + "\n- Click on the \"Version Infos\" ImageJ tool bar icon t
o look for new beta versions.";
about=about + "\n-------------------------------------------------------
-----------";
about=about +"\nAuthor : Gilles Carpentier"+"\nFaculte des Sciences et T
echnologies"+"\nUniversite Paris 12 Val de Marne, France.";
showMessage(about);
}
// function specific to the LUTs Updater
function OpenImageLink(question) {
demoimalocation = getDirectory("startup");
fildestination = demoimalocation+ "Downloaded Demo Images/" +demoimagena
me;
if (File.exists(fildestination) && ! isOpen(demoimagename)) {
if (question ==1 ) showMessageWithCancel ("The \"" + demoimagena
me + "\" has already been downloaded. Open it?");
open(fildestination);
}
else {
if (! isOpen(demoimagename)) { run("Blobs (25K)"); }
selectImage(demoimagename);
nomdimage = getTitle;
// Create a <Downloaded Demo Images> repertory in ImageJ folder.
ImaDemo = demoimalocation+"Downloaded Demo Images"+File.separato
r;
File.makeDirectory(ImaDemo);
if (!File.exists(ImaDemo)) exit("Unable to create directory, som
ething wrong in the ImageJ folder");
selectWindow(nomdimage);
save(""+ImaDemo+""+ nomdimage +"");
}
}
function lutRapport (cheminlut,liste) {
lutrapport="";LastLuts="";
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second,
msec);
reportname= ""+dayOfMonth+"-"+(month+1) +"-"+year+" at "+hour+"."+minut
e+"."+second+"";
lutrapport=lutrapport + "Installation report for the LUT update performe
d on: "+reportname;
lutrapport=lutrapport +"\n \nThe following "+liste.length+ " new LUTs ha
s been installed into the \""+cheminlut+ "\"\nrepertory of ImageJ:\n"; for (i=0
; i<liste.length; i++) {
lutrapport= lutrapport + "\nLut name: " + liste[i] ;
LastLuts=LastLuts + ShortName (liste[i]) + "\n";
}
foldername="LUTs Update Reports";
LutUpdateReports = cheminlut+ " " + foldername+File.separator;
File.makeDirectory(LutUpdateReports);
if (!File.exists(LutUpdateReports)) exit("Unable to create the "+foldern
ame+" directory, something wrong in the ImageJ folder");
f= File.open(LutUpdateReports + reportname+".txt" ); print (f,lutrapp
ort);
File.close(f);
f= File.open(LutUpdateReports + "Last New Installed Luts.txt" );
print (f,LastLuts);
File.close(f);
if (File.exists(LutUpdateReports + reportname+".txt")) open(LutUpdateRep
orts + reportname+".txt");
}
// Function giving the number of LUTs in a list
function GetnLUTs (lutlist) {
NumberOfLUTs=0;
for (i=0; i<lutlist.length; i++) {
showProgress(i,lutlist.length);
if (endsWith(lutlist[i], ".lut")) NumberOfLUTs ++; }
showProgress(1.0); return NumberOfLUTs;
}
// Function giving the list of elements (Lele) with the sufix ".lut" contained i
n the list (llut).
function llutPlace (llut,Lele) {
compteur=0;
for (i=0; i<llut.length; i++) {
showProgress(i,llut.length);
if (endsWith(llut[i], ".lut")) {Lele[compteur]=llut[i];compteur
++;} }
showProgress(1.0); return Lele;
}
// function opening the new luts
function showNewLuts(cheminLut,lNewlut,show) {
nomderampe = getTitle; setTool(10);
for (i=0; i<lNewlut.length; i++) {
if (show ==1) {
open(cheminLut + lNewlut[i]);
rename(lNewlut[i]);
if (non == 0) wait(500);
}
}
rename (nomderampe);non=0;
}
function makeRamp () {
setBatchMode(true);
if (! isOpen("LUTs visualisation")) {
newImage("LUTs visualisation", "8-bit ramp", 256, 32,1);
} else {selectImage("LUTs visualisation");}
nomderampe = getTitle;
setBatchMode("exit and display");
return nomderampe;
}
function checkForImage (cmd) {
imaname="";
if (nImages > 0) {
setBatchMode(true);visu=0;depth = bitDepth;imaname= getTitle;ok=
0;
if (depth > 8) {
showMessage("Color tables cannot be assigned to RGB imag
e.\nThe lut will be drawed on a \"ramp\" window,\nor applied to the demo image."
);
rampname= lookForaRamp ();
if (rampname == "") {makeRamp ();selectImage("LUTs visu
alisation");imaname= getTitle;depth = bitDepth;ok=1;}
if (rampname != "" && ok==0) {selectImage(rampname);ima
name= getTitle;depth = bitDepth;ok=1;}
}
if (depth == 8 && startsWith(imaname, "LUTs :" ) && ok==0) ok=1;
if (depth == 8 && imaname == demoimagename) ok=1;
if (depth == 8 && imaname == "LUTs visualisation") ok=1;
selectImage (imaname);
if (ok ==1 && depth ==8) {rename ("LUTs : " + cmd);}
imaname= getTitle;
setBatchMode("exit and display");
}
return imaname;
}
function lookForaRamp () {
rampansvers = "";
if (nImages > 0) {
for (i=1; i <= nImages; i++) {
selectImage(i);imaname=getTitle;
if (bitDepth == 8 && startsWith(imaname, "LUTs :
")) {rampansvers=imaname;}
}
}
return rampansvers;
}
function ShortName (longname) {
if (endsWith(longname, ".txt") || endsWith(longname, ".ijm") || endsWith
(longname, ".lut")) longname = substring(longname, 0, (lengthOf(longname)-4));
return longname;
}