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/29 14:17:16 UTC

svn commit: r599436 - in /xmlgraphics/fop/branches/Temp_ImagePackageRedesign: lib/ src/java/META-INF/services/ src/java/org/apache/fop/fo/flow/ src/java/org/apache/fop/image2/ src/java/org/apache/fop/image2/impl/ src/java/org/apache/fop/render/java2d/ ...

Author: jeremias
Date: Thu Nov 29 05:17:14 2007
New Revision: 599436

URL: http://svn.apache.org/viewvc?rev=599436&view=rev
Log:
Started integrating into Java2D and PostScript renderers and ExternalGraphic.
Added support for EPS graphics.
Added support for raw embedding of JPEG images (for PostScript).

Added:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderEPS.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawJPEG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawEPS.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawJPEG.java   (with props)
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/JPEGConstants.java   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/lib/xmlgraphics-commons-1.3svn.jar
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageLoaderFactory
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/ImageFlavor.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/PreloaderEPS.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderJPEG.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSRenderer.java
    xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/java/org/apache/fop/image2/ImageLoaderTestCase.java

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=599436&r1=599435&r2=599436&view=diff
==============================================================================
Binary files - no diff available.

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=599436&r1=599435&r2=599436&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 Thu Nov 29 05:17:14 2007
@@ -1,4 +1,5 @@
 org.apache.fop.image2.impl.imageio.ImageLoaderFactoryImageIO
 org.apache.fop.image2.impl.batik.ImageLoaderFactorySVG
 org.apache.fop.image2.impl.batik.ImageLoaderFactoryWMF
-org.apache.fop.image2.impl.ImageLoaderFactoryRaw
\ No newline at end of file
+org.apache.fop.image2.impl.ImageLoaderFactoryRaw
+org.apache.fop.image2.impl.ImageLoaderFactoryEPS
\ No newline at end of file

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/fo/flow/ExternalGraphic.java?rev=599436&r1=599435&r2=599436&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/fo/flow/ExternalGraphic.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/fo/flow/ExternalGraphic.java Thu Nov 29 05:17:14 2007
@@ -19,15 +19,21 @@
 
 package org.apache.fop.fo.flow;
 
+import java.io.IOException;
+
+import org.xml.sax.Locator;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.datatypes.Length;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.xml.sax.Locator;
+import org.apache.fop.fo.properties.FixedLength;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageManager;
 
 /**
  * Class modelling the fo:external-graphic object.
@@ -64,20 +70,22 @@
         src = pList.get(PR_SRC).getString();
         
         //Additional processing: preload image
-        url = ImageFactory.getURL(getSrc());
+        url = URISpecification.getURL(src);
         FOUserAgent userAgent = getUserAgent();
-        ImageFactory fact = userAgent.getFactory().getImageFactory();
-        FopImage fopimage = fact.getImage(url, userAgent);
-        if (fopimage == null) {
-            log.error("Image not available: " + getSrc());
-        } else {
-            // load dimensions
-            if (!fopimage.load(FopImage.DIMENSIONS)) {
-                log.error("Cannot read image dimensions: " + getSrc());
-            }
-            this.intrinsicWidth = fopimage.getIntrinsicWidth();
-            this.intrinsicHeight = fopimage.getIntrinsicHeight();
-            this.intrinsicAlignmentAdjust = fopimage.getIntrinsicAlignmentAdjust();
+        ImageManager manager = userAgent.getFactory().getImageManager();
+        ImageInfo info = null;
+        try {
+            info = manager.preloadImage(url, userAgent);
+        } catch (ImageException e) {
+            log.error("Image not available: " + e.getMessage());
+        } catch (IOException ioe) {
+            log.error("I/O error while loading image: " + ioe.getMessage());
+        }
+        if (info != null) {
+            this.intrinsicWidth = info.getSize().getWidthMpt();
+            this.intrinsicHeight = info.getSize().getHeightMpt();
+            this.intrinsicAlignmentAdjust = new FixedLength(
+                    -info.getSize().getBaselinePositionFromBottom());
         }
         //TODO Report to caller so he can decide to throw an exception
     }

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=599436&r1=599435&r2=599436&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 Thu Nov 29 05:17:14 2007
@@ -39,6 +39,8 @@
     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 raw EPS (Encapsulated PostScript) file/stream */
