Example usage for java.awt.image ByteLookupTable ByteLookupTable

List of usage examples for java.awt.image ByteLookupTable ByteLookupTable

Introduction

In this page you can find the example usage for java.awt.image ByteLookupTable ByteLookupTable.

Prototype

public ByteLookupTable(int offset, byte[] data) 

Source Link

Document

Constructs a ByteLookupTable object from an array of bytes representing a lookup table to be applied to all bands.

Usage

From source file:net.cloudkit.relaxation.VerifyImage.java

public void convBW(BufferedImage image) {
    byte[] threshold = new byte[256];

    for (int thresholdOp = 0; thresholdOp < 256; ++thresholdOp) {
        threshold[thresholdOp] = (byte) (thresholdOp < 128 ? 0 : -1);
    }//w ww. j a  va2  s . c  om

    LookupOp var4 = new LookupOp(new ByteLookupTable(0, threshold), (RenderingHints) null);
    var4.filter(image, image);
}

From source file:SaveImage.java

public void filterImage() {
    BufferedImageOp op = null;// w  ww . ja v  a  2s .c o m

    if (opIndex == lastOp) {
        return;
    }
    lastOp = opIndex;
    switch (opIndex) {

    case 0:
        biFiltered = bi; /* original */
        return;
    case 1: /* low pass filter */
    case 2: /* sharpen */
        float[] data = (opIndex == 1) ? BLUR3x3 : SHARPEN3x3;
        op = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null);

        break;

    case 3: /* lookup */
        byte lut[] = new byte[256];
        for (int j = 0; j < 256; j++) {
            lut[j] = (byte) (256 - j);
        }
        ByteLookupTable blut = new ByteLookupTable(0, lut);
        op = new LookupOp(blut, null);
        break;
    }

    /*
     * Rather than directly drawing the filtered image to the destination,
     * filter it into a new image first, then that filtered image is ready for
     * writing out or painting.
     */
    biFiltered = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    op.filter(bi, biFiltered);
}

From source file:ImageOps.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    int w = getSize().width;
    int h = getSize().height;

    g2.setColor(Color.black);//w w w  . ja  v  a2s  . c o m
    float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter
            0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 };

    String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" };
    for (int i = 0; i < bi.length; i++) {
        int iw = bi[i].getWidth(this);
        int ih = bi[i].getHeight(this);
        int x = 0, y = 0;

        AffineTransform at = new AffineTransform();
        at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih);

        BufferedImageOp biop = null;
        BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);

        switch (i) {
        case 0:
        case 1:
            x = i == 0 ? 5 : w / 2 + 3;
            y = 15;
            Kernel kernel = new Kernel(3, 3, data[i]);
            ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
            cop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            break;
        case 2:
            x = 5;
            y = h / 2 + 15;
            byte chlut[] = new byte[256];
            for (int j = 0; j < 200; j++)
                chlut[j] = (byte) (256 - j);
            ByteLookupTable blut = new ByteLookupTable(0, chlut);
            LookupOp lop = new LookupOp(blut, null);
            lop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            break;
        case 3:
            x = w / 2 + 3;
            y = h / 2 + 15;
            RescaleOp rop = new RescaleOp(1.1f, 20.0f, null);
            rop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
        }
        g2.drawImage(bimg, biop, x, y);
        TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext());
        tl.draw(g2, (float) x, (float) y - 4);
    }
}

From source file:Java2DExample.java

public BufferedImage processImage(BufferedImage image) {
    byte[] invertArray = new byte[256];

    for (int counter = 0; counter < 256; counter++)
        invertArray[counter] = (byte) (255 - counter);

    BufferedImageOp invertFilter = new LookupOp(new ByteLookupTable(0, invertArray), null);
    return invertFilter.filter(image, null);

}

From source file:ImageDrawingComponent.java

public void paint(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;

    switch (opIndex) {
    case 0: /* copy */
        g.drawImage(bi, 0, 0, null);//from ww  w .  j  a v a2  s .c o  m
        break;

    case 1: /* scale up using coordinates */
        g.drawImage(bi, 0, 0, w, h, /* dst rectangle */
                0, 0, w / 2, h / 2, /* src area of image */
                null);
        break;

    case 2: /* scale down using transform */
        g2.drawImage(bi, AffineTransform.getScaleInstance(0.7, 0.7), null);
        break;

    case 3: /* scale up using transform Op and BICUBIC interpolation */
        AffineTransform at = AffineTransform.getScaleInstance(1.5, 1.5);
        AffineTransformOp aop = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
        g2.drawImage(bi, aop, 0, 0);
        break;

    case 4: /* low pass filter */
    case 5: /* sharpen */
        float[] data = (opIndex == 4) ? BLUR3x3 : SHARPEN3x3;
        ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null);
        g2.drawImage(bi, cop, 0, 0);
        break;

    case 6: /* rescale */
        RescaleOp rop = new RescaleOp(1.1f, 20.0f, null);
        g2.drawImage(bi, rop, 0, 0);
        break;

    case 7: /* lookup */
        byte lut[] = new byte[256];
        for (int j = 0; j < 256; j++) {
            lut[j] = (byte) (256 - j);
        }
        ByteLookupTable blut = new ByteLookupTable(0, lut);
        LookupOp lop = new LookupOp(blut, null);
        g2.drawImage(bi, lop, 0, 0);
        break;

    default:
    }
}

From source file:ColorApp.java

public void reverseLUT() {
    byte reverse[] = new byte[256];
    for (int i = 0; i < 256; i++) {
        reverse[i] = (byte) (255 - i);
    }//from   w w  w.ja  v a  2  s  . com
    lookupTable = new ByteLookupTable(0, reverse);
}

From source file:org.apache.fop.render.pcl.PCLGenerator.java

private RenderedImage getMask(RenderedImage img, Dimension targetDim) {
    ColorModel cm = img.getColorModel();
    if (cm.hasAlpha()) {
        BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
        Raster raster = img.getData();
        GraphicsUtil.copyBand(raster, cm.getNumColorComponents(), alpha.getRaster(), 0);

        BufferedImageOp op1 = new LookupOp(new ByteLookupTable(0, THRESHOLD_TABLE), null);
        BufferedImage alphat = op1.filter(alpha, null);

        BufferedImage mask;/*from   w w  w. ja v  a2s .  c  o  m*/
        if (true) {
            mask = new BufferedImage(targetDim.width, targetDim.height, BufferedImage.TYPE_BYTE_BINARY);
        } else {
            byte[] arr = { (byte) 0, (byte) 0xff };
            ColorModel colorModel = new IndexColorModel(1, 2, arr, arr, arr);
            WritableRaster wraster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE, targetDim.width,
                    targetDim.height, 1, 1, null);
            mask = new BufferedImage(colorModel, wraster, false, null);
        }

        Graphics2D g2d = mask.createGraphics();
        try {
            AffineTransform at = new AffineTransform();
            double sx = targetDim.getWidth() / img.getWidth();
            double sy = targetDim.getHeight() / img.getHeight();
            at.scale(sx, sy);
            g2d.drawRenderedImage(alphat, at);
        } finally {
            g2d.dispose();
        }
        /*
        try {
        BatchDiffer.saveAsPNG(alpha, new java.io.File("D:/out-alpha.png"));
        BatchDiffer.saveAsPNG(mask, new java.io.File("D:/out-mask.png"));
        } catch (IOException e) {
        e.printStackTrace();
        }*/
        return mask;
    } else {
        return null;
    }
}