void createImage(FileInfo fi, boolean show) { IndexColorModel cm = new IndexColorModel(8, 256, fi.reds, fi.greens, fi.blues); ByteProcessor bp = createImage(cm); setProcessor(fi.fileName, bp); if (show) show(); }
/** Opens a lookup table (LUT) and returns it as a LUT object, or returns null if there is an error. * @see ij.ImagePlus#setLut */ public static LUT openLut(String filePathOrUrl) { return LutLoader.openLut(filePathOrUrl); }
/** Opens an NIH Image LUT, 768 byte binary LUT or text LUT from a file or URL. */ boolean openLut(FileInfo fi) { //IJ.log("openLut: " + fi.directory + fi.fileName); boolean isURL = fi.url!=null && !fi.url.equals(""); int length = 0; String path = isURL?fi.url:fi.directory+fi.fileName; if (!isURL) { File f = new File(path); length = (int)f.length(); if (length>10000) { error(path); return false; } } int size = 0; try { if (length>768) size = openBinaryLut(fi, isURL, false); // attempt to read NIH Image LUT if (size==0 && (length==0||length==768||length==970)) size = openBinaryLut(fi, isURL, true); // otherwise read raw LUT if (size==0 && length>768) size = openTextLut(fi); if (size==0) error(path); } catch (IOException e) { IJ.error("LUT Loader", ""+e); } return size==256; }
{invertLut(); return;} else if (arg.equals("fire")) nColors = fire(fi.reds, fi.greens, fi.blues); else if (arg.equals("grays")) nColors = grays(fi.reds, fi.greens, fi.blues); else if (arg.equals("ice")) nColors = ice(fi.reds, fi.greens, fi.blues); else if (arg.equals("spectrum")) nColors = spectrum(fi.reds, fi.greens, fi.blues); else if (arg.equals("3-3-2 RGB")) nColors = rgb332(fi.reds, fi.greens, fi.blues); else if (arg.equals("red")) nColors = primaryColor(4, fi.reds, fi.greens, fi.blues); else if (arg.equals("green")) nColors = primaryColor(2, fi.reds, fi.greens, fi.blues); else if (arg.equals("blue")) nColors = primaryColor(1, fi.reds, fi.greens, fi.blues); else if (arg.equals("cyan")) nColors = primaryColor(3, fi.reds, fi.greens, fi.blues); else if (arg.equals("magenta")) nColors = primaryColor(5, fi.reds, fi.greens, fi.blues); else if (arg.equals("yellow")) nColors = primaryColor(6, fi.reds, fi.greens, fi.blues); else if (arg.equals("redgreen")) nColors = redGreen(fi.reds, fi.greens, fi.blues); if (nColors>0) { if (nColors<256) interpolate(fi.reds, fi.greens, fi.blues, nColors); fi.fileName = arg;
/** Opens a LUT and returns it as a LUT object. */ public static LUT openLut(String pathOrURL) { FileInfo fi = new FileInfo(); fi.reds = new byte[256]; fi.greens = new byte[256]; fi.blues = new byte[256]; fi.lutSize = 256; int nColors = 0; if (pathOrURL.contains("://")) { fi.url = pathOrURL; fi.fileName = ""; } else { OpenDialog od = new OpenDialog("Open LUT...", pathOrURL); fi.directory = od.getDirectory(); fi.fileName = od.getFileName(); if (fi.fileName==null) return null; } LutLoader loader = new LutLoader(); boolean ok = loader.openLut(fi); if (ok) return new LUT(fi.reds, fi.greens, fi.blues); else return null; }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value != null) { labelItem.setText((String)value); labelItem.setIcon(new ImageIcon(LutLoader.createImage(luts.get(value)).createImage().getScaledInstance(150, 15, Image.SCALE_DEFAULT))); } if (isSelected) { labelItem.setBackground(SystemColor.textHighlight); labelItem.setForeground(SystemColor.textHighlightText); } else { labelItem.setBackground(SystemColor.text); labelItem.setForeground(SystemColor.textText); } return this; } }
/** Opens the specified ImageJ LUT and returns it as an IndexColorModel. Since 1.43t. */ public static IndexColorModel open(String path) throws IOException { return open(new FileInputStream(path)); }
f.read(fi.blues, 0, nColors); if (nColors<256) interpolate(fi.reds, fi.greens, fi.blues, nColors); f.close(); return 256;
{invertLut(); return;} else if (arg.equals("fire")) nColors = fire(fi.reds, fi.greens, fi.blues); else if (arg.equals("grays")) nColors = grays(fi.reds, fi.greens, fi.blues); else if (arg.equals("ice")) nColors = ice(fi.reds, fi.greens, fi.blues); else if (arg.equals("spectrum")) nColors = spectrum(fi.reds, fi.greens, fi.blues); else if (arg.equals("3-3-2 RGB")) nColors = rgb332(fi.reds, fi.greens, fi.blues); else if (arg.equals("red")) nColors = primaryColor(4, fi.reds, fi.greens, fi.blues); else if (arg.equals("green")) nColors = primaryColor(2, fi.reds, fi.greens, fi.blues); else if (arg.equals("blue")) nColors = primaryColor(1, fi.reds, fi.greens, fi.blues); else if (arg.equals("cyan")) nColors = primaryColor(3, fi.reds, fi.greens, fi.blues); else if (arg.equals("magenta")) nColors = primaryColor(5, fi.reds, fi.greens, fi.blues); else if (arg.equals("yellow")) nColors = primaryColor(6, fi.reds, fi.greens, fi.blues); else if (arg.equals("redgreen")) nColors = redGreen(fi.reds, fi.greens, fi.blues); if (nColors>0) { if (nColors<256) interpolate(fi.reds, fi.greens, fi.blues, nColors); fi.fileName = arg;
/** Opens a LUT and returns it as a LUT object. */ public static LUT openLut(String pathOrURL) { FileInfo fi = new FileInfo(); fi.reds = new byte[256]; fi.greens = new byte[256]; fi.blues = new byte[256]; fi.lutSize = 256; int nColors = 0; if (pathOrURL.contains("://")) { fi.url = pathOrURL; fi.fileName = ""; } else { OpenDialog od = new OpenDialog("Open LUT...", pathOrURL); fi.directory = od.getDirectory(); fi.fileName = od.getFileName(); if (fi.fileName==null) return null; } LutLoader loader = new LutLoader(); boolean ok = loader.openLut(fi); if (ok) return new LUT(fi.reds, fi.greens, fi.blues); else return null; }
createImage(fi, showImage);
/** Opens the specified ImageJ LUT and returns it as an IndexColorModel. Since 1.43t. */ public static IndexColorModel open(String path) throws IOException { return open(new FileInputStream(path)); }
f.read(fi.blues, 0, nColors); if (nColors<256) interpolate(fi.reds, fi.greens, fi.blues, nColors); f.close(); return 256;
void createImage(FileInfo fi, boolean show) { IndexColorModel cm = new IndexColorModel(8, 256, fi.reds, fi.greens, fi.blues); ByteProcessor bp = createImage(cm); setProcessor(fi.fileName, bp); if (show) show(); }
/** Opens an NIH Image LUT, 768 byte binary LUT or text LUT from a file or URL. */ boolean openLut(FileInfo fi) { //IJ.log("openLut: " + fi.directory + fi.fileName); boolean isURL = fi.url!=null && !fi.url.equals(""); int length = 0; String path = isURL?fi.url:fi.directory+fi.fileName; if (!isURL) { File f = new File(path); length = (int)f.length(); if (length>10000) { error(path); return false; } } int size = 0; try { if (length>768) size = openBinaryLut(fi, isURL, false); // attempt to read NIH Image LUT if (size==0 && (length==0||length==768||length==970)) size = openBinaryLut(fi, isURL, true); // otherwise read raw LUT if (size==0 && length>768) size = openTextLut(fi); if (size==0) error(path); } catch (IOException e) { IJ.error("LUT Loader", ""+e); } return size==256; }
/** Opens a lookup table (LUT) and returns it as a LUT object, or returns null if there is an error. * @see ij.ImagePlus#setLut */ public static LUT openLut(String filePathOrUrl) { return LutLoader.openLut(filePathOrUrl); }
createImage(fi, showImage);
private void initialize() { String path = IJ.getDirectory("luts"); List<File> files = IOUtils.listFilesInFolder(new File(path), false); luts = new HashMap<String, LUT>(); for (File f : files) { if (FilenameUtils.getExtension(f.getName()).toLowerCase().equals("lut")) { String lutName = FilenameUtils.removeExtension(f.getName()).replace('_', ' '); LUT lut = LutLoader.openLut(f.getAbsolutePath()); luts.put(lutName, lut); model.addElement(lutName); } } }