summaryrefslogtreecommitdiff
path: root/java/ImageProcessing
diff options
context:
space:
mode:
authorpjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-07 17:24:31 +0000
committerpjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-07 17:24:31 +0000
commita44df1655315ea029033bf81f555f8d2dc55f56f (patch)
tree6ba1dda005a8d247dc772b1f7133f50ec9c0134d /java/ImageProcessing
parent398bd1fdc56cba89870dc1f18a590e187d7c2fdc (diff)
downloadATCD-a44df1655315ea029033bf81f555f8d2dc55f56f.tar.gz
Added image filters to CVS
Diffstat (limited to 'java/ImageProcessing')
-rw-r--r--java/ImageProcessing/filters/Assert.java33
-rw-r--r--java/ImageProcessing/filters/BleachFilter.java60
-rw-r--r--java/ImageProcessing/filters/DarkenFilter.java48
-rw-r--r--java/ImageProcessing/filters/DissolveFilter.java52
-rw-r--r--java/ImageProcessing/filters/EmbossFilter.java90
-rw-r--r--java/ImageProcessing/filters/FivebyfiveFilter.java181
-rw-r--r--java/ImageProcessing/filters/MeanFilter.java147
-rw-r--r--java/ImageProcessing/filters/MedFilter.java6
-rw-r--r--java/ImageProcessing/filters/NinebynineFilter.java349
-rw-r--r--java/ImageProcessing/filters/RotateFilter.java186
-rw-r--r--java/ImageProcessing/filters/SharpenFilter.java137
-rw-r--r--java/ImageProcessing/filters/SobelFilter.java117
-rw-r--r--java/ImageProcessing/filters/SpatialFilter.java187
-rw-r--r--java/ImageProcessing/filters/ThreebythreeFilter.java133
-rw-r--r--java/ImageProcessing/filters/Timer.java23
-rw-r--r--java/ImageProcessing/filters/UnsharpFilter.java241
16 files changed, 1990 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/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/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/EmbossFilter.java b/java/ImageProcessing/filters/EmbossFilter.java
new file mode 100644
index 00000000000..4fb61842ebc
--- /dev/null
+++ b/java/ImageProcessing/filters/EmbossFilter.java
@@ -0,0 +1,90 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class EmbossFilter extends SpatialFilter
+{
+ int[] grey_raster_;
+
+ 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_];
+ createColorRasters();
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int new_grey = 0;
+ int alpha;
+
+ for (int x = 1; x < rows_; x++)
+ {
+ for (int y = 1; y < columns_; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 1) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+
+ new_grey =
+ (- grey_raster_[row1 - 1]
+ - grey_raster_[row1]
+ - grey_raster_[row2 - 1]
+ + grey_raster_[row2 + 1]
+ + grey_raster_[row3]
+ + grey_raster_[row3 + 1])/6 + 128;
+
+ if (new_grey > 255)
+ new_grey = 255;
+
+ pixels[y - 1] = (alpha << 24) | (new_grey << 16) | (new_grey << 8) | new_grey;
+
+ }
+ consumer.setPixels(0, x-1, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+
+ protected void createColorRasters()
+ {
+ int off = 0;
+ int index = columns_;
+ int pixel;
+ grey_raster_ = new int[(rows_ + 1)*(columns_ + 1)];
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y ++)
+ {
+ index++;
+ pixel = raster_[off];
+ grey_raster_[index] = (int)(((double).212671*(double)defaultRGB_.getRed(pixel))
+ + (double)((double).715160*(double)defaultRGB_.getGreen(pixel))
+ + (double)((double).072169*(double)defaultRGB_.getBlue(pixel)));
+
+ off++;
+ }
+ }
+ }
+}
diff --git a/java/ImageProcessing/filters/FivebyfiveFilter.java b/java/ImageProcessing/filters/FivebyfiveFilter.java
new file mode 100644
index 00000000000..af548c8d549
--- /dev/null
+++ b/java/ImageProcessing/filters/FivebyfiveFilter.java
@@ -0,0 +1,181 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class FivebyfiveFilter extends SpatialFilter
+{
+ protected int[] red_raster_;
+ protected int[] green_raster_;
+ protected int[] blue_raster_;
+ protected int[] new_matrix_;
+
+ public FivebyfiveFilter()
+ {
+ }
+
+ public FivebyfiveFilter(int[] matrix, int degree, int div_factor, int offset)
+ {
+ new_matrix_ = matrix;
+ degree_ = degree;
+ div_factor_ = div_factor;
+ offset_ = offset;
+ }
+
+ public String info ()
+ {
+ return "Base class filter. Doesn't do much";
+ }
+
+ 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_];
+ createColorRasters();
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha;
+
+ for (int x = 2; x < rows_ + 2; x++)
+ {
+ for (int y = 2; y < columns_ + 2; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 2) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+
+ new_red =
+ (red_raster_[row1 - 2] * new_matrix_[0]
+ + red_raster_[row1 - 1] * new_matrix_[1]
+ + red_raster_[row1] * new_matrix_[2]
+ + red_raster_[row1 + 1] * new_matrix_[3]
+ + red_raster_[row1 + 2] * new_matrix_[4]
+ + red_raster_[row2 - 2] * new_matrix_[5]
+ + red_raster_[row2 - 1] * new_matrix_[6]
+ + red_raster_[row2] * new_matrix_[7]
+ + red_raster_[row2 + 1] * new_matrix_[8]
+ + red_raster_[row2 + 2] * new_matrix_[9]
+ + red_raster_[row3 - 2] * new_matrix_[10]
+ + red_raster_[row3 - 1] * new_matrix_[11]
+ + red_raster_[row3] * new_matrix_[12]
+ + red_raster_[row3 + 1] * new_matrix_[13]
+ + red_raster_[row3 + 2] * new_matrix_[14]
+ + red_raster_[row4 - 2] * new_matrix_[15]
+ + red_raster_[row4 - 1] * new_matrix_[16]
+ + red_raster_[row4] * new_matrix_[17]
+ + red_raster_[row4 + 1] * new_matrix_[18]
+ + red_raster_[row4 + 2] * new_matrix_[19]
+ + red_raster_[row5 - 2] * new_matrix_[20]
+ + red_raster_[row5 - 1] * new_matrix_[21]
+ + red_raster_[row5] * new_matrix_[22]
+ + red_raster_[row5 + 1] * new_matrix_[23]
+ + red_raster_[row5 + 2] * new_matrix_[24])/div_factor_;
+
+ new_green =
+ (green_raster_[row1 - 2] * new_matrix_[0]
+ + green_raster_[row1 - 1] * new_matrix_[1]
+ + green_raster_[row1] * new_matrix_[2]
+ + green_raster_[row1 + 1] * new_matrix_[3]
+ + green_raster_[row1 + 2] * new_matrix_[4]
+ + green_raster_[row2 - 2] * new_matrix_[5]
+ + green_raster_[row2 - 1] * new_matrix_[6]
+ + green_raster_[row2] * new_matrix_[7]
+ + green_raster_[row2 + 1] * new_matrix_[8]
+ + green_raster_[row2 + 2] * new_matrix_[9]
+ + green_raster_[row3 - 2] * new_matrix_[10]
+ + green_raster_[row3 - 1] * new_matrix_[11]
+ + green_raster_[row3] * new_matrix_[12]
+ + green_raster_[row3 + 1] * new_matrix_[13]
+ + green_raster_[row3 + 2] * new_matrix_[14]
+ + green_raster_[row4 - 2] * new_matrix_[15]
+ + green_raster_[row4 - 1] * new_matrix_[16]
+ + green_raster_[row4] * new_matrix_[17]
+ + green_raster_[row4 + 1] * new_matrix_[18]
+ + green_raster_[row4 + 2] * new_matrix_[19]
+ + green_raster_[row5 - 2] * new_matrix_[20]
+ + green_raster_[row5 - 1] * new_matrix_[21]
+ + green_raster_[row5] * new_matrix_[22]
+ + green_raster_[row5 + 1] * new_matrix_[23]
+ + green_raster_[row5 + 2] * new_matrix_[24])/div_factor_;
+
+ new_blue =
+ (blue_raster_[row1 - 2] * new_matrix_[0]
+ + blue_raster_[row1 - 1] * new_matrix_[1]
+ + blue_raster_[row1] * new_matrix_[2]
+ + blue_raster_[row1 + 1] * new_matrix_[3]
+ + blue_raster_[row1 + 2] * new_matrix_[4]
+ + blue_raster_[row2 - 2] * new_matrix_[5]
+ + blue_raster_[row2 - 1] * new_matrix_[6]
+ + blue_raster_[row2] * new_matrix_[7]
+ + blue_raster_[row2 + 1] * new_matrix_[8]
+ + blue_raster_[row2 + 2] * new_matrix_[9]
+ + blue_raster_[row3 - 2] * new_matrix_[10]
+ + blue_raster_[row3 - 1] * new_matrix_[11]
+ + blue_raster_[row3] * new_matrix_[12]
+ + blue_raster_[row3 + 1] * new_matrix_[13]
+ + blue_raster_[row3 + 2] * new_matrix_[14]
+ + blue_raster_[row4 - 2] * new_matrix_[15]
+ + blue_raster_[row4 - 1] * new_matrix_[16]
+ + blue_raster_[row4] * new_matrix_[17]
+ + blue_raster_[row4 + 1] * new_matrix_[18]
+ + blue_raster_[row4 + 2] * new_matrix_[19]
+ + blue_raster_[row5 - 2] * new_matrix_[20]
+ + blue_raster_[row5 - 1] * new_matrix_[21]
+ + blue_raster_[row5] * new_matrix_[22]
+ + blue_raster_[row5 + 1] * new_matrix_[23]
+ + blue_raster_[row5 + 2] * new_matrix_[24])/div_factor_;
+
+ if (new_red > 255)
+ new_red = 255;
+
+ if (new_green > 255)
+ new_green = 255;
+
+ if (new_blue > 255)
+ new_blue = 255;
+
+ pixels[y - 2] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ consumer.setPixels(0, x-2, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+
+ protected void createColorRasters()
+ {
+ int off = 0;
+ int index = columns_;
+ int pixel;
+ red_raster_ = new int[(rows_ + 4)*(columns_ + 4)];
+ green_raster_ = new int[red_raster_.length];
+ blue_raster_ = new int[red_raster_.length];
+
+ for (int x = 2; x < rows_ + 2; x++)
+ {
+ for (int y = 2; y < columns_ + 2; y ++)
+ {
+ index++;
+ pixel = raster_[off];
+ red_raster_[index] = defaultRGB_.getRed(pixel);
+ green_raster_[index] = defaultRGB_.getGreen(pixel);
+ blue_raster_[index] = defaultRGB_.getBlue(pixel);
+ off++;
+ }
+ }
+ }
+}
diff --git a/java/ImageProcessing/filters/MeanFilter.java b/java/ImageProcessing/filters/MeanFilter.java
new file mode 100644
index 00000000000..95969246524
--- /dev/null
+++ b/java/ImageProcessing/filters/MeanFilter.java
@@ -0,0 +1,147 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class MeanFilter extends FivebyfiveFilter
+{
+ public MeanFilter()
+ {
+ }
+
+ public String info ()
+ {
+ return "Blurs an image.";
+ }
+
+ 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_];
+ createColorRasters();
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha;
+
+ for (int x = 2; x < rows_ + 2; x++)
+ {
+ for (int y = 2; y < columns_ + 2; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 2) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+
+ new_red =
+ (red_raster_[row1 - 2]
+ + red_raster_[row1 - 1]
+ + red_raster_[row1]
+ + red_raster_[row1 + 1]
+ + red_raster_[row1 + 2]
+ + red_raster_[row2 - 2]
+ + red_raster_[row2 - 1]
+ + red_raster_[row2]
+ + red_raster_[row2 + 1]
+ + red_raster_[row2 + 2]
+ + red_raster_[row3 - 2]
+ + red_raster_[row3 - 1]
+ + red_raster_[row3]
+ + red_raster_[row3 + 1]
+ + red_raster_[row3 + 2]
+ + red_raster_[row4 - 2]
+ + red_raster_[row4 - 1]
+ + red_raster_[row4]
+ + red_raster_[row4 + 1]
+ + red_raster_[row4 + 2]
+ + red_raster_[row5 - 2]
+ + red_raster_[row5 - 1]
+ + red_raster_[row5]
+ + red_raster_[row5 + 1]
+ + red_raster_[row5 + 2])/25;
+
+ new_green =
+ (green_raster_[row1 - 2]
+ + green_raster_[row1 - 1]
+ + green_raster_[row1]
+ + green_raster_[row1 + 1]
+ + green_raster_[row1 + 2]
+ + green_raster_[row2 - 2]
+ + green_raster_[row2 - 1]
+ + green_raster_[row2]
+ + green_raster_[row2 + 1]
+ + green_raster_[row2 + 2]
+ + green_raster_[row3 - 2]
+ + green_raster_[row3 - 1]
+ + green_raster_[row3]
+ + green_raster_[row3 + 1]
+ + green_raster_[row3 + 2]
+ + green_raster_[row4 - 2]
+ + green_raster_[row4 - 1]
+ + green_raster_[row4]
+ + green_raster_[row4 + 1]
+ + green_raster_[row4 + 2]
+ + green_raster_[row5 - 2]
+ + green_raster_[row5 - 1]
+ + green_raster_[row5]
+ + green_raster_[row5 + 1]
+ + green_raster_[row5 + 2])/25;
+
+ new_blue =
+ (blue_raster_[row1 - 2]
+ + blue_raster_[row1 - 1]
+ + blue_raster_[row1]
+ + blue_raster_[row1 + 1]
+ + blue_raster_[row1 + 2]
+ + blue_raster_[row2 - 2]
+ + blue_raster_[row2 - 1]
+ + blue_raster_[row2]
+ + blue_raster_[row2 + 1]
+ + blue_raster_[row2 + 2]
+ + blue_raster_[row3 - 2]
+ + blue_raster_[row3 - 1]
+ + blue_raster_[row3]
+ + blue_raster_[row3 + 1]
+ + blue_raster_[row3 + 2]
+ + blue_raster_[row4 - 2]
+ + blue_raster_[row4 - 1]
+ + blue_raster_[row4]
+ + blue_raster_[row4 + 1]
+ + blue_raster_[row4 + 2]
+ + blue_raster_[row5 - 2]
+ + blue_raster_[row5 - 1]
+ + blue_raster_[row5]
+ + blue_raster_[row5 + 1]
+ + blue_raster_[row5 + 2])/25;
+
+
+ if (new_red > 255)
+ new_red = 255;
+
+ if (new_green > 255)
+ new_green = 255;
+
+ if (new_blue > 255)
+ new_blue = 255;
+
+ pixels[y - 2] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ consumer.setPixels(0, x-2, 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/NinebynineFilter.java b/java/ImageProcessing/filters/NinebynineFilter.java
new file mode 100644
index 00000000000..8c3694033b2
--- /dev/null
+++ b/java/ImageProcessing/filters/NinebynineFilter.java
@@ -0,0 +1,349 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class NinebynineFilter extends SpatialFilter
+{
+ int[] red_raster_;
+ int[] green_raster_;
+ int[] blue_raster_;
+ int[] new_matrix_;
+
+ public NinebynineFilter(int[] matrix, int degree, int div_factor, int offset)
+ {
+ new_matrix_ = matrix;
+ degree_ = degree;
+ div_factor_ = div_factor;
+ offset_ = offset;
+ }
+
+ public String info ()
+ {
+ return "Base class filter. Doesn't do much";
+ }
+
+ 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_];
+ createColorRasters();
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5, row6, row7, row8, row9;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha;
+
+ for (int x = 4; x < rows_ + 4; x++)
+ {
+ for (int y = 4; y < columns_ + 4; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 4) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+ row6 = row5 + columns_;
+ row7 = row6 + columns_;
+ row8 = row7 + columns_;
+ row9 = row8 + columns_;
+
+ new_red =
+ (red_raster_[row1 - 4] * new_matrix_[0]
+ + red_raster_[row1 - 3] * new_matrix_[1]
+ + red_raster_[row1 - 2] * new_matrix_[2]
+ + red_raster_[row1 - 1] * new_matrix_[3]
+ + red_raster_[row1] * new_matrix_[4]
+ + red_raster_[row1 + 1] * new_matrix_[5]
+ + red_raster_[row1 + 2] * new_matrix_[6]
+ + red_raster_[row1 + 3] * new_matrix_[7]
+ + red_raster_[row1 + 4] * new_matrix_[8]
+ + red_raster_[row2 - 4] * new_matrix_[9]
+ + red_raster_[row2 - 3] * new_matrix_[10]
+ + red_raster_[row2 - 2] * new_matrix_[11]
+ + red_raster_[row2 - 1] * new_matrix_[12]
+ + red_raster_[row2] * new_matrix_[13]
+ + red_raster_[row2 + 1] * new_matrix_[14]
+ + red_raster_[row2 + 2] * new_matrix_[15]
+ + red_raster_[row2 + 3] * new_matrix_[16]
+ + red_raster_[row2 + 4] * new_matrix_[17]
+ + red_raster_[row3 - 4] * new_matrix_[18]
+ + red_raster_[row3 - 3] * new_matrix_[19]
+ + red_raster_[row3 - 2] * new_matrix_[20]
+ + red_raster_[row3 - 1] * new_matrix_[21]
+ + red_raster_[row3] * new_matrix_[22]
+ + red_raster_[row3 + 1] * new_matrix_[23]
+ + red_raster_[row3 + 2] * new_matrix_[24]
+ + red_raster_[row3 + 3] * new_matrix_[25]
+ + red_raster_[row3 + 4] * new_matrix_[26]
+ + red_raster_[row4 - 4] * new_matrix_[27]
+ + red_raster_[row4 - 3] * new_matrix_[28]
+ + red_raster_[row4 - 2] * new_matrix_[29]
+ + red_raster_[row4 - 1] * new_matrix_[30]
+ + red_raster_[row4] * new_matrix_[31]
+ + red_raster_[row4 + 1] * new_matrix_[32]
+ + red_raster_[row4 + 2] * new_matrix_[33]
+ + red_raster_[row4 + 3] * new_matrix_[34]
+ + red_raster_[row4 + 4] * new_matrix_[35]
+ + red_raster_[row5 - 4] * new_matrix_[36]
+ + red_raster_[row5 - 3] * new_matrix_[37]
+ + red_raster_[row5 - 2] * new_matrix_[38]
+ + red_raster_[row5 - 1] * new_matrix_[39]
+ + red_raster_[row5] * new_matrix_[40]
+ + red_raster_[row5 + 1] * new_matrix_[41]
+ + red_raster_[row5 + 2] * new_matrix_[42]
+ + red_raster_[row5 + 3] * new_matrix_[43]
+ + red_raster_[row5 + 4] * new_matrix_[44]
+ + red_raster_[row6 - 4] * new_matrix_[45]
+ + red_raster_[row6 - 3] * new_matrix_[46]
+ + red_raster_[row6 - 2] * new_matrix_[47]
+ + red_raster_[row6 - 1] * new_matrix_[48]
+ + red_raster_[row6] * new_matrix_[49]
+ + red_raster_[row6 + 1] * new_matrix_[50]
+ + red_raster_[row6 + 2] * new_matrix_[51]
+ + red_raster_[row6 + 3] * new_matrix_[52]
+ + red_raster_[row6 + 4] * new_matrix_[53]
+ + red_raster_[row7 - 4] * new_matrix_[54]
+ + red_raster_[row7 - 3] * new_matrix_[55]
+ + red_raster_[row7 - 2] * new_matrix_[56]
+ + red_raster_[row7 - 1] * new_matrix_[57]
+ + red_raster_[row7] * new_matrix_[58]
+ + red_raster_[row7 + 1] * new_matrix_[59]
+ + red_raster_[row7 + 2] * new_matrix_[60]
+ + red_raster_[row7 + 3] * new_matrix_[61]
+ + red_raster_[row7 + 4] * new_matrix_[62]
+ + red_raster_[row1 - 4] * new_matrix_[63]
+ + red_raster_[row1 - 3] * new_matrix_[64]
+ + red_raster_[row1 - 2] * new_matrix_[65]
+ + red_raster_[row1 - 1] * new_matrix_[66]
+ + red_raster_[row1] * new_matrix_[67]
+ + red_raster_[row1 + 1] * new_matrix_[68]
+ + red_raster_[row1 + 2] * new_matrix_[69]
+ + red_raster_[row1 + 3] * new_matrix_[70]
+ + red_raster_[row1 + 4] * new_matrix_[71]
+ + red_raster_[row1 - 4] * new_matrix_[72]
+ + red_raster_[row1 - 3] * new_matrix_[73]
+ + red_raster_[row1 - 2] * new_matrix_[74]
+ + red_raster_[row1 - 1] * new_matrix_[75]
+ + red_raster_[row1] * new_matrix_[76]
+ + red_raster_[row1 + 1] * new_matrix_[77]
+ + red_raster_[row1 + 2] * new_matrix_[78]
+ + red_raster_[row1 + 3] * new_matrix_[79]
+ + red_raster_[row1 + 4] * new_matrix_[80])/div_factor_;
+
+ new_green =
+ (green_raster_[row1 - 4] * new_matrix_[0]
+ + green_raster_[row1 - 3] * new_matrix_[1]
+ + green_raster_[row1 - 2] * new_matrix_[2]
+ + green_raster_[row1 - 1] * new_matrix_[3]
+ + green_raster_[row1] * new_matrix_[4]
+ + green_raster_[row1 + 1] * new_matrix_[5]
+ + green_raster_[row1 + 2] * new_matrix_[6]
+ + green_raster_[row1 + 3] * new_matrix_[7]
+ + green_raster_[row1 + 4] * new_matrix_[8]
+ + green_raster_[row2 - 4] * new_matrix_[9]
+ + green_raster_[row2 - 3] * new_matrix_[10]
+ + green_raster_[row2 - 2] * new_matrix_[11]
+ + green_raster_[row2 - 1] * new_matrix_[12]
+ + green_raster_[row2] * new_matrix_[13]
+ + green_raster_[row2 + 1] * new_matrix_[14]
+ + green_raster_[row2 + 2] * new_matrix_[15]
+ + green_raster_[row2 + 3] * new_matrix_[16]
+ + green_raster_[row2 + 4] * new_matrix_[17]
+ + green_raster_[row3 - 4] * new_matrix_[18]
+ + green_raster_[row3 - 3] * new_matrix_[19]
+ + green_raster_[row3 - 2] * new_matrix_[20]
+ + green_raster_[row3 - 1] * new_matrix_[21]
+ + green_raster_[row3] * new_matrix_[22]
+ + green_raster_[row3 + 1] * new_matrix_[23]
+ + green_raster_[row3 + 2] * new_matrix_[24]
+ + green_raster_[row3 + 3] * new_matrix_[25]
+ + green_raster_[row3 + 4] * new_matrix_[26]
+ + green_raster_[row4 - 4] * new_matrix_[27]
+ + green_raster_[row4 - 3] * new_matrix_[28]
+ + green_raster_[row4 - 2] * new_matrix_[29]
+ + green_raster_[row4 - 1] * new_matrix_[30]
+ + green_raster_[row4] * new_matrix_[31]
+ + green_raster_[row4 + 1] * new_matrix_[32]
+ + green_raster_[row4 + 2] * new_matrix_[33]
+ + green_raster_[row4 + 3] * new_matrix_[34]
+ + green_raster_[row4 + 4] * new_matrix_[35]
+ + green_raster_[row5 - 4] * new_matrix_[36]
+ + green_raster_[row5 - 3] * new_matrix_[37]
+ + green_raster_[row5 - 2] * new_matrix_[38]
+ + green_raster_[row5 - 1] * new_matrix_[39]
+ + green_raster_[row5] * new_matrix_[40]
+ + green_raster_[row5 + 1] * new_matrix_[41]
+ + green_raster_[row5 + 2] * new_matrix_[42]
+ + green_raster_[row5 + 3] * new_matrix_[43]
+ + green_raster_[row5 + 4] * new_matrix_[44]
+ + green_raster_[row6 - 4] * new_matrix_[45]
+ + green_raster_[row6 - 3] * new_matrix_[46]
+ + green_raster_[row6 - 2] * new_matrix_[47]
+ + green_raster_[row6 - 1] * new_matrix_[48]
+ + green_raster_[row6] * new_matrix_[49]
+ + green_raster_[row6 + 1] * new_matrix_[50]
+ + green_raster_[row6 + 2] * new_matrix_[51]
+ + green_raster_[row6 + 3] * new_matrix_[52]
+ + green_raster_[row6 + 4] * new_matrix_[53]
+ + green_raster_[row7 - 4] * new_matrix_[54]
+ + green_raster_[row7 - 3] * new_matrix_[55]
+ + green_raster_[row7 - 2] * new_matrix_[56]
+ + green_raster_[row7 - 1] * new_matrix_[57]
+ + green_raster_[row7] * new_matrix_[58]
+ + green_raster_[row7 + 1] * new_matrix_[59]
+ + green_raster_[row7 + 2] * new_matrix_[60]
+ + green_raster_[row7 + 3] * new_matrix_[61]
+ + green_raster_[row7 + 4] * new_matrix_[62]
+ + green_raster_[row1 - 4] * new_matrix_[63]
+ + green_raster_[row1 - 3] * new_matrix_[64]
+ + green_raster_[row1 - 2] * new_matrix_[65]
+ + green_raster_[row1 - 1] * new_matrix_[66]
+ + green_raster_[row1] * new_matrix_[67]
+ + green_raster_[row1 + 1] * new_matrix_[68]
+ + green_raster_[row1 + 2] * new_matrix_[69]
+ + green_raster_[row1 + 3] * new_matrix_[70]
+ + green_raster_[row1 + 4] * new_matrix_[71]
+ + green_raster_[row1 - 4] * new_matrix_[72]
+ + green_raster_[row1 - 3] * new_matrix_[73]
+ + green_raster_[row1 - 2] * new_matrix_[74]
+ + green_raster_[row1 - 1] * new_matrix_[75]
+ + green_raster_[row1] * new_matrix_[76]
+ + green_raster_[row1 + 1] * new_matrix_[77]
+ + green_raster_[row1 + 2] * new_matrix_[78]
+ + green_raster_[row1 + 3] * new_matrix_[79]
+ + green_raster_[row1 + 4] * new_matrix_[80])/div_factor_;
+
+ new_blue =
+ (blue_raster_[row1 - 4] * new_matrix_[0]
+ + blue_raster_[row1 - 3] * new_matrix_[1]
+ + blue_raster_[row1 - 2] * new_matrix_[2]
+ + blue_raster_[row1 - 1] * new_matrix_[3]
+ + blue_raster_[row1] * new_matrix_[4]
+ + blue_raster_[row1 + 1] * new_matrix_[5]
+ + blue_raster_[row1 + 2] * new_matrix_[6]
+ + blue_raster_[row1 + 3] * new_matrix_[7]
+ + blue_raster_[row1 + 4] * new_matrix_[8]
+ + blue_raster_[row2 - 4] * new_matrix_[9]
+ + blue_raster_[row2 - 3] * new_matrix_[10]
+ + blue_raster_[row2 - 2] * new_matrix_[11]
+ + blue_raster_[row2 - 1] * new_matrix_[12]
+ + blue_raster_[row2] * new_matrix_[13]
+ + blue_raster_[row2 + 1] * new_matrix_[14]
+ + blue_raster_[row2 + 2] * new_matrix_[15]
+ + blue_raster_[row2 + 3] * new_matrix_[16]
+ + blue_raster_[row2 + 4] * new_matrix_[17]
+ + blue_raster_[row3 - 4] * new_matrix_[18]
+ + blue_raster_[row3 - 3] * new_matrix_[19]
+ + blue_raster_[row3 - 2] * new_matrix_[20]
+ + blue_raster_[row3 - 1] * new_matrix_[21]
+ + blue_raster_[row3] * new_matrix_[22]
+ + blue_raster_[row3 + 1] * new_matrix_[23]
+ + blue_raster_[row3 + 2] * new_matrix_[24]
+ + blue_raster_[row3 + 3] * new_matrix_[25]
+ + blue_raster_[row3 + 4] * new_matrix_[26]
+ + blue_raster_[row4 - 4] * new_matrix_[27]
+ + blue_raster_[row4 - 3] * new_matrix_[28]
+ + blue_raster_[row4 - 2] * new_matrix_[29]
+ + blue_raster_[row4 - 1] * new_matrix_[30]
+ + blue_raster_[row4] * new_matrix_[31]
+ + blue_raster_[row4 + 1] * new_matrix_[32]
+ + blue_raster_[row4 + 2] * new_matrix_[33]
+ + blue_raster_[row4 + 3] * new_matrix_[34]
+ + blue_raster_[row4 + 4] * new_matrix_[35]
+ + blue_raster_[row5 - 4] * new_matrix_[36]
+ + blue_raster_[row5 - 3] * new_matrix_[37]
+ + blue_raster_[row5 - 2] * new_matrix_[38]
+ + blue_raster_[row5 - 1] * new_matrix_[39]
+ + blue_raster_[row5] * new_matrix_[40]
+ + blue_raster_[row5 + 1] * new_matrix_[41]
+ + blue_raster_[row5 + 2] * new_matrix_[42]
+ + blue_raster_[row5 + 3] * new_matrix_[43]
+ + blue_raster_[row5 + 4] * new_matrix_[44]
+ + blue_raster_[row6 - 4] * new_matrix_[45]
+ + blue_raster_[row6 - 3] * new_matrix_[46]
+ + blue_raster_[row6 - 2] * new_matrix_[47]
+ + blue_raster_[row6 - 1] * new_matrix_[48]
+ + blue_raster_[row6] * new_matrix_[49]
+ + blue_raster_[row6 + 1] * new_matrix_[50]
+ + blue_raster_[row6 + 2] * new_matrix_[51]
+ + blue_raster_[row6 + 3] * new_matrix_[52]
+ + blue_raster_[row6 + 4] * new_matrix_[53]
+ + blue_raster_[row7 - 4] * new_matrix_[54]
+ + blue_raster_[row7 - 3] * new_matrix_[55]
+ + blue_raster_[row7 - 2] * new_matrix_[56]
+ + blue_raster_[row7 - 1] * new_matrix_[57]
+ + blue_raster_[row7] * new_matrix_[58]
+ + blue_raster_[row7 + 1] * new_matrix_[59]
+ + blue_raster_[row7 + 2] * new_matrix_[60]
+ + blue_raster_[row7 + 3] * new_matrix_[61]
+ + blue_raster_[row7 + 4] * new_matrix_[62]
+ + blue_raster_[row1 - 4] * new_matrix_[63]
+ + blue_raster_[row1 - 3] * new_matrix_[64]
+ + blue_raster_[row1 - 2] * new_matrix_[65]
+ + blue_raster_[row1 - 1] * new_matrix_[66]
+ + blue_raster_[row1] * new_matrix_[67]
+ + blue_raster_[row1 + 1] * new_matrix_[68]
+ + blue_raster_[row1 + 2] * new_matrix_[69]
+ + blue_raster_[row1 + 3] * new_matrix_[70]
+ + blue_raster_[row1 + 4] * new_matrix_[71]
+ + blue_raster_[row1 - 4] * new_matrix_[72]
+ + blue_raster_[row1 - 3] * new_matrix_[73]
+ + blue_raster_[row1 - 2] * new_matrix_[74]
+ + blue_raster_[row1 - 1] * new_matrix_[75]
+ + blue_raster_[row1] * new_matrix_[76]
+ + blue_raster_[row1 + 1] * new_matrix_[77]
+ + blue_raster_[row1 + 2] * new_matrix_[78]
+ + blue_raster_[row1 + 3] * new_matrix_[79]
+ + blue_raster_[row1 + 4] * new_matrix_[80])/div_factor_;
+
+ if (new_red > 255)
+ new_red = 255;
+
+ if (new_green > 255)
+ new_green = 255;
+
+ if (new_blue > 255)
+ new_blue = 255;
+
+ pixels[y - 4] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ consumer.setPixels(0, x-5, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+
+ protected void createColorRasters()
+ {
+ int off = 0;
+ int index;
+ int pixel;
+ red_raster_ = new int[(rows_ + 4)*(columns_ + 4)];
+ green_raster_ = new int[red_raster_.length];
+ blue_raster_ = new int[red_raster_.length];
+
+ for (int x = 2; x < rows_ + 2; x++)
+ {
+ for (int y = 2; y < columns_ + 2; y ++)
+ {
+ index = x*columns_ + y;
+ pixel = raster_[off];
+ red_raster_[index] = defaultRGB_.getRed(pixel);
+ green_raster_[index] = defaultRGB_.getGreen(pixel);
+ blue_raster_[index] = defaultRGB_.getBlue(pixel);
+ off++;
+ }
+ }
+ }
+}
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..865132daded
--- /dev/null
+++ b/java/ImageProcessing/filters/SharpenFilter.java
@@ -0,0 +1,137 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class SharpenFilter extends SpatialFilter
+{
+ int[] red_raster_;
+ int[] green_raster_;
+ int[] blue_raster_;
+ int[] new_matrix_;
+
+ public SharpenFilter()
+ {
+ }
+
+ public String info ()
+ {
+ return "Sharpens an image.";
+ }
+
+ 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_];
+ createColorRasters();
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha;
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 1) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+
+ new_red =
+ (red_raster_[row1 - 1]
+ - (red_raster_[row1] << 1)
+ + red_raster_[row1 + 1]
+ - (red_raster_[row2 - 1] << 1)
+ + (red_raster_[row2] << 3)
+ - (red_raster_[row2 + 1] << 1)
+ + red_raster_[row3 - 1]
+ - (red_raster_[row3] << 1)
+ + red_raster_[row3 + 1]) >> 2;
+
+ new_green =
+ (green_raster_[row1 - 1]
+ - (green_raster_[row1] << 1)
+ + green_raster_[row1 + 1]
+ - (green_raster_[row2 - 1] << 1)
+ + (green_raster_[row2] << 3)
+ - (green_raster_[row2 + 1] << 1)
+ + green_raster_[row3 - 1]
+ - (green_raster_[row3] << 1)
+ + green_raster_[row3 + 1]) >> 2;
+
+
+ new_blue =
+ (blue_raster_[row1 - 1]
+ - (blue_raster_[row1] << 1)
+ + blue_raster_[row1 + 1]
+ - (blue_raster_[row2 - 1] << 1)
+ + (blue_raster_[row2] << 3)
+ - (blue_raster_[row2 + 1] << 1)
+ + blue_raster_[row3 - 1]
+ - (blue_raster_[row3] << 1)
+ + blue_raster_[row3 + 1]) >> 2;
+
+
+ if (new_red > 255)
+ new_red = 255;
+
+ if (new_green > 255)
+ new_green = 255;
+
+ if (new_blue > 255)
+ new_blue = 255;
+
+ if (new_red < 0)
+ new_red = 0;
+
+ if (new_green < 0)
+ new_green = 0;
+
+ if (new_blue < 0)
+ new_blue = 0;
+
+
+ pixels[y - 1] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ consumer.setPixels(0, x-1, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+
+ protected void createColorRasters()
+ {
+ int off = 0;
+ int index = columns_;
+ int pixel;
+ red_raster_ = new int[(rows_ + 2)*(columns_ + 2)];
+ green_raster_ = new int[red_raster_.length];
+ blue_raster_ = new int[red_raster_.length];
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y ++)
+ {
+ index++;
+ pixel = raster_[off];
+ red_raster_[index] = defaultRGB_.getRed(pixel);
+ green_raster_[index] = defaultRGB_.getGreen(pixel);
+ blue_raster_[index] = defaultRGB_.getBlue(pixel);
+ off++;
+ }
+ }
+ }
+}
diff --git a/java/ImageProcessing/filters/SobelFilter.java b/java/ImageProcessing/filters/SobelFilter.java
new file mode 100644
index 00000000000..649c7963220
--- /dev/null
+++ b/java/ImageProcessing/filters/SobelFilter.java
@@ -0,0 +1,117 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class SobelFilter extends FivebyfiveFilter
+{
+ public SobelFilter()
+ {
+ }
+
+ 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_];
+ createColorRasters();
+ 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 alpha;
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 1) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+
+ new_red1 =
+ (red_raster_[row1 - 1]
+ + (red_raster_[row1] << 1)
+ + red_raster_[row1 + 1]
+ - red_raster_[row3 - 1]
+ - (red_raster_[row3] << 1)
+ - red_raster_[row3 + 1]);
+
+ new_green1 =
+ (green_raster_[row1 - 1]
+ + (green_raster_[row1] << 1)
+ + green_raster_[row1 + 1]
+ - green_raster_[row3 - 1]
+ - (green_raster_[row3] << 1)
+ - green_raster_[row3 + 1]);
+
+ new_blue1 =
+ (blue_raster_[row1 - 1]
+ + (blue_raster_[row1] << 1)
+ + blue_raster_[row1 + 1]
+ - blue_raster_[row3 - 1]
+ - (blue_raster_[row3] << 1)
+ - blue_raster_[row3 + 1]);
+
+ new_red2 =
+ (- red_raster_[row1 - 1]
+ + red_raster_[row1 + 1]
+ - (red_raster_[row2 - 1] << 1)
+ + (red_raster_[row2 + 1] << 1)
+ - red_raster_[row3 - 1]
+ + red_raster_[row3 + 1]);
+
+ new_green2 =
+ (- green_raster_[row1 - 1]
+ + green_raster_[row1 + 1]
+ - (green_raster_[row2 - 1] << 1)
+ + (green_raster_[row2 + 1] << 1)
+ - green_raster_[row3 - 1]
+ + green_raster_[row3 + 1]);
+
+ new_blue2 =
+ (- blue_raster_[row1 - 1]
+ + blue_raster_[row1 + 1]
+ - (blue_raster_[row2 - 1] << 1)
+ + (blue_raster_[row2 + 1] << 1)
+ - blue_raster_[row3 - 1]
+ + blue_raster_[row3 + 1]);
+
+ 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 > 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);
+ }
+}
diff --git a/java/ImageProcessing/filters/SpatialFilter.java b/java/ImageProcessing/filters/SpatialFilter.java
new file mode 100644
index 00000000000..12befc0e614
--- /dev/null
+++ b/java/ImageProcessing/filters/SpatialFilter.java
@@ -0,0 +1,187 @@
+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 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(new_red, 255);
+ new_green = Math.min(new_green, 255);
+ new_blue = Math.min(new_blue, 255);
+
+ pixels[y] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ consumer.setPixels(0, x, 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 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/ThreebythreeFilter.java b/java/ImageProcessing/filters/ThreebythreeFilter.java
new file mode 100644
index 00000000000..134487123dd
--- /dev/null
+++ b/java/ImageProcessing/filters/ThreebythreeFilter.java
@@ -0,0 +1,133 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class ThreebythreeFilter extends SpatialFilter
+{
+ int[] red_raster_;
+ int[] green_raster_;
+ int[] blue_raster_;
+ int[] new_matrix_;
+
+ public ThreebythreeFilter()
+ {
+ }
+
+ public ThreebythreeFilter(int[] matrix, int degree, int div_factor, int offset)
+ {
+ new_matrix_ = matrix;
+ degree_ = degree;
+ div_factor_ = div_factor;
+ offset_ = offset;
+ }
+
+ public String info ()
+ {
+ return "Base Filter class. Doesn't do much";
+ }
+
+ 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_];
+ createColorRasters();
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3, row4, row5;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha;
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[pixel++]);
+
+ row1 = columns_*(x - 1) + y;
+ row2 = row1 + columns_;
+ row3 = row2 + columns_;
+ row4 = row3 + columns_;
+ row5 = row4 + columns_;
+
+ new_red =
+ (red_raster_[row1 - 1] * new_matrix_[0]
+ + red_raster_[row1] * new_matrix_[1]
+ + red_raster_[row1 + 1] * new_matrix_[2]
+ + red_raster_[row2 - 1] * new_matrix_[3]
+ + red_raster_[row2] * new_matrix_[4]
+ + red_raster_[row2 + 1] * new_matrix_[5]
+ + red_raster_[row3 - 1] * new_matrix_[6]
+ + red_raster_[row3] * new_matrix_[7]
+ + red_raster_[row3 + 1] * new_matrix_[8])/div_factor_;
+
+ new_green =
+ (green_raster_[row1 - 1] * new_matrix_[0]
+ + green_raster_[row1] * new_matrix_[1]
+ + green_raster_[row1 + 1] * new_matrix_[2]
+ + green_raster_[row2 - 1] * new_matrix_[3]
+ + green_raster_[row2] * new_matrix_[4]
+ + green_raster_[row2 + 1] * new_matrix_[5]
+ + green_raster_[row3 - 1] * new_matrix_[6]
+ + green_raster_[row3] * new_matrix_[7]
+ + green_raster_[row3 + 1] * new_matrix_[8])/div_factor_;
+
+ new_blue =
+ (blue_raster_[row1 - 1] * new_matrix_[0]
+ + blue_raster_[row1] * new_matrix_[1]
+ + blue_raster_[row1 + 1] * new_matrix_[2]
+ + blue_raster_[row2 - 1] * new_matrix_[3]
+ + blue_raster_[row2] * new_matrix_[4]
+ + blue_raster_[row2 + 1] * new_matrix_[5]
+ + blue_raster_[row3 - 1] * new_matrix_[6]
+ + blue_raster_[row3] * new_matrix_[7]
+ + blue_raster_[row3 + 1] * new_matrix_[8])/div_factor_;
+
+ if (new_red > 255)
+ new_red = 255;
+
+ if (new_green > 255)
+ new_green = 255;
+
+ if (new_blue > 255)
+ new_blue = 255;
+
+ pixels[y - 1] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ consumer.setPixels(0, x-1, columns_, 1, defaultRGB_, pixels, 0, columns_);
+ }
+ // System.out.println(timer);
+ consumer.imageComplete(status);
+ }
+
+ protected void createColorRasters()
+ {
+ int off = 0;
+ int index;
+ int pixel;
+ red_raster_ = new int[(rows_ + 2)*(columns_ + 2)];
+ green_raster_ = new int[red_raster_.length];
+ blue_raster_ = new int[red_raster_.length];
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y ++)
+ {
+ index = x*columns_ + y;
+ pixel = raster_[off];
+ red_raster_[index] = defaultRGB_.getRed(pixel);
+ green_raster_[index] = defaultRGB_.getGreen(pixel);
+ blue_raster_[index] = defaultRGB_.getBlue(pixel);
+ off++;
+ }
+ }
+ }
+}
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";
+ }
+}
diff --git a/java/ImageProcessing/filters/UnsharpFilter.java b/java/ImageProcessing/filters/UnsharpFilter.java
new file mode 100644
index 00000000000..26ac01d3e24
--- /dev/null
+++ b/java/ImageProcessing/filters/UnsharpFilter.java
@@ -0,0 +1,241 @@
+package imaging.filters;
+
+import java.awt.image.*;
+
+public class UnsharpFilter extends SpatialFilter
+{
+
+ int[] red_raster_;
+ int[] green_raster_;
+ int[] blue_raster_;
+
+ private int sharp_ = 1;
+ private int smooth_ = 5;
+ private float frac_ = (float)((float).8/(float)2);
+
+ public UnsharpFilter()
+ {
+ }
+
+ public UnsharpFilter(int sharp, int smooth, float frac)
+ {
+ float div = (float)2.0;
+ sharp_ = sharp;
+ smooth_ = smooth;
+ frac_ = frac/div;
+ }
+
+ public String info ()
+ {
+ return "Sharpens an image.";
+ }
+
+ public void imageComplete(int status)
+ {
+ if (status == IMAGEERROR || status == IMAGEABORTED)
+ {
+ consumer.imageComplete(status);
+ System.out.println("Image Error");
+ return;
+ }
+
+ int[] pixels = new int[columns_*rows_], temp;
+ int[] blurred_red = new int[columns_* rows_];
+ int[] blurred_blue = new int[columns_* rows_];
+ int[] blurred_green = new int[columns_* rows_];
+ int pixel = 0;
+ int red, green, blue;
+ int row1, row2, row3;
+ int index, sum, index_pixels;
+ int new_red = 0, new_green = 0, new_blue = 0;
+ int alpha, iterations;
+
+ if (sharp_ > smooth_)
+ iterations = sharp_;
+ else
+ iterations = smooth_;
+
+ createColorRasters();
+ for (int i = 0; i < iterations; i++)
+ {
+ 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_;
+
+ alpha = defaultRGB_.getAlpha(raster_[row2]);
+
+ new_red =
+ (red_raster_[row1 - 1]
+ + red_raster_[row1 + 1]
+ + red_raster_[row3 - 1]
+ + red_raster_[row3 + 1]
+ + ((red_raster_[row1]
+ + red_raster_[row2 - 1]
+ + red_raster_[row2 + 1]
+ + red_raster_[row3]) << 1)
+ + (red_raster_[row2] << 2)) >> 4;
+
+ new_green =
+ (green_raster_[row1 - 1]
+ + green_raster_[row1 + 1]
+ + green_raster_[row3 - 1]
+ + green_raster_[row3 + 1]
+ + ((green_raster_[row1]
+ + green_raster_[row2 - 1]
+ + green_raster_[row2 + 1]
+ + green_raster_[row3]) << 1)
+ + (green_raster_[row2] << 2)) >> 4;
+
+ new_blue =
+ (blue_raster_[row1 - 1]
+ + blue_raster_[row1 + 1]
+ + blue_raster_[row3 - 1]
+ + blue_raster_[row3 + 1]
+ + ((blue_raster_[row1]
+ + blue_raster_[row2 - 1]
+ + blue_raster_[row2 + 1]
+ + blue_raster_[row3]) << 1)
+ + (blue_raster_[row2] << 2)) >> 4;
+
+ pixels[x*columns_ + y] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ }
+ }
+
+ sum = columns_ - 1;
+ for (int y = 1; y < rows_ + 1; y++)
+ {
+ index = y*columns_;
+ index_pixels = (y-1)*columns_;
+
+ alpha = defaultRGB_.getAlpha(raster_[index_pixels]);
+ new_red = red_raster_[index];
+ new_blue = blue_raster_[index];
+ new_green = green_raster_[index];
+ pixels[index_pixels] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ index += sum;
+ index_pixels += sum;
+
+ alpha = defaultRGB_.getAlpha(raster_[index_pixels]);
+ new_red = red_raster_[index];
+ new_blue = blue_raster_[index];
+ new_green = green_raster_[index];
+ pixels[index_pixels] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+ }
+
+ sum = columns_*(rows_ -1);
+ for (int x = 1; x < columns_ + 1; x++)
+ {
+ alpha = defaultRGB_.getAlpha(raster_[x-1]);
+ new_red = red_raster_[x];
+ new_blue = blue_raster_[x];
+ new_green = green_raster_[x];
+ pixels[x-1] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+
+ index = x + sum;
+
+ alpha = defaultRGB_.getAlpha(raster_[index-1]);
+ new_red = red_raster_[index];
+ new_blue = blue_raster_[index];
+ new_green = green_raster_[index];
+
+ pixels[index-1] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+ }
+
+ temp = pixels;
+ pixels = raster_;
+ raster_ = temp;
+
+ createColorRasters();
+
+ if (i == sharp_ - 1)
+ {
+ sum = 0;
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y ++)
+ {
+ index = x*columns_ + y;
+ blurred_red[sum] = red_raster_[index];
+ blurred_blue[sum] = blue_raster_[index];
+ blurred_green[sum] = green_raster_[index];
+ sum++;
+ }
+ }
+ }
+ }
+
+ sum = 0;
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y++)
+ {
+ index = x*columns_ + y;
+
+ alpha = defaultRGB_.getAlpha(raster_[sum]);
+
+ new_red = blurred_red[sum] - (int)((float)red_raster_[index]*frac_);
+ if (new_red < 0)
+ new_red = 0;
+ else if (new_red > 255)
+ new_red = 255;
+
+ blurred_red[sum] = new_red;
+
+ new_blue = blurred_blue[sum] - (int)((float)blue_raster_[index]*frac_);
+ if (new_blue < 0)
+ new_blue = 0;
+ else if (new_blue > 255)
+ new_blue = 255;
+
+ blurred_blue[sum] = new_blue;
+
+ new_green = blurred_green[sum] - (int)((float)green_raster_[index]*frac_);
+ if (new_green < 0)
+ new_green = 0;
+ else if (new_green > 255)
+ new_green = 255;
+
+ blurred_green[sum] = new_green;
+
+ pixels[sum] = (alpha << 24) | (new_red << 16) | (new_green << 8) | new_blue;
+ sum++;
+ }
+ }
+
+ consumer.setPixels(0, 0, columns_, rows_, defaultRGB_, pixels, 0, columns_);
+ consumer.imageComplete(status);
+ }
+
+ protected void createColorRasters()
+ {
+ int off = 0;
+ int index;
+ int pixel;
+ red_raster_ = new int[(rows_ + 2)*(columns_ + 2)];
+ green_raster_ = new int[red_raster_.length];
+ blue_raster_ = new int[red_raster_.length];
+
+ for (int x = 1; x < rows_ + 1; x++)
+ {
+ for (int y = 1; y < columns_ + 1; y ++)
+ {
+ index = x*columns_ + y;
+ pixel = raster_[off];
+ red_raster_[index] = defaultRGB_.getRed(pixel);
+ green_raster_[index] = defaultRGB_.getGreen(pixel);
+ blue_raster_[index] = defaultRGB_.getBlue(pixel);
+ off++;
+ }
+ }
+ }
+}
+
+
+
+