Package javax.imageio.metadata

Examples of javax.imageio.metadata.IIOMetadata


    /**
     * @see org.apache.xmlgraphics.image.writer.imageio.ImageIOImageWriter#updateMetadata(javax.imageio.metadata.IIOMetadata, org.apache.xmlgraphics.image.writer.ImageWriterParams)
     */
    protected IIOMetadata updateMetadata(IIOMetadata meta, ImageWriterParams params) {
        IIOMetadata ret = super.updateMetadata(meta, params);

        //We set the resolution manually using the native format since it appears that
        //it doesn't work properly through the standard metadata. Haven't figured out why
        //that happens.
        if (params.getResolution() != null) {
View Full Code Here


    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
            throws ImageException, IOException {
        RenderedImage imageData = null;
        IIOException firstException = null;

        IIOMetadata iiometa = (IIOMetadata)info.getCustomObjects().get(
                ImageIOUtil.IMAGEIO_METADATA);
        boolean ignoreMetadata = (iiometa != null);
        boolean providerIgnoresICC = false;

        Source src = session.needSource(info.getOriginalURI());
        ImageInputStream imgStream = ImageUtil.needImageInputStream(src);
        try {
            Iterator iter = ImageIO.getImageReaders(imgStream);
            while (iter.hasNext()) {
                ImageReader reader = (ImageReader)iter.next();
                try {
                    imgStream.mark();
                    ImageReadParam param = reader.getDefaultReadParam();
                    reader.setInput(imgStream, false, ignoreMetadata);
                    final int pageIndex = ImageUtil.needPageIndexFromURI(info.getOriginalURI());
                    try {
                        if (ImageFlavor.BUFFERED_IMAGE.equals(this.targetFlavor)) {
                            imageData = reader.read(pageIndex, param);
                        } else {
                            imageData = reader.read(pageIndex, param);
                            //imageData = reader.readAsRenderedImage(pageIndex, param);
                            //TODO Reenable the above when proper listeners are implemented
                            //to react to late pixel population (so the stream can be closed
                            //properly).
                        }
                        if (iiometa == null) {
                            iiometa = reader.getImageMetadata(pageIndex);
                        }
                        providerIgnoresICC = checkProviderIgnoresICC(reader
                                .getOriginatingProvider());
                        break; //Quit early, we have the image
                    } catch (IndexOutOfBoundsException indexe) {
                        throw new ImageException("Page does not exist. Invalid image index: "
                                + pageIndex);
                    } catch (IllegalArgumentException iae) {
                        //Some codecs like com.sun.imageio.plugins.wbmp.WBMPImageReader throw
                        //IllegalArgumentExceptions when they have trouble parsing the image.
                        throw new ImageException("Error loading image using ImageIO codec", iae);
                    } catch (IIOException iioe) {
                        if (firstException == null) {
                            firstException = iioe;
                        } else {
                            log.debug("non-first error loading image: " + iioe.getMessage());
                        }
                    }
                    try {
                        //Try fallback for CMYK images
                        BufferedImage bi = getFallbackBufferedImage(reader, pageIndex, param);
                        imageData = bi;
                        firstException = null; //Clear exception after successful fallback attempt
                        break;
                    } catch (IIOException iioe) {
                        //ignore
                    }
                    imgStream.reset();
                } finally {
                    reader.dispose();
                }
            }
        } finally {
            ImageUtil.closeQuietly(src);
            //TODO Some codecs may do late reading.
        }
        if (firstException != null) {
            throw new ImageException("Error while loading image: "
                    + firstException.getMessage(), firstException);
        }
        if (imageData == null) {
            throw new ImageException("No ImageIO ImageReader found .");
        }

        ColorModel cm = imageData.getColorModel();

        Color transparentColor = null;
        if (cm instanceof IndexColorModel) {
            //transparent color will be extracted later from the image
        } else {
            if (providerIgnoresICC && cm instanceof ComponentColorModel) {
                // Apply ICC Profile to Image by creating a new image with a new
                // color model.
                ICC_Profile iccProf = tryToExctractICCProfile(iiometa);
                if (iccProf != null) {
                    ColorModel cm2 = new ComponentColorModel(
                            new ICC_ColorSpace(iccProf), cm.hasAlpha(), cm
                                    .isAlphaPremultiplied(), cm
                                    .getTransparency(), cm.getTransferType());
                    WritableRaster wr = Raster.createWritableRaster(imageData
                            .getSampleModel(), null);
                    imageData.copyData(wr);
                    BufferedImage bi = new BufferedImage(cm2, wr, cm2
                            .isAlphaPremultiplied(), null);
                    imageData = bi;
                    cm = cm2;
                }
            }
            // ImageIOUtil.dumpMetadataToSystemOut(iiometa);
            // Retrieve the transparent color from the metadata
            if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {
                Element metanode = (Element)iiometa.getAsTree(
                        IIOMetadataFormatImpl.standardMetadataFormatName);
                Element dim = ImageIOUtil.getChild(metanode, "Transparency");
                if (dim != null) {
                    Element child;
                    child = ImageIOUtil.getChild(dim, "TransparentColor");
View Full Code Here

        if (!iter.hasNext()) {
            return null;
        }

        IOException firstIOException = null;
        IIOMetadata iiometa = null;
        ImageSize size = null;
        String mime = null;
        while (iter.hasNext()) {
            in.mark();
View Full Code Here

        private BufferedImage readImage(ImageReader jpegReader, ImageReadParam param) throws IOException {
            if (ycckDecodeMode) {
                // The standard Oracle Java JPEG readers can't deal with CMYK YCCK encoded images
                // without a little help from us. We'll try and pick up such instances and work around it.
                final IIOMetadata imageMeta = jpegReader.getImageMetadata(0);
                if (imageMeta != null) {
                    final Node standardMeta = imageMeta.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
                    if (standardMeta != null) {
                        final Node chroma = getChild(standardMeta, "Chroma");
                        if (chroma != null) {
                            final Node csType = getChild(chroma, "ColorSpaceType");
                            if (csType != null) {
View Full Code Here

      Iterator<ImageWriter> imageWritersByFormatName = ImageIO.getImageWritersByFormatName(imageType);
      for(;;){
        ImageWriter writer = imageWritersByFormatName.next();
        ImageWriteParam writeParam = writer.getDefaultWriteParam();
        ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
        IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
        if ((metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) && imageWritersByFormatName.hasNext()) {
          continue;
                }
        addDpiToMetadata(metadata);
        final FileOutputStream outFile = new FileOutputStream(chosenFile);
        final ImageOutputStream stream = ImageIO.createImageOutputStream(outFile);
View Full Code Here

                                                                wparam.setCompressionType(ImageCollection._getCompressionType(selectedConversion, newImg.peek().getType()));
                                                            } catch (RuntimeException ex) {
                                                                ex.printStackTrace();
                                                            }
                                                        }
                                                        IIOMetadata imgMeta = null;
                                                        ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage((RenderedImage) newImg.peek());
                                                        imgMeta = w.getDefaultImageMetadata(type, wparam);
                                                        w.write(w.getDefaultStreamMetadata(wparam), new IIOImage((RenderedImage) newImg.peek(), null, imgMeta), wparam);
                                                    } catch (InterruptedException ex) {
                                                        ex.printStackTrace();
View Full Code Here

        private BufferedImage readImage(ImageReader jpegReader, ImageReadParam param) throws IOException {
            if (ycckDecodeMode) {
                // The standard Oracle Java JPEG readers can't deal with CMYK YCCK encoded images
                // without a little help from us. We'll try and pick up such instances and work around it.
                final IIOMetadata imageMeta = jpegReader.getImageMetadata(0);
                if (imageMeta != null) {
                    final Node standardMeta = imageMeta.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
                    if (standardMeta != null) {
                        final Node chroma = getChild(standardMeta, "Chroma");
                        if (chroma != null) {
                            final Node csType = getChild(chroma, "ColorSpaceType");
                            if (csType != null) {
View Full Code Here

            {
                throw new RuntimeException("No ImageReaders found");
            }
            reader = (ImageReader) readers.next();
            reader.setInput(input);
            IIOMetadata meta = reader.getImageMetadata(0);
            if (meta != null)
            {
                Node tree = meta.getAsTree("javax_imageio_jpeg_image_1.0");
                NodeList children = tree.getChildNodes();
                for (int i=0;i<children.getLength();i++)
                {
                    Node markerSequence = children.item(i);
                    if ("markerSequence".equals(markerSequence.getNodeName()))
View Full Code Here

         *
         */
        private static Map<String, Object> __loadImage(Object src, boolean innerResource, ImageReader r, int renderMode, int bufferedType, boolean useCache) throws IOException, IllegalArgumentException {
                Map<String, Object> imageMap = new HashMap<String, Object>();
                BufferedImage ndata = null;
                IIOMetadata metadata = null;
                r = SpriteIO.__getInput(src, innerResource, r, useCache);
                if ((renderMode & Sf3RenderableImpl.MODE_TILE) == 0) {
                        ndata = r.read(0, SpriteIO._getIRP(r, bufferedType));
                }
                metadata = r.getImageMetadata(0);
View Full Code Here

                }
                try {
                        final Monitor monitor = this.renderableImpl.imageSynch;
                        synchronized (monitor) {
                                Dimension dim = null;
                                IIOMetadata metadata = null;
                                ImageWriter w = this.renderableImpl.io.getWriter(0, this.storeMime);
                                ImageWriteParam iwp = this.renderableImpl.io._getIWP(w, dim, this.storeMime, this._type, compressionQuality);
                                if (this.renderableImpl.io.IIOcontrollerEnabled) {
                                        iwp.setController(SpriteIO.IIOControllers.get(this.storeMime));
                                        if (iwp.hasController()) {
View Full Code Here

TOP

Related Classes of javax.imageio.metadata.IIOMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.