Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

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

Usage

From source file:wsattacker.sso.openid.attacker.evaluation.report.SvgOutput.java

private String colorToHex(Color color) {
    return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
}

From source file:org.niord.web.wms.WmsProxyServlet.java

/**
 * Masks out white colour/*from  ww  w .j a v a  2  s .c o  m*/
 * @param image the image to mask out
 * @return the resulting image
 */
@SuppressWarnings("unused")
private BufferedImage transformWhiteToTransparent(BufferedImage image) {

    BufferedImage dest = image;
    if (image.getType() != BufferedImage.TYPE_INT_ARGB) {
        dest = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = dest.createGraphics();
        g2.drawImage(image, 0, 0, null);
        g2.dispose();

        image.flush();
    }

    // Mask out the white pixels
    final int width = image.getWidth();
    int[] imgData = new int[width];

    for (int y = 0; y < dest.getHeight(); y++) {
        // fetch a line of data from each image
        dest.getRGB(0, y, width, 1, imgData, 0, 1);
        // apply the mask
        for (int x = 0; x < width; x++) {
            for (Color col : MASKED_COLORS) {
                int colDist = Math.abs(col.getRed() - (imgData[x] >> 16 & 0x000000FF))
                        + Math.abs(col.getGreen() - (imgData[x] >> 8 & 0x000000FF))
                        + Math.abs(col.getBlue() - (imgData[x] & 0x000000FF));
                if (colDist <= COLOR_DIST) {
                    imgData[x] = 0x00FFFFFF & imgData[x];
                }
            }
        }
        // replace the data
        dest.setRGB(0, y, width, 1, imgData, 0, 1);
    }
    return dest;
}

From source file:org.jtrfp.trcl.file.LTEFile.java

/**
 * Reverse-compatible form of the emissive components in ESTuTv form where:<br>
 * R = E<br>/*from   w  w  w .java 2s.  com*/
 * G = S<br>
 * B = Tu<br>
 * A = Tv<br>
 * @return
 * @since Feb 5, 2015
 */
public Color[] toColors(Color[] referencePalette) {
    Color[] result = new Color[256];
    for (int i = 0; i < 256; i++) {
        final Color rColor = referencePalette[i];
        final Color loColor = referencePalette[gradientIndex(i, 0)];
        final Color hiColor = referencePalette[gradientIndex(i, 15)];
        final double loIntensity = new Vector3D(loColor.getRed(), loColor.getGreen(), loColor.getBlue())
                .getNorm();
        //Brightest
        final double hiIntensity = new Vector3D(hiColor.getRed(), hiColor.getGreen(), hiColor.getBlue())
                .getNorm();

        final float[] hsbVals = new float[3];
        Color.RGBtoHSB(rColor.getRed(), rColor.getGreen(), rColor.getBlue(), hsbVals);
        final double saturation = hsbVals[1];
        double dI = Math.pow(1 - (Math.abs(hiIntensity - loIntensity) / 442.), 1);
        //dI = nSaturation*128;
        if (dI > 255)
            dI = 255;
        else if (dI < 0)
            dI = 0;
        result[i] = new Color((int) (dI * saturation * 255.), 0, 0, 0);
    }
    return result;
}

From source file:main.java.whiteSocket.Bloop.java

