public HSBType(Color color) { if (color != null) { float[] hsbValues = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); this.hue = BigDecimal.valueOf(hsbValues[0] * 360); this.saturation = BigDecimal.valueOf(hsbValues[1] * 100); this.value = BigDecimal.valueOf(hsbValues[2] * 100); } else { throw new IllegalArgumentException("Constructor argument must not be null"); } }
private static float[] extractHSB(Color color) { return color == null ? null : Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); }
private Point closestPointToColor(Color target) { float[] hsb = Color.RGBtoHSB(target.getRed(), target.getGreen(), target.getBlue(), null); int offSize = size - 1; return new Point((int) (hsb[1] * offSize), offSize - (int) (hsb[2] * offSize)); }
/** * Calculates a close y value for the given target color. */ private int closestYToColor(Color target) { float[] hsb = Color.RGBtoHSB(target.getRed(), target.getGreen(), target.getBlue(), null); float hue = hsb[0]; int offHeight = height - 1; return Math.round(offHeight - hue * offHeight); }
public void setColor (Color color) { float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); hueSlider.setPercentage(hsb[0]); saturationSlider.setPercentage(1 - hsb[1]); lightnessSlider.setPercentage(1 - hsb[2]); colorPanel.setBackground(color); }
public void setColor (Color color) { float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); hueSlider.setPercentage(hsb[0]); saturationSlider.setPercentage(1 - hsb[1]); lightnessSlider.setPercentage(1 - hsb[2]); colorPanel.setBackground(color); }
public void setColor (Color color) { float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); hueSlider.setPercentage(hsb[0]); saturationSlider.setPercentage(1 - hsb[1]); lightnessSlider.setPercentage(1 - hsb[2]); colorPanel.setBackground(color); }
public void setColor (Color color) { float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); hueSlider.setPercentage(hsb[0]); saturationSlider.setPercentage(1 - hsb[1]); lightnessSlider.setPercentage(1 - hsb[2]); colorPanel.setBackground(color); }
private static Color brighter(int color) { float[] hsv = new float[3]; Color.RGBtoHSB(color >>> 16, (color >> 8) & 0xFF, color & 0xFF, hsv); return Color.getHSBColor(hsv[0], 1.f, 1.f); }
/** * This is implemented in native code in the Android SDK. * * <p>Since HSV == HSB then the implementation from {@link java.awt.Color} can be used, with a * small adjustment to the representation of the hue. * * <p>{@link java.awt.Color} represents hue as 0..1 (where 1 == 100% == 360 degrees), while {@link * android.graphics.Color} represents hue as 0..360 degrees. The correct hue can be calculated by * multiplying with 360. * * @param red Red component * @param green Green component * @param blue Blue component * @param hsv Array to store HSV components */ @Implementation protected static void RGBToHSV(int red, int green, int blue, float hsv[]) { java.awt.Color.RGBtoHSB(red, green, blue, hsv); hsv[0] = hsv[0] * 360; }
import java.awt.Color; float hsbVals[] = Color.RGBtoHSB( originalColour.getRed(), originalColour.getGreen(), originalColour.getBlue(), null ); Color highlight = Color.getHSBColor( hsbVals[0], hsbVals[1], 0.5f * ( 1f + hsbVals[2] )); Color shadow = Color.getHSBColor( hsbVals[0], hsbVals[1], 0.5f * hsbVals[2] );
b = (originalPixels[index] >> 0) & 0xff; float[] hsb = Color.RGBtoHSB(r, g, b, null); float h = hsb[0] * hue; float s = hsb[1] * saturation;
public static java.awt.Color mixedColor(java.awt.Color originalColor, java.awt.Color overlayColor) { final float[] hsbColor = java.awt.Color.RGBtoHSB(originalColor.getRed(), originalColor.getGreen(), originalColor.getBlue(), new float[3]); final float[] hsbError = java.awt.Color.RGBtoHSB(overlayColor.getRed(), overlayColor.getGreen(), overlayColor.getBlue(), new float[3]); final float[] hsbMixed = new float[3]; // kotlin code //hsbMixed[0] = hsbError[0] //hsbMixed[1] = hsbColor[1].rangeLimit(hsbError[1].max(0.3f).min(0.5f), 1.0f) //hsbMixed[2] = hsbColor[2].rangeLimit(hsbError[2].max(0.3f).min(0.5f), 1.0f) //return Color.getHSBColor(hsbMixed[0], hsbMixed[1], hsbMixed[2]) // incorrect translation from kotlin //hsbMixed[0] = hsbError[0]; //hsbMixed[1] = min(max(rangeLimit(hsbColor[1], hsbError[1], 0.3f), 0.5f), 1.0f); //hsbMixed[2] = min(max(rangeLimit(hsbColor[2], hsbError[2], 0.3f), 0.5f), 1.0f); //return java.awt.Color.getHSBColor(hsbMixed[0], hsbMixed[1], hsbMixed[2]); hsbMixed[0] = hsbError[0]; hsbMixed[1] = rangeLimit(hsbColor[1], min(max(hsbError[1], 0.3f), 0.5f), 1.0f); hsbMixed[2] = rangeLimit(hsbColor[2], min(max(hsbError[2], 0.3f), 0.5f), 1.0f); return java.awt.Color.getHSBColor(hsbMixed[0], hsbMixed[1], hsbMixed[2]); } }
public static Color brighter(@NotNull Color color, int tones) { final float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); float brightness = hsb[2]; for (int i = 0; i < tones; i++) { brightness = Math.min(1, brightness * 1.1F); if (brightness == 1) break; } return Color.getHSBColor(hsb[0], hsb[1], brightness); }
public static Color darker(@NotNull Color color, int tones) { final float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); float brightness = hsb[2]; for (int i = 0; i < tones; i++) { brightness = Math.max(0, brightness / 1.1F); if (brightness == 0) break; } return Color.getHSBColor(hsb[0], hsb[1], brightness); }
public static Color lighter(Color clr, double saturationFraction) { float[] hsb = new float[3]; Color.RGBtoHSB(clr.getRed(), clr.getGreen(), clr.getBlue(), hsb); hsb[1] = (float) MathUtil.clamp(hsb[1] * saturationFraction, 0, 1); Color chsb = Color.getHSBColor(hsb[0], hsb[1], hsb[2]); return new Color(chsb.getRed(), chsb.getGreen(), chsb.getBlue(), clr.getAlpha()); }
public static Color saturate(Color clr, double saturation) { float[] hsb = new float[3]; Color.RGBtoHSB(clr.getRed(), clr.getGreen(), clr.getBlue(), hsb); hsb[1] = (float) MathUtil.clamp(saturation, 0, 1);; return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); }
float[] hsl = Color.RGBtoHSB(r, g, b, null); hsl[0] -= (0.5f - l * l) * hueshift;