+    public static final ImageFlavor RAW_EPS = new ImageFlavor("RawEPS");
     /** An image in form of a Graphics2DImage (can be painted on a Graphics2D interface) */
     public static final ImageFlavor GRAPHICS2D = new ImageFlavor("Graphics2DImage");
     

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderEPS.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderEPS.java?rev=599436&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderEPS.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderEPS.java Thu Nov 29 05:17:14 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.image2.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+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.util.ImageUtil;
+
+/**
+ * ImageLoader for EPS (Encapsulated PostScript) images.
+ */
+public class ImageLoaderEPS extends AbstractImageLoader {
+
+    /**
+     * Main constructor.
+     */
+    public ImageLoaderEPS() {
+    }        
+
+    /** {@inheritDoc} */
+    public ImageFlavor getTargetFlavor() {
+        return ImageFlavor.RAW_EPS;
+    }
+
+    /** {@inheritDoc} */
+    public Image loadImage(ImageInfo info, Map hints) throws ImageException, IOException {
+        if (!MimeConstants.MIME_EPS.equals(info.getMimeType())) {
+            throw new IllegalArgumentException(
+                    "ImageInfo must be from a image with MIME type: " + MimeConstants.MIME_EPS);
+        }
+        InputStream in = ImageUtil.needInputStream(info.getSource());
+
+        PreloaderEPS.EPSBinaryFileHeader binaryHeader;
+        binaryHeader = (PreloaderEPS.EPSBinaryFileHeader)info.getCustomObjects().get(
+                PreloaderEPS.EPS_BINARY_HEADER); 
+        if (binaryHeader != null) {
+            //Binary EPS: just extract the EPS part
+            in.skip(binaryHeader.getPSStart());
+            in = new SubInputStream(in, binaryHeader.getPSLength());
+        }
+        
+        ImageRawEPS epsImage = new ImageRawEPS(info, in);
+        return epsImage;
+    }
+
+}

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

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

