Return-Path: Delivered-To: apmail-xmlgraphics-fop-commits-archive@www.apache.org Received: (qmail 8981 invoked from network); 11 Dec 2007 11:16:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Dec 2007 11:16:33 -0000 Received: (qmail 35150 invoked by uid 500); 11 Dec 2007 11:16:14 -0000 Delivered-To: apmail-xmlgraphics-fop-commits-archive@xmlgraphics.apache.org Received: (qmail 35128 invoked by uid 500); 11 Dec 2007 11:16:14 -0000 Mailing-List: contact fop-commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: fop-dev@xmlgraphics.apache.org Delivered-To: mailing list fop-commits@xmlgraphics.apache.org Received: (qmail 35100 invoked by uid 99); 11 Dec 2007 11:16:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2007 03:16:14 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2007 11:16:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8349B1A9832; Tue, 11 Dec 2007 03:16:04 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r603209 - in /xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2: ImageManager.java pipeline/ImageProviderPipeline.java pipeline/PipelineFactory.java Date: Tue, 11 Dec 2007 11:16:01 -0000 To: fop-commits@xmlgraphics.apache.org From: jeremias@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071211111604.8349B1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jeremias Date: Tue Dec 11 03:15:49 2007 New Revision: 603209 URL: http://svn.apache.org/viewvc?rev=603209&view=rev Log: Refine pipeline building: Expose a method to allow the PS Renderer to predict what kind of pipeline will be selected (because it doesn't support all image types as PostScript forms) If there are multiple candidate pipelines for one conversion type, choose the one with the lowest penalty, not just the one that happens to be first. Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/ImageProviderPipeline.java xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/PipelineFactory.java Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java?rev=603209&r1=603208&r2=603209&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java (original) +++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java Tue Dec 11 03:15:49 2007 @@ -231,11 +231,8 @@ String mime = info.getMimeType(); Image img = null; - int count = flavors.length; - ImageProviderPipeline[] candidates = new ImageProviderPipeline[count]; - for (int i = 0; i < count; i++) { - candidates[i] = getPipelineFactory().newImageConverterPipeline(mime, flavors[i]); - } + ImageProviderPipeline[] candidates = getPipelineFactory().determineCandidatePipelines( + mime, flavors); ImageProviderPipeline pipeline = choosePipeline(candidates); if (pipeline != null) { @@ -312,14 +309,14 @@ Image img = null; int count = flavors.length; - ImageProviderPipeline[] candidates = new ImageProviderPipeline[count]; for (int i = 0; i < count; i++) { if (image.getFlavor().equals(flavors[i])) { //Shortcut (the image is already in one of the requested formats) return image; } - candidates[i] = getPipelineFactory().newImageConverterPipeline(image, flavors[i]); } + ImageProviderPipeline[] candidates = getPipelineFactory().determineCandidatePipelines( + image, flavors); ImageProviderPipeline pipeline = choosePipeline(candidates); if (pipeline != null) { @@ -349,7 +346,12 @@ return convertImage(image, flavors, null); } - private ImageProviderPipeline choosePipeline(ImageProviderPipeline[] candidates) { + /** + * 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; Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/ImageProviderPipeline.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/ImageProviderPipeline.java?rev=603209&r1=603208&r2=603209&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/ImageProviderPipeline.java (original) +++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/ImageProviderPipeline.java Tue Dec 11 03:15:49 2007 @@ -128,7 +128,7 @@ int startingPoint = 0; if (cache != null) { for (int i = converterCount - 1; i >= 0; i--) { - ImageConverter converter = (ImageConverter)converters.get(i); + ImageConverter converter = getConverter(i); ImageFlavor flavor = converter.getTargetFlavor(); img = cache.getImage(info, flavor); if (img != null) { @@ -169,7 +169,7 @@ if (converterCount > 0) { for (int i = startingPoint; i < converterCount; i++) { - ImageConverter converter = (ImageConverter)converters.get(i); + ImageConverter converter = getConverter(i); start = System.currentTimeMillis(); img = converter.convert(img, hints); if (log.isTraceEnabled()) { @@ -202,6 +202,10 @@ return img; } + private ImageConverter getConverter(int index) { + return (ImageConverter)converters.get(index); + } + /** * In some cases the provided Image is not cacheable, nor is any of the intermediate Image * instances (for example, when loading a raw JPEG file). If the image is loaded over a @@ -294,6 +298,20 @@ penalty += converter.getConversionPenalty(); } return penalty; + } + + /** + * Returns the target flavor generated by this pipeline. + * @return the target flavor + */ + public ImageFlavor getTargetFlavor() { + if (converters.size() > 0) { + return getConverter(converters.size() - 1).getTargetFlavor(); + } else if (this.loader != null) { + return this.loader.getTargetFlavor(); + } else { + return null; + } } } Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/PipelineFactory.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/PipelineFactory.java?rev=603209&r1=603208&r2=603209&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/PipelineFactory.java (original) +++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/PipelineFactory.java Tue Dec 11 03:15:49 2007 @@ -20,8 +20,10 @@ package org.apache.fop.image2.pipeline; import java.util.Collection; +import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; +import java.util.SortedSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -128,6 +130,7 @@ // --> List of resulting flavors, possibly multiple loaders ImageLoaderFactory[] 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++) { loaderFactory = loaderFactories[i]; @@ -137,25 +140,34 @@ if (pipeline != null) { ImageLoader loader = loaderFactory.newImageLoader(flavors[j]); pipeline.setImageLoader(loader); - if (pipeline != null && log.isDebugEnabled()) { - log.debug("Pipeline: " + pipeline); - } - return pipeline; + candidates.add(pipeline); } } } //Build final pipeline - + if (candidates.size() > 0) { + pipeline = (ImageProviderPipeline)candidates.first(); + } } - } if (pipeline != null && log.isDebugEnabled()) { - log.debug("Pipeline: " + pipeline); + log.debug("Pipeline: " + pipeline + " with penalty " + pipeline.getConversionPenalty()); } return pipeline; } + private static class PipelineComparator implements Comparator { + + public int compare(Object o1, Object o2) { + ImageProviderPipeline p1 = (ImageProviderPipeline)o1; + ImageProviderPipeline p2 = (ImageProviderPipeline)o2; + //Lowest penalty first + return p1.getConversionPenalty() - p2.getConversionPenalty(); + } + + } + private ImageProviderPipeline findPipeline(DefaultEdgeDirectory dir, ImageFlavor originFlavor, ImageRepresentation destination) { DijkstraAlgorithm dijkstra = new DijkstraAlgorithm( @@ -191,5 +203,40 @@ return pipeline; } } + + /** + * Finds and returns an array of {@link ImageProviderPipeline} instances which can handle + * the given MIME type and return one of the given {@link ImageFlavor}s. + * @param sourceMime the MIME type of the source file + * @param flavors the possible target flavors + * @return an array of pipelines + */ + public ImageProviderPipeline[] determineCandidatePipelines(String sourceMime, + ImageFlavor[] flavors) { + int count = flavors.length; + ImageProviderPipeline[] candidates = new ImageProviderPipeline[count]; + for (int i = 0; i < count; i++) { + candidates[i] = newImageConverterPipeline(sourceMime, flavors[i]); + } + return candidates; + } + + /** + * Finds and returns an array of {@link ImageProviderPipeline} instances which can handle + * the convert the given {@link Image} and return one of the given {@link ImageFlavor}s. + * @param sourceImage the image to be converted + * @param flavors the possible target flavors + * @return an array of pipelines + */ + public ImageProviderPipeline[] determineCandidatePipelines(Image sourceImage, + ImageFlavor[] flavors) { + int count = flavors.length; + ImageProviderPipeline[] candidates = new ImageProviderPipeline[count]; + for (int i = 0; i < count; i++) { + candidates[i] = newImageConverterPipeline(sourceImage, flavors[i]); + } + return candidates; + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org