redesign of ymage classes

- less memory usage
- better usage of awt classes
- drawing abstractions: preparations for movable objects for animation class
- test applet for animations
- known bugs: wrong colours for network picture

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3214 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent c82f494b08
commit 5515571950

@ -48,13 +48,13 @@ import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaGrafics;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageMatrix;
// draw a picture of the yacy network
public class NetworkPicture {
public static ymagePainter respond(httpHeader header, serverObjects post, serverSwitch env) {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {
int width = 640;
int height = 480;

@ -48,17 +48,16 @@ import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaGrafics;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageMatrix;
// draw a picture of the yacy network
public class SearchEventPicture {
public static ymagePainter respond(httpHeader header, serverObjects post, serverSwitch env) {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {
ymagePainter yp = plasmaGrafics.getSearchEventPicture();
if (yp == null) return new ymageMatrixPainter(1, 1, "000000"); // empty image
ymageMatrix yp = plasmaGrafics.getSearchEventPicture();
if (yp == null) return new ymageMatrix(1, 1, "000000"); // empty image
return yp;
}

@ -47,14 +47,12 @@ import de.anomic.http.httpHeader;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.ymageMatrix;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageToolPrint;
public class imagetest {
public static ymagePainter respond(httpHeader header, serverObjects post, serverSwitch env) {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {
/*
BufferedImage bi = new BufferedImage(640, 400, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
@ -86,27 +84,27 @@ public class imagetest {
for (int i = 20; i < 100; i++) r.setPixel(i, 34, new int[]{0, 0, 255});
return bi;
*/
ymagePainter img = new ymageMatrixPainter(800, 600, "000000");
ymageMatrix img = new ymageMatrix(800, 600, "000000");
img.setMode(ymageMatrix.MODE_ADD);
img.setColor(ymageMatrix.ADDITIVE_BLACK);
for (int y = 0; y < 600; y = y + 50) img.print(0, 6 + y, 0, "" + y, true);
for (int x = 0; x < 800; x = x + 50) img.print(x, 6 , 0, "" + x, true);
img.setColor(ymageMatrix.ADDITIVE_RED);
img.setMode(ymageMatrix.MODE_SUB);
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
for (int y = 0; y < 600; y = y + 50) ymageToolPrint.print(img, 0, 6 + y, 0, "" + y, true);
for (int x = 0; x < 800; x = x + 50) ymageToolPrint.print(img, x, 6 , 0, "" + x, true);
img.setColor(ymageMatrix.SUBTRACTIVE_RED);
img.dot(550, 110, 90, true);
img.setColor(ymageMatrix.ADDITIVE_GREEN);
img.setColor(ymageMatrix.SUBTRACTIVE_GREEN);
img.dot(480, 200, 90, true);
img.setColor(ymageMatrix.ADDITIVE_BLUE);
img.setColor(ymageMatrix.SUBTRACTIVE_BLUE);
img.dot(620, 200, 90, true);
img.setColor(ymageMatrix.ADDITIVE_RED);
img.setColor(ymageMatrix.SUBTRACTIVE_RED);
img.arc(300, 270, 30, 70, 0, 360);
img.setColor("330000");
img.arc(220, 110, 50, 90, 30, 110);
img.arc(210, 120, 50, 90, 30, 110);
img.setColor(ymageMatrix.ADDITIVE_BLACK);
img.print(50, 110, 0, "BROADCAST MESSAGE #772: NODE %882 BLACK abcefghijklmnopqrstuvwxyz", true);
img.setColor(ymageMatrix.ADDITIVE_GREEN);
img.print(50, 120, 0, "BROADCAST MESSAGE #772: NODE %882 GREEN abcefghijklmnopqrstuvwxyz", true);
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
ymageToolPrint.print(img, 50, 110, 0, "BROADCAST MESSAGE #772: NODE %882 BLACK abcefghijklmnopqrstuvwxyz", true);
img.setColor(ymageMatrix.SUBTRACTIVE_GREEN);
ymageToolPrint.print(img, 50, 120, 0, "BROADCAST MESSAGE #772: NODE %882 GREEN abcefghijklmnopqrstuvwxyz", true);
for (long i = 0; i < 256; i++) {
img.setColor(i);
img.dot(10 + 14 * (int) (i / 16), 200 + 14 * (int) (i % 16), 6, true);
@ -128,12 +126,12 @@ public class imagetest {
for (int i = 0; i <= 360; i++) {
img.arc(550, 400, 40, 41 + i/9, 0, i);
}
img.setColor(ymageMatrix.ADDITIVE_BLACK);
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
int angle;
for (byte c = (byte) 'A'; c <= 'Z'; c++) {
angle = (c - (byte) 'A') * 360 / ((byte) 'Z' - (byte) 'A');
img.arcLine(550, 400, 81, 100, angle);
img.arcPrint(550, 400, 100, angle, "ANGLE" + angle + ":" + (char) c);
ymageToolPrint.arcPrint(img, 550, 400, 100, angle, "ANGLE" + angle + ":" + (char) c);
}
return img;

@ -12,6 +12,8 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Random;
import javax.imageio.ImageIO;
import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroCache;
import de.anomic.kelondro.kelondroFlexSplitTable;
@ -26,7 +28,6 @@ import de.anomic.kelondro.kelondroTree;
import de.anomic.server.serverInstantThread;
import de.anomic.server.serverMemory;
import de.anomic.ymage.ymageChart;
import de.anomic.ymage.ymagePNGEncoderAWT;
public class dbtest {
@ -673,7 +674,7 @@ final class memprofiler extends Thread {
try {Thread.sleep(100);} catch (InterruptedException e) {}
}
try {
ymagePNGEncoderAWT.toPNG(memChart, true, outputFile);
ImageIO.write(memChart.getImage(), "png", outputFile);
} catch (IOException e) {}
}

@ -115,9 +115,7 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.servletProperties;
import de.anomic.server.logging.serverLog;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePNGEncoderAWT;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageMatrix;
public final class httpdFileHandler extends httpdAbstractHandler implements httpdHandler {
@ -514,8 +512,8 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
// error with image generation; send file-not-found
httpd.sendRespondError(this.connectionProperties,out,3,404,"File not Found",null,null);
} else {
if (img instanceof ymagePainter) {
ymagePainter yp = (ymagePainter) img;
if (img instanceof ymageMatrix) {
ymageMatrix yp = (ymageMatrix) img;
// send an image to client
targetDate = new Date(System.currentTimeMillis());
nocache = true;
@ -527,9 +525,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
// ymagePNGEncoderJDE((ymageMatrixPainter) yp,
// ymagePNGEncoderJDE.FILTER_NONE, 0);
// byte[] result = jde.pngEncode();
ImageIO.write(ymagePNGEncoderAWT.toImage(
(ymageMatrixPainter) yp, true),
targetExt, baos);
ImageIO.write(yp.getImage(), targetExt, baos);
byte[] result = baos.toByteArray();
baos.close();
baos = null;

@ -53,27 +53,27 @@ import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySearch;
import de.anomic.yacy.yacySeed;
import de.anomic.ymage.ymageMatrix;
import de.anomic.ymage.ymageMatrixPainter;
import de.anomic.ymage.ymagePainter;
import de.anomic.ymage.ymageToolPrint;
public class plasmaGrafics {
private static int shortestName = 10;
private static int longestName = 12;
private static ymagePainter networkPicture = null;
private static ymageMatrix networkPicture = null;
private static long networkPictureDate = 0;
public static ymagePainter getSearchEventPicture() {
public static ymageMatrix getSearchEventPicture() {
if (plasmaSearchEvent.lastEvent == null) return null;
yacySearch[] primarySearches = plasmaSearchEvent.lastEvent.getPrimarySearchThreads();
yacySearch[] secondarySearches = plasmaSearchEvent.lastEvent.getSecondarySearchThreads();
if (primarySearches == null) return null; // this was a local search and there are no threads
// get a copy of a recent network picture
ymagePainter eventPicture = getNetworkPicture(120000);
if (eventPicture instanceof ymageMatrixPainter) eventPicture = new ymageMatrixPainter((ymageMatrix) eventPicture);
ymageMatrix eventPicture = getNetworkPicture(120000);
if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
// TODO: fix cloning of ymageMatrix pictures
// get dimensions
int cr = Math.min(eventPicture.getWidth(), eventPicture.getHeight()) / 5 - 20;
int cx = eventPicture.getWidth() / 2;
@ -84,7 +84,7 @@ public class plasmaGrafics {
// draw in the primary search peers
for (int j = 0; j < primarySearches.length; j++) {
eventPicture.setColor((primarySearches[j].isAlive()) ? ymageMatrix.ADDITIVE_RED : ymageMatrix.ADDITIVE_GREEN);
eventPicture.setColor((primarySearches[j].isAlive()) ? ymageMatrix.SUBTRACTIVE_RED : ymageMatrix.SUBTRACTIVE_GREEN);
hash = primarySearches[j].target().hash;
angle = (int) ((long) 360 * (yacySeed.dhtPosition(hash) / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
eventPicture.arcLine(cx, cy, cr - 20, cr, angle);
@ -93,7 +93,7 @@ public class plasmaGrafics {
// draw in the secondary search peers
if (secondarySearches != null) {
for (int j = 0; j < secondarySearches.length; j++) {
eventPicture.setColor((secondarySearches[j].isAlive()) ? ymageMatrix.ADDITIVE_RED : ymageMatrix.ADDITIVE_GREEN);
eventPicture.setColor((secondarySearches[j].isAlive()) ? ymageMatrix.SUBTRACTIVE_RED : ymageMatrix.SUBTRACTIVE_GREEN);
hash = secondarySearches[j].target().hash;
angle = (int) ((long) 360 * (yacySeed.dhtPosition(hash) / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1);
@ -104,8 +104,8 @@ public class plasmaGrafics {
// draw in the search target
plasmaSearchQuery query = plasmaSearchEvent.lastEvent.getQuery();
Iterator i = query.queryHashes.iterator();
eventPicture.setMode(ymageMatrix.MODE_ADD);
eventPicture.setColor(ymageMatrix.ADDITIVE_BLACK);
eventPicture.setMode(ymageMatrix.MODE_SUB);
eventPicture.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
while (i.hasNext()) {
hash = (String) i.next();
angle = (int) ((long) 360 * (yacySeed.dhtPosition(hash) / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
@ -115,11 +115,11 @@ public class plasmaGrafics {
return eventPicture;
}
public static ymagePainter getNetworkPicture(long maxAge) {
public static ymageMatrix getNetworkPicture(long maxAge) {
return getNetworkPicture(maxAge, 640, 480, 300, 300, 1000, true);
}
public static ymagePainter getNetworkPicture(long maxAge, int width, int height, int passiveLimit, int potentialLimit, int maxCount, boolean corona) {
public static ymageMatrix getNetworkPicture(long maxAge, int width, int height, int passiveLimit, int potentialLimit, int maxCount, boolean corona) {
if ((networkPicture == null) || ((System.currentTimeMillis() - networkPictureDate) > maxAge)) {
drawNetworkPicture(width, height, passiveLimit, potentialLimit, maxCount, corona);
}
@ -134,11 +134,11 @@ public class plasmaGrafics {
if (yacyCore.seedDB == null) return; // no other peers known
networkPicture = new ymageMatrixPainter(width, height, "000010");
networkPicture.setMode(ymageMatrix.MODE_ADD);
networkPicture = new ymageMatrix(width, height, "101010" /*"FFFFE0"*/);
networkPicture.setMode(ymageMatrix.MODE_SUB);
// draw network circle
networkPicture.setColor("008020");
networkPicture.setColor("A02080" /*"008020"*/);
networkPicture.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 0, 360);
//System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance);
@ -154,7 +154,7 @@ public class plasmaGrafics {
while (e.hasMoreElements() && count < maxCount) {
seed = (yacySeed) e.nextElement();
if (seed != null) {
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "000040", "608860", "B0FFB0", corona);
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "404000", "E8C0E8", "B0FFB0", corona);
count++;
}
}
@ -182,27 +182,27 @@ public class plasmaGrafics {
if (seed != null) {
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenTime()) / 1000 / 60);
if (lastseen > potentialLimit) break; // we have enough, this list is sorted so we don't miss anything
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "202000", "505000", "A0A000", corona);
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, "202040", "5050A0", "A0A0FF", corona);
count++;
}
}
totalCount += count;
// draw my own peer
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, yacyCore.seedDB.mySeed, "800000", "AAAAAA", "FFFFFF", corona);
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, yacyCore.seedDB.mySeed, "008080", "AAAAAA", "FFFFFF", corona);
// draw description
networkPicture.setColor("FFFFFF");
networkPicture.setMode(ymageMatrix.MODE_ADD);
networkPicture.print(2, 8, 0, "THE YACY NETWORK", true);
networkPicture.print(2, 16, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", true);
networkPicture.print(width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), false);
networkPicture.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
networkPicture.setMode(ymageMatrix.MODE_SUB);
ymageToolPrint.print(networkPicture, 2, 8, 0, "THE YACY NETWORK", true);
ymageToolPrint.print(networkPicture, 2, 16, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", true);
ymageToolPrint.print(networkPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), false);
// set timestamp
networkPictureDate = System.currentTimeMillis();
}
private static void drawNetworkPicturePeer(ymagePainter img, int x, int y, int innerradius, int outerradius, yacySeed seed, String colorDot, String colorLine, String colorText, boolean corona) {
private static void drawNetworkPicturePeer(ymageMatrix img, int x, int y, int innerradius, int outerradius, yacySeed seed, String colorDot, String colorLine, String colorText, boolean corona) {
String name = seed.getName().toUpperCase();
if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length();
@ -212,7 +212,7 @@ public class plasmaGrafics {
if (linelength > outerradius) linelength = outerradius;
int dotsize = 6 + 2 * (int) (seed.getLinkCount() / 500000L);
if (dotsize > 18) dotsize = 18;
img.setMode(ymageMatrix.MODE_ADD);
img.setMode(ymageMatrix.MODE_SUB);
// draw dot
img.setColor(colorDot);
img.arcDot(x, y, innerradius, angle, dotsize);
@ -221,7 +221,7 @@ public class plasmaGrafics {
img.arcLine(x, y, innerradius + 18, innerradius + linelength, angle);
// draw text
img.setColor(colorText);
img.arcPrint(x, y, innerradius + linelength, angle, name);
ymageToolPrint.arcPrint(img, x, y, innerradius + linelength, angle, name);
// draw corona around dot for crawling activity
int ppm10 = seed.getPPM() / 10;

@ -41,7 +41,7 @@
package de.anomic.ymage;
public class ymageChart extends ymageMatrixPainter {
public class ymageChart extends ymageMatrix {
public static final int DIMENSION_RIGHT = 0;
public static final int DIMENSION_TOP = 1;
@ -67,7 +67,7 @@ public class ymageChart extends ymageMatrixPainter {
this.topborder = topborder;
this.bottomborder = bottomborder;
if (name != null) {
print(width / 2 - name.length() * 3, 6, 0, name, true);
ymageToolPrint.print(this, width / 2 - name.length() * 3, 6, 0, name, true);
}
}
@ -111,12 +111,12 @@ public class ymageChart extends ymageMatrixPainter {
}
setColor(colorNaming);
line(x, y - 3, x, y + 3);
print(x, (top) ? y - 3 : y + 9, 0, Integer.toString(s), true);
ymageToolPrint.print(this, x, (top) ? y - 3 : y + 9, 0, Integer.toString(s), true);
x += pixelperscale;
s += scale;
}
setColor(colorNaming);
print(width - rightborder, (top) ? y - 9 : y + 15, 0, name, false);
ymageToolPrint.print(this, width - rightborder, (top) ? y - 9 : y + 15, 0, name, false);
line(leftborder - 4, y, width - rightborder + 4, y);
}
@ -135,12 +135,12 @@ public class ymageChart extends ymageMatrixPainter {
line(x - 3, y, x + 3, y);
s1 = Integer.toString(s);
if (s1.length() > s1max) s1max = s1.length();
print((left) ? leftborder - 4 : width - rightborder + 4, y, 0, s1, (!left));
ymageToolPrint.print(this, (left) ? leftborder - 4 : width - rightborder + 4, y, 0, s1, (!left));
y -= pixelperscale;
s += scale;
}
setColor(colorNaming);
print((left) ? x - s1max * 6 - 6 : x + s1max * 6 + 9, topborder, 90, name, false);
ymageToolPrint.print(this, (left) ? x - s1max * 6 - 6 : x + s1max * 6 + 9, topborder, 90, name, false);
line(x, topborder - 4, x, height - bottomborder + 4);
}

@ -0,0 +1,68 @@
package de.anomic.ymage;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
public class ymageDemoApplet extends Applet implements Runnable {
// can be run in eclipse with
// Run -> Run As -> Java Applet
// see http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html?page=3
private static final long serialVersionUID = -8230253094143014406L;
int delay;
Thread animator;
Dimension offDimension;
ymageMatrix offGraphics;
public void init() {
String str = getParameter("fps");
int fps = (str != null) ? Integer.parseInt(str) : 10;
delay = (fps > 0) ? (1000 / fps) : 100;
}
public void start() {
animator = new Thread(this);
animator.start();
}
public void run() {
while (Thread.currentThread() == animator) {
long time = System.currentTimeMillis();
repaint();
try {
Thread.sleep(delay - System.currentTimeMillis() + time);
} catch (InterruptedException e) {
break;
}
}
}
public void stop() {
animator = null;
}
public void update(Graphics g) {
Dimension d = getSize();
offGraphics = new ymageMatrix(d.width, d.height, ymageMatrix.SUBTRACTIVE_WHITE);
paintFrame(offGraphics);
g.drawImage(offGraphics.getImage(), 0, 0, null);
}
public void paint(Graphics g) {
if (offGraphics != null) {
g.drawImage(offGraphics.getImage(), 0, 0, null);
}
}
public void paintFrame(ymageMatrix m) {
ymageMatrix.demoPaint(m);
int y = (int) (System.currentTimeMillis() / 10 % 300);
m.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
ymageToolPrint.print(m, 0, y, 0, "Hello World", true);
}
}

@ -47,33 +47,38 @@
package de.anomic.ymage;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import javax.imageio.ImageIO;
import de.anomic.server.serverMemory;
public class ymageMatrix implements Cloneable {
// colors regarding RGB Color Model
public static final long ADDITIVE_RED = 0xFF0000;
public static final long ADDITIVE_GREEN = 0x00FF00;
public static final long ADDITIVE_BLUE = 0x0000FF;
public static final long ADDITIVE_BLACK = 0xFFFFFF;
public class ymageMatrix /*implements Cloneable*/ {
// colors regarding CMY Color Model
public static final long SUBTRACTIVE_CYAN = 0xFF0000;
public static final long SUBTRACTIVE_MAGENTA = 0x00FF00;
public static final long SUBTRACTIVE_YELLOW = 0x0000FF;
public static final long SUBTRACTIVE_WHITE = 0xFFFFFF;
public static final long SUBTRACTIVE_BLACK = 0xFFFFFF;
public static final long SUBTRACTIVE_WHITE = 0x000000;
public static final long SUBTRACTIVE_RED = 0x007F7F;
public static final long SUBTRACTIVE_GREEN = 0x7F007F;
public static final long SUBTRACTIVE_BLUE = 0x7F7F00;
public static final byte MODE_REPLACE = 0;
public static final byte MODE_ADD = 1;
public static final byte MODE_SUB = 2;
protected int width, height;
private byte[] grid; // one-dimensional arrays are much faster than two-dimensional
private int defaultColR, defaultColG, defaultColB;
private byte defaultMode;
private boolean grabComplementary = false;
protected int width, height;
private BufferedImage image;
private WritableRaster grid;
private int[] defaultCol;
private byte defaultMode;
/*
public ymageMatrix(ymageMatrix matrix) throws RuntimeException {
if (!(serverMemory.available(1024 * 1024 + 3 * width * height, true))) throw new RuntimeException("ymage: not enough memory (" + serverMemory.available() + ") available");
// clones the matrix
@ -83,10 +88,10 @@ public class ymageMatrix implements Cloneable {
this.defaultColG = matrix.defaultColG;
this.defaultColB = matrix.defaultColB;
this.defaultMode = matrix.defaultMode;
this.grabComplementary = matrix.grabComplementary;
this.grid = new byte[3 * width * height];
this.grid = (WritableRaster) matrix.grid.
System.arraycopy(matrix.grid, 0, this.grid, 0, matrix.grid.length);
}
*/
public ymageMatrix(int width, int height, String backgroundColor) {
this(width, height, colNum(backgroundColor));
@ -96,40 +101,42 @@ public class ymageMatrix implements Cloneable {
if (!(serverMemory.available(1024 * 1024 + 3 * width * height, true))) throw new RuntimeException("ymage: not enough memory (" + serverMemory.available() + ") available");
this.width = width;
this.height = height;
this.defaultColR = 0xFF;
this.defaultColG = 0xFF;
this.defaultColB = 0xFF;
this.defaultCol = new int[]{0xFF, 0xFF, 0xFF};
this.defaultMode = MODE_REPLACE;
grid = new byte[3 * width * height];
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gr = image.createGraphics();
gr.setBackground(Color.white);
//gr.clearRect(0, 0, width, height);
grid = image.getRaster();
// fill grid with background color
byte bgR = (byte) (backgroundColor >> 16);
byte bgG = (byte) ((backgroundColor >> 8) & 0xff);
byte bgB = (byte) (backgroundColor & 0xff);
for (int n = 3 * width * height - 3; n >= 0; n = n - 3) {
grid[n ] = bgR;
grid[n + 1] = bgG;
grid[n + 2] = bgB;
byte bgR = (byte) (0xFF - (backgroundColor >> 16));
byte bgG = (byte) (0xFF - ((backgroundColor >> 8) & 0xff));
byte bgB = (byte) (0xFF - (backgroundColor & 0xff));
int[] c = new int[]{bgR, bgG, bgB};
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
grid.setPixel(i, j, c);
}
}
}
public BufferedImage getImage() {
return this.image;
}
private static long colNum(String col) {
return Long.parseLong(col, 16);
//return Integer.parseInt(col.substring(0,2), 16) << 16 | Integer.parseInt(col.substring(2,4), 16) << 8 | Integer.parseInt(col.substring(4,6), 16);
}
/*
private static String colStr(long c) {
String s = Long.toHexString(c);
while (s.length() < 6) s = "0" + s;
return s;
}
*/
public Object clone() {
return new ymageMatrix(this);
}
*/
public int getWidth() {
return width;
}
@ -139,9 +146,9 @@ public class ymageMatrix implements Cloneable {
}
public void setColor(long c) {
defaultColR = (int) (c >> 16);
defaultColG = (int) ((c >> 8) & 0xff);
defaultColB = (int) (c & 0xff);
defaultCol[0] = (int) (c >> 16);
defaultCol[1] = (int) ((c >> 8) & 0xff);
defaultCol[2] = (int) (c & 0xff);
}
public void setColor(String s) {
@ -155,29 +162,19 @@ public class ymageMatrix implements Cloneable {
public void plot(int x, int y) {
if ((x < 0) || (x >= width)) return;
if ((y < 0) || (y >= height)) return;
int n = 3 * (x + y * width);
//int n = 3 * (x + y * width);
if (this.defaultMode == MODE_REPLACE) {
grid[n ] = (byte) defaultColR;
grid[n + 1] = (byte) defaultColG;
grid[n + 2] = (byte) defaultColB;
} else if (this.defaultMode == MODE_ADD) {
int r = (0xff & grid[n ]) + defaultColR; if (r > 0xff) r = 0xff;
int g = (0xff & grid[n + 1]) + defaultColG; if (g > 0xff) g = 0xff;
int b = (0xff & grid[n + 2]) + defaultColB; if (b > 0xff) b = 0xff;
grid[n ] = (byte) r;
grid[n + 1] = (byte) g;
grid[n + 2] = (byte) b;
grid.setPixel(x, y, defaultCol);
} else if (this.defaultMode == MODE_SUB) {
int r = (0xff & grid[n ]) - defaultColR; if (r < 0) r = 0;
int g = (0xff & grid[n + 1]) - defaultColG; if (g < 0) g = 0;
int b = (0xff & grid[n + 2]) - defaultColB; if (b < 0) b = 0;
grid[n ] = (byte) r;
grid[n + 1] = (byte) g;
grid[n + 2] = (byte) b;
int[] c = new int[3];
c = grid.getPixel(x, y, c);
int r = (0xff & c[0]) - defaultCol[0]; if (r < 0) r = 0;
int g = (0xff & c[1]) - defaultCol[1]; if (g < 0) g = 0;
int b = (0xff & c[2]) - defaultCol[2]; if (b < 0) b = 0;
grid.setPixel(x, y, new int[]{r, g, b});
}
}
public void line(int Ax, int Ay, int Bx, int By) {
// Bresenham's line drawing algorithm
int dX = Math.abs(Bx-Ax);
@ -218,24 +215,95 @@ public class ymageMatrix implements Cloneable {
}
}
public void getColorMode(boolean grabComplementary) {
this.grabComplementary = grabComplementary;
}
public int[] getColor(int x, int y) {
int n = 3 * (x + y * width);
if (grabComplementary) {
int r = 0xff & grid[n ];
int g = 0xff & grid[n + 1];
int b = 0xff & grid[n + 2];
return new int[]{(0x1fe - g - b) / 2, (0x1fe - r - b) / 2, (0x1fe - r - g) / 2};
int[] c = new int[3];
return grid.getPixel(x, y, c);
}
public void dot(int x, int y, int radius, boolean filled) {
if (filled) {
for (int r = radius; r >= 0; r--) ymageToolCircle.circle(this, x, y, r);
} else {
int r = 0xff & grid[n ];
int g = 0xff & grid[n + 1];
int b = 0xff & grid[n + 2];
return new int[]{r, g, b};
ymageToolCircle.circle(this, x, y, radius);
}
}
public void arc(int x, int y, int innerRadius, int outerRadius, int fromArc, int toArc) {
for (int r = innerRadius; r <= outerRadius; r++) ymageToolCircle.circle(this, x, y, r, fromArc, toArc);
}
public void arcLine(int cx, int cy, int innerRadius, int outerRadius, int angle) {
int xi = cx + (int) (innerRadius * Math.cos(Math.PI * angle / 180));
int yi = cy - (int) (innerRadius * Math.sin(Math.PI * angle / 180));
int xo = cx + (int) (outerRadius * Math.cos(Math.PI * angle / 180));
int yo = cy - (int) (outerRadius * Math.sin(Math.PI * angle / 180));
line(xi, yi, xo, yo);
}
public void arcDot(int cx, int cy, int arcRadius, int angle, int dotRadius) {
int x = cx + (int) (arcRadius * Math.cos(Math.PI * angle / 180));
int y = cy - (int) (arcRadius * Math.sin(Math.PI * angle / 180));
dot(x, y, dotRadius, true);
}
public void arcArc(int cx, int cy, int arcRadius, int angle, int innerRadius, int outerRadius, int fromArc, int toArc) {
int x = cx + (int) (arcRadius * Math.cos(Math.PI * angle / 180));
int y = cy - (int) (arcRadius * Math.sin(Math.PI * angle / 180));
arc(x, y, innerRadius, outerRadius, fromArc, toArc);
}
public static void demoPaint(ymageMatrix m) {
m.setMode(MODE_SUB);
m.setColor(SUBTRACTIVE_CYAN);
m.line(0, 10, 100, 10); ymageToolPrint.print(m, 0, 5, 0, "Cyan", true);
m.line(50, 0, 50, 300);
m.setColor(SUBTRACTIVE_MAGENTA);
m.line(0, 30, 100, 30); ymageToolPrint.print(m, 0, 25, 0, "Magenta", true);
m.line(55, 0, 55, 300);
m.setColor(SUBTRACTIVE_YELLOW);
m.line(0, 50, 100, 50); ymageToolPrint.print(m, 0, 45, 0, "Yellow", true);
m.line(60, 0, 60, 300);
m.setColor(SUBTRACTIVE_BLACK);
m.line(0, 70, 100, 70); ymageToolPrint.print(m, 0, 65, 0, "Black", true);
m.line(65, 0, 65, 300);
m.setColor(SUBTRACTIVE_RED);
m.line(0, 90, 100, 90); ymageToolPrint.print(m, 0, 85, 0, "Red", true);
m.line(70, 0, 70, 300);
m.setColor(SUBTRACTIVE_GREEN);
m.line(0, 110, 100, 110); ymageToolPrint.print(m, 0, 105, 0, "Green", true);
m.line(75, 0, 75, 300);
m.setColor(SUBTRACTIVE_BLUE);
m.line(0, 130, 100, 130); ymageToolPrint.print(m, 0, 125, 0, "Blue", true);
m.line(80, 0, 80, 300);
}
public static void main(String[] args) {
// go into headless awt mode
System.setProperty("java.awt.headless", "true");
ymageMatrix m = new ymageMatrix(200, 300, SUBTRACTIVE_WHITE);
demoPaint(m);
try {
ImageIO.write(m.getImage(), "png", new java.io.File(args[0]));
} catch (java.io.IOException e) {
e.printStackTrace();
}
// open file automatically, works only on Mac OS X
/*
Process p = null;
try {
p = Runtime.getRuntime().exec(new String[] {"/usr/bin/osascript", "-e", "open \"" + args[0] + "\""});
} catch (java.io.IOException e) {
e.printStackTrace();
}
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
}
}

@ -1,262 +0,0 @@
// ymageMatrixPainter.java
// ---------------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
// created: 31.10.2005
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
package de.anomic.ymage;
import java.util.ArrayList;
import java.util.HashSet;
public class ymageMatrixPainter extends ymageMatrix implements ymagePainter {
private static long[] font = new long[]{
0x0000000,0x0421004,0x0A50000,0x0AFABEA,0x0FA38BE,0x09B39B2,0x0E82A8A,0x0420000,
0x0221082,0x0821080,0x0051040,0x0023880,0x0001088,0x0003800,0x0000004,0x0111110,
0x0E9D72E,0x046108E,0x0E8991F,0x0E88A2E,0x0657C42,0x1F8783E,0x0E87A2E,0x1F11084,
0x0E8BA2E,0x0E8BC2E,0x0020080,0x0020088,0x0222082,0x00F83E0,0x0820888,0x0E11004,
0x0EEFA0E,0x04547F1,0x1C97A3E,0x0E8420E,0x1E8C63E,0x1F8721F,0x1F87210,0x0E85E2E,
0x118FE31,0x1F2109F,0x1F0862E,0x1197251,0x108421F,0x11DD631,0x11CD671,0x0E8C62E,
0x1E8FA10,0x0E8D64D,0x1E8FA51,0x0E8382E,0x1F21084,0x118C62E,0x118C544,0x118C6AA,
0x1151151,0x1151084,0x1F1111F,0x0E4210E,0x1041041,0x0E1084E,0x0454400,0x000001F,
0x0820000,0x0003E2F,0x1087A3E,0x0003E0F,0x010BE2F,0x0064A8F,0x0623884,0x00324BE,
0x1085B31,0x0401084,0x0401088,0x1084F93,0x0421084,0x0002AB5,0x0003A31,0x0003A2E,
0x00F47D0,0x007C5E1,0x0011084,0x0001932,0x0471084,0x000462E,0x0004544,0x00056AA,
0x000288A,0x0002884,0x0003C9E,0x0622086,0x0421084,0x0C2088C,0x0045440,0x1F8C63F
};
private static int[][] circles = new int[0][];
public ymageMatrixPainter(int width, int height, String backgroundColor) {
super(width, height, backgroundColor);
}
public ymageMatrixPainter(ymageMatrix matrix) {
super(matrix);
}
private static int[] getCircleCoords(int radius) {
if ((radius - 1) < circles.length) return circles[radius - 1];
// read some lines from known circles
HashSet crds = new HashSet();
crds.add("0|0");
String co;
for (int i = Math.max(0, circles.length - 5); i < circles.length; i++) {
for (int j = 0; j < circles[i].length; j = j + 2) {
co = circles[i][j] + "|" + circles[i][j + 1];
if (!(crds.contains(co))) crds.add(co);
}
}
// copy old circles into new array
int[][] newCircles = new int[radius + 30][];
System.arraycopy(circles, 0, newCircles, 0, circles.length);
// compute more lines in new circles
int x, y;
ArrayList crc;
for (int r = circles.length; r < newCircles.length; r++) {
crc = new ArrayList();
for (int a = 0; a <= 2 * (r + 1); a++) {
x = (int) ((r + 1) * Math.cos(Math.PI * a / (4 * (r + 1))));
y = (int) ((r + 1) * Math.sin(Math.PI * a / (4 * (r + 1))));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new int[]{x, y});
crds.add(co);
}
x = (int) ((r + 0.5) * Math.cos(Math.PI * a / (4 * (r + 1))));
y = (int) ((r + 0.5) * Math.sin(Math.PI * a / (4 * (r + 1))));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new int[]{x, y});
crds.add(co);
}
}
// put coordinates into array
//System.out.print("Radius " + r + " => " + crc.size() + " points: ");
newCircles[r] = new int[2 * (crc.size() - 1)];
int[] coords;
for (int i = 0; i < crc.size() - 1; i++) {
coords = (int[]) crc.get(i);
newCircles[r][2 * i ] = coords[0];
newCircles[r][2 * i + 1] = coords[1];
//System.out.print(circles[r][i][0] + "," +circles[r][i][1] + "; ");
}
//System.out.println();
}
crc = null;
crds = null;
// move newCircles to circles array
circles = newCircles;
newCircles = null;
// finally return wanted slice
return circles[radius - 1];
}
public void circle(int xc, int yc, int radius) {
if (radius == 0) {
plot(xc, yc);
} else {
int[] c = getCircleCoords(radius);
int x, y;
for (int i = (c.length / 2) - 1; i >= 0; i--) {
x = c[2 * i ];
y = c[2 * i + 1];
plot(xc + x , yc - y - 1); // quadrant 1
plot(xc - x + 1, yc - y - 1); // quadrant 2
plot(xc + x , yc + y ); // quadrant 4
plot(xc - x + 1, yc + y ); // quadrant 3
}
}
}
public void circle(int xc, int yc, int radius, int fromArc, int toArc) {
// draws only a part of a circle
// arc is given in degree
if (radius == 0) {
plot(xc, yc);
} else {
int[] c = getCircleCoords(radius);
int q = c.length / 2;
int[][] c4 = new int[q * 4][];
for (int i = 0; i < q; i++) {
c4[i ] = new int[]{ c[2 * (i )], -c[2 * (i ) + 1] - 1}; // quadrant 1
c4[i + q] = new int[]{1 - c[2 * (q - 1 - i)], -c[2 * (q - 1 - i) + 1] - 1}; // quadrant 2
c4[i + 2 * q] = new int[]{1 - c[2 * (i )], c[2 * (i ) + 1] }; // quadrant 3
c4[i + 3 * q] = new int[]{ c[2 * (q - 1 - i)], c[2 * (q - 1 - i) + 1] }; // quadrant 4
}
for (int i = q * 4 * fromArc / 360; i < q * 4 * toArc / 360; i++) {
plot(xc + c4[i][0], yc + c4[i][1]);
}
}
}
public void dot(int x, int y, int radius, boolean filled) {
if (filled) {
for (int r = radius; r >= 0; r--) circle(x, y, r);
} else {
circle(x, y, radius);
}
}
public void arc(int x, int y, int innerRadius, int outerRadius, int fromArc, int toArc) {
for (int r = innerRadius; r <= outerRadius; r++) circle(x, y, r, fromArc, toArc);
}
private void print(int x, int y, int angle, char letter) {
int index = (int) letter - 0x20;
if (index >= font.length) return;
long character = font[index];
long row;
for (int i = 0; i < 5; i++) {
row = character & 0x1f;
character = character >> 5;
if (angle == 0) {
for (int j = 0; j < 5; j++) {
if ((row & 1) == 1) plot(x + 5 - j, y);
row = row >> 1;
}
y--;
}
if (angle == 90) {
for (int j = 0; j < 5; j++) {
if ((row & 1) == 1) plot(x, y - 5 + j);
row = row >> 1;
}
x--;
}
}
}
public void print(int x, int y, int angle, String message, boolean alignLeft) {
int xx = 0, yy = 0;
if (angle == 0) {
xx = (alignLeft) ? x : x - 6 * message.length();
yy = y;
} else if (angle == 90) {
xx = x;
yy = (alignLeft) ? y : y + 6 * message.length();
}
for (int i = 0; i < message.length(); i++) {
print(xx, yy, angle, message.charAt(i));
if (angle == 0) xx += 6;
else if (angle == 90) yy -= 6;
}
}
private static final int arcDist = 8;
public void arcPrint(int cx, int cy, int radius, int angle, String message) {
int x = cx + (int) ((radius + 1) * Math.cos(Math.PI * angle / 180));
int y = cy - (int) ((radius + 1) * Math.sin(Math.PI * angle / 180));
int yp = y + 3;
if ((angle > arcDist) && (angle < 180 - arcDist)) yp = y;
if ((angle > 180 + arcDist) && (angle < 360 - arcDist)) yp = y + 6;
if ((angle > ( 90 - arcDist)) && (angle < ( 90 + arcDist))) yp -= 6;
if ((angle > (270 - arcDist)) && (angle < (270 + arcDist))) yp += 6;
int xp = x - 3 * message.length();
if ((angle > (90 + arcDist)) && (angle < (270 - arcDist))) xp = x - 6 * message.length();
if ((angle < (90 - arcDist)) || (angle > (270 + arcDist))) xp = x;
print(xp, yp, 0, message, true);
}
public void arcLine(int cx, int cy, int innerRadius, int outerRadius, int angle) {
int xi = cx + (int) (innerRadius * Math.cos(Math.PI * angle / 180));
int yi = cy - (int) (innerRadius * Math.sin(Math.PI * angle / 180));
int xo = cx + (int) (outerRadius * Math.cos(Math.PI * angle / 180));
int yo = cy - (int) (outerRadius * Math.sin(Math.PI * angle / 180));
line(xi, yi, xo, yo);
}
public void arcDot(int cx, int cy, int arcRadius, int angle, int dotRadius) {
int x = cx + (int) (arcRadius * Math.cos(Math.PI * angle / 180));
int y = cy - (int) (arcRadius * Math.sin(Math.PI * angle / 180));
dot(x, y, dotRadius, true);
}
public void arcArc(int cx, int cy, int arcRadius, int angle, int innerRadius, int outerRadius, int fromArc, int toArc) {
int x = cx + (int) (arcRadius * Math.cos(Math.PI * angle / 180));
int y = cy - (int) (arcRadius * Math.sin(Math.PI * angle / 180));
arc(x, y, innerRadius, outerRadius, fromArc, toArc);
}
}

@ -1,88 +0,0 @@
// ymagePNGEncoderAWT.java
// ---------------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
// created: 31.10.2005
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
package de.anomic.ymage;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ymagePNGEncoderAWT {
public static BufferedImage toImage(ymageMatrix matrix, boolean complementary) {
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// GraphicsDevice gs = ge.getDefaultScreenDevice();
// GraphicsConfiguration gc = gs.getDefaultConfiguration();
// BufferedImage bi = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
try {
BufferedImage bi = new BufferedImage(matrix.getWidth(), matrix.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D gr = bi.createGraphics();
gr.setBackground(Color.white);
gr.clearRect(0, 0, matrix.getWidth(), matrix.getHeight());
WritableRaster wr = bi.getRaster();
matrix.getColorMode(complementary);
for (int i = matrix.getWidth() - 1; i >= 0; i--) {
for (int j = matrix.getHeight() - 1; j >= 0; j--) {
wr.setPixel(i, j, matrix.getColor(i, j));
}
}
return bi;
} catch (Exception e) {
// strange case where environment disallowes generation of graphics
System.out.println("Error with Graphics environment:");
e.printStackTrace();
return new BufferedImage(0, 0, BufferedImage.TYPE_INT_RGB);
}
}
public static void toPNG(ymageMatrix matrix, boolean complementary, File f) throws IOException {
BufferedImage bi = toImage(matrix, complementary);
ImageIO.write(bi, "png", f);
}
}

@ -463,7 +463,7 @@ public class ymagePNGEncoderJDE extends Object
scanPos = 0;
startPos = 1;
int[] pixel;
matrix.getColorMode(true);
//matrix.getColorMode(true);
for (int i=0; i<width*nRows; i++)
{
if (i % width == 0)

@ -1,80 +0,0 @@
// ymagePainter.java
// ---------------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005
// created: 31.10.2005
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
package de.anomic.ymage;
public interface ymagePainter {
public Object clone();
public int getWidth();
public int getHeight();
public void setColor(String s);
public void setColor(long c);
public void setMode(byte m);
public void plot(int x, int y);
public void line(int Ax, int Ay, int Bx, int By);
public void circle(int xc, int yc, int radius);
public void circle(int xc, int yc, int radius, int fromArc, int toArc);
public void dot(int x, int y, int radius, boolean filled);
public void arc(int x, int y, int innerRadius, int outerRadius, int fromArc, int toArc);
public void print(int x, int y, int angle, String message, boolean alignLeft);
public void arcPrint(int cx, int cy, int radius, int angle, String message);
public void arcLine(int cx, int cy, int innerRadius, int outerRadius, int angle);
public void arcDot(int cx, int cy, int arcRadius, int angle, int dotRadius);
public void arcArc(int cx, int cy, int arcRadius, int angle, int innerRadius, int outerRadius, int fromArc, int toArc);
}

@ -0,0 +1,110 @@
package de.anomic.ymage;
import java.util.ArrayList;
import java.util.HashSet;
public class ymageToolCircle {
private static int[][] circles = new int[0][];
private static int[] getCircleCoords(int radius) {
if ((radius - 1) < circles.length) return circles[radius - 1];
// read some lines from known circles
HashSet crds = new HashSet();
crds.add("0|0");
String co;
for (int i = Math.max(0, circles.length - 5); i < circles.length; i++) {
for (int j = 0; j < circles[i].length; j = j + 2) {
co = circles[i][j] + "|" + circles[i][j + 1];
if (!(crds.contains(co))) crds.add(co);
}
}
// copy old circles into new array
int[][] newCircles = new int[radius + 30][];
System.arraycopy(circles, 0, newCircles, 0, circles.length);
// compute more lines in new circles
int x, y;
ArrayList crc;
for (int r = circles.length; r < newCircles.length; r++) {
crc = new ArrayList();
for (int a = 0; a <= 2 * (r + 1); a++) {
x = (int) ((r + 1) * Math.cos(Math.PI * a / (4 * (r + 1))));
y = (int) ((r + 1) * Math.sin(Math.PI * a / (4 * (r + 1))));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new int[]{x, y});
crds.add(co);
}
x = (int) ((r + 0.5) * Math.cos(Math.PI * a / (4 * (r + 1))));
y = (int) ((r + 0.5) * Math.sin(Math.PI * a / (4 * (r + 1))));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new int[]{x, y});
crds.add(co);
}
}
// put coordinates into array
//System.out.print("Radius " + r + " => " + crc.size() + " points: ");
newCircles[r] = new int[2 * (crc.size() - 1)];
int[] coords;
for (int i = 0; i < crc.size() - 1; i++) {
coords = (int[]) crc.get(i);
newCircles[r][2 * i ] = coords[0];
newCircles[r][2 * i + 1] = coords[1];
//System.out.print(circles[r][i][0] + "," +circles[r][i][1] + "; ");
}
//System.out.println();
}
crc = null;
crds = null;
// move newCircles to circles array
circles = newCircles;
newCircles = null;
// finally return wanted slice
return circles[radius - 1];
}
public static void circle(ymageMatrix matrix, int xc, int yc, int radius) {
if (radius == 0) {
matrix.plot(xc, yc);
} else {
int[] c = getCircleCoords(radius);
int x, y;
for (int i = (c.length / 2) - 1; i >= 0; i--) {
x = c[2 * i ];
y = c[2 * i + 1];
matrix.plot(xc + x , yc - y - 1); // quadrant 1
matrix.plot(xc - x + 1, yc - y - 1); // quadrant 2
matrix.plot(xc + x , yc + y ); // quadrant 4
matrix.plot(xc - x + 1, yc + y ); // quadrant 3
}
}
}
public static void circle(ymageMatrix matrix, int xc, int yc, int radius, int fromArc, int toArc) {
// draws only a part of a circle
// arc is given in degree
if (radius == 0) {
matrix.plot(xc, yc);
} else {
int[] c = getCircleCoords(radius);
int q = c.length / 2;
int[][] c4 = new int[q * 4][];
for (int i = 0; i < q; i++) {
c4[i ] = new int[]{ c[2 * (i )], -c[2 * (i ) + 1] - 1}; // quadrant 1
c4[i + q] = new int[]{1 - c[2 * (q - 1 - i)], -c[2 * (q - 1 - i) + 1] - 1}; // quadrant 2
c4[i + 2 * q] = new int[]{1 - c[2 * (i )], c[2 * (i ) + 1] }; // quadrant 3
c4[i + 3 * q] = new int[]{ c[2 * (q - 1 - i)], c[2 * (q - 1 - i) + 1] }; // quadrant 4
}
for (int i = q * 4 * fromArc / 360; i < q * 4 * toArc / 360; i++) {
matrix.plot(xc + c4[i][0], yc + c4[i][1]);
}
}
}
}

@ -0,0 +1,79 @@
package de.anomic.ymage;
public class ymageToolPrint {
private static long[] font = new long[]{
0x0000000,0x0421004,0x0A50000,0x0AFABEA,0x0FA38BE,0x09B39B2,0x0E82A8A,0x0420000,
0x0221082,0x0821080,0x0051040,0x0023880,0x0001088,0x0003800,0x0000004,0x0111110,
0x0E9D72E,0x046108E,0x0E8991F,0x0E88A2E,0x0657C42,0x1F8783E,0x0E87A2E,0x1F11084,
0x0E8BA2E,0x0E8BC2E,0x0020080,0x0020088,0x0222082,0x00F83E0,0x0820888,0x0E11004,
0x0EEFA0E,0x04547F1,0x1C97A3E,0x0E8420E,0x1E8C63E,0x1F8721F,0x1F87210,0x0E85E2E,
0x118FE31,0x1F2109F,0x1F0862E,0x1197251,0x108421F,0x11DD631,0x11CD671,0x0E8C62E,
0x1E8FA10,0x0E8D64D,0x1E8FA51,0x0E8382E,0x1F21084,0x118C62E,0x118C544,0x118C6AA,
0x1151151,0x1151084,0x1F1111F,0x0E4210E,0x1041041,0x0E1084E,0x0454400,0x000001F,
0x0820000,0x0003E2F,0x1087A3E,0x0003E0F,0x010BE2F,0x0064A8F,0x0623884,0x00324BE,
0x1085B31,0x0401084,0x0401088,0x1084F93,0x0421084,0x0002AB5,0x0003A31,0x0003A2E,
0x00F47D0,0x007C5E1,0x0011084,0x0001932,0x0471084,0x000462E,0x0004544,0x00056AA,
0x000288A,0x0002884,0x0003C9E,0x0622086,0x0421084,0x0C2088C,0x0045440,0x1F8C63F
};
private static void print(ymageMatrix matrix, int x, int y, int angle, char letter) {
int index = (int) letter - 0x20;
if (index >= font.length) return;
long character = font[index];
long row;
for (int i = 0; i < 5; i++) {
row = character & 0x1f;
character = character >> 5;
if (angle == 0) {
for (int j = 0; j < 5; j++) {
if ((row & 1) == 1) matrix.plot(x + 5 - j, y);
row = row >> 1;
}
y--;
}
if (angle == 90) {
for (int j = 0; j < 5; j++) {
if ((row & 1) == 1) matrix.plot(x, y - 5 + j);
row = row >> 1;
}
x--;
}
}
}
public static void print(ymageMatrix matrix, int x, int y, int angle, String message, boolean alignLeft) {
int xx = 0, yy = 0;
if (angle == 0) {
xx = (alignLeft) ? x : x - 6 * message.length();
yy = y;
} else if (angle == 90) {
xx = x;
yy = (alignLeft) ? y : y + 6 * message.length();
}
for (int i = 0; i < message.length(); i++) {
print(matrix, xx, yy, angle, message.charAt(i));
if (angle == 0) xx += 6;
else if (angle == 90) yy -= 6;
}
}
private static final int arcDist = 8;
public static void arcPrint(ymageMatrix matrix, int cx, int cy, int radius, int angle, String message) {
int x = cx + (int) ((radius + 1) * Math.cos(Math.PI * angle / 180));
int y = cy - (int) ((radius + 1) * Math.sin(Math.PI * angle / 180));
int yp = y + 3;
if ((angle > arcDist) && (angle < 180 - arcDist)) yp = y;
if ((angle > 180 + arcDist) && (angle < 360 - arcDist)) yp = y + 6;
if ((angle > ( 90 - arcDist)) && (angle < ( 90 + arcDist))) yp -= 6;
if ((angle > (270 - arcDist)) && (angle < (270 + arcDist))) yp += 6;
int xp = x - 3 * message.length();
if ((angle > (90 + arcDist)) && (angle < (270 - arcDist))) xp = x - 6 * message.length();
if ((angle < (90 - arcDist)) || (angle > (270 + arcDist))) xp = x;
print(matrix, xp, yp, 0, message, true);
}
}
Loading…
Cancel
Save