Search in sources :

Example 21 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class WBMPImageReader method getImageTypes.

public Iterator getImageTypes(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    readHeader();
    BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_BINARY);
    ArrayList list = new ArrayList(1);
    list.add(new ImageTypeSpecifier(bi));
    return list.iterator();
}
Also used : ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 22 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class PNGImageReader method getRawImageType.

/*
     * Super class implementation uses first element
     * of image types list as raw image type.
     *
     * Also, super implementation uses first element of this list
     * as default destination type image read param does not specify
     * anything other.
     *
     * However, in case of RGB and RGBA color types, raw image type
     * produces buffered image of custom type. It causes some
     * performance degradation of subsequent rendering operations.
     *
     * To resolve this contradiction we put standard image types
     * at the first positions of image types list (to produce standard
     * images by default) and put raw image type (which is custom)
     * at the last position of this list.
     *
     * After this changes we should override getRawImageType()
     * to return last element of image types list.
     */
public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException {
    Iterator<ImageTypeSpecifier> types = getImageTypes(imageIndex);
    ImageTypeSpecifier raw = null;
    do {
        raw = types.next();
    } while (types.hasNext());
    return raw;
}
Also used : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 23 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier 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 24 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class ImageUtil method canEncodeImage.

/** Checks that the provided <code>ImageWriter</code> can encode
     * the provided <code>ColorModel</code> and <code>SampleModel</code>.
     * If not, an <code>IIOException</code> will be thrown.
     * @param writer The provided <code>ImageWriter</code>.
     * @param colorModel The provided <code>ColorModel</code>.
     * @param sampleModel The provided <code>SampleModel</code>.
     * @throws IIOException If the writer cannot encoded the provided image.
     */
public static final void canEncodeImage(ImageWriter writer, ColorModel colorModel, SampleModel sampleModel) throws IIOException {
    ImageTypeSpecifier type = null;
    if (colorModel != null && sampleModel != null)
        type = new ImageTypeSpecifier(colorModel, sampleModel);
    canEncodeImage(writer, type);
}
Also used : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 25 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class BMPImageReader method getImageTypes.

public Iterator getImageTypes(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    ArrayList list = new ArrayList(1);
    list.add(new ImageTypeSpecifier(originalColorModel, originalSampleModel));
    return list.iterator();
}
Also used : ArrayList(java.util.ArrayList) IIOException(javax.imageio.IIOException) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Aggregations

ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)45 BufferedImage (java.awt.image.BufferedImage)25 IIOMetadata (javax.imageio.metadata.IIOMetadata)20 ImageWriter (javax.imageio.ImageWriter)18 IIOImage (javax.imageio.IIOImage)13 ImageOutputStream (javax.imageio.stream.ImageOutputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ImageReader (javax.imageio.ImageReader)11 ImageWriteParam (javax.imageio.ImageWriteParam)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Iterator (java.util.Iterator)9 ColorModel (java.awt.image.ColorModel)7 IOException (java.io.IOException)7 SampleModel (java.awt.image.SampleModel)6 File (java.io.File)6 ImageInputStream (javax.imageio.stream.ImageInputStream)6 Rectangle (java.awt.Rectangle)5 ImageReadParam (javax.imageio.ImageReadParam)5 IndexColorModel (java.awt.image.IndexColorModel)4 Node (org.w3c.dom.Node)4