git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1008 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
7a9fc653e9
commit
b058ecf0bc
@ -0,0 +1,573 @@
|
||||
// ymageFontGenerator.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 class ymageFontGenerator {
|
||||
|
||||
/*
|
||||
?0x20: !"#$%&'
|
||||
0x28:()*+,-./
|
||||
0x30:01234567
|
||||
0x38:89:;<=>?
|
||||
0x40:@ABCDEFG
|
||||
0x48:HIJKLMNO
|
||||
0x50:PQRSTUVW
|
||||
0x58:XYZ[\]^_
|
||||
0x60:`abcdefg
|
||||
0x68:hijklmno
|
||||
0x70:pqrstuvw
|
||||
0x78:xyz{|}~
|
||||
*/
|
||||
|
||||
public static final String[][] font =
|
||||
{
|
||||
{".....", //0x20
|
||||
".....",
|
||||
".....",
|
||||
".....",
|
||||
"....."},
|
||||
{"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
".....",
|
||||
"..X.."},
|
||||
{".X.X.",
|
||||
".X.X.",
|
||||
".....",
|
||||
".....",
|
||||
"....."},
|
||||
{".X.X.",
|
||||
"XXXXX",
|
||||
".X.X.",
|
||||
"XXXXX",
|
||||
".X.X."},
|
||||
{".XXXX",
|
||||
"X.X..",
|
||||
".XXX.",
|
||||
"..X.X",
|
||||
"XXXX."},
|
||||
{".X..X",
|
||||
"X.XX.",
|
||||
".XXX.",
|
||||
".XX.X",
|
||||
"X..X."},
|
||||
{".XXX.",
|
||||
"X....",
|
||||
".X.X.",
|
||||
"X.X..",
|
||||
".X.X."},
|
||||
{"..X..",
|
||||
"..X..",
|
||||
".....",
|
||||
".....",
|
||||
"....."},
|
||||
{"...X.", //0x28
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"...X."},
|
||||
{".X...",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
".x..."},
|
||||
{".....",
|
||||
".X.X.",
|
||||
"xxXxx",
|
||||
".x.X.",
|
||||
"....."},
|
||||
{".....",
|
||||
"..X..",
|
||||
".XXX.",
|
||||
"..X..",
|
||||
"....."},
|
||||
{".....",
|
||||
".....",
|
||||
"..X..",
|
||||
"..X..",
|
||||
".X..."},
|
||||
{".....",
|
||||
".....",
|
||||
".XXX.",
|
||||
".....",
|
||||
"....."},
|
||||
{".....",
|
||||
".....",
|
||||
".....",
|
||||
".....",
|
||||
"..X.."},
|
||||
{"....X",
|
||||
"...X.",
|
||||
"..X..",
|
||||
".X...",
|
||||
"X...."},
|
||||
{".XXX.", //0x30
|
||||
"X..XX",
|
||||
"X.X.X",
|
||||
"XX..X",
|
||||
".XXX."},
|
||||
{"..X..",
|
||||
".XX..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
".XXX."},
|
||||
{".XXX.",
|
||||
"X...X",
|
||||
"..XX.",
|
||||
".X...",
|
||||
"XXXXX"},
|
||||
{".XXX.",
|
||||
"X...X",
|
||||
"...X.",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{"..XX.",
|
||||
".X.X.",
|
||||
"XXXXX",
|
||||
"...X.",
|
||||
"...X."},
|
||||
{"XXXXX",
|
||||
"X....",
|
||||
"XXXX.",
|
||||
"....X",
|
||||
"XXXX."},
|
||||
{".XXX.",
|
||||
"X....",
|
||||
"XXXX.",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{"XXXXX",
|
||||
"...X.",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".XXX.", //0x38
|
||||
"X...X",
|
||||
".XXX.",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{".XXX.",
|
||||
"X...X",
|
||||
".XXXX",
|
||||
"....X",
|
||||
".XXX."},
|
||||
{".....",
|
||||
"..X..",
|
||||
".....",
|
||||
"..X..",
|
||||
"....."},
|
||||
{".....",
|
||||
"..X..",
|
||||
".....",
|
||||
"..X..",
|
||||
".X..."},
|
||||
{"...X.",
|
||||
"..X..",
|
||||
".X...",
|
||||
"..X..",
|
||||
"...X."},
|
||||
{".....",
|
||||
"XXXXX",
|
||||
".....",
|
||||
"XXXXX",
|
||||
"....."},
|
||||
{".X...",
|
||||
"..X..",
|
||||
"...X.",
|
||||
"..X..",
|
||||
".X..."},
|
||||
{".XXX.",
|
||||
"...X.",
|
||||
"..X..",
|
||||
".....",
|
||||
"..X.."},
|
||||
{".XXX.", //0x40
|
||||
"XXX.X",
|
||||
"XXXX.",
|
||||
"X....",
|
||||
".XXX."},
|
||||
{"..X..",
|
||||
".X.X.",
|
||||
"X...X",
|
||||
"XXXXX",
|
||||
"X...X"},
|
||||
{"XXX..",
|
||||
"X..X.",
|
||||
"XXXX.",
|
||||
"X...X",
|
||||
"XXXX."},
|
||||
{".XXX.",
|
||||
"X....",
|
||||
"X....",
|
||||
"X....",
|
||||
".XXX."},
|
||||
{"XXXX.",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"XXXX."},
|
||||
{"XXXXX",
|
||||
"X....",
|
||||
"XXX..",
|
||||
"X....",
|
||||
"XXXXX"},
|
||||
{"XXXXX",
|
||||
"X....",
|
||||
"XXX..",
|
||||
"X....",
|
||||
"X...."},
|
||||
{".XXX.",
|
||||
"X....",
|
||||
"X.XXX",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{"X...X", //0x48
|
||||
"X...X",
|
||||
"XXXXX",
|
||||
"X...X",
|
||||
"X...X"},
|
||||
{"XXXXX",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"XXXXX"},
|
||||
{"XXXXX",
|
||||
"....X",
|
||||
"....X",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{"X...X",
|
||||
"X..X.",
|
||||
"XXX..",
|
||||
"X..X..",
|
||||
"X...X"},
|
||||
{"X....",
|
||||
"X....",
|
||||
"X....",
|
||||
"X....",
|
||||
"XXXXX"},
|
||||
{"X...X",
|
||||
"XX.XX",
|
||||
"X.X.X",
|
||||
"X...X",
|
||||
"X...X"},
|
||||
{"X...X",
|
||||
"XX..X",
|
||||
"X.X.X",
|
||||
"X..XX",
|
||||
"X...X"},
|
||||
{".XXX.",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{"XXXX.", //0x50
|
||||
"X...X",
|
||||
"XXXX.",
|
||||
"X....",
|
||||
"X...."},
|
||||
{".XXX.",
|
||||
"X...X",
|
||||
"X.X.X",
|
||||
"X..X.",
|
||||
".XX.X"},
|
||||
{"XXXX.",
|
||||
"X...X",
|
||||
"XXXX.",
|
||||
"X..X.",
|
||||
"X...X"},
|
||||
{".XXX.",
|
||||
"X....",
|
||||
".XXX.",
|
||||
"....X",
|
||||
".XXX."},
|
||||
{"XXXXX",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
".X.X.",
|
||||
"..X.."},
|
||||
{"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"X.X.X",
|
||||
".X.X."},
|
||||
{"X...X", //0x58
|
||||
".X.X.",
|
||||
"..X..",
|
||||
".X.X.",
|
||||
"X...X"},
|
||||
{"X...X",
|
||||
".X.X.",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{"XXXXX",
|
||||
"...X.",
|
||||
"..X..",
|
||||
".X...",
|
||||
"XXXXX"},
|
||||
{".XXX.",
|
||||
".X...",
|
||||
".X...",
|
||||
".X...",
|
||||
".XXX."},
|
||||
{"X....",
|
||||
".X...",
|
||||
"..X..",
|
||||
"...X.",
|
||||
"....X"},
|
||||
{".XXX.",
|
||||
"...X.",
|
||||
"...X.",
|
||||
"...X.",
|
||||
".XXX."},
|
||||
{"..X..",
|
||||
".X.X.",
|
||||
"X...X",
|
||||
".....",
|
||||
"....."},
|
||||
{".....",
|
||||
".....",
|
||||
".....",
|
||||
".....",
|
||||
"XXXXX"},
|
||||
{".X...", //0x60
|
||||
"..X..",
|
||||
".....",
|
||||
".....",
|
||||
"....."},
|
||||
{".....",
|
||||
".....",
|
||||
".XXXX",
|
||||
"X...X",
|
||||
".XXXX"},
|
||||
{"X....",
|
||||
"X....",
|
||||
"XXXX.",
|
||||
"X...X",
|
||||
"XXXX."},
|
||||
{".....",
|
||||
".....",
|
||||
".XXXX",
|
||||
"X....",
|
||||
".XXXX"},
|
||||
{"....X",
|
||||
"....X",
|
||||
".XXXX",
|
||||
"X...X",
|
||||
".XXXX"},
|
||||
{".....",
|
||||
".XX..",
|
||||
"X..X.",
|
||||
"X.X..",
|
||||
".XXXX"},
|
||||
{"..XX.",
|
||||
"..X..",
|
||||
".XXX.",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".....",
|
||||
"..XX.",
|
||||
".X..X",
|
||||
"..X.X",
|
||||
"XXXX."},
|
||||
{"X....", //0x68
|
||||
"X....",
|
||||
"X.XX.",
|
||||
"XX..X",
|
||||
"X...X"},
|
||||
{"..X..",
|
||||
".....",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{"..X..",
|
||||
".....",
|
||||
"..X..",
|
||||
"..X..",
|
||||
".X..."},
|
||||
{"X....",
|
||||
"X....",
|
||||
"X..XX",
|
||||
"XXX..",
|
||||
"X..XX"},
|
||||
{"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".....",
|
||||
".....",
|
||||
".X.X.",
|
||||
"X.X.X",
|
||||
"X.X.X"},
|
||||
{".....",
|
||||
".....",
|
||||
".XXX.",
|
||||
"X...X",
|
||||
"X...X"},
|
||||
{".....",
|
||||
".....",
|
||||
".XXX.",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{".....", //0x70
|
||||
"XXXX.",
|
||||
"X...X",
|
||||
"XXXX.",
|
||||
"X...."},
|
||||
{".....",
|
||||
".XXXX",
|
||||
"X...X",
|
||||
".XXXX",
|
||||
"....X"},
|
||||
{".....",
|
||||
"...X.",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".....",
|
||||
".....",
|
||||
"..XX.",
|
||||
".X..X",
|
||||
"X..X."},
|
||||
{"..X..",
|
||||
".XXX.",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".....",
|
||||
".....",
|
||||
"X...X",
|
||||
"X...X",
|
||||
".XXX."},
|
||||
{".....",
|
||||
".....",
|
||||
"X...X",
|
||||
".X.X.",
|
||||
"..X.."},
|
||||
{".....",
|
||||
".....",
|
||||
"X.X.X",
|
||||
"X.X.X",
|
||||
".X.X."},
|
||||
{".....", //0x78
|
||||
".....",
|
||||
".X.X.",
|
||||
"..X..",
|
||||
".X.X."},
|
||||
{".....",
|
||||
".....",
|
||||
".X.X.",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".....",
|
||||
".....",
|
||||
".XXXX",
|
||||
"..X..",
|
||||
"XXXX."},
|
||||
{"..XX.",
|
||||
"..X..",
|
||||
".X...",
|
||||
"..X..",
|
||||
"..XX."},
|
||||
{"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X..",
|
||||
"..X.."},
|
||||
{".XX..",
|
||||
"..X..",
|
||||
"...X.",
|
||||
"..X..",
|
||||
".XX.."},
|
||||
{".....",
|
||||
".X...",
|
||||
"X.X.X",
|
||||
"...X.",
|
||||
"....."},
|
||||
{"XXXXX",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"X...X",
|
||||
"XXXXX"},
|
||||
};
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] letter;
|
||||
int b;
|
||||
int v;
|
||||
int c = 0;
|
||||
String s;
|
||||
for (int i = 0; i < font.length; i++) {
|
||||
letter = font[i];
|
||||
b = 0;
|
||||
for (int j = 0; j < 5; j++) {
|
||||
b = b << 5;
|
||||
v = 16;
|
||||
for (int col = 0; col < 5; col++) {
|
||||
if (letter[j].charAt(col) == 'X') b += v;
|
||||
v = v >> 1;
|
||||
}
|
||||
}
|
||||
s = Long.toHexString(b).toUpperCase();
|
||||
while (s.length() < 7) s = "0" + s;
|
||||
System.out.print("0x" + s + ",");
|
||||
c++;
|
||||
if (c >= 8) {
|
||||
System.out.println();
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
// ymageMatrix.java
|
||||
// ---------------------------
|
||||
// (C) by Michael Peter Christen; mc@anomic.de
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2005
|
||||
// last major change: 16.09.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.
|
||||
|
||||
/*
|
||||
This Class implements some convenience-methods to support drawing of statistical Data
|
||||
It is not intended to replace existing awt-funktions even if it looks so
|
||||
This class provides some drawing methods that creates transparency effects that
|
||||
are not available in awt.
|
||||
*/
|
||||
|
||||
package de.anomic.ymage;
|
||||
|
||||
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;
|
||||
|
||||
// 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 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;
|
||||
|
||||
public ymageMatrix(int width, int height, String backgroundColor) {
|
||||
this(width, height, colNum(backgroundColor));
|
||||
}
|
||||
|
||||
public ymageMatrix(int width, int height, long backgroundColor) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.defaultColR = 0xFF;
|
||||
this.defaultColG = 0xFF;
|
||||
this.defaultColB = 0xFF;
|
||||
this.defaultMode = MODE_REPLACE;
|
||||
grid = new byte[3*width*height];
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
ymageMatrix ip = new ymageMatrix(this.width, this.height, 0);
|
||||
System.arraycopy(this.grid, 0, ip.grid, 0, this.grid.length);
|
||||
ip.defaultColR = this.defaultColR;
|
||||
ip.defaultColG = this.defaultColG;
|
||||
ip.defaultColB = this.defaultColB;
|
||||
ip.defaultMode = this.defaultMode;
|
||||
return ip;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setColor(long c) {
|
||||
defaultColR = (int) (c >> 16);
|
||||
defaultColG = (int) ((c >> 8) & 0xff);
|
||||
defaultColB = (int) (c & 0xff);
|
||||
}
|
||||
|
||||
public void setColor(String s) {
|
||||
setColor(colNum(s));
|
||||
}
|
||||
|
||||
public void setMode(byte m) {
|
||||
this.defaultMode = m;
|
||||
}
|
||||
|
||||
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);
|
||||
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 = ((int) (0xff & grid[n ])) + defaultColR; if (r > 0xff) r = 0xff;
|
||||
int g = ((int) (0xff & grid[n + 1])) + defaultColG; if (g > 0xff) g = 0xff;
|
||||
int b = ((int) (0xff & grid[n + 2])) + defaultColB; if (b > 0xff) b = 0xff;
|
||||
grid[n ] = (byte) r;
|
||||
grid[n + 1] = (byte) g;
|
||||
grid[n + 2] = (byte) b;
|
||||
} else if (this.defaultMode == MODE_SUB) {
|
||||
int r = ((int) (0xff & grid[n ])) - defaultColR; if (r < 0) r = 0;
|
||||
int g = ((int) (0xff & grid[n + 1])) - defaultColG; if (g < 0) g = 0;
|
||||
int b = ((int) (0xff & grid[n + 2])) - defaultColB; if (b < 0) b = 0;
|
||||
grid[n ] = (byte) r;
|
||||
grid[n + 1] = (byte) g;
|
||||
grid[n + 2] = (byte) b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void line(int Ax, int Ay, int Bx, int By) {
|
||||
// Bresenham's line drawing algorithm
|
||||
int dX = Math.abs(Bx-Ax);
|
||||
int dY = Math.abs(By-Ay);
|
||||
int Xincr, Yincr;
|
||||
if (Ax > Bx) Xincr=-1; else Xincr=1;
|
||||
if (Ay > By) Yincr=-1; else Yincr=1;
|
||||
if (dX >= dY) {
|
||||
int dPr = dY<<1;
|
||||
int dPru = dPr - (dX<<1);
|
||||
int P = dPr - dX;
|
||||
for (; dX>=0; dX--) {
|
||||
plot(Ax, Ay);
|
||||
if (P > 0) {
|
||||
Ax+=Xincr;
|
||||
Ay+=Yincr;
|
||||
P+=dPru;
|
||||
} else {
|
||||
Ax+=Xincr;
|
||||
P+=dPr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int dPr = dX<<1;
|
||||
int dPru = dPr - (dY<<1);
|
||||
int P = dPr - dY;
|
||||
for (; dY>=0; dY--) {
|
||||
plot(Ax, Ay);
|
||||
if (P > 0) {
|
||||
Ax+=Xincr;
|
||||
Ay+=Yincr;
|
||||
P+=dPru;
|
||||
} else {
|
||||
Ay+=Yincr;
|
||||
P+=dPr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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};
|
||||
} else {
|
||||
int r = 0xff & grid[n ];
|
||||
int g = 0xff & grid[n + 1];
|
||||
int b = 0xff & grid[n + 2];
|
||||
return new int[]{r, g, b};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
// 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.Graphics2D;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
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();
|
||||
int n;
|
||||
int r, g, b;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,552 @@
|
||||
/**
|
||||
* PngEncoder takes a Java Image object and creates a byte string which can be saved as a PNG file.
|
||||
* The Image is presumed to use the DirectColorModel.
|
||||
*
|
||||
* Thanks to Jay Denny at KeyPoint Software
|
||||
* http://www.keypoint.com/
|
||||
* who let me develop this code on company time.
|
||||
*
|
||||
* You may contact me with (probably very-much-needed) improvements,
|
||||
* comments, and bug fixes at:
|
||||
*
|
||||
* david@catcode.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* A copy of the GNU LGPL may be found at
|
||||
* http://www.gnu.org/copyleft/lesser.html,
|
||||
*
|
||||
* @author J. David Eisenberg
|
||||
* @version 1.4, 31 March 2000
|
||||
*/
|
||||
|
||||
/*
|
||||
* this file was taken from
|
||||
* http://chem.sis.nlm.nih.gov/chemidplus/applet/chemaxon/marvin/help/PngEncoder.java.txt
|
||||
* and modified by Michael Peter Christen, Frankfurt, 2005
|
||||
* to work with ImagePainter Objects instead of awt.image Objetcs
|
||||
* this avoids using any awt routines
|
||||
*/
|
||||
|
||||
package de.anomic.ymage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.io.*;
|
||||
|
||||
public class ymagePNGEncoderJDE extends Object
|
||||
{
|
||||
/** Constants for filters */
|
||||
public static final int FILTER_NONE = 0;
|
||||
public static final int FILTER_SUB = 1;
|
||||
public static final int FILTER_UP = 2;
|
||||
public static final int FILTER_LAST = 2;
|
||||
|
||||
protected byte[] pngBytes;
|
||||
protected byte[] priorRow;
|
||||
protected byte[] leftBytes;
|
||||
protected ymageMatrix matrix;
|
||||
protected int width, height;
|
||||
protected int bytePos, maxPos;
|
||||
protected int hdrPos, dataPos, endPos;
|
||||
protected CRC32 crc = new CRC32();
|
||||
protected long crcValue;
|
||||
protected boolean encodeAlpha;
|
||||
protected int filter;
|
||||
protected int bytesPerPixel;
|
||||
protected int compressionLevel;
|
||||
|
||||
/**
|
||||
* Class constructor specifying Image source to encode, whether to encode alpha, filter to use, and compression level.
|
||||
*
|
||||
* @param image A Java Image object
|
||||
* @param encodeAlpha Encode the alpha channel? false=no; true=yes
|
||||
* @param whichFilter 0=none, 1=sub, 2=up
|
||||
* @param compLevel 0..9
|
||||
* @see java.awt.Image
|
||||
*/
|
||||
public ymagePNGEncoderJDE(ymageMatrix matrix, int whichFilter, int compLevel)
|
||||
{
|
||||
this.matrix = matrix;
|
||||
this.encodeAlpha = false;
|
||||
setFilter( whichFilter );
|
||||
if (compLevel >=0 && compLevel <=9)
|
||||
{
|
||||
this.compressionLevel = compLevel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an array of bytes that is the PNG equivalent of the current image, specifying whether to encode alpha or not.
|
||||
*
|
||||
* @param encodeAlpha boolean false=no alpha, true=encode alpha
|
||||
* @return an array of bytes, or null if there was a problem
|
||||
*/
|
||||
public byte[] pngEncode( boolean encodeAlpha )
|
||||
{
|
||||
byte[] pngIdBytes = { -119, 80, 78, 71, 13, 10, 26, 10 };
|
||||
int i;
|
||||
|
||||
if (matrix == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
width = matrix.getWidth();
|
||||
height = matrix.getHeight();
|
||||
this.matrix = matrix;
|
||||
|
||||
/*
|
||||
* start with an array that is big enough to hold all the pixels
|
||||
* (plus filter bytes), and an extra 200 bytes for header info
|
||||
*/
|
||||
pngBytes = new byte[((width+1) * height * 3) + 200];
|
||||
|
||||
/*
|
||||
* keep track of largest byte written to the array
|
||||
*/
|
||||
maxPos = 0;
|
||||
|
||||
bytePos = writeBytes( pngIdBytes, 0 );
|
||||
hdrPos = bytePos;
|
||||
writeHeader();
|
||||
dataPos = bytePos;
|
||||
if (writeImageData())
|
||||
{
|
||||
writeEnd();
|
||||
pngBytes = resizeByteArray( pngBytes, maxPos );
|
||||
}
|
||||
else
|
||||
{
|
||||
pngBytes = null;
|
||||
}
|
||||
return pngBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array of bytes that is the PNG equivalent of the current image.
|
||||
* Alpha encoding is determined by its setting in the constructor.
|
||||
*
|
||||
* @return an array of bytes, or null if there was a problem
|
||||
*/
|
||||
public byte[] pngEncode()
|
||||
{
|
||||
return pngEncode( encodeAlpha );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alpha encoding on or off.
|
||||
*
|
||||
* @param encodeAlpha false=no, true=yes
|
||||
*/
|
||||
public void setEncodeAlpha( boolean encodeAlpha )
|
||||
{
|
||||
this.encodeAlpha = encodeAlpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve alpha encoding status.
|
||||
*
|
||||
* @return boolean false=no, true=yes
|
||||
*/
|
||||
public boolean getEncodeAlpha()
|
||||
{
|
||||
return encodeAlpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filter to use
|
||||
*
|
||||
* @param whichFilter from constant list
|
||||
*/
|
||||
public void setFilter( int whichFilter )
|
||||
{
|
||||
this.filter = FILTER_NONE;
|
||||
if ( whichFilter <= FILTER_LAST )
|
||||
{
|
||||
this.filter = whichFilter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve filtering scheme
|
||||
*
|
||||
* @return int (see constant list)
|
||||
*/
|
||||
public int getFilter()
|
||||
{
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the compression level to use
|
||||
*
|
||||
* @param level 0 through 9
|
||||
*/
|
||||
public void setCompressionLevel( int level )
|
||||
{
|
||||
if ( level >= 0 && level <= 9)
|
||||
{
|
||||
this.compressionLevel = level;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve compression level
|
||||
*
|
||||
* @return int in range 0-9
|
||||
*/
|
||||
public int getCompressionLevel()
|
||||
{
|
||||
return compressionLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase or decrease the length of a byte array.
|
||||
*
|
||||
* @param array The original array.
|
||||
* @param newLength The length you wish the new array to have.
|
||||
* @return Array of newly desired length. If shorter than the
|
||||
* original, the trailing elements are truncated.
|
||||
*/
|
||||
protected byte[] resizeByteArray( byte[] array, int newLength )
|
||||
{
|
||||
byte[] newArray = new byte[newLength];
|
||||
int oldLength = array.length;
|
||||
|
||||
System.arraycopy( array, 0, newArray, 0,
|
||||
Math.min( oldLength, newLength ) );
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an array of bytes into the pngBytes array.
|
||||
* Note: This routine has the side effect of updating
|
||||
* maxPos, the largest element written in the array.
|
||||
* The array is resized by 1000 bytes or the length
|
||||
* of the data to be written, whichever is larger.
|
||||
*
|
||||
* @param data The data to be written into pngBytes.
|
||||
* @param offset The starting point to write to.
|
||||
* @return The next place to be written to in the pngBytes array.
|
||||
*/
|
||||
protected int writeBytes( byte[] data, int offset )
|
||||
{
|
||||
maxPos = Math.max( maxPos, offset + data.length );
|
||||
if (data.length + offset > pngBytes.length)
|
||||
{
|
||||
pngBytes = resizeByteArray( pngBytes, pngBytes.length +
|
||||
Math.max( 1000, data.length ) );
|
||||
}
|
||||
System.arraycopy( data, 0, pngBytes, offset, data.length );
|
||||
return offset + data.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an array of bytes into the pngBytes array, specifying number of bytes to write.
|
||||
* Note: This routine has the side effect of updating
|
||||
* maxPos, the largest element written in the array.
|
||||
* The array is resized by 1000 bytes or the length
|
||||
* of the data to be written, whichever is larger.
|
||||
*
|
||||
* @param data The data to be written into pngBytes.
|
||||
* @param nBytes The number of bytes to be written.
|
||||
* @param offset The starting point to write to.
|
||||
* @return The next place to be written to in the pngBytes array.
|
||||
*/
|
||||
protected int writeBytes( byte[] data, int nBytes, int offset )
|
||||
{
|
||||
maxPos = Math.max( maxPos, offset + nBytes );
|
||||
if (nBytes + offset > pngBytes.length)
|
||||
{
|
||||
pngBytes = resizeByteArray( pngBytes, pngBytes.length +
|
||||
Math.max( 1000, nBytes ) );
|
||||
}
|
||||
System.arraycopy( data, 0, pngBytes, offset, nBytes );
|
||||
return offset + nBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a two-byte integer into the pngBytes array at a given position.
|
||||
*
|
||||
* @param n The integer to be written into pngBytes.
|
||||
* @param offset The starting point to write to.
|
||||
* @return The next place to be written to in the pngBytes array.
|
||||
*/
|
||||
protected int writeInt2( int n, int offset )
|
||||
{
|
||||
byte[] temp = { (byte)((n >> 8) & 0xff),
|
||||
(byte) (n & 0xff) };
|
||||
return writeBytes( temp, offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a four-byte integer into the pngBytes array at a given position.
|
||||
*
|
||||
* @param n The integer to be written into pngBytes.
|
||||
* @param offset The starting point to write to.
|
||||
* @return The next place to be written to in the pngBytes array.
|
||||
*/
|
||||
protected int writeInt4( int n, int offset )
|
||||
{
|
||||
byte[] temp = { (byte)((n >> 24) & 0xff),
|
||||
(byte) ((n >> 16) & 0xff ),
|
||||
(byte) ((n >> 8) & 0xff ),
|
||||
(byte) ( n & 0xff ) };
|
||||
return writeBytes( temp, offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a single byte into the pngBytes array at a given position.
|
||||
*
|
||||
* @param n The integer to be written into pngBytes.
|
||||
* @param offset The starting point to write to.
|
||||
* @return The next place to be written to in the pngBytes array.
|
||||
*/
|
||||
protected int writeByte( int b, int offset )
|
||||
{
|
||||
byte[] temp = { (byte) b };
|
||||
return writeBytes( temp, offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string into the pngBytes array at a given position.
|
||||
* This uses the getBytes method, so the encoding used will
|
||||
* be its default.
|
||||
*
|
||||
* @param n The integer to be written into pngBytes.
|
||||
* @param offset The starting point to write to.
|
||||
* @return The next place to be written to in the pngBytes array.
|
||||
* @see java.lang.String#getBytes()
|
||||
*/
|
||||
protected int writeString( String s, int offset )
|
||||
{
|
||||
return writeBytes( s.getBytes(), offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a PNG "IHDR" chunk into the pngBytes array.
|
||||
*/
|
||||
protected void writeHeader()
|
||||
{
|
||||
int startPos;
|
||||
|
||||
startPos = bytePos = writeInt4( 13, bytePos );
|
||||
bytePos = writeString( "IHDR", bytePos );
|
||||
width = matrix.getWidth();
|
||||
height = matrix.getHeight();
|
||||
bytePos = writeInt4( width, bytePos );
|
||||
bytePos = writeInt4( height, bytePos );
|
||||
bytePos = writeByte( 8, bytePos ); // bit depth
|
||||
bytePos = writeByte( (encodeAlpha) ? 6 : 2, bytePos ); // direct model
|
||||
bytePos = writeByte( 0, bytePos ); // compression method
|
||||
bytePos = writeByte( 0, bytePos ); // filter method
|
||||
bytePos = writeByte( 0, bytePos ); // no interlace
|
||||
crc.reset();
|
||||
crc.update( pngBytes, startPos, bytePos-startPos );
|
||||
crcValue = crc.getValue();
|
||||
bytePos = writeInt4( (int) crcValue, bytePos );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform "sub" filtering on the given row.
|
||||
* Uses temporary array leftBytes to store the original values
|
||||
* of the previous pixels. The array is 16 bytes long, which
|
||||
* will easily hold two-byte samples plus two-byte alpha.
|
||||
*
|
||||
* @param pixels The array holding the scan lines being built
|
||||
* @param startPos Starting position within pixels of bytes to be filtered.
|
||||
* @param width Width of a scanline in pixels.
|
||||
*/
|
||||
protected void filterSub( byte[] pixels, int startPos, int width )
|
||||
{
|
||||
int i;
|
||||
int offset = bytesPerPixel;
|
||||
int actualStart = startPos + offset;
|
||||
int nBytes = width * bytesPerPixel;
|
||||
int leftInsert = offset;
|
||||
int leftExtract = 0;
|
||||
byte current_byte;
|
||||
|
||||
for (i=actualStart; i < startPos + nBytes; i++)
|
||||
{
|
||||
leftBytes[leftInsert] = pixels[i];
|
||||
pixels[i] = (byte) ((pixels[i] - leftBytes[leftExtract]) % 256);
|
||||
leftInsert = (leftInsert+1) % 0x0f;
|
||||
leftExtract = (leftExtract + 1) % 0x0f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform "up" filtering on the given row.
|
||||
* Side effect: refills the prior row with current row
|
||||
*
|
||||
* @param pixels The array holding the scan lines being built
|
||||
* @param startPos Starting position within pixels of bytes to be filtered.
|
||||
* @param width Width of a scanline in pixels.
|
||||
*/
|
||||
protected void filterUp( byte[] pixels, int startPos, int width )
|
||||
{
|
||||
int i, nBytes;
|
||||
byte current_byte;
|
||||
|
||||
nBytes = width * bytesPerPixel;
|
||||
|
||||
for (i=0; i < nBytes; i++)
|
||||
{
|
||||
current_byte = pixels[startPos + i];
|
||||
pixels[startPos + i] = (byte) ((pixels[startPos + i] - priorRow[i]) % 256);
|
||||
priorRow[i] = current_byte;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the image data into the pngBytes array.
|
||||
* This will write one or more PNG "IDAT" chunks. In order
|
||||
* to conserve memory, this method grabs as many rows as will
|
||||
* fit into 32K bytes, or the whole image; whichever is less.
|
||||
*
|
||||
*
|
||||
* @return true if no errors; false if error grabbing pixels
|
||||
*/
|
||||
protected boolean writeImageData()
|
||||
{
|
||||
|
||||
|
||||
int rowsLeft = height; // number of rows remaining to write
|
||||
int startRow = 0; // starting row to process this time through
|
||||
int nRows; // how many rows to grab at a time
|
||||
|
||||
byte[] scanLines; // the scan lines to be compressed
|
||||
int scanPos; // where we are in the scan lines
|
||||
int startPos; // where this line's actual pixels start (used for filtering)
|
||||
|
||||
byte[] compressedLines; // the resultant compressed lines
|
||||
int nCompressed; // how big is the compressed area?
|
||||
|
||||
int depth; // color depth ( handle only 8 or 32 )
|
||||
|
||||
bytesPerPixel = (encodeAlpha) ? 4 : 3;
|
||||
|
||||
Deflater scrunch = new Deflater( compressionLevel );
|
||||
ByteArrayOutputStream outBytes =
|
||||
new ByteArrayOutputStream(1024);
|
||||
|
||||
DeflaterOutputStream compBytes =
|
||||
new DeflaterOutputStream( outBytes, scrunch );
|
||||
try
|
||||
{
|
||||
while (rowsLeft > 0)
|
||||
{
|
||||
|
||||
nRows = Math.min( 32767 / (width*(bytesPerPixel+1)), rowsLeft );
|
||||
// nRows = rowsLeft;
|
||||
|
||||
/*
|
||||
* Create a data chunk. scanLines adds "nRows" for
|
||||
* the filter bytes.
|
||||
*/
|
||||
scanLines = new byte[width * nRows * bytesPerPixel + nRows];
|
||||
|
||||
if (filter == FILTER_SUB)
|
||||
{
|
||||
leftBytes = new byte[16];
|
||||
}
|
||||
if (filter == FILTER_UP)
|
||||
{
|
||||
priorRow = new byte[width*bytesPerPixel];
|
||||
}
|
||||
|
||||
scanPos = 0;
|
||||
startPos = 1;
|
||||
int[] pixel;
|
||||
matrix.getColorMode(true);
|
||||
for (int i=0; i<width*nRows; i++)
|
||||
{
|
||||
if (i % width == 0)
|
||||
{
|
||||
scanLines[scanPos++] = (byte) filter;
|
||||
startPos = scanPos;
|
||||
}
|
||||
pixel = matrix.getColor(i % width, i / width);
|
||||
scanLines[scanPos++] = (byte) pixel[0]; // red
|
||||
scanLines[scanPos++] = (byte) pixel[1]; // green
|
||||
scanLines[scanPos++] = (byte) pixel[2]; // blue
|
||||
if (encodeAlpha)
|
||||
{
|
||||
//scanLines[scanPos++] = (byte) ((pixels[i] >> 24) & 0xff );
|
||||
}
|
||||
if ((i % width == width-1) && (filter != FILTER_NONE))
|
||||
{
|
||||
if (filter == FILTER_SUB)
|
||||
{
|
||||
filterSub( scanLines, startPos, width );
|
||||
}
|
||||
if (filter == FILTER_UP)
|
||||
{
|
||||
filterUp( scanLines, startPos, width );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write these lines to the output area
|
||||
*/
|
||||
compBytes.write( scanLines, 0, scanPos );
|
||||
|
||||
|
||||
startRow += nRows;
|
||||
rowsLeft -= nRows;
|
||||
}
|
||||
compBytes.close();
|
||||
|
||||
/*
|
||||
* Write the compressed bytes
|
||||
*/
|
||||
compressedLines = outBytes.toByteArray();
|
||||
nCompressed = compressedLines.length;
|
||||
|
||||
crc.reset();
|
||||
bytePos = writeInt4( nCompressed, bytePos );
|
||||
bytePos = writeString("IDAT", bytePos );
|
||||
crc.update("IDAT".getBytes());
|
||||
bytePos = writeBytes( compressedLines, nCompressed, bytePos );
|
||||
crc.update( compressedLines, 0, nCompressed );
|
||||
|
||||
crcValue = crc.getValue();
|
||||
bytePos = writeInt4( (int) crcValue, bytePos );
|
||||
scrunch.finish();
|
||||
return true;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println( e.toString());
|
||||
return false;
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a PNG "IEND" chunk into the pngBytes array.
|
||||
*/
|
||||
protected void writeEnd()
|
||||
{
|
||||
bytePos = writeInt4( 0, bytePos );
|
||||
bytePos = writeString( "IEND", bytePos );
|
||||
crc.reset();
|
||||
crc.update("IEND".getBytes());
|
||||
crcValue = crc.getValue();
|
||||
bytePos = writeInt4( (int) crcValue, bytePos );
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
// 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);
|
||||
|
||||
}
|
Loading…
Reference in new issue