You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ca...@apache.org on 2007/01/16 01:59:50 UTC

svn commit: r496556 [1/5] - in /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics: image/ image/codec/png/ image/codec/tiff/ image/codec/util/ image/rendered/ image/writer/ image/writer/internal/ java2d/ util/ util/i18n/ util/io/

Author: cam
Date: Mon Jan 15 16:59:48 2007
New Revision: 496556

URL: http://svn.apache.org/viewvc?view=rev&rev=496556
Log:
Ported r389774:496552 from Batik trunk, in preparation for classes to be
moved out of Batik.

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGEncodeParam.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDecodeParam.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFEncodeParam.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFFaxDecoder.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImage.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoder.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFLZWDecoder.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/ForwardSeekableStream.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/ImageEncoder.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/MemoryCacheSeekableStream.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/PropertyUtil.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/SeekableOutputStream.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/SeekableStream.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/SimpleRenderedImage.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/util/SingleTileRenderedImage.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/rendered/AbstractRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/rendered/Any2sRGBRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/rendered/BufferedImageCachableRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/rendered/CachableRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/rendered/FormatRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/rendered/RenderedImageCachableRed.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriter.java   (contents, props changed)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterParams.java   (contents, props changed)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java   (contents, props changed)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/JPEGImageWriter.java   (contents, props changed)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/internal/PNGImageWriter.java   (contents, props changed)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicContext.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/TransformStackElement.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/Service.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/i18n/LocaleGroup.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/io/Base64DecodeStream.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java Mon Jan 15 16:59:48 2007
@@ -57,7 +57,7 @@
 
     /**
      * Standard prebuilt Linear_sRGB color model with no alpha */
