diff options
author | Francis Kung <fkung@redhat.com> | 2006-09-13 21:05:16 +0000 |
---|---|---|
committer | Francis Kung <fkung@redhat.com> | 2006-09-13 21:05:16 +0000 |
commit | 7b3e919d2f1c70d4084539150835aee50eac1054 (patch) | |
tree | a99bf7c8b1aeec4d3fea24f5a2966a36df960cc1 /java/awt | |
parent | 3865b205858734bcd24b1fb216466b8f66cbcbe8 (diff) | |
download | classpath-7b3e919d2f1c70d4084539150835aee50eac1054.tar.gz |
2006-09-13 Francis Kung <fkung@redhat.com>
* java/awt/image/BandCombineOp.java: Updated documentation.
(filter(Raster, WritableRaster)): Use int arrays, and added simple cache.
Diffstat (limited to 'java/awt')
-rw-r--r-- | java/awt/image/BandCombineOp.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/java/awt/image/BandCombineOp.java b/java/awt/image/BandCombineOp.java index c4e2d5810..d9ce16fad 100644 --- a/java/awt/image/BandCombineOp.java +++ b/java/awt/image/BandCombineOp.java @@ -40,6 +40,7 @@ package java.awt.image; import java.awt.RenderingHints; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.Arrays; /** * Filter Raster pixels by applying a matrix. @@ -53,6 +54,9 @@ import java.awt.geom.Rectangle2D; * for the destination. Therefore the destination Raster must contain the * same number of bands as the number of rows in the filter matrix. * + * This Op assumes that samples are integers; floating point sample types will + * be rounded to their nearest integer value during filtering. + * * @author Jerry Quinn (jlquinn@optonline.net) */ public class BandCombineOp implements RasterOp @@ -109,19 +113,27 @@ public class BandCombineOp implements RasterOp throw new IllegalArgumentException("Destination raster is incompatible with source raster"); // Filter the pixels - float[] spix = new float[matrix[0].length - 1]; - float[] dpix = new float[matrix.length]; + int[] spix = new int[matrix[0].length - 1]; + int[] spix2 = new int[matrix[0].length - 1]; + int[] dpix = new int[matrix.length]; for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) { // In case matrix rows have implicit translation - spix[spix.length - 1] = 1.0f; + spix[spix.length - 1] = 1; src.getPixel(x, y, spix); - for (int i = 0; i < matrix.length; i++) + + // Do not re-calculate if pixel is identical to the last one + // (ie, blocks of the same colour) + if (!Arrays.equals(spix, spix2)) { - dpix[i] = 0; - for (int j = 0; j < matrix[0].length - 1; j++) - dpix[i] += spix[j] * matrix[i][j]; + System.arraycopy(spix, 0, spix2, 0, spix.length); + for (int i = 0; i < matrix.length; i++) + { + dpix[i] = 0; + for (int j = 0; j < matrix[0].length - 1; j++) + dpix[i] += spix[j] * (int)matrix[i][j]; + } } dest.setPixel(x, y, dpix); } |