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/11/14 13:13:06 UTC

svn commit: r594848 [1/3] - in /xmlgraphics/fop/branches/Temp_ImagePackageRedesign: ./ lib/ src/java/META-INF/services/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/image2/ src/java/org/apache/fop/image2/impl/ src/java/org/apache/fop/image2/im...

Author: jeremias
Date: Wed Nov 14 04:12:50 2007
New Revision: 594848

URL: http://svn.apache.org/viewvc?rev=594848&view=rev
Log:
Initial upload of what I have already for the image package redesign.
For now, it's in a parallel package (image2). The final package name is TBD.
The code isn't hooked into the renderers, yet, and there's no image cache. This is still all work in progress.

Added:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/batik-all-1.7svn.jar   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/xml-apis-ext.jar
      - copied unchanged from r594834, xmlgraphics/batik/trunk/lib/xml-apis-ext.jar
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter
    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.image2.spi.ImagePreloader
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/Image.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageException.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageInfo.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageProcessingHints.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSize.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSource.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageConverter.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoader.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImagePreloader.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageBuffered.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBuffered2Rendered.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageGraphics2D.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRendered.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageXMLDOM.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderBMP.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderEMF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderEPS.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderGIF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderJPEG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderPNG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderTIFF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/BatikUtil.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterSVG2G2D.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterWMF2G2D.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactorySVG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderFactoryWMF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderSVG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageLoaderWMF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageWMF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/PreloaderSVG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/PreloaderWMF.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/package.html   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/package.html   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/package.html   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/package.html   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/package.html   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/package.html   (with props)
Removed:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/batik-all-1.6.jar
Modified:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/fop.bat
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/xmlgraphics-commons-1.3svn.jar
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/apps/FopFactory.java

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/fop.bat
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/fop.bat?rev=594848&r1=594847&r2=594848&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/fop.bat (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/fop.bat Wed Nov 14 04:12:50 2007
@@ -56,10 +56,11 @@
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LOCAL_FOP_HOME%build\fop-sandbox.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LOCAL_FOP_HOME%build\fop-hyph.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xml-apis-1.3.02.jar
+set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xml-apis-ext.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xercesImpl-2.7.1.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xalan-2.7.0.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\serializer-2.7.0.jar
-set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\batik-all-1.6.jar
+set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\batik-all-1.7svn.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xmlgraphics-commons-1.3svn.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\avalon-framework-4.2.0.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\commons-io-1.3.1.jar

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/batik-all-1.7svn.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/batik-all-1.7svn.jar?rev=594848&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/batik-all-1.7svn.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/xmlgraphics-commons-1.3svn.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/xmlgraphics-commons-1.3svn.jar?rev=594848&r1=594847&r2=594848&view=diff
==============================================================================
Binary files - no diff available.

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter Wed Nov 14 04:12:50 2007
@@ -0,0 +1,4 @@
+org.apache.fop.image2.impl.ImageConverterBuffered2Rendered
+org.apache.fop.image2.impl.ImageConverterG2D2Bitmap
+org.apache.fop.image2.impl.batik.ImageConverterSVG2G2D
+org.apache.fop.image2.impl.batik.ImageConverterWMF2G2D

Added: 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=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory Wed Nov 14 04:12:50 2007
@@ -0,0 +1,3 @@
+org.apache.fop.image2.impl.imageio.ImageLoaderFactoryImageIO
+org.apache.fop.image2.impl.batik.ImageLoaderFactorySVG
+org.apache.fop.image2.impl.batik.ImageLoaderFactoryWMF
\ No newline at end of file

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImagePreloader
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImagePreloader?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImagePreloader (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImagePreloader Wed Nov 14 04:12:50 2007
@@ -0,0 +1,9 @@
+org.apache.fop.image2.impl.PreloaderPNG
+org.apache.fop.image2.impl.PreloaderTIFF
+org.apache.fop.image2.impl.PreloaderGIF
+org.apache.fop.image2.impl.PreloaderJPEG
+org.apache.fop.image2.impl.PreloaderBMP
+org.apache.fop.image2.impl.PreloaderEMF
+org.apache.fop.image2.impl.PreloaderEPS
+org.apache.fop.image2.impl.batik.PreloaderSVG
+org.apache.fop.image2.impl.batik.PreloaderWMF
\ No newline at end of file

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/apps/FopFactory.java?rev=594848&r1=594847&r2=594848&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/apps/FopFactory.java Wed Nov 14 04:12:50 2007
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
@@ -36,7 +37,6 @@
 import org.xml.sax.SAXException;
 
 import org.apache.avalon.framework.configuration.Configuration;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -45,6 +45,7 @@
 import org.apache.fop.fonts.FontCache;
 import org.apache.fop.hyphenation.HyphenationTreeResolver;
 import org.apache.fop.image.ImageFactory;
+import org.apache.fop.image2.ImageManager;
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
 import org.apache.fop.render.RendererFactory;
 import org.apache.fop.render.XMLHandlerRegistry;
@@ -83,6 +84,9 @@
     /** Image factory for creating fop image objects */
     private ImageFactory imageFactory;
 
+    /** Image manager for loading and caching image objects */
+    private ImageManager imageManager;
+
     /** Configuration layer used to configure fop */
     private FopFactoryConfigurator config = null;
         
@@ -150,7 +154,8 @@
         this.elementMappingRegistry = new ElementMappingRegistry(this);
         this.foURIResolver = new FOURIResolver(validateUserConfigStrictly());
         this.colorSpaceCache = new ColorSpaceCache(foURIResolver);
-        this.imageFactory = new ImageFactory();        
+        this.imageFactory = new ImageFactory();
+        this.imageManager = new ImageManager();
         this.rendererFactory = new RendererFactory();
         this.xmlHandlers = new XMLHandlerRegistry();
         this.ignoredNamespaces = new java.util.HashSet();
@@ -293,6 +298,14 @@
     }
 
     /**
+     * Returns the image manager.
+     * @return the image manager
+     */
+    public ImageManager getImageManager() {
+        return this.imageManager;
+    }
+
+    /**
      * Add the element mapping with the given class name.
      * @param elementMapping the class name representing the element mapping.
      */
@@ -748,5 +761,6 @@
      */
     public ColorSpace getColorSpace(String baseUri, String iccProfileSrc) {
         return colorSpaceCache.get(baseUri, iccProfileSrc);
-    }    
+    }
+
 }

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/Image.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/Image.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/Image.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/Image.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * Represents an instance of an image (bitmap or vector graphic). The image may or may not be loaded
+ * into memory. Implementing classes will expose additional methods to access the actual image data.
+ */
+public interface Image {
+
+    /**
+     * Returns an object with basic information (URI, MIME type, intrinsic size) about the image. 
+     * @return the image information object
+     */
+    ImageInfo getInfo();
+    
+    /**
+     * Returns the image's intrinsic size. This is a shortcut for getInfo().getSize().
+     * @return the image's intrinsic size
+     */
+    ImageSize getSize();
+    
+    /**
+     * Returns the flavor of the image.
+     * @return the image flavor
+     */
+    ImageFlavor getFlavor();
+    
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageException.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageException.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageException.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+/**
+ * Base class for all image-related exceptions.
+ */
+public class ImageException extends Exception {
+
+    private static final long serialVersionUID = 3785613905389979249L;
+
+    /**
+     * Constructs an <code>ImageException</code> with the specified detail
+     * message. The error message string <code>s</code> can later be
+     * retrieved by the <code>{@link java.lang.Throwable#getMessage}</code>
+     * method of class <code>java.lang.Throwable</code>.
+     *
+     * @param   s   the detail message.
+     */
+    public ImageException(String s) {
+        super(s);
+    }
+
+    /**
+     * Constructs a new <code>ImageException</code> with the specified detail message and
+     * cause.  <p>Note that the detail message associated with
+     * <code>cause</code> is <i>not</i> automatically incorporated in
+     * this exception's detail message.
+     *
+     * @param  message the detail message (which is saved for later retrieval
+     *         by the {@link #getMessage()} method).
+     * @param  cause the cause (which is saved for later retrieval by the
+     *         {@link #getCause()} method).  (A <tt>null</tt> value is
+     *         permitted, and indicates that the cause is nonexistent or
+     *         unknown.)
+     */
+    public ImageException(String message, Throwable cause) {
+        super(message, cause);
+    }
+    
+}

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

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

Added: 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=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+/**
+ * The flavor of an image indicates in which form it is available. A bitmap image loaded into
+ * memory might be represented as a BufferedImage (indicated by ImageFlavor.BUFFERED_IMAGE).
+ * It is mostly used by consuming code to indicate what kind of flavors can be processed so a
+ * processing pipeline can do the necessary loading operations and conversions.
+ */
+public class ImageFlavor {
+
+    /** An image in form of a RenderedImage instance */
+    public static final ImageFlavor RENDERED_IMAGE = new ImageFlavor("RenderedImage");
+    /** An image in form of a BufferedImage instance */
+    public static final ImageFlavor BUFFERED_IMAGE = new ImageFlavor("BufferedImage");
+    /** An XML-based image in form of a W3C DOM instance */
+    public static final ImageFlavor XML_DOM = new ImageFlavor("text/xml;form=dom");
+    /** An image in form of a raw PNG file/stream */
+    public static final ImageFlavor RAW_PNG = new ImageFlavor("RawPNG");
+    /** An image in form of a raw JPEG/JFIF file/stream */
+    public static final ImageFlavor RAW_JPEG = new ImageFlavor("RawJPEG");
+    /** An image in form of a raw EMF (Windows Enhanced Metafile) file/stream */
+    public static final ImageFlavor RAW_EMF = new ImageFlavor("RawEMF");
+    /** An image in form of a Graphics2DImage (can be painted on a Graphics2D interface) */
+    public static final ImageFlavor GRAPHICS2D = new ImageFlavor("Graphics2DImage");
+    
+    private String name;
+    
+    /**
+     * Constructs a new ImageFlavor. Please reuse existing constants wherever possible!
+     * @param name the name of the flavor (must be unique)
+     */
+    public ImageFlavor(String name) {
+        this.name = name;
+    }
+    
+    /**
+     * Returns the name of the ImageFlavor.
+     * @return the flavor name
+     */
+    public String getName() {
+        return this.name;
+    }
+
+    /** {@inheritDoc} */
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        return result;
+    }
+
+    /** {@inheritDoc} */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final ImageFlavor other = (ImageFlavor)obj;
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        return getName();
+    }
+    
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageInfo.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageInfo.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageInfo.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,136 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+import javax.xml.transform.Source;
+
+/**
+ * Represents an image that may not have been fully loaded. Usually, the loading only goes as far
+ * as necessary to know the intrinsic size of the image. The image will only fully loaded later
+ * when the image needs to be presented in a particular format so the consuming component can
+ * actually process it. The "preloading" is done so a layout engine can work with the image without
+ * having to fully load it (in memory).
+ */
+public class ImageInfo {
+
+    /**
+     * Key to register the "original object" among the custom objects of an ImageInfo instance.
+     * @see #getOriginalImage()
+     */
+    public static final Object ORIGINAL_IMAGE = Image.class;
+
+    /** Original URI the image was accessed with */
+    private String originalURI;
+    /** Source to load the image from (may be null) */
+    private Source src;
+    /** MIME type of the image */
+    private String mimeType;
+
+    /** the image size */
+    private ImageSize size;
+
+    /**
+     * Map of custom objects that components further down the processing pipeline might need.
+     * Example: The DOM of an XML document.
+     */
+    private Map customObjects = new java.util.HashMap();
+    
+    /**
+     * Main constructor.
+     * @param originalURI the original URI that was specified by the user (not the resolved URI!)
+     * @param src The Source object from which an image is loaded
+     * @param mimeType the MIME type of the image
+     */
+    public ImageInfo(String originalURI, Source src, String mimeType) {
+        this.originalURI = originalURI;
+        this.src = src;
+        this.mimeType = mimeType;
+    }
+
+    /**
+     * Returns the Source that the image is originally loaded from.
+     * @return the Source
+     */
+    public Source getSource() {
+        return this.src;
+    }
+
+    /**
+     * Returns the original URI of the image.
+     * @return the original URI
+     */
+    public String getOriginalURI() {
+        return this.originalURI;
+    }
+
+    /**
+     * Returns the image's MIME type.
+     * @return the MIME type
+     */
+    public String getMimeType() {
+        return this.mimeType;
+    }
+
+    /**
+     * Returns the image's intrinsic size.
+     * @return the image size
+     */
+    public ImageSize getSize() {
+        return this.size;
+    }
+
+    /**
+     * Sets the image's intrinsic size.
+     * @param size the size
+     */
+    public void setSize(ImageSize size) {
+        this.size = size;
+    }
+    
+    /**
+     * Returns a Map of custom objects associated with this instance.
+     * @return the Map of custom objects
+     */
+    public Map getCustomObjects() {
+        return this.customObjects;
+    }
+    
+    /**
+     * Returns the original Image instance if such an Image instance is created while building
+     * this ImageInfo object. Some images cannot be "preloaded". They have to be fully loaded
+     * in order to determine the intrinsic image size. This method allows access to that fully
+     * loaded image so no additional re-loading has to be done later.
+     * <p>
+     * This method is short for: (Image)this.customObjects.get(ORIGINAL_IMAGE); 
+     * @return the original Image instance or null if none is set
+     * @see #ORIGINAL_IMAGE
+     */
+    public Image getOriginalImage() {
+        return (Image)this.customObjects.get(ORIGINAL_IMAGE);
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        return getMimeType() + ": " + getOriginalURI();
+    }
+    
+}

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

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

