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