harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r518588 - in /harmony/enhanced/classlib/trunk/modules/imageio: ./ src/main/java/javax/imageio/spi/ src/main/java/org/apache/harmony/x/imageio/internal/ src/main/java/org/apache/harmony/x/imageio/internal/nls/ src/main/java/org/apache/harmon...
Date Thu, 15 Mar 2007 11:37:18 GMT
Author: apetrenko
Date: Thu Mar 15 04:37:16 2007
New Revision: 518588

URL: http://svn.apache.org/viewvc?view=rev&rev=518588
Log:
Patch for HARMONY-3143 "javax.imageio.ImageIO.write doesn't work with png-images"

Added:
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/Messages.java   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterParam.java   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/pngencoder.h   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/pngencoder.c   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/exports.txt   (with props)
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/makefile
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/makefile
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.def
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.rc
Modified:
    harmony/enhanced/classlib/trunk/modules/imageio/build.xml
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java

Modified: harmony/enhanced/classlib/trunk/modules/imageio/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/build.xml?view=diff&rev=518588&r1=518587&r2=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/build.xml (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/build.xml Thu Mar 15 04:37:16 2007
@@ -107,6 +107,14 @@
                 <exclude name="*${manifest.suffix}"/>
             </fileset>
         </copy>
+        <make dir="${hy.imageio.src.main.native}/pngencoder/${hy.os.family}" />
+        <!-- Copy the built shared libs over to the jre/bin dir -->
+        <copy todir="${hy.jdk}/jre/bin" overwrite="yes">
+            <fileset dir="${hy.imageio.src.main.native}/pngencoder/">
+                <include name="*${shlib.suffix}*"/>
+                <exclude name="*${manifest.suffix}"/>
+            </fileset>
+        </copy>
     </target>
 
     <target name="copy-resources">

Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java?view=diff&rev=518588&r1=518587&r2=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java Thu Mar 15 04:37:16 2007
@@ -21,9 +21,11 @@
 package javax.imageio.spi;
 
 import java.util.Arrays;
+
 import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi;
 import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi;
 import org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi;
+import org.apache.harmony.x.imageio.plugins.png.PNGImageWriterSpi;
 import org.apache.harmony.x.imageio.spi.FileIISSpi;
 import org.apache.harmony.x.imageio.spi.FileIOSSpi;
 import org.apache.harmony.x.imageio.spi.InputStreamIISSpi;
@@ -32,7 +34,7 @@
 import org.apache.harmony.x.imageio.spi.RAFIOSSpi;
 
 /**
- * @author Rustem V. Rafikov
+ * @author Rustem V. Rafikov, Viskov Nikolay
  * @version $Revision: 1.3 $
  */
 public final class IIORegistry extends ServiceRegistry {
@@ -57,6 +59,7 @@
         registerServiceProvider(new JPEGImageWriterSpi());
         registerServiceProvider(new JPEGImageReaderSpi());
         registerServiceProvider(new PNGImageReaderSpi());
+        registerServiceProvider(new PNGImageWriterSpi());
         registerServiceProvider(new FileIOSSpi());
         registerServiceProvider(new FileIISSpi());
         registerServiceProvider(new RAFIOSSpi());

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/Messages.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/Messages.java?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/Messages.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/Messages.java Thu Mar 15 04:37:16 2007
@@ -0,0 +1,242 @@
+/* 
+ * 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.
+ */
+
+/*
+ * THE FILE HAS BEEN AUTOGENERATED BY MSGTOOL TOOL.
+ * All changes made to this file manually will be overwritten 
+ * if this tool runs again. Better make changes in the template file.
+ */
+
+package org.apache.harmony.x.imageio.internal.nls;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.harmony.kernel.vm.VM;
+
+/**
+ * This class retrieves strings from a resource bundle and returns them,
+ * formatting them with MessageFormat when required.
+ * <p>
+ * It is used by the system classes to provide national language support, by
+ * looking up messages in the <code>
+ *    org.apache.harmony.x.imageio.internal.nls.messages
+ * </code>
+ * resource bundle. Note that if this file is not available, or an invalid key
+ * is looked up, or resource bundle support is not available, the key itself
+ * will be returned as the associated message. This means that the <em>KEY</em>
+ * should a reasonable human-readable (english) string.
+ * 
+ */
+public class Messages {
+
+    // ResourceBundle holding the system messages.
+    static private ResourceBundle bundle = null;
+
+    /**
+     * Retrieves a message which has no arguments.
+     * 
+     * @param msg
+     *            String the key to look up.
+     * @return String the message for that key in the system message bundle.
+     */
+    static public String getString(String msg) {
+        if (bundle == null)
+            return msg;
+        try {
+            return bundle.getString(msg);
+        } catch (MissingResourceException e) {
+            return "Missing message: " + msg; //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Retrieves a message which takes 1 argument.
+     * 
+     * @param msg
+     *            String the key to look up.
+     * @param arg
+     *            Object the object to insert in the formatted output.
+     * @return String the message for that key in the system message bundle.
+     */
+    static public String getString(String msg, Object arg) {
+        return getString(msg, new Object[] { arg });
+    }
+
+    /**
+     * Retrieves a message which takes 1 integer argument.
+     * 
+     * @param msg
+     *            String the key to look up.
+     * @param arg
+     *            int the integer to insert in the formatted output.
+     * @return String the message for that key in the system message bundle.
+     */
+    static public String getString(String msg, int arg) {
+        return getString(msg, new Object[] { Integer.toString(arg) });
+    }
+
+    /**
+     * Retrieves a message which takes 1 character argument.
+     * 
+     * @param msg
+     *            String the key to look up.
+     * @param arg
+     *            char the character to insert in the formatted output.
+     * @return String the message for that key in the system message bundle.
+     */
+    static public String getString(String msg, char arg) {
+        return getString(msg, new Object[] { String.valueOf(arg) });
+    }
+
+    /**
+     * Retrieves a message which takes 2 arguments.
+     * 
+     * @param msg
+     *            String the key to look up.
+     * @param arg1
+     *            Object an object to insert in the formatted output.
+     * @param arg2
+     *            Object another object to insert in the formatted output.
+     * @return String the message for that key in the system message bundle.
+     */
+    static public String getString(String msg, Object arg1, Object arg2) {
+        return getString(msg, new Object[] { arg1, arg2 });
+    }
+
+    /**
+     * Retrieves a message which takes several arguments.
+     * 
+     * @param msg
+     *            String the key to look up.
+     * @param args
+     *            Object[] the objects to insert in the formatted output.
+     * @return String the message for that key in the system message bundle.
+     */
+    static public String getString(String msg, Object[] args) {
+        String format = msg;
+
+        if (bundle != null) {
+            try {
+                format = bundle.getString(msg);
+            } catch (MissingResourceException e) {
+            }
+        }
+
+        return format(format, args);
+    }
+    
+    /**
+     * Generates a formatted text string given a source string containing
+     * "argument markers" of the form "{argNum}" where each argNum must be in
+     * the range 0..9. The result is generated by inserting the toString of each
+     * argument into the position indicated in the string.
+     * <p>
+     * To insert the "{" character into the output, use a single backslash
+     * character to escape it (i.e. "\{"). The "}" character does not need to be
+     * escaped.
+     * 
+     * @param format
+     *            String the format to use when printing.
+     * @param args
+     *            Object[] the arguments to use.
+     * @return String the formatted message.
+     */
+    public static String format(String format, Object[] args) {
+        StringBuilder answer = new StringBuilder(format.length()
+                + (args.length * 20));
+        String[] argStrings = new String[args.length];
+        for (int i = 0; i < args.length; ++i) {
+            if (args[i] == null)
+                argStrings[i] = "<null>";	//$NON-NLS-1$
+            else
+                argStrings[i] = args[i].toString();
+        }
+        int lastI = 0;
+        for (int i = format.indexOf('{', 0); i >= 0; i = format.indexOf('{',
+                lastI)) {
+            if (i != 0 && format.charAt(i - 1) == '\\') {
+                // It's escaped, just print and loop.
+                if (i != 1)
+                    answer.append(format.substring(lastI, i - 1));
+                answer.append('{');
+                lastI = i + 1;
+            } else {
+                // It's a format character.
+                if (i > format.length() - 3) {
+                    // Bad format, just print and loop.
+                    answer.append(format.substring(lastI, format.length()));
+                    lastI = format.length();
+                } else {
+                    int argnum = (byte) Character.digit(format.charAt(i + 1),
+                            10);
+                    if (argnum < 0 || format.charAt(i + 2) != '}') {
+                        // Bad format, just print and loop.
+						answer.append(format.substring(lastI, i + 1));
+						lastI = i + 1;
+                    } else {
+                        // Got a good one!
+                        answer.append(format.substring(lastI, i));
+                        if (argnum >= argStrings.length)
+                            answer.append("<missing argument>");	//$NON-NLS-1$
+                        else
+                            answer.append(argStrings[argnum]);
+						lastI = i + 3;
+                    }
+                }
+            }
+        }
+        if (lastI < format.length())
+            answer.append(format.substring(lastI, format.length()));
+        return answer.toString();
+    }
+
+    /**
+     * Changes the locale of the messages.
+     * 
+     * @param locale
+     *            Locale the locale to change to.
+     */
+    static public ResourceBundle setLocale(final Locale locale,
+            final String resource) {
+        try {
+            final ClassLoader loader = VM.bootCallerClassLoader();
+            return (ResourceBundle) AccessController
+                    .doPrivileged(new PrivilegedAction<Object>() {
+                        public Object run() {
+                            return ResourceBundle.getBundle(resource, locale,
+                                    loader != null ? loader : ClassLoader.getSystemClassLoader());
+                        }
+                    });
+        } catch (MissingResourceException e) {
+        }
+        return null;
+    }
+
+    static {
+        // Attempt to load the messages.
+        try {
+            bundle = setLocale(Locale.getDefault(),
+                    "org.apache.harmony.x.imageio.internal.nls.messages"); //$NON-NLS-1$
+        } catch (Throwable e) {
+            e.printStackTrace();
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/Messages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties Thu Mar 15 04:37:16 2007
@@ -0,0 +1,18 @@
+# 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.
+# 
+
+# messages for EN locale
+imageio.1=Wrong bitDepth-numBands composition
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java Thu Mar 15 04:37:16 2007
@@ -0,0 +1,213 @@
+/*
+ *  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.
+ */
+/**
+ * @author Viskov Nikolay
+ * @version $Revision$
+ */
+package org.apache.harmony.x.imageio.plugins.png;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBufferByte;
+import java.awt.image.IndexColorModel;
+import java.awt.image.Raster;
+import java.awt.image.RenderedImage;
+import java.awt.image.WritableRaster;
+import java.io.IOException;
+
+import javax.imageio.IIOImage;
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.ImageWriter;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.spi.ImageWriterSpi;
+import javax.imageio.stream.ImageOutputStream;
+
+import org.apache.harmony.x.imageio.internal.nls.Messages;
+
+import org.apache.harmony.luni.util.NotImplementedException;
+
+public class PNGImageWriter extends ImageWriter {
+    private static int[][] BAND_OFFSETS = {
+            {}, {
+                0 }, {
+                    0, 1 }, {
+                    0, 1, 2 }, {
+                    0, 1, 2, 3 } };
+
+    // Each pixel is a grayscale sample.
+    private static final int PNG_COLOR_TYPE_GRAY = 0;
+    // Each pixel is an R,G,B triple.
+    private static final int PNG_COLOR_TYPE_RGB = 2;
+    // Each pixel is a palette index, a PLTE chunk must appear.
+    private static final int PNG_COLOR_TYPE_PLTE = 3;
+    // Each pixel is a grayscale sample, followed by an alpha sample.
+    private static final int PNG_COLOR_TYPE_GRAY_ALPHA = 4;
+    // Each pixel is an R,G,B triple, followed by an alpha sample.
+    private static final int PNG_COLOR_TYPE_RGBA = 6;
+
+    private static native void initIDs(Class<ImageOutputStream> iosClass);
+
+    static {
+        System.loadLibrary("pngencoder"); //$NON-NLS-1$
+        initIDs(ImageOutputStream.class);
+    }
+
+    private native int encode(byte[] input, int bytesInBuffer, int bytePixelSize, Object ios, int imageWidth,
+            int imageHeight, int bitDepth, int colorType, int[] palette, int i, boolean b);
+
+    protected PNGImageWriter(ImageWriterSpi iwSpi) {
+        super(iwSpi);
+    }
+
+    @Override
+    public IIOMetadata convertStreamMetadata(IIOMetadata arg0, ImageWriteParam arg1) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public IIOMetadata convertImageMetadata(IIOMetadata arg0, ImageTypeSpecifier arg1, ImageWriteParam arg2) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier arg0, ImageWriteParam arg1) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public IIOMetadata getDefaultStreamMetadata(ImageWriteParam arg0) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public void write(IIOMetadata streamMetadata, IIOImage iioimage, ImageWriteParam param) throws IOException {
+        if (output == null) {
+            throw new IllegalStateException("Output not been set");
+        }
+        if (iioimage == null) {
+            throw new IllegalArgumentException("Image equals null");
+        }
+        if (iioimage.hasRaster() && !canWriteRasters()) {
+            throw new UnsupportedOperationException("Can't write raster");
+        }// ImageOutputStreamImpl
+
+        int imageWidth, imageHeight;
+        int colorType = PNG_COLOR_TYPE_GRAY;
+        int bitDepth;
+        int numBands;
+
+        DataBufferByte dbuffer;
+
+        int[] palette = null;
+
+        boolean isInterlace = true;
+
+        RenderedImage image = iioimage.getRenderedImage();
+
+        imageWidth = image.getWidth();
+        imageHeight = image.getHeight();
+
+        numBands = image.getSampleModel().getNumBands();
+
+        ColorModel colorModel = image.getColorModel();
+
+        int pixelSize = colorModel.getPixelSize();
+
+        int bytePixelSize = pixelSize / 8;
+
+        bitDepth = pixelSize / numBands;
+
+        // byte per band
+        int bpb = bitDepth > 8 ? 2 : 1;
+
+        if (colorModel instanceof IndexColorModel) {
+            if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8) {
+//              Wrong bitDepth-numBands composition
+                throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
+            }
+            if (numBands != 1) {
+//              Wrong bitDepth-numBands composition
+                throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
+            }
+
+            IndexColorModel icm = (IndexColorModel) colorModel;
+
+            palette = new int[icm.getMapSize()];
+
+            icm.getRGBs(palette);
+
+            colorType = PNG_COLOR_TYPE_PLTE;
+
+        }
+        else if (numBands == 1) {
+            if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8 && bitDepth != 16) {
+//              Wrong bitDepth-numBands composition
+                throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
+            }
+            colorType = PNG_COLOR_TYPE_GRAY;
+        }
+        else if (numBands == 2) {
+            if (bitDepth != 8 && bitDepth != 16) {
+//              Wrong bitDepth-numBands composition
+                throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
+            }
+            colorType = PNG_COLOR_TYPE_GRAY_ALPHA;
+        }
+        else if (numBands == 3) {
+            if (bitDepth != 8 && bitDepth != 16) {
+//              Wrong bitDepth-numBands composition
+                throw new IllegalArgumentException(Messages.getString("imageio.1")); //$NON-NLS-1$
+            }
+            colorType = PNG_COLOR_TYPE_RGB;
+        }
+        else if (numBands == 4) {
+            if (bitDepth != 8 && bitDepth != 16) {
+                //Wrong bitDepth-numBands composition
+                throw new IllegalArgumentException(Messages.getString("imageio.1")); //$NON-NLS-1$
+            }
+            colorType = PNG_COLOR_TYPE_RGBA;
+        }
+
+        int dbufferLenght = bytePixelSize * imageHeight * imageWidth;
+
+        dbuffer = new DataBufferByte(dbufferLenght);
+
+        WritableRaster scanRaster = Raster.createInterleavedRaster(dbuffer, imageWidth, imageHeight, bpb * numBands
+                * imageWidth, bpb * numBands, BAND_OFFSETS[numBands], null);
+
+        scanRaster.setRect(((BufferedImage) image).getRaster()// image.getData()
+                .createChild(0, 0, imageWidth, imageHeight, 0, 0, null));
+
+        if (param instanceof PNGImageWriterParam) {
+            isInterlace = ((PNGImageWriterParam) param).getInterlace();
+        }
+
+        try {
+            encode(dbuffer.getData(), dbufferLenght, bytePixelSize, (ImageOutputStream) getOutput(), imageWidth,
+                    imageHeight, bitDepth, colorType, palette, palette == null ? 0 : palette.length, isInterlace);
+
+        }
+        catch (RuntimeException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public ImageWriteParam getDefaultWriteParam() {
+        return new PNGImageWriterParam();
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterParam.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterParam.java?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterParam.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterParam.java Thu Mar 15 04:37:16 2007
@@ -0,0 +1,41 @@
+/*
+ *  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.
+ */
+/**
+ * @author Viskov Nikolay
+ * @version $Revision$
+ */
+package org.apache.harmony.x.imageio.plugins.png;
+
+import javax.imageio.ImageWriteParam;
+
+public class PNGImageWriterParam extends ImageWriteParam {
+
+    private boolean isInterlace = true;
+
+    public PNGImageWriterParam() {
+        super();
+    }
+
+    public boolean getInterlace() {
+        return isInterlace;
+    }
+
+    public void setInterlace(boolean b) {
+        isInterlace = b;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterParam.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java Thu Mar 15 04:37:16 2007
@@ -0,0 +1,113 @@
+/*
+ *  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.
+ */
+/**
+ * @author Viskov Nikolay
+ * @version $Revision$
+ */
+package org.apache.harmony.x.imageio.plugins.png;
+
+import java.awt.image.ColorModel;
+import java.awt.image.DataBufferByte;
+import java.awt.image.IndexColorModel;
+import java.io.IOException;
+import java.util.Locale;
+
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.ImageWriter;
+import javax.imageio.spi.ImageWriterSpi;
+
+public class PNGImageWriterSpi extends ImageWriterSpi {
+
+    public PNGImageWriterSpi() {
+        super("Intel Corporation",// vendorName
+                "1.0",// version
+                new String[] {
+                        "png", "PNG" },// names
+                new String[] {
+                        "png", "PNG" },// suffixes
+                new String[] {
+                    "image/png" },// MIMETypes
+                "org.apache.harmony.x.imageio.plugins.png.PNGImageWriter",// writerClassName
+                STANDARD_OUTPUT_TYPE,// outputTypes
+                new String[] {
+                    "org.apache.harmony.x.imageio.plugins.png.PNGImageWriterSpi" },// readerSpiNames
+                false,// supportsStandardStreamMetadataFormat
+                null,// nativeStreamMetadataFormatName
+                null,// nativeStreamMetadataFormatClassName
+                null,// extraStreamMetadataFormatNames
+                null,// extraStreamMetadataFormatClassNames
+                false,// supportsStandardImageMetadataFormat
+                null,// nativeImageMetadataFormatName
+                null,// nativeImageMetadataFormatClassName
+                null,// extraImageMetadataFormatNames
+                null// extraImageMetadataFormatClassNames
+        );
+    }
+
+    @Override
+    public boolean canEncodeImage(ImageTypeSpecifier type) {
+        boolean canEncode = true;
+
+        int numBands = type.getSampleModel().getNumBands();
+
+        ColorModel colorModel = type.getColorModel();
+
+        int bitDepth = colorModel.getPixelSize() / numBands;
+
+        if (colorModel instanceof IndexColorModel) {
+            if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8) {
+                canEncode = false;
+            }
+            if (numBands != 1) {
+                canEncode = false;
+            }
+        }
+        else if (numBands == 1) {
+            if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8 && bitDepth != 16) {
+                canEncode = false;
+            }
+        }
+        else if (numBands == 2) {
+            if (bitDepth != 8 && bitDepth != 16) {
+                canEncode = false;
+            }
+        }
+        else if (numBands == 3) {
+            if (bitDepth != 8 && bitDepth != 16) {
+                canEncode = false;
+            }
+        }
+        else if (numBands == 4) {
+            if (bitDepth != 8 && bitDepth != 16) {
+                canEncode = false;
+            }
+        }
+
+        return canEncode;
+    }
+
+    @Override
+    public ImageWriter createWriterInstance(Object arg0) throws IOException {
+        return new PNGImageWriter(this);
+    }
+
+    @Override
+    public String getDescription(Locale arg0) {
+        return "DRL PNG encoder";
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriterSpi.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h Thu Mar 15 04:37:16 2007
@@ -0,0 +1,79 @@
+/*
+ *  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.
+ */
+/**
+ * @author Viskov Nikolay
+ * @version $Revision$
+ */
+/*
+ * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL.
+ * Please be aware that all changes made to this file manually
+ * will be overwritten by the tool if it runs again.
+ */
+
+#include <jni.h>
+
+
+/* Header for class org.apache.harmony.awt.gl.image.PngDecoder */
+
+#ifndef _org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_H
+#define _org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Static final fields */
+
+#undef org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_GRAY
+#define org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_GRAY 0L
+
+#undef org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_RGB
+#define org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_RGB 2L
+
+#undef org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_PLTE
+#define org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_PLTE 3L
+
+#undef org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_GRAY_ALPHA
+#define org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_GRAY_ALPHA 4L
+
+#undef org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_RGBA
+#define org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_PNG_COLOR_TYPE_RGBA 6L
+
+
+/* Native methods */
+
+/*
+ * Method: org.apache.harmony.awt.gl.image.PngDecoder.decode([BILjava/lang/Object;IIII[IIZ)I
+ */
+JNIEXPORT jint JNICALL
+Java_org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_encode(JNIEnv *, jobject, 
+            jbyteArray, jint, jint, jobject, jint, jint, jint, jint, jintArray, jint, jboolean);
+
+/*
+ * Method: org.apache.harmony.awt.gl.image.PngDecoder.initIDs()V
+ */
+JNIEXPORT void JNICALL
+Java_org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_initIDs(JNIEnv *, jclass, jclass);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_H */
+

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/pngencoder.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/pngencoder.h?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/pngencoder.h (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/pngencoder.h Thu Mar 15 04:37:16 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.
+ */
+ /**
+  * @author Viskov Nikolay
+  * @version $Revision$
+  *
+  */
+
+#ifndef _Included_PNGEncoder
+#define _Included_PNGEncoder
+
+#include <stdlib.h> // Strange because it's already included in pngconf.h, but it's needed
+//#include <setjmp.h>
+
+#include "png.h"
+#include "org_apache_harmony_x_imageio_plugins_png_PNGImageWriter.h"
+#include "exceptions.h"
+
+// Define "boolean" as int if not defined 
+#ifndef __RPCNDR_H__    // don't redefine if rpcndr.h already defined it 
+typedef int boolean;
+#endif
+#ifndef FALSE     
+#define FALSE 0   
+#endif
+#ifndef TRUE
+#define TRUE  1
+#endif
+
+#define IO_BUFFER_SIZE 8192L
+
+// Field ids
+jmethodID img_IOSwriteID;
+
+typedef struct png_encoder_info_tag {
+  png_structp png_ptr;
+  png_infop info_ptr;
+  unsigned char *inputBuffer;
+
+  png_bytepp tmpBuffer;
+
+  jobject ios;
+
+  //iobuffer vars
+  unsigned char ioBuffer[IO_BUFFER_SIZE];
+  size_t freeBytesInIOBuffer;
+
+  // palette  
+  //png_color_8_struct *png_palette;
+  jintArray jPalette;
+
+  // JNI-related vars
+  JNIEnv *env;
+  jobject obj;
+  jbyteArray jInputData;
+
+  // Nonlocal goto - only way to deal with errors in libpng...
+  jmp_buf jmpBuf;
+} png_encoder_info;
+
+typedef png_encoder_info* png_encoder_info_ptr;
+
+png_encoder_info_ptr initPng();
+void destroyPng(png_encoder_info_ptr *decoderInfo);
+void gl_flush_data(png_structp png_ptr);
+
+#endif //_Included_PNGEncoder

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/include/pngencoder.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/pngencoder.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/pngencoder.c?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/pngencoder.c (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/pngencoder.c Thu Mar 15 04:37:16 2007
@@ -0,0 +1,274 @@
+/*
+ *  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.
+ */
+ /**
+  * @author Viskov Nikolay
+  * @version $Revision$
+  *
+  */
+
+#include "pngencoder.h"
+#include <stdio.h>
+
+/*
+ * Class:     org_apache_harmony_awt_gl_image_PngEncoder
+ * Method:    initIDs
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_initIDs
+(JNIEnv *env, jclass cls, jclass iosClass) {
+      //-- ImageOutputStream.write(byte[], int, int)
+  img_IOSwriteID = (*env)->GetMethodID(env, iosClass, "write", "([BII)V");
+}
+
+void gl_write_data(png_structp png_ptr, png_bytep data, png_size_t length) {
+  png_encoder_info_ptr encoderInfo = png_get_io_ptr(png_ptr);
+  
+  jbyteArray java_buffer;
+  unsigned char *native_buffer;
+
+  JNIEnv *env = encoderInfo->env;
+
+  png_size_t bufferLength = IO_BUFFER_SIZE - encoderInfo->freeBytesInIOBuffer;
+
+  //printf("%u", length);
+
+  if (encoderInfo->freeBytesInIOBuffer < length) {
+      if (IO_BUFFER_SIZE < length) {          
+          java_buffer = (*env)->NewByteArray(env, (jsize) (length + bufferLength));
+          native_buffer = (unsigned char *)(*env)->GetPrimitiveArrayCritical(env, java_buffer, NULL);
+
+          memcpy(native_buffer, encoderInfo->ioBuffer, bufferLength);
+          memcpy(native_buffer + bufferLength, data, length);
+
+          (*env)->ReleasePrimitiveArrayCritical(env, java_buffer, native_buffer, 0);
+          
+          (*env)->CallVoidMethod(env, encoderInfo->ios, img_IOSwriteID, java_buffer, 0, length + bufferLength);
+
+          encoderInfo->freeBytesInIOBuffer = IO_BUFFER_SIZE;
+      } else {
+          gl_flush_data(encoderInfo->png_ptr);
+          memcpy(encoderInfo->ioBuffer, data, length);
+          encoderInfo->freeBytesInIOBuffer -= length;
+      }
+  } else {
+      memcpy(encoderInfo->ioBuffer + bufferLength, data, length);
+      encoderInfo->freeBytesInIOBuffer -= length;
+  }
+  //printf("passed\n");
+}
+
+void gl_flush_data(png_structp png_ptr) {
+  png_encoder_info_ptr encoderInfo = png_get_io_ptr(png_ptr);
+  
+  jbyteArray java_buffer;
+  unsigned char *native_buffer;
+
+  png_size_t bufferLength = IO_BUFFER_SIZE - encoderInfo->freeBytesInIOBuffer;
+
+  JNIEnv *env = encoderInfo->env;
+
+  //printf("flush ");
+
+  java_buffer = (*env)->NewByteArray(env, (jsize) bufferLength);
+  native_buffer = (unsigned char *)(*env)->GetPrimitiveArrayCritical(env, java_buffer, NULL);
+  memcpy(native_buffer, encoderInfo->ioBuffer, bufferLength);
+  (*env)->ReleasePrimitiveArrayCritical(env, java_buffer, native_buffer, 0);
+  
+  (*env)->CallVoidMethod(env, encoderInfo->ios, img_IOSwriteID, java_buffer, 0, bufferLength);
+
+  encoderInfo->freeBytesInIOBuffer = IO_BUFFER_SIZE;
+
+  //printf("passed\n");
+}
+
+/*
+ * Class:     org_apache_harmony_awt_gl_image_PngEncoder
+ * Method:    decode
+ * Signature: ([BILjava/lang/Object;IIII[IIZ)I
+ */
+JNIEXPORT jint JNICALL 
+Java_org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_encode
+(JNIEnv *env, 
+ jobject obj, 
+ jbyteArray jInput, 
+ jint bytesInBuffer, 
+ jint bytePixelSize,
+ jobject iosObj, 
+ jint imageWidth, 
+ jint imageHeight, 
+ jint bitDipth, 
+ jint colorType, 
+ jintArray palette, 
+ jint paletteSize, 
+ jboolean isInterlace) {
+
+
+
+  png_encoder_info_ptr encoderInfo;
+  int i;
+
+  if(!(encoderInfo = initPng())) {
+    throwNewExceptionByName(env, "java/lang/RuntimeException",
+                            "Can't create native PNG encoder");
+    return 2; // NULL
+  }
+  
+  if(setjmp(encoderInfo->jmpBuf)) { // Only way to deal with errors in libpng
+    destroyPng(&encoderInfo);
+    return 2;
+  }
+
+  png_set_write_fn(
+      encoderInfo->png_ptr,
+      encoderInfo, 
+      gl_write_data,
+      gl_flush_data
+      );
+
+  encoderInfo->ios = iosObj;
+
+  // Update JNI-related fields
+  encoderInfo->env = env;
+  encoderInfo->obj = obj;   
+
+  encoderInfo->jInputData = jInput;
+  encoderInfo->jPalette = palette;
+
+  png_set_IHDR(encoderInfo->png_ptr, encoderInfo->info_ptr, imageWidth, imageHeight,
+      bitDipth, colorType, isInterlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,
+       PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+
+  if (colorType == PNG_COLOR_TYPE_PALETTE) {
+      jint *tmpPalette = (jint *) (*env)->GetPrimitiveArrayCritical(env, palette, 0);   
+
+      png_colorp pngPalette = (png_colorp) malloc(paletteSize * sizeof(png_color));
+
+      //png_bytep alpha = (png_bytep) malloc(paletteSize * sizeof(png_byte)); 
+
+      for (i = 0;  i < paletteSize;  i ++) {          
+          //printf("n%u = %u\n", i, (tmpPalette[i] & 0xff000000));
+          (pngPalette + i)->red = (png_byte) tmpPalette[i] & 0x00ff0000;
+          (pngPalette + i)->green = (png_byte) tmpPalette[i] & 0x000000ff00;
+          (pngPalette + i)->blue = (png_byte) tmpPalette[i] & 0x000000ff;
+
+          //alpha[i] = 256 - (tmpPalette[i] & 0xff000000);
+      }
+
+      png_set_PLTE(encoderInfo->png_ptr, encoderInfo->info_ptr, pngPalette, paletteSize);      
+
+      //png_set_tRNS(encoderInfo->png_ptr, encoderInfo->info_ptr, alpha, paletteSize, NULL);
+
+      //free(alpha);
+      free(pngPalette);
+      (*env)->ReleasePrimitiveArrayCritical(env, palette, tmpPalette, 0); 
+  }  
+
+  encoderInfo->inputBuffer = (*env)->GetPrimitiveArrayCritical(env, jInput, 0);    
+
+  encoderInfo->tmpBuffer = (png_bytepp) malloc(imageHeight * sizeof(png_bytep));
+
+  for (i = 0;  i < imageHeight;  i ++) {
+      encoderInfo->tmpBuffer[i] = encoderInfo->inputBuffer + (i * (imageWidth * bytePixelSize));
+  }
+
+  png_set_rows(encoderInfo->png_ptr, encoderInfo->info_ptr, encoderInfo->tmpBuffer);
+  png_write_png(encoderInfo->png_ptr, encoderInfo->info_ptr, PNG_TRANSFORM_IDENTITY, NULL);  
+
+  free(encoderInfo->tmpBuffer);
+  encoderInfo->tmpBuffer = NULL;
+
+  (*env)->ReleasePrimitiveArrayCritical(env, jInput, encoderInfo->inputBuffer, 0);    
+  encoderInfo->inputBuffer = NULL;
+  
+  png_write_end(encoderInfo->png_ptr, encoderInfo->info_ptr);
+
+  png_write_flush(encoderInfo->png_ptr);
+
+  destroyPng(&encoderInfo);
+  
+  return 0;
+}
+
+void gl_error_fn(png_structp png_ptr, png_const_charp error_msg) {
+  png_encoder_info_ptr encoderInfo = png_get_error_ptr(png_ptr);
+  throwNewExceptionByName(encoderInfo->env, "java/lang/RuntimeException",
+                          error_msg);
+  
+  if(encoderInfo) { // Else there's no way to terminate correctly
+    longjmp(encoderInfo->jmpBuf, 1);
+  }
+}
+
+void gl_warning_fn(png_structp png_ptr, png_const_charp warning_msg) {
+}
+
+void destroyPng(png_encoder_info_ptr *encoderInfoP) {
+  png_encoder_info_ptr encoderInfo = *encoderInfoP;
+
+  JNIEnv *env = encoderInfo->env;
+
+  //printf("now = %u\n",(encoderInfo->inputBuffer));
+
+  // Release arrays
+  if(encoderInfo->jInputData && encoderInfo->inputBuffer) {
+    (*env)->ReleasePrimitiveArrayCritical(
+      env, encoderInfo->jInputData, encoderInfo->inputBuffer, 0
+    );
+    encoderInfo->inputBuffer = NULL;
+  }
+
+  if (encoderInfo->tmpBuffer) {
+      free(encoderInfo->tmpBuffer);
+  }
+  encoderInfo->tmpBuffer = NULL;
+
+  if(encoderInfo->png_ptr && encoderInfo->info_ptr)      
+    png_destroy_write_struct(&encoderInfo->png_ptr, &encoderInfo->info_ptr);
+
+  free(encoderInfo);
+  encoderInfo = NULL;
+}
+
+png_encoder_info_ptr initPng() {
+  png_encoder_info_ptr encoderInfo = calloc(sizeof(png_encoder_info), 1);
+  if(!encoderInfo) {
+    return NULL;
+  }  
+
+  encoderInfo->png_ptr = png_create_write_struct(
+    PNG_LIBPNG_VER_STRING,
+    encoderInfo, 
+    gl_error_fn, 
+    gl_warning_fn
+  );
+    
+  if(!encoderInfo->png_ptr) {
+    return NULL;
+  }
+
+  encoderInfo->info_ptr = png_create_info_struct(encoderInfo->png_ptr);
+
+  if (!encoderInfo->info_ptr) {
+    png_destroy_write_struct(&encoderInfo->png_ptr, png_infopp_NULL);
+    return NULL;
+  }
+
+  encoderInfo->freeBytesInIOBuffer = IO_BUFFER_SIZE;
+
+  return encoderInfo;
+}
+

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/shared/pngencoder.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/exports.txt?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/exports.txt (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/exports.txt Thu Mar 15 04:37:16 2007
@@ -0,0 +1,2 @@
+Java_org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_encode
+Java_org_apache_harmony_x_imageio_plugins_png_PNGImageWriter_initIDs
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/exports.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/makefile?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/makefile (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/unix/makefile Thu Mar 15 04:37:16 2007
@@ -0,0 +1,41 @@
+# 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.
+
+include $(HY_HDK)/build/make/defines.mk
+
+PNG_DIR=$(HY_HDK)/../depends/libs/build/png/
+
+CFLAGS += -fpic
+INCLUDES += -I$(SHARED)common -I$(SHAREDSUB)include -I$(PNG_DIR)
+
+BUILDFILES = \
+  $(SHAREDSUB)pngencoder.o \
+  libpng.a
+
+MDLLIBFILES += \
+	$(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so \
+	$(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
+
+OSLIBS += $(STDCLIBS)
+
+DLLNAME=../libpngencoder.so
+EXPNAME=HYPNGENCODER_0.1
+
+CLEANFILES=jconfig.h
+
+include $(HY_HDK)/build/make/rules.mk
+
+libpng.a: $(PNG_DIR)libpng.$(HY_PLATFORM)
+	cp $< $@

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/makefile?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/makefile (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/makefile Thu Mar 15 04:37:16 2007
@@ -0,0 +1,40 @@
+# 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.
+
+!include <$(HY_HDK)\build\make\defines.mak>
+
+PNG_DIR=$(HY_HDK)\..\depends\libs\build\png\# avoid continuation
+
+LIBBASE=pngencoder
+DLLNAME=..\$(LIBBASE).dll
+LIBNAME=$(LIBPATH)$(LIBBASE).lib
+HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def
+
+HYCFLAGS = $(HYCFLAGS) /I$(SHAREDSUB)include /I$(SHAREDSUB) \
+           /I$(PNG_DIR) /Iinclude
+
+BUILDFILES = $(SHAREDSUB)pngencoder.obj
+
+VIRTFILES = $(LIBBASE).res
+SYSLIBFILES = ws2_32.lib Iphlpapi.lib
+
+MDLLIBFILES = $(MDLLIBFILES) \
+  $(LIBPATH)hypool.lib $(LIBPATH)vmi.lib \
+  $(LIBPATH)hyzlib.lib $(PNG_DIR)libpng.lib
+
+DLLBASE=0x13300000
+COMMENT=/comment:"PNGENCODER native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
+
+!include <$(HY_HDK)\build\make\rules.mak>

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.def
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.def?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.def (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.def Thu Mar 15 04:37:16 2007
@@ -0,0 +1,7 @@
+LIBRARY	PNGENCODER
+
+SECTIONS
+	.data	READ WRITE
+	.text	EXECUTE READ
+
+EXPORTS

Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.rc
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.rc?view=auto&rev=518588
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.rc (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/native/pngencoder/windows/pngencoder.rc Thu Mar 15 04:37:16 2007
@@ -0,0 +1,48 @@
+;
+; 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.
+;
+
+#include <windows.h>
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 0,1,0,0
+ PRODUCTVERSION 0,1,0,0
+ FILEFLAGSMASK 0x3fL
+ FILEFLAGS 0x0L
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+BEGIN
+	BLOCK "StringFileInfo"
+	BEGIN
+		BLOCK "040904b0"
+		BEGIN
+			VALUE "CompanyName", "The Apache Software Foundation.\0"
+			VALUE "FileDescription", "PNG encoder native code\0"
+			VALUE "FileVersion", "0.1\0"
+			VALUE "InternalName", "pngencoder\0"
+			VALUE "LegalCopyright", "(c) Copyright 2007 The Apache Software Foundation or its licensors, as applicable.\0"
+			VALUE "OriginalFilename", "pngencoder.dll\0"
+			VALUE "ProductName", "Apache Harmony\0"
+			VALUE "ProductVersion", "0.1\0"
+		END
+	END
+	BLOCK "VarFileInfo"
+	BEGIN
+		VALUE "Translation", 0x0409, 1200
+	END
+END



Mime
View raw message