- the web visualization can now be generated in custom color

- added input fields in WatchWebStructure_p.html
- introduced enum classes for Draw Mode and Filter Mode

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7044 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 64d4204f44
commit 86d7f8a989

@ -41,7 +41,7 @@ public class SearchEventPicture {
final String eventID = header.get("event", SearchEventCache.lastEventID); final String eventID = header.get("event", SearchEventCache.lastEventID);
if (eventID == null) return null; if (eventID == null) return null;
final RasterPlotter yp = NetworkGraph.getSearchEventPicture(sb.peers, eventID, 0); final RasterPlotter yp = NetworkGraph.getSearchEventPicture(sb.peers, eventID, 0);
if (yp == null) return new RasterPlotter(1, 1, RasterPlotter.MODE_SUB, "000000"); // empty image if (yp == null) return new RasterPlotter(1, 1, RasterPlotter.DrawMode.MODE_SUB, "000000"); // empty image
return yp; return yp;
} }

@ -7,10 +7,10 @@
<style type="text/css"> <style type="text/css">
#left { #left {
float: left; float: left;
width: 224px; width: 246px;
} }
form dt { form dt {
width: 40px; width: 70px;
} }
form dd { form dd {
width: 130px; width: 130px;
@ -44,24 +44,29 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
</dd> </dd>
<dt>depth</dt> <dt>depth</dt>
<dd> <dd>
<a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depthd]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[time]#"><img src="env/grafics/minus.gif" width="11" height="11" alt="minus"/></a> <a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depthd]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[time]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#"><img src="env/grafics/minus.gif" width="11" height="11" alt="minus"/></a>
<input type="text" name="depth" value="#[depth]#" size="1" maxlength="1" /> <input type="text" name="depth" value="#[depth]#" size="1" maxlength="1" />
<a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depthi]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[time]#"><img src="env/grafics/plus.gif" width="11" height="11" alt="plus" /></a> <a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depthi]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[time]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#"><img src="env/grafics/plus.gif" width="11" height="11" alt="plus" /></a>
</dd> </dd>
<dt>nodes</dt> <dt>nodes</dt>
<dd> <dd>
<a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodesd]#&amp;time=#[time]#"><img src="env/grafics/minus.gif" width="11" height="11" alt="minus"/></a> <a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodesd]#&amp;time=#[time]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#"><img src="env/grafics/minus.gif" width="11" height="11" alt="minus"/></a>
<input type="text" name="nodes" value="#[nodes]#" size="4" maxlength="4" /> <input type="text" name="nodes" value="#[nodes]#" size="4" maxlength="4" />
<a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodesi]#&amp;time=#[time]#"><img src="env/grafics/plus.gif" width="11" height="11" alt="plus"/></a> <a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodesi]#&amp;time=#[time]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#"><img src="env/grafics/plus.gif" width="11" height="11" alt="plus"/></a>
</dd> </dd>
<dt>time</dt> <dt>time</dt>
<dd> <dd>
<a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[timed]#"><img src="env/grafics/minus.gif" width="11" height="11" alt="minus"/></a> <a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[timed]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#"><img src="env/grafics/minus.gif" width="11" height="11" alt="minus"/></a>
<input type="text" name="time" value="#[time]#" size="4" maxlength="4" /> <input type="text" name="time" value="#[time]#" size="4" maxlength="4" />
<a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[timei]#"><img src="env/grafics/plus.gif" width="11" height="11" alt="plus"/></a> <a href="WatchWebStructure_p.html?host=#[host]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[timei]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#"><img src="env/grafics/plus.gif" width="11" height="11" alt="plus"/></a>
</dd> </dd>
<dt>size</dt> <dt>size</dt>
<dd><input type="text" name="width" value="#[width]#" size="5" maxlength="5" />&nbsp;x&nbsp;<input type="text" name="height" value="#[height]#" size="5" maxlength="5" /></dd> <dd><input type="text" name="width" value="#[width]#" size="5" maxlength="5" />&nbsp;x&nbsp;<input type="text" name="height" value="#[height]#" size="5" maxlength="5" /></dd>
<dt>Background</dt><dd>Color <input type="text" name="colorback" value="#[colorback]#" size="6" maxlength="6" /></dd>
<dt>Text</dt><dd>Color <input type="text" name="colortext" value="#[colortext]#" size="6" maxlength="6" /></dd>
<dt>Line</dt><dd>Color <input type="text" name="colorline" value="#[colorline]#" size="6" maxlength="6" /></dd>
<dt>Dot</dt><dd>Color <input type="text" name="colordot" value="#[colordot]#" size="6" maxlength="6" /></dd>
<dt>Dot-end</dt><dd>Color <input type="text" name="colorlineend" value="#[colorlineend]#" size="6" maxlength="6" /></dd>
<dt>&nbsp;</dt> <dt>&nbsp;</dt>
<dd><input type="submit" value="change" /></dd> <dd><input type="submit" value="change" /></dd>
</dl> </dl>
@ -69,7 +74,7 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
</form> </form>
</div><br /> </div><br />
<img align="right" src="WebStructurePicture_p.png?host=#[besthost]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[time]#" alt="WebStructurePicture"/> <img align="right" src="WebStructurePicture_p.png?host=#[besthost]#&amp;depth=#[depth]#&amp;width=#[width]#&amp;height=#[height]#&amp;nodes=#[nodes]#&amp;time=#[time]#&amp;colortext=#[colortext]#&amp;colorback=#[colorback]#&amp;colordot=#[colordot]#&amp;colorline=#[colorline]#&amp;colorlineend=#[colorlineend]#" alt="WebStructurePicture"/>
#%env/templates/footer.template%# #%env/templates/footer.template%#
</body> </body>

