Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

In this page you can find the example usage for java.awt Color getGreen.

Prototype

public int getGreen() 

Source Link

Document

Returns the green component in the range 0-255 in the default sRGB space.

Usage

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(File input) throws IOException {
    BufferedImage image;/* w  w  w .  j a v a2 s.  com*/
    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:ml.hsv.java

public static hsv[][] img2RGB2HSV(String ip) throws IOException {
    BufferedImage image;/*from  w ww.j ava 2s.c  o 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:com.sandbox.utils.HSLColor.java

/**
 * Convert a RGB Color to it corresponding HSL values.
 *
 * @param color the color to convert.//from www.j  a v  a2 s.  c om
 * @param dest  the optional array to store the result in.
 * @return an array containing the 3 HSL values.
 */
public static float[] fromRGB(final Color color, float[] dest) {
    // Get RGB values in the range 0 - 1

    final float r = color.getRed() / 255f;
    final float g = color.getGreen() / 255f;
    final float b = color.getBlue() / 255f;

    // Minimum and Maximum RGB values are used in the HSL calculations

    final float min = FastMath.min(r, FastMath.min(g, b));
    final float max = FastMath.max(r, FastMath.max(g, b));

    // Calculate the Hue

    float h = 0;

    if (max == min)
        h = 0;
    else if (max == r)
        h = ((g - b) / (max - min) / 6f + 1) % 1;
    else if (max == g)
        h = (b - r) / (max - min) / 6f + 1f / 3f;
    else if (max == b)
        h = (r - g) / (max - min) / 6f + 2f / 3f;

    // Calculate the Luminance

    final float l = (max + min) / 2;

    // Calculate the Saturation

    float s = 0;

    if (max == min)
        s = 0;
    else if (l <= .5f)
        s = (max - min) / (max + min);
    else
        s = (max - min) / (2 - max - min);

    if (dest == null)
        dest = new float[3];
    dest[0] = h;
    dest[1] = s;
    dest[2] = l;

    return dest;
}

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  w w .  j ava  2  s  . co m*/
 * @return
 */
public static String getColorRGB(Color color) {
    return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
}

From source file:umontreal.ssj.charts.SSJCategorySeriesCollection.java

/**
 * Converts a java Color object into a friendly and readable LaTeX/xcolor string.
 *
 * @param   color    in color./*from   w w w .ja va 2s . c  o  m*/
 * @return           friendly color with string format as possible, null otherwise.
 */
protected static String detectXColorClassic(Color color) {
    String retour = null;

    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le parametre de transparence : Alpha
    if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
        return "green";
    else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
        return "red";
    else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
        return "white";
    else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
        return "gray";
    else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
        return "black";
    else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
        return "yellow";
    else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue()
            && green == Color.MAGENTA.getGreen())
        return "magenta";
    else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
        return "cyan";
    else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
        return "blue";
    else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
            && green == Color.DARK_GRAY.getGreen())
        return "darkgray";
    else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
            && green == Color.LIGHT_GRAY.getGreen())
        return "lightgray";
    else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
        return "orange";
    else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
        return "pink";

    if (red == 192 && blue == 128 && green == 64)
        return "brown";
    else if (red == 128 && blue == 128 && green == 0)
        return "olive";
    else if (red == 128 && blue == 0 && green == 128)
        return "violet";
    else if (red == 192 && blue == 0 && green == 64)
        return "purple";
    else
        return null;
}

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
        }/* w w w . jav a2 s  .c  om*/
        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:se.trixon.almond.GraphicsHelper.java

public static String colorToAABBGGRR(Color color, String... prefixSuffix) {
    String rr = StringUtils.leftPad(Integer.toHexString(color.getRed()), 2, "0");
    String gg = StringUtils.leftPad(Integer.toHexString(color.getGreen()), 2, "0");
    String bb = StringUtils.leftPad(Integer.toHexString(color.getBlue()), 2, "0");
    String aa = StringUtils.leftPad(Integer.toHexString(color.getAlpha()), 2, "0");
    StringBuilder builder = new StringBuilder();

    if (prefixSuffix.length > 0) {
        builder.append(prefixSuffix[0]);
    }//from  w  w  w  .j  a v  a2s .  c  o m

    builder.append(aa).append(bb).append(gg).append(rr);

    if (prefixSuffix.length > 1) {
        builder.append(prefixSuffix[1]);
    }

    return builder.toString();
}

From source file:umontreal.iro.lecuyer.charts.SSJCategorySeriesCollection.java

protected static String detectXColorClassic(Color color) {
    String retour = null;// w w w .  j  a v a2 s . c  o  m

    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le parametre de transparence : Alpha
    if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
        return "green";
    else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
        return "red";
    else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
        return "white";
    else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
        return "gray";
    else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
        return "black";
    else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
        return "yellow";
    else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue()
            && green == Color.MAGENTA.getGreen())
        return "magenta";
    else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
        return "cyan";
    else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
        return "blue";
    else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
            && green == Color.DARK_GRAY.getGreen())
        return "darkgray";
    else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
            && green == Color.LIGHT_GRAY.getGreen())
        return "lightgray";
    else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
        return "orange";
    else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
        return "pink";

    if (red == 192 && blue == 128 && green == 64)
        return "brown";
    else if (red == 128 && blue == 128 && green == 0)
        return "olive";
    else if (red == 128 && blue == 0 && green == 128)
        return "violet";
    else if (red == 192 && blue == 0 && green == 64)
        return "purple";
    else
        return null;
}

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  ww  .j  a va  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:org.fhcrc.cpl.viewer.mrm.Utils.java

public static Color paleColor(Color origColor) {

    int origRed = origColor.getRed();
    int origGreen = origColor.getGreen();
    int origBlue = origColor.getBlue();

    int maxColorVal = Math.max(Math.max(origRed, origGreen), origBlue);
    if (maxColorVal + PALE_CONSTANT > 255) {
        int adjust = (maxColorVal + PALE_CONSTANT) - 255;
        origRed = Math.max(0, origRed - adjust);
        origGreen = Math.max(0, origGreen - adjust);
        origBlue = Math.max(0, origBlue - adjust);
    }//from w ww .  jav  a2 s  . c  om

    Color paleColor = new Color(origRed + PALE_CONSTANT, origGreen + PALE_CONSTANT, origBlue + PALE_CONSTANT);
    return paleColor;
}