private static int getBrightnessThreshold() {
    /**//from  ww w  . j a  va 2s .  c  o m
     * get average pixel brightness of white pixels whiteboard input image
     * NOTE: lower brightness value = darker the pixel
     * using relative luminance
     * https://en.wikipedia.org/wiki/Relative_luminance
     * 
     * rough threshold value = 30% less than average of darkest corner
     * assumes average corner spans 60% brightness (+/-30%)
     */

    Color color = null;
    float brightness = 0;
    int r, g, b;
    int count = 0;
    int avg_UL, avg_UR, avg_LL, avg_LR;
    float totalBrightness = 0;

    for (int row = 0; row < 10; row++) { //   UL
        for (int col = 0; col < 10; col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_UL = (int) (totalBrightness / count);

    totalBrightness = 0;
    count = 0;
    for (int row = 0; row < 10; row++) { //  UR
        for (int col = sketch.getWidth() - 10; col < sketch.getWidth(); col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_UR = (int) (totalBrightness / count);

    totalBrightness = 0;
    count = 0;
    for (int row = sketch.getHeight() - 10; row < sketch.getHeight(); row++) { //   LL
        for (int col = 0; col < 10; col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_LL = (int) (totalBrightness / count);

    totalBrightness = 0;
    count = 0;
    for (int row = sketch.getHeight() - 10; row < sketch.getHeight(); row++) { //   LR
        for (int col = sketch.getWidth() - 10; col < sketch.getWidth(); col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_LR = (int) (totalBrightness / count);

    int threshold = (int) (0.7 * Math.min(Math.min(avg_LL, avg_LR), Math.min(avg_UL, avg_UR)));

    //      System.out.println("\nthreshold = "+threshold);

    return threshold;
}

From source file:herramientas.Ecualizacion_histograma.java

private void cogerDatos() {
    //        size = img.getWidth() * img.getHeight();
    datos = new int[256];

    //Inicializar datos a 0.
    for (int i = 0; i < 256; i++) {
        datos[i] = 0;/*from w w  w.j a va  2  s  .c o m*/
    }

    //Obtener datos de nivel de color.
    for (int i = 0; i < img.getWidth(); i++) {
        for (int j = 0; j < img.getHeight(); j++) {
            Color c = new Color(img.getRGB(i, j));

            datos[c.getRed()] += 1;
            //                System.out.println(i + "," + j);
            //                System.out.println(img.getRGB(i, j));
            //                System.out.println(c);
        }
    }
    datos[0] -= fondo;
    System.out.println("ec fondo" + fondo);

}

From source file:org.neo4art.colour.service.ImageDefaultManager.java

/**
 * //from  w  w w . jav  a  2s  . c  o m
 * @param red
 * @param green
 * @param blue
 * @return
 */
public Colour getClosestColour(Color color) {
    return getClosestColour(color.getRed(), color.getGreen(), color.getBlue());
}

From source file:com.cedarsoft.serialization.serializers.jackson.ColorSerializer.java

@Override
public void serialize(@Nonnull JsonGenerator serializeTo, @Nonnull Color object, @Nonnull Version formatVersion)
        throws IOException, VersionException, JsonProcessingException {
    serializeTo.writeNumberField(PROPERTY_RED, object.getRed());
    serializeTo.writeNumberField(PROPERTY_GREEN, object.getGreen());
    serializeTo.writeNumberField(PROPERTY_BLUE, object.getBlue());
}

From source file:org.geoserver.wms.wms_1_1_1.GetLegendGraphicTest.java

/**
 * Tests a dpi rescaled legend/*from   www  . j  a  v a 2 s  .co  m*/
 */
@Test
public void testStatesLegendDpiRescaled() throws Exception {
    String base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=Population"
            + "&format=image/png&width=20&height=20&legend_options=dpi:180";
    BufferedImage image = getAsImage(base, "image/png");

    assertPixel(image, 20, 20, Color.RED);
    assertPixel(image, 20, 60, Color.GREEN);
    assertPixel(image, 20, 100, Color.BLUE);
    Color linePixel = getPixelColor(image, 20, 140);
    assertTrue(linePixel.getRed() < 10);
    assertTrue(linePixel.getGreen() < 10);
    assertTrue(linePixel.getBlue() < 10);
}

From source file:baocaoxla.xuly_compare.java

public ChartPanel displayhistogram(BufferedImage image) {

    HistogramDataset dataset = new HistogramDataset();

    final int w = image.getWidth();
    final int h = image.getHeight();
    double[] r = new double[w * h];
    double[] g = new double[w * h];
    double[] b = new double[w * h];
    int dem = 0;/*from www.  ja v a2s .co m*/
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            Color c = new Color(image.getRGB(j, i));
            r[dem] = c.getRed();
            g[dem] = c.getGreen();
            b[dem] = c.getBlue();
            dem++;
        }
    }
    //r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, 256);
    //r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", g, 256);
    // r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", b, 256);
    // chart
    JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel panel = new ChartPanel(chart);
    return panel;

}

From source file:baocaoxla.xuly_compare.java

public int intersection(BufferedImage image, BufferedImage imgcompare) {
    int[] his = new int[256];
    int[] his1 = new int[256];

    for (int i = 0; i < 256; i++) {
        his[i] = 0;/*from w ww .  j a va 2s  . c  o m*/
        his1[i] = 0;

    }
    int width = image.getWidth();
    int height = image.getHeight();
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            his[(c.getRed() + c.getGreen() + c.getBlue()) / 3]++;

        }
    }
    int width1 = imgcompare.getWidth();
    int height1 = imgcompare.getHeight();
    for (int i = 0; i < height1; i++) {
        for (int j = 0; j < width1; j++) {
            Color c = new Color(imgcompare.getRGB(j, i));
            his1[(c.getRed() + c.getGreen() + c.getBlue()) / 3]++;
        }
    }
    double summin = 0;
    double sumhis = 0;

    for (int i = 0; i < 256; i++) {
        summin = summin + Math.min(his[i], his1[i]);
        sumhis = sumhis + his[i];
    }
    int percentred = (int) ((summin / sumhis) * 100);
    return percentred;
}