Search in sources :

Example 1 with IIOReadWarningListener

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

the class ImageReader method processWarningOccurred.

/**
     * Broadcasts a warning message to all registered
     * <code>IIOReadWarningListener</code>s by calling their
     * <code>warningOccurred</code> method.  Subclasses may use this
     * method as a convenience.
     *
     * @param warning the warning message to send.
     *
     * @exception IllegalArgumentException if <code>warning</code>
     * is <code>null</code>.
     */
protected void processWarningOccurred(String warning) {
    if (warningListeners == null) {
        return;
    }
    if (warning == null) {
        throw new IllegalArgumentException("warning == null!");
    }
    int numListeners = warningListeners.size();
    for (int i = 0; i < numListeners; i++) {
        IIOReadWarningListener listener = (IIOReadWarningListener) warningListeners.get(i);
        listener.warningOccurred(this, warning);
    }
}
Also used : IIOReadWarningListener(javax.imageio.event.IIOReadWarningListener) Point(java.awt.Point)

Example 2 with IIOReadWarningListener

use of javax.imageio.event.IIOReadWarningListener 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)

Example 3 with IIOReadWarningListener

use of javax.imageio.event.IIOReadWarningListener in project imageio-ext by geosolutions-it.

the class ImageReadMTCRIF method getImageReader.

/**
 * Get the <code>ImageReader</code> and set its input and metadata flag.
 * The input set on the reader might not be the same object as the input
 * passed in if the latter was replaced by getImageInputStream().
 */
static ImageReader getImageReader(ParameterBlock pb) {
    // Get the input.
    Object input = pb.getObjectParameter(0);
    // Get the reader parameter.
    ImageReader reader = (ImageReader) pb.getObjectParameter(8);
    // Attempt to create an ImageInputStream from the input.
    ImageInputStream stream = getImageInputStream(input);
    // If no reader passed in, try to find one.
    if (reader == null) {
        // Get all compatible readers.
        Iterator readers = ImageIO.getImageReaders(stream != null ? stream : input);
        // service provider indicates that it can decode the input.
        if (readers != null && readers.hasNext()) {
            do {
                ImageReader tmpReader = (ImageReader) readers.next();
                ImageReaderSpi readerSpi = tmpReader.getOriginatingProvider();
                try {
                    if (readerSpi.canDecodeInput(stream != null ? stream : input)) {
                        reader = tmpReader;
                    }
                } catch (IOException ioe) {
                // XXX Ignore it?
                }
            } while (reader == null && readers.hasNext());
        }
    }
    // If reader found, set its input and metadata flag.
    if (reader != null) {
        // Get the locale parameter and set on the reader.
        Locale locale = (Locale) pb.getObjectParameter(6);
        if (locale != null) {
            reader.setLocale(locale);
        }
        // Get the listeners parameter and set on the reader.
        EventListener[] listeners = (EventListener[]) pb.getObjectParameter(5);
        if (listeners != null) {
            for (int i = 0; i < listeners.length; i++) {
                EventListener listener = listeners[i];
                if (listener instanceof IIOReadProgressListener) {
                    reader.addIIOReadProgressListener((IIOReadProgressListener) listener);
                }
                if (listener instanceof IIOReadUpdateListener) {
                    reader.addIIOReadUpdateListener((IIOReadUpdateListener) listener);
                }
                if (listener instanceof IIOReadWarningListener) {
                    reader.addIIOReadWarningListener((IIOReadWarningListener) listener);
                }
            }
        }
        // Get the metadata reading flag.
        boolean readMetadata = ((Boolean) pb.getObjectParameter(2)).booleanValue();
        // Set the input and indicate metadata reading state.
        // seekForwardOnly
        reader.setInput(// seekForwardOnly
        stream != null ? stream : input, // seekForwardOnly
        false, // ignoreMetadata
        !readMetadata);
    }
    return reader;
}
Also used : Locale(java.util.Locale) IIOReadWarningListener(javax.imageio.event.IIOReadWarningListener) ImageInputStream(javax.imageio.stream.ImageInputStream) IIOReadProgressListener(javax.imageio.event.IIOReadProgressListener) IOException(java.io.IOException) IIOReadUpdateListener(javax.imageio.event.IIOReadUpdateListener) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Iterator(java.util.Iterator) EventListener(java.util.EventListener) ImageReader(javax.imageio.ImageReader)

Aggregations

IIOReadWarningListener (javax.imageio.event.IIOReadWarningListener)3 Point (java.awt.Point)2 ImageReader (javax.imageio.ImageReader)2 IIOReadUpdateListener (javax.imageio.event.IIOReadUpdateListener)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 EventListener (java.util.EventListener)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 IIOException (javax.imageio.IIOException)1 ImageReadParam (javax.imageio.ImageReadParam)1 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)1 IIOReadProgressListener (javax.imageio.event.IIOReadProgressListener)1 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1