@ -19,6 +19,12 @@ public class WatchWebStructure_p {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
String color_text = "888888";
String color_back = "FFFFFF";
String color_dot = "11BB11";
String color_line = "222222";
String color_lineend = "333333";
int width = 768; int width = 768;
int height = 576; int height = 576;
int depth = 3; int depth = 3;
@ -28,12 +34,17 @@ public class WatchWebStructure_p {
String besthost; String besthost;
if (post != null) { if (post != null) {
width = post.getInt("width", 768); width = post.getInt("width", 768);
height = post.getInt("height", 576); height = post.getInt("height", 576);
depth = post.getInt("depth", 3); depth = post.getInt("depth", 3);
nodes = post.getInt("nodes", width * height * 100 / 768 / 576); nodes = post.getInt("nodes", width * height * 100 / 768 / 576);
time = post.getInt("time", -1); time = post.getInt("time", -1);
host = post.get("host", "auto"); host = post.get("host", "auto");
color_text = post.get("colortext", color_text);
color_back = post.get("colorback", color_back);
color_dot = post.get("colordot", color_dot);
color_line = post.get("colorline", color_line);
color_lineend = post.get("colorlineend", color_lineend);
} }
if (host.equals("auto")) { if (host.equals("auto")) {
@ -77,6 +88,11 @@ public class WatchWebStructure_p {
prop.put("width", width); prop.put("width", width);
prop.put("height", height); prop.put("height", height);
prop.put("colortext", color_text);
prop.put("colorback", color_back);
prop.put("colordot", color_dot);
prop.put("colorline", color_line);
prop.put("colorlineend", color_lineend);
return prop; return prop;
} }
} }

@ -51,6 +51,12 @@ public class WebStructurePicture_p {
public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
String color_text = "888888";
String color_back = "FFFFFF";
String color_dot = "11BB11";
String color_line = "222222";
String color_lineend = "333333";
int width = 768; int width = 768;
int height = 576; int height = 576;
int depth = 3; int depth = 3;
@ -59,12 +65,17 @@ public class WebStructurePicture_p {
String host = null; String host = null;
if (post != null) { if (post != null) {
width = post.getInt("width", 768); width = post.getInt("width", 768);
height = post.getInt("height", 576); height = post.getInt("height", 576);
depth = post.getInt("depth", 3); depth = post.getInt("depth", 3);
nodes = post.getInt("nodes", width * height * 100 / 768 / 576); nodes = post.getInt("nodes", width * height * 100 / 768 / 576);
time = post.getInt("time", -1); time = post.getInt("time", -1);
host = post.get("host", null); host = post.get("host", null);
color_text = post.get("colortext", color_text);
color_back = post.get("colorback", color_back);
color_dot = post.get("colordot", color_dot);
color_line = post.get("colorline", color_line);
color_lineend = post.get("colorlineend", color_lineend);
} }
// too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS. // too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS.
@ -86,7 +97,7 @@ public class WebStructurePicture_p {
RasterPlotter graphPicture; RasterPlotter graphPicture;
if (host == null) { if (host == null) {
// probably no information available // probably no information available
graphPicture = new RasterPlotter(width, height, RasterPlotter.MODE_SUB, GraphPlotter.color_back); graphPicture = new RasterPlotter(width, height, RasterPlotter.DrawMode.MODE_SUB, color_back);
PrintTool.print(graphPicture, width / 2, height / 2, 0, "NO WEB STRUCTURE DATA AVAILABLE.", 0); PrintTool.print(graphPicture, width / 2, height / 2, 0, "NO WEB STRUCTURE DATA AVAILABLE.", 0);
PrintTool.print(graphPicture, width / 2, height / 2 + 16, 0, "START A WEB CRAWL TO OBTAIN STRUCTURE DATA.", 0); PrintTool.print(graphPicture, width / 2, height / 2 + 16, 0, "START A WEB CRAWL TO OBTAIN STRUCTURE DATA.", 0);
} else { } else {
@ -102,10 +113,10 @@ public class WebStructurePicture_p {
if (host != null) place(graph, sb.webStructure, hash, host, nodes, timeout, 0.0, 0.0, 0, depth); if (host != null) place(graph, sb.webStructure, hash, host, nodes, timeout, 0.0, 0.0, 0, depth);
//graph.print(); //graph.print();
graphPicture = graph.draw(width, height, 40, 40, 16, 16); graphPicture = graph.draw(width, height, 40, 40, 16, 16, color_back, color_dot, color_line, color_lineend, color_text);
} }
// print headline // print headline
graphPicture.setColor(GraphPlotter.color_text); graphPicture.setColor(color_text);
PrintTool.print(graphPicture, 2, 8, 0, "YACY WEB-STRUCTURE ANALYSIS", -1); PrintTool.print(graphPicture, 2, 8, 0, "YACY WEB-STRUCTURE ANALYSIS", -1);
if (host != null) PrintTool.print(graphPicture, 2, 16, 0, "LINK ENVIRONMENT OF DOMAIN " + host.toUpperCase(), -1); if (host != null) PrintTool.print(graphPicture, 2, 16, 0, "LINK ENVIRONMENT OF DOMAIN " + host.toUpperCase(), -1);
PrintTool.print(graphPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1); PrintTool.print(graphPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);

@ -64,7 +64,7 @@ public class imagetest {
for (int i = 20; i < 100; i++) r.setPixel(i, 34, new int[]{0, 0, 255}); for (int i = 20; i < 100; i++) r.setPixel(i, 34, new int[]{0, 0, 255});
return bi; return bi;
*/ */
final RasterPlotter img = new RasterPlotter(800, 600, RasterPlotter.MODE_SUB, "FFFFFF"); final RasterPlotter img = new RasterPlotter(800, 600, RasterPlotter.DrawMode.MODE_SUB, "FFFFFF");
img.setColor(RasterPlotter.GREY); img.setColor(RasterPlotter.GREY);
for (int y = 0; y < 600; y = y + 50) PrintTool.print(img, 0, 6 + y, 0, Integer.toString(y), -1); for (int y = 0; y < 600; y = y + 50) PrintTool.print(img, 0, 6 + y, 0, Integer.toString(y), -1);
for (int x = 0; x < 800; x = x + 50) PrintTool.print(img, x, 6 , 0, Integer.toString(x), -1); for (int x = 0; x < 800; x = x + 50) PrintTool.print(img, x, 6 , 0, Integer.toString(x), -1);

@ -171,7 +171,7 @@ public class NetworkGraph {
private static RasterPlotter drawNetworkPicture(final yacySeedDB seedDB, final int width, final int height, final int passiveLimit, final int potentialLimit, final int maxCount, final int coronaangle, final long communicationTimeout, final String networkName, final String networkTitle, final String bgcolor) { private static RasterPlotter drawNetworkPicture(final yacySeedDB seedDB, final int width, final int height, final int passiveLimit, final int potentialLimit, final int maxCount, final int coronaangle, final long communicationTimeout, final String networkName, final String networkTitle, final String bgcolor) {
RasterPlotter networkPicture = new RasterPlotter(width, height, (bgcolor.equals("000000")) ? RasterPlotter.MODE_ADD : RasterPlotter.MODE_SUB, bgcolor); RasterPlotter networkPicture = new RasterPlotter(width, height, (bgcolor.equals("000000")) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB, bgcolor);
if (seedDB == null) return networkPicture; // no other peers known if (seedDB == null) return networkPicture; // no other peers known
final int innerradius = Math.min(width, height) / 5; final int innerradius = Math.min(width, height) / 5;
@ -404,7 +404,7 @@ public class NetworkGraph {
final int exprlength = 19; final int exprlength = 19;
logo = newLogo; logo = newLogo;
bannerPicture = new RasterPlotter(width, height, RasterPlotter.MODE_REPLACE, bgcolor); bannerPicture = new RasterPlotter(width, height, RasterPlotter.DrawMode.MODE_REPLACE, bgcolor);
// draw description // draw description
bannerPicture.setColor(textcolor); bannerPicture.setColor(textcolor);
@ -423,7 +423,7 @@ public class NetworkGraph {
if (logo != null) { if (logo != null) {
final int x = (100/2 - logo.getWidth()/2); final int x = (100/2 - logo.getWidth()/2);
final int y = (height/2 - logo.getHeight()/2); final int y = (height/2 - logo.getHeight()/2);
bannerPicture.insertBitmap(logo, x, y, 0, 0, RasterPlotter.FILTER_ANTIALIASING); bannerPicture.insertBitmap(logo, x, y, 0, 0, RasterPlotter.FilterMode.FILTER_ANTIALIASING);
} }
if (!bordercolor.equals("")) { if (!bordercolor.equals("")) {

@ -61,7 +61,7 @@ public class OSMTile {
width = w * 2 + 1; width = w * 2 + 1;
final int h = (height - 1) / 2; final int h = (height - 1) / 2;
height = h * 2 + 1; height = h * 2 + 1;
final RasterPlotter m = new RasterPlotter(256 * width, 256 * height, RasterPlotter.MODE_REPLACE, "FFFFFF"); final RasterPlotter m = new RasterPlotter(256 * width, 256 * height, RasterPlotter.DrawMode.MODE_REPLACE, "FFFFFF");
List<Place> tileLoader = new ArrayList<Place>(); List<Place> tileLoader = new ArrayList<Place>();
Place place; Place place;
// start tile loading concurrently // start tile loading concurrently

@ -1139,7 +1139,7 @@ public class AnimGifEncoder {
public static void main(final String[] args) { public static void main(final String[] args) {
System.setProperty("java.awt.headless", "true"); System.setProperty("java.awt.headless", "true");
final RasterPlotter m = new RasterPlotter(200, 300, RasterPlotter.MODE_SUB, "FFFFFF"); final RasterPlotter m = new RasterPlotter(200, 300, RasterPlotter.DrawMode.MODE_SUB, "FFFFFF");
RasterPlotter.demoPaint(m); RasterPlotter.demoPaint(m);
final File file = new File("/Users/admin/Desktop/testimage.gif"); final File file = new File("/Users/admin/Desktop/testimage.gif");

@ -32,7 +32,7 @@ import net.yacy.kelondro.logging.Log;
public class Captcha extends RasterPlotter { public class Captcha extends RasterPlotter {
public Captcha(final int width, final int height, final byte displayMode, final String code) { public Captcha(final int width, final int height, final DrawMode displayMode, final String code) {
super(width, height, displayMode, "FFFFFF"); super(width, height, displayMode, "FFFFFF");
this.create(code); this.create(code);
} }
@ -85,7 +85,7 @@ public class Captcha extends RasterPlotter {
// go into headless awt mode // go into headless awt mode
System.setProperty("java.awt.headless", "true"); System.setProperty("java.awt.headless", "true");
final Captcha m = new Captcha(200, 70, RasterPlotter.MODE_REPLACE, args[1]); final Captcha m = new Captcha(200, 70, RasterPlotter.DrawMode.MODE_REPLACE, args[1]);
try { try {
ImageIO.write(m.getImage(), "png", new java.io.File(args[0])); ImageIO.write(m.getImage(), "png", new java.io.File(args[0]));
} catch (final java.io.IOException e) { } catch (final java.io.IOException e) {

@ -53,7 +53,7 @@ public class ChartPlotter extends RasterPlotter {
public ChartPlotter(final int width, final int height, final String backgroundColor, final String foregroundColor, final String lightColor, public ChartPlotter(final int width, final int height, final String backgroundColor, final String foregroundColor, final String lightColor,
final int leftborder, final int rightborder, final int topborder, final int bottomborder, final int leftborder, final int rightborder, final int topborder, final int bottomborder,
final String name, final String subline) { final String name, final String subline) {
super(width, height, RasterPlotter.MODE_REPLACE, backgroundColor); super(width, height, RasterPlotter.DrawMode.MODE_REPLACE, backgroundColor);
this.leftborder = leftborder; this.leftborder = leftborder;
this.rightborder = rightborder; this.rightborder = rightborder;
this.topborder = topborder; this.topborder = topborder;

@ -48,7 +48,7 @@ public class DemoApplet extends Applet implements Runnable {
public void update(final Graphics g) { public void update(final Graphics g) {
final Dimension d = getSize(); final Dimension d = getSize();
offGraphics = new RasterPlotter(d.width, d.height, RasterPlotter.MODE_REPLACE, "FFFFFF"); offGraphics = new RasterPlotter(d.width, d.height, RasterPlotter.DrawMode.MODE_REPLACE, "FFFFFF");
paintFrame(offGraphics); paintFrame(offGraphics);
g.drawImage(offGraphics.getImage(), 0, 0, null); g.drawImage(offGraphics.getImage(), 0, 0, null);
} }

@ -44,13 +44,6 @@ public class GraphPlotter {
// a ymageGraph is a set of points and borders between the points // a ymageGraph is a set of points and borders between the points
// to reference the points, they must all have a nickname // to reference the points, they must all have a nickname
public static final long color_back = 0xFFFFFF;
public static final long color_text = 0x888888;
private static final long color_dot = 0x11BB11;
private static final long color_line = 0x222222;
private static final long color_lineend = 0x333333;
HashMap<String, coordinate> points; HashMap<String, coordinate> points;
HashSet<String> borders; HashSet<String> borders;
double leftmost, rightmost, topmost, bottommost; double leftmost, rightmost, topmost, bottommost;
@ -132,8 +125,23 @@ public class GraphPlotter {
} }
} }
public RasterPlotter draw(final int width, final int height, final int leftborder, final int rightborder, final int topborder, final int bottomborder) { public RasterPlotter draw(
final RasterPlotter image = new RasterPlotter(width, height, RasterPlotter.MODE_SUB, color_back); final int width,
final int height,
final int leftborder,
final int rightborder,
final int topborder,
final int bottomborder,
final String color_back,
final String color_dot,
final String color_line,
final String color_lineend,
final String color_text
) {
RasterPlotter.DrawMode drawMode = RasterPlotter.DrawMode.MODE_SUB;
if (RasterPlotter.darkColor(color_back)) drawMode = RasterPlotter.DrawMode.MODE_ADD;
final RasterPlotter image = new RasterPlotter(width, height, drawMode, color_back);
final double xfactor = ((rightmost - leftmost) == 0.0) ? 0.0 : (width - leftborder - rightborder) / (rightmost - leftmost); final double xfactor = ((rightmost - leftmost) == 0.0) ? 0.0 : (width - leftborder - rightborder) / (rightmost - leftmost);
final double yfactor = ((topmost - bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (topmost - bottommost); final double yfactor = ((topmost - bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (topmost - bottommost);

@ -57,13 +57,13 @@ public class RasterPlotter {
public static final long BLUE = 0x0000FF; public static final long BLUE = 0x0000FF;
public static final long GREY = 0x888888; public static final long GREY = 0x888888;
public static final byte MODE_REPLACE = 0; public static enum DrawMode {
public static final byte MODE_ADD = 1; MODE_REPLACE, MODE_ADD, MODE_SUB;
public static final byte MODE_SUB = 2; }
public static final byte FILTER_ANTIALIASING = 0; public static enum FilterMode {
public static final byte FILTER_BLUR = 1; FILTER_ANTIALIASING, FILTER_BLUR, FILTER_INVERT;
public static final byte FILTER_INVERT = 2; }
protected final int width, height; protected final int width, height;
private final int[] cc; private final int[] cc;
@ -71,13 +71,13 @@ public class RasterPlotter {
private final WritableRaster grid; private final WritableRaster grid;
private int defaultColR, defaultColG, defaultColB; private int defaultColR, defaultColG, defaultColB;
private final long backgroundCol; private final long backgroundCol;
private final byte defaultMode; private DrawMode defaultMode;
public RasterPlotter(final int width, final int height, final byte drawMode, final String backgroundColor) { public RasterPlotter(final int width, final int height, final DrawMode drawMode, final String backgroundColor) {
this(width, height, drawMode, Long.parseLong(backgroundColor, 16)); this(width, height, drawMode, Long.parseLong(backgroundColor, 16));
} }
public RasterPlotter(final int width, final int height, final byte drawMode, final long backgroundColor) { public RasterPlotter(final int width, final int height, final DrawMode drawMode, final long backgroundColor) {
if (!(MemoryControl.request(1024 * 1024 + 3 * width * height, false))) throw new RuntimeException("ymage: not enough memory (" + MemoryControl.available() + ") available"); if (!(MemoryControl.request(1024 * 1024 + 3 * width * height, false))) throw new RuntimeException("ymage: not enough memory (" + MemoryControl.available() + ") available");
this.cc = new int[3]; this.cc = new int[3];
this.width = width; this.width = width;
@ -119,6 +119,10 @@ public class RasterPlotter {
*/ */
} }
public void setDrawMode(DrawMode drawMode) {
this.defaultMode = drawMode;
}
public BufferedImage getImage() { public BufferedImage getImage() {
return this.image; return this.image;
} }
@ -131,8 +135,19 @@ public class RasterPlotter {
return height; return height;
} }
public static boolean darkColor(final String s) {
return darkColor(Long.parseLong(s, 16));
}
public static boolean darkColor(final long c) {
final int r = (int) (c >> 16);
final int g = (int) ((c >> 8) & 0xff);
final int b = (int) (c & 0xff);
return r + g + b < 384;
}
public void setColor(final long c) { public void setColor(final long c) {
if (this.defaultMode == MODE_SUB) { if (this.defaultMode == DrawMode.MODE_SUB) {
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);
@ -159,7 +174,7 @@ public class RasterPlotter {
if ((x < 0) || (x >= width)) return; if ((x < 0) || (x >= width)) return;
if ((y < 0) || (y >= height)) return; if ((y < 0) || (y >= height)) return;
synchronized (cc) { synchronized (cc) {
if (this.defaultMode == MODE_REPLACE) { if (this.defaultMode == DrawMode.MODE_REPLACE) {
if (intensity == 100) { if (intensity == 100) {
cc[0] = defaultColR; cc[0] = defaultColR;
cc[1] = defaultColG; cc[1] = defaultColG;
@ -172,7 +187,7 @@ public class RasterPlotter {
c[2] = (intensity * defaultColB + (100 - intensity) * c[2]) / 100; c[2] = (intensity * defaultColB + (100 - intensity) * c[2]) / 100;
grid.setPixel(x, y, c); grid.setPixel(x, y, c);
} }
} else if (this.defaultMode == MODE_ADD) { } else if (this.defaultMode == DrawMode.MODE_ADD) {
int[] c = grid.getPixel(x, y, cc); int[] c = grid.getPixel(x, y, cc);
if (intensity == 100) { if (intensity == 100) {
c[0] = (0xff & c[0]) + defaultColR; if (cc[0] > 255) cc[0] = 255; c[0] = (0xff & c[0]) + defaultColR; if (cc[0] > 255) cc[0] = 255;
@ -184,7 +199,7 @@ public class RasterPlotter {
c[2] = (0xff & c[2]) + (intensity * defaultColB / 100); if (cc[2] > 255) cc[2] = 255; c[2] = (0xff & c[2]) + (intensity * defaultColB / 100); if (cc[2] > 255) cc[2] = 255;
} }
grid.setPixel(x, y, c); grid.setPixel(x, y, c);
} else if (this.defaultMode == MODE_SUB) { } else if (this.defaultMode == DrawMode.MODE_SUB) {
int[] c = grid.getPixel(x, y, cc); 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]) - defaultColR; if (cc[0] < 0) cc[0] = 0;
@ -240,6 +255,10 @@ public class RasterPlotter {
} }
} }
public void lineDot(final int x0, final int y0, final int x1, final int y1, final int radius, final int distance, final String lineColor, final String dotColor) {
lineDot(x0, y0, x1, y1, radius, distance, Long.parseLong(lineColor, 16), Long.parseLong(dotColor, 16));
}
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) { 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) {
// draw a line with a dot at the end. // draw a line with a dot at the end.
// the radius value is the radius of the dot // the radius value is the radius of the dot
@ -337,7 +356,7 @@ public class RasterPlotter {
* @param filter chooses filter * @param filter chooses filter
* @author Marc Nause * @author Marc Nause
*/ */
public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final byte filter) { public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final FilterMode filter) {
insertBitmap(bitmap, x, y, -1, filter); insertBitmap(bitmap, x, y, -1, filter);
} }
@ -366,7 +385,7 @@ public class RasterPlotter {
* @param filter chooses filter * @param filter chooses filter
* @author Marc Nause * @author Marc Nause
*/ */
public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final int xx, final int yy, final byte filter) { public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final int xx, final int yy, final FilterMode filter) {
insertBitmap(bitmap, x, y, bitmap.getRGB(xx, yy), filter); insertBitmap(bitmap, x, y, bitmap.getRGB(xx, yy), filter);
} }
@ -409,13 +428,13 @@ public class RasterPlotter {
* @param filter chooses filter * @param filter chooses filter
* @author Marc Nause * @author Marc Nause
*/ */
public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final int transRGB, final byte filter) { public void insertBitmap(final BufferedImage bitmap, final int x, final int y, final int transRGB, final FilterMode filter) {
insertBitmap(bitmap, x, y, transRGB); insertBitmap(bitmap, x, y, transRGB);
final int bitmapWidth = bitmap.getWidth(); final int bitmapWidth = bitmap.getWidth();
final int bitmapHeight = bitmap.getHeight(); final int bitmapHeight = bitmap.getHeight();
if (filter == FILTER_ANTIALIASING) { if (filter == FilterMode.FILTER_ANTIALIASING) {
int transX = -1; int transX = -1;
int transY = -1; int transY = -1;
@ -463,7 +482,7 @@ public class RasterPlotter {
* @author Marc Nause * @author Marc Nause
*/ */
public void antialiasing(final int lox, final int loy, final int rux, final int ruy, final int bgcolor) { public void antialiasing(final int lox, final int loy, final int rux, final int ruy, final int bgcolor) {
filter(lox, loy, rux, ruy, FILTER_ANTIALIASING, bgcolor); filter(lox, loy, rux, ruy, FilterMode.FILTER_ANTIALIASING, bgcolor);
} }
/** /**
@ -475,7 +494,7 @@ public class RasterPlotter {
* @author Marc Nause * @author Marc Nause
*/ */
public void blur(final int lox, final int loy, final int rux, final int ruy) { public void blur(final int lox, final int loy, final int rux, final int ruy) {
filter(lox, loy, rux, ruy, FILTER_BLUR, -1); filter(lox, loy, rux, ruy, FilterMode.FILTER_BLUR, -1);
} }
/** /**
@ -487,7 +506,7 @@ public class RasterPlotter {
* @author Marc Nause * @author Marc Nause
*/ */
public void invert(final int lox, final int loy, final int rux, final int ruy) { public void invert(final int lox, final int loy, final int rux, final int ruy) {
filter(lox, loy, rux, ruy, FILTER_INVERT, -1); filter(lox, loy, rux, ruy, FilterMode.FILTER_INVERT, -1);
} }
/** /**
@ -499,7 +518,7 @@ public class RasterPlotter {
* @param filter chooses filter * @param filter chooses filter
* @author Marc Nause * @author Marc Nause
*/ */
private void filter(int lox, int loy, int rux, int ruy, final byte filter, final int bgcolor) { private void filter(int lox, int loy, int rux, int ruy, final FilterMode filter, final int bgcolor) {
// taking care that all values are legal // taking care that all values are legal
if (lox < 0) { lox = 0; } if (lox < 0) { lox = 0; }
@ -539,7 +558,7 @@ public class RasterPlotter {
rgbG = 0; rgbG = 0;
rgbB = 0; rgbB = 0;
if (filter == FILTER_ANTIALIASING || filter == FILTER_BLUR) { if (filter == FilterMode.FILTER_ANTIALIASING || filter == FilterMode.FILTER_BLUR) {
// taking samples from neighbours of pixel // taking samples from neighbours of pixel
if (i > lox) { if (i > lox) {
rgb = image.getRGB(i - 1, j); rgb = image.getRGB(i - 1, j);
@ -589,7 +608,7 @@ public class RasterPlotter {
// 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
// the pixel is on the edge to the background color // the pixel is on the edge to the background color
if ((filter == FILTER_ANTIALIASING && border) || (filter == FILTER_BLUR)) { if (filter == FilterMode.FILTER_ANTIALIASING && border || filter == FilterMode.FILTER_BLUR) {
rgbR += (rgb >> 16 & 0xff); rgbR += (rgb >> 16 & 0xff);
rgbG += (rgb >> 8 & 0xff); rgbG += (rgb >> 8 & 0xff);
rgbB += (rgb & 0xff); rgbB += (rgb & 0xff);
@ -597,14 +616,14 @@ public class RasterPlotter {
border = false; border = false;
} }
// set to value of pixel => keep value // set to value of pixel => keep value
else if (filter == FILTER_ANTIALIASING) { else if (filter == FilterMode.FILTER_ANTIALIASING) {
rgbR = (rgb >> 16 & 0xff); rgbR = (rgb >> 16 & 0xff);
rgbG = (rgb >> 8 & 0xff); rgbG = (rgb >> 8 & 0xff);
rgbB = (rgb & 0xff); rgbB = (rgb & 0xff);
numberOfNeighbours = 1; numberOfNeighbours = 1;
} }
// set value of pixel to inverted value (using XOR) // set value of pixel to inverted value (using XOR)
else if (filter == FILTER_INVERT) { else if (filter == FilterMode.FILTER_INVERT) {
rgb = rgb ^ 0xffffff; rgb = rgb ^ 0xffffff;
rgbR = (rgb >> 16 & 0xff); rgbR = (rgb >> 16 & 0xff);
rgbG = (rgb >> 8 & 0xff); rgbG = (rgb >> 8 & 0xff);
@ -736,7 +755,7 @@ public class RasterPlotter {
// go into headless awt mode // go into headless awt mode
System.setProperty("java.awt.headless", "true"); System.setProperty("java.awt.headless", "true");
final RasterPlotter m = new RasterPlotter(200, 300, MODE_SUB, "FFFFFF"); final RasterPlotter m = new RasterPlotter(200, 300, DrawMode.MODE_SUB, "FFFFFF");
demoPaint(m); demoPaint(m);
final File file = new File("/Users/admin/Desktop/testimage.png"); final File file = new File("/Users/admin/Desktop/testimage.png");
try { try {

Loading…
Cancel
Save