stability bugfixes

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@8011 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent f121f4bb45
commit c31564ef08

@ -203,10 +203,17 @@ public class NewsQueue implements Iterable<NewsDB.Record> {
public NewsDB.Record next() { public NewsDB.Record next() {
if (this.stackNodeIterator == null) return null; if (this.stackNodeIterator == null) return null;
final Row.Entry row = this.stackNodeIterator.next(); Row.Entry row;
try {
row = this.stackNodeIterator.next();
} catch (final IndexOutOfBoundsException e) {
e.printStackTrace();
return null;
}
try { try {
return b2r(row); return b2r(row);
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace();
return null; return null;
} }
} }

@ -88,12 +88,12 @@ public class RasterPlotter {
this.defaultMode = drawMode; this.defaultMode = drawMode;
try { try {
this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
} catch (OutOfMemoryError e) { } catch (final OutOfMemoryError e) {
this.image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); this.image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
//throw new RuntimeException(RasterPlotter.class.getSimpleName() + ": not enough memory (" + MemoryControl.available() + ") available"); //throw new RuntimeException(RasterPlotter.class.getSimpleName() + ": not enough memory (" + MemoryControl.available() + ") available");
} }
this.clear(); clear();
this.grid = image.getRaster(); this.grid = this.image.getRaster();
} }
/** /**
@ -106,9 +106,9 @@ public class RasterPlotter {
final int bgG = (int) ((this.backgroundCol >> 8) & 0xff); final int bgG = (int) ((this.backgroundCol >> 8) & 0xff);
final int bgB = (int) (this.backgroundCol & 0xff); final int bgB = (int) (this.backgroundCol & 0xff);
final Graphics2D gr = image.createGraphics(); final Graphics2D gr = this.image.createGraphics();
gr.setBackground(new Color(bgR, bgG, bgB)); gr.setBackground(new Color(bgR, bgG, bgB));
gr.clearRect(0, 0, width, height); gr.clearRect(0, 0, this.width, this.height);
} }
public void setDrawMode(final DrawMode drawMode) { public void setDrawMode(final DrawMode drawMode) {
@ -120,11 +120,11 @@ public class RasterPlotter {
} }
public int getWidth() { public int getWidth() {
return width; return this.width;
} }
public int getHeight() { public int getHeight() {
return height; return this.height;
} }
public static boolean darkColor(final String s) { public static boolean darkColor(final String s) {
@ -143,13 +143,13 @@ public class RasterPlotter {
final int r = (int) (c >> 16); final int r = (int) (c >> 16);
final int g = (int) ((c >> 8) & 0xff); final int g = (int) ((c >> 8) & 0xff);
final int b = (int) (c & 0xff); final int b = (int) (c & 0xff);
defaultColR = (g + b) >>> 1; // / 2; this.defaultColR = (g + b) >>> 1; // / 2;
defaultColG = (r + b) >>> 1; // / 2; this.defaultColG = (r + b) >>> 1; // / 2;
defaultColB = (r + g) >>> 1; // / 2; this.defaultColB = (r + g) >>> 1; // / 2;
} else { } else {
defaultColR = (int) (c >> 16); this.defaultColR = (int) (c >> 16);
defaultColG = (int) ((c >> 8) & 0xff); this.defaultColG = (int) ((c >> 8) & 0xff);
defaultColB = (int) (c & 0xff); this.defaultColB = (int) (c & 0xff);
} }
} }
@ -163,49 +163,61 @@ public class RasterPlotter {
} }
public void plot(final int x, final int y, final int intensity) { public void plot(final int x, final int y, final int intensity) {
if ((x < 0) || (x >= width)) return; if ((x < 0) || (x >= this.width)) return;
if ((y < 0) || (y >= height)) return; if ((y < 0) || (y >= this.height)) return;
if (this.defaultMode == DrawMode.MODE_REPLACE) { if (this.defaultMode == DrawMode.MODE_REPLACE) {
if (intensity == 100) synchronized (cc) { if (intensity == 100) synchronized (this.cc) {
cc[0] = defaultColR; this.cc[0] = this.defaultColR;
cc[1] = defaultColG; this.cc[1] = this.defaultColG;
cc[2] = defaultColB; this.cc[2] = this.defaultColB;
grid.setPixel(x, y, cc); this.grid.setPixel(x, y, this.cc);
} else synchronized (cc) { } else synchronized (this.cc) {
final int[] c = grid.getPixel(x, y, cc); final int[] c = this.grid.getPixel(x, y, this.cc);
c[0] = (intensity * defaultColR + (100 - intensity) * c[0]) / 100; c[0] = (intensity * this.defaultColR + (100 - intensity) * c[0]) / 100;
c[1] = (intensity * defaultColG + (100 - intensity) * c[1]) / 100; c[1] = (intensity * this.defaultColG + (100 - intensity) * c[1]) / 100;
c[2] = (intensity * defaultColB + (100 - intensity) * c[2]) / 100; c[2] = (intensity * this.defaultColB + (100 - intensity) * c[2]) / 100;
grid.setPixel(x, y, c); this.grid.setPixel(x, y, c);
} }
} else if (this.defaultMode == DrawMode.MODE_ADD) synchronized (cc) { } else if (this.defaultMode == DrawMode.MODE_ADD) synchronized (this.cc) {
final int[] c = grid.getPixel(x, y, cc); int[] c = null;
try {
c = this.grid.getPixel(x, y, this.cc);
} catch (final ArrayIndexOutOfBoundsException e) {
// catch "Coordinate out of bounds"
return;
}
if (intensity == 100) { if (intensity == 100) {
c[0] = (0xff & c[0]) + defaultColR; if (cc[0] > 255) cc[0] = 255; c[0] = (0xff & c[0]) + this.defaultColR; if (this.cc[0] > 255) this.cc[0] = 255;
c[1] = (0xff & c[1]) + defaultColG; if (cc[1] > 255) cc[1] = 255; c[1] = (0xff & c[1]) + this.defaultColG; if (this.cc[1] > 255) this.cc[1] = 255;
c[2] = (0xff & c[2]) + defaultColB; if (cc[2] > 255) cc[2] = 255; c[2] = (0xff & c[2]) + this.defaultColB; if (this.cc[2] > 255) this.cc[2] = 255;
} else { } else {
c[0] = (0xff & c[0]) + (intensity * defaultColR / 100); if (cc[0] > 255) cc[0] = 255; c[0] = (0xff & c[0]) + (intensity * this.defaultColR / 100); if (this.cc[0] > 255) this.cc[0] = 255;
c[1] = (0xff & c[1]) + (intensity * defaultColG / 100); if (cc[1] > 255) cc[1] = 255; c[1] = (0xff & c[1]) + (intensity * this.defaultColG / 100); if (this.cc[1] > 255) this.cc[1] = 255;
c[2] = (0xff & c[2]) + (intensity * defaultColB / 100); if (cc[2] > 255) cc[2] = 255; c[2] = (0xff & c[2]) + (intensity * this.defaultColB / 100); if (this.cc[2] > 255) this.cc[2] = 255;
}
this.grid.setPixel(x, y, c);
} else if (this.defaultMode == DrawMode.MODE_SUB) synchronized (this.cc) {
int[] c = null;
try {
c = this.grid.getPixel(x, y, this.cc);
} catch (final ArrayIndexOutOfBoundsException e) {
// catch "Coordinate out of bounds"
return;
} }
grid.setPixel(x, y, c);
} else if (this.defaultMode == DrawMode.MODE_SUB) synchronized (cc) {
final int[] c = grid.getPixel(x, y, cc);
if (intensity == 100) { if (intensity == 100) {
c[0] = (0xff & c[0]) - defaultColR; if (cc[0] < 0) cc[0] = 0; c[0] = (0xff & c[0]) - this.defaultColR; if (this.cc[0] < 0) this.cc[0] = 0;
c[1] = (0xff & c[1]) - defaultColG; if (cc[1] < 0) cc[1] = 0; c[1] = (0xff & c[1]) - this.defaultColG; if (this.cc[1] < 0) this.cc[1] = 0;
c[2] = (0xff & c[2]) - defaultColB; if (cc[2] < 0) cc[2] = 0; c[2] = (0xff & c[2]) - this.defaultColB; if (this.cc[2] < 0) this.cc[2] = 0;
} else { } else {
c[0] = (0xff & c[0]) - (intensity * defaultColR / 100); if (cc[0] < 0) cc[0] = 0; c[0] = (0xff & c[0]) - (intensity * this.defaultColR / 100); if (this.cc[0] < 0) this.cc[0] = 0;
c[1] = (0xff & c[1]) - (intensity * defaultColG / 100); if (cc[1] < 0) cc[1] = 0; c[1] = (0xff & c[1]) - (intensity * this.defaultColG / 100); if (this.cc[1] < 0) this.cc[1] = 0;
c[2] = (0xff & c[2]) - (intensity * defaultColB / 100); if (cc[2] < 0) cc[2] = 0; c[2] = (0xff & c[2]) - (intensity * this.defaultColB / 100); if (this.cc[2] < 0) this.cc[2] = 0;
} }
grid.setPixel(x, y, c); this.grid.setPixel(x, y, c);
} }
} }
public void line(int Ax, int Ay, final int Bx, final int By, final int intensity) { public void line(final int Ax, final int Ay, final int Bx, final int By, final int intensity) {
line(Ax, Ay, Bx, By, null, intensity, null, -1, -1, -1, -1, false); line(Ax, Ay, Bx, By, null, intensity, null, -1, -1, -1, -1, false);
} }
@ -230,7 +242,7 @@ public class RasterPlotter {
if (dotc == dotPos) { if (dotc == dotPos) {
if (colorDot != null) this.setColor(colorDot); if (colorDot != null) this.setColor(colorDot);
if (dotRadius == 0) this.plot(Ax, Ay, intensityDot); if (dotRadius == 0) this.plot(Ax, Ay, intensityDot);
else if (dotRadius > 0) this.dot(Ax, Ay, dotRadius, dotFilled, intensityDot); else if (dotRadius > 0) dot(Ax, Ay, dotRadius, dotFilled, intensityDot);
} }
dotc++; dotc++;
if (dotc == dotDist) dotc = 0; if (dotc == dotDist) dotc = 0;
@ -253,7 +265,7 @@ public class RasterPlotter {
if (dotc == dotPos) { if (dotc == dotPos) {
if (colorDot != null) this.setColor(colorDot); if (colorDot != null) this.setColor(colorDot);
if (dotRadius == 0) this.plot(Ax, Ay, intensityDot); if (dotRadius == 0) this.plot(Ax, Ay, intensityDot);
else if (dotRadius > 0) this.dot(Ax, Ay, dotRadius, dotFilled, intensityDot); else if (dotRadius > 0) dot(Ax, Ay, dotRadius, dotFilled, intensityDot);
} }
dotc++; dotc++;
if (dotc == dotDist) dotc = 0; if (dotc == dotDist) dotc = 0;
@ -298,7 +310,7 @@ public class RasterPlotter {
public int[] getColor(final int x, final int y) { public int[] getColor(final int x, final int y) {
final int[] c = new int[3]; final int[] c = new int[3];
return grid.getPixel(x, y, c); return this.grid.getPixel(x, y, c);
} }
public void dot(final int x, final int y, final int radius, final boolean filled, final int intensity) { public void dot(final int x, final int y, final int radius, final boolean filled, final int intensity) {
@ -325,7 +337,7 @@ public class RasterPlotter {
public void arcLine(final int cx, final int cy, final int innerRadius, final int outerRadius, final int angle, final boolean in, public void arcLine(final int cx, final int cy, final int innerRadius, final int outerRadius, final int angle, final boolean in,
final String colorLine, final String colorDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled) { final String colorLine, final String colorDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled) {
final double a = PI180 * ((double) angle); final double a = PI180 * (angle);
final double cosa = Math.cos(a); final double cosa = Math.cos(a);
final double sina = Math.sin(a); final double sina = Math.sin(a);
final int xi = cx + (int) (innerRadius * cosa); final int xi = cx + (int) (innerRadius * cosa);
@ -349,7 +361,7 @@ public class RasterPlotter {
} }
public void arcDot(final int cx, final int cy, final int arcRadius, final int angle, final int dotRadius) { public void arcDot(final int cx, final int cy, final int arcRadius, final int angle, final int dotRadius) {
final double a = PI180 * ((double) angle); final double a = PI180 * (angle);
final int x = cx + (int) (arcRadius * Math.cos(a)); final int x = cx + (int) (arcRadius * Math.cos(a));
final int y = cy - (int) (arcRadius * Math.sin(a)); final int y = cy - (int) (arcRadius * Math.sin(a));
dot(x, y, dotRadius, true, 100); dot(x, y, dotRadius, true, 100);
@ -358,8 +370,8 @@ public class RasterPlotter {
public void arcConnect(final int cx, final int cy, final int arcRadius, final int angle1, final int angle2, final boolean in, public void arcConnect(final int cx, final int cy, final int arcRadius, final int angle1, final int angle2, final boolean in,
final String colorLine, final int intensityLine, final String colorLine, final int intensityLine,
final String colorDot, final int intensityDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled) { final String colorDot, final int intensityDot, final int dotDist, final int dotPos, final int dotRadius, final boolean dotFilled) {
final double a1 = PI180 * ((double) angle1); final double a1 = PI180 * (angle1);
final double a2 = PI180 * ((double) angle2); final double a2 = PI180 * (angle2);
final int x1 = cx + (int) (arcRadius * Math.cos(a1)); final int x1 = cx + (int) (arcRadius * Math.cos(a1));
final int y1 = cy - (int) (arcRadius * Math.sin(a1)); final int y1 = cy - (int) (arcRadius * Math.sin(a1));
final int x2 = cx + (int) (arcRadius * Math.cos(a2)); final int x2 = cx + (int) (arcRadius * Math.cos(a2));
@ -377,7 +389,7 @@ public class RasterPlotter {
public void arcArc(final int cx, final int cy, final int arcRadius, final int angle, public void arcArc(final int cx, final int cy, final int arcRadius, final int angle,
final int innerRadius, final int outerRadius, final int intensity) { final int innerRadius, final int outerRadius, final int intensity) {
final double a = PI180 * ((double) angle); final double a = PI180 * (angle);
final int x = cx + (int) (arcRadius * Math.cos(a)); final int x = cx + (int) (arcRadius * Math.cos(a));
final int y = cy - (int) (arcRadius * Math.sin(a)); final int y = cy - (int) (arcRadius * Math.sin(a));
arc(x, y, innerRadius, outerRadius, intensity); arc(x, y, innerRadius, outerRadius, intensity);
@ -385,7 +397,7 @@ public class RasterPlotter {
public void arcArc(final int cx, final int cy, final int arcRadius, final int angle, public void arcArc(final int cx, final int cy, final int arcRadius, final int angle,
final int innerRadius, final int outerRadius, final int fromArc, final int toArc) { final int innerRadius, final int outerRadius, final int fromArc, final int toArc) {
final double a = PI180 * ((double) angle); final double a = PI180 * (angle);
final int x = cx + (int) (arcRadius * Math.cos(a)); final int x = cx + (int) (arcRadius * Math.cos(a));
final int y = cy - (int) (arcRadius * Math.sin(a)); final int y = cy - (int) (arcRadius * Math.sin(a));
arc(x, y, innerRadius, outerRadius, fromArc, toArc); arc(x, y, innerRadius, outerRadius, fromArc, toArc);
@ -450,8 +462,8 @@ public class RasterPlotter {
public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final int transRGB) { public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final int transRGB) {
final int heightSrc = bitmap.getHeight(); final int heightSrc = bitmap.getHeight();
final int widthSrc = bitmap.getWidth(); final int widthSrc = bitmap.getWidth();
final int heightTgt = height; final int heightTgt = this.height;
final int widthTgt = width; final int widthTgt = this.width;
int rgb; int rgb;
for (int i = 0; i < heightSrc; i++) { for (int i = 0; i < heightSrc; i++) {
@ -460,7 +472,7 @@ public class RasterPlotter {
if (j + x >= 0 && i + y >= 0 && i + y < heightTgt && j + x < widthTgt) { if (j + x >= 0 && i + y >= 0 && i + y < heightTgt && j + x < widthTgt) {
rgb = bitmap.getRGB(j, i); rgb = bitmap.getRGB(j, i);
if (rgb != transRGB) { if (rgb != transRGB) {
image.setRGB(j + x, i + y, rgb); this.image.setRGB(j + x, i + y, rgb);
} }
} }
} }
@ -486,8 +498,8 @@ public class RasterPlotter {
int transX = -1; int transX = -1;
int transY = -1; int transY = -1;
final int imageWidth = image.getWidth(); final int imageWidth = this.image.getWidth();
final int imageHeight = image.getHeight(); final int imageHeight = this.image.getHeight();
// find first pixel in bitmap that equals transRGB // find first pixel in bitmap that equals transRGB
// and also lies in area of image that will be covered by bitmap // and also lies in area of image that will be covered by bitmap
@ -512,7 +524,7 @@ public class RasterPlotter {
// of the bitmap that covers part of tha image is not within the borders of // of the bitmap that covers part of tha image is not within the borders of
// the image (i.e. bitmap is larger than image) // the image (i.e. bitmap is larger than image)
if (transX != -1) { if (transX != -1) {
filter(x - 1, y - 1, x + bitmapWidth, y + bitmapHeight, filter, image.getRGB(transX + x, transY + y)); filter(x - 1, y - 1, x + bitmapWidth, y + bitmapHeight, filter, this.image.getRGB(transX + x, transY + y));
} }
} else { } else {
@ -566,10 +578,10 @@ public class RasterPlotter {
private void filter(final int ulx, final int uly, final int lrx, final int lry, final FilterMode filter, final int bgcolor) { private void filter(final int ulx, final int uly, final int lrx, final int lry, final FilterMode filter, final int bgcolor) {
// taking care that all values are legal // taking care that all values are legal
final int lox = Math.min(Math.max(Math.min(ulx, lrx), 0), width - 1); final int lox = Math.min(Math.max(Math.min(ulx, lrx), 0), this.width - 1);
final int loy = Math.min(Math.max(Math.min(uly, lry), 0), height -1); final int loy = Math.min(Math.max(Math.min(uly, lry), 0), this.height -1);
final int rux = Math.min(Math.max(Math.max(ulx, lrx), 0), width - 1); final int rux = Math.min(Math.max(Math.max(ulx, lrx), 0), this.width - 1);
final int ruy = Math.min(Math.max(Math.max(uly, lry), 0), height -1); final int ruy = Math.min(Math.max(Math.max(uly, lry), 0), this.height -1);
int numberOfNeighbours = 0; int numberOfNeighbours = 0;
int rgbR = 0; int rgbR = 0;
@ -592,7 +604,7 @@ public class RasterPlotter {
if (filter == FilterMode.FILTER_ANTIALIASING || filter == FilterMode.FILTER_BLUR) { if (filter == FilterMode.FILTER_ANTIALIASING || filter == FilterMode.FILTER_BLUR) {
// taking samples from neighbouring pixel // taking samples from neighbouring pixel
if (i > lox) { if (i > lox) {
rgb = image.getRGB(i - 1, j); rgb = this.image.getRGB(i - 1, j);
border = (rgb == bgcolor); border = (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff; rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8 & 0xff; rgbG += rgb >> 8 & 0xff;
@ -600,23 +612,23 @@ public class RasterPlotter {
numberOfNeighbours++; numberOfNeighbours++;
} }
if (j > loy) { if (j > loy) {
rgb = image.getRGB(i, j - 1); rgb = this.image.getRGB(i, j - 1);
border = border || (rgb == bgcolor); border = border || (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff; rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8 & 0xff; rgbG += rgb >> 8 & 0xff;
rgbB += rgb & 0xff; rgbB += rgb & 0xff;
numberOfNeighbours++; numberOfNeighbours++;
} }
if (i < width - 1) { if (i < this.width - 1) {
rgb = image.getRGB(i + 1, j); rgb = this.image.getRGB(i + 1, j);
border = border || (rgb == bgcolor); border = border || (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff; rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8 & 0xff; rgbG += rgb >> 8 & 0xff;
rgbB += rgb & 0xff; rgbB += rgb & 0xff;
numberOfNeighbours++; numberOfNeighbours++;
} }
if (i < height - 1) { if (i < this.height - 1) {
rgb = image.getRGB(i, j + 1); rgb = this.image.getRGB(i, j + 1);
border = border || (rgb == bgcolor); border = border || (rgb == bgcolor);
rgbR += rgb >> 16 & 0xff; rgbR += rgb >> 16 & 0xff;
rgbG += rgb >> 8 & 0xff; rgbG += rgb >> 8 & 0xff;
@ -626,7 +638,7 @@ public class RasterPlotter {
} }
rgb = image.getRGB(i, j); rgb = this.image.getRGB(i, j);
// add value of pixel // add value of pixel
// in case filter is used for antialiasing this will only be done if // in case filter is used for antialiasing this will only be done if

Loading…
Cancel
Save