Package org.apache.xmlgraphics.image.loader.spi

Examples of org.apache.xmlgraphics.image.loader.spi.ImageLoader


                .getImageLoaderFactories(mime);
        if (ilfs != null) {
            for (int i = 0; i < ilfs.length; i++) {
                ImageLoaderFactory ilf = ilfs[i];
                try {
                    final ImageLoader il = ilf.newImageLoader(rawFlavor);
                    if (il instanceof ImageLoaderRawPNG || il instanceof ImageLoaderPNG) {
                        // temporary measure until ImageLoaderRawPNG and ImageLoader PNG handle ICC profiles
                        continue;
                    }
                    final ImageInfo im = new ImageInfo(uri, mime);
                    final Image img = il.loadImage(im, isc);
                    final ICC_Profile icc = img.getICCProfile();
                    // Assume the profile can only be correct if the image could
                    // actually be interpreted.
                    if (img.getColorSpace() != null) {
                        profiles.add(icc);
                    }
                } catch (IllegalArgumentException e) {
                    // Ignore. This imageLoader does not support RAW
                }
                try {
                    final ImageLoader il = ilf.newImageLoader(ImageFlavor.BUFFERED_IMAGE);
                    final ImageInfo im = new ImageInfo(uri, mime);
                    final Image img = il.loadImage(im, isc);
                    final ICC_Profile icc = img.getICCProfile();
                    profiles.add(icc);
                } catch (IllegalArgumentException e) {
                    // Ignore. This imageLoader does not support Buffered.
                }
View Full Code Here


        }
    }

    @Test
    public void testNewImageLoader() {
        ImageLoader il = ilfpng.newImageLoader(ImageFlavor.RENDERED_IMAGE);
        assertTrue(il instanceof ImageLoaderPNG);
    }
