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 [3/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...
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/package.html?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/package.html (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/package.html Wed Nov 14 04:12:50 2007
@@ -0,0 +1,26 @@
+<!--
+ 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$ -->
+<HTML>
+<TITLE>org.apache.fop.image2.impl.batik Package</TITLE>
+<BODY>
+<P>
+ Contains implementations of image loaders and converters which are dependent
+ on Apache Batik (SVG and WMF).
+</P>
+</BODY>
+</HTML>
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,109 @@
+/*
+ * 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.imageio;
+
+import javax.imageio.metadata.IIOMetadata;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.fop.image2.ImageSize;
+import org.apache.fop.util.UnitConv;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Helper and convenience methods for ImageIO.
+ */
+public class ImageIOUtil {
+
+ /**
+ * Extracts the resolution information from the standard ImageIO metadata.
+ * @param iiometa the metadata provided by ImageIO
+ * @param size the image size object
+ */
+ public static void extractResolution(IIOMetadata iiometa, ImageSize size) {
+ if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {
+ Element metanode = (Element)iiometa.getAsTree("javax_imageio_1.0");
+ Element dim = getChild(metanode, "Dimension");
+ if (dim != null) {
+ Element child;
+ double dpiHorz = size.getDpiHorizontal();
+ double dpiVert = size.getDpiVertical();
+ child = getChild(dim, "HorizontalPixelSize");
+ if (child != null) {
+ dpiHorz = UnitConv.IN2MM
+ / Float.parseFloat(child.getAttribute("value"));
+ }
+ child = getChild(dim, "VerticalPixelSize");
+ if (child != null) {
+ dpiVert = UnitConv.IN2MM
+ / Float.parseFloat(child.getAttribute("value"));
+ }
+ size.setResolution(dpiHorz, dpiVert);
+ size.calcSizeFromPixels();
+ }
+ }
+ }
+
+ private static Element getChild(Element el, String name) {
+ NodeList nodes = el.getElementsByTagName(name);
+ if (nodes.getLength() > 0) {
+ return (Element)nodes.item(0);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Dumps the content of an IIOMetadata instance to System.out.
+ * @param iiometa the metadata
+ */
+ public static void dumpMetadataToSystemOut(IIOMetadata iiometa) {
+ String[] metanames = iiometa.getMetadataFormatNames();
+ for (int j = 0; j < metanames.length; j++) {
+ System.out.println("--->" + metanames[j]);
+ dumpNodeToSystemOut(iiometa.getAsTree(metanames[j]));
+ }
+ }
+
+ /**
+ * Serializes a W3C DOM node to a String and dumps it to System.out.
+ * @param node a W3C DOM node
+ */
+ private static void dumpNodeToSystemOut(Node node) {
+ try {
+ Transformer trans = TransformerFactory.newInstance().newTransformer();
+ trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ trans.setOutputProperty(OutputKeys.INDENT, "yes");
+ Source src = new DOMSource(node);
+ Result res = new StreamResult(System.out);
+ trans.transform(src, res);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageIOUtil.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.impl.imageio;
+
+import javax.imageio.ImageIO;
+
+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 based on ImageIO.
+ */
+public class ImageLoaderFactoryImageIO implements ImageLoaderFactory {
+
+ private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
+ ImageFlavor.RENDERED_IMAGE,
+ ImageFlavor.BUFFERED_IMAGE};
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMIMETypes() {
+ return ImageIO.getReaderMIMETypes();
+ }
+
+ /** {@inheritDoc} */
+ public ImageFlavor[] getSupportedFlavors(String mime) {
+ return FLAVORS;
+ }
+
+ /** {@inheritDoc} */
+ public ImageLoader newImageLoader(ImageFlavor targetFlavor) {
+ return new ImageLoaderImageIO(targetFlavor);
+ }
+
+ /** {@inheritDoc} */
+ public int getUsagePenalty(String mime, ImageFlavor flavor) {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ public boolean isAvailable() {
+ return (getSupportedMIMETypes().length > 0);
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderFactoryImageIO.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.imageio;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
+
+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.impl.AbstractImageLoader;
+import org.apache.fop.image2.impl.ImageBuffered;
+import org.apache.fop.image2.impl.ImageRendered;
+import org.apache.fop.image2.util.ImageUtil;
+
+/**
+ * An ImageLoader implementation based on ImageIO for loading bitmap images.
+ */
+public class ImageLoaderImageIO extends AbstractImageLoader {
+
+ private ImageFlavor targetFlavor;
+
+ /**
+ * Main constructor.
+ * @param targetFlavor the target flavor
+ */
+ public ImageLoaderImageIO(ImageFlavor targetFlavor) {
+ if (!(ImageFlavor.BUFFERED_IMAGE.equals(targetFlavor)
+ || ImageFlavor.RENDERED_IMAGE.equals(targetFlavor))) {
+ throw new IllegalArgumentException("Unsupported target ImageFlavor: " + targetFlavor);
+ }
+ this.targetFlavor = targetFlavor;
+ }
+
+ /** {@inheritDoc} */
+ public ImageFlavor getTargetFlavor() {
+ return this.targetFlavor;
+ }
+
+ /** {@inheritDoc} */
+ public Image loadImage(ImageInfo info, Map hints) throws ImageException, IOException {
+ ImageInputStream imgStream = ImageUtil.needImageInputStream(info.getSource());
+ Iterator iter = ImageIO.getImageReaders(imgStream);
+ if (!iter.hasNext()) {
+ throw new ImageException("No ImageIO ImageReader found .");
+ }
+ ImageReader reader = (ImageReader)iter.next();
+ ImageReadParam param = reader.getDefaultReadParam();
+ reader.setInput(imgStream, true, true); //Don't need metadata anymore at this stage
+ BufferedImage imageData = reader.read(0, param);
+
+ if (ImageFlavor.BUFFERED_IMAGE.equals(this.targetFlavor)) {
+ return new ImageBuffered(info, imageData);
+ } else {
+ return new ImageRendered(info, imageData);
+ }
+ }
+
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/ImageLoaderImageIO.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/package.html?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/package.html (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/package.html Wed Nov 14 04:12:50 2007
@@ -0,0 +1,25 @@
+<!--
+ 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$ -->
+<HTML>
+<TITLE>org.apache.fop.image2.impl.imageio Package</TITLE>
+<BODY>
+<P>
+ Contains an implementation of an image loader which uses ImageIO.
+</P>
+</BODY>
+</HTML>
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/imageio/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/package.html?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/package.html (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/package.html Wed Nov 14 04:12:50 2007
@@ -0,0 +1,25 @@
+<!--
+ 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$ -->
+<HTML>
+<TITLE>org.apache.fop.image2.impl Package</TITLE>
+<BODY>
+<P>
+ Contains implementations of image loaders and converters.
+</P>
+</BODY>
+</HTML>
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/package.html?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/package.html (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/package.html Wed Nov 14 04:12:50 2007
@@ -0,0 +1,26 @@
+<!--
+ 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$ -->
+<HTML>
+<TITLE>org.apache.fop.image2 Package</TITLE>
+<BODY>
+<P>
+ Contains image loading and conversion infrastructure for various image
+ sources and an image cache.
+</P>
+</BODY>
+</HTML>
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.spi;
+
+import org.apache.fop.util.dijkstra.Edge;
+import org.apache.fop.util.dijkstra.Vertex;
+
+/**
+ * Represents an image conversion. The class basically wraps an ImageConverter so it can be
+ * used with Dijkstra's shortest route algorithm to build image conversion pipelines.
+ */
+public class ImageConversionEdge implements Edge {
+
+ private ImageRepresentation source;
+ private ImageRepresentation target;
+ private ImageConverter converter;
+
+ /**
+ * Main constructor.
+ * @param converter the image converter
+ */
+ public ImageConversionEdge(
+ ImageConverter converter) {
+ this.converter = converter;
+ this.source = new ImageRepresentation(converter.getSourceFlavor());
+ this.target = new ImageRepresentation(converter.getTargetFlavor());
+ }
+
+ /**
+ * Returns the wrapped ImageConverter.
+ * @return the ImageConverter
+ */
+ public ImageConverter getImageConverter() {
+ return this.converter;
+ }
+
+ /** {@inheritDoc} */
+ public int getPenalty() {
+ return getImageConverter().getConversionPenalty();
+ }
+
+ /** {@inheritDoc} */
+ public Vertex getStart() {
+ return this.source;
+ }
+
+ /** {@inheritDoc} */
+ public Vertex getEnd() {
+ return this.target;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConversionEdge.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java Wed Nov 14 04:12:50 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.spi;
+
+import java.util.Map;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+
+/**
+ * Defines an image converter that can convert one image representation into another.
+ */
+public interface ImageConverter {
+
+ /** Used if the conversion penalty is negligible (for example a simple cast). */
+ int NO_CONVERSION_PENALTY = 0;
+ /** Used if the conversion penalty is minimal */
+ int MINIMAL_CONVERSION_PENALTY = 1;
+ /** Default/Medium conversion penalty (if there's some effort to convert the image format) */
+ int MEDIUM_CONVERSION_PENALTY = 10;
+
+ /**
+ * Converts an image into a different representation.
+ * @param src the source image
+ * @param hints the conversion hints
+ * @return the converted image
+ * @throws ImageException if an error occurs while converting the image
+ */
+ Image convert(Image src, Map hints) throws ImageException;
+
+ /**
+ * Returns the flavor that this converter converts images into.
+ * @return the target flavor
+ */
+ ImageFlavor getTargetFlavor();
+
+ /**
+ * Returns the flavor that this converter expects.
+ * @return the source flavor
+ */
+ ImageFlavor getSourceFlavor();
+
+ /**
+ * Returns the conversion penalty for the conversion that this implementation supports.
+ * @return the conversion penalty (must be a non-negative integer)
+ */
+ int getConversionPenalty();
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.spi;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * Represents a pipeline of ImageConverters with an ImageLoader at the beginning of the
+ * pipeline.
+ */
+public class ImageConverterPipeline {
+
+ /** logger */
+ protected static Log log = LogFactory.getLog(ImageConverterPipeline.class);
+
+ private ImageLoader loader;
+ private List converters = new java.util.LinkedList();
+
+ /**
+ * Main constructor.
+ * @param loader the image loader to drive the pipeline with
+ */
+ public ImageConverterPipeline(ImageLoader loader) {
+ this.loader = loader;
+ }
+
+ /**
+ * Executes the image converter pipeline. First, the image indicated by the ImageInfo instance
+ * is loaded through an ImageLoader and then optionally converted by a series of
+ * ImageConverters. At the end of the pipeline, the fully loaded and converted image is
+ * returned.
+ * @param info the image info object indicating the image to load
+ * @param hints a Map of image conversion hints
+ * @return the requested image
+ * @throws ImageException if an error occurs while loader or converting the image
+ * @throws IOException if an I/O error occurs
+ */
+ public Image execute(ImageInfo info, Map hints) throws ImageException, IOException {
+ long start, duration;
+ start = System.currentTimeMillis();
+ Image img = loader.loadImage(info, hints);
+ if (log.isTraceEnabled()) {
+ duration = System.currentTimeMillis() - start;
+ log.trace("Image loading using " + loader + " took " + duration + " ms.");
+ }
+
+ Iterator iter = converters.iterator();
+ while (iter.hasNext()) {
+ ImageConverter converter = (ImageConverter)iter.next();
+ start = System.currentTimeMillis();
+ img = converter.convert(img, hints);
+ if (log.isTraceEnabled()) {
+ duration = System.currentTimeMillis() - start;
+ log.trace("Image conversion using " + converter + " took " + duration + " ms.");
+ }
+ }
+ return img;
+ }
+
+ /**
+ * Adds an additional ImageConverter to the end of the pipeline.
+ * @param converter the ImageConverter instance
+ */
+ public void addConverter(ImageConverter converter) {
+ //TODO check for compatibility
+ this.converters.add(converter);
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Loader: ").append(loader);
+ if (converters.size() > 0) {
+ sb.append(" Converters: ");
+ sb.append(converters);
+ }
+ return sb.toString();
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageConverterPipeline.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,305 @@
+/*
+ * 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.spi;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.util.dijkstra.DefaultEdgeDirectory;
+import org.apache.fop.util.dijkstra.DijkstraAlgorithm;
+import org.apache.fop.util.dijkstra.Vertex;
+import org.apache.xmlgraphics.util.Service;
+
+/**
+ * This class is the registry for all implementations of the various service provider interfaces
+ * for the image package.
+ */
+public class ImageImplRegistry {
+
+ /** logger */
+ protected static Log log = LogFactory.getLog(ImageImplRegistry.class);
+
+ /** Holds the list of preloaders */
+ private List preloaders = new java.util.ArrayList();
+ //Content: List<ImagePreloader>
+
+ /** Holds the list of ImageLoaderFactories */
+ private Map loaders = new java.util.HashMap();
+ //Content: Map<String,Map<ImageFlavor,ImageLoaderFactory>>
+
+ /** Holds the list of ImageConverters */
+ private List converters = new java.util.ArrayList();
+ //Content: List<ImageConverter>
+
+ /** Holds the EdgeDirectory for all image conversions */
+ private DefaultEdgeDirectory converterEdgeDirectory = new DefaultEdgeDirectory();
+
+ /** Singleton instance */
+ private static ImageImplRegistry defaultInstance;
+
+ /**
+ * Main constructor.
+ * @see #getDefaultInstance()
+ */
+ public ImageImplRegistry() {
+ discoverClasspathImplementations();
+ }
+
+ /**
+ * Returns the default instance of the Image implementation registry.
+ * @return the default instance
+ */
+ public static ImageImplRegistry getDefaultInstance() {
+ if (defaultInstance == null) {
+ defaultInstance = new ImageImplRegistry();
+ }
+ return defaultInstance;
+ }
+
+ /**
+ * Discovers all implementations in the application's classpath.
+ */
+ public void discoverClasspathImplementations() {
+ //Dynamic registration of ImagePreloaders
+ Iterator iter = Service.providers(ImagePreloader.class, true);
+ while (iter.hasNext()) {
+ registerPreloader((ImagePreloader)iter.next());
+ }
+
+ //Dynamic registration of ImageLoaderFactories
+ iter = Service.providers(ImageLoaderFactory.class, true);
+ while (iter.hasNext()) {
+ registerLoaderFactory((ImageLoaderFactory)iter.next());
+ }
+
+ //Dynamic registration of ImageConverters
+ iter = Service.providers(ImageConverter.class, true);
+ while (iter.hasNext()) {
+ registerConverter((ImageConverter)iter.next());
+ }
+ }
+
+ /**
+ * Registers a new ImagePreloader.
+ * @param preloader An ImagePreloader instance
+ */
+ public void registerPreloader(ImagePreloader preloader) {
+ if (log.isDebugEnabled()) {
+ log.debug("Registered " + preloader.getClass().getName()
+ + ": MIME = " + preloader.getMimeType());
+ }
+ preloaders.add(preloader);
+ }
+
+ /**
+ * Registers a new ImageLoaderFactory.
+ * @param loaderFactory An ImageLoaderFactory instance
+ */
+ public void registerLoaderFactory(ImageLoaderFactory loaderFactory) {
+ if (!loaderFactory.isAvailable()) {
+ if (log.isDebugEnabled()) {
+ log.debug("ImageLoaderFactory reports not available: "
+ + loaderFactory.getClass().getName());
+ }
+ return;
+ }
+ String[] mimes = loaderFactory.getSupportedMIMETypes();
+ for (int i = 0, ci = mimes.length; i < ci; i++) {
+ String mime = mimes[i];
+
+ synchronized (loaders) {
+ Map flavorMap = (Map)loaders.get(mime);
+ if (flavorMap == null) {
+ flavorMap = new java.util.HashMap();
+ loaders.put(mime, flavorMap);
+ }
+
+ ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(mime);
+ for (int j = 0, cj = flavors.length; j < cj; j++) {
+ ImageFlavor flavor = flavors[j];
+
+ List factoryList = (List)flavorMap.get(flavor);
+ if (factoryList == null) {
+ factoryList = new java.util.ArrayList();
+ flavorMap.put(flavor, factoryList);
+ }
+ factoryList.add(loaderFactory);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Registered " + loaderFactory.getClass().getName()
+ + ": MIME = " + mime + ", Flavor = " + flavor);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Registers a new ImageConverter.
+ * @param converter An ImageConverter instance
+ */
+ public void registerConverter(ImageConverter converter) {
+ converters.add(converter);
+ converterEdgeDirectory.addEdge(new ImageConversionEdge(converter));
+ if (log.isDebugEnabled()) {
+ log.debug("Registered: " + converter.getClass().getName());
+ }
+ }
+
+ /**
+ * Returns an iterator over all registered ImagePreloader instances.
+ * @return an iterator over ImagePreloader instances.
+ */
+ public Iterator getPreloaderIterator() {
+ return this.preloaders.iterator();
+ }
+
+ /**
+ * Returns the best ImageLoaderFactory supporting the given MIME type and image flavor.
+ * If there are multiple ImageLoaderFactories the one with the least usage penalty is selected.
+ * @param mime the MIME type
+ * @param flavor the image flavor.
+ * @return an ImageLoaderFactory instance or null, if no suitable implementation was found
+ */
+ public ImageLoaderFactory getImageLoaderFactory(String mime, ImageFlavor flavor) {
+ Map flavorMap = (Map)loaders.get(mime);
+ if (flavorMap != null) {
+ List factoryList = (List)flavorMap.get(flavor);
+ if (factoryList != null && factoryList.size() > 0) {
+ Iterator iter = factoryList.iterator();
+ int bestPenalty = Integer.MAX_VALUE;
+ ImageLoaderFactory bestFactory = null;
+ while (iter.hasNext()) {
+ ImageLoaderFactory factory = (ImageLoaderFactory)iter.next();
+ int penalty = factory.getUsagePenalty(mime, flavor);
+ if (penalty < bestPenalty) {
+ bestPenalty = penalty;
+ bestFactory = factory;
+ }
+ }
+ return bestFactory;
+ }
+ }
+ return null;
+ }
+
+ private ImageLoaderFactory[] getImageLoaderFactories(String mime) {
+ Map flavorMap = (Map)loaders.get(mime);
+ if (flavorMap != null) {
+ Set factories = new java.util.HashSet();
+ Iterator iter = flavorMap.values().iterator();
+ while (iter.hasNext()) {
+ List factoryList = (List)iter.next();
+ factories.addAll(factoryList);
+ }
+ int factoryCount = factories.size();
+ if (factoryCount > 0) {
+ return (ImageLoaderFactory[])factories.toArray(
+ new ImageLoaderFactory[factoryCount]);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Creates and returns an ImageConverterPipeline that allows to load an image of the given
+ * MIME type and present it in the requested image flavor.
+ * @param originalMime the MIME type of the original image
+ * @param targetFlavor the requested image flavor
+ * @return an ImageConverterPipeline or null if no suitable pipeline could be assembled
+ */
+ public ImageConverterPipeline newImageConverterPipeline(
+ String originalMime, ImageFlavor targetFlavor) {
+ ImageConverterPipeline pipeline = null;
+ ImageLoaderFactory loaderFactory = getImageLoaderFactory(originalMime, targetFlavor);
+ if (loaderFactory != null) {
+ //Directly load image and return it
+ ImageLoader loader = loaderFactory.newImageLoader(targetFlavor);
+ pipeline = new ImageConverterPipeline(loader);
+ } else {
+ //Need to use ImageConverters
+ if (log.isDebugEnabled()) {
+ log.debug("No ImageLoaderFactory found that can load this format directly."
+ + " Trying ImageConverters instead...");
+ }
+
+ ImageRepresentation destination = new ImageRepresentation(targetFlavor);
+ //Get Loader for originalMIME
+ // --> List of resulting flavors, possibly multiple loaders
+ ImageLoaderFactory[] loaderFactories = getImageLoaderFactories(originalMime);
+ if (loaderFactories != null) {
+ //Find best pipeline -> best loader
+ for (int i = 0, ci = loaderFactories.length; i < ci; i++) {
+ loaderFactory = loaderFactories[i];
+ ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(originalMime);
+ for (int j = 0, cj = flavors.length; j < cj; j++) {
+ DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(
+ this.converterEdgeDirectory);
+ ImageRepresentation origin = new ImageRepresentation(flavors[i]);
+ dijkstra.execute(origin, destination);
+ if (log.isDebugEnabled()) {
+ log.debug("Lowest penalty: " + dijkstra.getLowestPenalty(destination));
+ }
+
+ Vertex prev = destination;
+ Vertex pred = dijkstra.getPredecessor(destination);
+ if (pred == null) {
+ log.error("No route found!");
+ }
+ LinkedList stops = new LinkedList();
+ //stops.addLast(destination);
+ while ((pred = dijkstra.getPredecessor(prev)) != null) {
+ ImageConversionEdge edge = (ImageConversionEdge)
+ this.converterEdgeDirectory.getBestEdge(pred, prev);
+ stops.addFirst(edge);
+ prev = pred;
+ }
+ ImageLoader loader = loaderFactory.newImageLoader(flavors[i]);
+ pipeline = new ImageConverterPipeline(loader);
+ Iterator iter = stops.iterator();
+ while (iter.hasNext()) {
+ ImageConversionEdge edge = (ImageConversionEdge)iter.next();
+ pipeline.addConverter(edge.getImageConverter());
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Pipeline: " + pipeline);
+ }
+ return pipeline;
+ }
+ }
+
+ //Build final pipeline
+
+ }
+
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Pipeline: " + pipeline);
+ }
+ return pipeline;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageImplRegistry.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.image2.spi;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This interface is implemented by classes which load images from a source. Normally, such a
+ * source will be an InputStream but can also be something else.
+ */
+public interface ImageLoader {
+
+ /**
+ * Loads and returns an image.
+ * @param info the image info object indicating the image
+ * @param hints a Map of hints that can be used by implementations to customize the loading
+ * process.
+ * @return the fully loaded image
+ * @throws ImageException if an error occurs while loading the image
+ * @throws IOException if an I/O error occurs while loading the image
+ */
+ Image loadImage(ImageInfo info, Map hints) throws ImageException, IOException;
+
+ /**
+ * Loads and returns an image.
+ * @param info the image info object indicating the image
+ * @return the fully loaded image
+ * @throws ImageException if an error occurs while loading the image
+ * @throws IOException if an I/O error occurs while loading the image
+ */
+ Image loadImage(ImageInfo info) throws ImageException, IOException;
+
+ /**
+ * Returns the image flavor that is returned by this ImageLoader implementation.
+ * @return the target image flavor
+ */
+ ImageFlavor getTargetFlavor();
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoader.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.spi;
+
+import org.apache.fop.image2.ImageFlavor;
+
+/**
+ * This interface is implemented to provide information about an ImageLoader and to create new
+ * instances. A separate factory allows implementation to dynamically detect if the underlying
+ * libraries are available in the classpath so the caller can skip this implementation if it's
+ * not functional.
+ */
+public interface ImageLoaderFactory {
+
+ /**
+ * Returns an array of MIME types supported by this implementation.
+ * @return the MIME type array
+ */
+ String[] getSupportedMIMETypes();
+
+ /**
+ * Returns an array of ImageFlavors that are supported by this implementation for a given
+ * MIME type.
+ * @param mime the MIME type
+ * @return the ImageFlavor array
+ */
+ ImageFlavor[] getSupportedFlavors(String mime);
+
+ /**
+ * Creates and returns a new ImageLoader instance.
+ * @param targetFlavor the target image flavor to produce
+ * @return a new ImageLoader instance
+ */
+ ImageLoader newImageLoader(ImageFlavor targetFlavor);
+
+ /**
+ * Returns the usage penalty for a particular ImageLoader. This is used to select the best
+ * ImageLoader implementation for loading an image.
+ * @param mime the MIME type
+ * @param flavor the target image flavor
+ * @return the usage penalty (must be a non-negative integer)
+ */
+ int getUsagePenalty(String mime, ImageFlavor flavor);
+
+ /**
+ * Indicates whether the underlying libraries needed by the implementation are available.
+ * @return true if the implementation is functional.
+ */
+ boolean isAvailable();
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageLoaderFactory.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,57 @@
+/*
+ * 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.spi;
+
+import java.io.IOException;
+
+import javax.xml.transform.Source;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.image2.ImageException;
+import org.apache.fop.image2.ImageInfo;
+
+/**
+ * This interface provides two functions: determining whether an image format is supported and if
+ * that's the case, some minimal information (mostly the image's intrinsic size) is extracted
+ * and returned.
+ */
+public interface ImagePreloader {
+
+ /**
+ * "Preloads" an image, i.e. indentifies whether the source image is supported by this
+ * implementation and determines the image's intrinsic size and possibly some additional
+ * information. The image is usually not fully loaded at this time to conserve memory.
+ * @param originalURI the original (unresolved) URI of the image
+ * @param src a image source the image is loaded from
+ * @param userAgent the user agent providing context and configuration information
+ * @return an image info object with the basic information about an image
+ * @throws ImageException if an error occurs while preloading the image
+ * @throws IOException if an I/O error occurs while preloading the image
+ */
+ ImageInfo preloadImage(String originalURI,
+ Source src, FOUserAgent userAgent) throws ImageException, IOException;
+
+ /**
+ * Returns the MIME type supported by the image preloader.
+ * @return the MIME type
+ */
+ String getMimeType();
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImagePreloader.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.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.spi;
+
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.util.dijkstra.Vertex;
+
+/**
+ * This class represents a combination of MIME type and an image flavor.
+ * It is used in conjunction with Dijkstra's algorithm to find and construct a
+ * conversion pipeline for images.
+ */
+public class ImageRepresentation implements Vertex {
+
+ //private String mime;
+ private ImageFlavor flavor;
+
+ /**
+ * Main constructor
+ * @param mime the MIME type
+ * @param flavor the image flavor
+ */
+ public ImageRepresentation(/*String mime,*/ ImageFlavor flavor) {
+ //this.mime = mime;
+ this.flavor = flavor;
+ }
+
+ /**
+ * Returns the MIME type.
+ * @return the MIME type
+ *//*
+ public String getMIMEType() {
+ return mime;
+ }*/
+
+ /**
+ * Returns the image flavor.
+ * @return the image flavor
+ */
+ public ImageFlavor getFlavor() {
+ return flavor;
+ }
+
+ /** {@inheritDoc} */
+ public boolean equals(Object obj) {
+ return toString().equals(((ImageRepresentation)obj).toString());
+ }
+
+ /** {@inheritDoc} */
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ /** {@inheritDoc} */
+ public int compareTo(Object obj) {
+ return toString().compareTo(((ImageRepresentation)obj).toString());
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return /*getMIMEType() +*/ " (" + getFlavor() + ")";
+ }
+
+}
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/ImageRepresentation.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/package.html?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/package.html (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/package.html Wed Nov 14 04:12:50 2007
@@ -0,0 +1,25 @@
+<!--
+ 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$ -->
+<HTML>
+<TITLE>org.apache.fop.image2.spi Package</TITLE>
+<BODY>
+<P>
+ Defines service provider interfaces for the image infrastructure.
+</P>
+</BODY>
+</HTML>
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/spi/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,99 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.stream.ImageInputStream;
+
+/**
+ * Decorates an ImageInputStream with an InputStream interface. The methods <code>mark()</code>
+ * and <code>reset()</code> are fully supported. The method <code>available()</code> will
+ * always return 0.
+ */
+public class ImageInputStreamAdapter extends InputStream {
+
+ private ImageInputStream iin;
+
+ private long lastMarkPosition;
+
+ /**
+ * Creates a new ImageInputStreamAdapter.
+ * @param iin the underlying ImageInputStream
+ */
+ public ImageInputStreamAdapter(ImageInputStream iin) {
+ this.iin = iin;
+ }
+
+ /** {@inheritDoc} */
+ public int read(byte[] b, int off, int len) throws IOException {
+ return iin.read(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ public int read(byte[] b) throws IOException {
+ return iin.read(b);
+ }
+
+ /** {@inheritDoc} */
+ public int read() throws IOException {
+ return iin.read();
+ }
+
+ /** {@inheritDoc} */
+ public long skip(long n) throws IOException {
+ return iin.skipBytes(n);
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ iin.close();
+ iin = null;
+ }
+
+ /** {@inheritDoc} */
+ public synchronized void mark(int readlimit) {
+ //Parameter readlimit is ignored
+ try {
+ //Cannot use mark()/reset() since they are nestable, and InputStream's are not
+ this.lastMarkPosition = iin.getStreamPosition();
+ } catch (IOException ioe) {
+ throw new RuntimeException(
+ "Unexpected IOException in ImageInputStream.getStreamPosition()", ioe);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public boolean markSupported() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public synchronized void reset() throws IOException {
+ iin.seek(this.lastMarkPosition);
+ }
+
+ /** {@inheritDoc} */
+ public int available() throws IOException {
+ return 0;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageInputStreamAdapter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,235 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.zip.GZIPInputStream;
+
+import javax.imageio.stream.ImageInputStream;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.image2.ImageSource;
+
+/**
+ * Helper and convenience methods for working with the image package.
+ */
+public class ImageUtil {
+
+ /**
+ * Returns the InputStream of a Source object.
+ * @param src the Source object
+ * @return the InputStream (or null if there's not InputStream available)
+ */
+ public static InputStream getInputStream(Source src) {
+ if (src instanceof StreamSource) {
+ return ((StreamSource)src).getInputStream();
+ } else if (src instanceof ImageSource) {
+ return new ImageInputStreamAdapter(((ImageSource)src).getImageInputStream());
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the ImageInputStream of a Source object.
+ * @param src the Source object
+ * @return the ImageInputStream (or null if there's not ImageInputStream available)
+ */
+ public static ImageInputStream getImageInputStream(Source src) {
+ if (src instanceof ImageSource) {
+ return ((ImageSource)src).getImageInputStream();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the InputStream of a Source object. This method throws an IllegalArgumentException
+ * if there's no InputStream instance available from the Source object.
+ * @param src the Source object
+ * @return the InputStream
+ */
+ public static InputStream needInputStream(Source src) {
+ InputStream in = getInputStream(src);
+ if (in != null) {
+ return in;
+ } else {
+ throw new IllegalArgumentException("Source must be a StreamSource with an InputStream"
+ + " or an ImageSource");
+ }
+ }
+
+ /**
+ * Returns the ImageInputStream of a Source object. This method throws an
+ * IllegalArgumentException if there's no ImageInputStream instance available from the
+ * Source object.
+ * @param src the Source object
+ * @return the ImageInputStream
+ */
+ public static ImageInputStream needImageInputStream(Source src) {
+ ImageInputStream in = getImageInputStream(src);
+ if (in != null) {
+ return in;
+ } else {
+ throw new IllegalArgumentException("Source must be an ImageSource");
+ }
+ }
+
+ /**
+ * Indicates whether the Source object has an InputStream instance.
+ * @param src the Source object
+ * @return true if an InputStream is available
+ */
+ public static boolean hasInputStream(Source src) {
+ if (src instanceof StreamSource) {
+ InputStream in = ((StreamSource)src).getInputStream();
+ return (in != null);
+ } else if (src instanceof ImageSource) {
+ return hasImageInputStream(src);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Indicates whether the Source object has an ImageInputStream instance.
+ * @param src the Source object
+ * @return true if an ImageInputStream is available
+ */
+ public static boolean hasImageInputStream(Source src) {
+ if (src instanceof ImageSource) {
+ ImageInputStream in = ((ImageSource)src).getImageInputStream();
+ if (in != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Closes the InputStreams or ImageInputStreams of Source objects. Any exception occurring
+ * while closing the stream is ignored.
+ * @param src the Source object
+ */
+ public static void closeQuietly(Source src) {
+ if (src instanceof StreamSource) {
+ StreamSource streamSource = (StreamSource)src;
+ IOUtils.closeQuietly(streamSource.getInputStream());
+ streamSource.setInputStream(null);
+ IOUtils.closeQuietly(streamSource.getReader());
+ streamSource.setReader(null);
+ } else if (src instanceof ImageSource) {
+ ImageSource imageSource = (ImageSource)src;
+ if (imageSource.getImageInputStream() != null) {
+ try {
+ imageSource.getImageInputStream().close();
+ } catch (IOException ioe) {
+ //ignore
+ }
+ imageSource.setImageInputStream(null);
+ }
+ } else {
+ throw new IllegalArgumentException("Source not supported!");
+ }
+ }
+
+ /**
+ * Decorates an ImageInputStream so the flush*() methods are ignored and have no effect.
+ * The decoration is implemented using a dynamic proxy.
+ * @param in the ImageInputStream
+ * @return the decorated ImageInputStream
+ */
+ public static ImageInputStream ignoreFlushing(final ImageInputStream in) {
+ return (ImageInputStream)Proxy.newProxyInstance(in.getClass().getClassLoader(),
+ new Class[] {ImageInputStream.class},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ String methodName = method.getName();
+ //Ignore calls to flush*()
+ if (!methodName.startsWith("flush")) {
+ return method.invoke(in, args);
+ } else {
+ return null;
+ }
+ }
+ });
+ }
+
+ /**
+ * GZIP header magic number bytes, like found in a gzipped
+ * files, which are encoded in Intel format (i..e. little indian).
+ */
+ private static final byte[] GZIP_MAGIC = {(byte)0x1f, (byte)0x8b};
+
+ /**
+ * Indicates whether an InputStream is GZIP compressed. The InputStream must support
+ * mark()/reset().
+ * @param in the InputStream (must return true on markSupported())
+ * @return true if the InputStream is GZIP compressed
+ * @throws IOException in case of an I/O error
+ */
+ public static boolean isGZIPCompressed(InputStream in) throws IOException {
+ if (!in.markSupported()) {
+ throw new IllegalArgumentException("InputStream must support mark()!");
+ }
+ byte[] data = new byte[2];
+ in.mark(2);
+ in.read(data);
+ in.reset();
+ return ((data[0] == GZIP_MAGIC[0]) && (data[1] == GZIP_MAGIC[1]));
+ }
+
+ /**
+ * Decorates an InputStream with a BufferedInputStream if it doesn't support mark()/reset().
+ * @param in the InputStream
+ * @return the decorated InputStream
+ */
+ public static InputStream decorateMarkSupported(InputStream in) {
+ if (in.markSupported()) {
+ return in;
+ } else {
+ return new java.io.BufferedInputStream(in);
+ }
+ }
+
+ /**
+ * Automatically decorates an InputStream so it is buffered. Furthermore, it makes sure
+ * it is decorated with a GZIPInputStream if the stream is GZIP compressed.
+ * @param in the InputStream
+ * @return the decorated InputStream
+ * @throws IOException in case of an I/O error
+ */
+ public static InputStream autoDecorateInputStream(InputStream in) throws IOException {
+ in = decorateMarkSupported(in);
+ if (isGZIPCompressed(in)) {
+ return new GZIPInputStream(in);
+ }
+ return in;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/ImageUtil.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java Wed Nov 14 04:12:50 2007
@@ -0,0 +1,73 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.xmlgraphics.image.codec.util.SeekableStream;
+
+/**
+ * Adapter which provides a SeekableStream interface over an ImageInputStream.
+ */
+public class SeekableStreamAdapter extends SeekableStream {
+
+ private ImageInputStream iin;
+
+ /**
+ * Main constructor
+ * @param iin the ImageInputStream to operate on
+ */
+ public SeekableStreamAdapter(ImageInputStream iin) {
+ this.iin = iin;
+ }
+
+ /** {@inheritDoc} */
+ public long getFilePointer() throws IOException {
+ return iin.getStreamPosition();
+ }
+
+ /** {@inheritDoc} */
+ public int read() throws IOException {
+ return iin.read();
+ }
+
+ /** {@inheritDoc} */
+ public int read(byte[] b, int off, int len) throws IOException {
+ return iin.read(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ public void seek(long pos) throws IOException {
+ iin.seek(pos);
+ }
+
+ /** {@inheritDoc} */
+ public boolean canSeekBackwards() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public int skipBytes(int n) throws IOException {
+ return iin.skipBytes(n);
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/SeekableStreamAdapter.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/package.html?rev=594848&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/package.html (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/package.html Wed Nov 14 04:12:50 2007
@@ -0,0 +1,26 @@
+<!--
+ 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$ -->
+<HTML>
+<TITLE>org.apache.fop.image2.util Package</TITLE>
+<BODY>
+<P>
+ Contains utilities and helper classes useful in conjunction with the image
+ package.
+</P>
+</BODY>
+</HTML>
\ No newline at end of file
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/util/package.html
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org