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

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


     * @throws Exception if an error occurs
     */
    public void testPipelineFactoryPlain() throws Exception {
        MockImageContext imageContext = MockImageContext.newSafeInstance();
        ImageManager manager = imageContext.getImageManager();
        PipelineFactory pFactory = new PipelineFactory(manager);

        //Input is some TIFF file
        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());
View Full Code Here


     * @throws Exception if an error occurs
     */
    public void testPipelineFactoryImageInfoDependency() throws Exception {
        MockImageContext imageContext = MockImageContext.newSafeInstance();
        ImageManager manager = imageContext.getImageManager();
        PipelineFactory pFactory = new PipelineFactory(manager);

        //Input is some TIFF file with CCITT Group 4 compression
        ImageInfo imageInfo = new ImageInfo("test:tiff", "image/tiff");
        imageInfo.getCustomObjects().put("TIFF_STRIP_COUNT", new Integer(1));
        imageInfo.getCustomObjects().put("TIFF_COMPRESSION", new Integer(TIFFImage.COMP_FAX_G4_2D));

        //We want either a G2D image or a raw CCITT image
        ImageFlavor[] targetFlavors = new ImageFlavor[] {
                ImageFlavor.GRAPHICS2D, ImageFlavor.RAW_CCITTFAX};

        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);
View Full Code Here

     * @throws Exception if an error occurs
     */
    public void testPipelineFactoryAdditionalPenalty() throws Exception {
        MockImageContext imageContext = MockImageContext.newSafeInstance();
        ImageManager manager = imageContext.getImageManager();
        PipelineFactory pFactory = new PipelineFactory(manager);

        //Adding additional penalty for CCITT loading
        ImageImplRegistry registry = imageContext.getImageManager().getRegistry();
        registry.setAdditionalPenalty(ImageLoaderRawCCITTFax.class.getName(),
                Penalty.toPenalty(10000));

        //Input is some TIFF file with CCITT Group 4 compression
        ImageInfo imageInfo = new ImageInfo("test:tiff", "image/tiff");
        imageInfo.getCustomObjects().put("TIFF_STRIP_COUNT", new Integer(1));
        imageInfo.getCustomObjects().put("TIFF_COMPRESSION", new Integer(TIFFImage.COMP_FAX_G4_2D));

        //We want either a G2D image or a raw CCITT image
        ImageFlavor[] targetFlavors = new ImageFlavor[] {
                ImageFlavor.GRAPHICS2D, ImageFlavor.RAW_CCITTFAX};

        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);

        candidates = pFactory.determineCandidatePipelines(imageInfo, targetFlavors);
        assertNotNull(candidates);
        assertEquals(1, candidates.length);
        //While earlier 2 candidates were returned, here we only get 1 because of the infinite
        //penalty.
    }
View Full Code Here

TOP

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

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.