Package org.apache.xmlgraphics.image.loader.pipeline

Examples of org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline


        if (hints == null) {
            hints = Collections.EMPTY_MAP;
        }
       
        Image img = null;
        ImageProviderPipeline pipeline = getPipelineFactory().newImageConverterPipeline(
                info, flavor);
        if (pipeline != null) {
            img = pipeline.execute(info, hints, session);
        }
        if (img == null) {
            throw new ImageException(
                    "Cannot load image (no suitable loader/converter combination available) for "
                        + info);
View Full Code Here


        }

        Image img = null;
        ImageProviderPipeline[] candidates = getPipelineFactory().determineCandidatePipelines(
                info, flavors);
        ImageProviderPipeline pipeline = choosePipeline(candidates);
       
        if (pipeline != null) {
            img = pipeline.execute(info, hints, session);
        }
        if (img == null) {
            throw new ImageException(
                    "Cannot load image (no suitable loader/converter combination available) for "
                            + info);
View Full Code Here

                return image;
            }
        }
        ImageProviderPipeline[] candidates = getPipelineFactory().determineCandidatePipelines(
                image, flavors);
        ImageProviderPipeline pipeline = choosePipeline(candidates);
       
        if (pipeline != null) {
            img = pipeline.execute(info, image, hints, null);
        }
        if (img == null) {
            throw new ImageException(
                    "Cannot convert image " + image
                    + " (no suitable converter combination available)");
View Full Code Here

     * Chooses the best {@link ImageProviderPipeline} from a set of candidates.
     * @param candidates the candidates
     * @return the best pipeline
     */
    public ImageProviderPipeline choosePipeline(ImageProviderPipeline[] candidates) {
        ImageProviderPipeline pipeline = null;
        int minPenalty = Integer.MAX_VALUE;
        int count = candidates.length;
        for (int i = count - 1; i >= 0; i--) {
            if (candidates[i] == null) {
                continue;
View Full Code Here

       
        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);
        assertEquals(ImageFlavor.RAW_PNG, img.getFlavor());
        assertTrue(img instanceof ImageRawStream);
    }
View Full Code Here

        ImageSessionContext sessionContext = imageContext.newSessionContext();
        ImageManager manager = imageContext.getImageManager();

        Image original = createG2DImage();
       
        ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), null);
        pipeline.addConverter(new ImageConverterG2D2Bitmap());
        pipeline.addConverter(new ImageConverterBuffered2Rendered());
        pipeline.addConverter(new ImageConverterRendered2PNG());
       
        Image img = pipeline.execute(original.getInfo(), original, null,
                sessionContext);
        assertNotNull("Image must not be null", img);
        assertEquals(ImageFlavor.RAW_PNG, img.getFlavor());
        assertTrue(img instanceof ImageRawStream);
    }
View Full Code Here

        ImageFlavor[] inlineFlavors = getInlineFlavors();
        ImageManager manager = getUserAgent().getFactory().getImageManager();
        ImageProviderPipeline[] inlineCandidates
            = manager.getPipelineFactory().determineCandidatePipelines(
                    info, inlineFlavors);
        ImageProviderPipeline inlineChoice = manager.choosePipeline(inlineCandidates);
        ImageFlavor inlineFlavor = (inlineChoice != null ? inlineChoice.getTargetFlavor() : null);
       
        //Investigate choice for form mode
        ImageFlavor[] formFlavors = getFormFlavors();
        ImageProviderPipeline[] formCandidates
            = manager.getPipelineFactory().determineCandidatePipelines(
                    info, formFlavors);
        ImageProviderPipeline formChoice = manager.choosePipeline(formCandidates);
        ImageFlavor formFlavor = (formChoice != null ? formChoice.getTargetFlavor() : null);
       
        //Inline if form is not supported or if a better choice is available with inline mode
        return formFlavor == null || !formFlavor.equals(inlineFlavor);
    }
