xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r447153 - in /xmlgraphics/commons/trunk/src: java-1.4/org/apache/xmlgraphics/image/writer/imageio/ java/org/apache/xmlgraphics/image/writer/ java/org/apache/xmlgraphics/image/writer/internal/ resources/META-INF/services/
Date Sun, 17 Sep 2006 21:48:57 GMT
Author: jeremias
Date: Sun Sep 17 14:48:56 2006
New Revision: 447153

URL: http://svn.apache.org/viewvc?view=rev&rev=447153
Log:
Extended the ImageWriter abstraction to handle formats which support multiple pages per file
(like TIFF).
New ImageWriter for TIFF using the internal codec (used be FOP in a JDK 1.3 situation).
ImageIOImageWriter extended to support multiple pages per file where possible.

Added:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/AbstractImageWriter.java
  (with props)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/MultiImageWriter.java
  (with props)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/TIFFImageWriter.java
  (with props)
Modified:
    xmlgraphics/commons/trunk/src/java-1.4/org/apache/xmlgraphics/image/writer/imageio/ImageIOImageWriter.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriter.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterParams.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/JPEGImageWriter.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/PNGImageWriter.java
    xmlgraphics/commons/trunk/src/resources/META-INF/services/org.apache.xmlgraphics.image.writer.ImageWriter

Modified: xmlgraphics/commons/trunk/src/java-1.4/org/apache/xmlgraphics/image/writer/imageio/ImageIOImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java-1.4/org/apache/xmlgraphics/image/writer/imageio/ImageIOImageWriter.java?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java-1.4/org/apache/xmlgraphics/image/writer/imageio/ImageIOImageWriter.java
(original)
+++ xmlgraphics/commons/trunk/src/java-1.4/org/apache/xmlgraphics/image/writer/imageio/ImageIOImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -38,6 +38,7 @@
 
 import org.apache.xmlgraphics.image.writer.ImageWriter;
 import org.apache.xmlgraphics.image.writer.ImageWriterParams;