View Full Code Here

    /** {@inheritDoc} */
    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
            throws ImageException, IOException {
        ImageException firstException = null;
        for (int i = 0, c = this.loaders.length; i < c; i++) {
            ImageLoader loader = this.loaders[i];
            try {
                Image img = loader.loadImage(info, hints, session);
                if (img != null && firstException != null) {
                    log.debug("First ImageLoader failed (" + firstException.getMessage()
                            + "). Fallback was successful.");
                }
                return img;
View Full Code Here

       
        ImageLoaderFactory[] loaderFactories = registry.getImageLoaderFactories(
                imageInfo, targetFlavor);
        if (loaderFactories != null) {
            //Directly load image and return it
            ImageLoader loader;
            if (loaderFactories.length == 1) {
                 loader = loaderFactories[0].newImageLoader(targetFlavor);
            } else {
                int count = loaderFactories.length;
                ImageLoader[] loaders = new ImageLoader[count];
                for (int i = 0; i < count; i++) {
                    loaders[i] = loaderFactories[i].newImageLoader(targetFlavor);
                }
                loader = new CompositeImageLoader(loaders);
            }
            pipeline = new ImageProviderPipeline(manager.getCache(), loader);
        } else {
            //Need to use ImageConverters
            if (log.isTraceEnabled()) {
                log.trace("No ImageLoaderFactory found that can load this format directly."
                        + " Trying ImageConverters instead...");
            }
           
            ImageRepresentation destination = new ImageRepresentation(targetFlavor);
            //Get Loader for originalMIME
            // --> List of resulting flavors, possibly multiple loaders
            loaderFactories = registry.getImageLoaderFactories(originalMime);
            if (loaderFactories != null) {
                SortedSet candidates = new java.util.TreeSet(new PipelineComparator());
                //Find best pipeline -> best loader
                for (int i = 0, ci = loaderFactories.length; i < ci; i++) {
                    ImageLoaderFactory loaderFactory = loaderFactories[i];
                    ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(originalMime);
                    for (int j = 0, cj = flavors.length; j < cj; j++) {
                        pipeline = findPipeline(dir, flavors[j], destination);
                        if (pipeline != null) {
                            ImageLoader loader = loaderFactory.newImageLoader(flavors[j]);
                            pipeline.setImageLoader(loader);
                            candidates.add(pipeline);
                        }
                    }
                }
View Full Code Here

        ImageManager manager = imageContext.getImageManager();
       
        ImageInfo info = manager.preloadImage(uri, sessionContext);
        assertNotNull("ImageInfo must not be null", info);
       
        ImageLoader loader = new ImageLoaderImageIO(ImageFlavor.RENDERED_IMAGE);
        ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), loader);
        pipeline.addConverter(new ImageConverterRendered2PNG());
       
        Image img = pipeline.execute(info, null, sessionContext);
        assertNotNull("Image must not be null", img);
View Full Code Here

                .getImageLoaderFactories(mime);
        if (ilfs != null)
            for (int i = 0; i < ilfs.length; i++) {
                ImageLoaderFactory ilf = ilfs[i];
                try {
                    final ImageLoader il = ilf.newImageLoader(rawFlavor);
                    final ImageInfo im = new ImageInfo(uri, mime);
                    final Image img = il.loadImage(im, isc);
                    final ICC_Profile icc = img.getICCProfile();
                    // Assume the profile can only be correct if the image could
                    // actually be interpreted.
                    if (img.getColorSpace() != null) {
                        profiles.add(icc);
                    }
                } catch (IllegalArgumentException e) {
                    // Ignore. This imageLoader does not support RAW
                }
                try {
                    final ImageLoader il = ilf
                            .newImageLoader(ImageFlavor.BUFFERED_IMAGE);
                    final ImageInfo im = new ImageInfo(uri, mime);
                    final Image img = il.loadImage(im, isc);
                    final ICC_Profile icc = img.getICCProfile();
                    profiles.add(icc);
                } catch (IllegalArgumentException e) {
                    // Ignore. This imageLoader does not support Buffered.
                }
View Full Code Here

        ImageManager manager = imageContext.getImageManager();

        ImageInfo info = manager.preloadImage(uri, sessionContext);
        assertNotNull("ImageInfo must not be null", info);

        ImageLoader loader = new ImageLoaderImageIO(ImageFlavor.RENDERED_IMAGE);
        ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), loader);
        pipeline.addConverter(new ImageConverterRendered2PNG());

        Image img = pipeline.execute(info, null, sessionContext);
        assertNotNull("Image must not be null", img);
View Full Code Here

     * {@inheritDoc}
     * @deprecated Redundancy with {@link ImageLoader#getUsagePenalty()}
     */
    public int getUsagePenalty(String mime, ImageFlavor flavor) {
        //Kept for compatibility
        ImageLoader loader = newImageLoader(flavor);
        return loader.getUsagePenalty();
    }
View Full Code Here

    /** {@inheritDoc} */
    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
            throws ImageException, IOException {
        ImageException firstException = null;
        for (int i = 0, c = this.loaders.length; i < c; i++) {
            ImageLoader loader = this.loaders[i];
            try {
                Image img = loader.loadImage(info, hints, session);
                if (img != null && firstException != null) {
                    log.debug("First ImageLoader failed (" + firstException.getMessage()
                            + "). Fallback was successful.");
                }
                return img;
View Full Code Here

        ImageLoaderFactory[] loaderFactories = registry.getImageLoaderFactories(
                imageInfo, targetFlavor);
        if (loaderFactories != null) {
            //Directly load image and return it
            ImageLoader loader;
            if (loaderFactories.length == 1) {
                 loader = loaderFactories[0].newImageLoader(targetFlavor);
            } else {
                int count = loaderFactories.length;
                ImageLoader[] loaders = new ImageLoader[count];
                for (int i = 0; i < count; i++) {
                    loaders[i] = loaderFactories[i].newImageLoader(targetFlavor);
                }
                loader = new CompositeImageLoader(loaders);
            }
            ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), loader);
            candidates.add(pipeline);
        } else {
            //Need to use ImageConverters
            if (log.isTraceEnabled()) {
                log.trace("No ImageLoaderFactory found that can load this format ("
                        + targetFlavor + ") directly. Trying ImageConverters instead...");
            }

            ImageRepresentation destination = new ImageRepresentation(targetFlavor);
            //Get Loader for originalMIME
            // --> List of resulting flavors, possibly multiple loaders
            loaderFactories = registry.getImageLoaderFactories(originalMime);
            if (loaderFactories != null) {

                //Find best pipeline -> best loader
                for (int i = 0, ci = loaderFactories.length; i < ci; i++) {
                    ImageLoaderFactory loaderFactory = loaderFactories[i];
                    ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(originalMime);
                    for (int j = 0, cj = flavors.length; j < cj; j++) {
                        ImageProviderPipeline pipeline = findPipeline(dir, flavors[j], destination);
                        if (pipeline != null) {
                            ImageLoader loader = loaderFactory.newImageLoader(flavors[j]);
                            pipeline.setImageLoader(loader);
                            candidates.add(pipeline);
                        }
                    }
                }
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.loader.spi.ImageLoader

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.