harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r495940 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/image/ConvolveOp.java test/api/java/common/java/awt/image/ConvolveOpTest.java
Date Sat, 13 Jan 2007 18:10:35 GMT
Author: hindessm
Date: Sat Jan 13 10:10:33 2007
New Revision: 495940

URL: http://svn.apache.org/viewvc?view=rev&rev=495940
Log:
Applying patch from "[#HARMONY-2601] [classlib][awt]
java.awt.image.ConvolveOp.filter(Raster ,WritableRaster) throws
NegativeArraySizeException while RI throws ImagingOpException".  I removed
the verbose print from the test.

Added:
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ConvolveOpTest.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ConvolveOp.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ConvolveOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ConvolveOp.java?view=diff&rev=495940&r1=495939&r2=495940
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ConvolveOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ConvolveOp.java
Sat Jan 13 10:10:33 2007
@@ -141,103 +141,106 @@
         return dst;
     }
 
-    private final int slowFilter(Raster src, WritableRaster dst) {
-        SampleModel sm = src.getSampleModel();
+    private int slowFilter(Raster src, WritableRaster dst) {
+        try {
+            SampleModel sm = src.getSampleModel();
+
+            int numBands = src.getNumBands();
+            int srcHeight = src.getHeight();
+            int srcWidth = src.getWidth();
+
+            int xOrigin = kernel.getXOrigin();
+            int yOrigin = kernel.getYOrigin();
+            int kWidth = kernel.getWidth();
+            int kHeight = kernel.getHeight();
+            float[] data = kernel.getKernelData(null);
+
+            int srcMinX = src.getMinX();
+            int srcMinY = src.getMinY();
+            int dstMinX = dst.getMinX();
+            int dstMinY = dst.getMinY();
+
+            int srcConvMaxX = srcWidth - (kWidth - xOrigin - 1);
+            int srcConvMaxY = srcHeight - (kHeight - yOrigin - 1);
+
+            int[] maxValues = new int[numBands];
+            int[] masks = new int[numBands];
+            int[] sampleSizes = sm.getSampleSize();
+
+            for (int i=0; i < numBands; i++){
+                maxValues[i] = (1 << sampleSizes[i]) - 1;
+                masks[i] = ~(maxValues[i]);
+            }
 
-        int numBands = src.getNumBands();
-        int srcHeight = src.getHeight();
-        int srcWidth = src.getWidth();
-
-        int xOrigin = kernel.getXOrigin();
-        int yOrigin = kernel.getYOrigin();
-        int kWidth = kernel.getWidth();
-        int kHeight = kernel.getHeight();
-        float[] data = kernel.getKernelData(null);
-
-        int srcMinX = src.getMinX();
-        int srcMinY = src.getMinY();
-        int dstMinX = dst.getMinX();
-        int dstMinY = dst.getMinY();
-
-        int srcConvMaxX = srcWidth - (kWidth - xOrigin - 1);
-        int srcConvMaxY = srcHeight - (kHeight - yOrigin - 1);
-
-        int[] maxValues = new int[numBands];
-        int[] masks = new int[numBands];
-        int[] sampleSizes = sm.getSampleSize();
-
-        for (int i=0; i < numBands; i++){
-            maxValues[i] = (1 << sampleSizes[i]) - 1;
-            masks[i] = ~(maxValues[i]);
-        }
+            // Processing bounds
+            float[] pixels = null;
+            pixels = src.getPixels(srcMinX, srcMinY, srcWidth, srcHeight, pixels);
+            float[] newPixels = new float[pixels.length];
+            int rowLength = srcWidth*numBands;
+            if (this.edgeCond == ConvolveOp.EDGE_NO_OP){
+                // top
+                int start = 0;
+                int length = yOrigin*rowLength;
+                System.arraycopy(pixels, start, newPixels, start, length);
+                // bottom
+                start = (srcHeight - (kHeight - yOrigin - 1))*rowLength;
+                length = (kHeight - yOrigin - 1)*rowLength;
+                System.arraycopy(pixels, start, newPixels, start, length);
+                // middle
+                length = xOrigin*numBands;
+                int length1 = (kWidth - xOrigin - 1)*numBands;
+                start = yOrigin*rowLength;
+                int start1 = (yOrigin+1)*rowLength - length1;
+                for (int i = yOrigin; i < (srcHeight - (kHeight - yOrigin - 1)); i ++)
{
+                    System.arraycopy(pixels, start, newPixels, start, length);
+                    System.arraycopy(pixels, start1, newPixels, start1, length1);
+                    start +=rowLength;
+                    start1 +=rowLength;
+                }
 
-        // Processing bounds
-        float[] pixels = null;
-        pixels = src.getPixels(srcMinX, srcMinY, srcWidth, srcHeight, pixels);
-        float[] newPixels = new float[pixels.length];
-        int rowLength = srcWidth*numBands;
-        if (this.edgeCond == ConvolveOp.EDGE_NO_OP){
-            // top
-            int start = 0;
-            int length = yOrigin*rowLength;
-            System.arraycopy(pixels, start, newPixels, start, length);
-            // bottom
-            start = (srcHeight - (kHeight - yOrigin - 1))*rowLength;
-            length = (kHeight - yOrigin - 1)*rowLength;
-            System.arraycopy(pixels, start, newPixels, start, length);
-            // middle
-            length = xOrigin*numBands;
-            int length1 = (kWidth - xOrigin - 1)*numBands;
-            start = yOrigin*rowLength;
-            int start1 = (yOrigin+1)*rowLength - length1;
-            for (int i = yOrigin; i < (srcHeight - (kHeight - yOrigin - 1)); i ++) {
-                   System.arraycopy(pixels, start, newPixels, start, length);
-                   System.arraycopy(pixels, start1, newPixels, start1, length1);
-                   start +=rowLength;
-                   start1 +=rowLength;
             }
 
-        }
-
-        // Cycle over pixels to be calculated
-        for (int i = yOrigin; i < srcConvMaxY; i++){
-            for (int j = xOrigin; j < srcConvMaxX; j++){
-
-                // Take kernel data in backward direction, convolution
-                int kernelIdx = data.length - 1;
-
-                int pixelIndex = i * rowLength + j * numBands;
-                for (int hIdx = 0, rasterHIdx = i - yOrigin;
-                     hIdx < kHeight;
-                     hIdx++, rasterHIdx++
-                    ){
-                    for (int wIdx = 0, rasterWIdx = j - xOrigin;
-                         wIdx < kWidth;
-                         wIdx++, rasterWIdx++
-                    ){
-                        int curIndex = rasterHIdx * rowLength + rasterWIdx * numBands;
-                        for (int idx=0; idx < numBands; idx++){
-                            newPixels[pixelIndex+idx] += data[kernelIdx] * pixels[curIndex+idx];
+            // Cycle over pixels to be calculated
+            for (int i = yOrigin; i < srcConvMaxY; i++){
+                for (int j = xOrigin; j < srcConvMaxX; j++){
+
+                    // Take kernel data in backward direction, convolution
+                    int kernelIdx = data.length - 1;
+
+                    int pixelIndex = i * rowLength + j * numBands;
+                    for (int hIdx = 0, rasterHIdx = i - yOrigin;
+                         hIdx < kHeight;
+                         hIdx++, rasterHIdx++
+                            ){
+                        for (int wIdx = 0, rasterWIdx = j - xOrigin;
+                             wIdx < kWidth;
+                             wIdx++, rasterWIdx++
+                                ){
+                            int curIndex = rasterHIdx * rowLength + rasterWIdx * numBands;
+                            for (int idx=0; idx < numBands; idx++){
+                                newPixels[pixelIndex+idx] += data[kernelIdx] * pixels[curIndex+idx];
+                            }
+                            kernelIdx--;
                         }
-                        kernelIdx--;
                     }
-                }
 
-                // Check for overflow now
-                for (int idx=0; idx < numBands; idx++){
-                    if (((int)newPixels[pixelIndex+idx] & masks[idx]) != 0) {
-                        if (newPixels[pixelIndex+idx] < 0) {
-                            newPixels[pixelIndex+idx] = 0;
-                        } else {
-                            newPixels[pixelIndex+idx] = maxValues[idx];
+                    // Check for overflow now
+                    for (int idx=0; idx < numBands; idx++){
+                        if (((int)newPixels[pixelIndex+idx] & masks[idx]) != 0) {
+                            if (newPixels[pixelIndex+idx] < 0) {
+                                newPixels[pixelIndex+idx] = 0;
+                            } else {
+                                newPixels[pixelIndex+idx] = maxValues[idx];
+                            }
                         }
                     }
                 }
             }
-        }
-
-        dst.setPixels(dstMinX, dstMinY, srcWidth, srcHeight, newPixels);
 
+            dst.setPixels(dstMinX, dstMinY, srcWidth, srcHeight, newPixels);
+        } catch (Exception e) { // Something goes wrong, signal error
+            return 1;
+        }
         return 0;
     }
 

Added: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ConvolveOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ConvolveOpTest.java?view=auto&rev=495940
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ConvolveOpTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ConvolveOpTest.java
Sat Jan 13 10:10:33 2007
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+
+package java.awt.image;
+
+import junit.framework.TestCase;
+
+import java.awt.*;
+
+public class ConvolveOpTest extends TestCase {
+    class RR extends Raster {
+        public RR (SampleModel sampleModel, Point origin) {
+            super(sampleModel, origin);
+        }
+    }
+
+    // Regression test
+    public void testFilter() {
+        float[] array0 = new float[71];
+        Kernel localKernel = new Kernel(8, 7, array0);
+        ConvolveOp localConvolveOp = new ConvolveOp(localKernel);
+        int[] array1 = new int[704];
+        ComponentSampleModel localComponentSampleModel = new ComponentSampleModel(2,43970,127,4,7,array1);
+        Point localPoint = new Point(5, 9);
+        RR localRaster = new RR(localComponentSampleModel, localPoint);
+        try {
+            localConvolveOp.filter(localRaster, (WritableRaster) null);
+            fail("ImagingOpException expected, but not thrown");
+        } catch (NegativeArraySizeException unexpectedException) {
+            fail(unexpectedException + " was thrown");
+        } catch (ImagingOpException expectedException) {
+            // expected
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ConvolveOpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message