Added: 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=599436&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderFactoryEPS.java Thu Nov 29 05:17:14 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.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 {
+
+    private static final String[] MIMES = new String[] {
+        MimeConstants.MIME_EPS};
+    
+    private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
+        ImageFlavor.RAW_EPS};
+
+    
+    /** {@inheritDoc} */
+    public String[] getSupportedMIMETypes() {
+        return MIMES;
+    }
+    
+    /** {@inheritDoc} */
+    public ImageFlavor[] getSupportedFlavors(String mime) {
+        if (MimeConstants.MIME_EPS.equals(mime)) {
+            return FLAVORS;
+        }
+        throw new IllegalArgumentException("Unsupported MIME type: " + mime);
+    }
+    
+    /** {@inheritDoc} */
+    public ImageLoader newImageLoader(ImageFlavor targetFlavor) {
+        return new ImageLoaderEPS();
+    }
+    
+    /** {@inheritDoc} */
+    public int getUsagePenalty(String mime, ImageFlavor flavor) {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isAvailable() {
+        return true;
+    }
+
+}

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

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

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=599436&r1=599435&r2=599436&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 Thu Nov 29 05:17:14 2007
@@ -76,7 +76,11 @@
     
     /** {@inheritDoc} */
     public ImageLoader newImageLoader(ImageFlavor targetFlavor) {
-        return new ImageLoaderRaw(targetFlavor);
+        if (targetFlavor.equals(ImageFlavor.RAW_JPEG)) {
+            return new ImageLoaderRawJPEG();
+        } else {
+            return new ImageLoaderRaw(targetFlavor);
+        }
     }
     
     /** {@inheritDoc} */

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawJPEG.java?rev=599436&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawJPEG.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageLoaderRawJPEG.java Thu Nov 29 05:17:14 2007
@@ -0,0 +1,249 @@
+/*
+ * 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 java.awt.color.ICC_Profile;
+import java.io.IOException;
+import java.util.Map;
+
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+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.util.ImageUtil;
+import org.apache.fop.util.CMYKColorSpace;
+
+/**
+ * ImageLoader for JPEG images consumed "raw" (undecoded). Provides a
+ * raw/undecoded stream.
+ */
+public class ImageLoaderRawJPEG extends AbstractImageLoader implements JPEGConstants {
+
+    /** logger */
+    protected static Log log = LogFactory.getLog(ImageLoaderRawJPEG.class);
+
+    /**
+     * Main constructor.
+     */
+    public ImageLoaderRawJPEG() {
+    }
+
+    /** {@inheritDoc} */
+    public ImageFlavor getTargetFlavor() {
+        return ImageFlavor.RAW_JPEG;
+    }
+
+    /** {@inheritDoc} */
+    public Image loadImage(ImageInfo info, Map hints) throws ImageException, IOException {
+        if (!MimeConstants.MIME_JPEG.equals(info.getMimeType())) {
+            throw new IllegalArgumentException("ImageInfo must be from a image with MIME type: "
+                    + MimeConstants.MIME_JPEG);
+        }
+
+        ColorSpace colorSpace = null;
+        boolean appeFound = false;
+        int sofType = 0;
+        ByteArrayOutputStream iccStream = null;
+        
+        ImageInputStream in = ImageUtil.needImageInputStream(info.getSource());
+        in.mark();
+        try {
+            outer:
+            while (true) {
+                int reclen;
+                int segID = readMarkerSegment(in);
+                log.debug("Seg Marker: " + Integer.toHexString(segID));
+                switch (segID) {
+                case EOI:
+                    log.debug("EOI found. Stopping.");
+                    break outer;
+                case SOS:
+                    log.debug("SOS found. Stopping early."); //TODO Not sure if this is safe
+                    break outer;
+                case SOI:
+                case NULL:
+                    break;
+                case SOF0: //baseline
+                case SOF2: //progressive (since PDF 1.3)
+                case SOFA: //progressive (since PDF 1.3)
+                    sofType = segID;
+                    if (log.isDebugEnabled()) {
+                        log.debug("SOF: " + Integer.toHexString(sofType));
+                    }
+                    in.mark();
+                    try {
+                        reclen = in.readUnsignedShort();
+                        in.skipBytes(1); //data precision
+                        in.skipBytes(2); //height
+                        in.skipBytes(2); //width
+                        int numComponents = in.readUnsignedByte();
+                        if (numComponents == 1) {
+                            colorSpace = ColorSpace.getInstance(
+                              ColorSpace.CS_GRAY);
+                        } else if (numComponents == 3) {
+                            colorSpace = ColorSpace.getInstance(
+                              ColorSpace.CS_LINEAR_RGB);
+                        } else if (numComponents == 4) {
+                            colorSpace = CMYKColorSpace.getInstance();
+                        } else {
+                            throw new ImageException("Unsupported ColorSpace for image "
+                                        + info 
+                                        + ". The number of components supported are 1, 3 and 4.");
+                        }
+                    } finally {
+                        in.reset();
+                    }
+                    in.skipBytes(reclen);
+                    break;
+                case APP2: //ICC (see ICC1V42.pdf)
+                    in.mark();
+                    try {
+                        reclen = in.readUnsignedShort();
+                        // Check for ICC profile
+                        byte[] iccString = new byte[11];
+                        in.readFully(iccString);
+                        in.skipBytes(1); //string terminator (null byte)
+
+                        if ("ICC_PROFILE".equals(new String(iccString, "US-ASCII"))) {
+                            log.debug("JPEG has an ICC profile");
+                            in.skipBytes(2); //chunk sequence number and total number of chunks
+                            if (iccStream == null) {
+                                //ICC profiles can be split into several chunks
+                                //so collect in a byte array output stream
+                                iccStream = new ByteArrayOutputStream();
+                            }
+                            byte[] buf = new byte[reclen - 18];
+                            in.readFully(buf);
+                            iccStream.write(buf);
+                        }
+                    } finally {
+                        in.reset();
+                    }
+                    in.skipBytes(reclen);
+                    break;
+                case APPE: //Adobe-specific (see 5116.DCT_Filter.pdf)
+                    in.mark();
+                    try {
+                        reclen = in.readUnsignedShort();
+                        // Check for Adobe header
+                        byte[] adobeHeader = new byte[5];
+                        in.readFully(adobeHeader);
+                        
+                        if ("Adobe".equals(new String(adobeHeader, "US-ASCII"))) {
+                            // The reason for reading the APPE marker is that Adobe Photoshop
+                            // generates CMYK JPEGs with inverted values. The correct thing
+                            // to do would be to interpret the values in the marker, but for now
+                            // only assume that if APPE marker is present and colorspace is CMYK,
+                            // the image is inverted.
+                            appeFound = true;
+                        }
+                    } finally {
+                        in.reset();
+                    }
+                    in.skipBytes(reclen);
+                    break;
+                default:
+                    reclen = in.readUnsignedShort();
+                    in.skipBytes(reclen - 2);
+                }
+            }
+        } finally {
+            in.reset();
+        }
+        
+        ICC_Profile iccProfile = buildICCProfile(info, colorSpace, iccStream);
+        if (iccProfile == null && colorSpace == null) {
+            throw new ImageException("ColorSpace not be identified for JPEG image " + info);
+        }
+
+        boolean invertImage = false;
+        if (appeFound && colorSpace.getType() == ColorSpace.TYPE_CMYK) {
+            if (log.isDebugEnabled()) {
+                log.debug("JPEG has an Adobe APPE marker. Note: CMYK Image will be inverted. ("
+                        + info.getOriginalURI() + ")");
+            }
+            invertImage = true;
+        }
+
+        ImageRawJPEG rawImage = new ImageRawJPEG(info,
+                ImageUtil.needInputStream(info.getSource()),
+                sofType, colorSpace, iccProfile, invertImage);
+        return rawImage;
+    }
+
+    private ICC_Profile buildICCProfile(ImageInfo info, ColorSpace colorSpace,
+            ByteArrayOutputStream iccStream) throws IOException, ImageException {
+        if (iccStream != null && iccStream.size() > 0) {
+            int padding = (8 - (iccStream.size() % 8)) % 8;
+            if (padding != 0) {
+                try {
+                    iccStream.write(new byte[padding]);
+                } catch (IOException ioe) {
+                    throw new IOException("Error while aligning ICC stream: " + ioe.getMessage());
+                }
+            }
+            ICC_Profile iccProfile = null;
+            try {
+                iccProfile = ICC_Profile.getInstance(iccStream.toByteArray());
+                log.debug("JPEG has an ICC profile: " + iccProfile.toString());
+            } catch (IllegalArgumentException iae) {
+                log.warn("An ICC profile is present but it is invalid (" 
+                        + iae.getMessage() + "). The color profile will be ignored. (" 
+                        + info.getOriginalURI() + ")");
+            }
+            if (iccProfile.getNumComponents() != colorSpace.getNumComponents()) {
+                log.warn("The number of components of the ICC profile ("
+                        + iccProfile.getNumComponents() 
+                        + ") doesn't match the image ("
+                        + colorSpace.getNumComponents()
+                        + "). Ignoring the ICC color profile.");
+                return null;
+            } else {
+                return iccProfile;
+            }
+        } else {
+            return null; //no ICC profile available
+        }
+    }
+
+    private int readMarkerSegment(ImageInputStream in) throws IOException {
+        int marker;
+        int count = 0;
+        long startPos = in.getStreamPosition();
+        do {
+            marker = in.read();
+            count++;
+        } while (marker != MARK);
+        if (count > 1) {
+            log.warn("no direct marker found: " + count + " at pos " + startPos);
+        }
+        int segID = in.read();
+        return segID;
+    }
+
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawEPS.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawEPS.java?rev=599436&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawEPS.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawEPS.java Thu Nov 29 05:17:14 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.image2.impl;
+
+import java.awt.geom.Rectangle2D;
+import java.io.InputStream;
+
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This class is an implementation of the Image interface exposing EPS file. It provides an
+ * InputStream to access the EPS content and the decoded high-res bounding box. 
+ */
+public class ImageRawEPS extends ImageRawStream {
+
+    /**
+     * Main constructor.
+     * @param info the image info object
+     * @param in the InputStream with the raw content
+     */
+    public ImageRawEPS(ImageInfo info, InputStream in) {
+        super(info, ImageFlavor.RAW_EPS, in);
+    }
+    
+    /**
+     * Returns the bounding box of the EPS image.
+     * @return the bounding box
+     */
+    public Rectangle2D getBoundingBox() {
+        Rectangle2D bbox = (Rectangle2D)getInfo().getCustomObjects().get(
+                PreloaderEPS.EPS_BOUNDING_BOX);
+        return bbox;
+    }
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawJPEG.java?rev=599436&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawJPEG.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageRawJPEG.java Thu Nov 29 05:17:14 2007
@@ -0,0 +1,89 @@
+/*
+ * 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 java.awt.color.ICC_Profile;
+
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This class is an implementation of the Image interface exposing a JPEG file. It provides an
+ * InputStream to access the JPEG content and some additional information on the image. 
+ */
+public class ImageRawJPEG extends ImageRawStream {
+
+    private int sofType;
+    private ColorSpace colorSpace;
+    private ICC_Profile iccProfile;
+    private boolean invertImage = false;
+    
+    /**
+     * Main constructor.
+     * @param info the image info object
+     * @param in the ImageInputStream with the raw content
+     * @param sofType the SOFn identifier
+     * @param colorSpace the color space
+     * @param iccProfile an ICC color profile or null if no profile is associated
+     * @param invertImage true if the image should be inverted when painting it
+     */
+    public ImageRawJPEG(ImageInfo info, java.io.InputStream in,
+                int sofType, ColorSpace colorSpace, ICC_Profile iccProfile, boolean invertImage) {
+        super(info, ImageFlavor.RAW_EPS, in);
+        this.sofType = sofType;
+        this.colorSpace = colorSpace;
+        this.iccProfile = iccProfile;
+        this.invertImage = invertImage;
+    }
+    
+    /**
+     * Returns the SOFn identifier of the image which describes the coding format of the image.
+     * @return the SOFn identifier
+     */
+    public int getSOFType() {
+        return this.sofType;
+    }
+    
+    /**
+     * Returns the ICC color profile if one is associated with the JPEG image.
+     * @return the ICC color profile or null if there's no profile
+     */
+    public ICC_Profile getICCProfile() {
+        return this.iccProfile;
+    }
+    
+    /**
+     * Indicates whether the image should be inverted when interpreting it.
+     * @return true if the image is to be inverted
+     */
+    public boolean isInverted() {
+        return this.invertImage;
+    }
+
+    /**
+     * Returns the image's color space
+     * @return the color space
+     */
+    public ColorSpace getColorSpace() {
+        return this.colorSpace;
+    }
+    
+}

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

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

Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/JPEGConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/JPEGConstants.java?rev=599436&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/JPEGConstants.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/JPEGConstants.java Thu Nov 29 05:17:14 2007
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+/**
+ * Constants for JPEG images
+ */
+public interface JPEGConstants {
+
+    /*
+     * Only SOFn and APPn markers are defined as SOFn is needed for the height
+     * and width search. APPn is also defined because if the JPEG contains
+     * thumbnails the dimensions of the thumbnail would also be after the SOFn
+     * marker enclosed inside the APPn marker. And we don't want to confuse
+     * those dimensions with the image dimensions.
+     */
+    /** Beginning of a Marker */
+    int MARK = 0xff;
+    /** Special case for 0xff00 */
+    int NULL = 0x00;
+    /** Baseline DCT */
+    int SOF0 = 0xc0;
+    /** Extended Sequential DCT */
+    int SOF1 = 0xc1;
+    /** Progressive DCT only PDF 1.3 */
+    int SOF2 = 0xc2;
+    /** Progressive DCT only PDF 1.3 */
+    int SOFA = 0xca;
+    /** Application marker, JFIF */
+    int APP0 = 0xe0;
+    /** Application marker, JFIF */
+    int APP2 = 0xe2;
+    /** Application marker APPE */
+    int APPE = 0xee; 
+    /** Application marker APPF */
+    int APPF = 0xef; 
+    /** Start of Scan */
+    int SOS = 0xda;
+    /** start of Image */
+    int SOI = 0xd8; 
+    /** end of Image */
+    int EOI = 0xd9; 
+
+}

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

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

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderEPS.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderEPS.java?rev=599436&r1=599435&r2=599436&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderEPS.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderEPS.java Thu Nov 29 05:17:14 2007
@@ -26,12 +26,6 @@
 import javax.imageio.stream.ImageInputStream;
 import javax.xml.transform.Source;
 
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.image2.ImageInfo;
-import org.apache.fop.image2.ImageSize;
-import org.apache.fop.image2.util.ImageInputStreamAdapter;
-import org.apache.fop.image2.util.ImageUtil;
 import org.apache.xmlgraphics.ps.DSCConstants;
 import org.apache.xmlgraphics.ps.dsc.DSCException;
 import org.apache.xmlgraphics.ps.dsc.DSCParser;
@@ -40,11 +34,23 @@
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
 import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
 
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageSize;
+import org.apache.fop.image2.util.ImageInputStreamAdapter;
+import org.apache.fop.image2.util.ImageUtil;
+
 /**
  * Image preloader for EPS images (Encapsulated PostScript).
  */
 public class PreloaderEPS extends AbstractImagePreloader {
 
+    /** Key for binary header object used in custom objects of the ImageInfo class. */
+    public static final Object EPS_BINARY_HEADER = EPSBinaryFileHeader.class;
+    /** Key for bounding box used in custom objects of the ImageInfo class. */
+    public static final Object EPS_BOUNDING_BOX = Rectangle2D.class;
+    
     /** {@inheritDoc} */
     public ImageInfo preloadImage(String uri, Source src, FOUserAgent userAgent)
             throws IOException {
@@ -55,32 +61,41 @@
         in.mark();
         ByteOrder originalByteOrder = in.getByteOrder();
         in.setByteOrder(ByteOrder.LITTLE_ENDIAN);
+        EPSBinaryFileHeader binaryHeader = null;
         try {
             long magic = in.readUnsignedInt();
             // Check if binary header
             boolean supported = false;
             if (magic == 0xC6D3D0C5L) {
-                supported = true;
+                supported = true; //binary EPS
 
-                EPSBinaryFileHeader offsets = readBinaryFileHeader(in);
+                binaryHeader = readBinaryFileHeader(in);
                 in.reset();
-                in.seek(offsets.psStart);
+                in.mark(); //Mark start of file again
+                in.seek(binaryHeader.psStart);
                 
             } else if (magic == 0x53502125L) { //"%!PS" in little endian
-                supported = true;
+                supported = true; //ascii EPS
                 in.reset();
+                in.mark(); //Mark start of file again
             } else {
                 in.reset();
             }
             
             if (supported) {
-                ImageSize size = determineSize(in, userAgent);
-                if (size == null) {
+                ImageInfo info = new ImageInfo(uri, src, getMimeType());
+                boolean success = determineSize(in, userAgent, info);
+                in.reset(); //Need to go back to start of file
+                if (!success) {
                     //No BoundingBox found, so probably no EPS
                     return null;
                 }
-                ImageInfo info = new ImageInfo(uri, src, getMimeType());
-                info.setSize(size);
+                if (in.getStreamPosition() != 0) {
+                    throw new IllegalStateException("Need to be at the start of the file here");
+                }
+                if (binaryHeader != null) {
+                    info.getCustomObjects().put(EPS_BINARY_HEADER, binaryHeader);
+                }
                 return info;
             } else {
                 return null;
@@ -106,7 +121,7 @@
         return offsets;
     }
     
-    private ImageSize determineSize(ImageInputStream in, FOUserAgent userAgent)
+    private boolean determineSize(ImageInputStream in, FOUserAgent userAgent, ImageInfo info)
             throws IOException {
 
         in.mark();
@@ -143,7 +158,7 @@
                     }
                 }
                 if (bbox == null) {
-                    return null;
+                    return false;
                 }
             } catch (DSCException e) {
                 throw new IOException("Error while parsing EPS file: " + e.getMessage());
@@ -155,7 +170,9 @@
                     (int)Math.round(bbox.getHeight() * 1000));
             size.setResolution(userAgent.getSourceResolution());
             size.calcPixelsFromSize();
-            return size;
+            info.setSize(size);
+            info.getCustomObjects().put(EPS_BOUNDING_BOX, bbox);
+            return true;
         } finally {
             in.reset();
         }

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderJPEG.java?rev=599436&r1=599435&r2=599436&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderJPEG.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/PreloaderJPEG.java Thu Nov 29 05:17:14 2007
@@ -34,25 +34,8 @@
 /**
  * Image preloader for JPEG images.
  */
-public class PreloaderJPEG extends AbstractImagePreloader {
+public class PreloaderJPEG extends AbstractImagePreloader  implements JPEGConstants {
 
-    /**
-     * Only SOFn and APPn markers are defined as SOFn is needed for the height
-     * and width search. APPn is also defined because if the JPEG contains
-     * thumbnails the dimensions of the thumbnail would also be after the SOFn
-     * marker enclosed inside the APPn marker. And we don't want to confuse
-     * those dimensions with the image dimensions.
-     */
-    private static final int MARK = 0xff; // Beginning of a Marker
-    private static final int NULL = 0x00; // Special case for 0xff00
-    private static final int SOF1 = 0xc0; // Baseline DCT
-    private static final int SOF2 = 0xc1; // Extended Sequential DCT
-    private static final int SOF3 = 0xc2; // Progressive DCT only PDF 1.3
-    private static final int SOFA = 0xca; // Progressive DCT only PDF 1.3
-    private static final int APP0 = 0xe0; // Application marker, JFIF
-    //private static final int APPF = 0xef; // Application marker
-    //private static final int SOS = 0xda; // Start of Scan
-    private static final int SOI = 0xd8; // start of Image
     private static final int JPG_SIG_LENGTH = 3;
 
     /** {@inheritDoc} 
@@ -114,9 +97,9 @@
                     }
                     in.skipBytes(reclen - 14);
                     break;
+                case SOF0:
                 case SOF1:
-                case SOF2:
-                case SOF3: // SOF3 and SOFA are only supported by PDF 1.3
+                case SOF2: // SOF2 and SOFA are only supported by PDF 1.3
                 case SOFA:
                     in.skipBytes(2); //length field
                     in.skipBytes(1);

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/java2d/Java2DRenderer.java?rev=599436&r1=599435&r2=599436&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/java2d/Java2DRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/java2d/Java2DRenderer.java Thu Nov 29 05:17:14 2007
@@ -25,7 +25,6 @@
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
-import java.awt.color.ColorSpace;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
@@ -33,14 +32,6 @@
 import java.awt.geom.Point2D;
 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.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
 import java.awt.print.PageFormat;
 import java.awt.print.Printable;
 import java.awt.print.PrinterException;
@@ -51,8 +42,6 @@
 import java.util.Map;
 import java.util.Stack;
 
-import org.w3c.dom.Document;
-
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactoryConfigurator;
@@ -65,13 +54,19 @@
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.Typeface;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageManager;
+import org.apache.fop.image2.impl.ImageGraphics2D;
+import org.apache.fop.image2.impl.ImageRendered;
+import org.apache.fop.image2.impl.ImageXMLDOM;
+import org.apache.fop.image2.util.ImageUtil;
 import org.apache.fop.render.AbstractPathOrientedRenderer;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.RendererContext;
@@ -884,15 +879,55 @@
     /**
      * {@inheritDoc}
      */
-    protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
+    protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
 
         int x = currentIPPosition + (int)Math.round(pos.getX());
         int y = currentBPPosition + (int)Math.round(pos.getY());
-        url = ImageFactory.getURL(url);
-
-        ImageFactory fact = userAgent.getFactory().getImageFactory();
-        FopImage fopimage = fact.getImage(url, userAgent);
+        uri = URISpecification.getURL(uri);
+        
+        //ImageFactory fact = userAgent.getFactory().getImageFactory();
+        //FopImage fopimage = fact.getImage(url, userAgent);
+        ImageManager manager = getUserAgent().getFactory().getImageManager();
+        ImageInfo info = null;
+        try {
+            info = manager.preloadImage(uri, getUserAgent());
+            final ImageFlavor[] flavors = new ImageFlavor[]
+                {ImageFlavor.GRAPHICS2D,
+                    ImageFlavor.BUFFERED_IMAGE, 
+                    ImageFlavor.RENDERED_IMAGE, 
+                    ImageFlavor.XML_DOM};
+            Map hints = ImageUtil.getDefaultHints(getUserAgent());
+            org.apache.fop.image2.Image img = manager.getImage(info, flavors, hints);
+            if (img instanceof ImageGraphics2D) {
+                ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+                int width = (int)pos.getWidth();
+                int height = (int)pos.getHeight();
+                RendererContext context = createRendererContext(
+                        x, y, width, height, foreignAttributes);
+                getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+                        context, x, y, width, height);
+            } else if (img instanceof ImageRendered) {
+                ImageRendered imgRend = (ImageRendered)img;
+                AffineTransform at = new AffineTransform();
+                at.translate(x / 1000f, y / 1000f);
+                double sx = pos.getWidth() / info.getSize().getWidthMpt();
+                double sy = pos.getHeight() / info.getSize().getHeightMpt();
+                at.scale(sx, sy);
+                state.getGraph().drawRenderedImage(imgRend.getRenderedImage(), at);
+            } else if (img instanceof ImageXMLDOM) {
+                ImageXMLDOM imgXML = (ImageXMLDOM)img;
+                renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+                        pos, foreignAttributes);
+            }
+        } catch (ImageException ie) {
+            log.error("Error while processing image: "
+                    + (info != null ? info.toString() : uri), ie);
+        } catch (IOException ioe) {
+            log.error("I/O error while processing image: "
+                    + (info != null ? info.toString() : uri), ioe);
+        }
 
+        /*
         if (fopimage == null) {
             return;
         }
@@ -948,7 +983,7 @@
             state.getGraph().drawImage(awtImage, 
                     (int)(x / 1000f), (int)(y / 1000f), 
                     (int)(pos.getWidth() / 1000f), (int)(pos.getHeight() / 1000f), null);
-        }
+        }*/
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSRenderer.java?rev=599436&r1=599435&r2=599436&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSRenderer.java Thu Nov 29 05:17:14 2007
@@ -38,8 +38,18 @@
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.ImageEncoder;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSProcSets;
+import org.apache.xmlgraphics.ps.PSResource;
+import org.apache.xmlgraphics.ps.PSState;
+import org.apache.xmlgraphics.ps.dsc.DSCException;
+import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.BlockViewport;
 import org.apache.fop.area.CTM;
@@ -56,15 +66,23 @@
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.fonts.Typeface;
-import org.apache.fop.image.EPSImage;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+import org.apache.fop.image2.ImageManager;
+import org.apache.fop.image2.impl.ImageGraphics2D;
+import org.apache.fop.image2.impl.ImageRawEPS;
+import org.apache.fop.image2.impl.ImageRawJPEG;
+import org.apache.fop.image2.impl.ImageRawStream;
+import org.apache.fop.image2.impl.ImageRendered;
+import org.apache.fop.image2.impl.ImageXMLDOM;
+import org.apache.fop.image2.util.ImageUtil;
 import org.apache.fop.render.AbstractPathOrientedRenderer;
 import org.apache.fop.render.Graphics2DAdapter;
 import org.apache.fop.render.ImageAdapter;
@@ -75,14 +93,6 @@
 import org.apache.fop.render.ps.extensions.PSSetPageDevice;
 import org.apache.fop.render.ps.extensions.PSSetupCode;
 import org.apache.fop.util.CharUtilities;
-import org.apache.xmlgraphics.ps.DSCConstants;
-import org.apache.xmlgraphics.ps.PSGenerator;
-import org.apache.xmlgraphics.ps.PSProcSets;
-import org.apache.xmlgraphics.ps.PSResource;
-import org.apache.xmlgraphics.ps.PSState;
-import org.apache.xmlgraphics.ps.dsc.DSCException;
-import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
-import org.w3c.dom.Document;
 
 /**
  * Renderer that renders to PostScript.
@@ -369,12 +379,98 @@
         }
     }
 
+    private final ImageFlavor[] level2Flavors = new ImageFlavor[]
+                                                  {ImageFlavor.RAW_EPS,
+                                                   ImageFlavor.GRAPHICS2D,
+                                                   ImageFlavor.BUFFERED_IMAGE, 
+                                                   ImageFlavor.RENDERED_IMAGE, 
+                                                   ImageFlavor.XML_DOM};
+
+    private final ImageFlavor[] level3Flavors = new ImageFlavor[]
+                                                  {ImageFlavor.RAW_EPS,
+                                                   ImageFlavor.RAW_JPEG,
+                                                   ImageFlavor.GRAPHICS2D,
+                                                   ImageFlavor.BUFFERED_IMAGE, 
+                                                   ImageFlavor.RENDERED_IMAGE, 
+                                                   ImageFlavor.XML_DOM};
     /** {@inheritDoc} */
     protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
         endTextObject();
-        uri = ImageFactory.getURL(uri);
-        ImageFactory fact = userAgent.getFactory().getImageFactory();
-        FopImage fopimage = fact.getImage(uri, userAgent);
+        int x = currentIPPosition + (int)Math.round(pos.getX());
+        int y = currentBPPosition + (int)Math.round(pos.getY());
+        uri = URISpecification.getURL(uri);
+        if (log.isDebugEnabled()) {
+            log.debug("Handling image: " + uri);
+        }
+        
+        ImageManager manager = getUserAgent().getFactory().getImageManager();
+        ImageInfo info = null;
+        try {
+            info = manager.preloadImage(uri, getUserAgent());
+            Map hints = ImageUtil.getDefaultHints(getUserAgent());
+            ImageFlavor[] flavors;
+            if (gen.getPSLevel() >= 3) {
+                flavors = level3Flavors;
+            } else {
+                flavors = level2Flavors;
+            }
+            int width = (int)pos.getWidth();
+            int height = (int)pos.getHeight();
+            org.apache.fop.image2.Image img = manager.getImage(info, flavors, hints);
+            if (img instanceof ImageGraphics2D) {
+                ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+                RendererContext context = createRendererContext(
+                        x, y, width, height, foreignAttributes);
+                getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+                        context, x, y, width, height);
+            } else if (img instanceof ImageRendered) {
+                ImageRendered imgRend = (ImageRendered)img;
+                RendererContext context = createRendererContext(
+                        x, y, width, height, foreignAttributes);
+                paintImage(imgRend.getRenderedImage(), context, x, y, width, height);
+            } else if (img instanceof ImageXMLDOM) {
+                ImageXMLDOM imgXML = (ImageXMLDOM)img;
+                renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+                        pos, foreignAttributes);
+            } else if (img instanceof ImageRawStream) {
+                final ImageRawStream raw = (ImageRawStream)img;
+                if (MimeConstants.MIME_EPS.equals(raw.getInfo().getMimeType())) {
+                    ImageRawEPS eps = (ImageRawEPS)raw;
+                    Rectangle2D bbox = eps.getBoundingBox(); 
+                    PSImageUtils.renderEPS(raw.getInputStream(), uri,
+                        x / 1000f, y / 1000f,
+                        width / 1000f, height / 1000f,
+                        (float)bbox.getX(), (float)bbox.getY(),
+                        (float)bbox.getWidth(), (float)bbox.getHeight(),
+                        gen);
+                } else if (MimeConstants.MIME_JPEG.equals(raw.getInfo().getMimeType())) {
+                    ImageRawJPEG jpeg = (ImageRawJPEG)raw;
+                    ImageEncoder encoder = new ImageEncoder() {
+                        public void writeTo(OutputStream out) throws IOException {
+                            IOUtils.copy(raw.getInputStream(), out);
+                        }
+                        public String getImplicitFilter() {
+                            return "<< >> /DCTDecode";
+                        }
+                    };
+                    Rectangle2D targetRect = new Rectangle2D.Float(
+                            x / 1000f, y / 1000f,
+                            width / 1000f, height / 1000f);
+                    PSImageUtils.writeImage(encoder, info.getSize().getDimensionPx(),
+                            uri, targetRect,
+                            jpeg.getColorSpace(), jpeg.isInverted(), gen);
+                } else {
+                    throw new UnsupportedOperationException("Unsupported raw image: " + info);
+                }
+            }
+        } catch (ImageException ie) {
+            log.error("Error while processing image: "
+                    + (info != null ? info.toString() : uri), ie);
+        } catch (IOException ioe) {
+            handleIOTrouble(ioe);
+        }
+
+        /*
         if (fopimage == null) {
             return;
         }
@@ -418,9 +514,15 @@
         } catch (IOException ioe) {
             handleIOTrouble(ioe);
         }
+        */
     }
 
