// // EnhancementTable.java // /* This source file is part of the edu.wisc.ssec.mcidas package and is Copyright (C) 1998 - 2006 by Tom Whittaker, Tommy Jasmin, Tom Rink, Don Murray, James Kelly, Bill Hibbard, Dave Glowacki, Curtis Rueden and others. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ //package edu.wisc.ssec.mcidas; import java.awt.Color; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.BufferedInputStream; import java.io.IOException; import java.io.File; import java.net.URL; /** * Class for reading a McIDAS enhancement table (.ET file). The default * constructor creates a grey scale enhancement. */ public class EnhancementTable { private int[][] rgbValues = null; private int[] rgbInts = null; private DataInputStream dataStream; public EnhancementTable(URL url) { try { dataStream = new DataInputStream( new BufferedInputStream(url.openStream())); } catch (Exception e) { System.out.println("#### Unable to open enhancement table at URL" + url); } readRGBValues(); } /** * read in the values */ private void readRGBValues() { rgbValues = new int[3][256]; rgbInts = new int[256]; try { int reservedWord = dataStream.readInt(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 256; j++) rgbValues[i][j] = dataStream.readInt(); } for (int j=0; j< 256; j++) { rgbInts[j] = (rgbValues[0][j]<<16) | (rgbValues[1][j] << 8) | rgbValues[2][j]; } } catch (Exception e) { System.out.println("#### Invalid enhancement table"); } } /** * Retrieve the data values. * * @return integer array [3][256] of red, green, blue values or null if * the table was not initialized correctly. Values * range from 0-255. */ public int[][] getRGBValues() { return rgbValues; } /** * Look up a unique (hopefully) RGB value and return the index * * @return index value (0-255) or -1 if not found * */ public int getIndex(int rgb) { int inx; int testval = (rgb & 0xffffff); // ignore alpha for (inx=0; inx<256; inx++) { if (testval == rgbInts[inx]) { return inx; } } return -1; } /** * Print out a pretty table. Currently lists all values, but will * eventually print a format like EU TABLE. * * @return table of levels, red, green and blue values */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append(" Brightness Red Green Blue "); sb.append("\n"); sb.append(" min max min max min max min max"); sb.append("\n"); sb.append(" --- --- --- --- --- --- --- ---"); sb.append("\n"); for (int i = 0; i < 256; i++) { sb.append(" " + i + " " + rgbValues[0][i] + " " + rgbValues[1][i] + " " + rgbValues[2][i]); sb.append("\n"); } return sb.toString(); } }