@NotNull public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) { float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); final BufferedImage image = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT); final Graphics2D g = image.createGraphics(); source.paintIcon(null, g, 0, 0); g.dispose(); final BufferedImage img = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT); int[] rgba = new int[4]; float[] hsb = new float[3]; for (int y = 0; y < image.getRaster().getHeight(); y++) { for (int x = 0; x < image.getRaster().getWidth(); x++) { image.getRaster().getPixel(x, y, rgba); if (rgba[3] != 0) { Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb); int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]); img.getRaster() .setPixel(x, y, new int[] {rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3]}); } } } return createImageIcon(img); }
public static WritableRaster glowmask(Raster img) { Coord sz = imgsz(img); int nb = img.getNumBands(); WritableRaster ret = alpharaster(sz); float[] hsv = new float[3]; float max = 0; for (int y = 0; y < sz.y; y++) { for (int x = 0; x < sz.x; x++) { Color.RGBtoHSB(img.getSample(x, y, 0), img.getSample(x, y, 1), img.getSample(x, y, 2), hsv); float a = (nb > 3) ? (img.getSample(x, y, 3) / 255f) : 1f; float val = ((1f - hsv[1]) * hsv[2]) * a; max = Math.max(max, val); } } float imax = 1f / max; for (int y = 0; y < sz.y; y++) { for (int x = 0; x < sz.x; x++) { Color.RGBtoHSB(img.getSample(x, y, 0), img.getSample(x, y, 1), img.getSample(x, y, 2), hsv); float a = (nb > 3) ? (img.getSample(x, y, 3) / 255f) : 1f; float val = ((1f - hsv[1]) * hsv[2]) * a; ret.setSample(x, y, 0, Math.min(Math.max((int) (Math.sqrt(val * imax) * 255), 0), 255)); } } return (ret); }
public void composeRGB(int[] src, int[] dst, float alpha) { int w = src.length; for (int i = 0; i < w; i += 4) { int sr = src[i]; int dir = dst[i]; int sg = src[i + 1]; int dig = dst[i + 1]; int sb = src[i + 2]; int dib = dst[i + 2]; int sa = src[i + 3]; int dia = dst[i + 3]; int dor, dog, dob; Color.RGBtoHSB(sr, sg, sb, sHSB); Color.RGBtoHSB(dir, dig, dib, dHSB); dHSB[0] = sHSB[0]; int doRGB = Color.HSBtoRGB(dHSB[0], dHSB[1], dHSB[2]); dor = (doRGB & 0xff0000) >> 16; dog = (doRGB & 0xff00) >> 8; dob = (doRGB & 0xff); float a = alpha * sa / 255f; float ac = 1 - a; dst[i] = (int) (a * dor + ac * dir); dst[i + 1] = (int) (a * dog + ac * dig); dst[i + 2] = (int) (a * dob + ac * dib); dst[i + 3] = (int) (sa * alpha + dia * ac); } }
public static Color getComplementaryColor(final Color color1) { final Color complement = new Color( COLOR_RANGE_MAX - color1.getRed(), COLOR_RANGE_MAX - color1.getGreen(), COLOR_RANGE_MAX - color1.getBlue()); final float[] hsb = Color.RGBtoHSB(color1.getRed(), color1.getGreen(), color1.getBlue(), null); final float[] cHSB = Color.RGBtoHSB(complement.getRed(), complement.getGreen(), complement.getBlue(), null); if (hsb[2] > 0.7f) return Color.getHSBColor(cHSB[0], 1.0f - hsb[1], 0f); else return Color.getHSBColor(cHSB[0], 1.0f - hsb[1], 1.0f); }
public double getBrightness() { java.awt.Color col = new java.awt.Color( (float) getRed(), (float) getGreen(), (float) getBlue(), (float) getAlpha()); float[] comps = java.awt.Color.RGBtoHSB(col.getRed(), col.getGreen(), col.getBlue(), null); return comps[2]; }
/** * Much of this code is copied from GlyphPainter1's implementation. * * @see javax.swing.text.GlyphView.GlyphPainter#paint(javax.swing.text.GlyphView, * java.awt.Graphics, java.awt.Shape, int, int) */ @Override public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) { sync(v); Segment text; TabExpander expander = v.getTabExpander(); Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds(); // determine the x coordinate to render the glyphs int x = alloc.x; int p = v.getStartOffset(); if (p != p0) { text = v.getText(p, p0); int width = Utilities.getTabbedTextWidth(text, metrics, x, expander, p); x += width; } // endif // determine the y coordinate to render the glyphs int y = alloc.y + metrics.getHeight() - metrics.getDescent(); // Calculate the background highlight, it gets painted first. Color bg = TwoToneTextPane.getTwoToneColor(v.getElement().getAttributes()); Color fg = g.getColor(); if (bg == null) { // No color set, guess black or white float[] hsb = Color.RGBtoHSB(fg.getRed(), fg.getGreen(), fg.getBlue(), null); bg = hsb[2] > 0.7 ? Color.BLACK : Color.WHITE; } // endif g.setColor(bg); // render the glyphs, first in bg highlight, then in fg text = v.getText(p0, p1); g.setFont(metrics.getFont()); Utilities.drawTabbedText(text, x + HORIZONTAL_OFFSET, y + VERTICAL_OFFSET, g, expander, p0); g.setColor(fg); Utilities.drawTabbedText(text, x, y, g, expander, p0); }
/** * Compute a contrasting background color to draw the label's outline. * * @param color Label color. * @return A color that contrasts with {@code color}. */ protected Color computeBackgroundColor(Color color) { float[] colorArray = new float[4]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), colorArray); if (colorArray[2] > 0.5) return new Color(0, 0, 0, 0.7f); else return new Color(1, 1, 1, 0.7f); }
public boolean isValidRedPixel(int red, int green, int blue) { float[] hsbvals = new float[3]; hsbvals = Color.RGBtoHSB(red, green, blue, hsbvals); int hue = (int) (255 * hsbvals[0]); int sat = (int) (255 * hsbvals[1]); int val = (int) (255 * hsbvals[2]); // Green! if (hue > 60 && hue < 100 && sat >= 200 && val >= 100) return true; // GREEN? // if (hue > 85 && hue < 110) return true; // if (hue < 15 || hue > 240) return true; // if((hue < 10 || hue > 240) && sat >= 150 && sat <=180 && val >= 95 && val <=120) // return true; // if(hue >= 140 && hue <= 160 && sat >= 190 && sat <=205 && val >=160 && val <=170) // return true; // if (hue < 15 && sat >= 185 && sat <= 205 && val >= 165 && val <= 190) return true; // if (hue > 120 && hue <= 140 && sat >= 140 && sat <= 160 && val >= 215 && val <= 235) return // true; // if ((hue <= 15 || hue > 240) && sat >= 100 && val >= 10) return true; return false; }
private float[] toHSB(FlatColor color) { java.awt.Color col = new java.awt.Color( (float) color.getRed(), (float) color.getGreen(), (float) color.getBlue(), 1.0f); float[] comps = java.awt.Color.RGBtoHSB(col.getRed(), col.getGreen(), col.getBlue(), null); return comps; }
/** * Segment out a blob from the src image (if a good candidate exists). * * <p><code>dest</code> is a packed RGB image for a java image drawing routine. If it's not null, * the blob is highlighted. * * @param src the source RGB image, not packed * @param dest the destination RGB image, packed, may be null */ public void apply(Image src, Image dest) { stepTiming(); // monitors the frame rate // Begin Student Code boolean hsb = true; int h = src.getHeight(); int w = src.getWidth(); int ht = h / 10; int wt = w / 10; // int ht_start = h / 2 - ht / 2; // int wt_start = w / 2 - wt / 2; int ht_start = 0; int wt_start = 0; int[] colors = new int[3]; // Determine the average rgb/hsb pixel values in the upper left hand corner for (int x = wt_start; x < wt_start + wt; x++) { for (int y = ht_start; y < ht_start + ht; y++) { int red = src.getPixelRed(x, y) & 0xff; int green = src.getPixelGreen(x, y) & 0xff; int blue = src.getPixelBlue(x, y) & 0xff; if (!hsb) { colors[0] += red; colors[1] += green; colors[2] += blue; } else { float[] hsbvals = new float[3]; Color.RGBtoHSB(red, green, blue, hsbvals); colors[0] += (int) (hsbvals[0] * 255); colors[1] += (int) (hsbvals[1] * 255); colors[2] += (int) (hsbvals[2] * 255); } } } colors[0] = colors[0] / (ht * wt); colors[1] = colors[1] / (ht * wt); colors[2] = colors[2] / (ht * wt); if (!hsb) { System.out.println("Upper left in RGB: " + colors[0] + ", " + colors[1] + ", " + colors[2]); } else { System.out.println("Upper left in HSB: " + colors[0] + ", " + colors[1] + ", " + colors[2]); } blobPresent(src, dest); // Comment out the next two lines to display the histogram overlayed over the src image // dest.setPixelArray(src.toArray()); // Histogram.getHistogram(src, dest, hsb); // System.out.println("In apply!"); // End Student Code }
public int getHue(int x, int y) { int red = getPixelRed(x, y) & 0xff; int green = getPixelGreen(x, y) & 0xff; int blue = getPixelBlue(x, y) & 0xff; float[] hsbvals = new float[3]; hsbvals = Color.RGBtoHSB(red, green, blue, hsbvals); return (int) (255 * hsbvals[0]); }
/** * Computes and returns a Color that is slightly brighter than the specified Color. * * @param color the color used as basis for the brightened color * @param factor the factor used to compute the brightness * @return a slightly brighter color */ public static Color getSlightlyBrighter(Color color, float factor) { float[] hsbValues = new float[3]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbValues); float hue = hsbValues[0]; float saturation = hsbValues[1]; float brightness = hsbValues[2]; float newBrightness = Math.min(brightness * factor, 1.0f); return Color.getHSBColor(hue, saturation, newBrightness); }
/** * Conversion from RGB into HSB color space. * * <p>This method simply calls the <code>RGBtoHSB</code> method containing in the jre, in the * <code>java.awt.Color</code>-class. * * @see java.awt.Color#RGBtoHSB(int, int, int, float[]) * @param rgbColor The array of red/green/blue-parts as ints. * @return The array of float containing the hue/saturation/brightness-parts in the range <code> * 0.0 : 1.0</code>. */ private float[] rgbToHSB_JRE(final int[] rgbColor) { assert rgbColor != null; return Color.RGBtoHSB( rgbColor[RED_COMPONENT_INDEX], rgbColor[GREEN_COMPONENT_INDEX], rgbColor[BLUE_COMPONENT_INDEX], null); }
@Override public BufferedImage doTransform(BufferedImage src, BufferedImage dest) { int hueP = hue.getValue(); int satP = saturation.getValue(); int briP = brightness.getValue(); if ((hueP == 0) && (satP == 0) && (briP == 0)) { return src; } float satShift = saturation.getValueAsPercentage(); float briShift = brightness.getValueAsPercentage(); float hueShift = hue.getValueAsFloat() / 360.0f; int[] srcData = ImageUtils.getPixelsAsArray(src); int[] destData = ImageUtils.getPixelsAsArray(dest); int length = srcData.length; assert length == destData.length; float[] tmpHSBArray = {0.0f, 0.0f, 0.0f}; for (int i = 0; i < length; i++) { int rgb = srcData[i]; int a = rgb & 0xFF000000; int r = (rgb >>> 16) & 0xFF; int g = (rgb >>> 8) & 0xFF; int b = (rgb) & 0xFF; tmpHSBArray = Color.RGBtoHSB(r, g, b, tmpHSBArray); float shiftedHue = tmpHSBArray[0] + hueShift; float shiftedSat = tmpHSBArray[1] + satShift; float shiftedBri = tmpHSBArray[2] + briShift; if (shiftedSat < 0.0f) { shiftedSat = 0.0f; } if (shiftedSat > 1.0f) { shiftedSat = 1.0f; } if (shiftedBri < 0.0f) { shiftedBri = 0.0f; } if (shiftedBri > 1.0f) { shiftedBri = 1.0f; } int newRGB = Color.HSBtoRGB(shiftedHue, shiftedSat, shiftedBri); // alpha is 255 here newRGB &= 0x00FFFFFF; // set alpha to 0 destData[i] = a | newRGB; // add the real alpha } return dest; }
public void select(int x, int y) { ArrayList<Point> points = new ArrayList<Point>(); points.add(new Point(x, y)); Color origin = new Color(buffer.getRGB(x, y)); float[] ori = Color.RGBtoHSB(origin.getRed(), origin.getGreen(), origin.getBlue(), null); while (!points.isEmpty()) { Point p = points.remove(0); Color cur = new Color(buffer.getRGB(p.x, p.y)); Color alt = new Color(contBuffer.getRGB(p.x, p.y)); float[] c = Color.RGBtoHSB(cur.getRed(), cur.getGreen(), cur.getBlue(), null); if (!cur.equals(alt) && c[2] > 0.5) { buffer.setRGB(p.x, p.y, contBuffer.getRGB(p.x, p.y)); if (p.x > 0) points.add(new Point(p.x - 1, p.y)); if (p.x < buffer.getWidth() - 1) points.add(new Point(p.x + 1, p.y)); if (p.y > 0) points.add(new Point(p.x, p.y - 1)); if (p.y < buffer.getHeight() - 1) points.add(new Point(p.x, p.y + 1)); } } }
private int getBinForHSB(int rgb, float[] hsbvals) { final int r = (rgb & 0xFF0000) >> 16, g = (rgb & 0x00FF00) >> 8, b = (rgb & 0x0000FF); // TODO: AWT Color.RGBtoHSB can be sped up numerically Color.RGBtoHSB(r, g, b, hsbvals); // The values returned by RGBtoHSB are all in [0:1] int h = Math.min((int) Math.floor(binX * hsbvals[0]), binX - 1); int s = Math.min((int) Math.floor(binY * hsbvals[1]), binY - 1); int v = Math.min((int) Math.floor(binZ * hsbvals[2]), binZ - 1); return h * binY * binZ + s * binZ + v; }
public static float[] getHSB(Color color) { float[] rgb = new float[4]; float[] hsb = new float[3]; color.getComponents(rgb); int r = (int) (rgb[0] * 256); int g = (int) (rgb[1] * 256); int b = (int) (rgb[2] * 256); Color.RGBtoHSB(r, g, b, hsb); return hsb; }
static { RAINBOW_COLOUR_0 = Color.decode("#8A56E2"); RAINBOW_BASE_HSB = new float[3]; Color.RGBtoHSB( RAINBOW_COLOUR_0.getRed(), RAINBOW_COLOUR_0.getGreen(), RAINBOW_COLOUR_0.getBlue(), RAINBOW_BASE_HSB); }
/** * Method which determines the color that the place p, should get depending on its average waiting * time. This color is returned as String in dot-form * * @param p ExtendedPlace: the place to be colored * @return String */ private String determinePlaceColor(ExtendedPlace p) { String temp = "fillcolor="; // paint places according to their waiting time level: double bnd0 = 0, bnd1 = 0, wait = 0; Color col0, col1, col2; if (p.hasSettings()) { bnd0 = ((Double) p.getBounds().get(0)).doubleValue() * timeDivider; bnd1 = ((Double) p.getBounds().get(1)).doubleValue() * timeDivider; col0 = (Color) p.getColors().get(0); col1 = (Color) p.getColors().get(1); col2 = (Color) p.getColors().get(2); } else { bnd0 = ((Double) bounds.get(0)).doubleValue() * timeDivider; bnd1 = ((Double) bounds.get(1)).doubleValue() * timeDivider; col0 = (Color) levelColors.get(0); col1 = (Color) levelColors.get(1); col2 = (Color) levelColors.get(2); } try { p.calculateMetrics(currentlySelectedInstances, advancedSettings[1], failedInstances); wait = (p.getMeanWaitingTime()); } catch (Exception ex) { } // array to store HSB values in float[] hsb = new float[3]; if (wait <= bnd0) { Color.RGBtoHSB(col0.getRed(), col0.getGreen(), col0.getBlue(), hsb); temp += "\"" + hsb[0] + "," + hsb[1] + "," + hsb[2] + "\""; } else if (wait <= bnd1) { Color.RGBtoHSB(col1.getRed(), col1.getGreen(), col1.getBlue(), hsb); temp += "\"" + hsb[0] + "," + hsb[1] + "," + hsb[2] + "\""; } else if (wait > bnd1) { // final one Color.RGBtoHSB(col2.getRed(), col2.getGreen(), col2.getBlue(), hsb); temp += "\"" + hsb[0] + "," + hsb[1] + "," + hsb[2] + "\""; } else { Color.RGBtoHSB(col0.getRed(), col0.getGreen(), col0.getBlue(), hsb); temp += "\"" + hsb[0] + "," + hsb[1] + "," + hsb[2] + "\""; } return temp; }
/** * Creates a new color that is 30% less saturated * * @return */ public Color lessSaturated() { float[] hsb = java.awt.Color.RGBtoHSB((int) (r * 255f), (int) (g * 255f), (int) (b * 255f), null); hsb[1] *= 0.7f; int rgbColor = java.awt.Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]); int r = (rgbColor & 0x00FF0000) >> 16; int g = (rgbColor & 0x0000FF00) >> 8; int b = rgbColor & 0x000000FF; return new Color(r, g, b, (int) this.a * 255); }
/** * Creates a new color with the identical value component but with the brightness specified * * @param brightness 1 is bright, 0 is black * @return */ public Color getColorWithSpecificBrighness(float brightness) { float[] hsb = new float[3]; java.awt.Color.RGBtoHSB((int) (r * 255f), (int) (g * 255f), (int) (b * 255f), hsb); hsb[2] = brightness; java.awt.Color convertedColor = java.awt.Color.getHSBColor(hsb[0], hsb[1], brightness); return new Color( convertedColor.getRed() / 255f, convertedColor.getGreen() / 255f, convertedColor.getBlue() / 255f); }
protected void paintComponent(Graphics g) { String shortcuts = pref.get("fields_shortcuts", "`1234567890qwertyuiopasdfghjkl"); // paint fields Field ef = new Field(Field.EMPTY); Field[] fs = new Field[board.getData().getFields().length + 1]; fs[0] = ef; System.arraycopy(board.getData().getFields(), 0, fs, 1, board.getData().getFields().length); // ef.paint(g,0,0,fieldW,fieldH); for (int i = 0; i < fs.length; i++) { Field f = fs[i]; f.paint(g, i * fieldW, 0, fieldW, fieldH); // paint shortcuts if (i >= shortcuts.length()) continue; Color fieldColor = new Color( (f.getColor1().getRed() + f.getColor2().getRed()) / 2, (f.getColor1().getGreen() + f.getColor2().getGreen()) / 2, (f.getColor1().getBlue() + f.getColor2().getBlue()) / 2); if (Color.RGBtoHSB(fieldColor.getRed(), fieldColor.getGreen(), fieldColor.getBlue(), null)[2] < 0.5) { // dark background, bright color g.setColor( new Color( 255 - descColor.getRed(), 255 - descColor.getGreen(), 255 - descColor.getBlue())); } else { // bright background, dark color g.setColor(descColor); } String str = Character.toString(shortcuts.charAt(i)); int fontSize = (int) (fieldH * 0.5) + 1; int strWidth; Font font; do { fontSize--; font = new Font(Font.SERIF, Font.PLAIN, fontSize); } while ((strWidth = g.getFontMetrics().stringWidth(str)) > 0.9 * fieldW); g.setFont(font); g.drawString(str, i * fieldW + fieldW / 4 - strWidth / 2, fieldH / 4 + fontSize / 2); } // paint grid g.setColor(lineColor); int totalWidth = (board.getData().getFields().length + 1) * fieldW; for (int i = 0; i < board.getData().getFields().length + 2; i++) { g.drawLine(i * fieldW, 0, i * fieldW, fieldH); } g.drawLine(0, 0, totalWidth, 0); g.drawLine(0, fieldH, totalWidth, fieldH); }
private static Color brightness(Color color, double newBrightness, double newBrightnessKof) { // color. float[] hue = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); float h = hue[0]; float s = hue[1]; float b = (float) (((double) hue[2] * (1d - newBrightnessKof)) + ((double) newBrightness * newBrightnessKof)); int rgb = Color.HSBtoRGB(h, s, b); return new Color(rgb); }
@Override protected int[] getComponents(int pixel) { int[] components = new int[3]; float[] hsbvals = new float[3]; Color c = new Color(pixel); hsbvals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsbvals); components[0] = (int) (hsbvals[0] * 255); components[1] = (int) (hsbvals[1] * 255); components[2] = (int) (hsbvals[2] * 255); return components; }
private void sendBoardToDisplay(MITrisBoard board, Display2D display, double brightness) { int width = display.getWidth(); int height = display.getHeight(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Piece p = board.getPosition(x, y); Color c = p == null ? Color.BLACK : p.getColor(board.getLevel(), gameDisplayTime); float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), new float[3]); hsb[2] *= brightness; display.setPixelHSB(x, height - 1 - y, hsb[0], hsb[1], hsb[2]); } } }
private void setColor(Color color, Object source) { float[] hsb = new float[3]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb); myColor = color; myHue = hsb[0]; mySaturation = hsb[1]; myBrightness = hsb[2]; myOpacity = color.getAlpha(); fireColorChanged(source); repaint(); }
public void turnQuickOn() { hidePanels(); hideTabs(); deactivateTabs(); pHsearch1.setVisible(true); pHsearch1.revalidate(); pHsearch1.repaint(); if (tabs > 0) { tabButton1.setVisible(true); tabButton1.revalidate(); tabButton1.repaint(); } if (tabs > 1) { tabButton2.setVisible(true); } if (tabs > 2) { tabButton3.setVisible(true); } if (tabs > 3) { tabButton4.setVisible(true); } if (tabs > 4) { tabButton5.setVisible(true); } if (tabs > 0 && oldTabRef != null) { oldTabRef.setVisible(true); oldTabRef.revalidate(); oldTabRef.repaint(); } if (currentTab == 1) { tabButton1.activate(true); currentTabRef = tab1; } else if (currentTab == 2) { tabButton2.activate(true); currentTabRef = tab2; } else if (currentTab == 3) { tabButton3.activate(true); currentTabRef = tab3; } else if (currentTab == 4) { tabButton4.activate(true); currentTabRef = tab4; } else if (currentTab == 5) { tabButton5.activate(true); currentTabRef = tab5; } replaceImg(); float[] RGBConv = Color.RGBtoHSB(94, 88, 88, null); pHquickSearch1.setBackground(Color.getHSBColor(RGBConv[0], RGBConv[1], RGBConv[2])); pHquickSearch1.changeState(true); }
/** * returns a color for a group/order and for a state * * @param order A color order number. This determines the base color (hue). <br> * -2 => Wire <br> * else group index * @param what The goal for this color. <br> * 0 = unselected face. <br> * 1 = selected face. <br> * 2 = unselected internal edge <br> * 3 = selected internal edge <br> * 4 = unselected external edge <br> * 5 = selected external edge <br> * 6 = selected quad <br> */ public float[] getColorForOrder(int order, int what) { // wires have no group if (order == -2) { switch (what) { case 0: return new float[] {0.4f, 0.4f, 0.4f}; case 1: return new float[] {1.0f, 1.0f, 1.0f}; case 2: return new float[] {0.95f, 0.95f, 0.95f}; } } float s, h; float b = 1.0f; Color c = baseColor.get(new Integer(order)); float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); h = hsb[0]; s = hsb[1]; b = hsb[2]; switch (what) { case 0: s = s * 1.0f; break; // unactive face has saturated color case 1: s = s * 0.75f; break; // selected face is whiter case 2: s = s * 0.5f; break; // internal edges case 3: s = s * 0.0f; break; // selected internal edges case 4: s = s * 1.0f; b = b * 0.8f; break; // external edges case 5: s = 0.0f; break; // selected external edges case 6: s = s * 0.3f; break; // selected quad is whiter default: s = s * 1.0f; break; } return Color.getHSBColor(h, s, b).getRGBColorComponents(null); }
public void setColor(Color color, Object source) { float[] hsb = new float[3]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb); myBrightnessComponent.setValue(255 - (int) (hsb[2] * 255)); myBrightnessComponent.repaint(); myColorWheel.dropImage(); if (myOpacityComponent != null && source instanceof ColorPicker) { myOpacityComponent.setValue(color.getAlpha()); myOpacityComponent.repaint(); } myColorWheel.setColor(color, source); }
public int[][][] getHSVArray() { int[][][] hsvArray = new int[height][width][3]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int red = getPixelRed(x, y) & 0xff; int green = getPixelGreen(x, y) & 0xff; int blue = getPixelBlue(x, y) & 0xff; float[] hsbvals = new float[3]; hsbvals = Color.RGBtoHSB(red, green, blue, hsbvals); hsvArray[y][x][0] = (int) (255 * hsbvals[0]); hsvArray[y][x][1] = (int) (255 * hsbvals[1]); hsvArray[y][x][2] = (int) (255 * hsbvals[2]); } } return hsvArray; }