+import org.apache.xmlgraphics.image.writer.MultiImageWriter;
 
 /**
  * ImageWriter implementation that uses Image I/O to write images.
@@ -69,45 +70,49 @@
     public void writeImage(RenderedImage image, OutputStream out, 
             ImageWriterParams params) 
                 throws IOException {
-        Iterator iter;
-        iter = ImageIO.getImageWritersByMIMEType(getMIMEType());
-        javax.imageio.ImageWriter iiowriter = (javax.imageio.ImageWriter)iter.next();
-        if (iiowriter != null) {
-            iiowriter.addIIOWriteWarningListener(this);
+        javax.imageio.ImageWriter iiowriter = getIIOImageWriter();
+        iiowriter.addIIOWriteWarningListener(this);
+        
+        ImageOutputStream imgout = ImageIO.createImageOutputStream(out);
+        try {
             
-            ImageOutputStream imgout = ImageIO.createImageOutputStream(out);
-            try {
-                
-                ImageWriteParam iwParam = getDefaultWriteParam(iiowriter, image, params);
-                
-                ImageTypeSpecifier type;
-                if (iwParam.getDestinationType() != null) {
-                    type = iwParam.getDestinationType();
-                } else {
-                    type = ImageTypeSpecifier.createFromRenderedImage(image);
-                }
-                
-                //Handle metadata
-                IIOMetadata meta = iiowriter.getDefaultImageMetadata(
-                        type, iwParam);
-                //meta might be null for some JAI codecs as they don't support metadata
-                if (params != null && meta != null) {
-                    meta = updateMetadata(meta, params); 
-                }
-                
-                //Write image
-                iiowriter.setOutput(imgout);
-                IIOImage iioimg = new IIOImage(image, null, meta);
-                iiowriter.write(null, iioimg, iwParam);
-                
-            } finally {
-                imgout.close();
+            ImageWriteParam iwParam = getDefaultWriteParam(iiowriter, image, params);
+            
+            ImageTypeSpecifier type;
+            if (iwParam.getDestinationType() != null) {
+                type = iwParam.getDestinationType();
+            } else {
+                type = ImageTypeSpecifier.createFromRenderedImage(image);
+            }
+            
+            //Handle metadata
+            IIOMetadata meta = iiowriter.getDefaultImageMetadata(
+                    type, iwParam);
+            //meta might be null for some JAI codecs as they don't support metadata
+            if (params != null && meta != null) {
+                meta = updateMetadata(meta, params); 
             }
+            
+            //Write image
+            iiowriter.setOutput(imgout);
+            IIOImage iioimg = new IIOImage(image, null, meta);
+            iiowriter.write(null, iioimg, iwParam);
+            
+        } finally {
+            imgout.close();
+            iiowriter.dispose();
+        }
+    }
+    
+    private javax.imageio.ImageWriter getIIOImageWriter() {
+        Iterator iter = ImageIO.getImageWritersByMIMEType(getMIMEType());
+        javax.imageio.ImageWriter iiowriter = (javax.imageio.ImageWriter)iter.next();
+        if (iiowriter != null) {
+            return iiowriter;
         } else {
             throw new UnsupportedOperationException("No ImageIO codec for writing " 
                     + getMIMEType() + " is available!");
         }
-        
     }
     
     /**
@@ -184,19 +189,90 @@
         return null;
     }
 
-    /**
-     * @see ImageWriter#getMIMEType()
-     */
+    /** @see ImageWriter#getMIMEType() */
     public String getMIMEType() {
         return this.targetMIME;
     }
 
     /**
-     * @see javax.imageio.event.IIOWriteWarningListener#warningOccurred(javax.imageio.ImageWriter,
int, java.lang.String)
+     * @see javax.imageio.event.IIOWriteWarningListener#warningOccurred(
+     *          javax.imageio.ImageWriter, int, java.lang.String)
      */
     public void warningOccurred(javax.imageio.ImageWriter source, 
             int imageIndex, String warning) {
         System.err.println("Problem while writing image using ImageI/O: " 
                 + warning);
     }
