3 import java.awt.image.*;
8 private int width, height;
10 private int mapSize = 0;
11 private ColorModel cm;
12 private byte[] rLUT, gLUT,bLUT;
16 PixelGrabber pg =
new PixelGrabber(img, 0, 0, 1, 1,
false);
19 cm = pg.getColorModel();
21 catch (InterruptedException e){};
30 void getColors(ColorModel cm) {
31 if (cm instanceof IndexColorModel) {
32 IndexColorModel m = (IndexColorModel)cm;
33 mapSize = m.getMapSize();
34 rLUT =
new byte[mapSize];
35 gLUT =
new byte[mapSize];
36 bLUT =
new byte[mapSize];
43 public int getMapSize() {
47 public byte[] getReds() {
51 public byte[] getGreens() {
55 public byte[] getBlues() {
59 public ColorModel getColorModel() {
67 boolean isGray =
true;
71 for (
int i=0; i<mapSize; i++)
72 if ((rLUT[i] != gLUT[i]) || (gLUT[i] != bLUT[i]))
77 public void drawColorBar(Graphics g,
int x,
int y,
int width,
int height) {
81 double scale = 256.0/mapSize;
82 for (
int i = 0; i<256; i++) {
83 int index = (int)(i/scale);
84 cp.
setColor(
new Color(rLUT[index]&0xff,gLUT[index]&0xff,bLUT[index]&0xff));
88 g.setColor(Color.black);
89 g.drawRect(x, y, width, height);
92 public void drawUnscaledColorBar(ImageProcessor ip,
int x,
int y,
int width,
int height) {
93 ImageProcessor bar = null;
94 if (ip instanceof ColorProcessor)
95 bar =
new ColorProcessor(width, height);
97 bar =
new ByteProcessor(width, height);
99 for (
int i = 0; i < 256; i++) {
100 bar.setColor(
new Color(i, i, i));
101 bar.moveTo(i, 0); bar.lineTo(i, height);
105 for (
int i = 0; i<mapSize; i++) {
106 bar.setColor(
new Color(rLUT[i]&0xff, gLUT[i]&0xff, bLUT[i]&0xff));
107 bar.moveTo(i, 0); bar.lineTo(i, height);
111 ip.setColor(Color.black);
112 ip.drawRect(x-1, y, width+2, height);
115 public static ColorModel createGrayscaleColorModel(
boolean invert) {
116 byte[] rLUT =
new byte[256];
117 byte[] gLUT =
new byte[256];
118 byte[] bLUT =
new byte[256];
120 for(
int i=0; i<256; i++) {
126 for(
int i=0; i<256; i++) {
132 return(
new IndexColorModel(8, 256, rLUT, gLUT, bLUT));