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