+    
+    /**
+     * @see org.apache.xmlgraphics.image.writer.ImageWriter#createMultiImageWriter(
+     *          java.io.OutputStream)
+     */
+    public MultiImageWriter createMultiImageWriter(OutputStream out) throws IOException {
+        return new IIOMultiImageWriter(out);
+    }
+
+    /** @see org.apache.xmlgraphics.image.writer.ImageWriter#supportsMultiImageWriter() */
+    public boolean supportsMultiImageWriter() {
+        javax.imageio.ImageWriter iiowriter = getIIOImageWriter();
+        try {
+            return iiowriter.canWriteSequence();
+        } finally {
+            iiowriter.dispose();
+        }
+    }
+
+    private class IIOMultiImageWriter implements MultiImageWriter {
+
+        private javax.imageio.ImageWriter iiowriter;
+        private ImageOutputStream imageStream;
+        
+        public IIOMultiImageWriter(OutputStream out) throws IOException {
+            this.iiowriter = getIIOImageWriter();
+            if (!iiowriter.canWriteSequence()) {
+                throw new UnsupportedOperationException("This ImageWriter does not support
writing"
+                        + " multiple images to a single image file.");
+            }
+            iiowriter.addIIOWriteWarningListener(ImageIOImageWriter.this);
+            
+            imageStream = ImageIO.createImageOutputStream(out);
+            iiowriter.setOutput(imageStream);
+            iiowriter.prepareWriteSequence(null);
+        }
+        
+        public void writeImage(RenderedImage image, ImageWriterParams params) throws IOException
{
+            if (iiowriter == null) {
+                throw new IllegalStateException("MultiImageWriter already closed!");
+            }
+            ImageWriteParam iwParam = getDefaultWriteParam(iiowriter, image, params);
+            
+            ImageTypeSpecifier type;
+            if (iwParam.getDestinationType() != null) {
+                type = iwParam.getDestinationType();
+            } else {
+                type = ImageTypeSpecifier.createFromRenderedImage(image);
+            }
+            
+            //Handle metadata
+            IIOMetadata meta = iiowriter.getDefaultImageMetadata(
+                    type, iwParam);
+            //meta might be null for some JAI codecs as they don't support metadata
+            if (params != null && meta != null) {
+                meta = updateMetadata(meta, params); 
+            }
+            
+            //Write image
+            IIOImage iioimg = new IIOImage(image, null, meta);
+            iiowriter.writeToSequence(iioimg, iwParam);
+        }
+        
+        public void close() throws IOException {
+            imageStream.close();
+            imageStream = null;
+            iiowriter.dispose();
+            iiowriter = null;
+        }
+
+    }
+
 }

Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/AbstractImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/AbstractImageWriter.java?view=auto&rev=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/AbstractImageWriter.java
(added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/AbstractImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -0,0 +1,47 @@
+/*
+ * 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.xmlgraphics.image.writer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Abstract base class for ImageWriter implementations.
+ *
+ * @version $Id: ImageWriter.java 426584 2006-07-28 16:01:47Z jeremias $
+ */
+public abstract class AbstractImageWriter implements ImageWriter {
+
+    /**
+     * @see org.apache.xmlgraphics.image.writer.ImageWriter#createMultiImageWriter(
+     *                  java.io.OutputStream)
+     */
+    public MultiImageWriter createMultiImageWriter(OutputStream out)
+            throws IOException {
+        throw new UnsupportedOperationException("This ImageWriter does not support writing"
+                + " multiple images to a single image file.");
+    }
+
+    /** @see org.apache.xmlgraphics.image.writer.ImageWriter#supportsMultiImageWriter() */
+    public boolean supportsMultiImageWriter() {
+        return false;
+    }
+    
+}

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/AbstractImageWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriter.java?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriter.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -1,21 +1,22 @@
 /*
+ * 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.
+ */
 
-   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.xmlgraphics.image.writer;
 
 import java.awt.image.RenderedImage;
@@ -51,5 +52,17 @@
 
     /** @return the target MIME type supported by this ImageWriter */
     public String getMIMEType();
+
+    /** @return true if the implemented format supports multiple pages in a single file */
+    public boolean supportsMultiImageWriter();
+    
+    /**
+     * Creates a MultiImageWriter instance that lets you put multiple pages into a single
file
+     * if the format supports it.
+     * @param out the OutputStream to write the image to
+     * @return the requested MultiImageWriter instance
+     * @throws IOException In case of an /IO problem
+     */
+    public MultiImageWriter createMultiImageWriter(OutputStream out) throws IOException;
     
 }

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterParams.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterParams.java?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterParams.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterParams.java
Sun Sep 17 14:48:56 2006
@@ -1,21 +1,22 @@
 /*
+ * 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.
+ */
 
-   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.xmlgraphics.image.writer;
 
 /**

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
Sun Sep 17 14:48:56 2006
@@ -1,21 +1,22 @@
 /*
+ * 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.
+ */
 
