Example usage for java.awt.image FilteredImageSource FilteredImageSource

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

Introduction

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

Prototype

public FilteredImageSource(ImageProducer orig, ImageFilter imgf) 

Source Link

Document

Constructs an ImageProducer object from an existing ImageProducer and a filter object.

Usage

From source file:edu.stanford.epad.epadws.handlers.dicom.DSOUtil.java

private static Image makeAnyColorWhite(BufferedImage im) {
    nonBlank.set(false);//from  ww  w  . j  a  v  a2  s  .  c o m
    ImageFilter filter = new RGBImageFilter() {

        @Override
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb & 0x00FFFFFF) != 0) {
                nonBlank.set(true);
                return 0xFFFFFFFF;
            } else {
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:edu.stanford.epad.epadws.handlers.dicom.DSOUtil.java

private static Image makeColorOpaque(BufferedImage im, final Color color) {
    nonBlank.set(false);/*from w  w  w .  j  av a 2  s.c  om*/
    ImageFilter filter = new RGBImageFilter() {
        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb & 0x00FFFFFF) != 0) {
                nonBlank.set(true);
            }
            if ((rgb | 0xFF000000) == markerRGB) {
                //               nonBlank.set(true);
                return 0xFF000000 | rgb;
            } else {
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:edu.stanford.epad.epadws.handlers.dicom.DSOUtil.java

private static Image makeColorTransparent(BufferedImage im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {
        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override//from  w  ww . j  av a  2s  . co m
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                return 0x00FFFFFF & rgb;
            } else {
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:nz.co.fortytwo.freeboard.server.util.ChartProcessor.java

/**
 * Use Imagemajick convert to make white transparent, so we can overlay charts
 * @param dir/*from   w w  w.  j a  va2  s .c om*/
 * @throws IOException
 * @throws InterruptedException
 */
private void processPng(File dir) throws IOException, InterruptedException {
    //   File tmpPng = new File(dir.getAbsoluteFile()+".new");
    if (manager) {
        System.out.print("      Convert " + dir.getName() + "\n");
    }
    if (logger.isDebugEnabled())
        logger.debug("      Convert " + dir.getName());

    BufferedImage img = ImageIO.read(dir);
    ImageProducer ip = new FilteredImageSource(img.getSource(), filter);
    Image transparentImage = Toolkit.getDefaultToolkit().createImage(ip);
    BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = dest.createGraphics();
    g2.drawImage(transparentImage, 0, 0, null);
    g2.dispose();
    ImageIO.write(dest, "PNG", dir);

}

From source file:nz.co.fortytwo.freeboard.server.util.ChartProcessor.java

public Image makeColorTransparent(Image im, final Color color) {
    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:org.exist.xquery.modules.image.CropFunction.java

/**
 * evaluate the call to the xquery crop() function,
 * it is really the main entry point of this class
 * //from   w  w w.  j  a v  a2  s  . c  om
 * @param args      arguments from the crop() function call
 * @param contextSequence   the Context Sequence to operate on (not used here internally!)
 * @return      A sequence representing the result of the crop() function call
 * 
 * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
 */
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    //was an image and a mime-type speficifed
    if (args[0].isEmpty() || args[2].isEmpty()) {
        return Sequence.EMPTY_SEQUENCE;
    }

    //get the maximum dimensions to crop to
    int x1 = 0;
    int y1 = 0;
    int x2 = MAXHEIGHT;
    int y2 = MAXWIDTH;

    if (!args[1].isEmpty()) {
        x1 = ((IntegerValue) args[1].itemAt(0)).getInt();
        if (args[1].hasMany()) {
            y1 = ((IntegerValue) args[1].itemAt(1)).getInt();
            x2 = ((IntegerValue) args[1].itemAt(2)).getInt();
            y2 = ((IntegerValue) args[1].itemAt(3)).getInt();
        }
    }

    //get the mime-type
    String mimeType = args[2].itemAt(0).getStringValue();
    String formatName = mimeType.substring(mimeType.indexOf("/") + 1);

    //TODO currently ONLY tested for JPEG!!!
    Image image = null;
    BufferedImage bImage = null;
    try {
        //get the image data
        image = ImageIO.read(((BinaryValue) args[0].itemAt(0)).getInputStream());
        //         image = ImageModule.getImage((Base64BinaryValueType)args[0].itemAt(0));
        //               image = ImageIO.read(new ByteArrayInputStream(getImageData((Base64BinaryValueType)args[0].itemAt(0))));
        if (image == null) {
            logger.error("Unable to read image data!");
            return Sequence.EMPTY_SEQUENCE;
        }

        //crop the image
        Image cropImage = Toolkit.getDefaultToolkit()
                .createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(x1, y1, x2, y2)));
        if (cropImage instanceof BufferedImage) {
            // just in case cropImage is allready an BufferedImage
            bImage = (BufferedImage) cropImage;
        } else {
            bImage = new BufferedImage(cropImage.getHeight(null), cropImage.getWidth(null),
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D g = bImage.createGraphics(); // Paint the image onto the buffered image
            g.drawImage(cropImage, 0, 0, null);
            g.dispose();
        }

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(bImage, formatName, os);

        //return the new croped image data
        return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(),
                new ByteArrayInputStream(os.toByteArray()));

    } catch (Exception e) {
        throw new XPathException(this, e.getMessage());
    }
}

From source file:org.mbari.aved.ui.classifier.ClassModelListRenderer.java

/**
 * Converts and image into gray scale if the color space is grayscale
 * TODO: convert to whatever color space is required here, not just gray
 * @param image/*from ww w.ja v a  2s.  co  m*/
 * @param colorSpace
 * @return
 */
public static ImageIcon convertImageIcon(Image image, ColorSpace colorSpace) {

    // Convert to gray if in that color space. Images
    // are actually stored in color but converted to gray
    // in the classifier. Display them as GRAY to avoid
    // confusion as the classifier can only work in one
    // color space at a time, e.g. classes in different
    // color spaces cannot be mixed
    if (colorSpace != null && colorSpace.equals(ColorSpace.GRAY)) {

        // This isn't necessarily how the image is rendered in the Matlab
        // code, but it makes it easier to see the thumbnails
        ImageFilter filter = new GrayFilter(true, 50);
        ImageProducer prod;

        prod = new FilteredImageSource(image.getSource(), filter);

        Image grayScale = Toolkit.getDefaultToolkit().createImage(prod);

        return new ImageIcon(grayScale);
    } else {
        return new ImageIcon(image);
    }
}

From source file:org.polymap.core.data.image.ImageTransparencyProcessor.java

public static BufferedImage transparency(Image image, final Color markerColor) throws IOException {
    long start = System.currentTimeMillis();

    RGBImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque
        public int markerRGB = markerColor.getRGB() | 0xFF000000;

        byte threshold = 25;

        double range = ((double) 0xFF) / (3 * threshold);

        public final int filterRGB(int x, int y, int rgb) {
            Color probe = new Color(rgb);
            //log.info( "probe=" + probe + ", marker=" + markerColor );

            // delta values
            int dRed = markerColor.getRed() - probe.getRed();
            int dGreen = markerColor.getGreen() - probe.getGreen();
            int dBlue = markerColor.getBlue() - probe.getBlue();
            //log.info( "    dRed=" + dRed + ", dGreen=" + dGreen );

            if (dRed >= 0 && dRed < threshold && dGreen >= 0 && dGreen < threshold && dBlue >= 0
                    && dBlue < threshold) {
                int alpha = (int) Math.round(range * (dRed + dGreen + dBlue));
                //log.info( "    -> alpha=" + alpha );

                return ((alpha << 24) | 0x00FFFFFF) & rgb;
            } else {
                // nothing to do
                return rgb;
            }//w w  w . ja  va2 s. c o m
        }
    };

    //        BufferedImage bimage = null;
    //        if (image instanceof BufferedImage) {
    //            bimage = (BufferedImage)image;
    //        }
    //        else {
    //            bimage = new BufferedImage(
    //                    image.getHeight( null ), image.getWidth( null ), BufferedImage.TYPE_INT_ARGB );
    //            Graphics g = bimage.getGraphics();
    //            g.drawImage( image, 0, 0, null );
    //            g.dispose();
    //        }

    ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
    Image result = Toolkit.getDefaultToolkit().createImage(ip);

    BufferedImage bresult = new BufferedImage(image.getHeight(null), image.getWidth(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics g = bresult.getGraphics();
    g.drawImage(result, 0, 0, null);
    g.dispose();

    //        // XXX this can surely be done any more clever
    //        int width = bimage.getWidth();
    //        int height = bimage.getHeight();
    //        for (int x=bimage.getMinX(); x<width; x++) {
    //            for (int y=bimage.getMinY(); y<height; y++) {
    //                int filtered = filter.filterRGB( x, y, bimage.getRGB( x, y ) );
    //                result.setRGB( x, y, filtered );
    //            }
    //        }

    log.debug("Transparency done. (" + (System.currentTimeMillis() - start) + "ms)");
    return bresult;
}

From source file:org.polymap.rhei.batik.engine.svg.Svg2Png.java

public static BufferedImage makeColorTransparent(BufferedImage im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {

        private int shift = 0xFF000000;

        public int rgbToMakeTransparent = color.getRGB() | shift;

        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | shift) == rgbToMakeTransparent) {
                return 0x00FFFFFF & rgb;
            }/*from  w w w .j av  a 2 s.  c o  m*/
            return rgb;
        }
    };
    Image newImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(im.getSource(), filter));
    BufferedImage bufferedImage = new BufferedImage(newImage.getWidth(null), newImage.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bufferedImage.createGraphics();
    g2.drawImage(newImage, 0, 0, null);
    g2.dispose();
    return bufferedImage;
}

From source file:org.tolven.security.bean.DocProtectionBean.java

/**
 * Create a new scaled image using a filter.
 * @param sourceImage/*  w  w  w  .ja  v  a2 s  .co  m*/
 * @param width The width of the resulting picture
 * @param height The height of the resulting picture
 * @return The Image
 */
static public Image scaleImage(Image sourceImage, int width, int height) {
    ImageFilter filter = new ReplicateScaleFilter(width, height);
    ImageProducer producer = new FilteredImageSource(sourceImage.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(producer);
}