View Full Code Here

        ImageProviderPipeline[] candidates = pFactory.determineCandidatePipelines(
                imageInfo, targetFlavors);
        assertNotNull(candidates);
        assertEquals(2, candidates.length);

        ImageProviderPipeline pipeline = manager.choosePipeline(candidates);

        //0 penalty because the raw loader is the most efficient choice here
        assertEquals(0, pipeline.getConversionPenalty());
        assertEquals(ImageFlavor.RAW_CCITTFAX, pipeline.getTargetFlavor());
        if (pipeline.toString().indexOf("LoaderRawCCITTFax") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }

        //Now, we set this to a multi-strip TIFF which should disable the raw loader
        imageInfo.getCustomObjects().put("TIFF_STRIP_COUNT", new Integer(7));

        candidates = pFactory.determineCandidatePipelines(
                imageInfo, targetFlavors);
        assertNotNull(candidates);
        assertEquals(1, candidates.length);

        pipeline = manager.choosePipeline(candidates);

        //penalty for internal TIFF implementation (fallback role) is 1000 + 10 for the conversion
        assertEquals(1010, pipeline.getConversionPenalty());
        assertEquals(ImageFlavor.GRAPHICS2D, pipeline.getTargetFlavor());
        if (pipeline.toString().indexOf("LoaderInternalTIFF") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }
        if (pipeline.toString().indexOf("ImageConverterBitmap2G2D") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }
    }
View Full Code Here

        ImageProviderPipeline[] candidates = pFactory.determineCandidatePipelines(
                imageInfo, targetFlavors);
        assertNotNull(candidates);
        assertEquals(2, candidates.length);

        ImageProviderPipeline pipeline = manager.choosePipeline(candidates);

        //penalty for internal TIFF implementation (fallback role) is 1000 + 10 for the conversion
        assertEquals(1010, pipeline.getConversionPenalty());
        assertEquals(ImageFlavor.GRAPHICS2D, pipeline.getTargetFlavor());
        if (pipeline.toString().indexOf("LoaderInternalTIFF") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }
        if (pipeline.toString().indexOf("ImageConverterBitmap2G2D") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }

        //Now set an infinite penalty making the solution ineligible
        registry.setAdditionalPenalty(ImageLoaderRawCCITTFax.class.getName(),
                Penalty.INFINITE_PENALTY);
View Full Code Here

        ImageInfo imageInfo = new ImageInfo("test:tiff", "image/tiff");

        //We want a G2D image
        ImageFlavor targetFlavor = ImageFlavor.GRAPHICS2D;

        ImageProviderPipeline pipeline = pFactory.newImageConverterPipeline(
                imageInfo, targetFlavor);
        assertNotNull(pipeline);
        assertEquals(pipeline.getTargetFlavor(), targetFlavor);

        //penalty for internal TIFF implementation (fallback role) is 1000 + 10 for the conversion
        assertEquals(1010, pipeline.getConversionPenalty());
        assertEquals(ImageFlavor.GRAPHICS2D, pipeline.getTargetFlavor());
        if (pipeline.toString().indexOf("LoaderInternalTIFF") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }
        if (pipeline.toString().indexOf("ImageConverterBitmap2G2D") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }

        ImageProviderPipeline[] candidates = pFactory.determineCandidatePipelines(
                imageInfo, new ImageFlavor[] {targetFlavor});
        assertEquals(1, candidates.length);

        //Now add another implementation that poses as TIFF loader
        imageContext.getImageManager().getRegistry().registerLoaderFactory(
                new MockImageLoaderFactoryTIFF());

        candidates = pFactory.determineCandidatePipelines(
                imageInfo, targetFlavor);
        assertEquals(3, candidates.length);
        //3 because the mock impl provides Buffered- and RenderedImage capabilities

        pipeline = pFactory.newImageConverterPipeline(imageInfo, targetFlavor);
        assertNotNull(pipeline);
        assertEquals(pipeline.getTargetFlavor(), targetFlavor);

        //Assuming mock impl without penalty + 10 for the conversion
        assertEquals(10, pipeline.getConversionPenalty());
        assertEquals(ImageFlavor.GRAPHICS2D, pipeline.getTargetFlavor());
        if (pipeline.toString().indexOf(MockImageLoaderFactoryTIFF.class.getName()) < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }
        if (pipeline.toString().indexOf("ImageConverterBitmap2G2D") < 0) {
            fail("Chose the wrong pipeline: " + pipeline.toString());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline

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.