00001 package com.meapsoft.gui;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00053 Arrays.fill(g, 0, n/8, (byte)0);
00054
00055
00056 for(int x = 0; x < n/4; x++)
00057 g[x+n/8] = (byte)(maxval*x*4/n);
00058
00059 Arrays.fill(g, n*3/8, n*5/8, (byte)maxval);
00060
00061
00062 for(int x = 0; x < n/4; x++)
00063 g[x+n*5/8] = (byte)(maxval-(maxval*x*4/n));
00064
00065 Arrays.fill(g, n*7/8, n, (byte)0);
00066
00067
00068
00069 for(int x = 0; x < g.length; x++)
00070 b[x] = g[(x+n/4) % g.length];
00071
00072 Arrays.fill(b, n*7/8, n, (byte)0);
00073
00074 Arrays.fill(g, 0, n/8, (byte)0);
00075
00076
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
00088
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 }