/* Color Chart $Id: ColorChart.java,v 1.5 1996/04/29 03:08:29 ryo2 Exp ryo2 $ */ import java.applet.Applet; import java.awt.*; import java.util.StringTokenizer; import java.io.*; import java.net.URL; import java.net.MalformedURLException; public class ColorChart extends Applet { Color fg, bg, lcol, vcol; TextField blankf, blankb; Checkbox con, coff; ColorBoard cp; ColorMonitor monitor; public void init() { int i, iFontSize = 14, mFontSize = 18, iBarWidth = 10; double dFactor = 0.92; int mSize[]; boolean monitorShow = false; String rgb = "rgb.csv"; Font font, mfont; String s = null, sFont = "Helvetica", mFont ="TimesRoman"; Dimension d = size(); resize(d.width,d.height); Panel topPanel = new Panel(); StringTokenizer st; s = getParameter("monitor"); if (s != null && s.equals("on")) monitorShow = true; s = getParameter("rgb"); if (s != null) rgb = s; s = getParameter("fontsize"); if (s != null) iFontSize = Integer.valueOf(s).intValue(); s = getParameter("font"); if (s != null) sFont = s; font = new Font(sFont,Font.PLAIN,iFontSize); s = getParameter("monitorfont"); if (s != null) mFont = s; s = getParameter("monitorfontsize"); if (s != null) mFontSize = Integer.valueOf(s).intValue(); mfont = new Font(mFont,Font.PLAIN,mFontSize); setFont(font); bg = str2color(getParameter("bgcolor"), "c0|c0|c0"); fg = str2color(getParameter("text"), "00|00|00"); lcol = str2color(getParameter("link"), "00|00|ee"); vcol = str2color(getParameter("vlink"), "55|1a|8b"); s = getParameter("monitorsize"); mSize = new int[2]; if (s == null || (new StringTokenizer(s,"| ,")).countTokens() != 2) { s = "550|680"; } st = new StringTokenizer(s,"| ,"); i = 0; while (st.hasMoreTokens() == true) { mSize[i++] = Integer.parseInt(st.nextToken()); } s = getParameter("bsize-factor"); if (s != null) { st = new StringTokenizer(s,"| ,"); if (st.hasMoreTokens() == true) { iBarWidth = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens() == true) dFactor = Double.valueOf(st.nextToken()).doubleValue(); } } setLayout(new BorderLayout()); topPanel.add(new Label("Monitor")); topPanel.setForeground(fg); topPanel.setBackground(bg); CheckboxGroup cmonitor = new CheckboxGroup(); topPanel.add(con = new Checkbox("ON", cmonitor, monitorShow)); topPanel.add(coff = new Checkbox("OFF", cmonitor, (!monitorShow))); add("North", topPanel); monitor = new ColorMonitor(font, mfont, (ColorChart)this, mSize[0], mSize[1], iBarWidth, dFactor,fg, bg, lcol, vcol); ColorBoard cp = new ColorBoard(this, rgb, fg, bg); add("Center", cp); if (monitorShow) monitor.show(); } public void stop() { monitor.hide(); } public Color str2color(String s, String def) { int sArray[], i; StringTokenizer st; sArray = new int[3]; if (s == null || (new StringTokenizer(s,"| ,")).countTokens() != 3) { s = def; } st = new StringTokenizer(s,"| ,"); i = 0; while (st.hasMoreTokens() == true) { sArray[i++] = Integer.parseInt(st.nextToken(),16); } return new Color(sArray[0],sArray[1],sArray[2]); } public boolean action(Event e, Object arg) { if (e.target instanceof Checkbox) { Checkbox c = (Checkbox)(e.target); if (((Boolean)arg).booleanValue()) { if (c.getLabel().equals("ON")) { monitor.show(); } else { monitor.hide(); } } return true; } return false; } } class ColorBoard extends Panel { Color bg, fg; ColorChart parent; int num = 0, iRGB[]; String sCol[], sName[]; private static final int COLORNUM = 548; public ColorBoard(ColorChart parent, String rgb, Color f, Color b){ this.parent = parent; fg = f; bg = b; int i; sCol = new String[800]; sName = new String[800]; setForeground(fg); setBackground(bg); open(rgb); iRGB = new int[3]; this.setLayout(new GridLayout(110,5,4,0)); for(i = 0; i < COLORNUM; i++) { add(new ColorPanel(parent, iRGB, sName[i], sCol[i], fg)); } } /** * read rgb.csv and set to sCol and sName */ public void open(String fname) { int i; String buf = new String(); StringTokenizer st; String sRGB[]; sRGB = new String[4]; for(i = 0; i < 4; i++) sRGB[i] = new String(); try { InputStream fin = new URL(parent.getDocumentBase(),fname).openStream(); DataInputStream din = new DataInputStream(fin); for(num = 0; num < COLORNUM; num++) { buf = din.readLine(); sCol[num] = buf.substring(0,8); sName[num] = buf.substring(9); } } catch (FileNotFoundException e) { System.err.println("file '"+fname+"'not found."); } catch (IOException e) { System.err.println("Cannot access the file '"+fname+"'."); } } } class ColorPanel extends Panel { ColorChart p; Image image; Color col, fontcol; String sHex, sName; float f[]; Float hue, sat; Double br; public ColorPanel(ColorChart parent, int iRGB[], String nm, String hx, Color fc) { p = parent; StringTokenizer st; fontcol = fc; resize(50,70); image = createImage(30,8); // this.setLayout(new FlowLayout()); sHex = hx; sName = nm; iRGB = new int[3]; st = new StringTokenizer(hx," "); iRGB[0] = Integer.parseInt(st.nextToken(), 16); iRGB[1] = Integer.parseInt(st.nextToken(), 16); iRGB[2] = Integer.parseInt(st.nextToken(), 16); col = new Color(iRGB[0],iRGB[1],iRGB[2]); f = new float[3]; } public void paint(Graphics g) { g.setColor(Color.white); g.drawRect(0,25,50,20); g.setColor(col); g.fillRect(1,26,48,18); g.setColor(fontcol); g.drawString(sName,2,18); g.drawString(sHex,5,62); } public boolean mouseDown(Event evt, int x, int y) { int rightButton; if (y < 24 || y > 46 || x > 50) return false; /* MouseButton modifiers(after JDKb4) (before JKDbeta) * LEFT None Nome * MIDDLE Alt Shift * RIGHT Meta CTRL */ evt.modifiers &= (evt.SHIFT_MASK + evt.ALT_MASK + evt.META_MASK + evt.CTRL_MASK); rightButton = evt.modifiers & (evt.META_MASK + evt.CTRL_MASK); if (evt.modifiers == 0) { p.monitor.blankf.setText(sHex.substring(0,2)+sHex.substring(3,5)+sHex.substring(6)); p.monitor.getHexStrings(); p.monitor.setDecStrings(); p.monitor.redraw(p.monitor.bF, p.monitor.r1.getValue(), p.monitor.g1.getValue(), p.monitor.b1.getValue(), p.monitor.r2.getValue(), p.monitor.g2.getValue(), p.monitor.b2.getValue()); f = col.RGBtoHSB(col.getRed(), col.getGreen(), col.getBlue(), f); p.showStatus("H:"+Float.toString(f[0]*360)+" S:"+Float.toString(f[1]) +" B:"+Float.toString(f[2])); return true; } else { if (rightButton != 0) { p.monitor.blankb.setText(sHex.substring(0,2)+sHex.substring(3,5)+sHex.substring(6)); p.monitor.getHexStrings(); p.monitor.setDecStrings(); p.monitor.redraw(p.monitor.bF, p.monitor.r1.getValue(), p.monitor.g1.getValue(), p.monitor.b1.getValue(), p.monitor.r2.getValue(), p.monitor.g2.getValue(), p.monitor.b2.getValue()); p.showStatus("H:"+Float.toString(f[0]*360)+" S:"+Float.toString(f[1]) +" B:"+Float.toString(f[2])); return true; } } return false; } } class ColorMonitor extends Frame { private final static String FCOLOR = "Foreground Color"; private final static String BCOLOR = "Background Color"; private final static String LCOLOR = "Link Color"; private final static String VCOLOR = "Vlink Color"; private final static String NOFILTER = "No Filter"; private final static String RGCBLIND = "Red-Green Colorblindness"; private final static String RCBLIND = "Red Colorblindness"; private final static String GCBLIND = "Green Colorblindness"; private final static String RGBFILTER = "Red-Green Filter(old)"; private final static String BRIGHT = "Bright"; private final static String DARK = "Dark"; private final static int LBLNUM = 8; String DEF_FCOLOR; /* "000000" */ String DEF_BCOLOR; /* "c0c0c0" */ static int LEFT = 0; static int RIGHT = 1; Button setcol, resetcol; int rgbLt[][], rgbRt[][], ibar; double dFactor; Scrollbar r1, r2, g1, g2, b1, b2, currBar; TextField blankf, blankb, tr1, tr2, tg1, tg2, tb1, tb2; Choice sel, scol1, scol2, currChoice; Label llabel, vlabel, lbl[]; Button lbrigh, ldark, rbrigh, rdark; Panel ph = new Panel(); Panel pr = new Panel(); Panel pg = new Panel(); Panel pb = new Panel(); Panel pl1 = new Panel(); Panel pl2 = new Panel(); Panel pn = new Panel(); Panel pn2 = new Panel(); Panel pn3 = new Panel(); BlindFilter bF; ColorChart parent; String s = new String(); Color defFg, defBg, defLc, defVc, currCol, nextCol; public ColorMonitor(Font font, Font mfont, ColorChart parent, int width, int height, int barwidth, double factor, Color fg, Color bg, Color lcol, Color vcol) { this.parent = parent; lbl = new Label[LBLNUM]; defFg = fg; defBg = bg; defLc = lcol; defVc = vcol; ibar = barwidth; dFactor = factor; rgbLt = new int[2][]; rgbRt = new int[2][]; rgbLt[0] = new int[3]; rgbLt[1] = new int[3]; rgbRt[0] = new int[3]; rgbRt[1] = new int[3]; col2int(rgbLt[0], fg); col2int(rgbLt[1], lcol); col2int(rgbRt[0], bg); col2int(rgbRt[1], vcol); DEF_FCOLOR = Integer.toString(fg.getRGB() & 0xffffff, 16); DEF_BCOLOR = Integer.toString(bg.getRGB() & 0xffffff, 16); setFont(font); setLayout(new GridLayout(LBLNUM + 8, 1, 0, 0)); resize(width, height); pr.setLayout(new GridLayout(2, 2, 10, 0)); pg.setLayout(new GridLayout(2, 2, 10, 0)); pb.setLayout(new GridLayout(2, 2, 10, 0)); ph.add(scol1 = new Choice()); scol1.addItem(FCOLOR); scol1.addItem(LCOLOR); ph.add(blankf = new TextField(DEF_FCOLOR, 7)); ph.add(scol2 = new Choice()); scol2.addItem(BCOLOR); scol2.addItem(VCOLOR); ph.add(blankb = new TextField(DEF_BCOLOR, 7)); pr.add(new Label(" (R)", Label.LEFT)); pr.add(new Label(" (R)", Label.LEFT)); pg.add(new Label(" (G)", Label.LEFT)); pg.add(new Label(" (G)", Label.LEFT)); pb.add(new Label(" (B)", Label.LEFT)); pb.add(new Label(" (B)", Label.LEFT)); pr.add(r1 = new Scrollbar(Scrollbar.HORIZONTAL, 0, ibar, 0, 255)); pg.add(g1 = new Scrollbar(Scrollbar.HORIZONTAL, 0, ibar, 0, 255)); pb.add(b1 = new Scrollbar(Scrollbar.HORIZONTAL, 0, ibar, 0, 255)); pr.add(r2 = new Scrollbar(Scrollbar.HORIZONTAL, 192, ibar, 0, 255)); pg.add(g2 = new Scrollbar(Scrollbar.HORIZONTAL, 192, ibar, 0, 255)); pb.add(b2 = new Scrollbar(Scrollbar.HORIZONTAL, 192, ibar, 0, 255)); pn.add(new Label("Foreground",Label.LEFT)); pn.add(tr1 = new TextField("", 3)); pn.add(tg1 = new TextField("", 3)); pn.add(tb1 = new TextField("", 3)); pn.add(new Label(" Background",Label.LEFT)); pn.add(tr2 = new TextField("", 3)); pn.add(tg2 = new TextField("", 3)); pn.add(tb2 = new TextField("", 3)); pn2.add(lbrigh = new Button(BRIGHT)); pn2.add(ldark = new Button(DARK)); pn2.add(rbrigh = new Button(BRIGHT)); pn2.add(rdark = new Button(DARK)); pn3.add(setcol = new Button(" SET COLOR ")); pn3.add(resetcol = new Button(" RESET ")); pn3.add(sel = new Choice()); sel.addItem(NOFILTER); sel.addItem(RGCBLIND); sel.addItem(RCBLIND); sel.addItem(GCBLIND); sel.addItem(RGBFILTER); add(ph); add(pr); add(pg); add(pb); add(pn); add(pn2); add(pn3); rgbLR2Bar(LEFT, 0); rgbLR2Bar(RIGHT, 0); setDecStrings(); setFont(mfont); add(lbl[0] = new Label(" ------------------------------------------------------", Label.LEFT)); add(lbl[1] = new Label(" Color Monitor",Label.LEFT)); add(lbl[2] = new Label(" ------------------------------------------------------", Label.LEFT)); add(lbl[3] = new Label(" Push mouse LEFT button on the color box makes charactors color", Label.LEFT)); add(lbl[4] = new Label(" change, and RIGHT button makes background color change.", Label.LEFT)); add(lbl[5] = new Label(" Fill the HEXadecimal code(RRGGBB) in the blanks, hit ENTER key,", Label.LEFT)); add(lbl[6] = new Label(" and you can get those colors. Pull down choice is for the simulation", Label.LEFT)); add(lbl[7] = new Label(" of red-green color blindness. You can set ", Label.LEFT)); pl1.add(llabel = new Label("unfollowed link color")); pl1.add(new Label(" and ")); pl1.add(vlabel = new Label("visited link color")); pl1.add(new Label(" on some browser.")); llabel.setForeground(lcol); vlabel.setForeground(vcol); add(pl1); setForeground(defFg); setBackground(defBg); bF = new BlindFilter(); redraw(bF, rgbLt[0][0], rgbLt[0][1], rgbLt[0][2], rgbRt[0][0], rgbRt[0][1], rgbRt[0][2]); setTitle("Color Monitor"); } public void setMonoColor(TextField t) { t.setForeground(Color.black); t.setBackground(Color.white); } public boolean handleEvent(Event e) { if (e.target == r1) { tr1.setText(Integer.toString(r1.getValue())); } else if (e.target == g1) { tg1.setText(Integer.toString(g1.getValue())); } else if (e.target == b1) { tb1.setText(Integer.toString(b1.getValue())); } else if (e.target == r2) { tr2.setText(Integer.toString(r2.getValue())); } else if (e.target == g2) { tg2.setText(Integer.toString(g2.getValue())); } else if (e.target == b2) { tb2.setText(Integer.toString(b2.getValue())); } else { return super.handleEvent(e); } setHexStrings(); return true; } public boolean action(Event e, Object arg) { int i, j; if (e.target instanceof TextField || e.target instanceof Button) { if ((e.target == blankf) || (e.target == blankb)) { if ("".equals(blankf.getText().trim())) { blankf.setText(DEF_FCOLOR); } if ("".equals(blankb.getText().trim())) { blankb.setText(DEF_BCOLOR); } getHexStrings(); setDecStrings(); redraw(bF, r1.getValue(),g1.getValue(),b1.getValue(), r2.getValue(),g2.getValue(),b2.getValue()); } else { if (e.target == resetcol) { col2int(rgbLt[0], defFg); col2int(rgbLt[1], defLc); col2int(rgbRt[0], defBg); col2int(rgbRt[1], defVc); // scol1.select(0); scol2.select(0); if (scol1.getSelectedItem().equals(FCOLOR)) rgbLR2Bar(LEFT, 0); else rgbLR2Bar(LEFT, 1); if (scol2.getSelectedItem().equals(BCOLOR)) rgbLR2Bar(RIGHT, 0); else rgbLR2Bar(RIGHT, 1); } else if (e.target == setcol) { if (e.target == tr1 || e.target instanceof Button) getnum(r1, tr1); if (e.target == tg1 || e.target instanceof Button) getnum(g1, tg1); if (e.target == tb1 || e.target instanceof Button) getnum(b1, tb1); if (e.target == tr2 || e.target instanceof Button) getnum(r2, tr2); if (e.target == tg2 || e.target instanceof Button) getnum(g2, tg2); if (e.target == tb2 || e.target instanceof Button) getnum(b2, tb2); } else { /* if (BRIGHT.equals(arg) || DARK.equals(arg)) */ if (e.target == lbrigh || e.target == ldark) { j = 1; currCol = new Color(r1.getValue(),g1.getValue(),b1.getValue()); } else { j = 2; currCol = new Color(r2.getValue(),g2.getValue(),b2.getValue()); } if (BRIGHT.equals(arg)) { if (currCol.equals(Color.black)) nextCol = new Color(12, 12, 12); else nextCol = brighter(currCol); } else { nextCol = darker(currCol); } i = 0; if (j == 1) { if (scol1.getSelectedItem().equals(LCOLOR)) i++; col2int(rgbLt[i], nextCol); rgbLR2Bar(LEFT, i); } else { if (scol2.getSelectedItem().equals(VCOLOR)) i++; col2int(rgbRt[i], nextCol); rgbLR2Bar(RIGHT, i); } setDecStrings(); } setHexStrings(); redraw(bF, r1.getValue(),g1.getValue(),b1.getValue(), r2.getValue(),g2.getValue(),b2.getValue()); return true; } } else if (e.target instanceof Choice) { if (bF.isLabel((String)arg)) { redraw(bF, r1.getValue(),g1.getValue(),b1.getValue(), r2.getValue(),g2.getValue(),b2.getValue()); } else { if (e.target == scol1) { if (((String)arg).equals(FCOLOR)) rgbLR2Bar(LEFT, 0); else rgbLR2Bar(LEFT, 1); setHexStrings(); setDecStrings(); } else if (e.target == scol2) { if (((String)arg).equals(BCOLOR)) rgbLR2Bar(RIGHT, 0); else rgbLR2Bar(RIGHT, 1); setHexStrings(); setDecStrings(); } } return true; } return false; } /** * %x to %02x */ public String hex2(String s) { if (s.length() == 1) s = "0" +s; return s; } /** * get decimal-number strings from Textfield */ public void getnum(Scrollbar s, TextField t) { int i; try { i = Integer.parseInt(t.getText()); } catch (NumberFormatException ex){ i = s.getValue(); } if (i < 0 || i > 255) i = s.getValue(); t.setText(Integer.toString(i)); s.setValue(i); } /** * read value of scrollbar and set decical field */ public void setDecStrings() { tr1.setText(Integer.toString(r1.getValue())); tg1.setText(Integer.toString(g1.getValue())); tb1.setText(Integer.toString(b1.getValue())); tr2.setText(Integer.toString(r2.getValue())); tg2.setText(Integer.toString(g2.getValue())); tb2.setText(Integer.toString(b2.getValue())); } /** * read value of scrollbar and set hexadecical field */ public void setHexStrings() { s = hex2(Integer.toString(r1.getValue(), 16)) + hex2(Integer.toString(g1.getValue(), 16)) + hex2(Integer.toString(b1.getValue(), 16)); blankf.setText(s); s = hex2(Integer.toString(r2.getValue(), 16)) + hex2(Integer.toString(g2.getValue(), 16)) + hex2(Integer.toString(b2.getValue(), 16)); blankb.setText(s); } /** * read hexadecical field and set scrollbar */ public void getHexStrings() { String f, b; f = blankf.getText().trim(); b = blankb.getText().trim(); r1.setValue(Integer.parseInt(f.substring(0,2),16)); g1.setValue(Integer.parseInt(f.substring(2,4),16)); b1.setValue(Integer.parseInt(f.substring(4),16)); r2.setValue(Integer.parseInt(b.substring(0,2),16)); g2.setValue(Integer.parseInt(b.substring(2,4),16)); b2.setValue(Integer.parseInt(b.substring(4),16)); } public void redraw(BlindFilter bF, int r1, int g1, int b1, int r2, int g2, int b2) { int i, newL0[], newL1[], newR0[], newR1[]; newL0 = new int[3]; newL1 = new int[3]; newR0 = new int[3]; newR1 = new int[3]; if (bF.mode == 0) { newL0[0] = r1; newL0[1] = g1; newL0[2] = b1; newR0[0] = r2; newR0[1] = g2; newR0[2] = b2; bF.bcfilter(rgbLt[1], newL1); bF.bcfilter(rgbRt[1], newR1); } else { bF.bcfilter(rgbLt[0],newL0); bF.bcfilter(rgbLt[1],newL1); bF.bcfilter(rgbRt[0],newR0); bF.bcfilter(rgbRt[1],newR1); } ph.setForeground(defFg); setMonoColor(tr1); setMonoColor(tg1); setMonoColor(tb1); setMonoColor(tr2); setMonoColor(tg2); setMonoColor(tb2); setMonoColor(blankf); setMonoColor(blankb); if (scol1.getSelectedItem().equals(FCOLOR)) { for(i = 0; i < LBLNUM; i++) { lbl[i].setForeground(new Color(newL0[0], newL0[1], newL0[2])); } rgbLt[0][0] = r1; rgbLt[0][1] = g1; rgbLt[0][2] = b1; pl1.setForeground(new Color(newL0[0], newL0[1], newL0[2])); llabel.setForeground(new Color(newL1[0], newL1[1], newL1[2])); } else { rgbLt[1][0] = r1; rgbLt[1][1] = g1; rgbLt[1][2] = b1; llabel.setForeground(new Color(newL0[0], newL0[1], newL0[2])); } if (scol2.getSelectedItem().equals(BCOLOR)) { for(i = 0; i < LBLNUM; i++) { lbl[i].setBackground(new Color(newR0[0], newR0[1], newR0[2])); } rgbRt[0][0] = r2; rgbRt[0][1] = g2; rgbRt[0][2] = b2; pl1.setBackground(new Color(newR0[0], newR0[1], newR0[2])); vlabel.setForeground(new Color(newR1[0], newR1[1], newR1[2])); } else { rgbRt[1][0] = r2; rgbRt[1][1] = g2; rgbRt[1][2] = b2; vlabel.setForeground(new Color(newR0[0], newR0[1], newR0[2])); } } /** * convert color value to integer array */ public void col2int(int i[], Color col) { i[0] = col.getRed(); i[1] = col.getGreen(); i[2] = col.getBlue(); } /** * set RGB-integer to scrollbar * i = 0:Left 1:Right, j = use rgb[Lt|Rt][j] */ public void rgbLR2Bar(int side, int sel) { if (side == LEFT) { r1.setValue(rgbLt[sel][0]); g1.setValue(rgbLt[sel][1]); b1.setValue(rgbLt[sel][2]); } else { r2.setValue(rgbRt[sel][0]); g2.setValue(rgbRt[sel][1]); b2.setValue(rgbRt[sel][2]); } } // private static final double FACTOR = 0.92; public Color brighter(Color c) { return new Color(Math.min((int)(c.getRed() *(1/dFactor)), 255), Math.min((int)(c.getGreen()*(1/dFactor)), 255), Math.min((int)(c.getBlue() *(1/dFactor)), 255)); } public Color darker(Color c) { return new Color(Math.max((int)(c.getRed() *dFactor), 0), Math.max((int)(c.getGreen()*dFactor), 0), Math.max((int)(c.getBlue() *dFactor), 0)); } } class BlindFilter { int mode; private final static String NOFILTER = "No Filter"; private final static String RGCBLIND = "Red-Green Colorblindness"; private final static String RCBLIND = "Red Colorblindness"; private final static String GCBLIND = "Green Colorblindness"; private final static String RGBFILTER = "Red-Green Filter(old)"; String lbl; float f[]; /* f[0]=hue f[1]=saturation f[2]=brightness */ public BlindFilter() { mode = 0; lbl = toString(mode); f = new float[3]; } public boolean isLabel(String s) { if (s.equals(NOFILTER)) { mode = 0; } else if (s.equals(RGCBLIND)) { mode = 1; } else if (s.equals(RCBLIND)) { mode = 2; } else if (s.equals(GCBLIND)) { mode = 3; } else if (s.equals(RGBFILTER)) { mode = 4; } else { return false; } return true; } public String toString(int mode) { switch (mode) { case 0: return NOFILTER; case 1: return RGCBLIND; case 2: return RCBLIND; case 3: return GCBLIND; case 4: return RGBFILTER; } return null; } public void bcfilter(int[] source, int[] dest) { int i; switch (mode) { case 0: dest[0] = source[0]; dest[1] = source[1]; dest[2] = source[2]; break; case 1: f = Color.RGBtoHSB(source[0], source[1], source[2], f); if (f[0] > 0.9305556 || f[0] < 0.06944444) { if (f[0] < 0.5) f[0] += 0.5; else f[0] -= 0.5; } else if (f[0] > 0.2638889 && f[0] < 0.4027778) { f[0] += 0.5; } hsb2rgb(f, dest); break; case 2: f = Color.RGBtoHSB(source[0], source[1], source[2], f); if (f[0] > 0.9305556 || f[0] < 0.06944444) { if (f[0] < 0.5) f[0] += 0.5; else f[0] -= 0.5; } hsb2rgb(f, dest); break; case 3: f = Color.RGBtoHSB(source[0], source[1], source[2], f); if (f[0] > 0.2638889 && f[0] < 0.4027778) { f[0] += 0.5; } hsb2rgb(f, dest); break; case 4: dest[0] = (int)((source[0] + source[1]) /2) ; dest[1] = dest[0]; dest[2] = source[2]; break; } } private void hsb2rgb(float[] f, int[] dest) { int i; i = Color.HSBtoRGB(f[0], f[1], f[2]) & 0xffffff; dest[0] = i >> 16; dest[1] = (i & 0x00ff00) >> 8; dest[2] = i & 0xff; } }