Added: 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=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageManager.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,241 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.image2.spi.ImageConverterPipeline;
+import org.apache.fop.image2.spi.ImageImplRegistry;
+import org.apache.fop.image2.spi.ImagePreloader;
+import org.apache.fop.image2.util.ImageUtil;
+
+/**
+ * ImageManager is the central starting point for image access.
+ */
+public class ImageManager {
+
+    /** logger */
+    protected static Log log = LogFactory.getLog(ImageManager.class);
+
+    /** Holds all registered interface implementations for the image package */
+    private ImageImplRegistry registry = ImageImplRegistry.getDefaultInstance();
+    
+    /**
+     * Returns the ImageImplRegistry in use by the ImageManager.
+     * @return the ImageImplRegistry
+     */
+    public ImageImplRegistry getRegistry() {
+        return this.registry;
+    }
+    
+    protected ImageSource newImageSource(String uri, FOUserAgent userAgent) {
+        Source source = userAgent.resolveURI(uri);
+        if (source == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("URI could not be resolved: " + uri);
+            }
+            return null;
+        }
+        
+        ImageSource imageSource = null;
+        
+        String resolvedURI = source.getSystemId();
+        URL url;
+        try {
+            url = new URL(resolvedURI);
+        } catch (MalformedURLException e) {
+            url = null;
+        } 
+        File f = FileUtils.toFile(url);
+        if (f != null) {
+            boolean directFileAccess = true;
+            InputStream in = null;
+            if (source instanceof StreamSource) {
+                StreamSource streamSource = (StreamSource)source; 
+                in = streamSource.getInputStream();
+                in = ImageUtil.decorateMarkSupported(in);
+                try {
+                    if (ImageUtil.isGZIPCompressed(in)) {
+                        //GZIPped stream are not seekable, so buffer/cache like other URLs
+                        directFileAccess = false;
+                    }
+                } catch (IOException ioe) {
+                    log.error("Error while checking the InputStream for GZIP compression."
+                            + " Could not load image from system identifier '"
+                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
+                    return null;
+                }
+            }
+            
+            if (directFileAccess) {
+                //Close as the file is reopened in a more optimal way
+                IOUtils.closeQuietly(in);
+                try {
+                    imageSource = new ImageSource(ImageIO.createImageInputStream(f), resolvedURI);
+                } catch (IOException ioe) {
+                    log.error("Unable to create ImageInputStream for local file"
+                            + " from system identifier '"
+                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
+                }
+            }
+        }
+        
+        if (imageSource == null) {
+            // Got a valid source, obtain an InputStream from it
+            InputStream in = null;
+            if (source instanceof StreamSource) {
+                in = ((StreamSource)source).getInputStream();
+            }
+            if (in == null && url != null) {
+                try {
+                    in = url.openStream();
+                } catch (Exception ex) {
+                    log.error("Unable to obtain stream from system identifier '" 
+                        + source.getSystemId() + "'");
+                }
+            }
+            if (in == null) {
+                log.error("The Source that was returned from URI resolution didn't contain"
+                        + " an InputStream for URI: " + uri);
+                return null;
+            }
+
+            try {
+                //Buffer and uncompress if necessary
+                in = ImageUtil.autoDecorateInputStream(in);
+                imageSource = new ImageSource(
+                        ImageIO.createImageInputStream(in), source.getSystemId());
+            } catch (IOException ioe) {
+                log.error("Unable to create ImageInputStream for InputStream"
+                        + " from system identifier '"
+                        + source.getSystemId() + "' (" + ioe.getMessage() + ")");
+            }
+        }
+        return imageSource;
+    }
+    
+    /**
+     * Preloads an image, i.e. the format of the image is identified and some basic information
+     * (MIME type, intrinsic size and possibly other values) are loaded and returned as an
+     * ImageInfo object. Note that the image is not fully loaded normally. Only with certain formats
+     * the image is already fully loaded and references added to the ImageInfo's custom objects
+     * (see {@link ImageInfo#getOriginalImage()}).
+     * <p>
+     * The reason for the preloading: Apache FOP, for example, only needs the image's intrinsic
+     * size during layout. Only when the document is rendered to the final format does FOP need
+     * to load the full image. Like this a lot of memory can be saved.
+     * @param uri the URI to load the image from
+     * @param userAgent the user agent used during the loading process
+     * @return the ImageInfo object created from the image
+     * @throws ImageException If no suitable ImagePreloader can be found to load the image or
+     *          if an error occurred while preloading the image.
+     * @throws IOException If an I/O error occurs while preloading the image
+     */
+    public ImageInfo preloadImage(String uri, FOUserAgent userAgent)
+                throws ImageException, IOException {
+        ImageSource imageSource = newImageSource(uri, userAgent);
+        return preloadImage(uri, imageSource, userAgent);
+    }
+
+    private ImageInfo preloadImage(String uri, Source src, FOUserAgent userAgent)
+            throws ImageException, IOException {
+        Iterator iter = registry.getPreloaderIterator();
+        while (iter.hasNext()) {
+            ImagePreloader preloader = (ImagePreloader)iter.next();
+            ImageInfo info = preloader.preloadImage(uri, src, userAgent);
+            if (info != null) {
+                return info;
+            }
+        }
+        ImageUtil.closeQuietly(src);
+        throw new ImageException("No ImagePreloader found for " + uri);
+    }
+
+    /**
+     * Loads an image. The caller can indicate what kind of image flavor is requested. When this
+     * method is called the code looks for a suitable ImageLoader and, if necessary, builds
+     * a conversion pipeline so it can return the image in exactly the form the caller needs.
+     * <p>
+     * Optionally, it is possible to pass in Map of hints. These hints may be used by ImageLoaders
+     * and ImageConverters to act on the image. See {@link ImageProcessingHints} for common hints
+     * used by the bundled implementations. You can, of course, define your own hints.
+     * @param info the ImageInfo instance for the image (obtained by 
+     *                  {@link #preloadImage(String, FOUserAgent)})
+     * @param flavor the requested image flavor.
+     * @param hints a Map of hints to any of the background components or null
+     * @return the fully loaded image
+     * @throws ImageException If no suitable loader/converter combination is available to fulfill
+     *                  the request or if an error occurred while loading the image.
+     * @throws IOException If an I/O error occurs
+     */
+    public Image getImage(ImageInfo info, ImageFlavor flavor, Map hints)
+            throws ImageException, IOException {
+        if (hints == null) {
+            hints = Collections.EMPTY_MAP;
+        }
+        String mime = info.getMimeType();
+        
+        Image img = null;
+        ImageConverterPipeline pipeline = registry.newImageConverterPipeline(mime, flavor);
+        if (pipeline != null) {
+            img = pipeline.execute(info, hints);
+        }
+        if (img == null) {
+            throw new ImageException(
+                    "Cannot load image (no suitable loader/converter combination available) for "
+                        + info);
+        }
+        return img;
+    }
+    
+    /**
+     * Loads an image with no hints. See {@link #getImage(ImageInfo, ImageFlavor, Map)} for more
+     * information.
+     * @param info the ImageInfo instance for the image (obtained by 
+     *                  {@link #preloadImage(String, FOUserAgent)})
+     * @param flavor the requested image flavor.
+     * @return the fully loaded image
+     * @throws ImageException If no suitable loader/converter combination is available to fulfill
+     *                  the request or if an error occurred while loading the image.
+     * @throws IOException If an I/O error occurs
+     */
+    public Image getImage(ImageInfo info, ImageFlavor flavor)
+            throws ImageException, IOException {
+        return getImage(info, flavor, null);
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageProcessingHints.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageProcessingHints.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageProcessingHints.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageProcessingHints.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * This interface defines some standard hints to be used for image processing in this package.
+ * They are provided for convenience. You can define your own hints as you like.
+ */
+public interface ImageProcessingHints {
+
+    /** Used to send a hint about the source resolution for pixel to unit conversions. */
+    Object SOURCE_RESOLUTION = "SOURCE_RESOLUTION"; //Value: Number (unit dpi)
+    /** Used to send a hint about the target resolution (of the final output format). */
+    Object TARGET_RESOLUTION = "TARGET_RESOLUTION"; //Value: Number (unit dpi)
+    
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSize.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSize.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSize.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSize.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,192 @@
+/*
+ * 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;
+
+import java.awt.Dimension;
+
+import org.apache.fop.util.UnitConv;
+
+/**
+ * Encapsulates the size of an image.
+ */
+public class ImageSize {
+
+    private int widthPx;
+    private int heightPx;
+    
+    private int widthMpt;
+    private int heightMpt;
+    
+    private double dpiHorizontal;
+    private double dpiVertical;
+    
+    /**
+     * Constructor.
+     * @param widthPx the width of the image in pixels
+     * @param heightPx the height of the image in pixels
+     * @param dpiHorizontal the horizontal resolution in dots per inch
+     * @param dpiVertical the vertical resolution in dots per inch
+     */
+    public ImageSize(int widthPx, int heightPx, double dpiHorizontal, double dpiVertical) {
+        setSizeInPixels(widthPx, heightPx);
+        setResolution(dpiHorizontal, dpiVertical);
+    }
+    
+    /**
+     * Constructor.
+     * @param widthPx the width of the image in pixels
+     * @param heightPx the height of the image in pixels
+     * @param dpi the resolution in dots per inch
+     */
+    public ImageSize(int widthPx, int heightPx, double dpi) {
+        this(widthPx, heightPx, dpi, dpi);
+    }
+    
+    /**
+     * Default Constructor.
+     */
+    public ImageSize() {
+        //nop
+    }
+    
+    /**
+     * Sets the image's size in pixels.
+     * @param width the width in pixels 
+     * @param height the height in pixels
+     */
+    public void setSizeInPixels(int width, int height) {
+        this.widthPx = width;
+        this.heightPx = height;
+    }
+    
+    /**
+     * Sets the image's size in millipoints.
+     * @param width the width in millipoints 
+     * @param height the height in millipoints
+     */
+    public void setSizeInMillipoints(int width, int height) {
+        this.widthMpt = width;
+        this.heightMpt = height;
+    }
+    
+    /**
+     * Sets the image's resolution for interpreting the pixel size.
+     * @param horizontal the horizontal resolution in dpi
+     * @param vertical the vertical resolution in dpi
+     */
+    public void setResolution(double horizontal, double vertical) {
+        this.dpiHorizontal = horizontal;
+        this.dpiVertical = vertical;
+    }
+    
+    /**
+     * Sets the image's resolution for interpreting the pixel size.
+     * @param resolution the resolution in dpi
+     */
+    public void setResolution(double resolution) {
+        setResolution(resolution, resolution);
+    }
+    
+    /**
+     * Returns the image's width in pixels.
+     * @return the width in pixels
+     */
+    public int getWidthPx() {
+        return widthPx;
+    }
+
+    /**
+     * Returns the image's height in pixels.
+     * @return the height in pixels
+     */
+    public int getHeightPx() {
+        return heightPx;
+    }
+
+    /**
+     * Returns the image's width in millipoints.
+     * @return the width in millipoints
+     */
+    public int getWidthMpt() {
+        return widthMpt;
+    }
+
+    /**
+     * Returns the image's height in millipoints.
+     * @return the height in millipoints
+     */
+    public int getHeightMpt() {
+        return heightMpt;
+    }
+
+    /**
+     * Returns the image's horizontal resolution in dpi (dots per inch).
+     * @return the horizontal resolution in dpi
+     */
+    public double getDpiHorizontal() {
+        return dpiHorizontal;
+    }
+
+    /**
+     * Returns the image's vertical resolution in dpi (dots per inch).
+     * @return the vertical resolution in dpi
+     */
+    public double getDpiVertical() {
+        return dpiVertical;
+    }
+
+    /**
+     * Returns the size in millipoints as a Dimension object.
+     * @return the size in millipoints
+     */
+    public Dimension getDimensionMpt() {
+        return new Dimension(getWidthMpt(), getHeightMpt());
+    }
+    
+    /**
+     * Calculates the size in millipoints based on the size in pixels and the resolution.
+     */
+    public void calcSizeFromPixels() {
+        this.widthMpt = (int)Math.round(UnitConv.in2mpt(this.widthPx / this.dpiHorizontal));
+        this.heightMpt = (int)Math.round(UnitConv.in2mpt(this.heightPx / this.dpiVertical));
+    }
+
+    /**
+     * Calculates the size in pixels based on the size in millipoints and the resolution.
+     */
+    public void calcPixelsFromSize() {
+        this.widthPx = (int)Math.round(UnitConv.mpt2in(this.widthMpt * this.dpiHorizontal));
+        this.heightPx = (int)Math.round(UnitConv.mpt2in(this.heightMpt * this.dpiVertical));
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("Size: ");
+        sb.append(getWidthMpt()).append('x').append(getHeightMpt()).append(" mpt");
+        sb.append(" (");
+        sb.append(getWidthPx()).append('x').append(getHeightPx()).append(" px");
+        sb.append(" at ").append(getDpiHorizontal()).append('x').append(getDpiVertical());
+        sb.append(" dpi");
+        sb.append(")");
+        return sb.toString();
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSource.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSource.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSource.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageSource.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+import javax.xml.transform.Source;
+
+import org.apache.fop.image2.util.ImageInputStreamAdapter;
+
+/**
+ * Acts as a holder for the input to image loading operations.
+ */
+public class ImageSource implements Source {
+    
+    private String systemId;
+    private ImageInputStream iin;
+
+    /**
+     * Main constructor.
+     * @param in the ImageInputStream to load from
+     * @param systemId the system identifier (resolved URI) of the image
+     */
+    public ImageSource(ImageInputStream in, String systemId) {
+        this.iin = in;
+        this.systemId = systemId;
+    }
+
+    /**
+     * Returns an InputStream which operates on the underlying ImageInputStream.
+     * @return the InputStream or null if the stream has been closed
+     */
+    public InputStream getInputStream() {
+        return new ImageInputStreamAdapter(this.iin);
+    }
+
+    /**
+     * Returns the ImageInputStream.
+     * @return the ImageInputStream or null if the stream has been closed
+     */
+    public ImageInputStream getImageInputStream() {
+        return this.iin;
+    }
+    
+    /**
+     * Sets the ImageInputStream.
+     * @param in the ImageInputStream
+     */
+    public void setImageInputStream(ImageInputStream in) {
+        this.iin = in;
+    }
+    
+    /** {@inheritDoc} */
+    public String getSystemId() {
+        return this.systemId;
+    }
+
+    /** {@inheritDoc} */
+    public void setSystemId(String systemId) {
+        this.systemId = systemId;
+    }
+    
+}

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

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

Added: 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=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImage.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.Image;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageSize;
+
+/**
+ * Abstract base class for Image implementations.
+ */
+public abstract class AbstractImage implements Image {
+
+    private ImageInfo info;
+    
+    /**
+     * Main constructor
+     * @param info the image info object associated with this image
+     */
+    public AbstractImage(ImageInfo info) {
+        this.info = info;
+    }
+    
+    /** {@inheritDoc} */
+    public ImageInfo getInfo() {
+        return this.info;
+    }
+
+    /** {@inheritDoc} */
+    public ImageSize getSize() {
+        return getInfo().getSize();
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageConverter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageConverter.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageConverter.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageConverter.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.Image;
+import org.apache.fop.image2.spi.ImageConverter;
+
+/**
+ * This ImageConverter converts WMF images (represented by Batik's WMFRecordStore) to a
+ * BufferedImage.
+ */
+public abstract class AbstractImageConverter implements ImageConverter {
+
+    /**
+     * Checks if the source flavor of the given image is compatible with this ImageConverter.
+     * @param img the image to check
+     */
+    protected void checkSourceFlavor(Image img) {
+        if (!getSourceFlavor().equals(img.getFlavor())) {
+            throw new IllegalArgumentException("Incompatible image: " + img);
+        }
+    }
+    
+    /** {@inheritDoc} */
+    public int getConversionPenalty() {
+        return MEDIUM_CONVERSION_PENALTY;
+    }
+    
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoader.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoader.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImageLoader.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.spi.ImageLoader;
+
+/**
+ * Simple abstract base class for ImageLoaders.
+ */
+public abstract class AbstractImageLoader implements ImageLoader {
+
+    /** {@inheritDoc} */ 
+    public Image loadImage(ImageInfo info) throws ImageException, IOException {
+        return loadImage(info, null);
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImagePreloader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImagePreloader.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImagePreloader.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/AbstractImagePreloader.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,50 @@
+/*
+ * 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 javax.imageio.stream.ImageInputStream;
+
+import org.apache.fop.image2.spi.ImagePreloader;
+
+/**
+ * Abstract base class for image preloaders. It provides helper methods for often-used tasks.
+ */
+public abstract class AbstractImagePreloader implements ImagePreloader {
+
+    /**
+     * Allows to read an image header (usually just a magic number). The InputStream is reset
+     * to the position before the header was read.
+     * @param in the ImageInputStream to read from 
+     * @param size the size of the header
+     * @return the loaded header
+     * @throws IOException if an I/O error occurs while reading the header
+     */
+    protected byte[] getHeader(ImageInputStream in, int size)
+                throws IOException {
+        byte[] header = new byte[size];
+        long startPos = in.getStreamPosition();
+        in.readFully(header);
+        in.seek(startPos); //Seek back to start position
+        return header;
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageBuffered.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageBuffered.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageBuffered.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageBuffered.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.image.BufferedImage;
+
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This class is an implementation of the Image interface exposing a BufferedImage.
+ */
+public class ImageBuffered extends ImageRendered {
+
+    /**
+     * Main constructor.
+     * @param info the image info object
+     * @param buffered the BufferedImage instance
+     */
+    public ImageBuffered(ImageInfo info, BufferedImage buffered) {
+        super(info, buffered);
+    }
+    
+    /** {@inheritDoc} */
+    public ImageFlavor getFlavor() {
+        return ImageFlavor.BUFFERED_IMAGE;
+    }
+
+    /**
+     * Returns the contained BufferedImage instance.
+     * @return the BufferedImage instance
+     */
+    public java.awt.image.BufferedImage getBufferedImage() {
+        return (BufferedImage)getRenderedImage();
+    }
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBuffered2Rendered.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBuffered2Rendered.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBuffered2Rendered.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBuffered2Rendered.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.util.Map;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageFlavor;
+
+/**
+ * This ImageConverter converts BufferedImages to RenderedImages (well, it's basically just a
+ * class cast).
+ */
+public class ImageConverterBuffered2Rendered extends AbstractImageConverter {
+
+    /** {@inheritDoc} */
+    public Image convert(Image src, Map hints) {
+        checkSourceFlavor(src);
+        ImageBuffered buffered = (ImageBuffered)src;
+        return new ImageRendered(buffered.getInfo(), buffered.getRenderedImage());
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor getSourceFlavor() {
+        return ImageFlavor.BUFFERED_IMAGE;
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor getTargetFlavor() {
+        return ImageFlavor.RENDERED_IMAGE;
+    }
+
+    /** {@inheritDoc} */
+    public int getConversionPenalty() {
+        return NO_CONVERSION_PENALTY;
+    }
+    
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,173 @@
+/*
+ * 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;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+import java.util.Map;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageProcessingHints;
+import org.apache.fop.image2.ImageSize;
+import org.apache.fop.util.UnitConv;
+
+/**
+ * This ImageConverter converts WMF images (represented by Batik's WMFRecordStore) to a
+ * BufferedImage.
+ */
+public class ImageConverterG2D2Bitmap extends AbstractImageConverter {
+
+    /** {@inheritDoc} */
+    public Image convert(Image src, Map hints) {
+        checkSourceFlavor(src);
+        ImageGraphics2D g2dImage = (ImageGraphics2D)src;
+
+        //TODO Make configurable!
+        boolean gray = false;
+        boolean withAlpha = true;
+        int resolution = 300; //default: 300dpi
+        Number res = (Number)hints.get(ImageProcessingHints.TARGET_RESOLUTION);
+        if (res != null) {
+            resolution = res.intValue();
+        }
+        
+        BufferedImage bi = paintToBufferedImage(g2dImage, gray, withAlpha, resolution);
+        
+        ImageBuffered bufImage = new ImageBuffered(src.getInfo(), bi);
+        return bufImage;
+    }
+
+    /**
+     * Paints a Graphics2D image on a BufferedImage and returns this bitmap.
+     * @param g2dImage the Graphics2D image
+     * @param gray true if the generated image should be in grayscales
+     * @param withAlpha true if the generated image should have an alpha channel
+     * @param resolution the requested bitmap resolution
+     * @return the newly created BufferedImage
+     */
+    protected BufferedImage paintToBufferedImage(ImageGraphics2D g2dImage,
+            boolean gray, boolean withAlpha, int resolution) {
+        ImageSize size = g2dImage.getSize();
+        
+        int bmw = (int)Math.ceil(UnitConv.mpt2px(size.getWidthMpt(), resolution));
+        int bmh = (int)Math.ceil(UnitConv.mpt2px(size.getHeightMpt(), resolution));
+        BufferedImage bi;
+        if (gray) {
+            if (withAlpha) {
+                bi = createGrayBufferedImageWithAlpha(bmw, bmh);
+            } else {
+                bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_BYTE_GRAY);
+            }
+        } else {
+            if (withAlpha) {
+                bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_ARGB);
+            } else {
+                bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_RGB);
+            }
+        }
+        Graphics2D g2d = bi.createGraphics();
+        try {
+            g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, 
+                    RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+            setRenderingHintsForBufferedImage(g2d);
+            
+            g2d.setBackground(Color.white);
+            g2d.setColor(Color.black);
+            if (!withAlpha) {
+                g2d.clearRect(0, 0, bmw, bmh);
+            }
+            /* debug code
+            int off = 2;
+            g2d.drawLine(off, 0, off, bmh);
+            g2d.drawLine(bmw - off, 0, bmw - off, bmh);
+            g2d.drawLine(0, off, bmw, off);
+            g2d.drawLine(0, bmh - off, bmw, bmh - off);
+            */
+            double sx = (double)bmw / size.getWidthMpt();
+            double sy = (double)bmh / size.getHeightMpt();
+            g2d.scale(sx, sy);
+
+            //Paint the image on the BufferedImage
+            Rectangle2D area = new Rectangle2D.Double(
+                    0.0, 0.0, size.getWidthMpt(), size.getHeightMpt());
+            g2dImage.getGraphics2DImagePainter().paint(g2d, area);
+        } finally {
+            g2d.dispose();
+        }
+        return bi;
+    }
+
+    private static BufferedImage createGrayBufferedImageWithAlpha(int width, int height) {
+        BufferedImage bi;
+        boolean alphaPremultiplied = true;
+        int bands = 2;
+        int[] bits = new int[bands];
+        for (int i = 0; i < bands; i++) {
+            bits[i] = 8;
+        }
+        ColorModel cm = new ComponentColorModel(
+                ColorSpace.getInstance(ColorSpace.CS_GRAY),
+                bits,
+                true, alphaPremultiplied,
+                Transparency.TRANSLUCENT,
+                DataBuffer.TYPE_BYTE);
+        WritableRaster wr = Raster.createInterleavedRaster(
+                DataBuffer.TYPE_BYTE,
+                width, height, bands,
+                new Point(0, 0));
+        bi = new BufferedImage(cm, wr, alphaPremultiplied, null);
+        return bi;
+    }
+
+    /**
+     * Sets rendering hints on the Graphics2D created for painting to a BufferedImage. Subclasses
+     * can modify the settings to customize the behaviour.
+     * @param g2d the Graphics2D instance
+     */
+    protected void setRenderingHintsForBufferedImage(Graphics2D g2d) {
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
+            RenderingHints.VALUE_ANTIALIAS_OFF);
+        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 
+            RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor getSourceFlavor() {
+        return ImageFlavor.GRAPHICS2D;
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor getTargetFlavor() {
+        return ImageFlavor.BUFFERED_IMAGE;
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageGraphics2D.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageGraphics2D.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageGraphics2D.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.render.Graphics2DImagePainter;
+
+/**
+ * This class is an implementation of the Image interface exposing a Graphics2DImagePainter.
+ */
+public class ImageGraphics2D extends AbstractImage {
+
+    private Graphics2DImagePainter painter;
+    
+    /**
+     * Main constructor.
+     * @param info the image info object
+     * @param painter the image painter that will paint the Java2D image
+     */
+    public ImageGraphics2D(ImageInfo info, Graphics2DImagePainter painter) {
+        super(info);
+        this.painter = painter;
+    }
+    
+    /** {@inheritDoc} */
+    public ImageFlavor getFlavor() {
+        return ImageFlavor.GRAPHICS2D;
+    }
+
+    /**
+     * Returns the contained Graphics2DImagePainter instance.
+     * @return the image painter
+     */
+    public Graphics2DImagePainter getGraphics2DImagePainter() {
+        return this.painter;
+    }
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRendered.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRendered.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRendered.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRendered.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,56 @@
+/*
+ * 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.image.RenderedImage;
+
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This class is an implementation of the Image interface exposing a RenderedImage.
+ */
+public class ImageRendered extends AbstractImage {
+
+    private RenderedImage red;
+    
+    /**
+     * Main constructor.
+     * @param info the image info object
+     * @param red the RenderedImage instance
+     */
+    public ImageRendered(ImageInfo info, RenderedImage red) {
+        super(info);
+        this.red = red;
+    }
+    
+    /** {@inheritDoc} */
+    public ImageFlavor getFlavor() {
+        return ImageFlavor.RENDERED_IMAGE;
+    }
+
+    /**
+     * Returns the contained RenderedImage instance.
+     * @return the RenderedImage instance
+     */
+    public RenderedImage getRenderedImage() {
+        return this.red;
+    }
+}

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

Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRendered.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