List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:ColorUtils.java
/** * Serializes a color to its HTML markup (e.g. "#ff0000" for red) * /*from ww w. j a v a 2 s .co m*/ * @param c The color to serialize * @return The HTML markup of the color */ public static String toHTML(Color c) { String ret = "#"; String hex; hex = Integer.toHexString(c.getRed()); if (hex.length() < 2) hex = "0" + hex; ret += hex; hex = Integer.toHexString(c.getGreen()); if (hex.length() < 2) hex = "0" + hex; ret += hex; hex = Integer.toHexString(c.getBlue()); if (hex.length() < 2) hex = "0" + hex; ret += hex; return ret; }
From source file:org.asqatasun.rules.elementchecker.contrast.helper.ContrastHelper.java
/** * * @param color//from w w w . j a v a2s .co m * @return */ public static double getLuminosity(Color color) { double luminosity = getComposantValue(color.getRed()) * RED_FACTOR + getComposantValue(color.getGreen()) * GREEN_FACTOR + getComposantValue(color.getBlue()) * BLUE_FACTOR; return luminosity; }
From source file:ml.hsv.java
public static hsv[][] img2RGB2HSV(File input) throws IOException { BufferedImage image;// www . j a va2s. c om int width, height; // File input = new File(ip); image = ImageIO.read(input); width = image.getWidth(); height = image.getHeight(); hsv hsvImage[][] = new hsv[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue()); } } // HSV2File(hsvImage,width,height); debugging code removed return hsvImage; }
From source file:ImageProcessing.ImageProcessing.java
public static double[] extractGrayColor(BufferedImage source) { //Extracts the gray value from the pixels at the source by //calculating the average of the RGB value at the given pixel. int imageWidth = source.getWidth(); int imageHeight = source.getHeight(); double[] values = new double[imageWidth * imageHeight]; for (int i = 0; i < imageHeight; i++) { for (int j = 0; j < imageWidth; j++) { int rgbValue = source.getRGB(j, i); Color currentPixel = new Color(rgbValue, true); int value = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3; values[(i * imageWidth) + j] = value; }/*w w w . j a va 2s .c om*/ } return values; }
From source file:ml.hsv.java
public static hsv[][] img2RGB2HSV(String ip) throws IOException { BufferedImage image;//from w w w . j a va 2s .co m int width, height; File input = new File(ip); image = ImageIO.read(input); width = image.getWidth(); height = image.getHeight(); hsv hsvImage[][] = new hsv[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue()); } } HSV2File(hsvImage, width, height); return hsvImage; }
From source file:Util.java
/** * Return a string representation of a color * // www .j a v a 2 s .c o m * @param color * @return string representation */ public static String colorToString(Color color) { if (color == null) { return ""; } StringBuffer buf = new StringBuffer(); buf.append('#'); buf.append(numberToPaddedHexString(color.getRed(), 2)); buf.append(numberToPaddedHexString(color.getGreen(), 2)); buf.append(numberToPaddedHexString(color.getBlue(), 2)); return buf.toString(); }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.Utils.java
public static Color getListBackground(final boolean selected) { if (selected) { if (isUnderNimbusLookAndFeel()) { return UIManager.getColor("List[Selected].textBackground"); // Nimbus }/*from w w w .ja va 2s.com*/ return UIManager.getColor("List.selectionBackground"); } else { if (isUnderNimbusLookAndFeel()) { final Color color = UIManager.getColor("List.background"); //noinspection UseJBColor return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } // Under GTK+ L&F "Table.background" often has main panel color, which looks ugly return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("List.background"); } }
From source file:OAT.ui.util.UiUtil.java
/** * Returns the RGB components (rrr, ggg, bbb) in the range of 0-255. * * @param color/*from w ww. j av a 2 s . co m*/ * @return */ public static String getColorRGB(Color color) { return color.getRed() + "," + color.getGreen() + "," + color.getBlue(); }
From source file:org.nuxeo.theme.presets.PhotoshopPaletteParser.java
public static Map<String, String> parse(byte[] bytes) { Map<String, String> entries = new LinkedHashMap<String, String>(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); DataInputStream dis = new DataInputStream(is); char[] words = new char[bytes.length]; int size = 0; while (true) { try {//from w w w. j a v a 2s. c o m words[size] = dis.readChar(); size++; } catch (Exception e) { break; } } try { is.close(); dis.close(); } catch (IOException e) { log.error(e, e); } int offset = 1; int version = words[0] & 0xffff; int nc = words[1] & 0xffff; // get version 2 if it exists if (version == 1 && size > nc * 5 + 2) { offset += nc * 5 + 2; version = words[offset - 1] & 0xffff; nc = words[offset] & 0xffff; } if (version == 1) { log.debug("Found ACO v1 color file (Photoshop < 7.0)"); } else if (version == 2) { log.debug("Found ACO v2 color file (Photoshop >= 7.0)"); } else { log.error("Unknown ACO file version: " + version); return entries; } log.debug("Found " + nc + " colors."); int counter = 1; for (int j = 0; j < nc; j++) { String value = null; int colorSpace = words[offset + 1] & 0xff; int w = words[offset + 2] & 0xffff; int x = words[offset + 3] & 0xffff; int y = words[offset + 4] & 0xffff; int z = words[offset + 5] & 0xffff; if (colorSpace == RGB) { value = rgbToHex(w / 256, x / 256, y / 256); } else if (colorSpace == HSB) { float hue = w / 65535F; // [0.0-1.0] float saturation = x / 65535F; // [0.0-1.0] float brightness = y / 65535F; // [0.0-1.0] Color color = Color.getHSBColor(hue, saturation, brightness); value = rgbToHex(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace == CMYK) { float cyan = 1F - w / 65535F; // [0.0-1.0] float magenta = 1F - x / 65535F; // [0.0-1.0] float yellow = 1F - y / 65535F; // [0.0-1.0] float black = 1F - z / 65535F; // [0.0-1.0] // TODO: do the conversion to RGB. An ICC profile is required. log.warn("Unsupported color space: CMYK"); } else if (colorSpace == GRAYSCALE) { int gray = (int) (w * 256F / 10000F); // [0-256] value = rgbToHex(gray, gray, gray); } else if (colorSpace == LAB) { float l = w / 100F; float a = x / 100F; float b = y / 100F; // TODO: do the conversion to RGB. An ICC profile is required. log.warn("Unsupported color space: CIE Lab"); } else if (colorSpace == WIDE_CMYK) { float cyan = w / 10000F; // [0.0-1.0] float magenta = x / 10000F; // [0.0-1.0] float yellow = y / 10000F; // [0.0-1.0] float black = z / 10000F; // [0.0-1.0] // TODO: do the conversion to RGB. An ICC profile is required. log.warn("Unsupported color space: Wide CMYK"); } else { log.warn("Unknown color space: " + colorSpace); } String name = ""; if (version == 1) { name = String.format("Color %s", counter); } else if (version == 2) { int len = (words[offset + 7] & 0xffff) - 1; name = String.copyValueOf(words, offset + 8, len); offset += len + 3; String n = name; int c = 2; while (entries.containsKey(n)) { n = String.format("%s %s", name, c); c++; } name = n; } if (value != null) { entries.put(name, value); } offset += 5; counter++; } return entries; }
From source file:net.tbnr.gearz.game.kits.GearzKitItem.java
static GearzKitItem fromJsonObject(JSONObject object) throws GearzKitReadException { String materialName;/*from w w w.ja v a2s .com*/ Integer quantity = 1; try { materialName = object.getString("item_type"); } catch (JSONException ex) { throw GearzKit.exceptionFromJSON("Could not read class", ex); } try { quantity = object.getInt("quantity"); } catch (JSONException ignored) { } Material material = Material.getMaterial(materialName); if (material == null) { throw new GearzKitReadException("Invalid Material Specified: " + materialName); } JSONArray enchants = null; Short data = null; try { if (object.has("enchants")) { enchants = object.getJSONArray("enchants"); } if (object.has("data")) { data = (short) object.getInt("data"); } } catch (JSONException ignored) { } HashMap<Enchantment, Integer> enchantmentMap = null; if (enchants != null) { enchantmentMap = new HashMap<>(); for (int x = 0; x < enchants.length(); x++) { try { JSONObject enchantObject = enchants.getJSONObject(x); String enchant_name = enchantObject.getString("name"); int level = enchantObject.getInt("level"); Enchantment e = Enchantment.getByName(enchant_name); if (e == null || level < 1) { throw new GearzKitReadException( "Invalid Enchantment " + x + " " + enchant_name + " " + level); } enchantmentMap.put(e, level); Gearz.getInstance().debug("Added enchant " + x + " " + e.getName() + ":" + level); } catch (JSONException e) { throw GearzKit.exceptionFromJSON("Could not read enchantment " + x, e); } } } GearzItemMeta itemMeta = new GearzItemMeta(); try { if (object.has("title")) { itemMeta.setTitle(object.getString("title")); } if (object.has("lore")) { JSONArray loreJSON = object.getJSONArray("lore"); List<String> lore = new ArrayList<>(); for (int y = 0; y < loreJSON.length(); y++) { lore.add(loreJSON.getString(y)); } itemMeta.setLore(lore); } if (object.has("owner")) { itemMeta.setOwner(object.getString("owner")); } if (object.has("color")) { Color decode = Color.decode(object.getString("color")); org.bukkit.Color color = org.bukkit.Color.fromRGB(decode.getRed(), decode.getGreen(), decode.getBlue()); itemMeta.setColor(color); } } catch (JSONException ex) { throw GearzKit.exceptionFromJSON("Could not read meta", ex); } GearzKitItem gearzKitItem = new GearzKitItem(material, quantity, itemMeta); if (enchantmentMap != null) { gearzKitItem.setEnchantments(enchantmentMap); } if (data != null) { gearzKitItem.setData(data); } return gearzKitItem; }