-   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.xmlgraphics.image.writer;
 
 import java.io.IOException;

Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/MultiImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/MultiImageWriter.java?view=auto&rev=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/MultiImageWriter.java
(added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/MultiImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.xmlgraphics.image.writer;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+
+/**
+ * Interface which allows writing multiple images into one image file if the output format
+ * supports this feature. 
+ *
+ * @version $Id$
+ */
+public interface MultiImageWriter {
+
+    /**
+     * Encodes an image and writes it to the image file.
+     * @param image the image to be encoded
+     * @param params a parameters object to customize the encoding.
+     * @throws IOException In case of an /IO problem
+     */
+    public void writeImage(RenderedImage image, ImageWriterParams params) 
+            throws IOException;
+    
+    public void close() throws IOException;
+    
+}

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/MultiImageWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/JPEGImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/JPEGImageWriter.java?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/JPEGImageWriter.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/JPEGImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -1,21 +1,22 @@
 /*
+ * 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.
+ */
 
-   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.xmlgraphics.image.writer.internal;
 
 import java.awt.image.BufferedImage;
@@ -24,6 +25,7 @@
 import java.io.OutputStream;
 
 import org.apache.xmlgraphics.image.GraphicsUtil;
+import org.apache.xmlgraphics.image.writer.AbstractImageWriter;
 import org.apache.xmlgraphics.image.writer.ImageWriter;
 import org.apache.xmlgraphics.image.writer.ImageWriterParams;
 
@@ -34,10 +36,13 @@
 /**
  * ImageWriter implementation that uses the sun.com.image.codec.jpeg
  * intefaces to write JPEG files.
+ * <p>
+ * Note: This class depends on a Sun runtime environment and is therefore not compatible
with 
+ * non-Sun VMs (such as Harmony or GNU Classpath based VMs).
  *
  * @version $Id$
  */
-public class JPEGImageWriter implements ImageWriter {
+public class JPEGImageWriter extends AbstractImageWriter {
 
     /**
      * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream)

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/PNGImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/PNGImageWriter.java?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/PNGImageWriter.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/PNGImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -1,21 +1,22 @@
 /*
+ * 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.
+ */
 
-   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.xmlgraphics.image.writer.internal;
 
 import java.awt.image.RenderedImage;
@@ -23,16 +24,17 @@
 import java.io.OutputStream;
 
 import org.apache.xmlgraphics.image.codec.png.PNGImageEncoder;
+import org.apache.xmlgraphics.image.writer.AbstractImageWriter;
 import org.apache.xmlgraphics.image.writer.ImageWriter;
 import org.apache.xmlgraphics.image.writer.ImageWriterParams;
 
 /**
- * ImageWriter implementation that uses Batik's PNG codec to 
+ * ImageWriter implementation that uses the internal PNG codec to 
  * write PNG files.
  *
  * @version $Id$
  */
-public class PNGImageWriter implements ImageWriter {
+public class PNGImageWriter extends AbstractImageWriter {
 
     /**
      * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream)

Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/TIFFImageWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/TIFFImageWriter.java?view=auto&rev=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/TIFFImageWriter.java
(added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/TIFFImageWriter.java
Sun Sep 17 14:48:56 2006
@@ -0,0 +1,151 @@
+/*
+ * 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.xmlgraphics.image.writer.internal;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFField;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImageDecoder;
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImageEncoder;
+import org.apache.xmlgraphics.image.writer.AbstractImageWriter;
+import org.apache.xmlgraphics.image.writer.ImageWriter;
+import org.apache.xmlgraphics.image.writer.ImageWriterParams;
+import org.apache.xmlgraphics.image.writer.MultiImageWriter;
+
+/**
+ * ImageWriter implementation that uses the internal TIFF codec to 
+ * write TIFF files.
+ *
+ * @version $Id$
+ */
+public class TIFFImageWriter extends AbstractImageWriter {
+
+    /**
+     * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream)
+     */
+    public void writeImage(RenderedImage image, OutputStream out)
+            throws IOException {
+        writeImage(image, out, null);
+    }
+
+    /**
+     * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, ImageWriterParams)
+     */
+    public void writeImage(RenderedImage image, OutputStream out,
+            ImageWriterParams params) throws IOException {
+        TIFFEncodeParam encodeParams = createTIFFEncodeParams(params);
+        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
+        encoder.encode(image);
+    }
+
+    private TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params) {
+        TIFFEncodeParam encodeParams = new TIFFEncodeParam();
+        if (params.getCompressionMethod() == null) {
+            //PackBits as default
+            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
+        } else if ("PackBits".equalsIgnoreCase(params.getCompressionMethod())) {
+            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
+        } else if ("NONE".equalsIgnoreCase(params.getCompressionMethod())) {
+            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
+        } else if ("JPEG".equalsIgnoreCase(params.getCompressionMethod())) {
+            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
+        } else if ("Deflate".equalsIgnoreCase(params.getCompressionMethod())) {
+            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
+        } else {
+            throw new UnsupportedOperationException("Compression method not supported: "
+                    + params.getCompressionMethod());
+        }
+        
+        if (params.getResolution() != null) {
+            // Set target resolution
+            float pixSzMM = 25.4f / params.getResolution().floatValue();
+            // num Pixs in 100 Meters
+            int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5); 
+            int denom = 100 * 100;  // Centimeters per 100 Meters;
+            long [] rational = {numPix, denom};
+            TIFFField [] fields = {
+                new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT, 
+                              TIFFField.TIFF_SHORT, 1, 
+                              new char[] {(char)3}),
+                new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION, 
+                              TIFFField.TIFF_RATIONAL, 1, 
+                              new long[][] {rational}),
+                new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION, 
+                              TIFFField.TIFF_RATIONAL, 1, 
+                              new long[][] {rational}) 
+                    };
+            encodeParams.setExtraFields(fields);
+        }
+        return encodeParams;
+    }
+    
+    /**
+     * @see ImageWriter#getMIMEType()
+     */
+    public String getMIMEType() {
+        return "image/tiff";
+    }
+    
+    /**
+     * @see org.apache.xmlgraphics.image.writer.ImageWriter#createMultiImageWriter(
+     *          java.io.OutputStream)
+     */
+    public MultiImageWriter createMultiImageWriter(OutputStream out) throws IOException {
+        return new TIFFMultiImageWriter(out);
+    }
+
+    /** @see org.apache.xmlgraphics.image.writer.ImageWriter#supportsMultiImageWriter() */
+    public boolean supportsMultiImageWriter() {
+        return true;
+    }
+
+    private class TIFFMultiImageWriter implements MultiImageWriter {
+
+        private OutputStream out;
+        private TIFFEncodeParam encodeParams;
+        private TIFFImageEncoder encoder;
+        private Object context;
+        
+        public TIFFMultiImageWriter(OutputStream out) throws IOException {
+            this.out = out;
+        }
+        
+        public void writeImage(RenderedImage image, ImageWriterParams params) throws IOException
{
+            if (encoder == null) {
+                encodeParams = createTIFFEncodeParams(params);
+                encoder = new TIFFImageEncoder(out, encodeParams);
+            }
+            context = encoder.encodeMultiple(context, image);
+        }
+        
+        public void close() throws IOException {
+            encoder.finishMultiple(context);
+            encoder = null;
+            encodeParams = null;
+            out.flush();
+        }
+
+    }
+
+    
+}

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/TIFFImageWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/src/resources/META-INF/services/org.apache.xmlgraphics.image.writer.ImageWriter
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/resources/META-INF/services/org.apache.xmlgraphics.image.writer.ImageWriter?view=diff&rev=447153&r1=447152&r2=447153
==============================================================================
--- xmlgraphics/commons/trunk/src/resources/META-INF/services/org.apache.xmlgraphics.image.writer.ImageWriter
(original)
+++ xmlgraphics/commons/trunk/src/resources/META-INF/services/org.apache.xmlgraphics.image.writer.ImageWriter
Sun Sep 17 14:48:56 2006
@@ -1,4 +1,5 @@
 org.apache.xmlgraphics.image.writer.internal.PNGImageWriter
+org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter
 org.apache.xmlgraphics.image.writer.internal.JPEGImageWriter
 org.apache.xmlgraphics.image.writer.imageio.ImageIOPNGImageWriter
 org.apache.xmlgraphics.image.writer.imageio.ImageIOTIFFImageWriter



---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message