Skip to content

Commit

Permalink
*) quick hack for antialiasing, works only on borders now => less blu…
Browse files Browse the repository at this point in the history
…rry image

*) code is not finished, needs refactoring, still thinking about how to do it best


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4260 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
low012 committed Dec 9, 2007
1 parent 4331e52 commit 7397152
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions source/de/anomic/ymage/ymageMatrix.java
Expand Up @@ -363,7 +363,7 @@ public void insertBitmap(BufferedImage bitmap, int x, int y, int transRGB) {
*/
public void insertBitmap(BufferedImage bitmap, int x, int y, int transRGB, byte filter) {
insertBitmap(bitmap, x, y, transRGB);
filter(x-1, y-1, x + bitmap.getWidth(), y + bitmap.getHeight(), filter);
filter(x-1, y-1, x + bitmap.getWidth(), y + bitmap.getHeight(), filter, image.getRGB(x, y));
}

/**
Expand All @@ -372,10 +372,11 @@ public void insertBitmap(BufferedImage bitmap, int x, int y, int transRGB, byte
* @param loy y value for left upper coordinate
* @param rux x value for right lower coordinate
* @param ruy y value for right lower coordinate
* @param rgb color of background
* @author Marc Nause
*/
public void antialiasing(int lox, int loy, int rux, int ruy) {
filter(lox, loy, rux, ruy, FILTER_ANTIALIASING);
public void antialiasing(int lox, int loy, int rux, int ruy, int bgcolor) {
filter(lox, loy, rux, ruy, FILTER_ANTIALIASING, bgcolor);
}

/**
Expand All @@ -387,7 +388,7 @@ public void antialiasing(int lox, int loy, int rux, int ruy) {
* @author Marc Nause
*/
public void blur(int lox, int loy, int rux, int ruy) {
filter(lox, loy, rux, ruy, FILTER_BLUR);
filter(lox, loy, rux, ruy, FILTER_BLUR, -1);
}

/**
Expand All @@ -399,7 +400,7 @@ public void blur(int lox, int loy, int rux, int ruy) {
* @param filter chooses filter
* @author Marc Nause
*/
private void filter(int lox, int loy, int rux, int ruy, byte filter) {
private void filter(int lox, int loy, int rux, int ruy, byte filter, int bgcolor) {

// taking care that all values are legal
if (lox < 0) { lox = 0; }
Expand Down Expand Up @@ -428,6 +429,7 @@ private void filter(int lox, int loy, int rux, int ruy, byte filter) {
int rgb = 0;
int width2 = rux - lox + 1;
int height2 = ruy - loy + 1;
boolean border = false;
BufferedImage image2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_RGB);

for (int i = lox; i < rux + 1; i++) {
Expand All @@ -441,27 +443,39 @@ private void filter(int lox, int loy, int rux, int ruy, byte filter) {
// taking samples from neighbours of pixel
if (i > lox) {
rgb = image.getRGB(i-1, j);
if (rgb == bgcolor) {
border = true;
}
rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8& 0xff;
rgbB += rgb & 0xff;
numberOfNeighbours++;
}
if (j > loy) {
rgb = image.getRGB(i, j-1);
if (rgb == bgcolor) {
border = true;
}
rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8& 0xff;
rgbB += rgb & 0xff;
numberOfNeighbours++;
}
if (i < width- 1) {
rgb = image.getRGB(i+1, j);
if (rgb == bgcolor) {
border = true;
}
rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8& 0xff;
rgbB += rgb & 0xff;
numberOfNeighbours++;
}
if (i < height - 1) {
rgb = image.getRGB(i, j+1);
rgb = image.getRGB(i, j+1);
if (rgb == bgcolor) {
border = true;
}
rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8& 0xff;
rgbB += rgb & 0xff;
Expand All @@ -471,20 +485,25 @@ private void filter(int lox, int loy, int rux, int ruy, byte filter) {
rgb = image.getRGB(i, j);

// put more weight on pixle than on neighbours
if (filter == FILTER_ANTIALIASING) {
if (numberOfNeighbours == 0) {
numberOfNeighbours = 1;
}
rgbR += (rgb >> 16 & 0xff) * numberOfNeighbours;
rgbG += (rgb >> 8 & 0xff) * numberOfNeighbours;
rgbB += (rgb & 0xff) * numberOfNeighbours;
if (numberOfNeighbours > 1) {
numberOfNeighbours += numberOfNeighbours;
}
if (filter == FILTER_ANTIALIASING && border) {
// rgbR += (rgb >> 16 & 0xff) * numberOfNeighbours;
// rgbG += (rgb >> 8 & 0xff) * numberOfNeighbours;
// rgbB += (rgb & 0xff) * numberOfNeighbours;
// numberOfNeighbours += numberOfNeighbours;
rgbR += (rgb >> 16 & 0xff);
rgbG += (rgb >> 8 & 0xff);
rgbB += (rgb & 0xff);
numberOfNeighbours++;
border = false;
}
else if (filter == FILTER_ANTIALIASING) {
rgbR = (rgb >> 16 & 0xff);
rgbG = (rgb >> 8 & 0xff);
rgbB = (rgb & 0xff);
numberOfNeighbours = 1;
}

// put same weight in neighbours as on pixel
if (filter == FILTER_BLUR) {
else if (filter == FILTER_BLUR) {
rgbR += (rgb >> 16 & 0xff);
rgbG += (rgb >> 8 & 0xff);
rgbB += (rgb & 0xff);
Expand Down

0 comments on commit 7397152

Please sign in to comment.