Skip to content

Commit

Permalink
enhancement in drawing speed and reduction of object allocation durin…
Browse files Browse the repository at this point in the history
…g drawing

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7017 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Aug 3, 2010
1 parent 610855e commit 55a2536
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 60 deletions.
4 changes: 2 additions & 2 deletions htroot/NetworkPicture.java
Expand Up @@ -44,12 +44,12 @@ public static EncodedImage respond(final RequestHeader header, final serverObjec
final boolean authorized = sb.adminAuthenticated(header) >= 2;

long timeSeconds = System.currentTimeMillis() / 1000;
if (buffer != null && timeSeconds - lastAccessSeconds < 2) {
if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) {
//System.out.println("*** NetworkPicture: cache hit (1)");
return buffer;
}
synchronized (sync) {
if (buffer != null && timeSeconds - lastAccessSeconds < 2) {
if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) {
//System.out.println("*** NetworkPicture: cache hit (2)");
return buffer;
}
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/visualization/Captcha.java
Expand Up @@ -76,7 +76,7 @@ private void create(final String code){
setColor(((random.nextInt(128)+64)<<16) + ((random.nextInt(128)+64)<<8) + random.nextInt(128)+64);
x = random.nextInt(width);
y = random.nextInt(height);
line(x, y, x + random.nextInt(5), y + random.nextInt(5));
line(x, y, x + random.nextInt(5), y + random.nextInt(5), 100);
}

}
Expand Down
14 changes: 7 additions & 7 deletions source/net/yacy/visualization/ChartPlotter.java
Expand Up @@ -99,7 +99,7 @@ public void chartLine(final int dimension_x, final int dimension_y, final int co
final int y1 = (coord_y1 - offsets[dimension_y]) * pixels[dimension_y] / scales[dimension_y];
final int x2 = (coord_x2 - offsets[dimension_x]) * pixels[dimension_x] / scales[dimension_x];
final int y2 = (coord_y2 - offsets[dimension_y]) * pixels[dimension_y] / scales[dimension_y];
line(leftborder + x1, height - bottomborder - y1, leftborder + x2, height - bottomborder - y2);
line(leftborder + x1, height - bottomborder - y1, leftborder + x2, height - bottomborder - y2, 100);
}

private void drawHorizontalScale(final boolean top, final int scale, final int pixelperscale, final int offset, final String colorNaming, final String colorScale, final String name) {
Expand All @@ -109,17 +109,17 @@ private void drawHorizontalScale(final boolean top, final int scale, final int p
while (x < width - rightborder) {
if ((colorScale != null) && (x > leftborder) && (x < (width - rightborder))) {
setColor(colorScale);
line(x, topborder, x, height - bottomborder);
line(x, topborder, x, height - bottomborder, 100);
}
setColor(colorNaming);
line(x, y - 3, x, y + 3);
line(x, y - 3, x, y + 3, 100);
PrintTool.print(this, x, (top) ? y - 3 : y + 9, 0, Integer.toString(s), -1);
x += pixelperscale;
s += scale;
}
setColor(colorNaming);
PrintTool.print(this, width - rightborder, (top) ? y - 9 : y + 15, 0, name, 1);
line(leftborder - 4, y, width - rightborder + 4, y);
line(leftborder - 4, y, width - rightborder + 4, y, 100);
}

private void drawVerticalScale(final boolean left, final int scale, final int pixelperscale, final int offset, final String colorNaming, final String colorScale, final String name) {
Expand All @@ -131,10 +131,10 @@ private void drawVerticalScale(final boolean left, final int scale, final int pi
while (y > topborder) {
if ((colorScale != null) && (y > topborder) && (y < (height - bottomborder))) {
setColor(colorScale);
line(leftborder, y, width - rightborder, y);
line(leftborder, y, width - rightborder, y, 100);
}
setColor(colorNaming);
line(x - 3, y, x + 3, y);
line(x - 3, y, x + 3, y, 100);
s1 = (s >= 1000000 && s % 10000 == 0) ? Integer.toString(s / 1000000) + "M" : (s >= 1000 && s % 1000 == 0) ? Integer.toString(s / 1000) + "K" : Integer.toString(s);
if (s1.length() > s1max) s1max = s1.length();
PrintTool.print(this, (left) ? leftborder - 4 : width - rightborder + 4, y, 0, s1, (left) ? 1 : -1);
Expand All @@ -143,7 +143,7 @@ private void drawVerticalScale(final boolean left, final int scale, final int pi
}
setColor(colorNaming);
PrintTool.print(this, (left) ? x - s1max * 6 - 6 : x + s1max * 6 + 9, topborder, 90, name, 1);
line(x, topborder - 4, x, height - bottomborder + 4);
line(x, topborder - 4, x, height - bottomborder + 4, 100);
}

public static void main(final String[] args) {
Expand Down
86 changes: 36 additions & 50 deletions source/net/yacy/visualization/RasterPlotter.java
Expand Up @@ -41,7 +41,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

Expand Down Expand Up @@ -165,56 +164,44 @@ public void plot(final int x, final int y, final int intensity) {
cc[0] = defaultColR;
cc[1] = defaultColG;
cc[2] = defaultColB;
grid.setPixel(x, y, cc);
} else {
int[] c = new int[3];
c = grid.getPixel(x, y, c);
cc[0] = (intensity * defaultColR + (100 - intensity) * c[0]) / 100;
cc[1] = (intensity * defaultColG + (100 - intensity) * c[1]) / 100;
cc[2] = (intensity * defaultColB + (100 - intensity) * c[2]) / 100;
int[] c = grid.getPixel(x, y, cc);
c[0] = (intensity * defaultColR + (100 - intensity) * c[0]) / 100;
c[1] = (intensity * defaultColG + (100 - intensity) * c[1]) / 100;
c[2] = (intensity * defaultColB + (100 - intensity) * c[2]) / 100;
grid.setPixel(x, y, c);
}
} else if (this.defaultMode == MODE_ADD) {
int[] c = new int[3];
c = grid.getPixel(x, y, c);
int[] c = grid.getPixel(x, y, cc);
if (intensity == 100) {
cc[0] = (0xff & c[0]) + defaultColR; if (cc[0] > 255) cc[0] = 255;
cc[1] = (0xff & c[1]) + defaultColG; if (cc[1] > 255) cc[1] = 255;
cc[2] = (0xff & c[2]) + defaultColB; if (cc[2] > 255) cc[2] = 255;
c[0] = (0xff & c[0]) + defaultColR; if (cc[0] > 255) cc[0] = 255;
c[1] = (0xff & c[1]) + defaultColG; if (cc[1] > 255) cc[1] = 255;
c[2] = (0xff & c[2]) + defaultColB; if (cc[2] > 255) cc[2] = 255;
} else {
cc[0] = (0xff & c[0]) + (intensity * defaultColR / 100); if (cc[0] > 255) cc[0] = 255;
cc[1] = (0xff & c[1]) + (intensity * defaultColG / 100); if (cc[1] > 255) cc[1] = 255;
cc[2] = (0xff & c[2]) + (intensity * defaultColB / 100); if (cc[2] > 255) cc[2] = 255;
c[0] = (0xff & c[0]) + (intensity * defaultColR / 100); if (cc[0] > 255) cc[0] = 255;
c[1] = (0xff & c[1]) + (intensity * defaultColG / 100); if (cc[1] > 255) cc[1] = 255;
c[2] = (0xff & c[2]) + (intensity * defaultColB / 100); if (cc[2] > 255) cc[2] = 255;
}
grid.setPixel(x, y, c);
} else if (this.defaultMode == MODE_SUB) {
int[] c = new int[3];
c = grid.getPixel(x, y, c);
int[] c = grid.getPixel(x, y, cc);
if (intensity == 100) {
cc[0] = (0xff & c[0]) - defaultColR; if (cc[0] < 0) cc[0] = 0;
cc[1] = (0xff & c[1]) - defaultColG; if (cc[1] < 0) cc[1] = 0;
cc[2] = (0xff & c[2]) - defaultColB; if (cc[2] < 0) cc[2] = 0;
c[0] = (0xff & c[0]) - defaultColR; if (cc[0] < 0) cc[0] = 0;
c[1] = (0xff & c[1]) - defaultColG; if (cc[1] < 0) cc[1] = 0;
c[2] = (0xff & c[2]) - defaultColB; if (cc[2] < 0) cc[2] = 0;
} else {
cc[0] = (0xff & c[0]) - (intensity * defaultColR / 100); if (cc[0] < 0) cc[0] = 0;
cc[1] = (0xff & c[1]) - (intensity * defaultColG / 100); if (cc[1] < 0) cc[1] = 0;
cc[2] = (0xff & c[2]) - (intensity * defaultColB / 100); if (cc[2] < 0) cc[2] = 0;
c[0] = (0xff & c[0]) - (intensity * defaultColR / 100); if (cc[0] < 0) cc[0] = 0;
c[1] = (0xff & c[1]) - (intensity * defaultColG / 100); if (cc[1] < 0) cc[1] = 0;
c[2] = (0xff & c[2]) - (intensity * defaultColB / 100); if (cc[2] < 0) cc[2] = 0;
}
grid.setPixel(x, y, c);
}
grid.setPixel(x, y, cc);
}
}


public void line(final int Ax, final int Ay, final int Bx, final int By) {
if (this.defaultMode == MODE_REPLACE) {
List<int[]> points = linex(Ax * 2, Ay * 2, Bx * 2, By * 2);
for (int[] point: points) plot(point[0] / 2, point[1] / 2, 100);
} else {
List<int[]> points = linex(Ax * 2, Ay * 2, Bx * 2, By * 2);
for (int[] point: points) plot(point[0] / 2, point[1] / 2, 50);
}
}

private List<int[]> linex(int Ax, int Ay, final int Bx, final int By) {
public void line(int Ax, int Ay, final int Bx, final int By, final int intensity) {
// Bresenham's line drawing algorithm
ArrayList<int[]> points = new ArrayList<int[]>();
int dX = Math.abs(Bx-Ax);
int dY = Math.abs(By-Ay);
int Xincr, Yincr;
Expand All @@ -225,7 +212,7 @@ private List<int[]> linex(int Ax, int Ay, final int Bx, final int By) {
final int dPru = dPr - (dX<<1);
int P = dPr - dX;
for (; dX>=0; dX--) {
points.add(new int[]{Ax, Ay});
plot(Ax, Ay, intensity);
if (P > 0) {
Ax+=Xincr;
Ay+=Yincr;
Expand All @@ -240,7 +227,7 @@ private List<int[]> linex(int Ax, int Ay, final int Bx, final int By) {
final int dPru = dPr - (dY<<1);
int P = dPr - dY;
for (; dY>=0; dY--) {
points.add(new int[]{Ax, Ay});
plot(Ax, Ay, intensity);
if (P > 0) {
Ax+=Xincr;
Ay+=Yincr;
Expand All @@ -251,7 +238,6 @@ private List<int[]> linex(int Ax, int Ay, final int Bx, final int By) {
}
}
}
return points;
}

public void lineDot(final int x0, final int y0, final int x1, final int y1, final int radius, final int distance, final long lineColor, final long dotColor) {
Expand All @@ -275,7 +261,7 @@ public void lineDot(final int x0, final int y0, final int x1, final int y1, fina
final int x3 = x0 + ((int) (rc * Math.cos(angle)));
final int y3 = y0 - ((int) (rc * Math.sin(angle)));
setColor(lineColor);
line(x0, y0, x3, y3);
line(x0, y0, x3, y3, 100);
setColor(dotColor);
dot(x2, y2, radius, true);
}
Expand Down Expand Up @@ -305,7 +291,7 @@ public void arcLine(final int cx, final int cy, final int innerRadius, final int
final int yi = cy - (int) (innerRadius * sina);
final int xo = cx + (int) (outerRadius * cosa);
final int yo = cy - (int) (outerRadius * sina);
line(xi, yi, xo, yo);
line(xi, yi, xo, yo, 100);
}

public void arcDot(final int cx, final int cy, final int arcRadius, final int angle, final int dotRadius) {
Expand All @@ -322,7 +308,7 @@ public void arcConnect(final int cx, final int cy, final int arcRadius, final in
final int y1 = cy - (int) (arcRadius * Math.sin(a1));
final int x2 = cx + (int) (arcRadius * Math.cos(a2));
final int y2 = cy - (int) (arcRadius * Math.sin(a2));
line(x1, y1, x2, y2);
line(x1, y1, x2, y2, 100);
}

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) {
Expand Down Expand Up @@ -644,17 +630,17 @@ else if (filter == FILTER_INVERT) {

public static void demoPaint(final RasterPlotter m) {
m.setColor(GREY);
m.line(0, 70, 100, 70); PrintTool.print(m, 0, 65, 0, "Grey", -1);
m.line(65, 0, 65, 300);
m.line(0, 70, 100, 70, 100); PrintTool.print(m, 0, 65, 0, "Grey", -1);
m.line(65, 0, 65, 300, 100);
m.setColor(RED);
m.line(0, 90, 100, 90); PrintTool.print(m, 0, 85, 0, "Red", -1);
m.line(70, 0, 70, 300);
m.line(0, 90, 100, 90, 100); PrintTool.print(m, 0, 85, 0, "Red", -1);
m.line(70, 0, 70, 300, 100);
m.setColor(GREEN);
m.line(0, 110, 100, 110); PrintTool.print(m, 0, 105, 0, "Green", -1);
m.line(75, 0, 75, 300);
m.line(0, 110, 100, 110, 100); PrintTool.print(m, 0, 105, 0, "Green", -1);
m.line(75, 0, 75, 300, 100);
m.setColor(BLUE);
m.line(0, 130, 100, 130); PrintTool.print(m, 0, 125, 0, "Blue", -1);
m.line(80, 0, 80, 300);
m.line(0, 130, 100, 130, 100); PrintTool.print(m, 0, 125, 0, "Blue", -1);
m.line(80, 0, 80, 300, 100);
}
/*
private static class imageBuffer {
Expand Down

0 comments on commit 55a2536

Please sign in to comment.