Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

ColorMap.java

00001 package com.meapsoft.gui;
00002 
00003 /*
00004  * Copyright 1999-2004 Carnegie Mellon University.  
00005  * Portions Copyright 2002-2004 Sun Microsystems, Inc.  
00006  * Portions Copyright 2002-2004 Mitsubishi Electric Research Laboratories.
00007  * All Rights Reserved.  Use is subject to license terms.
00008  * 
00009  * See the file "README" for information on usage and
00010  * redistribution of this file, and for a DISCLAIMER OF ALL 
00011  * WARRANTIES.
00012  *
00013  */
00014 
00015 import java.util.Arrays;
00016 import java.awt.Color;
00017 
00025 public class ColorMap
00026 {
00027     public int size;
00028     public byte r[];
00029     public byte g[];
00030     public byte b[];
00031     public Color table[];
00032 
00036     public static ColorMap getJet()
00037     {
00038         return getJet(64);
00039     }
00040 
00045     public static ColorMap getJet(int n)
00046     {
00047         byte r[] = new byte[n];
00048         byte g[] = new byte[n];
00049         byte b[] = new byte[n];
00050         
00051         int maxval = 255;
00052         //Arrays.fill(g, 0, 8, (byte)0);
00053         Arrays.fill(g, 0, n/8, (byte)0);
00054         //for(int x = 0; x < 16; x++)
00055         //    g[x+8] = (byte)(maxval*x/16);
00056         for(int x = 0; x < n/4; x++)
00057             g[x+n/8] = (byte)(maxval*x*4/n);
00058         //Arrays.fill(g, 24, 40, (byte)maxval);
00059         Arrays.fill(g, n*3/8, n*5/8, (byte)maxval);
00060         //for(int x = 0; x < 16; x++)
00061         //    g[x+40] = (byte)(maxval-(maxval*x/16));
00062         for(int x = 0; x < n/4; x++)
00063             g[x+n*5/8] = (byte)(maxval-(maxval*x*4/n));
00064         //Arrays.fill(g, 56, 64, (byte)0);
00065         Arrays.fill(g, n*7/8, n, (byte)0);
00066 
00067         //for(int x = 0; x < g.length; x++)
00068         //    b[x] = g[(x+16) % g.length];
00069         for(int x = 0; x < g.length; x++)
00070             b[x] = g[(x+n/4) % g.length];
00071         //Arrays.fill(b, 56, 64, (byte)0);
00072         Arrays.fill(b, n*7/8, n, (byte)0);
00073         //Arrays.fill(g, 0, 8, (byte)0);
00074         Arrays.fill(g, 0, n/8, (byte)0);
00075         //for(int x = 8; x < g.length; x++)
00076         //    r[x] = g[(x+48) % g.length];
00077         for(int x = n/8; x < g.length; x++)
00078             r[x] = g[(x+n*6/8) % g.length];
00079         
00080         ColorMap cm = new ColorMap();
00081         cm.size = n;
00082         cm.r = r;
00083         cm.g = g;
00084         cm.b = b;
00085         cm.table = new Color[n];
00086         for(int x = 0; x < n; x++)
00087             //cm.table[x] = new Color((int)r[x]+maxval/2+1,
00088             //(int)g[x]+maxval/2+1, (int)b[x]+maxval/2+1);
00089             cm.table[x] = new Color(cm.getColor(x));
00090         return cm;
00091     }
00092 
00093 
00097     public int getColor(int idx)
00098     {
00099         int pixel = ((r[idx] << 16) & 0xff0000)
00100             | ((g[idx] << 8) & 0xff00)
00101             | (b[idx] & 0xff);
00102 
00103         return pixel;
00104     }
00105 
00106     public String toString()
00107     {
00108         StringBuffer s = new StringBuffer(500);
00109         for(int x = 0; x < size; x++)
00110         {
00111             s.append(x+": {"+r[x]+",\t"+g[x]+",\t"+b[x]+"}\t");
00112             if(x%3 == 2)
00113                 s.append("\n");
00114         }
00115 
00116         return s.toString();
00117     }
00118 
00119     public static void main(String[] args)
00120     {
00121         ColorMap jet = getJet();
00122         ColorMap jet128 = getJet(128);
00123 
00124         
00125         System.out.println("Jet:\n"+jet+"\n\nJet128:\n"+jet128);
00126     }
00127 }

Generated on Tue Feb 6 19:02:24 2007 for MEAPsoft by doxygen1.2.18