summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorsbw1 <sbw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-05-15 17:11:12 +0000
committersbw1 <sbw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-05-15 17:11:12 +0000
commit61e1f83f8f7ffe1a9b9a067e475fa9126a8d7d77 (patch)
tree57c8836fc7f84f54f906d27fda99fd8758acf381 /java
parentd9c8fa2ca0395d29c53011a348e48a06cb7bbd91 (diff)
downloadATCD-61e1f83f8f7ffe1a9b9a067e475fa9126a8d7d77.tar.gz
These are the filters I've attempted to port from XV.
Diffstat (limited to 'java')
-rw-r--r--java/ImageProcessing/filters/Assert.java33
-rw-r--r--java/ImageProcessing/filters/BleachFilter.java60
-rw-r--r--java/ImageProcessing/filters/BlurFilter.java85
-rw-r--r--java/ImageProcessing/filters/DarkenFilter.java48
-rw-r--r--java/ImageProcessing/filters/DeSpeckleFilter.java107
-rw-r--r--java/ImageProcessing/filters/DissolveFilter.java52
-rw-r--r--java/ImageProcessing/filters/EdgeDetectFilter.java243
-rw-r--r--java/ImageProcessing/filters/EmbossFilter.java75
-rw-r--r--java/ImageProcessing/filters/MedFilter.java6
-rw-r--r--java/ImageProcessing/filters/OilPaintFilter.java68
-rw-r--r--java/ImageProcessing/filters/PixelizeFilter.java111
-rw-r--r--java/ImageProcessing/filters/RotateFilter.java186
-rw-r--r--java/ImageProcessing/filters/SharpenFilter.java262
-rw-r--r--java/ImageProcessing/filters/SpatialFilter.java201
-rw-r--r--java/ImageProcessing/filters/SpreadFilter.java119
-rw-r--r--java/ImageProcessing/filters/Timer.java23
16 files changed, 1679 insertions, 0 deletions
diff --git a/java/ImageProcessing/filters/Assert.java b/java/ImageProcessing/filters/Assert.java
new file mode 100644
index 00000000000..c83f9ca94c0
--- /dev/null
+++ b/java/ImageProcessing/filters/Assert.java
@@ -0,0 +1,33 @@
+package imaging.filters;
+
+/**
+ * A simple assertion mechanism for asserting validity of
+ * arguments.<p>
+ *
+ * @version 1.0, Apr 1 1996
+ * @author David Geary
+ */
+class Assert {
+ static public void notFalse(boolean b)
+ throws IllegalArgumentException {
+ if(b == false)
+ throw new IllegalArgumentException(
+ "boolean expression false");
+ }
+ static public void notNull(Object obj)
+ throws IllegalArgumentException {
+ if(obj == null)
+ throw new IllegalArgumentException("null argument");
+ }
+
+ static public void notFalse(boolean b, String s)
+ throws IllegalArgumentException {
+ if(b == false)
+ throw new IllegalArgumentException(s);
+ }
+ static public void notNull(Object obj, String s)
+ throws IllegalArgumentException {
+ if(obj == null)
+ throw new IllegalArgumentException(s);
+ }
+}
diff --git a/java/ImageProcessing/filters/BleachFilter.java b/java/ImageProcessing/filters/BleachFilter.java
new file mode 100644
index 00000000000..ea269788aea
--- /dev/null
+++ b/java/ImageProcessing/filters/BleachFilter.java
@@ -0,0 +1,60 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+/**
+ * A derivation of RGBImageFilter that bleaches an image.<p>
+ *
+ * Extent of the bleaching effect is controlled by the only
+ * constructor argument: an integer representing the percentage
+ * of bleaching. The percentage of bleaching may also be
+ * controlled after instantiation by invoking the
+ * void percent(int) method.<p>
+ *
+ * @version 1.0, Apr 1 1996
+ * @author David Geary
+ * @see RGBImageFilter
+ */
+public class BleachFilter extends RGBImageFilter implements MedFilter
+{
+ private int percent;
+
+ public BleachFilter(int percent)
+ {
+ Assert.notFalse(percent >= 0 && percent <= 100);
+ this.percent = percent;
+ canFilterIndexColorModel = true;
+ }
+
+ public String info ()
+ {
+ return "Bleaches/Lightens an image";
+ }
+
+ public int percent() { return percent; }
+ public void percent(int percent) { percent = percent; }
+
+ public int filterRGB(int x, int y, int rgb) {
+ DirectColorModel cm =
+ (DirectColorModel)ColorModel.getRGBdefault();
+
+ int alpha = cm.getAlpha(rgb);
+ int red = cm.getRed (rgb);
+ int green = cm.getGreen(rgb);
+ int blue = cm.getBlue (rgb);
+ double percentMultiplier = (double)percent/100;
+
+ red = Math.min((int)
+ (red + (red * percentMultiplier)), 255);
+ green = Math.min((int)
+ (green + (green * percentMultiplier)), 255);
+ blue = Math.min((int)
+ (blue + (blue * percentMultiplier)), 255);
+
+ alpha = alpha << 24;
+ red = red << 16;
+ green = green << 8;
+
+ return alpha | red | green | blue;
+ }
+}
diff --git a/java/ImageProcessing/filters/BlurFilter.java b/java/ImageProcessing/filters/BlurFilter.java
new file mode 100644
index 00000000000..95937d52f93
--- /dev/null
+++ b/java/ImageProcessing/filters/BlurFilter.java
@@ -0,0 +1,85 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class BlurFilter extends SpatialFilter
+{
+ private int[][] mean_filter;
+ private int degree_ = 3;
+
+ public BlurFilter()
+ {
+ }
+
+ public BlurFilter(int degree)
+ {
+ degree_ = degree;
+ }
+
+ public void imageComplete(int status)
+ {
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error");
+ return;
+ }
+
+ int[] pixels = new int[columns_];
+ int pixel = 0, count = 0;
+ int red, green, blue;
+ int alpha, n2 = degree_/2;
+
+ for (int y = 0; y < rows_; y++)
+ {
+ for (int x = 0; x < columns_ - 1; x++)
+ {
+ red = 0; green = 0; blue = 0; count = 0;
+ alpha = (raster_[y*columns_ + x] >> 24) & 0xff;
+
+ for (int y1 = y - n2; y1 < y + n2; y1++)
+ {
+ if (y1 >= 0 && y1 < rows_)
+ {
+ for (int x1 = x - n2; x1 < x + n2; x1++)
+ {
+ if (x1 >= 0 && x1 < columns_)
+ {
+ pixel = raster_[y1*columns_ + x1];
+
+ red += (pixel >> 16) & 0xff;
+ green += (pixel >> 8) & 0xff;
+ blue += (pixel) & 0xff;
+ count++;
+ }
+ }
+ }
+ }
+
+ red /= count;
+ green /= count;
+ blue /= count;
+
+ if (red < 0) red = 0;
+ if (green < 0) green = 0;
+ if (blue < 0) blue = 0 ;
+
+ if (red > 255) red = 255;
+ if (green > 255) green = 255;
+ if (blue > 255) blue = 255;
+
+ pixels[x] = (alpha << 24) | (red << 16) | (green << 8) | blue;
+ }
+
+ consumer.setPixels(0, y, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+
+ System.out.println("Finished altering image");
+ consumer.imageComplete(status);
+ }
+
+ public String info ()
+ {
+ return "Blurs an image.";
+ }
+}
diff --git a/java/ImageProcessing/filters/DarkenFilter.java b/java/ImageProcessing/filters/DarkenFilter.java
new file mode 100644
index 00000000000..ea20d15a46b
--- /dev/null
+++ b/java/ImageProcessing/filters/DarkenFilter.java
@@ -0,0 +1,48 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class DarkenFilter extends RGBImageFilter implements MedFilter
+{
+ private int percent_;
+
+ public DarkenFilter ()
+ {
+ percent_ = 50;
+ canFilterIndexColorModel = true;
+ }
+
+ public DarkenFilter(int percent)
+ {
+ Assert.notFalse(percent >= 0 && percent <= 100);
+ percent_ = percent;
+ canFilterIndexColorModel = true;
+ }
+
+ public String info ()
+ {
+ return "Darkens an image.";
+ }
+
+ public int filterRGB(int x, int y, int rgb)
+ {
+ DirectColorModel cm =
+ (DirectColorModel)ColorModel.getRGBdefault();
+
+ int alpha = cm.getAlpha(rgb);
+ int red = cm.getRed (rgb);
+ int green = cm.getGreen(rgb);
+ int blue = cm.getBlue (rgb);
+ double percentMultiplier = (double)((double)1.0 - (double)percent_/100);
+
+ red *= percentMultiplier;
+ blue *= percentMultiplier;
+ green *= percentMultiplier;
+
+ alpha = alpha << 24;
+ red = red << 16;
+ green = green << 8;
+
+ return alpha | red | green | blue;
+ }
+}
diff --git a/java/ImageProcessing/filters/DeSpeckleFilter.java b/java/ImageProcessing/filters/DeSpeckleFilter.java
new file mode 100644
index 00000000000..9e94ec44fab
--- /dev/null
+++ b/java/ImageProcessing/filters/DeSpeckleFilter.java
@@ -0,0 +1,107 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class DeSpeckleFilter extends SpatialFilter
+{
+ private int degree_ = 3;
+
+ public DeSpeckleFilter()
+ {
+ }
+
+ public DeSpeckleFilter(int degree)
+ {
+ degree_ = degree;
+ }
+
+ public void imageComplete(int status)
+ {
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error: " + status);
+ return;
+ }
+
+ int rsum, bsum, gsum, r, g, b, a;
+ int count, n2, nsq, c2;
+ int[] rtab, gtab, btab;
+ int[] pixels = new int[columns_];
+
+ n2 = degree_/2;
+ nsq = degree_ * degree_;
+
+ rtab = new int[nsq];
+ gtab = new int[nsq];
+ btab = new int[nsq];
+
+ for (int y = 0; y < rows_; y++)
+ {
+ for (int x = 0; x < columns_; x++)
+ {
+ rsum = gsum = bsum = 0;
+ count = 0;
+
+ for (int y1 = y - n2; y1 < y + n2; y1++)
+ {
+ if (y1 >= 0 && y1 < rows_)
+ {
+ for (int x1 = x - n2; x1 < x + n2; x1++)
+ {
+ if (x1 >= 0 && x1 < columns_)
+ {
+ int pixel = raster_[y1*columns_ + x1];
+ rtab[count] = (pixel >> 16) & 0xff;
+ gtab[count] = (pixel >> 8) & 0xff;
+ btab[count] = (pixel) & 0xff;
+ count++;
+ }
+ }
+ }
+ }
+
+ for (int d = count/2; d > 0; d=d/2)
+ {
+ for (int i = d; i < count; i++)
+ {
+ for (int j = i - d; j >= 0 && rtab[j] > rtab[j+d]; j -= d)
+ {
+ int t = rtab[j];
+ rtab[j] = rtab[j + d];
+ rtab[j + d] = t;
+ }
+
+ for (int j = i - d; j >= 0 && gtab[j] > gtab[j+d]; j -= d)
+ {
+ int t = gtab[j];
+ gtab[j] = gtab[j + d];
+ gtab[j + d] = t;
+ }
+
+ for (int j = i - d; j >= 0 && btab[j] > btab[j+d]; j -= d)
+ {
+ int t = btab[j];
+ btab[j] = btab[j + d];
+ btab[j + d] = t;
+ }
+ }
+ }
+
+ c2 = count/2;
+
+ a = (raster_[y*columns_ + x] >> 24) & 0xff;
+ r = ( (count % 2 == 0) ? (rtab[c2] + rtab[c2 - 1])/2 : rtab[c2]);
+ g = ( (count % 2 == 0) ? (gtab[c2] + gtab[c2 - 1])/2 : gtab[c2]);
+ b = ( (count % 2 == 0) ? (btab[c2] + btab[c2 - 1])/2 : btab[c2]);
+
+ pixels[x] = (a << 24) | (r << 16) | (g << 8) | b;
+ }
+
+ consumer.setPixels(0, y, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+
+ consumer.imageComplete(status);
+ }
+
+}
diff --git a/java/ImageProcessing/filters/DissolveFilter.java b/java/ImageProcessing/filters/DissolveFilter.java
new file mode 100644
index 00000000000..0225aad6ad1
--- /dev/null
+++ b/java/ImageProcessing/filters/DissolveFilter.java
@@ -0,0 +1,52 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+/**
+ * A derivation of RGBImageFilter that partially or wholly
+ * dissolves an image.<p>
+ *
+ * Extent of dissolving is set by the setOpacity(int) method,
+ * which is passed an integer between 0 and 255 (inclusive).
+ * The integer represents the alpha value to be applied to
+ * every color in the image.<p>
+ *
+ * An alpha value of 255 signifies an opaque color, while an
+ * alpha value of 0 signifies a translucent color.<p>
+ *
+ * @version 1.0, Apr 1 1996
+ * @author David Geary
+ * @see RGBImageFilter
+ */
+public class DissolveFilter extends RGBImageFilter implements MedFilter
+{
+ private int opacity;
+
+ public DissolveFilter() {
+ this(0);
+ }
+ public DissolveFilter(int opacity) {
+ canFilterIndexColorModel = true;
+ setOpacity(opacity);
+ }
+ public String info ()
+ {
+ return "Dissolves an image";
+ }
+ public void setOpacity(int opacity) {
+ Assert.notFalse(opacity >= 0 && opacity <= 255);
+ this.opacity = opacity;
+ }
+ public int filterRGB(int x, int y, int rgb) {
+ DirectColorModel cm =
+ (DirectColorModel)ColorModel.getRGBdefault();
+ int alpha = cm.getAlpha(rgb);
+ int red = cm.getRed (rgb);
+ int green = cm.getGreen(rgb);
+ int blue = cm.getBlue (rgb);
+
+ alpha = opacity;
+
+ return alpha << 24 | red << 16 | green << 8 | blue;
+ }
+}
diff --git a/java/ImageProcessing/filters/EdgeDetectFilter.java b/java/ImageProcessing/filters/EdgeDetectFilter.java
new file mode 100644
index 00000000000..8855a757a46
--- /dev/null
+++ b/java/ImageProcessing/filters/EdgeDetectFilter.java
@@ -0,0 +1,243 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class EdgeDetectFilter extends SpatialFilter
+{
+ public EdgeDetectFilter()
+ {
+ }
+
+ public String info ()
+ {
+ return "Edge detection filter.";
+ }
+
+ public void imageComplete(int status)
+ {
+ Timer timer = new Timer();
+
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error");
+ return;
+ }
+
+ int[] pixels = new int[columns_];
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int new_red1 = 0, new_green1 = 0, new_blue1 = 0,
+ new_red2 = 0, new_green2 = 0, new_blue2 = 0;
+ int ul, um, ur, ll, lm, lr, ml, mr;
+ int alpha;
+
+ for (int x = 1; x < rows_ - 1; x++)
+ {
+ for (int y = 1; y < columns_ - 1; y++)
+ {
+ row1 = columns_*(x - 1) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+
+ ul = raster_[row1 - 1];
+ um = raster_[row1];
+ ur = raster_[row1 + 1];
+ ml = raster_[row2 - 1];
+ mr = raster_[row2 + 1];
+ ll = raster_[row3 - 1];
+ lm = raster_[row3];
+ lr = raster_[row3 + 1];
+
+ alpha = (raster_[row2] >> 24) & 0xff;
+
+ new_red1 =
+ (((ul >> 16) & 0xff)
+ + (((um >> 16) & 0xff) << 1)
+ + ((ur >> 16) & 0xff)
+ - ((ll >> 16) & 0xff)
+ - (((lm >> 16) & 0xff) << 1)
+ - ((lr >> 16) & 0xff));
+
+ new_green1 =
+ (((ul >> 8) & 0xff)
+ + (((um >> 8) & 0xff) << 1)
+ + ((ur >> 8) & 0xff)
+ - ((ll >> 8) & 0xff)
+ - (((lm >> 8) & 0xff) << 1)
+ - ((lr >> 8) & 0xff));
+
+ new_blue1 =
+ (((ul) & 0xff)
+ + (((um) & 0xff) << 1)
+ + ((ur) & 0xff)
+ - ((ll) & 0xff)
+ - (((lm) & 0xff) << 1)
+ - ((lr) & 0xff));
+
+ new_red2 =
+ (- ((ul >> 16) & 0xff)
+ + ((ur >> 16) & 0xff)
+ - (((ml >> 16) & 0xff) << 1)
+ + (((mr >> 16) & 0xff) << 1)
+ - ((ll >> 16) & 0xff)
+ + ((lr >> 16) & 0xff));
+
+ new_green2 =
+ (- ((ul >> 8) & 0xff)
+ + ((ur >> 8) & 0xff)
+ - (((ml >> 8) & 0xff) << 1)
+ + (((mr >> 8) & 0xff) << 1)
+ - ((ll >> 8) & 0xff)
+ + ((lr >> 8) & 0xff));
+
+ new_blue2 =
+ (- ((ul) & 0xff)
+ + ((ur) & 0xff)
+ - (((ml) & 0xff) << 1)
+ + (((mr) & 0xff) << 1)
+ - ((ll) & 0xff)
+ + ((lr) & 0xff));
+
+
+ new_red1 = (int)Math.sqrt(new_red1*new_red1 + new_red2*new_red2);
+ new_green1 = (int)Math.sqrt(new_green1*new_green1 + new_green2*new_green2);
+ new_blue1 = (int)Math.sqrt(new_blue1*new_blue1 + new_blue2*new_blue2);
+
+ if (new_red1 < 0) red = 0;
+ if (new_green1 < 0) green = 0;
+ if (new_blue1 < 0) blue = 0 ;
+
+
+ if (new_red1 > 255)
+ new_red1 = 255;
+
+ if (new_green1 > 255)
+ new_green1 = 255;
+
+ if (new_blue1 > 255)
+ new_blue1 = 255;
+
+ pixels[y - 1] = (alpha << 24) | (new_red1 << 16) | (new_green1 << 8) | new_blue1;
+
+ }
+ consumer.setPixels(0, x-1, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+
+ /*
+ public void imageComplete(int status)
+ {
+ Timer timer = new Timer();
+
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error");
+ return;
+ }
+
+ int[][] pixels = new int[rows_][columns_];
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int a, b, c, d, rsum, gsum, bsum, v, maxv = 0;
+ int ul, um, ur, ml, mr, ll, lm, lr;
+ int alpha;
+
+ for (int y = 1; y < rows_ - 1; y++)
+ {
+ for (int x = 1; x < columns_ - 1; x++)
+ {
+ row1 = columns_*(y-1) + x;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ ul = raster_[row1 - 1];
+ um = raster_[row1];
+ ur = raster_[row1 + 1];
+ ml = raster_[row2 - 1];
+ mr = raster_[row2 + 1];
+ ll = raster_[row3 - 1];
+ lm = raster_[row3];
+ lr = raster_[row3 + 1];
+
+ alpha = defaultRGB_.getAlpha(raster_[row2]);
+
+ a = ((lr >> 16) & 0xff) - ((ul >> 16) & 0xff);
+ b = ((mr >> 16) & 0xff) - ((ml >> 16) & 0xff);
+ c = ((ur >> 16) & 0xff) - ((ll >> 16) & 0xff);
+ d = ((um >> 16) & 0xff) - ((lm >> 16) & 0xff);
+
+ rsum = a + b + c;
+ if (rsum < 0) rsum = -rsum;
+ a = a - c - d;
+ if (a < 0) a = -a;
+ if (rsum > a) rsum = a;
+ rsum /= 3;
+
+ a = ((lr >> 8) & 0xff) - ((ul >> 8) & 0xff);
+ b = ((mr >> 8) & 0xff) - ((ml >> 8) & 0xff);
+ c = ((ur >> 8) & 0xff) - ((ll >> 8) & 0xff);
+ d = ((um >> 8) & 0xff) - ((lm >> 8) & 0xff);
+
+ gsum = a + b + c;
+ if (gsum < 0) gsum = -gsum;
+ a = a - c - d;
+ if (a < 0) a = -a;
+ if (gsum > a) gsum = a;
+ gsum /= 3;
+
+ a = ((lr) & 0xff) - ((ul) & 0xff);
+ b = ((mr) & 0xff) - ((ml) & 0xff);
+ c = ((ur) & 0xff) - ((ll) & 0xff);
+ d = ((um) & 0xff) - ((lm) & 0xff);
+
+ bsum = a + b + c;
+ if (bsum < 0) bsum = -bsum;
+ a = a - c - d;
+ if (a < 0) a = -a;
+ if (bsum > a) bsum = a;
+ bsum /= 3;
+
+ pixels[y][x] = (alpha << 24) | (rsum << 16) | (gsum << 8) | bsum;
+
+ v = (((int)(rsum)*11 + ((int)(gsum) << 4) + (int)(bsum)*5) >> 5);
+
+ if (maxv < v)
+ maxv = v;
+ }
+
+ }
+
+ for (int y = 1; y < rows_ - 1; y++)
+ {
+ for (int x = 1; x < columns_ - 1; x++)
+ {
+ pixel = pixels[y][x];
+ alpha = (pixel >> 24) & 0xff;
+ red = (((pixel >> 16) & 0xff) * 255) / maxv;
+ green = (((pixel >> 8) & 0xff) * 255) / maxv;
+ blue = ((pixel & 0xff) * 255) / maxv;
+
+ if (red < 0) red = 0;
+ if (green < 0) green = 0;
+ if (blue < 0) blue = 0 ;
+
+ if (red > 255) red = 255;
+ if (green > 255) green = 255;
+ if (blue > 255) blue = 255;
+
+ pixels[y][x] = (alpha << 24) | (red << 16) | (green << 8) | blue;
+ }
+
+ consumer.setPixels(0, y, columns_, 1, defaultRGB_, pixels[y], 0, columns_);
+ }
+
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+ */
+}
diff --git a/java/ImageProcessing/filters/EmbossFilter.java b/java/ImageProcessing/filters/EmbossFilter.java
new file mode 100644
index 00000000000..3dd24cbbfa5
--- /dev/null
+++ b/java/ImageProcessing/filters/EmbossFilter.java
@@ -0,0 +1,75 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class EmbossFilter extends SpatialFilter
+{
+
+ public EmbossFilter()
+ {
+ }
+
+ public String info ()
+ {
+ return "Embosses an image.";
+ }
+
+ public void imageComplete(int status)
+ {
+ Timer timer = new Timer();
+
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error: " + status);
+ return;
+ }
+
+ int[] pixels = new int[columns_];
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, ul, um, ml, mr, lm, lr;
+ int new_grey = 0;
+ int alpha;
+
+ for (int x = 1; x < rows_ - 1; x++)
+ {
+ for (int y = 1; y < columns_ - 1; y++)
+ {
+
+ row1 = columns_*(x - 1) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+
+ ul = raster_[row1 - 1];
+ um = raster_[row1];
+ ml = raster_[row2 - 1];
+ mr = raster_[row2 + 1];
+ lm = raster_[row3];
+ lr = raster_[row3 + 1];
+
+ alpha = (raster_[row2] >> 24) & 0xff;
+
+ red = ((- (((ul >> 16) & 0xff) << 1) - ((um >> 16) & 0xff) -
+ ((ml >> 16) & 0xff) + ((mr >> 16) & 0xff) +
+ ((lm >> 16) & 0xff) + (((lr >> 16) & 0xff) << 1)) >> 3) + 128;
+
+ green = ((- (((ul >> 8) & 0xff) << 1) - ((um >> 8) & 0xff) -
+ ((ml >> 8) & 0xff) + ((mr >> 8) & 0xff) +
+ ((lm >> 8) & 0xff) + (((lr >> 8) & 0xff) << 1)) >> 3) + 128;
+
+ blue = ((- ((ul & 0xff) << 1) - (um & 0xff) -
+ (ml & 0xff) + (mr & 0xff) +
+ (lm & 0xff) + ((lr & 0xff) << 1)) >> 3) + 128;
+
+ new_grey = (((int)(red)*11 + ((int)(green) << 4) + (int)(blue)*5) >> 5);
+
+ pixels[y] = (alpha << 24) | (new_grey << 16) | (new_grey << 8) | new_grey;
+
+ }
+ consumer.setPixels(0, x, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+}
diff --git a/java/ImageProcessing/filters/MedFilter.java b/java/ImageProcessing/filters/MedFilter.java
new file mode 100644
index 00000000000..def0bd2075a
--- /dev/null
+++ b/java/ImageProcessing/filters/MedFilter.java
@@ -0,0 +1,6 @@
+package imaging.filters;
+
+public interface MedFilter
+{
+ String info ();
+}
diff --git a/java/ImageProcessing/filters/OilPaintFilter.java b/java/ImageProcessing/filters/OilPaintFilter.java
new file mode 100644
index 00000000000..e2eee743a44
--- /dev/null
+++ b/java/ImageProcessing/filters/OilPaintFilter.java
@@ -0,0 +1,68 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class OilPaintFilter extends SpatialFilter
+{
+ private int degree_ = 3;
+
+ public OilPaintFilter()
+ {
+ }
+
+ public OilPaintFilter(int degree)
+ {
+ degree_ = degree;
+ }
+
+ public void imageComplete(int status)
+ {
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error: " + status);
+ return;
+ }
+
+ int[] pixels = new int[columns_];
+ int[] nnrect = new int[degree_*degree_];
+ int offset = degree_/2, cnt = 0, maxcnt = 0, col = 0;
+
+ for (int y = offset; y < rows_ - offset; y++)
+ {
+ for (int x = offset; x < columns_ - offset; x++)
+ {
+
+ for (int i = 0; i < degree_*degree_; i++)
+ nnrect[i] = raster_[(y + (i / degree_ - 1))*columns_ + (x + (i % degree_ - 1)) ];
+
+ maxcnt = 0;
+ col = 0;
+ for (int i = 0; i < degree_*degree_; i++)
+ {
+ cnt = 1;
+
+ for (int j = i+1; j < degree_*degree_; j++)
+ {
+ if (nnrect[i] == nnrect[j])
+ cnt++;
+ }
+
+ if (cnt > maxcnt)
+ {
+ col = nnrect[i];
+ maxcnt = cnt;
+ }
+ }
+
+ pixels[x] = col;
+ }
+
+ consumer.setPixels(0, y, columns_, 1, defaultRGB_, pixels, 0, columns_);
+
+ }
+
+ consumer.imageComplete(status);
+ }
+
+}
diff --git a/java/ImageProcessing/filters/PixelizeFilter.java b/java/ImageProcessing/filters/PixelizeFilter.java
new file mode 100644
index 00000000000..18dcec5e771
--- /dev/null
+++ b/java/ImageProcessing/filters/PixelizeFilter.java
@@ -0,0 +1,111 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class PixelizeFilter extends SpatialFilter
+{
+ private int pwidth_ = 4;
+ private int pheight_ = 4;
+
+ public PixelizeFilter()
+ {
+ }
+
+ public PixelizeFilter(int pwidth, int pheight)
+ {
+ pwidth_ = pwidth;
+ pheight_ = pheight;
+ }
+
+ public void imageComplete(int status)
+ {
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error: " + status);
+ return;
+ }
+
+ int pixel;
+ int nsum, asum, rsum, gsum, bsum, nwide, nhigh, stx, sty, x, y;
+ int x_offset, y_offset, x_extent, y_extent;
+ int[] results = new int[pwidth_*pheight_];
+
+ nwide = (columns_ + pwidth_ - 1) / pwidth_;
+ nhigh = (rows_ + pheight_ - 1) / pheight_;
+
+ stx = -(nwide*pwidth_ - columns_)/2;
+ sty = -(nhigh*pheight_ - rows_)/2;
+
+ y = sty;
+ for (int i = 0; i < nhigh; i++, y += pheight_)
+ {
+ x = stx;
+
+ for (int j = 0; j < nwide; j++, x += pwidth_)
+ {
+ nsum = asum = rsum = bsum = gsum = 0;
+
+ for (int y1 = y; y1 < y + pheight_; y1++)
+ {
+ for (int x1 = x; x1 < x + pwidth_; x1++)
+ {
+ if (x1 >= 0 && y1 >= 0 && x1 < columns_ && y1 < rows_)
+ {
+ nsum++;
+ pixel = raster_[y1*columns_ + x1];
+
+ asum += (pixel >> 24) & 0xff;
+ rsum += (pixel >> 16) & 0xff;
+ gsum += (pixel >> 8 ) & 0xff;
+ bsum += pixel & 0xff;
+ }
+ }
+ }
+
+ if (nsum > 0)
+ {
+ rsum /= nsum;
+ gsum /= nsum;
+ bsum /= nsum;
+
+ if (asum < 0) asum = 0;
+ if (rsum < 0) rsum = 0;
+ if (gsum < 0) gsum = 0;
+ if (bsum < 0) bsum = 0 ;
+
+ if (asum > 255) asum = 255;
+ if (rsum > 255) rsum = 255;
+ if (gsum > 255) gsum = 255;
+ if (bsum > 255) bsum = 255;
+
+ }
+
+ for (int k = 0; k < pwidth_*pheight_; k++)
+ results[k] = (asum << 24) | (rsum << 16) | (gsum << 8) | bsum;
+
+ x_offset = x;
+ y_offset = y;
+ x_extent = pwidth_;
+ y_extent = pheight_;
+
+ if (x < 0)
+ x_offset = -x;
+
+ if (y < 0)
+ y_offset = -y;
+
+ if (x + pwidth_ > columns_)
+ x_extent = x - columns_;
+
+ if (y + pheight_ > rows_)
+ y_extent = y - rows_;
+
+ consumer.setPixels(x_offset, y_offset, x_extent, y_extent, defaultRGB_, results, 0, x_extent);
+
+ }
+ }
+
+ consumer.imageComplete(status);
+ }
+}
diff --git a/java/ImageProcessing/filters/RotateFilter.java b/java/ImageProcessing/filters/RotateFilter.java
new file mode 100644
index 00000000000..161392bb28d
--- /dev/null
+++ b/java/ImageProcessing/filters/RotateFilter.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * and its documentation for NON-COMMERCIAL purposes and without
+ * fee is hereby granted provided that this copyright notice
+ * appears in all copies. Please refer to the file "copyright.html"
+ * for further important copyright and licensing information.
+ *
+ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
+ * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+ * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+ */
+package imaging.filters;
+
+import java.awt.image.ColorModel;
+import java.awt.image.ImageFilter;
+import java.util.Hashtable;
+import java.awt.Rectangle;
+
+public class RotateFilter extends ImageFilter implements MedFilter
+{
+
+ private static ColorModel defaultRGB = ColorModel.getRGBdefault();
+
+ private double angle;
+ private double sin;
+ private double cos;
+ private double coord[] = new double[2];
+
+ private int raster[];
+ private int xoffset, yoffset;
+ private int srcW, srcH;
+ private int dstW, dstH;
+
+ public RotateFilter ()
+ {
+ this.angle = 90;
+ sin = Math.sin(this.angle);
+ cos = Math.cos(this.angle);
+ }
+
+
+ public RotateFilter(double angle) {
+ this.angle = angle;
+ sin = Math.sin(angle);
+ cos = Math.cos(angle);
+ }
+
+ public String info ()
+ {
+ return "Rotates an image";
+ }
+
+ public void transform(double x, double y, double[] retcoord) {
+ // Remember that the coordinate system is upside down so apply
+ // the transform as if the angle were negated.
+ // cos(-angle) = cos(angle)
+ // sin(-angle) = -sin(angle)
+ retcoord[0] = cos * x + sin * y;
+ retcoord[1] = cos * y - sin * x;
+ }
+
+ public void itransform(double x, double y, double[] retcoord) {
+ // Remember that the coordinate system is upside down so apply
+ // the transform as if the angle were negated. Since inverting
+ // the transform is also the same as negating the angle, itransform
+ // is calculated the way you would expect to calculate transform.
+ retcoord[0] = cos * x - sin * y;
+ retcoord[1] = cos * y + sin * x;
+ }
+
+ public void transformBBox(Rectangle rect) {
+ double minx = Double.POSITIVE_INFINITY;
+ double miny = Double.POSITIVE_INFINITY;
+ double maxx = Double.NEGATIVE_INFINITY;
+ double maxy = Double.NEGATIVE_INFINITY;
+ for (int y = 0; y <= 1; y++) {
+ for (int x = 0; x <= 1; x++) {
+ transform(rect.x + x * rect.width,
+ rect.y + y * rect.height,
+ coord);
+ minx = Math.min(minx, coord[0]);
+ miny = Math.min(miny, coord[1]);
+ maxx = Math.max(maxx, coord[0]);
+ maxy = Math.max(maxy, coord[1]);
+ }
+ }
+ rect.x = (int) Math.floor(minx);
+ rect.y = (int) Math.floor(miny);
+ rect.width = (int) Math.ceil(maxx) - rect.x + 1;
+ rect.height = (int) Math.ceil(maxy) - rect.y + 1;
+ }
+
+ public void setDimensions(int width, int height) {
+ Rectangle rect = new Rectangle(0, 0, width, height);
+ transformBBox(rect);
+ xoffset = -rect.x;
+ yoffset = -rect.y;
+ srcW = width;
+ srcH = height;
+ dstW = rect.width;
+ dstH = rect.height;
+ raster = new int[srcW * srcH];
+ consumer.setDimensions(dstW, dstH);
+ }
+
+ public void setColorModel(ColorModel model) {
+ consumer.setColorModel(defaultRGB);
+ }
+
+ public void setHints(int hintflags) {
+ consumer.setHints(TOPDOWNLEFTRIGHT
+ | COMPLETESCANLINES
+ | SINGLEPASS
+ | (hintflags & SINGLEFRAME));
+ }
+
+ public void setPixels(int x, int y, int w, int h, ColorModel model,
+ byte pixels[], int off, int scansize) {
+ int srcoff = off;
+ int dstoff = y * srcW + x;
+ for (int yc = 0; yc < h; yc++) {
+ for (int xc = 0; xc < w; xc++) {
+ raster[dstoff++] = model.getRGB(pixels[srcoff++] & 0xff);
+ }
+ srcoff += (scansize - w);
+ dstoff += (srcW - w);
+ }
+ }
+
+ public void setPixels(int x, int y, int w, int h, ColorModel model,
+ int pixels[], int off, int scansize) {
+ int srcoff = off;
+ int dstoff = y * srcW + x;
+ if (model == defaultRGB) {
+ for (int yc = 0; yc < h; yc++) {
+ srcoff += scansize;
+ dstoff += srcW;
+ }
+ } else {
+ for (int yc = 0; yc < h; yc++) {
+ for (int xc = 0; xc < w; xc++) {
+ raster[dstoff++] = model.getRGB(pixels[srcoff++]);
+ }
+ srcoff += (scansize - w);
+ dstoff += (srcW - w);
+ }
+ }
+ }
+
+ public void imageComplete(int status) {
+
+ if (status == IMAGEERROR || status == IMAGEABORTED) {
+ consumer.imageComplete(status);
+ return;
+ }
+ int pixels[] = new int[dstW];
+ for (int dy = 0; dy < dstH; dy++) {
+ itransform(0 - xoffset, dy - yoffset, coord);
+ double x1 = coord[0];
+ double y1 = coord[1];
+ itransform(dstW - xoffset, dy - yoffset, coord);
+ double x2 = coord[0];
+ double y2 = coord[1];
+ double xinc = (x2 - x1) / dstW;
+ double yinc = (y2 - y1) / dstW;
+ for (int dx = 0; dx < dstW; dx++) {
+ int sx = (int) Math.round(x1);
+ int sy = (int) Math.round(y1);
+ if (sx < 0 || sy < 0 || sx >= srcW || sy >= srcH) {
+ pixels[dx] = 0;
+ } else {
+ pixels[dx] = raster[sy * srcW + sx];
+ }
+ x1 += xinc;
+ y1 += yinc;
+ }
+ consumer.setPixels(0, dy, dstW, 1, defaultRGB, pixels, 0, dstW);
+ }
+ consumer.imageComplete(status);
+ }
+}
diff --git a/java/ImageProcessing/filters/SharpenFilter.java b/java/ImageProcessing/filters/SharpenFilter.java
new file mode 100644
index 00000000000..079c2b93c91
--- /dev/null
+++ b/java/ImageProcessing/filters/SharpenFilter.java
@@ -0,0 +1,262 @@
+package imaging.filters;
+
+import java.awt.image.*;
+import java.util.*;
+
+public class SharpenFilter extends SpatialFilter
+{
+ double percentage_ = 75.0;
+
+ public SharpenFilter()
+ {
+ }
+
+ public SharpenFilter(double percentage)
+ {
+ percentage_ = percentage;
+ }
+
+ public String info ()
+ {
+ return "Sharpens an image.";
+ }
+
+
+ public void imageComplete(int status)
+ {
+ System.out.println("Image Complete called");
+
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error");
+ return;
+ }
+
+ HSV hsv;
+ RGB rgb;
+ int pixel, alpha;
+ int[] pixels = new int[columns_];
+ double fact, ifact, hue,sat,val, vsum;
+ double[] line0 = new double[columns_],
+ linep1 = new double[columns_],
+ linem1 = new double[columns_],
+ tmpptr;
+
+ fact = percentage_/100.0;
+ ifact = 1.0 - fact;
+
+ for (int x = 0; x < columns_; x++)
+ {
+ pixel = raster_[x];
+ hsv = getHSV(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), (pixel & 0xff));
+ line0[x] = hsv.val_;
+ }
+
+ for (int x = columns_, index = 0; x < 2*columns_; x++, index++)
+ {
+ pixel = raster_[x];
+ hsv = getHSV(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), (pixel & 0xff));
+ linep1[index] = hsv.val_;
+ }
+
+ for (int y = 1; y < rows_ - 1; y++)
+ {
+ tmpptr = linem1;
+ linem1 = line0;
+ line0 = linep1;
+ linep1 = tmpptr;
+
+ for (int x = columns_*(y+1), index= 0; x < columns_*(y+2); x++, index++)
+ {
+ pixel = raster_[x];
+ hsv = getHSV(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), (pixel & 0xff));
+ linep1[index] = hsv.val_;
+ }
+
+ for (int x = 1; x < columns_ - 1; x++)
+ {
+ vsum = 0.0;
+ vsum = linem1[x-1] + linem1[x] + linem1[x+1] +
+ line0[x-1] + line0[x] + line0[x + 1] +
+ linep1[x-1] + linep1[x] + linep1[x + 1];
+
+ pixel = raster_[y*columns_ + x];
+ alpha = (pixel >> 24) & 0xff;
+ hsv = getHSV(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), (pixel & 0xff));
+ hsv.val_ = ((hsv.val_ - (fact * vsum) / 9) / ifact);
+ if (hsv.val_ < 1.0)
+ {
+ if (hsv.val_ < 0.0)
+ hsv.val_ = 0.0;
+ }
+ else
+ hsv.val_ = 1.0;
+
+ rgb = getRGB(hsv.hue_, hsv.sat_, hsv.val_);
+
+ if (rgb.red_ < 0) rgb.red_ = 0;
+ if (rgb.green_ < 0) rgb.green_ = 0;
+ if (rgb.blue_ < 0) rgb.blue_ = 0 ;
+
+ if (rgb.red_ > 255) rgb.red_ = 255;
+ if (rgb.green_ > 255) rgb.green_ = 255;
+ if (rgb.blue_ > 255) rgb.blue_ = 255;
+
+ pixels[x] =
+ (alpha << 24) | (rgb.red_ << 16) | (rgb.green_ << 8) | rgb.blue_;
+ }
+
+ consumer.setPixels(0, y, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+
+
+ System.out.println("Finished altering image");
+ consumer.imageComplete(status);
+ }
+
+
+ static private HSV getHSV(int red, int green, int blue)
+ {
+ double rd, gd, bd, max, min, del, rc, gc, bc;
+ HSV hsv = new HSV();
+
+ /* convert RGB to HSV */
+ rd = red / 255.0; /* rd,gd,bd range 0-1 instead of 0-255 */
+ gd = green / 255.0;
+ bd = blue / 255.0;
+
+ /* compute maximum of rd,gd,bd */
+ if (rd >= gd)
+ {
+ if (rd >= bd)
+ max = rd;
+ else
+ max = bd;
+ }
+ else
+ {
+ if (gd >= bd)
+ max = gd;
+ else
+ max = bd;
+ }
+
+ /* compute minimum of rd,gd,bd */
+ if (rd<=gd)
+ {
+ if (rd<=bd)
+ min = rd;
+ else
+ min = bd;
+ }
+ else
+ {
+ if (gd<=bd)
+ min = gd;
+ else
+ min = bd;
+ }
+
+ del = max - min;
+ hsv.val_ = max;
+
+ if (max != 0.0)
+ hsv.sat_ = (del) / max;
+ else
+ hsv.sat_ = 0.0;
+
+ hsv.hue_ = -1;
+
+ if (hsv.sat_ != 0.0)
+ {
+ rc = (max - rd) / del;
+ gc = (max - gd) / del;
+ bc = (max - bd) / del;
+
+ if (rd == max)
+ hsv.hue_ = bc - gc;
+ else
+ if (gd == max)
+ hsv.hue_ = 2 + rc - bc;
+ else
+ if (bd == max)
+ hsv.hue_ = 4 + gc - rc;
+
+ hsv.hue_ *= 60;
+ if (hsv.hue_<0)
+ hsv.hue_ += 360;
+ }
+
+ return hsv;
+ }
+
+ static private RGB getRGB(double hue, double sat, double val)
+ {
+ int j;
+ double rd, gd, bd;
+ double f, p, q, t;
+ RGB rgb = new RGB();
+
+ /* convert HSV back to RGB */
+ if (hue == -1 || sat == 0.0)
+ {
+ rd = val; gd = val; bd = val;
+ }
+ else
+ {
+ if (hue==360.0) hue = 0.0;
+ hue = hue / 60.0;
+ j = (int) Math.floor(hue);
+ if (j<0) j=0; /* either hue or floor seem to go neg on some sys */
+ f = hue - j;
+ p = val * (1-sat);
+ q = val * (1 - (sat*f));
+ t = val * (1 - (sat*(1 - f)));
+
+ switch (j) {
+ case 0: rd = val; gd = t; bd = p; break;
+ case 1: rd = q; gd = val; bd = p; break;
+ case 2: rd = p; gd = val; bd = t; break;
+ case 3: rd = p; gd = q; bd = val; break;
+ case 4: rd = t; gd = p; bd = val; break;
+ case 5: rd = val; gd = p; bd = q; break;
+ default: rd = val; gd = t; bd = p; break; /* never happen */
+ }
+ }
+
+ rgb.red_ = (int) Math.floor((rd * 255.0) + 0.5);
+ rgb.green_ = (int) Math.floor((gd * 255.0) + 0.5);
+ rgb.blue_ = (int) Math.floor((bd * 255.0) + 0.5);
+
+
+ return rgb;
+ }
+}
+
+class HSV
+{
+ public double hue_;
+ public double sat_;
+ public double val_;
+}
+
+class RGB
+{
+ public int red_;
+ public int green_;
+ public int blue_;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/ImageProcessing/filters/SpatialFilter.java b/java/ImageProcessing/filters/SpatialFilter.java
new file mode 100644
index 00000000000..1b6fb8d615d
--- /dev/null
+++ b/java/ImageProcessing/filters/SpatialFilter.java
@@ -0,0 +1,201 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class SpatialFilter extends ImageFilter implements MedFilter
+{
+ public SpatialFilter()
+ {
+ }
+
+ public SpatialFilter(int[][] matrix, int degree)
+ {
+ this(matrix, degree, 1, 0);
+ }
+
+ public SpatialFilter(int[][] matrix, int degree, int div_factor, int offset)
+ {
+ matrix_ = matrix;
+ div_factor_ = div_factor;
+ offset_ = offset;
+ degree_ = degree;
+ }
+
+ public void setFilter(int[][] matrix, int degree, int div_factor)
+ {
+ matrix_ = matrix;
+ degree_ = degree;
+ div_factor_ = div_factor;
+ }
+
+ public String info ()
+ {
+ return "Base Filter class. Doesn't do much";
+ }
+
+ public void setDimensions(int width, int height)
+ {
+ rows_ = height;
+ columns_ = width;
+ raster_ = new int[width * height];
+ consumer.setDimensions(width, height);
+ }
+
+ public void setPixels(int x, int y, int w, int h, ColorModel model,
+ byte pixels[], int off, int scansize)
+ {
+ int source_offset = off;
+ int dest_offset = y * columns_ + x;
+
+ for (int y_ind = 0; y_ind < h; y_ind++)
+ {
+ for (int x_ind = 0; x_ind < w; x_ind++)
+ {
+ raster_[dest_offset] = model.getRGB(pixels[source_offset] & 0xff);
+ dest_offset++;
+ source_offset++;
+ }
+
+ source_offset += (scansize - w);
+ dest_offset += (columns_ - w);
+ }
+ }
+
+ public void setPixels(int x, int y, int w, int h, ColorModel model,
+ int pixels[], int off, int scansize)
+ {
+ int source_offset = off;
+ int dest_offset = y * columns_ + x;
+
+ if (model == defaultRGB_)
+ {
+ for (int yc = 0; yc < h; yc++)
+ {
+ System.arraycopy(pixels, source_offset, raster_, dest_offset, w);
+ source_offset += scansize;
+ dest_offset += columns_;
+ }
+ }
+ else
+ {
+
+ for (int yc = 0; yc < h; yc++)
+ {
+ for (int xc = 0; xc < w; xc++)
+ {
+ raster_[dest_offset] = model.getRGB(pixels[source_offset]);
+ dest_offset++;
+ source_offset++;
+ }
+ source_offset += (scansize - w);
+ dest_offset += (columns_ - w);
+ }
+ }
+ }
+
+ public void setColorModel(ColorModel model)
+ {
+ consumer.setColorModel(defaultRGB_);
+ }
+
+ public void setHints(int hintflags)
+ {
+ consumer.setHints(TOPDOWNLEFTRIGHT
+ | COMPLETESCANLINES
+ | SINGLEPASS
+ | (hintflags & SINGLEFRAME));
+ }
+
+
+ public void imageComplete(int status)
+ {
+ System.out.println("Image Complete called");
+
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error");
+ return;
+ }
+
+ int[] pixels = new int[columns_];
+ int[][] new_raster= expandRaster();
+ int pixel = 0;
+ int red, green, blue;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha;
+
+ for (int x = raster_offset_; x < rows_; x++)
+ {
+ for (int y = raster_offset_; y < columns_; y++)
+ {
+ new_red = 0; new_green = 0; new_blue = 0;
+ alpha = defaultRGB_.getAlpha(new_raster[x][y]);
+ for (int i = 0; i < degree_; i++)
+ {
+ for (int j = 0; j < degree_; j++)
+ {
+ pixel = new_raster[x + (i - raster_offset_)][y + (j - raster_offset_)];
+
+ red = defaultRGB_.getRed(pixel) * matrix_[i][j];
+ blue = defaultRGB_.getBlue(pixel) * matrix_[i][j];
+ green = defaultRGB_.getGreen(pixel) * matrix_[i][j];
+
+ new_red += red;
+ new_green += green;
+ new_blue += blue;
+ }
+ }
+
+ new_red /= div_factor_;
+ new_green /= div_factor_;
+ new_blue /= div_factor_;
+
+ new_red = Math.min(Math.abs(new_red), 255);
+ new_green = Math.min(Math.abs(new_green), 255);
+ new_blue = Math.min(Math.abs(new_blue), 255);
+
+ pixels[y - raster_offset_] =
+ (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+ }
+
+ consumer.setPixels(0, x - raster_offset_, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+
+ System.out.println("Finished altering image");
+ consumer.imageComplete(status);
+ }
+
+ protected int[][] expandRaster()
+ {
+ int[][] new_raster;
+ int index = 0;
+
+ raster_offset_ = degree_ / 2;
+ new_raster = new int[rows_ + raster_offset_*2][columns_ + raster_offset_*2];
+
+ for (int x = 0; x < rows_; x++)
+ {
+ for (int y = 0; y < columns_; y++)
+ {
+ new_raster[x + raster_offset_][y + raster_offset_] = raster_[index];
+ index++;
+ }
+ }
+
+ return new_raster;
+ }
+
+ protected int intensity(int rd, int gn, int bl)
+ {
+ return (((int)(rd)*11 + (int)(gn)*16 + (int)(bl)*5) >> 5);
+ }
+
+ protected static ColorModel defaultRGB_ = ColorModel.getRGBdefault();
+ protected int[][] matrix_;
+ protected int[] raster_;
+ protected int rows_ = 0, columns_ = 0;
+ protected int div_factor_ = 1, offset_, degree_;
+ protected int raster_offset_ = 0;
+
+}
diff --git a/java/ImageProcessing/filters/SpreadFilter.java b/java/ImageProcessing/filters/SpreadFilter.java
new file mode 100644
index 00000000000..03b12eb8c4c
--- /dev/null
+++ b/java/ImageProcessing/filters/SpreadFilter.java
@@ -0,0 +1,119 @@
+package imaging.filters;
+
+import java.awt.image.*;
+import java.util.Random;
+
+public class SpreadFilter extends SpatialFilter
+{
+ private int pwidth_ = 5;
+ private int pheight_ = 5;
+
+ public SpreadFilter()
+ {
+ }
+
+ public SpreadFilter(int pwidth, int pheight)
+ {
+ pwidth_ = pwidth;
+ pheight_ = pheight;
+ }
+
+ public void imageComplete(int status)
+ {
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error: " + status);
+ return;
+ }
+
+ Random rand = new Random();
+ int[] pixels = new int[columns_];
+ int d, dx, dy, x1, y1, xrng, xoff, yrng, yoff;
+ int minx, maxx, miny, maxy, rdist, tmp;
+
+ for (int y = 0; y < rows_; y++)
+ {
+
+ for (int x = 0; x < columns_; x++)
+ {
+
+ if (pwidth_ < 0)
+ {
+ d = (pwidth_ < 0 ? -pwidth_ : pwidth_);
+
+ minx = x - d;
+ if (minx < 0)
+ minx = 0;
+
+ maxx = x + d;
+ if (maxx >= columns_)
+ maxx = columns_ - 1;
+
+ tmp = rand.nextInt();
+ tmp = (tmp < 0 ? -tmp : tmp);
+ x1 = minx + tmp % ((maxx - minx) + 1);
+
+ miny = y - d;
+ if (miny < 0)
+ miny = 0;
+
+ maxy = y + d;
+ if (maxy >= rows_)
+ maxy = rows_ - 1;
+
+ rdist = d - (x1 < x ? -(x1 - x) : x1 - x);
+ if (y - miny > rdist)
+ miny = (y - rdist);
+ if (maxy - y > rdist)
+ maxy = (y + rdist);
+
+ tmp = rand.nextInt();
+ tmp = (tmp < 0 ? -tmp : tmp);
+ y1 = miny + tmp % ((maxy - miny) + 1);
+ }
+ else
+ {
+ minx = x - pwidth_;
+ if (minx < 0)
+ minx = 0;
+
+ maxx = x + pwidth_;
+ if (maxx >= columns_)
+ maxx = columns_ - 1;
+
+ tmp = rand.nextInt();
+ tmp = (tmp < 0 ? -tmp : tmp);
+ x1 = minx + tmp % ((maxx - minx) + 1);
+
+ miny = y - pheight_;
+ if (miny < 0)
+ miny = 0;
+
+ maxy = y + pheight_;
+ if (maxx >= columns_)
+ maxx = columns_ - 1;
+
+ tmp = rand.nextInt();
+ tmp = (tmp < 0 ? -tmp : tmp);
+ y1 = miny + tmp % ((maxy - miny) + 1);
+ }
+
+ if (x1 >= 0 && y1 >= 0 && x1 < columns_ && y1 < rows_)
+ {
+ int pixel = raster_[y1*columns_ + x1];
+ int alpha = (pixel >> 24) & 0xff;
+ int red = (pixel >> 16) & 0xff;
+ int green = (pixel >> 8) & 0xff;
+ int blue = pixel & 0xff;
+
+ pixels[x] = (alpha << 24) | (red << 16) | (green << 8) | blue;
+ }
+ }
+
+ consumer.setPixels(0, y, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+
+ consumer.imageComplete(status);
+ }
+}
diff --git a/java/ImageProcessing/filters/Timer.java b/java/ImageProcessing/filters/Timer.java
new file mode 100644
index 00000000000..609ec8aa366
--- /dev/null
+++ b/java/ImageProcessing/filters/Timer.java
@@ -0,0 +1,23 @@
+package imaging.filters;
+
+public class Timer
+{
+ long start_time_;
+ long stop_time_;
+
+ public void start()
+ {
+ start_time_ = System.currentTimeMillis();
+ }
+
+ public void stop()
+ {
+ stop_time_ = System.currentTimeMillis();
+ }
+
+ public String toString()
+ {
+ long total = stop_time_ - start_time_;
+ return "Total Time:" + total + " ms";
+ }
+}