harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r488779 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/image/ main/java/common/org/apache/harmony/awt/internal/nls/ test/api/java/common/org/apache/harmony/awt/tests/java/awt/image/
Date Tue, 19 Dec 2006 19:35:16 GMT
Author: apetrenko
Date: Tue Dec 19 11:35:15 2006
New Revision: 488779

URL: http://svn.apache.org/viewvc?view=rev&rev=488779
Log:
Patch for HARMONY-1652 "[classlib][awt]Compatibility: java.awt.image.LookupOp.filter() throws
ArrayIndexOutOfBoundsException while RI throws IllegalArgumentException"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/LookupOp.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/java/awt/image/LookupOpTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/LookupOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/LookupOp.java?view=diff&rev=488779&r1=488778&r2=488779
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/LookupOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/LookupOp.java
Tue Dec 19 11:35:15 2006
@@ -134,9 +134,16 @@
     public final WritableRaster filter(Raster src, WritableRaster dst) {
         if (dst == null) {
             dst = createCompatibleDestRaster(src);
-        } else if (src.getNumBands() != dst.getNumBands()) {
-            // awt.237=Source and destinations rasters do not have the same number of bands
-            throw new IllegalArgumentException(Messages.getString("awt.237")); //$NON-NLS-1$
+        } else {
+            if (src.getNumBands() != dst.getNumBands()) {
+                throw new IllegalArgumentException(Messages.getString("awt.237")); //$NON-NLS-1$
           }
+            }
+            if (src.getWidth() != dst.getWidth()){
+                throw new IllegalArgumentException(Messages.getString("awt.28F")); //$NON-NLS-1$
           }
+            }
+            if (src.getHeight() != dst.getHeight()){
+                throw new IllegalArgumentException(Messages.getString("awt.290")); //$NON-NLS-1$
           }
+            }
         }
 
         if (lut.getNumComponents() != 1 && lut.getNumComponents() != src.getNumBands())
{
@@ -186,16 +193,29 @@
         if (dst == null) {
             finalDst = dst;
             dst = createCompatibleDestImage(src, null);
-        } else if (!srcCM.equals(dst.getColorModel())) {
-            // Treat BufferedImage.TYPE_INT_RGB and BufferedImage.TYPE_INT_ARGB as same
-            if (
-                    !((src.getType() == BufferedImage.TYPE_INT_RGB ||
-                       src.getType() == BufferedImage.TYPE_INT_ARGB) &&
-                      (dst.getType() == BufferedImage.TYPE_INT_RGB ||
-                       dst.getType() == BufferedImage.TYPE_INT_ARGB))
-            ) {
-                finalDst = dst;
-                dst = createCompatibleDestImage(src, null);
+        } else {
+            if (src.getWidth() != dst.getWidth()){
+                throw new IllegalArgumentException(
+                        "Source and destination images do not have " +
+                        "the same width!");
+            }
+
+            if (src.getHeight() != dst.getHeight()){
+                throw new IllegalArgumentException(
+                        "Source and destination images do not have " +
+                        "the same height!");
+            }
+
+            if (!srcCM.equals(dst.getColorModel())) {
+                // Treat BufferedImage.TYPE_INT_RGB and
+                // BufferedImage.TYPE_INT_ARGB as same
+                if (!((src.getType() == BufferedImage.TYPE_INT_RGB || src
+                        .getType() == BufferedImage.TYPE_INT_ARGB) && (dst
+                        .getType() == BufferedImage.TYPE_INT_RGB || dst
+                        .getType() == BufferedImage.TYPE_INT_ARGB))) {
+                    finalDst = dst;
+                    dst = createCompatibleDestImage(src, null);
+                }
             }
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties?view=diff&rev=488779&r1=488778&r2=488779
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
Tue Dec 19 11:35:15 2006
@@ -478,6 +478,8 @@
 awt.28C=Rect is null
 awt.28D=Length of dataArray[{0}] is less than size + offset[{1}]
 awt.28E=Length of dataArray is less than size + offset
+awt.28F=Source and destination rasters do not have the same width!
+awt.290=Source and destination rasters do not have the same height!
 
 awt.err.00=file dialog {0} error!
 awt.err.01=error: {0}

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/java/awt/image/LookupOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/java/awt/image/LookupOpTest.java?view=diff&rev=488779&r1=488778&r2=488779
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/java/awt/image/LookupOpTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/java/awt/image/LookupOpTest.java
Tue Dec 19 11:35:15 2006
@@ -18,6 +18,8 @@
 package org.apache.harmony.awt.tests.java.awt.image;
 
 import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.awt.image.ByteLookupTable;
 import java.awt.image.LookupOp;
 import java.awt.image.LookupTable;
 
@@ -37,6 +39,61 @@
         super.tearDown();
     }
 
+    public static BufferedImage getImage(int w, int h) {
+        return new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
+    }
+
+    /*
+     * Test method for 'java.awt.image.LookupOp.filter()' when src and dst have
+     * different heights or widths.
+     */
+    public final void test_LookupOp_filter_DifferentDimentionsTest() {
+        // regression test for Harmony-1632
+        byte[] array0 = new byte[96];
+        ByteLookupTable localByteLookupTable = new ByteLookupTable(1, array0);
+        LookupOp localLookupOp = new LookupOp(localByteLookupTable, null);
+
+        BufferedImage localBufferedImage = getImage(5069, 19);
+
+        // filter(BI,BI) non-equal widths
+        BufferedImage localBufferedImage1 = getImage(6, 19);
+        try {
+            localLookupOp.filter(localBufferedImage, localBufferedImage1);
+            fail("IllegalArgumentException expected!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // filter(R,WR) non-equal widths
+
+        try {
+            localLookupOp.filter(localBufferedImage.getRaster(),
+                    localBufferedImage1.getRaster());
+            fail("IllegalArgumentException expected!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // filter(BI,BI) non-equal heights
+
+        localBufferedImage1 = getImage(5069, 5);
+        try {
+            localLookupOp.filter(localBufferedImage, localBufferedImage1);
+            fail("IllegalArgumentException expected!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+
+        // filter(R, WR) non-equal heights
+        try {
+            localLookupOp.filter(localBufferedImage.getRaster(),
+                    localBufferedImage1.getRaster());
+            fail("IllegalArgumentException expected!");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
     /*
      * Test method for 'java.awt.image.LookupOp.LookupOp(LookupTable, RenderingHints)'
      * when the LookupTable argument is null.
@@ -51,7 +108,4 @@
             // expected
         }
     }
-
-    
-
 }



Mime
View raw message