Search in sources :

Example 6 with IIOReadUpdateListener

use of javax.imageio.event.IIOReadUpdateListener in project jdk8u_jdk by JetBrains.

the class ImageReader method processPassStarted.

/**
     * Broadcasts the beginning of a progressive pass to all
     * registered <code>IIOReadUpdateListener</code>s by calling their
     * <code>passStarted</code> method.  Subclasses may use this
     * method as a convenience.
     *
     * @param theImage the <code>BufferedImage</code> being updated.
     * @param pass the index of the current pass, starting with 0.
     * @param minPass the index of the first pass that will be decoded.
     * @param maxPass the index of the last pass that will be decoded.
     * @param minX the X coordinate of the upper-left pixel included
     * in the pass.
     * @param minY the X coordinate of the upper-left pixel included
     * in the pass.
     * @param periodX the horizontal separation between pixels.
     * @param periodY the vertical separation between pixels.
     * @param bands an array of <code>int</code>s indicating the
     * set of affected bands of the destination.
     */
protected void processPassStarted(BufferedImage theImage, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands) {
    if (updateListeners == null) {
        return;
    }
    int numListeners = updateListeners.size();
    for (int i = 0; i < numListeners; i++) {
        IIOReadUpdateListener listener = (IIOReadUpdateListener) updateListeners.get(i);
        listener.passStarted(this, theImage, pass, minPass, maxPass, minX, minY, periodX, periodY, bands);
    }
}
Also used : IIOReadUpdateListener(javax.imageio.event.IIOReadUpdateListener) Point(java.awt.Point)

Example 7 with IIOReadUpdateListener

use of javax.imageio.event.IIOReadUpdateListener in project jdk8u_jdk by JetBrains.

the class BMPImageReader method readEmbedded.

/** Decodes the jpeg/png image embedded in the bitmap using any jpeg
     *  ImageIO-style plugin.
     *
     * @param bi The destination <code>BufferedImage</code>.
     * @param bmpParam The <code>ImageReadParam</code> for decoding this
     *          BMP image.  The parameters for subregion, band selection and
     *          subsampling are used in decoding the jpeg image.
     */
private BufferedImage readEmbedded(int type, BufferedImage bi, ImageReadParam bmpParam) throws IOException {
    String format;
    switch(type) {
        case BI_JPEG:
            format = "JPEG";
            break;
        case BI_PNG:
            format = "PNG";
            break;
        default:
            throw new IOException("Unexpected compression type: " + type);
    }
    ImageReader reader = ImageIO.getImageReadersByFormatName(format).next();
    if (reader == null) {
        throw new RuntimeException(I18N.getString("BMPImageReader4") + " " + format);
    }
    // prepare input
    byte[] buff = new byte[(int) imageSize];
    iis.read(buff);
    reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(buff)));
    if (bi == null) {
        ImageTypeSpecifier embType = reader.getImageTypes(0).next();
        bi = embType.createBufferedImage(destinationRegion.x + destinationRegion.width, destinationRegion.y + destinationRegion.height);
    }
    reader.addIIOReadProgressListener(new EmbeddedProgressAdapter() {

        public void imageProgress(ImageReader source, float percentageDone) {
            processImageProgress(percentageDone);
        }
    });
    reader.addIIOReadUpdateListener(new IIOReadUpdateListener() {

        public void imageUpdate(ImageReader source, BufferedImage theImage, int minX, int minY, int width, int height, int periodX, int periodY, int[] bands) {
            processImageUpdate(theImage, minX, minY, width, height, periodX, periodY, bands);
        }

        public void passComplete(ImageReader source, BufferedImage theImage) {
            processPassComplete(theImage);
        }

        public void passStarted(ImageReader source, BufferedImage theImage, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands) {
            processPassStarted(theImage, pass, minPass, maxPass, minX, minY, periodX, periodY, bands);
        }

        public void thumbnailPassComplete(ImageReader source, BufferedImage thumb) {
        }

        public void thumbnailPassStarted(ImageReader source, BufferedImage thumb, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands) {
        }

        public void thumbnailUpdate(ImageReader source, BufferedImage theThumbnail, int minX, int minY, int width, int height, int periodX, int periodY, int[] bands) {
        }
    });
    reader.addIIOReadWarningListener(new IIOReadWarningListener() {

        public void warningOccurred(ImageReader source, String warning) {
            processWarningOccurred(warning);
        }
    });
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestination(bi);
    param.setDestinationBands(bmpParam.getDestinationBands());
    param.setDestinationOffset(bmpParam.getDestinationOffset());
    param.setSourceBands(bmpParam.getSourceBands());
    param.setSourceRegion(bmpParam.getSourceRegion());
    param.setSourceSubsampling(bmpParam.getSourceXSubsampling(), bmpParam.getSourceYSubsampling(), bmpParam.getSubsamplingXOffset(), bmpParam.getSubsamplingYOffset());
    reader.read(0, param);
    return bi;
}
Also used : IIOReadWarningListener(javax.imageio.event.IIOReadWarningListener) IIOException(javax.imageio.IIOException) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) IIOReadUpdateListener(javax.imageio.event.IIOReadUpdateListener) ImageReadParam(javax.imageio.ImageReadParam) ImageReader(javax.imageio.ImageReader)

Aggregations

Point (java.awt.Point)7 IIOReadUpdateListener (javax.imageio.event.IIOReadUpdateListener)7 BufferedImage (java.awt.image.BufferedImage)1 IIOException (javax.imageio.IIOException)1 ImageReadParam (javax.imageio.ImageReadParam)1 ImageReader (javax.imageio.ImageReader)1 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)1 IIOReadWarningListener (javax.imageio.event.IIOReadWarningListener)1