first big cleanup
parent
445eb8f1c3
commit
378baf6192
@ -0,0 +1,2 @@
|
||||
*.png
|
||||
build/
|
@ -1,9 +0,0 @@
|
||||
package deepZoom;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//new MandelAnimator();
|
||||
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package deepZoom.calculator;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date Apr 19, 2009
|
||||
*/
|
||||
public interface Calculator {
|
||||
|
||||
public void prepareCalculation();
|
||||
|
||||
public void calculate(int cpu);
|
||||
|
||||
public void calculationCompleted();
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package deepZoom.calculator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date Apr 19, 2009
|
||||
*/
|
||||
public class ParallelCalculator implements Runnable {
|
||||
|
||||
private static int NUM_CPUS;
|
||||
private static boolean[] WAIT;
|
||||
private static boolean[] GO;
|
||||
|
||||
public static void createCalculators(Calculator calculator, int numCPUs) {
|
||||
ParallelCalculator.NUM_CPUS = numCPUs;
|
||||
|
||||
ParallelCalculator.WAIT = new boolean[numCPUs];
|
||||
ParallelCalculator.GO = new boolean[numCPUs];
|
||||
|
||||
for (int i = 0; i < numCPUs; i++) {
|
||||
new ParallelCalculator(calculator, i);
|
||||
}
|
||||
}
|
||||
private int cpu;
|
||||
private Calculator calculator;
|
||||
|
||||
private ParallelCalculator(Calculator calculator, int cpu) {
|
||||
this.calculator = calculator;
|
||||
this.cpu = cpu;
|
||||
|
||||
System.out.println("Starting core " + cpu);
|
||||
|
||||
prepare();
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
calculator.calculate(cpu);
|
||||
syncWithOthers();
|
||||
}
|
||||
}
|
||||
|
||||
private void prepare() {
|
||||
if (cpu == 0) {
|
||||
Arrays.fill(ParallelCalculator.WAIT, true);
|
||||
Arrays.fill(ParallelCalculator.GO, true);
|
||||
|
||||
calculator.prepareCalculation();
|
||||
}
|
||||
}
|
||||
|
||||
private void syncWithOthers() {
|
||||
ParallelCalculator.WAIT[cpu] = false;
|
||||
|
||||
if (cpu == 0) {
|
||||
while (true) {
|
||||
boolean done = true;
|
||||
for (int i = ParallelCalculator.NUM_CPUS - 1; i >= 0; i--) {
|
||||
if (ParallelCalculator.WAIT[i]) {
|
||||
done = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
// All threads done.
|
||||
|
||||
calculator.calculationCompleted();
|
||||
prepare();
|
||||
|
||||
Arrays.fill(ParallelCalculator.WAIT, true);
|
||||
Arrays.fill(ParallelCalculator.GO, true);
|
||||
} else {
|
||||
while (!ParallelCalculator.GO[cpu]) {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ParallelCalculator.GO[cpu] = false;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package deepZoom.renderer;
|
||||
|
||||
import deepZoom.colorings.Coloring;
|
||||
import deepZoom.fractals.Fractal;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date May 3, 2009
|
||||
*/
|
||||
public class Layer {
|
||||
|
||||
protected Fractal fractal;
|
||||
protected Coloring coloring;
|
||||
|
||||
public void setFractal(Fractal fractal) {
|
||||
this.fractal = fractal;
|
||||
}
|
||||
|
||||
public void setColoring(Coloring coloring) {
|
||||
this.coloring = coloring;
|
||||
}
|
||||
|
||||
public void initFrame() {
|
||||
fractal.initFrame();
|
||||
coloring.initParameters();
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/02
|
||||
*/
|
||||
public class AngularScheduler extends Scheduler {
|
||||
|
||||
private int bands;
|
||||
|
||||
public AngularScheduler(int bands) {
|
||||
this.bands = bands;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
double dy = y - (height - 0.875) * 0.5;
|
||||
for (int x = 0; x < width; x++) {
|
||||
double dx = x - (width - 0.75) * 0.5;
|
||||
|
||||
double a = StrictMath.abs((StrictMath.atan2(dy, -dx) / (2 * StrictMath.PI) + 0.5) * bands % 1 - 0.5);
|
||||
add(new PriorityPoint(i, x, y, -a));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/05
|
||||
*/
|
||||
public class CRTScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int dy = height - y;
|
||||
for (int x = 0; x < width; x++) {
|
||||
int dx = width - x;
|
||||
add(new PriorityPoint(i, x, y, -x * y * dx * dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/02
|
||||
*/
|
||||
public class ClockScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
double dy = y - (height - 0.875) * 0.5;
|
||||
for (int x = 0; x < width; x++) {
|
||||
double dx = x - (width - 0.75) * 0.5;
|
||||
add(new PriorityPoint(i, x, y, Math.atan2(-dy, -dx)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/03
|
||||
*/
|
||||
public class DitherScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int dy = Integer.reverse(y) >>> 16;
|
||||
for (int x = 0; x < width; x++) {
|
||||
int dx = Integer.reverse(x) >>> 16;
|
||||
|
||||
add(new PriorityPoint(i, x, y, dx + dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/03
|
||||
*/
|
||||
public class FlowerScheduler extends Scheduler {
|
||||
|
||||
private int petals;
|
||||
private double petalSize;
|
||||
|
||||
public FlowerScheduler(int petals, double petalSize) {
|
||||
this.petals = petals;
|
||||
this.petalSize = 4 / petalSize + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
double dy = y - (height - 0.875) * 0.5;
|
||||
for (int x = 0; x < width; x++) {
|
||||
double dx = x - (width - 0.75) * 0.5;
|
||||
|
||||
double a = StrictMath.atan2(dy, -dx) * petals;
|
||||
double r = StrictMath.sqrt(dx * dx + dy * dy);
|
||||
dx = r * (StrictMath.cos(a) + petalSize);
|
||||
add(new PriorityPoint(i, x, y, dx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/05
|
||||
*/
|
||||
public class ModScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
add(new PriorityPoint(i, x, y, x % (y + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/04/17
|
||||
*/
|
||||
public class PriorityPoint implements Comparable<PriorityPoint> {
|
||||
|
||||
public int layer;
|
||||
public int x;
|
||||
public int y;
|
||||
private double priority;
|
||||
|
||||
public PriorityPoint(int layer, int x, int y, double priority) {
|
||||
this.layer = layer;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PriorityPoint other) {
|
||||
double d = priority - other.priority;
|
||||
return d < 0 ? -1 : d > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "[layer " + layer + ", (" + x + ", " + y + ")]";
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/03
|
||||
*/
|
||||
public class PythagorasScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
||||
add(new PriorityPoint(i, x, y, x & y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/04/17
|
||||
*/
|
||||
public class RadialScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
double dy = y - (height - 0.875) * 0.5;
|
||||
dy *= dy;
|
||||
for (int x = 0; x < width; x++) {
|
||||
double dx = x - (width - 0.75) * 0.5;
|
||||
|
||||
add(new PriorityPoint(i, x, y, dx * dx + dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
import digisoft.custom.NumberFunctions;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/02
|
||||
*/
|
||||
public class RandomScheduler extends Scheduler {
|
||||
|
||||
private int area = -1;
|
||||
private double[] order;
|
||||
private int position = 0;
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
if (area != width * height) {
|
||||
area = width * height;
|
||||
|
||||
order = new double[area];
|
||||
for (int i = 0; i < area; i++) {
|
||||
order[i] = NumberFunctions.RND.nextDouble();
|
||||
}
|
||||
}
|
||||
|
||||
super.clear();
|
||||
|
||||
int p = position;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
add(new PriorityPoint(i, x, y, order[p]));
|
||||
}
|
||||
p = (p + 1) % area;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PriorityPoint poll() {
|
||||
position = (position + area - 1) % area;
|
||||
return super.poll();
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import deepZoom.viewports.Viewport;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/04/17
|
||||
*/
|
||||
public abstract class Scheduler extends PriorityBlockingQueue<PriorityPoint> {
|
||||
|
||||
protected int numLayers = 1;
|
||||
protected int width;
|
||||
protected int height;
|
||||
private int total;
|
||||
private Viewport viewport;
|
||||
|
||||
public void setNumLayers(int numLayers) {
|
||||
this.numLayers = numLayers;
|
||||
}
|
||||
|
||||
public void setViewport(Viewport viewport) {
|
||||
this.viewport = viewport;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
width = viewport.width;
|
||||
height = viewport.height;
|
||||
|
||||
initImpl();
|
||||
|
||||
total = super.size();
|
||||
}
|
||||
|
||||
protected abstract void initImpl();
|
||||
|
||||
public double getProgress() {
|
||||
return (total - super.size()) / (double) total;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/03
|
||||
*/
|
||||
public class SimpleScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int dy = y * width;
|
||||
for (int x = 0; x < width; x++) {
|
||||
add(new PriorityPoint(i, x, y, dy + x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/02
|
||||
*/
|
||||
public class SpiralScheduler extends Scheduler {
|
||||
|
||||
private double thickness;
|
||||
|
||||
public SpiralScheduler(double thickness) {
|
||||
this.thickness = thickness;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
double dy = y - (height - 0.875) * 0.5;
|
||||
for (int x = 0; x < width; x++) {
|
||||
double dx = x - (width - 0.75) * 0.5;
|
||||
|
||||
double a = StrictMath.atan2(dy, -dx) / (2 * StrictMath.PI);
|
||||
dx = (int) (a + StrictMath.sqrt(dx * dx + dy * dy) / thickness) * thickness - a;
|
||||
add(new PriorityPoint(i, x, y, dx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/03
|
||||
*/
|
||||
public class SplitScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int dy = StrictMath.abs(y - (height >> 1)) * width;
|
||||
for (int x = 0; x < width; x++) {
|
||||
add(new PriorityPoint(i, x, y, dy + x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/04
|
||||
*/
|
||||
public class SquareSpiralScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int dy = y - (height >> 1);
|
||||
for (int x = 0; x < width; x++) {
|
||||
int dx = x - (width >> 1);
|
||||
|
||||
if (dx > dy) {
|
||||
if (dx < -dy) {
|
||||
dx = 4 * dy * dy + 7 * dy + 3 + dx;
|
||||
} else {
|
||||
dx = 4 * dx * dx + 3 * dx + 1 + dy;
|
||||
}
|
||||
} else if (dx < -dy) {
|
||||
dx = 4 * dx * dx + 1 * dx - 1 - dy;
|
||||
} else {
|
||||
dx = 4 * dy * dy + 5 * dy + 1 - dx;
|
||||
}
|
||||
|
||||
add(new PriorityPoint(i, x, y, dx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package deepZoom.schedulers;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/05/03
|
||||
*/
|
||||
public class XorScheduler extends Scheduler {
|
||||
|
||||
@Override
|
||||
protected void initImpl() {
|
||||
super.clear();
|
||||
|
||||
for (int i = 0; i < numLayers; i++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int dy = StrictMath.abs(y - (height >> 1));
|
||||
for (int x = 0; x < width; x++) {
|
||||
int dx = StrictMath.abs(x - (width >> 1));
|
||||
|
||||
add(new PriorityPoint(i, x, y, dx ^ dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package digisoft.custom.swing;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.RenderingHints;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2007/12/01
|
||||
*/
|
||||
public class GraphicsFunctions {
|
||||
|
||||
public static final BasicStroke DEFAULT_SQUARE_STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
|
||||
public static final BasicStroke DEFAULT_ROUND_STROKE = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
|
||||
public static void setNiceLookAndFeel() {
|
||||
try {
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAntialiased(Graphics2D g, boolean antialiased) {
|
||||
if (antialiased && g.getRenderingHint(RenderingHints.KEY_ANTIALIASING) != RenderingHints.VALUE_ANTIALIAS_ON) {
|
||||
g.translate(0.5, 0.5);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
||||
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||
}
|
||||
if (!antialiased && g.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) {
|
||||
g.translate(-0.5, -0.5);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_DEFAULT);
|
||||
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
public static GraphicsDevice getDisplayDevice() {
|
||||
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||
}
|
||||
|
||||
public static DisplayMode getDisplayMode(int width, int height) {
|
||||
DisplayMode currentMode = GraphicsFunctions.getDisplayDevice().getDisplayMode();
|
||||
DisplayMode[] modes = GraphicsFunctions.getDisplayDevice().getDisplayModes();
|
||||
|
||||
int bitDepth = currentMode.getBitDepth();
|
||||
int refreshRate = currentMode.getRefreshRate();
|
||||
|
||||
for (DisplayMode mode : modes) {
|
||||
if (mode.getHeight() == height && mode.getWidth() == width && mode.getBitDepth() == bitDepth && mode.getRefreshRate() == refreshRate) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
refreshRate = Integer.MAX_VALUE;
|
||||
int index = -1;
|
||||
for (int i = modes.length - 1; i >= 0; i--) {
|
||||
DisplayMode mode = modes[i];
|
||||
if (mode.getHeight() == height && mode.getWidth() == width && mode.getBitDepth() == bitDepth) {
|
||||
if (refreshRate > mode.getRefreshRate()) {
|
||||
refreshRate = mode.getRefreshRate();
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return index < 0 ? null : modes[index];
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package digisoft.custom.swing;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.sun.image.codec.jpeg.JPEGCodec;
|
||||
import com.sun.image.codec.jpeg.JPEGEncodeParam;
|
||||
import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/04/28
|
||||
*/
|
||||
public class ImageFunctions {
|
||||
|
||||
public static final int SCALE_HINT_ALWAYS = 0;
|
||||
public static final int SCALE_HINT_FIT_INSIDE = 1;
|
||||
public static final int SCALE_HINT_WHEN_NECESSARY = 2;
|
||||
|
||||
public static ImageIcon scaleImage(ImageIcon imageIcon, int width, int height, int scalingHint) {
|
||||
switch (scalingHint) {
|
||||
case SCALE_HINT_WHEN_NECESSARY: {
|
||||
if (imageIcon.getIconWidth() <= width && imageIcon.getIconHeight() <= height) {
|
||||
return imageIcon;
|
||||
}
|
||||
// Fall through.
|
||||
}
|
||||
case SCALE_HINT_ALWAYS: {
|
||||
return ImageFunctions.scaleImage(imageIcon, width, height);
|
||||
}
|
||||
case SCALE_HINT_FIT_INSIDE: {
|
||||
Image image = imageIcon.getImage();
|
||||
|
||||
double wf = (double) width / image.getWidth(null);
|
||||
double hf = (double) height / image.getHeight(null);
|
||||
|
||||
if (wf > hf) {
|
||||
height = (int) (wf * image.getHeight(null) + 0.5);
|
||||
} else if (hf > wf) {
|
||||
width = (int) (hf * image.getWidth(null) + 0.5);
|
||||
}
|
||||
|
||||
// imageIcon.setImage(image.getScaledInstance(width, height,
|
||||
// Image.SCALE_AREA_AVERAGING));
|
||||
// return imageIcon;
|
||||
return new ImageIcon(image.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING));
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Illegal scalingHint. Must be one of SCALE_HINT_ALWAYS, SCALE_HINT_FIT_INSIDE, SCALE_HINT_WHEN_NECESSARY");
|
||||
}
|
||||
|
||||
public static ImageIcon scaleImage(ImageIcon imageIcon, int width, int height) {
|
||||
Image image = imageIcon.getImage();
|
||||
|
||||
double wf = (double) width / image.getWidth(null);
|
||||
double hf = (double) height / image.getHeight(null);
|
||||
|
||||
if (wf < hf) {
|
||||
height = (int) (wf * image.getHeight(null) + 0.5);
|
||||
} else if (hf < wf) {
|
||||
width = (int) (hf * image.getWidth(null) + 0.5);
|
||||
}
|
||||
|
||||
// imageIcon.setImage(image.getScaledInstance(width, height,
|
||||
// Image.SCALE_AREA_AVERAGING));
|
||||
// return imageIcon;
|
||||
return new ImageIcon(image.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING));
|
||||
}
|
||||
|
||||
public static void saveJPEG(String filename, int[] pixels, int width, int height) throws IOException {
|
||||
BufferedImage saveImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
|
||||
saveImage.setRGB(0, 0, width, height, pixels, 0, width);
|
||||
|
||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
|
||||
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
|
||||
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(saveImage);
|
||||
param.setQuality(0.95f, false);
|
||||
encoder.setJPEGEncodeParam(param);
|
||||
encoder.encode(saveImage);
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static void savePNG(String filename, int[] pixels, int width, int height) throws IOException {
|
||||
BufferedImage saveImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
saveImage.setRGB(0, 0, width, height, pixels, 0, width);
|
||||
|
||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
|
||||
ImageIO.write(saveImage, "png", out);
|
||||
|
||||
out.close();
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package digisoft.custom.swing;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2008/12/27
|
||||
*/
|
||||
public interface RefreshListener {
|
||||
|
||||
public void refreshing();
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package digisoft.custom.swing;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/04/16
|
||||
*/
|
||||
public class RefreshThread extends Thread {
|
||||
|
||||
private double delay;
|
||||
private RefreshListener runnable;
|
||||
|
||||
public RefreshThread(RefreshListener refreshListener, int fps) {
|
||||
super();
|
||||
|
||||
runnable = refreshListener;
|
||||
delay = 1e9 / fps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
double t = System.nanoTime();
|
||||
while (true) {
|
||||
runnable.refreshing();
|
||||
|
||||
t += delay;
|
||||
|
||||
long sleepTime = (long) ((t - System.nanoTime()) / 1e6);
|
||||
|
||||
if (sleepTime > 0) {
|
||||
Thread.sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package digisoft.custom.swing.window;
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import digisoft.custom.swing.GraphicsFunctions;
|
||||
import digisoft.custom.swing.window.canvas.GraphicsCanvas;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/03/22
|
||||
*/
|
||||
public class CanvasWindow extends JFrame {
|
||||
|
||||
/**
|
||||
* Creates a fullscreen CanvasWindow using a given GraphicsCanvas
|
||||
*
|
||||
*
|
||||
* @param canvas
|
||||
* the GraphicsCanvas defining the drawing method
|
||||
* @param x
|
||||
* the x-position of the upper-left corner of the window
|
||||
* @param y
|
||||
* the y-position of the upper-left corner of the window
|
||||
* @param width
|
||||
* the width of the drawable area of the window
|
||||
* @param height
|
||||
* the height of the drawable area of the window
|
||||
*/
|
||||
public CanvasWindow(GraphicsCanvas canvas, int x, int y, int width, int height) {
|
||||
super();
|
||||
|
||||
this.setup(canvas, width, height);
|
||||
|
||||
super.setResizable(false);
|
||||
super.pack();
|
||||
super.setLocation(x, y);
|
||||
super.setVisible(true);
|
||||
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(CanvasWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
canvas.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fullscreen CanvasWindow using a given GraphicsCanvas
|
||||
*
|
||||
*
|
||||
* @param canvas
|
||||
* the GraphicsCanvas defining the drawing method
|
||||
* @param width
|
||||
* the width of the drawable area of the window
|
||||
* @param height
|
||||
* the height of the drawable area of the window
|
||||
*/
|
||||
public CanvasWindow(GraphicsCanvas canvas, int width, int height) {
|
||||
super();
|
||||
|
||||
this.setup(canvas, width, height);
|
||||
|
||||
super.setResizable(false);
|
||||
super.pack();
|
||||
super.setLocationRelativeTo(null);
|
||||
super.setVisible(true);
|
||||
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(CanvasWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
canvas.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fullscreen CanvasWindow using a given GraphicsCanvas
|
||||
*
|
||||
* @param canvas
|
||||
* the GraphicsCanvas defining the drawing method
|
||||
* @param exclusive
|
||||
* when this is set, the window becomes fullscreen, otherwise, it
|
||||
* will stretch to fit the screen.
|
||||
*/
|
||||
public CanvasWindow(GraphicsCanvas canvas, boolean exclusive) {
|
||||
super();
|
||||
|
||||
GraphicsDevice displayDevice = GraphicsFunctions.getDisplayDevice();
|
||||
DisplayMode mode = displayDevice.getDisplayMode();
|
||||
int width = mode.getWidth();
|
||||
int height = mode.getHeight();
|
||||
|
||||
this.setup(canvas, width, height);
|
||||
|
||||
super.invalidate();
|
||||
super.setUndecorated(true);
|
||||
|
||||
super.setResizable(false);
|
||||
super.pack();
|
||||
super.setLocationRelativeTo(null);
|
||||
|
||||
if (exclusive) {
|
||||
displayDevice.setFullScreenWindow(this);
|
||||
} else {
|
||||
super.setBounds(new Rectangle(0, 0, width, height));
|
||||
super.setVisible(true);
|
||||
}
|
||||
|
||||
canvas.requestFocus();
|
||||
}
|
||||
|
||||
public CanvasWindow(GraphicsCanvas canvas, DisplayMode mode) {
|
||||
super();
|
||||
|
||||
GraphicsDevice displayDevice = GraphicsFunctions.getDisplayDevice();
|
||||
int width = mode.getWidth();
|
||||
int height = mode.getHeight();
|
||||
|
||||
this.setup(canvas, width, height);
|
||||
|
||||
super.invalidate();
|
||||
super.setUndecorated(true);
|
||||
|
||||
super.setResizable(false);
|
||||
super.pack();
|
||||
super.setLocationRelativeTo(null);
|
||||
|
||||
displayDevice.setFullScreenWindow(this);
|
||||
displayDevice.setDisplayMode(mode);
|
||||
|
||||
canvas.requestFocus();
|
||||
}
|
||||
|
||||
private void setup(GraphicsCanvas canvas, int width, int height) {
|
||||
super.setName(this.getClass().getSimpleName());
|
||||
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
super.setLayout(null);
|
||||
|
||||
{
|
||||
canvas.init(width, height, false);
|
||||
|
||||
super.setContentPane(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
public void setExclusive(boolean b) {
|
||||
GraphicsFunctions.getDisplayDevice().setFullScreenWindow(b ? this : null);
|
||||
|
||||
GraphicsCanvas canvas = (GraphicsCanvas) this.getContentPane();
|
||||
if (b) {
|
||||
super.setBounds(new Rectangle(0, 0, canvas.width, canvas.height));
|
||||
} else {
|
||||
super.pack();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package digisoft.custom.swing.window;
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
|
||||
import digisoft.custom.swing.GraphicsFunctions;
|
||||
import digisoft.custom.swing.window.canvas.MemoryImageSourceCanvas;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/04/04
|
||||
*/
|
||||
public class PixelWindow extends MemoryImageSourceCanvas {
|
||||
|
||||
private CanvasWindow window;
|
||||
private DisplayMode backupMode = null;
|
||||
|
||||
/**
|
||||
* Creates a fullscreen CanvasWindow using a given GraphicsCanvas
|
||||
*
|
||||
*
|
||||
* @param x
|
||||
* the x-position of the upper-left corner of the window
|
||||
* @param y
|
||||
* the y-position of the upper-left corner of the window
|
||||
* @param width
|
||||
* the width of the drawable area of the window
|
||||
* @param height
|
||||
* the height of the drawable area of the window
|
||||
*/
|
||||
public PixelWindow(int x, int y, int width, int height) {
|
||||
super();
|
||||
|
||||
window = new CanvasWindow(this, x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fullscreen CanvasWindow using a given GraphicsCanvas
|
||||
*
|
||||
*
|
||||
* @param width
|
||||
* the width of the drawable area of the window
|
||||
* @param height
|
||||
* the height of the drawable area of the window
|
||||
*/
|
||||
public PixelWindow(int width, int height) {
|
||||
super();
|
||||
|
||||
window = new CanvasWindow(this, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fullscreen CanvasWindow using a given GraphicsCanvas
|
||||
*
|
||||
* @param exclusive
|
||||
* when this is set, the window becomes fullscreen, otherwise, it
|
||||
* will stretch to fit the screen.
|
||||
*/
|
||||
public PixelWindow(boolean exclusive) {
|
||||
super();
|
||||
|
||||
window = new CanvasWindow(this, exclusive);
|
||||
}
|
||||
|
||||
public PixelWindow(DisplayMode mode) {
|
||||
super();
|
||||
|
||||
backupMode = GraphicsFunctions.getDisplayDevice().getDisplayMode();
|
||||
|
||||
window = new CanvasWindow(this, mode);
|
||||
|
||||
while (pixels == null) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
|
||||
public void setExclusive(boolean b) {
|
||||
window.setExclusive(b);
|
||||
}
|
||||
|
||||
public void setFullscreen(DisplayMode mode) {
|
||||
if (backupMode == null) {
|
||||
window.setExclusive(true);
|
||||
backupMode = GraphicsFunctions.getDisplayDevice().getDisplayMode();
|
||||
GraphicsFunctions.getDisplayDevice().setDisplayMode(mode);
|
||||
} else {
|
||||
GraphicsFunctions.getDisplayDevice().setDisplayMode(backupMode);
|
||||
window.setExclusive(false);
|
||||
backupMode = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(String name) {
|
||||
window.setTitle(name);
|
||||
}
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
package digisoft.custom.swing.window.canvas;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/03/22
|
||||
*/
|
||||
public abstract class GraphicsCanvas extends JPanel implements ComponentListener {
|
||||
|
||||
public int width;
|
||||
public int height;
|
||||
public int halfWidth;
|
||||
public int halfHeight;
|
||||
private volatile boolean resizeRequest;
|
||||
protected Graphics pg = null;
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
public GraphicsCanvas() {
|
||||
addComponentListener(this);
|
||||
}
|
||||
|
||||
public void init(int width, int height, boolean painting) {
|
||||
if (this.width != width || this.height != height) {
|
||||
setPreferredSize(new Dimension(width, height));
|
||||
|
||||
initImpl(width, height);
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
halfWidth = width >> 1;
|
||||
halfHeight = height >> 1;
|
||||
|
||||
g = null;
|
||||
|
||||
if (painting) {
|
||||
resized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
public void clear(Paint paint) {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no clear(Paint paint)");
|
||||
}
|
||||
|
||||
public void clear(int rgb) {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no clear(int rgb)");
|
||||
}
|
||||
|
||||
public void clear(int rgba, boolean hasAlpha) {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no clear(int rgba, boolean hasAlpha)");
|
||||
}
|
||||
|
||||
public void pset(int x, int y, int rgb) {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no pset(int x, int y, int rgb)");
|
||||
}
|
||||
|
||||
public int pget(int x, int y) {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no pget(int x, int y)");
|
||||
}
|
||||
|
||||
public Graphics2D graphics() {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no 2D graphics. Only pixel access supported.");
|
||||
}
|
||||
|
||||
public void setAntialiased(boolean b) {
|
||||
throw new Error("Engine " + this.getClass().getSimpleName() + " has no 2D graphics. No antialiasing supported.");
|
||||
}
|
||||
|
||||
protected abstract void initImpl(int width, int height);
|
||||
|
||||
protected abstract void paintImpl(Graphics g);
|
||||
|
||||
public boolean ready() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
public void resized() {
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (resizeRequest) {
|
||||
init(super.getWidth(), super.getHeight(), true);
|
||||
resizeRequest = false;
|
||||
} else {
|
||||
paintImpl(g);
|
||||
}
|
||||
}
|
||||
private Graphics2D g = null;
|
||||
|
||||
public void repaintNow() {
|
||||
if (g == null) {
|
||||
g = (Graphics2D) getGraphics();
|
||||
}
|
||||
paint(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
System.out.println("componentResized " + width + "\t" + height);
|
||||
if (width != super.getWidth() || height != super.getHeight()) {
|
||||
resizeRequest = true;
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent arg0) {
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package digisoft.custom.swing.window.canvas;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.MemoryImageSource;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Zom-B
|
||||
* @since 1.0
|
||||
* @date 2009/03/22
|
||||
*/
|
||||
public class MemoryImageSourceCanvas extends GraphicsCanvas {
|
||||
|
||||
private Image image;
|
||||
public int[] pixels;
|
||||
public int pixelCount;
|
||||
private ColorModel cm;
|
||||
private MemoryImageSource source;
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
@Override
|
||||
public void clear(int backgroundColor) {
|
||||
Arrays.fill(pixels, backgroundColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pset(int x, int y, int rgb) {
|
||||
pixels[y * width + x] = rgb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int pget(int x, int y) {
|
||||
return pixels[y * width + x];
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
@Override
|
||||
protected void initImpl(int width, int height) {
|
||||
pixelCount = width * height;
|
||||
|
||||
if (pixels == null || pixels.length < pixelCount) {
|
||||
pixels = new int[pixelCount];
|
||||
}
|
||||
|
||||
cm = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);
|
||||
source = new MemoryImageSource(width, height, pixels, 0, width);
|
||||
source.setFullBufferUpdates(true);
|
||||
source.setAnimated(true);
|
||||
image = Toolkit.getDefaultToolkit().createImage(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintImpl(Graphics g) {
|
||||
if (source != null) {
|
||||
source.newPixels(pixels, cm, 0, width);
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
g.drawImage(image, 0, 0, null);
|
||||
|
||||
// force repaint now (proper method)
|
||||
// Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue