You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2007/12/17 20:03:49 UTC

svn commit: r604968 [1/2] - in /xmlgraphics/fop/branches/Temp_ImagePackageRedesign: examples/mathml/src/org/apache/fop/mathml/ src/java/META-INF/services/ src/java/org/apache/fop/image2/ src/java/org/apache/fop/image2/impl/ src/java/org/apache/fop/imag...

Author: jeremias
Date: Mon Dec 17 11:03:45 2007
New Revision: 604968

URL: http://svn.apache.org/viewvc?rev=604968&view=rev
Log:
Added an isSupported() method to ImageLoaderFactory so we can check early if an ImageLoader may or may not support a particular subformat. This is used to allow optimized loading of CCITT compressed TIFF images.
Support for undecoded embedding of single-strip CCITT compressed images for PDF, PostScript and AFP.
Added a fallback mechanism for ImageLoaders: if one ImageLoader cannot load a particular image, try equivalent others registered for the same format.

Added:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/resources/images/tiff_group3-1d.tif   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/resources/images/tiff_group3-2d.tif   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/resources/images/tiff_group3-multi-strip.tif   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.render.pdf.PDFImageHandler
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRaw.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderTIFF.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactorySVG.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactoryWMF.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/pipeline/PipelineFactory.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/afp/AFPRenderer.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawJPEGAdapter.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSRenderer.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSSupportedFlavors.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ResourceHandler.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/java/org/apache/fop/image2/ImagePreloaderTestCase.java

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/examples/mathml/src/org/apache/fop/mathml/ImageLoaderFactoryMathML.java Mon Dec 17 11:03:45 2007
@@ -20,13 +20,13 @@
 package org.apache.fop.mathml;
 
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.impl.AbstractImageLoaderFactory;
 import org.apache.fop.image2.spi.ImageLoader;
-import org.apache.fop.image2.spi.ImageLoaderFactory;
 
 /**
  * Factory class for the ImageLoader for MathML.
  */
-public class ImageLoaderFactoryMathML implements ImageLoaderFactory {
+public class ImageLoaderFactoryMathML extends AbstractImageLoaderFactory {
 
     /** MathML MIME type */
     public static final String MIME_MATHML = "text/mathml";

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory Mon Dec 17 11:03:45 2007
@@ -2,4 +2,5 @@
 org.apache.fop.image2.impl.batik.ImageLoaderFactorySVG
 org.apache.fop.image2.impl.batik.ImageLoaderFactoryWMF
 org.apache.fop.image2.impl.ImageLoaderFactoryRaw
-org.apache.fop.image2.impl.ImageLoaderFactoryEPS
\ No newline at end of file
+org.apache.fop.image2.impl.ImageLoaderFactoryRawCCITTFax
+org.apache.fop.image2.impl.ImageLoaderFactoryEPS

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.render.pdf.PDFImageHandler
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.render.pdf.PDFImageHandler?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.render.pdf.PDFImageHandler (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.render.pdf.PDFImageHandler Mon Dec 17 11:03:45 2007
@@ -1,4 +1,5 @@
 org.apache.fop.render.pdf.PDFImageHandlerRawJPEG
+org.apache.fop.render.pdf.PDFImageHandlerRawCCITTFax
 org.apache.fop.render.pdf.PDFImageHandlerGraphics2D
 org.apache.fop.render.pdf.PDFImageHandlerRenderedImage
 org.apache.fop.render.pdf.PDFImageHandlerXML

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java Mon Dec 17 11:03:45 2007
@@ -41,6 +41,8 @@
     public static final ImageFlavor RAW_EMF = new ImageFlavor("RawEMF");
     /** An image in form of a raw EPS (Encapsulated PostScript) file/stream */
     public static final ImageFlavor RAW_EPS = new ImageFlavor("RawEPS");
+    /** An image in form of a raw CCITTFax stream */
+    public static final ImageFlavor RAW_CCITTFAX = new ImageFlavor("RawCCITTFax");
     /** An image in form of a Graphics2DImage (can be painted on a Graphics2D interface) */
     public static final ImageFlavor GRAPHICS2D = new ImageFlavor("Graphics2DImage");
     

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=604968&r1=604967&r2=604968&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 Mon Dec 17 11:03:45 2007
@@ -186,11 +186,10 @@
         if (hints == null) {
             hints = Collections.EMPTY_MAP;
         }
-        String mime = info.getMimeType();
         
         Image img = null;
         ImageProviderPipeline pipeline = getPipelineFactory().newImageConverterPipeline(
-                mime, flavor);
+                info, flavor);
         if (pipeline != null) {
             img = pipeline.execute(info, hints, session);
         }
@@ -228,11 +227,10 @@
         if (hints == null) {
             hints = Collections.EMPTY_MAP;
         }
-        String mime = info.getMimeType();
 
         Image img = null;
         ImageProviderPipeline[] candidates = getPipelineFactory().determineCandidatePipelines(
-                mime, flavors);
+                info, flavors);
         ImageProviderPipeline pipeline = choosePipeline(candidates);
         
         if (pipeline != null) {
@@ -364,6 +362,9 @@
                 pipeline = candidates[i];
                 minPenalty = penalty;
             }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("Chosen pipeline: " + pipeline);
         }
         return pipeline;
     }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java Mon Dec 17 11:03:45 2007
@@ -20,6 +20,7 @@
 package org.apache.fop.image2.impl;
 
 import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
 import java.awt.color.ICC_Profile;
 
 import org.apache.fop.image2.Image;
@@ -58,7 +59,11 @@
 
     /** {@inheritDoc} */
     public ICC_Profile getICCProfile() {
-        return null;
+        if (getColorSpace() instanceof ICC_ColorSpace) {
+            return ((ICC_ColorSpace)getColorSpace()).getProfile();
+        } else {
+            return null;
+        }
     }
 
     /** {@inheritDoc} */

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.impl;
+
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.spi.ImageLoaderFactory;
+
+/**
+ * Abstract base class for ImageLoaderFactory implementations.
+ */
+public abstract class AbstractImageLoaderFactory implements ImageLoaderFactory {
+
+    /** {@inheritDoc} */
+    public boolean isSupported(ImageInfo imageInfo) {
+        //Most ImageLoaderFactories are assumed to support the complete feature set of
+        //an image format.
+        return true;
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoaderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.impl;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageSessionContext;
+import org.apache.fop.image2.spi.ImageLoader;
+
+/**
+ * Composite ImageLoader implementation in order to provide fallbacks when one ImageLoader
+ * fails due to some limitation.
+ */
+public class CompositeImageLoader extends AbstractImageLoader {
+
+    /** logger */
+    protected static Log log = LogFactory.getLog(CompositeImageLoader.class);
+
+    private ImageLoader[] loaders;
+    
+    /**
+     * Main constructor.
+     * @param loaders the contained image loaders
+     */
+    public CompositeImageLoader(ImageLoader[] loaders) {
+        if (loaders == null || loaders.length == 0) {
+            throw new IllegalArgumentException("Must at least pass one ImageLoader as parameter");
+        }
+        for (int i = 1, c = loaders.length; i < c; i++) {
+            if (!loaders[0].getTargetFlavor().equals(loaders[i].getTargetFlavor())) {
+                throw new IllegalArgumentException(
+                        "All ImageLoaders must produce the same target flavor");
+            }
+        }
+        this.loaders = loaders;
+    }
+    
+    /** {@inheritDoc} */
+    public ImageFlavor getTargetFlavor() {
+        return loaders[0].getTargetFlavor();
+    }
+
+    /** {@inheritDoc} */
+    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
+            throws ImageException, IOException {
+        ImageException firstException = null;
+        for (int i = 0, c = this.loaders.length; i < c; i++) {
+            ImageLoader loader = this.loaders[i];
+            try {
+                Image img = loader.loadImage(info, hints, session);
+                if (img != null && firstException != null) {
+                    log.debug("First ImageLoader failed (" + firstException.getMessage() 
+                            + "). Fallback was successful.");
+                }
+                return img;
+            } catch (ImageException ie) {
+                if (firstException == null) {
+                    firstException = ie;
+                }
+            }
+        }
+        throw firstException;
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        StringBuffer sb = new StringBuffer("[");
+        for (int i = 0; i < this.loaders.length; i++) {
+            if (i > 0) {
+                sb.append(",");
+            }
+            sb.append(this.loaders[i].toString());
+        }
+        sb.append("]");
+        return sb.toString();
+    }
+    
+}

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/CompositeImageLoader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java Mon Dec 17 11:03:45 2007
@@ -22,12 +22,11 @@
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.image2.ImageFlavor;
 import org.apache.fop.image2.spi.ImageLoader;
-import org.apache.fop.image2.spi.ImageLoaderFactory;
 
 /**
  * Factory class for the ImageLoader for EPS (Encapsulated PostScript) images.
  */
-public class ImageLoaderFactoryEPS implements ImageLoaderFactory {
+public class ImageLoaderFactoryEPS extends AbstractImageLoaderFactory {
 
     private static final String[] MIMES = new String[] {
         MimeConstants.MIME_EPS};

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRaw.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRaw.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRaw.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRaw.java Mon Dec 17 11:03:45 2007
@@ -22,12 +22,11 @@
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.image2.ImageFlavor;
 import org.apache.fop.image2.spi.ImageLoader;
-import org.apache.fop.image2.spi.ImageLoaderFactory;
 
 /**
  * Factory class for the ImageLoader for raw/undecoded images.
  */
-public class ImageLoaderFactoryRaw implements ImageLoaderFactory {
+public class ImageLoaderFactoryRaw extends AbstractImageLoaderFactory {
 
     /** MIME type for EMF (Windows Enhanced Metafile) */
     public static final String MIME_EMF = "image/x-emf"; 
@@ -38,7 +37,9 @@
         MIME_EMF};
     
     private static final ImageFlavor[][] FLAVORS = new ImageFlavor[][] {
-        {ImageFlavor.RAW_PNG}, {ImageFlavor.RAW_JPEG}, {ImageFlavor.RAW_EMF}};
+        {ImageFlavor.RAW_PNG},
+        {ImageFlavor.RAW_JPEG},
+        {ImageFlavor.RAW_EMF}};
 
     
     /**

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.impl;
+
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.spi.ImageLoader;
+
+/**
+ * Factory class for the ImageLoader for raw/undecoded CCITT encoded images.
+ */
+public class ImageLoaderFactoryRawCCITTFax extends AbstractImageLoaderFactory {
+
+    private static final String[] MIMES = new String[] {
+        MimeConstants.MIME_TIFF};
+    
+    private static final ImageFlavor[][] FLAVORS = new ImageFlavor[][] {
+        {ImageFlavor.RAW_CCITTFAX}};
+
+    
+    /**
+     * Returns the MIME type for a given ImageFlavor if it is from a format that is consumed
+     * without being undecoded. If the ImageFlavor is no raw flavor, an IllegalArgumentException
+     * is thrown.
+     * @param flavor the image flavor
+     * @return the associated MIME type
+     */
+    public static String getMimeForRawFlavor(ImageFlavor flavor) {
+        for (int i = 0, ci = FLAVORS.length; i < ci; i++) {
+            for (int j = 0, cj = FLAVORS[i].length; j < cj; j++) {
+                if (FLAVORS[i][j].equals(flavor)) {
+                    return MIMES[i];
+                }
+            }
+        }
+        throw new IllegalArgumentException("ImageFlavor is not a \"raw\" flavor: " + flavor);
+    }
+
+    /** {@inheritDoc} */
+    public String[] getSupportedMIMETypes() {
+        return MIMES;
+    }
+    
+    /** {@inheritDoc} */
+    public ImageFlavor[] getSupportedFlavors(String mime) {
+        for (int i = 0, c = MIMES.length; i < c; i++) {
+            if (MIMES[i].equals(mime)) {
+                return FLAVORS[i];
+            }
+        }
+        throw new IllegalArgumentException("Unsupported MIME type: " + mime);
+    }
+    
+    /** {@inheritDoc} */
+    public ImageLoader newImageLoader(ImageFlavor targetFlavor) {
+        if (targetFlavor.equals(ImageFlavor.RAW_CCITTFAX)) {
+            return new ImageLoaderRawCCITTFax();
+        } else {
+            throw new IllegalArgumentException("Unsupported image flavor: " + targetFlavor);
+        }
+    }
+    
+    /** {@inheritDoc} */
+    public int getUsagePenalty(String mime, ImageFlavor flavor) {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isAvailable() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isSupported(ImageInfo imageInfo) {
+        Boolean tiled = (Boolean)imageInfo.getCustomObjects().get("TIFF_TILED");
+        if (Boolean.TRUE.equals(tiled)) {
+            //We don't support tiled images
+            return false;
+        }
+        Integer compression = (Integer)imageInfo.getCustomObjects().get("TIFF_COMPRESSION");
+        if (compression == null) {
+            return false;
+        }
+        switch (compression.intValue()) {
+        case TIFFImage.COMP_FAX_G3_1D:
+        case TIFFImage.COMP_FAX_G3_2D:
+        case TIFFImage.COMP_FAX_G4_2D:
+            Integer stripCount = (Integer)imageInfo.getCustomObjects().get("TIFF_STRIP_COUNT");
+            return (stripCount != null && stripCount.intValue() == 1);
+        default:
+            return false;
+        }
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryRawCCITTFax.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.impl;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.imageio.stream.ImageInputStream;
+import javax.xml.transform.Source;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFDirectory;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFField;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImageDecoder;
+import org.apache.xmlgraphics.image.codec.util.SeekableStream;
+import org.apache.xmlgraphics.util.io.SubInputStream;
+
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageSessionContext;
+import org.apache.fop.image2.util.ImageUtil;
+import org.apache.fop.image2.util.SeekableStreamAdapter;
+
+/**
+ * ImageLoader for CCITT group 3 and 4 images consumed "raw" (undecoded). Provides a
+ * raw/undecoded stream.
+ */
+public class ImageLoaderRawCCITTFax extends AbstractImageLoader implements JPEGConstants {
+
+    /** logger */
+    protected static Log log = LogFactory.getLog(ImageLoaderRawCCITTFax.class);
+
+    /**
+     * Main constructor.
+     */
+    public ImageLoaderRawCCITTFax() {
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor getTargetFlavor() {
+        return ImageFlavor.RAW_CCITTFAX;
+    }
+
+    /** {@inheritDoc} */
+    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
+                throws ImageException, IOException {
+        if (!MimeConstants.MIME_TIFF.equals(info.getMimeType())) {
+            throw new IllegalArgumentException("ImageInfo must be from a image with MIME type: "
+                    + MimeConstants.MIME_TIFF);
+        }
+        int fillOrder = 1;
+        int compression = TIFFImage.COMP_NONE;
+        long stripOffset;
+        long stripLength;
+        TIFFDirectory dir;
+        
+        Source src = session.needSource(info.getOriginalURI());
+        ImageInputStream in = ImageUtil.needImageInputStream(src);
+        in.mark();
+        try {
+            SeekableStream seekable = new SeekableStreamAdapter(in);
+            dir = new TIFFDirectory(seekable, 0);
+            TIFFField fld;
+            
+            fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
+            if (fld != null) {
+                compression = fld.getAsInt(0);
+                switch (compression) {
+                case TIFFImage.COMP_FAX_G3_1D:
+                case TIFFImage.COMP_FAX_G3_2D:
+                case TIFFImage.COMP_FAX_G4_2D:
+                    break;
+                default:
+                    log.debug("Unsupported compression " + compression);
+                    throw new ImageException(
+                            "ImageLoader doesn't support TIFF compression: " + compression);
+                }
+            }
+            //Read information used for raw embedding
+            fld = dir.getField(TIFFImageDecoder.TIFF_FILL_ORDER);
+            if (fld != null) {
+                fillOrder = fld.getAsInt(0);
+            }
+
+            int stripCount;
+            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
+            if (fld == null) {
+                stripCount = 1;
+            } else {
+                stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0));
+            }
+            if (stripCount > 1) {
+                log.debug("More than one strip found in TIFF image.");
+                throw new ImageException(
+                        "ImageLoader doesn't support multiple strips");
+            }
+            stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0);
+            stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0);
+        } finally {
+            in.reset();
+        }
+        
+        in.seek(stripOffset);
+        InputStream subin = new SubInputStream(ImageUtil.needInputStream(src), stripLength, true);
+        if (fillOrder == 2) {
+            //Decorate to flip bit order
+            subin = new FillOrderChangeInputStream(subin);
+        }
+        ImageRawCCITTFax rawImage = new ImageRawCCITTFax(info, subin, compression);
+        //Strip stream from source as we pass it on internally
+        ImageUtil.removeStreams(src);
+        return rawImage;
+    }
+    
+    private static class FillOrderChangeInputStream extends FilterInputStream {
+
+        protected FillOrderChangeInputStream(InputStream in) {
+            super(in);
+        }
+
+        /** {@inheritDoc} */
+        public int read(byte[] b, int off, int len) throws IOException {
+            int result = super.read(b, off, len);
+            if (result > 0) {
+                int endpos = off + result;
+                for (int i = off; i < endpos; i++) {
+                    b[i] = FLIP_TABLE[b[i] & 0xff];
+                }
+            }
+            return result;
+        }
+
+        /** {@inheritDoc} */
+        public int read() throws IOException {
+            int b = super.read();
+            if (b < 0) {
+                return b;
+            } else {
+                return FLIP_TABLE[b] & 0xff;
+            }
+        }
+        
+        // Table to be used when fillOrder = 2, for flipping bytes.
+        // Copied from XML Graphics Commons' TIFFFaxDecoder class
+        private static final byte[] FLIP_TABLE = {
+         0,  -128,    64,   -64,    32,   -96,    96,   -32,
+        16,  -112,    80,   -48,    48,   -80,   112,   -16,
+         8,  -120,    72,   -56,    40,   -88,   104,   -24,
+        24,  -104,    88,   -40,    56,   -72,   120,    -8,
+         4,  -124,    68,   -60,    36,   -92,   100,   -28,
+        20,  -108,    84,   -44,    52,   -76,   116,   -12,
+        12,  -116,    76,   -52,    44,   -84,   108,   -20,
+        28,  -100,    92,   -36,    60,   -68,   124,    -4,
+         2,  -126,    66,   -62,    34,   -94,    98,   -30,
+        18,  -110,    82,   -46,    50,   -78,   114,   -14,
+        10,  -118,    74,   -54,    42,   -86,   106,   -22,
+        26,  -102,    90,   -38,    58,   -70,   122,    -6,
+         6,  -122,    70,   -58,    38,   -90,   102,   -26,
+        22,  -106,    86,   -42,    54,   -74,   118,   -10,
+        14,  -114,    78,   -50,    46,   -82,   110,   -18,
+        30,   -98,    94,   -34,    62,   -66,   126,    -2,
+         1,  -127,    65,   -63,    33,   -95,    97,   -31,
+        17,  -111,    81,   -47,    49,   -79,   113,   -15,
+         9,  -119,    73,   -55,    41,   -87,   105,   -23,
+        25,  -103,    89,   -39,    57,   -71,   121,    -7,
+         5,  -123,    69,   -59,    37,   -91,   101,   -27,
+        21,  -107,    85,   -43,    53,   -75,   117,   -11,
+        13,  -115,    77,   -51,    45,   -83,   109,   -19,
+        29,   -99,    93,   -35,    61,   -67,   125,    -3,
+         3,  -125,    67,   -61,    35,   -93,    99,   -29,
+        19,  -109,    83,   -45,    51,   -77,   115,   -13,
+        11,  -117,    75,   -53,    43,   -85,   107,   -21,
+        27,  -101,    91,   -37,    59,   -69,   123,    -5,
+         7,  -121,    71,   -57,    39,   -89,   103,   -25,
+        23,  -105,    87,   -41,    55,   -73,   119,    -9,
+        15,  -113,    79,   -49,    47,   -81,   111,   -17,
+        31,   -97,    95,   -33,    63,   -65,   127,    -1,
+        };
+        // end
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawCCITTFax.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.impl;
+
+import java.awt.color.ColorSpace;
+
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This class is an implementation of the Image interface exposing a 1-bit bitmap image stream
+ * that can be decoded by the PostScript or PDF CCITTFaxDecode filter. 
+ */
+public class ImageRawCCITTFax extends ImageRawStream {
+
+    private int compression;
+    
+    /**
+     * Main constructor.
+     * @param info the image info object
+     * @param in the ImageInputStream with the raw content
+     * @param compression the integer value of the TIFF compression scheme
+     */
+    public ImageRawCCITTFax(ImageInfo info, java.io.InputStream in, int compression) {
+        super(info, ImageFlavor.RAW_CCITTFAX, in);
+        this.compression = compression;
+    }
+    
+    /**
+     * Returns the image's color space
+     * @return the color space
+     */
+    public ColorSpace getColorSpace() {
+        return ColorSpace.getInstance(ColorSpace.CS_GRAY);
+    }
+
+    /**
+     * Returns the TIFF compression scheme.
+     * @return the TIFF compression scheme
+     */
+    public int getCompression() {
+        return this.compression;
+    }
+    
+}

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawCCITTFax.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderTIFF.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderTIFF.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderTIFF.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderTIFF.java Mon Dec 17 11:03:45 2007
@@ -78,55 +78,82 @@
         }
 
         if (supported) {
-            ImageInfo info = new ImageInfo(uri, MimeConstants.MIME_TIFF);
-            info.setSize(determineSize(in, context));
+            ImageInfo info = createImageInfo(uri, in, context); 
             return info;
         } else {
             return null;
         }
     }
 
-    private ImageSize determineSize(ImageInputStream in, ImageContext context)
+    private ImageInfo createImageInfo(String uri, ImageInputStream in, ImageContext context)
                 throws IOException, ImageException {
+        ImageInfo info = null;
         in.mark();
-
-        SeekableStream seekable = new SeekableStreamAdapter(in);
-        TIFFDirectory dir = new TIFFDirectory(seekable, 0);
-        int width = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_WIDTH);
-        int height = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH);
-        ImageSize size = new ImageSize();
-        size.setSizeInPixels(width, height);
-        int unit = 2; //inch is default
-        if (dir.isTagPresent(TIFFImageDecoder.TIFF_RESOLUTION_UNIT)) {
-            unit = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_RESOLUTION_UNIT);
-        }
-        if (unit == 2 || unit == 3) {
-            float xRes, yRes;
-            TIFFField fldx = dir.getField(TIFFImageDecoder.TIFF_X_RESOLUTION);
-            TIFFField fldy = dir.getField(TIFFImageDecoder.TIFF_Y_RESOLUTION);
-            if (fldx == null || fldy == null) {
-                unit = 2;
-                xRes = context.getSourceResolution();
-                yRes = xRes;
+        try {
+            SeekableStream seekable = new SeekableStreamAdapter(in);
+            TIFFDirectory dir = new TIFFDirectory(seekable, 0);
+            int width = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_WIDTH);
+            int height = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH);
+            ImageSize size = new ImageSize();
+            size.setSizeInPixels(width, height);
+            int unit = 2; //inch is default
+            if (dir.isTagPresent(TIFFImageDecoder.TIFF_RESOLUTION_UNIT)) {
+                unit = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_RESOLUTION_UNIT);
+            }
+            if (unit == 2 || unit == 3) {
+                float xRes, yRes;
+                TIFFField fldx = dir.getField(TIFFImageDecoder.TIFF_X_RESOLUTION);
+                TIFFField fldy = dir.getField(TIFFImageDecoder.TIFF_Y_RESOLUTION);
+                if (fldx == null || fldy == null) {
+                    unit = 2;
+                    xRes = context.getSourceResolution();
+                    yRes = xRes;
+                } else {
+                    xRes = fldx.getAsFloat(0);
+                    yRes = fldy.getAsFloat(0);
+                }
+                if (unit == 2) {
+                    size.setResolution(xRes, yRes); //Inch
+                } else {
+                    size.setResolution(
+                            UnitConv.in2mm(xRes) / 10,
+                            UnitConv.in2mm(yRes) / 10); //Centimeters
+                }
             } else {
-                xRes = fldx.getAsFloat(0);
-                yRes = fldy.getAsFloat(0);
+                size.setResolution(context.getSourceResolution());
+            }
+            size.calcSizeFromPixels();
+
+            info = new ImageInfo(uri, MimeConstants.MIME_TIFF);
+            info.setSize(size);
+            
+            TIFFField fld;
+            
+            fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
+            if (fld != null) {
+                int compression = fld.getAsInt(0);
+                info.getCustomObjects().put("TIFF_COMPRESSION", new Integer(compression));
+            }
+            
+            fld = dir.getField(TIFFImageDecoder.TIFF_TILE_WIDTH);
+            if (fld != null) {
+                info.getCustomObjects().put("TIFF_TILED", Boolean.TRUE);
             }
-            if (unit == 2) {
-                size.setResolution(xRes, yRes); //Inch
+            
+            int stripCount;
+            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
+            if (fld == null) {
+                stripCount = 1;
             } else {
-                size.setResolution(
-                        UnitConv.in2mm(xRes) / 10,
-                        UnitConv.in2mm(yRes) / 10); //Centimeters
+                stripCount = (int)(size.getHeightPx() / fld.getAsLong(0));
             }
-        } else {
-            size.setResolution(context.getSourceResolution());
+            info.getCustomObjects().put("TIFF_STRIP_COUNT", new Integer(stripCount));
+            
+        } finally {
+            in.reset();
         }
-        size.calcSizeFromPixels();
-
-        in.reset();
 
-        return size;
+        return info;
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactorySVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactorySVG.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactorySVG.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactorySVG.java Mon Dec 17 11:03:45 2007
@@ -21,13 +21,13 @@
 
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.impl.AbstractImageLoaderFactory;
 import org.apache.fop.image2.spi.ImageLoader;
-import org.apache.fop.image2.spi.ImageLoaderFactory;
 
 /**
  * Factory class for the ImageLoader for SVG.
  */
-public class ImageLoaderFactorySVG implements ImageLoaderFactory {
+public class ImageLoaderFactorySVG extends AbstractImageLoaderFactory {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.XML_DOM};

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactoryWMF.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactoryWMF.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactoryWMF.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactoryWMF.java Mon Dec 17 11:03:45 2007
@@ -20,13 +20,13 @@
 package org.apache.fop.image2.impl.batik;
 
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.impl.AbstractImageLoaderFactory;
 import org.apache.fop.image2.spi.ImageLoader;
-import org.apache.fop.image2.spi.ImageLoaderFactory;
 
 /**
  * Factory class for the ImageLoader for WMF (Windows Metafile).
  */
-public class ImageLoaderFactoryWMF implements ImageLoaderFactory {
+public class ImageLoaderFactoryWMF extends AbstractImageLoaderFactory {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageWMF.WMF_IMAGE};

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java Mon Dec 17 11:03:45 2007
@@ -22,13 +22,13 @@
 import javax.imageio.ImageIO;
 
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.impl.AbstractImageLoaderFactory;
 import org.apache.fop.image2.spi.ImageLoader;
-import org.apache.fop.image2.spi.ImageLoaderFactory;
 
 /**
  * Factory class for the ImageLoader based on ImageIO.
  */
-public class ImageLoaderFactoryImageIO implements ImageLoaderFactory {
+public class ImageLoaderFactoryImageIO extends AbstractImageLoaderFactory {
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.RENDERED_IMAGE,

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=604968&r1=604967&r2=604968&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 Mon Dec 17 11:03:45 2007
@@ -30,7 +30,9 @@
 
 import org.apache.fop.image2.Image;
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
 import org.apache.fop.image2.ImageManager;
+import org.apache.fop.image2.impl.CompositeImageLoader;
 import org.apache.fop.image2.spi.ImageConverter;
 import org.apache.fop.image2.spi.ImageImplRegistry;
 import org.apache.fop.image2.spi.ImageLoader;
@@ -100,23 +102,34 @@
     /**
      * Creates and returns an {@link ImageProviderPipeline} that allows to load an image of the
      * given MIME type and present it in the requested image flavor.
-     * @param originalMime the MIME type of the original image
+     * @param imageInfo the image info object of the original image
      * @param targetFlavor the requested image flavor
      * @return an {@link ImageProviderPipeline} or null if no suitable pipeline could be assembled
      */
     public ImageProviderPipeline newImageConverterPipeline(
-                String originalMime, ImageFlavor targetFlavor) {
+                ImageInfo imageInfo, ImageFlavor targetFlavor) {
+        String originalMime = imageInfo.getMimeType();
         ImageImplRegistry registry = manager.getRegistry();
         ImageProviderPipeline pipeline = null;
         
         //Get snapshot to avoid concurrent modification problems (thread-safety)
         DefaultEdgeDirectory dir = getEdgeDirectory();
         
-        ImageLoaderFactory loaderFactory = registry.getImageLoaderFactory(
-                originalMime, targetFlavor);
-        if (loaderFactory != null) {
+        ImageLoaderFactory[] loaderFactories = registry.getImageLoaderFactories(
+                imageInfo, targetFlavor);
+        if (loaderFactories != null) {
             //Directly load image and return it
-            ImageLoader loader = loaderFactory.newImageLoader(targetFlavor);
+            ImageLoader loader;
+            if (loaderFactories.length == 1) {
+                 loader = loaderFactories[0].newImageLoader(targetFlavor);
+            } else {
+                int count = loaderFactories.length;
+                ImageLoader[] loaders = new ImageLoader[count];
+                for (int i = 0; i < count; i++) {
+                    loaders[i] = loaderFactories[i].newImageLoader(targetFlavor);
+                }
+                loader = new CompositeImageLoader(loaders);
+            }
             pipeline = new ImageProviderPipeline(manager.getCache(), loader);
         } else {
             //Need to use ImageConverters
@@ -128,12 +141,12 @@
             ImageRepresentation destination = new ImageRepresentation(targetFlavor);
             //Get Loader for originalMIME
             // --> List of resulting flavors, possibly multiple loaders
-            ImageLoaderFactory[] loaderFactories = registry.getImageLoaderFactories(originalMime);
+            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];
+                    ImageLoaderFactory loaderFactory = loaderFactories[i];
                     ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(originalMime);
                     for (int j = 0, cj = flavors.length; j < cj; j++) {
                         pipeline = findPipeline(dir, flavors[j], destination);
@@ -187,7 +200,6 @@
             return null;
         } else {
             LinkedList stops = new LinkedList();
-            //stops.addLast(destination);
             while ((pred = dijkstra.getPredecessor(prev)) != null) {
                 ImageConversionEdge edge = (ImageConversionEdge)
                         dir.getBestEdge(pred, prev);
@@ -207,16 +219,16 @@
     /**
      * 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 imageInfo the image info object
      * @param flavors the possible target flavors
      * @return an array of pipelines
      */
-    public ImageProviderPipeline[] determineCandidatePipelines(String sourceMime,
+    public ImageProviderPipeline[] determineCandidatePipelines(ImageInfo imageInfo,
             ImageFlavor[] flavors) {
         int count = flavors.length;
         ImageProviderPipeline[] candidates = new ImageProviderPipeline[count];
         for (int i = 0; i < count; i++) {
-            candidates[i] = newImageConverterPipeline(sourceMime, flavors[i]);
+            candidates[i] = newImageConverterPipeline(imageInfo, flavors[i]);
         }
         return candidates;
     }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java Mon Dec 17 11:03:45 2007
@@ -32,6 +32,7 @@
 import org.apache.xmlgraphics.util.Service;
 
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
 
 /**
  * This class is the registry for all implementations of the various service provider interfaces
@@ -257,13 +258,14 @@
     }
 
     /**
-     * Returns the best ImageLoaderFactory supporting the given MIME type and image flavor.
+     * Returns the best ImageLoaderFactory supporting the {@link ImageInfo} and image flavor.
      * If there are multiple ImageLoaderFactories the one with the least usage penalty is selected.
-     * @param mime the MIME type
+     * @param imageInfo the image info object
      * @param flavor the image flavor.
      * @return an ImageLoaderFactory instance or null, if no suitable implementation was found
      */
-    public ImageLoaderFactory getImageLoaderFactory(String mime, ImageFlavor flavor) {
+    public ImageLoaderFactory getImageLoaderFactory(ImageInfo imageInfo, ImageFlavor flavor) {
+        String mime = imageInfo.getMimeType();
         Map flavorMap = (Map)loaders.get(mime);
         if (flavorMap != null) {
             List factoryList = (List)flavorMap.get(flavor);
@@ -273,6 +275,9 @@
                 ImageLoaderFactory bestFactory = null;
                 while (iter.hasNext()) {
                     ImageLoaderFactory factory = (ImageLoaderFactory)iter.next();
+                    if (!factory.isSupported(imageInfo)) {
+                        continue;
+                    }
                     int penalty = factory.getUsagePenalty(mime, flavor); 
                     if (penalty < bestPenalty) {
                         bestPenalty = penalty;
@@ -285,6 +290,56 @@
         return null;
     }
 
+    /**
+     * Returns an array of {@link ImageLoaderFactory} instances that support the MIME type
+     * indicated by an {@link ImageInfo} object and can generate the given image flavor.
+     * @param imageInfo the image info object
+     * @param flavor the target image flavor
+     * @return the array of image loader factories
+     */
+    public ImageLoaderFactory[] getImageLoaderFactories(ImageInfo imageInfo, ImageFlavor flavor) {
+        String mime = imageInfo.getMimeType();
+        Collection matches = new java.util.TreeSet(new ImageLoaderFactoryComparator(mime, flavor));
+        Map flavorMap = (Map)loaders.get(mime);
+        if (flavorMap != null) {
+            List factoryList = (List)flavorMap.get(flavor);
+            if (factoryList != null && factoryList.size() > 0) {
+                Iterator iter = factoryList.iterator();
+                while (iter.hasNext()) {
+                    ImageLoaderFactory factory = (ImageLoaderFactory)iter.next();
+                    if (factory.isSupported(imageInfo)) {
+                        matches.add(factory);
+                    }
+                }
+            }
+        }
+        if (matches.size() == 0) {
+            return null;
+        } else {
+            return (ImageLoaderFactory[])matches.toArray(new ImageLoaderFactory[matches.size()]);
+        }
+    }
+    
+    private static class ImageLoaderFactoryComparator implements Comparator {
+
+        private String mime;
+        private ImageFlavor targetFlavor;
+        
+        public ImageLoaderFactoryComparator(String mime, ImageFlavor targetFlavor) {
+            this.mime = mime;
+            this.targetFlavor = targetFlavor;
+        }
+        
+        public int compare(Object o1, Object o2) {
+            ImageLoaderFactory f1 = (ImageLoaderFactory)o1;
+            ImageLoaderFactory f2 = (ImageLoaderFactory)o2;
+            //Lowest penalty first
+            return f1.getUsagePenalty(mime, targetFlavor) - f2.getUsagePenalty(mime, targetFlavor);
+        }
+        
+    }
+    
+    
     /**
      * Returns an array of ImageLoaderFactory instances which support the given MIME type. The
      * instances are returned in no particular order.

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java Mon Dec 17 11:03:45 2007
@@ -20,6 +20,7 @@
 package org.apache.fop.image2.spi;
 
 import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
 
 /**
  * This interface is implemented to provide information about an ImageLoader and to create new
@@ -44,6 +45,19 @@
     ImageFlavor[] getSupportedFlavors(String mime);
     
     /**
+     * Indicates whether the given image (represented by an {@link ImageInfo} object) is supported
+     * by the loader. By default, implementations return true assuming all images of the supported
+     * MIME types can be processed correctly. In some cases, however, an ImageLoader may only
+     * support a subset of a format because it offers an optimized way to embed the image in
+     * the target format (for example: CCITT compressed TIFF files in PDF and PostScript). For
+     * this to work, the preloader must register some information in the ImageInfo's custom
+     * objects so the factory can identify if an image may or may not be supported.
+     * @param imageInfo the image info object
+     * @return true if the image is supported by the loaders generated by this factory
+     */
+    boolean isSupported(ImageInfo imageInfo);
+    
+    /**
      * Creates and returns a new ImageLoader instance.
      * @param targetFlavor the target image flavor to produce
      * @return a new ImageLoader instance
@@ -64,5 +78,5 @@
      * @return true if the implementation is functional.
      */
     boolean isAvailable();
-    
+
 }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/afp/AFPRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/afp/AFPRenderer.java Mon Dec 17 11:03:45 2007
@@ -26,6 +26,7 @@
 import java.awt.image.RenderedImage;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
@@ -34,7 +35,9 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
 import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 
 import org.apache.fop.apps.FOUserAgent;
@@ -67,6 +70,7 @@
 import org.apache.fop.image2.ImageManager;
 import org.apache.fop.image2.ImageSessionContext;
 import org.apache.fop.image2.impl.ImageGraphics2D;
+import org.apache.fop.image2.impl.ImageRawCCITTFax;
 import org.apache.fop.image2.impl.ImageRendered;
 import org.apache.fop.image2.impl.ImageXMLDOM;
 import org.apache.fop.image2.util.ImageUtil;
@@ -744,7 +748,8 @@
     }
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[]
-                                                     {ImageFlavor.GRAPHICS2D,
+                                                     {ImageFlavor.RAW_CCITTFAX,
+                                                      ImageFlavor.GRAPHICS2D,
                                                       ImageFlavor.BUFFERED_IMAGE, 
                                                       ImageFlavor.RENDERED_IMAGE,
                                                       ImageFlavor.XML_DOM};
@@ -798,6 +803,42 @@
                             posInt.y + currentBPPosition,
                             posInt.width,
                             posInt.height);
+                } else if (img instanceof ImageRawCCITTFax) {
+                    ImageRawCCITTFax ccitt = (ImageRawCCITTFax)img;
+                    int afpx = mpts2units(posInt.x + currentIPPosition);
+                    int afpy = mpts2units(posInt.y + currentBPPosition);
+                    int afpw = mpts2units(posInt.getWidth());
+                    int afph = mpts2units(posInt.getHeight());
+                    int afpres = getResolution();
+                    ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw, afph,
+                            afpres, afpres);
+                    io.setImageParameters(
+                            (int) (ccitt.getSize().getDpiHorizontal() * 10),
+                            (int) (ccitt.getSize().getDpiVertical() * 10),
+                            ccitt.getSize().getWidthPx(),
+                            ccitt.getSize().getHeightPx());
+                    int compression = ccitt.getCompression();
+                    switch (compression) {
+                    case TIFFImage.COMP_FAX_G3_1D :
+                        io.setImageEncoding((byte) 0x80);
+                        break;
+                    case TIFFImage.COMP_FAX_G3_2D :
+                        io.setImageEncoding((byte) 0x81);
+                        break;
+                    case TIFFImage.COMP_FAX_G4_2D :
+                        io.setImageEncoding((byte) 0x82);
+                        break;
+                    default:
+                        throw new IllegalStateException(
+                                "Invalid compression scheme: " + compression);
+                    }
+                    InputStream in = ccitt.createInputStream();
+                    try {
+                        byte[] buf = IOUtils.toByteArray(in);
+                        io.setImageData(buf);
+                    } finally {
+                        IOUtils.closeQuietly(in);
+                    }
                 } else if (img instanceof ImageXMLDOM) {
                     ImageXMLDOM imgXML = (ImageXMLDOM)img;
                     renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pdf;
+import java.awt.color.ColorSpace;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+
+import org.apache.fop.image2.impl.ImageRawCCITTFax;
+import org.apache.fop.pdf.CCFFilter;
+import org.apache.fop.pdf.PDFDeviceColorSpace;
+import org.apache.fop.pdf.PDFDictionary;
+import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFFilter;
+import org.apache.fop.pdf.PDFFilterList;
+
+/**
+ * PDFImage implementation for the PDF renderer which handles raw CCITT fax images.
+ */
+public class ImageRawCCITTFaxAdapter extends AbstractImageAdapter {
+
+    private PDFFilter pdfFilter = null;
+
+    /**
+     * Creates a new PDFImage from an Image instance.
+     * @param image the CCITT encoded image
+     * @param key XObject key
+     */
+    public ImageRawCCITTFaxAdapter(ImageRawCCITTFax image, String key) {
+        super(image, key);
+    }
+
+    /**
+     * Returns the {@link ImageRawCCITTFax} instance for this adapter.
+     * @return the image instance
+     */
+    public ImageRawCCITTFax getImage() {
+        return ((ImageRawCCITTFax)this.image);
+    }
+    
+    /** {@inheritDoc} */
+    public void setup(PDFDocument doc) {
+        pdfFilter = new CCFFilter();
+        pdfFilter.setApplied(true);
+        PDFDictionary dict = new PDFDictionary();
+        dict.put("Columns", this.image.getSize().getWidthPx());
+        int compression = getImage().getCompression();
+        switch (compression) {
+        case TIFFImage.COMP_FAX_G3_1D :
+            dict.put("K", 0);
+            break;
+        case TIFFImage.COMP_FAX_G3_2D :
+            dict.put("K", 1);
+            break;
+        case TIFFImage.COMP_FAX_G4_2D :
+            dict.put("K", -1);
+            break;
+        default:
+            throw new IllegalStateException("Invalid compression scheme: " + compression);
+        }
+        ((CCFFilter)pdfFilter).setDecodeParms(dict);
+
+        super.setup(doc);
+    }
+
+    /** {@inheritDoc} */
+    public PDFDeviceColorSpace getColorSpace() {
+        return toPDFColorSpace(ColorSpace.getInstance(ColorSpace.CS_GRAY));
+    }
+
+    /** {@inheritDoc} */
+    public int getBitsPerComponent() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    public PDFFilter getPDFFilter() {
+        return pdfFilter;
+    }
+    
+    /** {@inheritDoc} */
+    public void outputContents(OutputStream out) throws IOException {
+        getImage().writeTo(out);
+    }
+
+    /** {@inheritDoc} */
+    public String getFilterHint() {
+        return PDFFilterList.TIFF_FILTER;
+    }
+
+}
+

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawCCITTFaxAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawJPEGAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawJPEGAdapter.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawJPEGAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/ImageRawJPEGAdapter.java Mon Dec 17 11:03:45 2007
@@ -45,8 +45,8 @@
     }
 
     /**
-     * Returns the ImageRendered instance for this adapter.
-     * @return the ImageRendered instance
+     * Returns the {@link ImageRawJPEG} instance for this adapter.
+     * @return the image instance
      */
     public ImageRawJPEG getImage() {
         return ((ImageRawJPEG)this.image);

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pdf;
+
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.io.IOException;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.impl.ImageRawCCITTFax;
+import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFImage;
+import org.apache.fop.pdf.PDFResourceContext;
+import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.RendererContext;
+
+/**
+ * PDFImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
+ */
+public class PDFImageHandlerRawCCITTFax implements PDFImageHandler {
+
+    private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
+        ImageFlavor.RAW_CCITTFAX,
+    };
+    
+    /** {@inheritDoc} */
+    public PDFXObject generateImage(RendererContext context, Image image, 
+            Point origin, Rectangle pos)
+            throws IOException {
+        PDFRenderer renderer = (PDFRenderer)context.getRenderer();
+        ImageRawCCITTFax ccitt = (ImageRawCCITTFax)image;
+        PDFDocument pdfDoc = (PDFDocument)context.getProperty(
+                PDFRendererContextConstants.PDF_DOCUMENT);
+        PDFResourceContext resContext = (PDFResourceContext)context.getProperty(
+                PDFRendererContextConstants.PDF_CONTEXT);
+        
+        PDFImage pdfimage = new ImageRawCCITTFaxAdapter(ccitt, image.getInfo().getOriginalURI());
+        PDFXObject xobj = pdfDoc.addImage(resContext, pdfimage);
+
+        float x = (float)pos.getX() / 1000f;
+        float y = (float)pos.getY() / 1000f;
+        float w = (float)pos.getWidth() / 1000f;
+        float h = (float)pos.getHeight() / 1000f;
+        renderer.placeImage(x, y, w, h, xobj);
+        
+        return xobj;
+    }
+
+    /** {@inheritDoc} */
+    public int getPriority() {
+        return 100;
+    }
+
+    /** {@inheritDoc} */
+    public Class getSupportedImageClass() {
+        return ImageRawCCITTFax.class;
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor[] getSupportedImageFlavors() {
+        return FLAVORS;
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java Mon Dec 17 11:03:45 2007
@@ -33,7 +33,7 @@
 import org.apache.fop.render.RendererContext;
 
 /**
- * PDFImageHandler implementation which handles Graphics2D images.
+ * PDFImageHandler implementation which handles raw JPEG images.
  */
 public class PDFImageHandlerRawJPEG implements PDFImageHandler {
 

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java?rev=604968&r1=604967&r2=604968&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java Mon Dec 17 11:03:45 2007
@@ -22,8 +22,8 @@
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
-import java.util.SortedSet;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -52,6 +52,8 @@
 
     /** Map containing PDF image handlers for various MIME types */
     private Map handlers = new java.util.HashMap();
+    /** List containing the same handlers as above but ordered by priority */
+    private List handlerList = new java.util.LinkedList();
     
     /** Sorted Set of registered handlers */
     private ImageFlavor[] supportedFlavors = new ImageFlavor[0];
@@ -97,6 +99,17 @@
     public synchronized void addHandler(PDFImageHandler handler) {
         Class imageClass = handler.getSupportedImageClass();
         this.handlers.put(imageClass, handler);
+        
+        //Sorted insert
+        ListIterator iter = this.handlerList.listIterator();
+        while (iter.hasNext()) {
+            PDFImageHandler h = (PDFImageHandler)iter.next();
+            if (HANDLER_COMPARATOR.compare(handler, h) < 0) {
+                iter.previous();
+                break;
+            }
+        }
+        iter.add(handler);
         this.handlerRegistrations++;
     }
     
@@ -135,13 +148,9 @@
      */
     public synchronized ImageFlavor[] getSupportedFlavors() {
         if (this.lastSync != this.handlerRegistrations) {
-            //Sort...
-            SortedSet sorted = new java.util.TreeSet(HANDLER_COMPARATOR);
-            sorted.addAll(this.handlers.values());
-            
-            //...and extract all ImageFlavors into a single array
+            //Extract all ImageFlavors into a single array
             List flavors = new java.util.ArrayList();
-            Iterator iter = sorted.iterator();
+            Iterator iter = this.handlerList.iterator();
             while (iter.hasNext()) {
                 ImageFlavor[] f = ((PDFImageHandler)iter.next()).getSupportedImageFlavors();
                 for (int i = 0; i < f.length; i++) {

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+import org.apache.xmlgraphics.ps.ImageEncoder;
+
+import org.apache.fop.image2.impl.ImageRawCCITTFax;
+
+/**
+ * ImageEncoder implementation for CCITT encoded images.
+ */
+public class ImageEncoderCCITTFax implements ImageEncoder {
+    
+    private final ImageRawCCITTFax ccitt;
+
+    /**
+     * Main constructor.
+     * @param ccitt the CCITT encoded image
+     */
+    public ImageEncoderCCITTFax(ImageRawCCITTFax ccitt) {
+        this.ccitt = ccitt;
+    }
+
+    /** {@inheritDoc} */
+    public void writeTo(OutputStream out) throws IOException {
+        ccitt.writeTo(out);
+    }
+
+    /** {@inheritDoc} */
+    public String getImplicitFilter() {
+        PSDictionary dict = new PSDictionary();
+        dict.put("/Columns", new Integer(ccitt.getSize().getWidthPx()));
+        int compression = ccitt.getCompression();
+        switch (compression) {
+        case TIFFImage.COMP_FAX_G3_1D :
+            dict.put("/K", new Integer(0));
+            break;
+        case TIFFImage.COMP_FAX_G3_2D :
+            dict.put("/K", new Integer(1));
+            break;
+        case TIFFImage.COMP_FAX_G4_2D :
+            dict.put("/K", new Integer(-1));
+            break;
+        default:
+            throw new IllegalStateException(
+                    "Invalid compression scheme: " + compression);
+        }
+        
+        return dict.toString() + " /CCITTFaxDecode";
+    }
+}
\ No newline at end of file

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderCCITTFax.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java?rev=604968&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java Mon Dec 17 11:03:45 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.xmlgraphics.ps.ImageEncoder;
+
+import org.apache.fop.image2.impl.ImageRawJPEG;
+
+/**
+ * ImageEncoder implementation for JPEG images.
+ */
+public class ImageEncoderJPEG implements ImageEncoder {
+    private final ImageRawJPEG jpeg;
+
+    /**
+     * Main constructor
+     * @param jpeg the JPEG image
+     */
+    public ImageEncoderJPEG(ImageRawJPEG jpeg) {
+        this.jpeg = jpeg;
+    }
+
+    /** {@inheritDoc} */
+    public void writeTo(OutputStream out) throws IOException {
+        jpeg.writeTo(out);
+    }
+
+    /** {@inheritDoc} */
+    public String getImplicitFilter() {
+        return "<< >> /DCTDecode";
+    }
+}
\ No newline at end of file

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/ImageEncoderJPEG.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org