
// ShowLUT.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Display a 'ramp' image showing how the specified
   ImageJ Lookup Tables LUT is mapped to grayscale 
   values.

   In addition, the macro "Show_ALL_LUTs" is called
   to display a montage of all the LUTs in the 
   ImageJ/luts directory.

   The macro is from
   https://imagej.nih.gov/ij/macros/Show_All_LUTs.txt

 
   Usage:
     > compile ShowLUT.java
     > run ShowLUT <LUT name>
   e.g.
     > run ShowLUT Fire
     > run ShowLUT Royal

*/

import java.awt.*;
import java.awt.image.*;
import java.awt.color.*;
import java.util.*;

import ij.*;
import ij.process.*;
import ij.plugin.*;
import ij.macro.*;

public class ShowLUT
{

  public static void main(String[] args)
  {
    if (args.length != 1) {
      System.out.println("Usage: run ShowLUT <LUT name>");
      return;
    }
    String lutNm = args[0];

    String[] luts = IJ.getLuts();
    System.out.println("LUTs: " + Arrays.toString(luts));

    if (!Arrays.asList(luts).contains(lutNm)) {
      System.out.println(lutNm + " not in Lookup Tables menu");
      return;
    }

    IndexColorModel cm  = LutLoader.getLut(lutNm);
    ByteProcessor bp = LutLoader.createImage(cm);

    ImagePlus imp = new ImagePlus(lutNm + " LUT", bp);
    imp.show();

    System.out.println("Run Show_All_LUTs macro");
    String path = IJ.getDir("macros") + "Show_All_LUTs.txt";
    // System.out.println("Using " + path);
    // System.out.println("Path exists: " + new File(path).exists());

    String macroCode = ImageUtils.readFile(path);
    ImagePlus montageImp = new Interpreter().runBatchMacro(macroCode, null);
    montageImp.show();

    ImageUtils.waitGone(imp);
    System.exit(0);
  } /* main */

  

}  // end of ShowLUT class