-    protected PSResource getFormForImage(String uri, FopImage fopimage) {
+    /**
+     * Returns a PSResource instance representing a image as a PostScript form.
+     * @param uri the image URI
+     * @return a PSResource instance
+     */
+    protected PSResource getFormForImage(String uri) {
         if (this.formResources == null) {
             this.formResources = new java.util.HashMap();
         }
@@ -431,8 +533,14 @@
         }
         return form;
     }
-    
-    protected boolean isImageInlined(String uri, FopImage image) {
+
+    /**
+     * Indicates whether an image with the given URI should be inlined or added as a PostScript
+     * form.
+     * @param uri the image URI
+     * @return true if the image should be inlined rather than added as a form
+     */
+    protected boolean isImageInlined(String uri) {
         return !isOptimizeResources();
     }
     

Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/java/org/apache/fop/image2/ImageLoaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/java/org/apache/fop/image2/ImageLoaderTestCase.java?rev=599436&r1=599435&r2=599436&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/java/org/apache/fop/image2/ImageLoaderTestCase.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/java/org/apache/fop/image2/ImageLoaderTestCase.java Thu Nov 29 05:17:14 2007
@@ -20,6 +20,8 @@
 package org.apache.fop.image2;
 
 import java.io.File;
+import java.io.InputStreamReader;
+import java.io.Reader;
 
 import junit.framework.TestCase;
 
@@ -27,6 +29,7 @@
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
+import org.apache.fop.image2.impl.ImageRawStream;
 import org.apache.fop.image2.impl.ImageRendered;
 import org.apache.fop.image2.impl.ImageXMLDOM;
 import org.apache.fop.image2.util.ImageUtil;
@@ -153,5 +156,50 @@
         assertEquals(612000, info.getSize().getHeightMpt());
     }
  