-    public final static ColorModel Linear_sRGB =
+    public static final ColorModel Linear_sRGB =
         new DirectColorModel(ColorSpace.getInstance
                              (ColorSpace.CS_LINEAR_RGB), 24,
                              0x00FF0000, 0x0000FF00,
@@ -66,7 +66,7 @@
     /**
      * Standard prebuilt Linear_sRGB color model with premultiplied alpha.
      */
-    public final static ColorModel Linear_sRGB_Pre =
+    public static final ColorModel Linear_sRGB_Pre =
         new DirectColorModel(ColorSpace.getInstance
                              (ColorSpace.CS_LINEAR_RGB), 32,
                              0x00FF0000, 0x0000FF00,
@@ -75,7 +75,7 @@
     /**
      * Standard prebuilt Linear_sRGB color model with unpremultiplied alpha.
      */
-    public final static ColorModel Linear_sRGB_Unpre =
+    public static final ColorModel Linear_sRGB_Unpre =
         new DirectColorModel(ColorSpace.getInstance
                              (ColorSpace.CS_LINEAR_RGB), 32,
                              0x00FF0000, 0x0000FF00,
@@ -85,7 +85,7 @@
     /**
      * Standard prebuilt sRGB color model with no alpha.
      */
-    public final static ColorModel sRGB =
+    public static final ColorModel sRGB =
         new DirectColorModel(ColorSpace.getInstance
                              (ColorSpace.CS_sRGB), 24,
                              0x00FF0000, 0x0000FF00,
@@ -94,7 +94,7 @@
     /**
      * Standard prebuilt sRGB color model with premultiplied alpha.
      */
-    public final static ColorModel sRGB_Pre =
+    public static final ColorModel sRGB_Pre =
         new DirectColorModel(ColorSpace.getInstance
                              (ColorSpace.CS_sRGB), 32,
                              0x00FF0000, 0x0000FF00,
@@ -103,7 +103,7 @@
     /**
      * Standard prebuilt sRGB color model with unpremultiplied alpha.
      */
-    public final static ColorModel sRGB_Unpre =
+    public static final ColorModel sRGB_Unpre =
         new DirectColorModel(ColorSpace.getInstance
                              (ColorSpace.CS_sRGB), 32,
                              0x00FF0000, 0x0000FF00,
@@ -118,10 +118,9 @@
      *                the alpha channel set in accordance with
      *                <tt>premult</tt>
      */
-    public static ColorModel makeLinear_sRGBCM(boolean premult) {
-        if (premult)
-            return Linear_sRGB_Pre;
-        return Linear_sRGB_Unpre;
+    public static ColorModel makeLinear_sRGBCM( boolean premult ) {
+
+         return premult ? Linear_sRGB_Pre : Linear_sRGB_Unpre;
     }
 
     /**
@@ -485,7 +484,7 @@
 
         // System.out.println("CoerceData: " + cm.isAlphaPremultiplied() +
         //                    " Out: " + newAlphaPreMult);
-        if (cm.hasAlpha()== false)
+        if ( ! cm.hasAlpha() )
             // Nothing to do no alpha channel
             return cm;
 
@@ -532,7 +531,7 @@
                 }
         }
     }
-    
+
     public static void divideAlpha(WritableRaster wr) {
         if (is_BYTE_COMP_Data(wr.getSampleModel()))
             divide_BYTE_COMP_Data(wr);
@@ -543,7 +542,7 @@
             float ialpha;
             int    bands = wr.getNumBands();
             int [] pixel = null;
-        
+
             x0 = wr.getMinX();
             x1 = x0+wr.getWidth();
             y0 = wr.getMinY();
@@ -606,7 +605,7 @@
         //                    " is: " + dst.isAlphaPremultiplied());
 
         if (srcAlpha == dstAlpha)
-            if ((srcAlpha == false) ||
+            if (( ! srcAlpha ) ||
                 (src.isAlphaPremultiplied() == dst.isAlphaPremultiplied())) {
                 // They match one another so just copy everything...
                 copyData(src.getRaster(), dst.getRaster());
@@ -858,20 +857,19 @@
             = (db.getOffset() +
                sppsm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
                                wr.getMinY()-wr.getSampleModelTranslateY()));
-        int pixel, a, aFP;
+
         // Access the pixel data array
-        final int pixels[] = db.getBankData()[0];
+        final int[] pixels = db.getBankData()[0];
         for (int y=0; y<wr.getHeight(); y++) {
             int sp = base + y*scanStride;
             final int end = sp + width;
             while (sp < end) {
-                pixel = pixels[sp];
-                a = pixel>>>24;
+                int pixel = pixels[sp];
+                int a = pixel>>>24;
                 if (a<=0) {
                     pixels[sp] = 0x00FFFFFF;
-                }
-                else if (a<255) {
-                    aFP = (0x00FF0000/a);
+                } else if (a<255) {
+                    int aFP = (0x00FF0000/a);
                     pixels[sp] =
                         ((a << 24) |
                          (((((pixel&0xFF0000)>>16)*aFP)&0xFF0000)    ) |
@@ -898,14 +896,14 @@
                sppsm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
                                wr.getMinY()-wr.getSampleModelTranslateY()));
         // Access the pixel data array
-        final int pixels[] = db.getBankData()[0];
+        final int[] pixels = db.getBankData()[0];
         for (int y=0; y<wr.getHeight(); y++) {
             int sp = base + y*scanStride;
             final int end = sp + width;
             while (sp < end) {
                 int pixel = pixels[sp];
                 int a = pixel>>>24;
-                if ((a>=0) && (a<255)) {
+                if ((a>=0) && (a<255)) {   // this does NOT include a == 255 (0xff) !
                     pixels[sp] = ((a << 24) |
                                   ((((pixel&0xFF0000)*a)>>8)&0xFF0000) |
                                   ((((pixel&0x00FF00)*a)>>8)&0x00FF00) |
@@ -935,25 +933,23 @@
                csm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
                              wr.getMinY()-wr.getSampleModelTranslateY()));
 
-
-        int a=0;
         int aOff = bandOff[bandOff.length-1];
         int bands = bandOff.length-1;
-        int b, i;
+
         // Access the pixel data array
-        final byte pixels[] = db.getBankData()[0];
+        final byte[] pixels = db.getBankData()[0];
         for (int y=0; y<wr.getHeight(); y++) {
             int sp = base + y*scanStride;
             final int end = sp + width*pixStride;
             while (sp < end) {
-              a = pixels[sp+aOff]&0xFF;
+              int a = pixels[sp+aOff]&0xFF;
               if (a==0) {
-                for (b=0; b<bands; b++)
+                for ( int b=0; b<bands; b++)
                   pixels[sp+bandOff[b]] = (byte)0xFF;
-              } else if (a<255) {
+              } else if (a<255) {         // this does NOT include a == 255 (0xff) !
                 int aFP = (0x00FF0000/a);
-                for (b=0; b<bands; b++) {
-                  i = sp+bandOff[b];
+                for ( int b=0; b<bands; b++) {
+                  int i = sp+bandOff[b];
                   pixels[i] = (byte)(((pixels[i]&0xFF)*aFP)>>>16);
                 }
               }
@@ -981,21 +977,19 @@
                              wr.getMinY()-wr.getSampleModelTranslateY()));
 
 
-        int a=0;
         int aOff = bandOff[bandOff.length-1];
         int bands = bandOff.length-1;
-        int b, i;
 
         // Access the pixel data array
-        final byte pixels[] = db.getBankData()[0];
+        final byte[] pixels = db.getBankData()[0];
         for (int y=0; y<wr.getHeight(); y++) {
             int sp = base + y*scanStride;
             final int end = sp + width*pixStride;
             while (sp < end) {
-              a = pixels[sp+aOff]&0xFF;
+              int a = pixels[sp+aOff]&0xFF;
               if (a!=0xFF)
-                for (b=0; b<bands; b++) {
-                  i = sp+bandOff[b];
+                for ( int b=0; b<bands; b++) {
+                  int i = sp+bandOff[b];
                   pixels[i] = (byte)(((pixels[i]&0xFF)*a)>>8);
                 }
               sp+=pixStride;
@@ -1013,7 +1007,7 @@
                 org.ImageDisplay.printImage
                     (label, subBI,
                      new Rectangle(75-iR.x, 90-iR.y, 32, 32));
-                
+
             }
 
 
@@ -1045,7 +1039,7 @@
                     System.out.println("BICM class: " + ri.getColorModel().getClass());
                     System.out.println("BICS: " + ri.getColorModel().getColorSpace());
                     System.out.println
-                        ("sRGB CS: " + 
+                        ("sRGB CS: " +
                          ColorSpace.getInstance(ColorSpace.CS_sRGB));
                     System.out.println("G2D info");
                     System.out.println("\tComposite: " + g2d.getComposite());

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGEncodeParam.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGEncodeParam.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGEncodeParam.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGEncodeParam.java Mon Jan 15 16:59:48 2007
@@ -27,7 +27,8 @@
 import java.awt.image.RenderedImage;
 import java.awt.image.SampleModel;
 import java.util.Date;
-import java.util.Vector;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * An instance of <code>ImageEncodeParam</code> for encoding images in
@@ -82,7 +83,7 @@
      * <p> Note that this method does not provide any guarantee that
      * the given image will be successfully encoded by the PNG
      * encoder, as it only performs a very superficial analysis of
-     * the image structure. 
+     * the image structure.
      */
     public static PNGEncodeParam getDefaultEncodeParam(RenderedImage im) {
         ColorModel colorModel = im.getColorModel();
@@ -106,16 +107,16 @@
         public Palette() {}
 
         // bKGD chunk
-        
+
         private boolean backgroundSet = false;
-        
+
         /**
          * Suppresses the 'bKGD' chunk from being output.
          */
         public void unsetBackground() {
             backgroundSet = false;
         }
-        
+
         /**
          * Returns true if a 'bKGD' chunk will be output.
          */
@@ -136,7 +137,7 @@
             this.bitDepth = bitDepth;
             bitDepthSet = true;
         }
-    
+
         // PLTE chunk
 
         private int[] palette = null;
@@ -155,18 +156,18 @@
          */
         public void setPalette(int[] rgb) {
             if (rgb.length < 1*3 || rgb.length > 256*3) {
-		throw new 
-		  IllegalArgumentException(PropertyUtil.getString("PNGEncodeParam0"));
+                throw new
+                  IllegalArgumentException(PropertyUtil.getString("PNGEncodeParam0"));
             }
             if ((rgb.length % 3) != 0) {
-                throw new 
-         	  IllegalArgumentException(PropertyUtil.getString("PNGEncodeParam1"));
+                throw new
+                   IllegalArgumentException(PropertyUtil.getString("PNGEncodeParam1"));
             }
-            
+
             palette = (int[])(rgb.clone());
             paletteSet = true;
         }
-        
+
         /**
          * Returns the current RGB palette.
          *
@@ -191,7 +192,7 @@
             palette = null;
             paletteSet = false;
         }
-        
+
         /**
          * Returns true if a 'PLTE' chunk will be output.
          */
@@ -200,9 +201,9 @@
         }
 
         // bKGD chunk
-        
+
         private int backgroundPaletteIndex;
-        
+
         /**
          * Sets the palette index of the suggested background color.
          *
@@ -212,7 +213,7 @@
             backgroundPaletteIndex = index;
             backgroundSet = true;
         }
-        
+
         /**
          * Returns the palette index of the suggested background color.
          *
@@ -247,7 +248,7 @@
             }
             transparencySet = true;
         }
-        
+
         /**
          * Returns the alpha values associated with each palette entry.
          *
@@ -276,16 +277,16 @@
         public Gray() {}
 
         // bKGD chunk
-        
+
         private boolean backgroundSet = false;
-        
+
         /**
          * Suppresses the 'bKGD' chunk from being output.
          */
         public void unsetBackground() {
             backgroundSet = false;
         }
-        
+
         /**
          * Returns true if a 'bKGD' chunk will be output.
          */
@@ -311,9 +312,9 @@
             this.bitDepth = bitDepth;
             bitDepthSet = true;
         }
-    
+
         // bKGD chunk
-        
+
         private int backgroundPaletteGray;
 
         /**
@@ -325,7 +326,7 @@
             backgroundPaletteGray = gray;
             backgroundSet = true;
         }
-        
+
         /**
          * Returns the suggested gray level of the background.
          *
@@ -360,7 +361,7 @@
             transparency[0] = transparentGray;
             transparencySet = true;
         }
-        
+
         /**
          * Returns the gray value to be used to denote transparency.
          *
@@ -396,7 +397,7 @@
             bitShiftSet = true;
         }
 
-        /** 
+        /**
          * Returns the desired bit shift for a grayscale image.
          *
          * <p> If the bit shift has not previously been set, or has been
@@ -440,16 +441,16 @@
         public RGB() {}
 
         // bKGD chunk
-        
+
         private boolean backgroundSet = false;
-        
+
         /**
          * Suppresses the 'bKGD' chunk from being output.
          */
         public void unsetBackground() {
             backgroundSet = false;
         }
-        
+
         /**
          * Returns true if a 'bKGD' chunk will be output.
          */
@@ -468,14 +469,14 @@
             this.bitDepth = bitDepth;
             bitDepthSet = true;
         }
-    
+
         // bKGD chunk
 
         private int[] backgroundRGB;
 
         /**
          * Sets the RGB value of the suggested background color.
-         * The <code>rgb</code> parameter should have 3 entries. 
+         * The <code>rgb</code> parameter should have 3 entries.
          *
          * <p> The 'bKGD' chunk will encode this information.
          */
@@ -486,7 +487,7 @@
             backgroundRGB = rgb;
             backgroundSet = true;
         }
-        
+
         /**
          * Returns the RGB value of the suggested background color.
          *
@@ -505,7 +506,7 @@
         // tRNS chunk
 
         private int[] transparency;
-        
+
         /**
          * Sets the RGB value to be used to denote transparency.
          *
@@ -518,7 +519,7 @@
             transparency = (int[])(transparentRGB.clone());
             transparencySet = true;
         }
-        
+
         /**
          * Returns the RGB value to be used to denote transparency.
          *
@@ -543,8 +544,8 @@
      * Sets the desired bit depth of an image.
      */
     public abstract void setBitDepth(int bitDepth);
-    
-    /** 
+
+    /**
      * Returns the desired bit depth for a grayscale image.
      *
      * <p> If the bit depth has not previously been set, or has been
@@ -562,7 +563,7 @@
     /**
      * Suppresses the setting of the bit depth of a grayscale image.
      * The depth of the encoded image will be inferred from the source
-     * image bit depth, rounded up to the next power of 2 between 1 
+     * image bit depth, rounded up to the next power of 2 between 1
      * and 16.
      */
     public void unsetBitDepth() {
@@ -584,7 +585,7 @@
     public boolean getInterlacing() {
         return useInterlacing;
     }
-    
+
     // bKGD chunk - delegate to subclasses
 
     // In JAI 1.0, 'backgroundSet' was private.  The JDK 1.2 compiler
@@ -861,7 +862,7 @@
         pd[0] = xPixelsPerUnit;
         pd[1] = yPixelsPerUnit;
         pd[2] = unitSpecifier;
-        
+
         setPhysicalDimension(pd);
     }
 
@@ -880,7 +881,7 @@
         if (!physicalDimensionSet) {
             throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam16"));
         }
-        return (int[])(physicalDimension.clone());        
+        return (int[])(physicalDimension.clone());
     }
 
     /**
@@ -955,7 +956,7 @@
 
     /**
      * Sets the number of significant bits for each band of the image.
-     * 
+     *
      * <p> The number of entries in the <code>significantBits</code>
      * array must be equal to the number of output bands in the image:
      * 1 for a gray image, 2 for gray+alpha, 3 for index or truecolor,
@@ -1212,9 +1213,9 @@
     }
 
     // Other chunk types
-    
-    Vector chunkType = new Vector();
-    Vector chunkData = new Vector();
+
+    List chunkType = new ArrayList();
+    List chunkData = new ArrayList();
 
     /**
      * Adds a private chunk, in binary form, to the list of chunks to
@@ -1243,7 +1244,7 @@
      * than the return value of <code>getNumPrivateChunks</code>.
      */
     public synchronized String getPrivateChunkType(int index) {
-        return (String)chunkType.elementAt(index);
+        return (String)chunkType.get(index);
     }
 
     /**
@@ -1253,7 +1254,7 @@
      * <code>getNumPrivateChunks</code>.
      */
     public synchronized byte[] getPrivateChunkData(int index) {
-        return (byte[])chunkData.elementAt(index);
+        return (byte[])chunkData.get(index);
     }
 
     /**
@@ -1262,8 +1263,8 @@
      * transcoding PNG images.
      */
     public synchronized void removeUnsafeToCopyPrivateChunks() {
-        Vector newChunkType = new Vector();
-        Vector newChunkData = new Vector();
+        List newChunkType = new ArrayList();
+        List newChunkData = new ArrayList();
 
         int len = getNumPrivateChunks();
         for (int i = 0; i < len; i++) {
@@ -1283,8 +1284,8 @@
      * Remove all private chunks associated with this parameter instance.
      */
     public synchronized void removeAllPrivateChunks() {
-        chunkType = new Vector();
-        chunkData = new Vector();
+        chunkType = new ArrayList();
+        chunkData = new ArrayList();
     }
 
     /**
@@ -1385,7 +1386,7 @@
             left   = currRow[i - bytesPerPixel] & 0xff;
             up     = prevRow[i] & 0xff;
             upleft = prevRow[i - bytesPerPixel] & 0xff;
-                
+
             // no filter
             badness[0] += curr;
 
@@ -1398,12 +1399,12 @@
             diff = curr - up;
             scratchRows[2][i]  = (byte)diff;
             badness    [2]    +=   (diff>=0)?diff:-diff;
-                
+
             // average filter
             diff = curr - ((left+up)>>1);
             scratchRows[3][i]  = (byte)diff;
             badness    [3]    +=   (diff>=0)?diff:-diff;
-                
+
             // paeth filter
 
             // Original code much simplier but doesn't take full
@@ -1441,7 +1442,7 @@
                     diff = curr-left;
                   else
                     diff = curr-upleft;
-                else 
+                else
                   // pc is negative and less than or equal to pa,
                   // but since pa is greater than pb this isn't an issue...
                   if (pb <= -pc)
@@ -1452,18 +1453,18 @@
             } else {
               if (pb<0) {
                 pb =-pb; // make it positive...
-                if (pa <= pb) {  
+                if (pa <= pb) {
                   // pc would be negative and less than or equal to pb
                   pc = pb-pa;
                   if (pa <= pc)
                     diff = curr-left;
-                  else if (pb == pc) 
+                  else if (pb == pc)
                     // if pa is zero then pc==pb otherwise
                     // pc must be less than pb.
                     diff = curr-up;
-                  else 
+                  else
                     diff = curr-upleft;
-                } else { 
+                } else {
                   // pc would be positive and less than pa.
                   pc = pa-pb;
                   if (pb <= pc)
@@ -1484,7 +1485,7 @@
         }
         int filterType = 0;
         int minBadness = badness[0];
-        
+
         for (int i = 1; i < 5; i++) {
             if (badness[i] < minBadness) {
                 minBadness = badness[i];
@@ -1497,7 +1498,7 @@
                              scratchRows[0], bytesPerPixel,
                              bytesPerRow);
         }
-        
+
         return filterType;
     }
 }

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java Mon Jan 15 16:59:48 2007
@@ -42,7 +42,9 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.TimeZone;
-import java.util.Vector;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
 
@@ -51,6 +53,7 @@
 import org.apache.xmlgraphics.image.codec.util.SimpleRenderedImage;
 
 /**
+ * @version $Id$
  */
 public class PNGImageDecoder extends ImageDecoderImpl {
 
@@ -81,7 +84,7 @@
         this.data = data;
         this.crc = crc;
 
-        typeString = new String();
+        typeString = "";
         typeString += (char)(type >> 24);
         typeString += (char)((type >> 16) & 0xff);
         typeString += (char)((type >> 8) & 0xff);
@@ -125,12 +128,11 @@
     }
 
     public String getString4(int offset) {
-        String s = new String();
-        s += (char)data[offset];
-        s += (char)data[offset + 1];
-        s += (char)data[offset + 2];
-        s += (char)data[offset + 3];
-        return s;
+        return  ""
+            + (char)data[offset]
+            + (char)data[offset + 1]
+            + (char)data[offset + 2]
+            + (char)data[offset + 3];
     }
 
     public boolean isType(String typeName) {
@@ -177,7 +179,7 @@
     private int compressionMethod;
     private int filterMethod;
     private int interlaceMethod;
-    
+
     private int paletteEntries;
     private byte[] redPalette;
     private byte[] greenPalette;
@@ -204,7 +206,7 @@
 
     // If true, perform palette lookup internally
     private boolean expandPalette = false;
-    
+
     // If true, output < 8 bit gray images in 8 bit components format
     private boolean output8BitGray = false;
 
@@ -265,13 +267,13 @@
     private static final int POST_ADD_GRAY_TRANS = 6;
 
     // Add transparency to a given RGB value (w/ optional gamma)
-    private static final int POST_ADD_RGB_TRANS = 7; 
+    private static final int POST_ADD_RGB_TRANS = 7;
 
     // Remove the alpha channel from a gray image (w/ optional gamma)
     private static final int POST_REMOVE_GRAY_TRANS = 8;
 
     // Remove the alpha channel from an RGB image (w/optional gamma)
-    private static final int POST_REMOVE_RGB_TRANS = 9; 
+    private static final int POST_REMOVE_RGB_TRANS = 9;
 
     // Mask to add expansion of GA -> GGGA
     private static final int POST_EXP_MASK = 16;
@@ -289,10 +291,10 @@
         POST_GRAY_LUT_ADD_TRANS | POST_EXP_MASK;
 
     // Add transparency to a given gray value, expand
-    private static final int POST_ADD_GRAY_TRANS_EXP = 
+    private static final int POST_ADD_GRAY_TRANS_EXP =
         POST_ADD_GRAY_TRANS | POST_EXP_MASK;
 
-    private Vector streamVec = new Vector();
+    private List streamVec = new ArrayList();
     private DataInputStream dataStream;
 
     private int bytesPerPixel; // number of bytes per input pixel
@@ -302,11 +304,11 @@
     // Number of private chunks
     private int chunkIndex = 0;
 
-    private Vector textKeys = new Vector();
-    private Vector textStrings = new Vector();
+    private List textKeys = new ArrayList();
+    private List textStrings = new ArrayList();
 
-    private Vector ztextKeys = new Vector();
-    private Vector ztextStrings = new Vector();
+    private List ztextKeys = new ArrayList();
+    private List ztextStrings = new ArrayList();
 
     private WritableRaster theTile;
 
@@ -347,9 +349,7 @@
         grayLut = new int[len];
 
         if (performGammaCorrection) {
-            for (int i = 0; i < len; i++) {
-                grayLut[i] = gammaLut[i];
-            }
+            System.arraycopy( gammaLut, 0, grayLut, 0, len );
         } else {
             for (int i = 0; i < len; i++) {
                 grayLut[i] = expandBits[bits][i];
@@ -382,7 +382,7 @@
             output8BitGray = true;
         }
         this.generateEncodeParam = decodeParam.getGenerateEncodeParam();
-        
+
         if (emitProperties) {
             properties.put("file_type", "PNG v. 1.0");
         }
@@ -398,11 +398,11 @@
             String msg = PropertyUtil.getString("PNGImageDecoder1");
             throw new RuntimeException(msg);
         }
-            
+
         do {
             try {
                 PNGChunk chunk;
-                
+
                 String chunkType = getChunkType(distream);
                 if (chunkType.equals("IHDR")) {
                     chunk = readChunk(distream);
@@ -463,7 +463,7 @@
                         encodeParam.addPrivateChunk(type, data);
                     }
                     if (emitProperties) {
-                        String key = "chunk_" + chunkIndex++ + ":" + type;
+                        String key = "chunk_" + chunkIndex++ + ':' + type;
                         properties.put(key.toLowerCase(), data);
                     }
                 }
@@ -495,7 +495,7 @@
             int type      =    distream.readInt();
             distream.reset();
 
-            String typeString = new String();
+            String typeString = "";        // todo simplify this
             typeString += (char)(type >> 24);
             typeString += (char)((type >> 16) & 0xff);
             typeString += (char)((type >> 8) & 0xff);
@@ -514,7 +514,7 @@
             byte[] data = new byte[length];
             distream.readFully(data);
             int crc = distream.readInt();
-            
+
             return new PNGChunk(length, type, data, crc);
         } catch (Exception e) {
             e.printStackTrace();
@@ -527,7 +527,7 @@
         tileHeight = height = chunk.getInt4(4);
 
         bitDepth = chunk.getInt1(8);
-        
+
         if ((bitDepth != 1) && (bitDepth != 2) && (bitDepth != 4) &&
             (bitDepth != 8) && (bitDepth != 16)) {
             // Error -- bad bit depth
@@ -603,7 +603,7 @@
             }
         }
 
-        compressionMethod = chunk.getInt1(10); 
+        compressionMethod = chunk.getInt1(10);
         if (compressionMethod != 0) {
             // Error -- only know about compression method 0
             String msg = PropertyUtil.getString("PNGImageDecoder9");
@@ -637,7 +637,7 @@
             String msg = PropertyUtil.getString("PNGImageDecoder11");
             throw new RuntimeException(msg);
         }
-        
+
         bytesPerPixel = (bitDepth == 16) ? 2 : 1;
 
         switch (colorType) {
@@ -721,12 +721,12 @@
         int textLen = textKeys.size();
         String[] textArray = new String[2*textLen];
         for (int i = 0; i < textLen; i++) {
-            String key = (String)textKeys.elementAt(i);
-            String val = (String)textStrings.elementAt(i);
+            String key = (String)textKeys.get(i);
+            String val = (String)textStrings.get(i);
             textArray[2*i] = key;
             textArray[2*i + 1] = val;
             if (emitProperties) {
-                String uniqueKey = "text_" + i + ":" + key;
+                String uniqueKey = "text_" + i + ':' + key;
                 properties.put(uniqueKey.toLowerCase(), val);
             }
         }
@@ -738,12 +738,12 @@
         int ztextLen = ztextKeys.size();
         String[] ztextArray = new String[2*ztextLen];
         for (int i = 0; i < ztextLen; i++) {
-            String key = (String)ztextKeys.elementAt(i);
-            String val = (String)ztextStrings.elementAt(i);
+            String key = (String)ztextKeys.get(i);
+            String val = (String)ztextStrings.get(i);
             ztextArray[2*i] = key;
             ztextArray[2*i + 1] = val;
             if (emitProperties) {
-                String uniqueKey = "ztext_" + i + ":" + key;
+                String uniqueKey = "ztext_" + i + ':' + key;
                 properties.put(uniqueKey.toLowerCase(), val);
             }
         }
@@ -752,15 +752,15 @@
         }
 
         // Parse prior IDAT chunks
-        InputStream seqStream = 
-            new SequenceInputStream(streamVec.elements());
+        InputStream seqStream =
+            new SequenceInputStream( Collections.enumeration( streamVec ) );
         InputStream infStream =
             new InflaterInputStream(seqStream, new Inflater());
         dataStream = new DataInputStream(infStream);
-        
+
         // Create an empty WritableRaster
         int depth = bitDepth;
-        if ((colorType == PNG_COLOR_GRAY) && 
+        if ((colorType == PNG_COLOR_GRAY) &&
             (bitDepth < 8) && output8BitGray) {
             depth = 8;
         }
@@ -802,7 +802,7 @@
                                                  greenPalette,
                                                  bluePalette);
             }
-        } else if ((colorType == PNG_COLOR_GRAY) && 
+        } else if ((colorType == PNG_COLOR_GRAY) &&
                    (bitDepth < 8) && !output8BitGray) {
             byte[] palette = expandBits[bitDepth];
             colorModel = new IndexColorModel(bitDepth,
@@ -972,12 +972,12 @@
 
         int pltIndex = 0;
 
-        // gAMA chunk must precede PLTE chunk 
+        // gAMA chunk must precede PLTE chunk
         if (performGammaCorrection) {
             if (gammaLut == null) {
                 initGammaLut(bitDepth == 16 ? 16 : 8);
             }
-            
+
             for (int i = 0; i < paletteEntries; i++) {
                 byte r = chunk.getByte(pltIndex++);
                 byte g = chunk.getByte(pltIndex++);
@@ -1102,7 +1102,7 @@
             properties.put("gamma", new Float(fileGamma*exp));
         }
     }
-    
+
     private void parse_hIST_chunk(PNGChunk chunk) {
         if (redPalette == null) {
             String msg = PropertyUtil.getString("PNGImageDecoder18");
@@ -1114,14 +1114,14 @@
         for (int i = 0; i < length; i++) {
             hist[i] = chunk.getInt2(2*i);
         }
-        
+
         if (encodeParam != null) {
             encodeParam.setPaletteHistogram(hist);
         }
     }
 
     private void parse_iCCP_chunk(PNGChunk chunk) {
-        String name = new String();
+        String name = "";  // todo simplify this
         byte b;
 
         int textIndex = 0;
@@ -1143,7 +1143,7 @@
         if (emitProperties) {
             properties.put("x_pixels_per_unit", new Integer(xPixelsPerUnit));
             properties.put("y_pixels_per_unit", new Integer(yPixelsPerUnit));
-            properties.put("pixel_aspect_ratio", 
+            properties.put("pixel_aspect_ratio",
                            new Float((float)xPixelsPerUnit/yPixelsPerUnit));
             if (unitSpecifier == 1) {
                 properties.put("pixel_units", "Meters");
@@ -1220,10 +1220,10 @@
     }
 
     private void parse_tEXt_chunk(PNGChunk chunk) {
-        String key = new String();
-        String value = new String();
+        String key = "";   // todo simplify this
+        String value = ""; // todo simplify this
         byte b;
-        
+
         int textIndex = 0;
         while ((b = chunk.getByte(textIndex++)) != 0) {
             key += (char)b;
@@ -1244,14 +1244,14 @@
         int hour = chunk.getInt1(4);
         int minute = chunk.getInt1(5);
         int second = chunk.getInt1(6);
-        
+
         TimeZone gmt = TimeZone.getTimeZone("GMT");
-        
+
         GregorianCalendar cal = new GregorianCalendar(gmt);
         cal.set(year, month, day,
                 hour, minute, second);
         Date date = cal.getTime();
-        
+
         if (encodeParam != null) {
             encodeParam.setModificationTime(date);
         }
@@ -1274,7 +1274,7 @@
             for (int i = 0; i < entries; i++) {
                 alphaPalette[i] = chunk.getByte(i);
             }
-            
+
             // Fill rest of palette with 255
             for (int i = entries; i < paletteEntries; i++) {
                 alphaPalette[i] = (byte)255;
@@ -1290,7 +1290,7 @@
             }
         } else if (colorType == PNG_COLOR_GRAY) {
             grayTransparentAlpha = chunk.getInt2(0);
-            
+
             if (!suppressAlpha) {
                 if (bitDepth < 8) {
                     output8BitGray = true;
@@ -1306,7 +1306,7 @@
                 } else {
                     outputBands = 2;
                 }
-                
+
                 if (encodeParam != null) {
                     ((PNGEncodeParam.Gray)encodeParam).
                         setTransparentGray(grayTransparentAlpha);
@@ -1320,7 +1320,7 @@
             if (!suppressAlpha) {
                 outputBands = 4;
                 postProcess = POST_ADD_RGB_TRANS;
-                
+
                 if (encodeParam != null) {
                     int[] rgbTrans = new int[3];
                     rgbTrans[0] = redTransparentAlpha;
@@ -1339,10 +1339,10 @@
     }
 
     private void parse_zTXt_chunk(PNGChunk chunk) {
-        String key = new String();
-        String value = new String();
+        String key = "";    // todo simplify this
+        String value = "";  // todo simplify this
         byte b;
-        
+
         int textIndex = 0;
         while ((b = chunk.getByte(textIndex++)) != 0) {
             key += (char)b;
@@ -1355,12 +1355,12 @@
             InputStream cis =
                 new ByteArrayInputStream(data, textIndex, length);
             InputStream iis = new InflaterInputStream(cis);
-            
+
             int c;
             while ((c = iis.read()) != -1) {
                 value += (char)c;
             }
-            
+
             ztextKeys.add(key);
             ztextStrings.add(value);
         } catch (Exception e) {
@@ -1432,7 +1432,7 @@
         for (int i = 0; i < bpp; i++) {
             raw = curr[i] & 0xff;
             priorRow = prev[i] & 0xff;
-            
+
             curr[i] = (byte)(raw + priorRow/2);
         }
 
@@ -1440,7 +1440,7 @@
             raw = curr[i] & 0xff;
             priorPixel = curr[i - bpp] & 0xff;
             priorRow = prev[i] & 0xff;
-            
+
             curr[i] = (byte)(raw + (priorPixel + priorRow)/2);
         }
     }
@@ -1458,7 +1458,7 @@
         } else {
             return c;
         }
-    } 
+    }
 
     private static void decodePaethFilter(byte[] curr, byte[] prev,
                                           int count, int bpp) {
@@ -1505,12 +1505,12 @@
         case POST_GAMMA:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                    
+
                 for (int i = 0; i < inputBands; i++) {
                     int x = ps[i];
                     ps[i] = gammaLut[x];
                 }
-                    
+
                 dst.setPixel(dstX, y, ps);
                 dstX += step;
             }
@@ -1538,7 +1538,7 @@
                 } else {
                     pd[1] = maxOpacity;
                 }
-                
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1547,12 +1547,12 @@
         case POST_PALETTE_TO_RGB:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                
+
                 int val = ps[0];
                 pd[0] = redPalette[val];
                 pd[1] = greenPalette[val];
                 pd[2] = bluePalette[val];
-                
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1663,7 +1663,7 @@
         case POST_GAMMA_EXP:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                    
+
                 int val = ps[0];
                 int alpha = ps[1];
                 int gamma = gammaLut[val];
@@ -1671,7 +1671,7 @@
                 pd[1] = gamma;
                 pd[2] = gamma;
                 pd[3] = alpha;
-                    
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1680,14 +1680,14 @@
         case POST_GRAY_ALPHA_EXP:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                    
+
                 int val = ps[0];
                 int alpha = ps[1];
                 pd[0] = val;
                 pd[1] = val;
                 pd[2] = val;
                 pd[3] = alpha;
-                    
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1729,7 +1729,7 @@
                 } else {
                     pd[3] = maxOpacity;
                 }
-                
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1738,7 +1738,7 @@
     }
 
     /**
-     * Reads in an image of a given size and returns it as a 
+     * Reads in an image of a given size and returns it as a
      * WritableRaster.
      */
     private void decodePass(WritableRaster imRas,

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java Mon Jan 15 16:59:48 2007
@@ -46,6 +46,8 @@
 import java.util.Hashtable;
 import java.util.TimeZone;
 import java.util.Vector;
+import java.util.List;
+import java.util.ArrayList;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
 
@@ -53,77 +55,82 @@
 import org.apache.xmlgraphics.image.rendered.AbstractRed;
 import org.apache.xmlgraphics.image.rendered.CachableRed;
 
+/**
+ *
+ * @version $Id$
+ */
+
 public class PNGRed extends AbstractRed {
 
     static class PNGChunk {
-	int length;
-	int type;
-	byte[] data;
-	int crc;
-
-	String typeString;
-
-	public PNGChunk(int length, int type, byte[] data, int crc) {
-	    this.length = length;
-	    this.type = type;
-	    this.data = data;
-	    this.crc = crc;
-
-	    typeString = new String();
-	    typeString += (char)(type >> 24);
-	    typeString += (char)((type >> 16) & 0xff);
-	    typeString += (char)((type >> 8) & 0xff);
-	    typeString += (char)(type & 0xff);
-	}
-
-	public int getLength() {
-	    return length;
-	}
-
-	public int getType() {
-	    return type;
-	}
-
-	public String getTypeString() {
-	    return typeString;
-	}
-
-	public byte[] getData() {
-	    return data;
-	}
-
-	public byte getByte(int offset) {
-	    return data[offset];
-	}
-
-	public int getInt1(int offset) {
-	    return data[offset] & 0xff;
-	}
-
-	public int getInt2(int offset) {
-	    return ((data[offset] & 0xff) << 8) |
-		(data[offset + 1] & 0xff);
-	}
-
-	public int getInt4(int offset) {
-	    return ((data[offset] & 0xff) << 24) |
-		((data[offset + 1] & 0xff) << 16) |
-		((data[offset + 2] & 0xff) << 8) |
-		(data[offset + 3] & 0xff);
-	}
-
-	public String getString4(int offset) {
-	    String s = new String();
-	    s += (char)data[offset];
-	    s += (char)data[offset + 1];
-	    s += (char)data[offset + 2];
-	    s += (char)data[offset + 3];
-	    return s;
-	}
-
-	public boolean isType(String typeName) {
-	    return typeString.equals(typeName);
-	}
+        int length;
+        int type;
+        byte[] data;
+        int crc;
+
+        String typeString;
+
+        public PNGChunk(int length, int type, byte[] data, int crc) {
+            this.length = length;
+            this.type = type;
+            this.data = data;
+            this.crc = crc;
+
+            typeString = "";
+            typeString += (char)(type >> 24);
+            typeString += (char)((type >> 16) & 0xff);
+            typeString += (char)((type >> 8) & 0xff);
+            typeString += (char)(type & 0xff);
+        }
+
+        public int getLength() {
+            return length;
+        }
+
+        public int getType() {
+            return type;
+        }
+
+        public String getTypeString() {
+            return typeString;
+        }
+
+        public byte[] getData() {
+            return data;
+        }
+
+        public byte getByte(int offset) {
+            return data[offset];
+        }
+
+        public int getInt1(int offset) {
+            return data[offset] & 0xff;
+        }
+
+        public int getInt2(int offset) {
+            return ((data[offset] & 0xff) << 8) |
+                (data[offset + 1] & 0xff);
+        }
+
+        public int getInt4(int offset) {
+            return ((data[offset] & 0xff) << 24) |
+                ((data[offset + 1] & 0xff) << 16) |
+                ((data[offset + 2] & 0xff) << 8) |
+                (data[offset + 3] & 0xff);
+        }
+
+        public String getString4(int offset) {
+            String s = new String();
+            s += (char)data[offset];
+            s += (char)data[offset + 1];
+            s += (char)data[offset + 2];
+            s += (char)data[offset + 3];
+            return s;
+        }
+
+        public boolean isType(String typeName) {
+            return typeString.equals(typeName);
+        }
     }
 
     public static final int PNG_COLOR_GRAY = 0;
@@ -157,7 +164,7 @@
     private int compressionMethod;
     private int filterMethod;
     private int interlaceMethod;
-    
+
     private int paletteEntries;
     private byte[] redPalette;
     private byte[] greenPalette;
@@ -184,7 +191,7 @@
 
     // If true, perform palette lookup internally
     private boolean expandPalette = false;
-    
+
     // If true, output < 8 bit gray images in 8 bit components format
     private boolean output8BitGray = false;
 
@@ -245,13 +252,13 @@
     private static final int POST_ADD_GRAY_TRANS = 6;
 
     // Add transparency to a given RGB value (w/ optional gamma)
-    private static final int POST_ADD_RGB_TRANS = 7; 
+    private static final int POST_ADD_RGB_TRANS = 7;
 
     // Remove the alpha channel from a gray image (w/ optional gamma)
     private static final int POST_REMOVE_GRAY_TRANS = 8;
 
     // Remove the alpha channel from an RGB image (w/optional gamma)
-    private static final int POST_REMOVE_RGB_TRANS = 9; 
+    private static final int POST_REMOVE_RGB_TRANS = 9;
 
     // Mask to add expansion of GA -> GGGA
     private static final int POST_EXP_MASK = 16;
@@ -269,7 +276,7 @@
         POST_GRAY_LUT_ADD_TRANS | POST_EXP_MASK;
 
     // Add transparency to a given gray value, expand
-    private static final int POST_ADD_GRAY_TRANS_EXP = 
+    private static final int POST_ADD_GRAY_TRANS_EXP =
         POST_ADD_GRAY_TRANS | POST_EXP_MASK;
 
     private Vector streamVec = new Vector();
@@ -282,11 +289,11 @@
     // Number of private chunks
     private int chunkIndex = 0;
 
-    private Vector textKeys = new Vector();
-    private Vector textStrings = new Vector();
+    private List textKeys = new ArrayList();
+    private List textStrings = new ArrayList();
 
-    private Vector ztextKeys = new Vector();
-    private Vector ztextStrings = new Vector();
+    private List ztextKeys = new ArrayList();
+    private List ztextStrings = new ArrayList();
 
     private WritableRaster theTile;
     private Rectangle bounds;
@@ -331,9 +338,7 @@
         grayLut = new int[len];
 
         if (performGammaCorrection) {
-            for (int i = 0; i < len; i++) {
-                grayLut[i] = gammaLut[i];
-            }
+            System.arraycopy( gammaLut, 0, grayLut, 0, len );
         } else {
             for (int i = 0; i < len; i++) {
                 grayLut[i] = expandBits[bits][i];
@@ -342,7 +347,7 @@
     }
 
     public PNGRed(InputStream stream) throws IOException {
-	this(stream, null);
+        this(stream, null);
     }
 
     public PNGRed(InputStream stream, PNGDecodeParam decodeParam)
@@ -370,7 +375,7 @@
             output8BitGray = true;
         }
         this.generateEncodeParam = decodeParam.getGenerateEncodeParam();
-        
+
         if (emitProperties) {
             properties.put("file_type", "PNG v. 1.0");
         }
@@ -386,11 +391,11 @@
             String msg = PropertyUtil.getString("PNGImageDecoder1");
             throw new RuntimeException(msg);
         }
-            
+
         do {
             try {
                 PNGChunk chunk;
-                
+
                 String chunkType = getChunkType(distream);
                 if (chunkType.equals("IHDR")) {
                     chunk = readChunk(distream);
@@ -451,7 +456,7 @@
                         encodeParam.addPrivateChunk(type, data);
                     }
                     if (emitProperties) {
-                        String key = "chunk_" + chunkIndex++ + ":" + type;
+                        String key = "chunk_" + chunkIndex++ + ':' + type;
                         properties.put(key.toLowerCase(), data);
                     }
                 }
@@ -483,11 +488,11 @@
             int type      =    distream.readInt();
             distream.reset();
 
-            String typeString = new String();
-            typeString += (char)(type >> 24);
-            typeString += (char)((type >> 16) & 0xff);
-            typeString += (char)((type >> 8) & 0xff);
-            typeString += (char)(type & 0xff);
+            String typeString = ""
+                              + (char)((type >> 24) & 0xff)
+                              + (char)((type >> 16) & 0xff)
+                              + (char)((type >>  8) & 0xff)
+                              + (char)( type        & 0xff);
             return typeString;
         } catch (Exception e) {
             e.printStackTrace();
@@ -502,7 +507,7 @@
             byte[] data = new byte[length];
             distream.readFully(data);
             int crc = distream.readInt();
-            
+
             return new PNGChunk(length, type, data, crc);
         } catch (Exception e) {
             e.printStackTrace();
@@ -514,13 +519,13 @@
         int width  = chunk.getInt4(0);
         int height = chunk.getInt4(4);
 
-	bounds = new Rectangle(0, 0, width, height);
+        bounds = new Rectangle(0, 0, width, height);
 
         bitDepth = chunk.getInt1(8);
-        
-        if ((bitDepth != 1) && (bitDepth != 2) && (bitDepth != 4) &&
-            (bitDepth != 8) && (bitDepth != 16)) {
-            // Error -- bad bit depth
+
+        int validMask = (1 << 1) | ( 1 << 2 ) | ( 1 << 4 ) | ( 1 << 8 ) | ( 1 << 16 );
+        if (( ( 1 << bitDepth ) & validMask ) == 0 ) {
+            // bitDepth is not one of { 1, 2, 4, 8, 16 }: Error -- bad bit depth
             String msg = PropertyUtil.getString("PNGImageDecoder3");
             throw new RuntimeException(msg);
         }
@@ -593,7 +598,7 @@
             }
         }
 
-        compressionMethod = chunk.getInt1(10); 
+        compressionMethod = chunk.getInt1(10);
         if (compressionMethod != 0) {
             // Error -- only know about compression method 0
             String msg = PropertyUtil.getString("PNGImageDecoder9");
@@ -627,7 +632,7 @@
             String msg = PropertyUtil.getString("PNGImageDecoder11");
             throw new RuntimeException(msg);
         }
-        
+
         bytesPerPixel = (bitDepth == 16) ? 2 : 1;
 
         switch (colorType) {
@@ -711,12 +716,12 @@
         int textLen = textKeys.size();
         String[] textArray = new String[2*textLen];
         for (int i = 0; i < textLen; i++) {
-            String key = (String)textKeys.elementAt(i);
-            String val = (String)textStrings.elementAt(i);
+            String key = (String)textKeys.get(i);
+            String val = (String)textStrings.get(i);
             textArray[2*i] = key;
             textArray[2*i + 1] = val;
             if (emitProperties) {
-                String uniqueKey = "text_" + i + ":" + key;
+                String uniqueKey = "text_" + i + ':' + key;
                 properties.put(uniqueKey.toLowerCase(), val);
             }
         }
@@ -728,12 +733,12 @@
         int ztextLen = ztextKeys.size();
         String[] ztextArray = new String[2*ztextLen];
         for (int i = 0; i < ztextLen; i++) {
-            String key = (String)ztextKeys.elementAt(i);
-            String val = (String)ztextStrings.elementAt(i);
+            String key = (String)ztextKeys.get(i);
+            String val = (String)ztextStrings.get(i);
             ztextArray[2*i] = key;
             ztextArray[2*i + 1] = val;
             if (emitProperties) {
-                String uniqueKey = "ztext_" + i + ":" + key;
+                String uniqueKey = "ztext_" + i + ':' + key;
                 properties.put(uniqueKey.toLowerCase(), val);
             }
         }
@@ -742,23 +747,23 @@
         }
 
         // Parse prior IDAT chunks
-        InputStream seqStream = 
+        InputStream seqStream =
             new SequenceInputStream(streamVec.elements());
         InputStream infStream =
             new InflaterInputStream(seqStream, new Inflater());
         dataStream = new DataInputStream(infStream);
-        
+
         // Create an empty WritableRaster
         int depth = bitDepth;
-        if ((colorType == PNG_COLOR_GRAY) && 
+        if ((colorType == PNG_COLOR_GRAY) &&
             (bitDepth < 8) && output8BitGray) {
             depth = 8;
         }
         if ((colorType == PNG_COLOR_PALETTE) && expandPalette) {
             depth = 8;
         }
-	int width  = bounds.width;
-	int height = bounds.height;
+        int width  = bounds.width;
+        int height = bounds.height;
 
         int bytesPerRow = (outputBands*width*depth + 7)/8;
         int scanlineStride =
@@ -779,7 +784,7 @@
 
         decodeImage(interlaceMethod == 1);
         SampleModel sm = theTile.getSampleModel();
-	ColorModel  cm;
+        ColorModel  cm;
 
         if ((colorType == PNG_COLOR_PALETTE) && !expandPalette) {
             if (outputHasAlphaPalette) {
@@ -796,7 +801,7 @@
                                                  greenPalette,
                                                  bluePalette);
             }
-        } else if ((colorType == PNG_COLOR_GRAY) && 
+        } else if ((colorType == PNG_COLOR_GRAY) &&
                    (bitDepth < 8) && !output8BitGray) {
             byte[] palette = expandBits[bitDepth];
             cm = new IndexColorModel(bitDepth,
@@ -809,7 +814,7 @@
                 createComponentColorModel(sm);
         }
 
-	init((CachableRed)null, bounds, cm, sm, 0, 0, properties);
+        init((CachableRed)null, bounds, cm, sm, 0, 0, properties);
     }
 
     private static final int[] GrayBits8 = { 8 };
@@ -968,20 +973,20 @@
 
         int pltIndex = 0;
 
-        // gAMA chunk must precede PLTE chunk 
+        // gAMA chunk must precede PLTE chunk
         if (performGammaCorrection) {
             if (gammaLut == null) {
                 initGammaLut(bitDepth == 16 ? 16 : 8);
             }
-            
+
             for (int i = 0; i < paletteEntries; i++) {
                 byte r = chunk.getByte(pltIndex++);
                 byte g = chunk.getByte(pltIndex++);
                 byte b = chunk.getByte(pltIndex++);
 
-                redPalette[i] = (byte)gammaLut[r & 0xff];
+                redPalette[i]   = (byte)gammaLut[r & 0xff];
                 greenPalette[i] = (byte)gammaLut[g & 0xff];
-                bluePalette[i] = (byte)gammaLut[b & 0xff];
+                bluePalette[i]  = (byte)gammaLut[b & 0xff];
             }
         } else {
             for (int i = 0; i < paletteEntries; i++) {
@@ -997,9 +1002,9 @@
         case PNG_COLOR_PALETTE:
             int bkgdIndex = chunk.getByte(0) & 0xff;
 
-            bkgdRed = redPalette[bkgdIndex] & 0xff;
+            bkgdRed   = redPalette[bkgdIndex]   & 0xff;
             bkgdGreen = greenPalette[bkgdIndex] & 0xff;
-            bkgdBlue = bluePalette[bkgdIndex] & 0xff;
+            bkgdBlue  = bluePalette[bkgdIndex]  & 0xff;
 
             if (encodeParam != null) {
                 ((PNGEncodeParam.Palette)encodeParam).
@@ -1031,21 +1036,21 @@
             break;
         }
 
-        int r = 0, g = 0, b = 0;
-        if ((colorType == PNG_COLOR_PALETTE) || (bitDepth == 8)) {
-            r = bkgdRed;
-            g = bkgdGreen;
-            b = bkgdBlue;
-        } else if (bitDepth < 8) {
-            r = expandBits[bitDepth][bkgdRed];
-            g = expandBits[bitDepth][bkgdGreen];
-            b = expandBits[bitDepth][bkgdBlue];
-        } else if (bitDepth == 16) {
-            r = bkgdRed >> 8;
-            g = bkgdGreen >> 8;
-            b = bkgdBlue >> 8;
-        }
         if (emitProperties) {
+            int r = 0, g = 0, b = 0;
+            if ((colorType == PNG_COLOR_PALETTE) || (bitDepth == 8)) {
+                r = bkgdRed;
+                g = bkgdGreen;
+                b = bkgdBlue;
+            } else if (bitDepth < 8) {
+                r = expandBits[bitDepth][bkgdRed];
+                g = expandBits[bitDepth][bkgdGreen];
+                b = expandBits[bitDepth][bkgdBlue];
+            } else if (bitDepth == 16) {
+                r = bkgdRed >> 8;
+                g = bkgdGreen >> 8;
+                b = bkgdBlue >> 8;
+            }
             properties.put("background_color", new Color(r, g, b));
         }
     }
@@ -1098,7 +1103,7 @@
             properties.put("gamma", new Float(fileGamma*exp));
         }
     }
-    
+
     private void parse_hIST_chunk(PNGChunk chunk) {
         if (redPalette == null) {
             String msg = PropertyUtil.getString("PNGImageDecoder18");
@@ -1110,14 +1115,14 @@
         for (int i = 0; i < length; i++) {
             hist[i] = chunk.getInt2(2*i);
         }
-        
+
         if (encodeParam != null) {
             encodeParam.setPaletteHistogram(hist);
         }
     }
 
     private void parse_iCCP_chunk(PNGChunk chunk) {
-        String name = new String();
+        String name = "";
         byte b;
 
         int textIndex = 0;
@@ -1139,7 +1144,7 @@
         if (emitProperties) {
             properties.put("x_pixels_per_unit", new Integer(xPixelsPerUnit));
             properties.put("y_pixels_per_unit", new Integer(yPixelsPerUnit));
-            properties.put("pixel_aspect_ratio", 
+            properties.put("pixel_aspect_ratio",
                            new Float((float)xPixelsPerUnit/yPixelsPerUnit));
             if (unitSpecifier == 1) {
                 properties.put("pixel_units", "Meters");
@@ -1216,21 +1221,21 @@
     }
 
     private void parse_tEXt_chunk(PNGChunk chunk) {
-        String key = new String();
-        String value = new String();
+        StringBuffer key = new StringBuffer();
+        StringBuffer value = new StringBuffer();
         byte b;
-        
+
         int textIndex = 0;
         while ((b = chunk.getByte(textIndex++)) != 0) {
-            key += (char)b;
+            key.append( (char)b );
         }
 
         for (int i = textIndex; i < chunk.getLength(); i++) {
-            value += (char)chunk.getByte(i);
+            value.append( (char)chunk.getByte(i) );
         }
 
-        textKeys.add(key);
-        textStrings.add(value);
+        textKeys.add(key.toString());
+        textStrings.add(value.toString());
     }
 
     private void parse_tIME_chunk(PNGChunk chunk) {
@@ -1240,14 +1245,14 @@
         int hour = chunk.getInt1(4);
         int minute = chunk.getInt1(5);
         int second = chunk.getInt1(6);
-        
+
         TimeZone gmt = TimeZone.getTimeZone("GMT");
-        
+
         GregorianCalendar cal = new GregorianCalendar(gmt);
         cal.set(year, month, day,
                 hour, minute, second);
         Date date = cal.getTime();
-        
+
         if (encodeParam != null) {
             encodeParam.setModificationTime(date);
         }
@@ -1270,7 +1275,7 @@
             for (int i = 0; i < entries; i++) {
                 alphaPalette[i] = chunk.getByte(i);
             }
-            
+
             // Fill rest of palette with 255
             for (int i = entries; i < paletteEntries; i++) {
                 alphaPalette[i] = (byte)255;
@@ -1286,7 +1291,7 @@
             }
         } else if (colorType == PNG_COLOR_GRAY) {
             grayTransparentAlpha = chunk.getInt2(0);
-            
+
             if (!suppressAlpha) {
                 if (bitDepth < 8) {
                     output8BitGray = true;
@@ -1302,7 +1307,7 @@
                 } else {
                     outputBands = 2;
                 }
-                
+
                 if (encodeParam != null) {
                     ((PNGEncodeParam.Gray)encodeParam).
                         setTransparentGray(grayTransparentAlpha);
@@ -1316,7 +1321,7 @@
             if (!suppressAlpha) {
                 outputBands = 4;
                 postProcess = POST_ADD_RGB_TRANS;
-                
+
                 if (encodeParam != null) {
                     int[] rgbTrans = new int[3];
                     rgbTrans[0] = redTransparentAlpha;
@@ -1335,13 +1340,13 @@
     }
 
     private void parse_zTXt_chunk(PNGChunk chunk) {
-        String key = new String();
-        String value = new String();
+        StringBuffer key = new StringBuffer();
+        StringBuffer value = new StringBuffer();
         byte b;
-        
+
         int textIndex = 0;
         while ((b = chunk.getByte(textIndex++)) != 0) {
-            key += (char)b;
+            key.append( (char)b );
         }
         /* int method = */ chunk.getByte(textIndex++);
 
@@ -1351,14 +1356,14 @@
             InputStream cis =
                 new ByteArrayInputStream(data, textIndex, length);
             InputStream iis = new InflaterInputStream(cis);
-            
+
             int c;
             while ((c = iis.read()) != -1) {
-                value += (char)c;
+                value.append( (char)c );
             }
-            
-            ztextKeys.add(key);
-            ztextStrings.add(value);
+
+            ztextKeys.add(key.toString() );
+            ztextStrings.add(value.toString() );
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -1414,7 +1419,7 @@
     private static void decodeUpFilter(byte[] curr, byte[] prev,
                                        int count) {
         for (int i = 0; i < count; i++) {
-            int raw = curr[i] & 0xff;
+            int raw   = curr[i] & 0xff;
             int prior = prev[i] & 0xff;
 
             curr[i] = (byte)(raw + prior);
@@ -1423,20 +1428,18 @@
 
     private static void decodeAverageFilter(byte[] curr, byte[] prev,
                                             int count, int bpp) {
-        int raw, priorPixel, priorRow;
-
         for (int i = 0; i < bpp; i++) {
-            raw = curr[i] & 0xff;
-            priorRow = prev[i] & 0xff;
-            
+            int raw      = curr[i] & 0xff;
+            int priorRow = prev[i] & 0xff;
+
             curr[i] = (byte)(raw + priorRow/2);
         }
 
         for (int i = bpp; i < count; i++) {
-            raw = curr[i] & 0xff;
-            priorPixel = curr[i - bpp] & 0xff;
-            priorRow = prev[i] & 0xff;
-            
+            int raw = curr[i] & 0xff;
+            int priorPixel = curr[i - bpp] & 0xff;
+            int priorRow = prev[i] & 0xff;
+
             curr[i] = (byte)(raw + (priorPixel + priorRow)/2);
         }
     }
@@ -1454,23 +1457,23 @@
         } else {
             return c;
         }
-    } 
+    }
 
     private static void decodePaethFilter(byte[] curr, byte[] prev,
                                           int count, int bpp) {
-        int raw, priorPixel, priorRow, priorRowPixel;
+        int priorPixel, priorRowPixel;
 
         for (int i = 0; i < bpp; i++) {
-            raw = curr[i] & 0xff;
-            priorRow = prev[i] & 0xff;
+            int raw = curr[i] & 0xff;
+            int priorRow = prev[i] & 0xff;
 
             curr[i] = (byte)(raw + priorRow);
         }
 
         for (int i = bpp; i < count; i++) {
-            raw = curr[i] & 0xff;
+            int raw = curr[i] & 0xff;
             priorPixel = curr[i - bpp] & 0xff;
-            priorRow = prev[i] & 0xff;
+            int priorRow = prev[i] & 0xff;
             priorRowPixel = prev[i - bpp] & 0xff;
 
             curr[i] = (byte)(raw + paethPredictor(priorPixel,
@@ -1501,12 +1504,12 @@
         case POST_GAMMA:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                    
+
                 for (int i = 0; i < inputBands; i++) {
                     int x = ps[i];
                     ps[i] = gammaLut[x];
                 }
-                    
+
                 dst.setPixel(dstX, y, ps);
                 dstX += step;
             }
@@ -1534,7 +1537,7 @@
                 } else {
                     pd[1] = maxOpacity;
                 }
-                
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1543,12 +1546,12 @@
         case POST_PALETTE_TO_RGB:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                
+
                 int val = ps[0];
                 pd[0] = redPalette[val];
                 pd[1] = greenPalette[val];
                 pd[2] = bluePalette[val];
-                
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1590,16 +1593,18 @@
             break;
 
         case POST_ADD_RGB_TRANS:
+            boolean flagGammaCorrection = performGammaCorrection; // local is cheaper
+            int[] workGammaLut = gammaLut;
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
 
                 int r = ps[0];
                 int g = ps[1];
                 int b = ps[2];
-                if (performGammaCorrection) {
-                    pd[0] = gammaLut[r];
-                    pd[1] = gammaLut[g];
-                    pd[2] = gammaLut[b];
+                if (flagGammaCorrection) {
+                    pd[0] = workGammaLut[r];
+                    pd[1] = workGammaLut[g];
+                    pd[2] = workGammaLut[b];
                 } else {
                     pd[0] = r;
                     pd[1] = g;
@@ -1659,7 +1664,7 @@
         case POST_GAMMA_EXP:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                    
+
                 int val = ps[0];
                 int alpha = ps[1];
                 int gamma = gammaLut[val];
@@ -1667,7 +1672,7 @@
                 pd[1] = gamma;
                 pd[2] = gamma;
                 pd[3] = alpha;
-                    
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1676,14 +1681,14 @@
         case POST_GRAY_ALPHA_EXP:
             for (srcX = 0; srcX < width; srcX++) {
                 src.getPixel(srcX, 0, ps);
-                    
+
                 int val = ps[0];
                 int alpha = ps[1];
                 pd[0] = val;
                 pd[1] = val;
                 pd[2] = val;
                 pd[3] = alpha;
-                    
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1725,7 +1730,7 @@
                 } else {
                     pd[3] = maxOpacity;
                 }
-                
+
                 dst.setPixel(dstX, y, pd);
                 dstX += step;
             }
@@ -1734,7 +1739,7 @@
     }
 
     /**
-     * Reads in an image of a given size and returns it as a 
+     * Reads in an image of a given size and returns it as a
      * WritableRaster.
      */
     private void decodePass(WritableRaster imRas,
@@ -1795,7 +1800,7 @@
                 decodePaethFilter(curr, prior, bytesPerRow, bytesPerPixel);
                 break;
             default:
-                // Error -- uknown filter type
+                // Error -- unknown filter type
                 String msg = PropertyUtil.getString("PNGImageDecoder16");
                 throw new RuntimeException(msg);
             }
@@ -1823,8 +1828,8 @@
     }
 
     private void decodeImage(boolean useInterlacing) {
-	int width = bounds.width;
-	int height = bounds.height;
+        int width = bounds.width;
+        int height = bounds.height;
 
         if (!useInterlacing) {
             decodePass(theTile, 0, 0, 1, 1, width, height);

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDecodeParam.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDecodeParam.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDecodeParam.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDecodeParam.java Mon Jan 15 16:59:48 2007
@@ -85,7 +85,7 @@
      * and no short to byte lookup will be applied to them.
      */
     public void setDecodePaletteAsShorts(boolean decodePaletteAsShorts) {
-	this.decodePaletteAsShorts = decodePaletteAsShorts;
+        this.decodePaletteAsShorts = decodePaletteAsShorts;
     }
     
     /**
@@ -93,7 +93,7 @@
      * shorts, resulting in an output image with short datatype.
      */ 
     public boolean getDecodePaletteAsShorts() {
-	return decodePaletteAsShorts;
+        return decodePaletteAsShorts;
     }
 
     /** 
@@ -106,7 +106,7 @@
      * deals correctly only with 16 bit unsigned values.
      */
     public byte decode16BitsTo8Bits(int s) {
-	return (byte)((s >> 8) & 0xffff);
+        return (byte)((s >> 8) & 0xffff);
     }
 
     /** 
@@ -115,7 +115,7 @@
      * 16 bit signed range.
      */
     public byte decodeSigned16BitsTo8Bits(short s) {
-	return (byte)((s + Short.MIN_VALUE) >> 8);
+        return (byte)((s + Short.MIN_VALUE) >> 8);
     }
 
     /**

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFDirectory.java Mon Jan 15 16:59:48 2007
@@ -24,7 +24,8 @@
 import java.util.Iterator;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Vector;
+import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.xmlgraphics.image.codec.util.SeekableStream;
 
@@ -48,12 +49,13 @@
  * be removed or changed in future releases of JAI.</b>
  *
  * @see TIFFField
+ * @version $Id$
  */
 public class TIFFDirectory extends Object implements Serializable {
 
     /** A boolean storing the endianness of the stream. */
     boolean isBigEndian;
-    
+
     /** The number of entries in the IFD. */
     int numEntries;
 
@@ -96,28 +98,28 @@
         stream.seek(0L);
         int endian = stream.readUnsignedShort();
         if (!isValidEndianTag(endian)) {
-            throw new 
-		IllegalArgumentException("TIFFDirectory1");
+            throw new
+                IllegalArgumentException("TIFFDirectory1");
         }
         isBigEndian = (endian == 0x4d4d);
 
         int magic = readUnsignedShort(stream);
         if (magic != 42) {
-            throw new 
-		IllegalArgumentException("TIFFDirectory2");
+            throw new
+                IllegalArgumentException("TIFFDirectory2");
         }
 
         // Get the initial ifd offset as an unsigned int (using a long)
         ifd_offset = readUnsignedInt(stream);
-        
+
         for (int i = 0; i < directory; i++) {
             if (ifd_offset == 0L) {
-                throw new 
-		   IllegalArgumentException("TIFFDirectory3");
+                throw new
+                   IllegalArgumentException("TIFFDirectory3");
             }
-            
+
             stream.seek(ifd_offset);
-            int entries = readUnsignedShort(stream);
+            long entries = readUnsignedShort(stream);
             stream.skip(12*entries);
 
             ifd_offset = readUnsignedInt(stream);
@@ -148,8 +150,8 @@
         stream.seek(0L);
         int endian = stream.readUnsignedShort();
         if (!isValidEndianTag(endian)) {
-            throw new 
-		IllegalArgumentException("TIFFDirectory1");
+            throw new
+                IllegalArgumentException("TIFFDirectory1");
         }
         isBigEndian = (endian == 0x4d4d);
 
@@ -160,7 +162,7 @@
         int dirNum = 0;
         while(dirNum < directory) {
             // Get the number of fields in the current IFD.
-            int numEntries = readUnsignedShort(stream);
+            long numEntries = readUnsignedShort(stream);
 
             // Skip to the next IFD offset value field.
             stream.seek(ifd_offset + 12*numEntries);
@@ -192,7 +194,7 @@
         4, //  9 = slong
         8, // 10 = srational
         4, // 11 = float
-        8  // 12 = double 
+        8  // 12 = double
     };
 
     private void initialize(SeekableStream stream) throws IOException {
@@ -203,30 +205,30 @@
 
         numEntries = readUnsignedShort(stream);
         fields = new TIFFField[numEntries];
-        
+
         for (i = 0; i < numEntries; i++) {
             int tag = readUnsignedShort(stream);
             int type = readUnsignedShort(stream);
             int count = (int)(readUnsignedInt(stream));
             int value = 0;
-	    
+
             // The place to return to to read the next tag
             nextTagOffset = stream.getFilePointer() + 4;
 
-	    try {
-		// If the tag data can't fit in 4 bytes, the next 4 bytes
-		// contain the starting offset of the data
-		if (count*sizeOfType[type] > 4) {
-		    value = (int)(readUnsignedInt(stream));
-		    stream.seek(value);
-		}
-	    } catch (ArrayIndexOutOfBoundsException ae) {
-
-		System.err.println(tag + " " + "TIFFDirectory4");
-		// if the data type is unknown we should skip this TIFF Field
-		stream.seek(nextTagOffset);
-		continue;
-	    }
+            try {
+                // If the tag data can't fit in 4 bytes, the next 4 bytes
+                // contain the starting offset of the data
+                if (count*sizeOfType[type] > 4) {
+                    value = (int)(readUnsignedInt(stream));
+                    stream.seek(value);
+                }
+            } catch (ArrayIndexOutOfBoundsException ae) {
+
+                System.err.println(tag + " " + "TIFFDirectory4");
+                // if the data type is unknown we should skip this TIFF Field
+                stream.seek(nextTagOffset);
+                continue;
+            }
 
             fieldIndex.put(new Integer(tag), new Integer(i));
             Object obj = null;
@@ -239,43 +241,40 @@
                 byte[] bvalues = new byte[count];
                 stream.readFully(bvalues, 0, count);
 
-		if (type == TIFFField.TIFF_ASCII) {
+                if (type == TIFFField.TIFF_ASCII) {
+
+                    // Can be multiple strings
+                    int index = 0, prevIndex = 0;
+                    List v = new ArrayList();
 
-		    // Can be multiple strings
-		    int index = 0, prevIndex = 0;
-		    Vector v = new Vector();
+                    while (index < count) {
 
-		    while (index < count) {
-			
                         while ((index < count) && (bvalues[index++] != 0));
 
-			// When we encountered zero, means one string has ended
-			v.add(new String(bvalues, prevIndex, 
-					 (index - prevIndex)) );
-			prevIndex = index;
-		    }
-
-		    count = v.size();
-		    String strings[] = new String[count];
-		    for (int c = 0 ; c < count; c++) {
-			strings[c] = (String)v.elementAt(c);
-		    }
-
-		    obj = strings;
-		} else {
-		    obj = bvalues;
-		}
+                        // When we encountered zero, means one string has ended
+                        v.add(new String(bvalues, prevIndex,
+                                         (index - prevIndex)) );
+                        prevIndex = index;
+                    }
+
+                    count = v.size();
+                    String[] strings = new String[count];
+                    v.toArray( strings );
+                    obj = strings;
+                } else {
+                    obj = bvalues;
+                }
 
                 break;
 
             case TIFFField.TIFF_SHORT:
                 char[] cvalues = new char[count];
                 for (j = 0; j < count; j++) {
-		    cvalues[j] = (char)(readUnsignedShort(stream));
+                    cvalues[j] = (char)(readUnsignedShort(stream));
                 }
                 obj = cvalues;
                 break;
-                
+
             case TIFFField.TIFF_LONG:
                 long[] lvalues = new long[count];
                 for (j = 0; j < count; j++) {
@@ -283,24 +282,24 @@
                 }
                 obj = lvalues;
                 break;
-                
+
             case TIFFField.TIFF_RATIONAL:
                 long[][] llvalues = new long[count][2];
                 for (j = 0; j < count; j++) {
                     llvalues[j][0] = readUnsignedInt(stream);
                     llvalues[j][1] = readUnsignedInt(stream);
                 }
-		obj = llvalues;
+                obj = llvalues;
                 break;
-                
+
             case TIFFField.TIFF_SSHORT:
                 short[] svalues = new short[count];
                 for (j = 0; j < count; j++) {
-		    svalues[j] = readShort(stream);
+                    svalues[j] = readShort(stream);
                 }
                 obj = svalues;
                 break;
-                
+
             case TIFFField.TIFF_SLONG:
                 int[] ivalues = new int[count];
                 for (j = 0; j < count; j++) {
@@ -308,7 +307,7 @@
                 }
                 obj = ivalues;
                 break;
-                
+
             case TIFFField.TIFF_SRATIONAL:
                 int[][] iivalues = new int[count][2];
                 for (j = 0; j < count; j++) {
@@ -366,7 +365,7 @@
     }
 
     /**
-     * Returns true if a tag appears in the directory. 
+     * Returns true if a tag appears in the directory.
      */
     public boolean isTagPresent(int tag) {
         return fieldIndex.containsKey(new Integer(tag));
@@ -499,7 +498,7 @@
         }
     }
 
-    private int readInt(SeekableStream stream) 
+    private int readInt(SeekableStream stream)
         throws IOException {
         if (isBigEndian) {
             return stream.readInt();
@@ -508,7 +507,7 @@
         }
     }
 
-    private long readUnsignedInt(SeekableStream stream) 
+    private long readUnsignedInt(SeekableStream stream)
         throws IOException {
         if (isBigEndian) {
             return stream.readUnsignedInt();
@@ -555,7 +554,7 @@
     }
 
     private static long readUnsignedInt(SeekableStream stream,
-                                        boolean isBigEndian) 
+                                        boolean isBigEndian)
         throws IOException {
         if (isBigEndian) {
             return stream.readUnsignedInt();
@@ -577,16 +576,16 @@
         stream.seek(0L);
         int endian = stream.readUnsignedShort();
         if (!isValidEndianTag(endian)) {
-            throw new 
-		IllegalArgumentException("TIFFDirectory1");
+            throw new
+                IllegalArgumentException("TIFFDirectory1");
         }
         boolean isBigEndian = (endian == 0x4d4d);
         int magic = readUnsignedShort(stream, isBigEndian);
         if (magic != 42) {
-            throw new 
-		IllegalArgumentException("TIFFDirectory2");
+            throw new
+                IllegalArgumentException("TIFFDirectory2");
         }
-        
+
         stream.seek(4L);
         long offset = readUnsignedInt(stream, isBigEndian);
 
@@ -595,22 +594,22 @@
             ++numDirectories;
 
             stream.seek(offset);
-            int entries = readUnsignedShort(stream, isBigEndian);
+            long entries = readUnsignedShort(stream, isBigEndian);
             stream.skip(12*entries);
             offset = readUnsignedInt(stream, isBigEndian);
         }
-      
+
         stream.seek(pointer); // Reset stream pointer
         return numDirectories;
     }
 
     /**
      * Returns a boolean indicating whether the byte order used in the
-     * the TIFF file is big-endian.  That is, whether the byte order is from  
+     * the TIFF file is big-endian.  That is, whether the byte order is from
      * the most significant to the least significant.
      */
     public boolean isBigEndian() {
-	return isBigEndian;
+        return isBigEndian;
     }
 
     /**

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFEncodeParam.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFEncodeParam.java?view=diff&rev=496556&r1=496555&r2=496556
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFEncodeParam.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/codec/tiff/TIFFEncodeParam.java Mon Jan 15 16:59:48 2007
@@ -121,7 +121,7 @@
      * Returns the value of the compression parameter.
      */
     public int getCompression() {
-	return compression;
+        return compression;
     }
 
     /**
@@ -151,17 +151,17 @@
             // Do nothing.
             break;
         default:
-	    throw new Error("TIFFEncodeParam0");
-	}
+            throw new Error("TIFFEncodeParam0");
+        }
 
-	this.compression = compression;
+        this.compression = compression;
     }
 
     /**
      * Returns the value of the writeTiled parameter. 
      */
     public boolean getWriteTiled() {
-	return writeTiled;
+        return writeTiled;
     }
 
     /**
@@ -172,7 +172,7 @@
      *                       wriiten out in tiled format.
      */
     public void setWriteTiled(boolean writeTiled) {
-	this.writeTiled = writeTiled;
+        this.writeTiled = writeTiled;
     }
 
     /**
@@ -254,7 +254,7 @@
     public void setDeflateLevel(int deflateLevel) {
         if(deflateLevel < 1 && deflateLevel > 9 &&
            deflateLevel != Deflater.DEFAULT_COMPRESSION) {
-	    throw new Error("TIFFEncodeParam1");
+            throw new Error("TIFFEncodeParam1");
         }
 
         this.deflateLevel = deflateLevel;



---------------------------------------------------------------------
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


Re: svn commit: r496556 [1/5] - in /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics: image/ image/codec/png/ image/codec/tiff/ image/codec/util/ image/rendered/ image/writer/ image/writer/internal/ java2d/ util/ util/i18n/ util/io/

Posted by Cameron McCormack <ca...@mcc.id.au>.
Jeremias Maerki:
> Cameron, thanks for doing this! It's good to see that happening.

A few days ago I tried to get Batik working with the Commons classes,
but something was wrong with SVG filters, and the colours in the
generated images weren’t correct.  I’m not sure if this was an error in
my porting the changes or what.  So unless I find the problem in a few
days, I’m going to leave it until after Batik’s release.

Cameron

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

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


Re: svn commit: r496556 [1/5] - in /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics: image/ image/codec/png/ image/codec/tiff/ image/codec/util/ image/rendered/ image/writer/ image/writer/internal/ java2d/ util/ util/i18n/ util/io/

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Cameron, thanks for doing this! It's good to see that happening.

On 16.01.2007 01:59:50 cam wrote:
> Author: cam
> Date: Mon Jan 15 16:59:48 2007
> New Revision: 496556
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=496556
> Log:
> Ported r389774:496552 from Batik trunk, in preparation for classes to be
> moved out of Batik.
<snip/>

Jeremias Maerki


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