-    
+    public void testEPSASCII() throws Exception {
+        String uri = "test/resources/images/barcode.eps";
+        
+        FOUserAgent userAgent = fopFactory.newFOUserAgent();
+        
+        ImageManager manager = fopFactory.getImageManager();
+        ImageInfo info = manager.preloadImage(uri, userAgent);
+        assertNotNull("ImageInfo must not be null", info);
+        
+        Image img = manager.getImage(info, ImageFlavor.RAW_EPS,
+                ImageUtil.getDefaultHints(userAgent));
+        assertNotNull("Image must not be null", img);
+        assertEquals(ImageFlavor.RAW_EPS, img.getFlavor());
+        ImageRawStream imgEPS = (ImageRawStream)img;
+        assertNotNull(imgEPS.getInputStream());
+        Reader reader = new InputStreamReader(imgEPS.getInputStream(), "US-ASCII");
+        char[] c = new char[4];
+        reader.read(c);
+        if (!("%!PS".equals(new String(c)))) {
+            fail("EPS header expected");
+        }
+    }
+ 
+    public void testEPSBinary() throws Exception {
+        String uri = "test/resources/images/img-with-tiff-preview.eps";
+        
+        FOUserAgent userAgent = fopFactory.newFOUserAgent();
+        
+        ImageManager manager = fopFactory.getImageManager();
+        ImageInfo info = manager.preloadImage(uri, userAgent);
+        assertNotNull("ImageInfo must not be null", info);
+        
+        Image img = manager.getImage(info, ImageFlavor.RAW_EPS,
+                ImageUtil.getDefaultHints(userAgent));
+        assertNotNull("Image must not be null", img);
+        assertEquals(ImageFlavor.RAW_EPS, img.getFlavor());
+        ImageRawStream imgEPS = (ImageRawStream)img;
+        assertNotNull(imgEPS.getInputStream());
+        Reader reader = new InputStreamReader(imgEPS.getInputStream(), "US-ASCII");
+        char[] c = new char[4];
+        reader.read(c);
+        if (!("%!PS".equals(new String(c)))) {
+            fail("EPS header expected");
+        }
+    }
+ 
 }



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