first big cleanup

This commit is contained in:
josch 2011-09-29 21:28:19 +02:00
parent 445eb8f1c3
commit 378baf6192
32 changed files with 68 additions and 1590 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.png
build/

View file

@ -1,9 +0,0 @@
package deepZoom;
public class Main {
public static void main(String[] args) {
//new MandelAnimator();
}
}

View file

@ -1,58 +1,40 @@
package deepZoom;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import deepZoom.calculator.Calculator;
import deepZoom.calculator.ParallelCalculator;
import deepZoom.colorings.Coloring;
import deepZoom.colorings.SmoothIterationsColoringBad;
import deepZoom.fractals.Fractal;
import deepZoom.fractals.Mandel;
import deepZoom.fractals.MandelPrecision;
import deepZoom.parameters.ZoomAnimation;
import deepZoom.renderer.Layer;
import deepZoom.renderer.Scene;
import deepZoom.schedulers.AngularScheduler;
import deepZoom.schedulers.CRTScheduler;
import deepZoom.schedulers.ClockScheduler;
import deepZoom.schedulers.DitherScheduler;
import deepZoom.schedulers.FlowerScheduler;
import deepZoom.schedulers.ModScheduler;
import deepZoom.schedulers.PythagorasScheduler;
import deepZoom.schedulers.RadialScheduler;
import deepZoom.schedulers.RandomScheduler;
import deepZoom.schedulers.Scheduler;
import deepZoom.schedulers.SimpleScheduler;
import deepZoom.schedulers.SpiralScheduler;
import deepZoom.schedulers.SplitScheduler;
import deepZoom.schedulers.SquareSpiralScheduler;
import deepZoom.schedulers.XorScheduler;
import deepZoom.viewports.Viewport;
import digisoft.custom.NumberFunctions;
import digisoft.custom.awt.Color3f;
import digisoft.custom.swing.ImageFunctions;
import digisoft.custom.swing.RefreshListener;
import digisoft.custom.swing.RefreshThread;
import digisoft.custom.swing.gradient.Gradient;
import digisoft.custom.swing.gradient.OpaqueGradient;
import digisoft.custom.swing.window.PixelWindow;
import digisoft.custom.util.geom.DoubleDouble;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.File;
import javax.imageio.ImageIO;
/**
* @author Zom-B
* @since 1.0
* @see date 2006/10/20
*/
public class MandelAnimator implements RefreshListener, Calculator, MouseListener {
public class MandelAnimator {
private static final String SAVEPATH = "C:/Animation golden/";
private static final int WIDTH = (int) (1024);
private static final int HEIGHT = (int) (576);
private static final String SAVEPATH = "./";
private static final int WIDTH = (int) (1920);
private static final int HEIGHT = (int) (1080);
private static int FRAME_START = 1;
private static final int FRAME_END = 3600;
private static final int FRAME_STEP = 1;
@ -71,22 +53,20 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
new MandelAnimator();
}
private static final int NUM_CPUS = Runtime.getRuntime().availableProcessors();
private PixelWindow aaWindow = new PixelWindow(10, 10, MandelAnimator.WIDTH, MandelAnimator.HEIGHT);
private PixelWindow iterWindow = new PixelWindow(10, 10, MandelAnimator.WIDTH, MandelAnimator.HEIGHT);
private PixelWindow fractalWindow = new PixelWindow(10, 10, MandelAnimator.WIDTH, MandelAnimator.HEIGHT);
private Viewport viewport = new Viewport();
private Layer layer = new Layer();
private ZoomAnimation animation = new ZoomAnimation();
private Fractal fractal = new Mandel();
private Coloring coloring = new SmoothIterationsColoringBad(makeGradient());
private Scheduler[] schedulers = {new SpiralScheduler(10)};
private int scheduler;
private Scene scene = new Scene();
private int frameNr;
private boolean antialiasStep = false;
private long runTime;
private long frameTime;
private int[] fractal_pixels;
private int[] iter_pixels;
private int[] aa_pixels;
public MandelAnimator() {
File dirFile = new File(SAVEPATH);
dirFile.mkdir();
@ -102,10 +82,6 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
}
MandelAnimator.FRAME_START = newSave;
fractalWindow.addMouseListener(this);
iterWindow.setTitle("Iter");
aaWindow.setTitle("AA");
animation.setWidth(MandelAnimator.WIDTH);
animation.setNumFrames(MandelAnimator.NUM_FRAMES);
animation.setCenterX(centerX);
@ -119,27 +95,26 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
fractal.setParameters(animation);
coloring.setParameters(animation);
for (Scheduler s : schedulers) {
s.setViewport(viewport);
}
fractal_pixels = new int[MandelAnimator.WIDTH*MandelAnimator.HEIGHT];
iter_pixels = new int[MandelAnimator.WIDTH*MandelAnimator.HEIGHT];
aa_pixels = new int[MandelAnimator.WIDTH*MandelAnimator.HEIGHT];
scene.setViewport(viewport);
scene.setColorPixels(fractalWindow.pixels);
scene.setIterMap(iterWindow.pixels);
scene.setEdgeMap(aaWindow.pixels);
scene.setColorPixels(fractal_pixels);
scene.setIterMap(iter_pixels);
scene.setEdgeMap(aa_pixels);
scene.setNumCPUs(MandelAnimator.NUM_CPUS);
{
layer.setFractal(fractal);
layer.setColoring(coloring);
scene.addLayer(layer);
}
scene.setFractal(fractal);
scene.setColoring(coloring);
frameNr = MandelAnimator.FRAME_START;
runTime = frameTime = System.currentTimeMillis();
ParallelCalculator.createCalculators(this, MandelAnimator.NUM_CPUS);
new RefreshThread(this, 30).start();
while (true) {
prepareCalculation();
calculate(0);
calculationCompleted();
}
}
public static Gradient makeGradient() {
@ -202,8 +177,13 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
private void saveFrame() {
try {
ImageFunctions.savePNG(MandelAnimator.SAVEPATH + NumberFunctions.toStringFixedLength(frameNr, 4) + ".png", fractalWindow.pixels,
MandelAnimator.WIDTH, MandelAnimator.HEIGHT);
BufferedImage saveImage = new BufferedImage(MandelAnimator.WIDTH, MandelAnimator.HEIGHT, BufferedImage.TYPE_INT_RGB);
saveImage.setRGB(0, 0, MandelAnimator.WIDTH, MandelAnimator.HEIGHT, fractal_pixels, 0, MandelAnimator.WIDTH);
OutputStream out = new BufferedOutputStream(new FileOutputStream(MandelAnimator.SAVEPATH + NumberFunctions.toStringFixedLength(frameNr, 4) + ".png"));
ImageIO.write(saveImage, "png", out);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
@ -211,9 +191,6 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
private void destroyImage() {
System.gc();
fractalWindow.clear(0);
iterWindow.clear(0);
aaWindow.clear(0);
}
private void nextFrame() {
@ -230,14 +207,8 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
}
}
@Override
public void prepareCalculation() {
scheduler = NumberFunctions.RND.nextInt(schedulers.length);
scene.setScheduler(schedulers[scheduler]);
if (!antialiasStep) {
fractalWindow.setTitle(Integer.toString(frameNr) + " First pass");
animation.setFrame(frameNr);
System.out.println("Rough: " + frameNr + " magn=" + animation.getMagn() + " maxiter=" + animation.getMaxiter());
@ -245,8 +216,6 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
destroyImage();
scene.initFrame();
} else {
fractalWindow.setTitle(Integer.toString(frameNr) + " Antialiasing");
animation.setFrame(frameNr);
animation.setMaxiter(animation.getMaxiter() << 2);
@ -254,11 +223,8 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
scene.calcAntialiasMask();
}
schedulers[scheduler].init();
}
@Override
public void calculate(int cpu) {
if (!antialiasStep) {
scene.render(cpu);
@ -267,15 +233,12 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
}
}
@Override
public void calculationCompleted() {
if (!antialiasStep && MandelAnimator.DO_ANTIALIAS) {
antialiasStep = true;
} else {
antialiasStep = false;
fractalWindow.repaintNow();
iterWindow.repaintNow();
saveFrame();
long time = System.currentTimeMillis();
@ -291,44 +254,4 @@ public class MandelAnimator implements RefreshListener, Calculator, MouseListene
nextFrame();
}
}
@Override
public void refreshing() {
fractalWindow.repaintNow();
iterWindow.repaintNow();
aaWindow.repaintNow();
if (antialiasStep) {
aaWindow.setTitle("AA " + (int) (schedulers[scheduler].getProgress() * 1000) / 10f + "%");
} else {
iterWindow.setTitle("Iter " + (int) (schedulers[scheduler].getProgress() * 1000) / 10f + "%");
}
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
centerX = viewport.getPX(e.getX(), e.getY());
centerY = viewport.getPY(e.getX(), e.getY());
System.out.println("/tprivate DoubleDouble/t/t/tcenterX/t/t/t= new DoubleDouble(" + centerX.hi + ", " + centerX.lo + ");");
System.out.println("/tprivate DoubleDouble/t/t/tcenterY/t/t/t= new DoubleDouble(" + centerY.hi + ", " + centerY.lo + ");");
} else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
}

View file

@ -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();
}

View file

@ -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;
}
}

View file

@ -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();
}
}

View file

@ -1,9 +1,11 @@
package deepZoom.renderer;
import deepZoom.schedulers.PriorityPoint;
import deepZoom.schedulers.Scheduler;
import java.awt.Point;
import deepZoom.viewports.Viewport;
import deepZoom.colorings.Coloring;
import deepZoom.fractals.Fractal;
import digisoft.custom.awt.Color3f;
import digisoft.custom.awt.Color3fConst;
@ -15,24 +17,27 @@ import digisoft.custom.awt.Color3fConst;
public class Scene {
private Viewport viewport;
private Scheduler scheduler;
private int[] pixels;
private int[] iterMap;
private int[] edgeMap;
private Color3f[] colors;
private int[] mask;
// Multiple layer support unfinished!
private Layer layer;
private Fractal fractal;
private Coloring coloring;
private int width;
private int height;
private int area = -1;
public void setViewport(Viewport viewport) {
this.viewport = viewport;
public void setFractal(Fractal fractal) {
this.fractal = fractal;
}
public void setScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
public void setColoring(Coloring coloring) {
this.coloring = coloring;
}
public void setViewport(Viewport viewport) {
this.viewport = viewport;
}
public void setColorPixels(int[] pixels) {
@ -47,13 +52,10 @@ public class Scene {
this.edgeMap = edgeMap;
}
public void addLayer(Layer layer) {
this.layer = layer;
}
public void initFrame() {
viewport.initParameters();
layer.initFrame();
fractal.initFrame();
coloring.initParameters();
width = viewport.width;
height = viewport.height;
@ -74,11 +76,11 @@ public class Scene {
}
}
public void render(PointInfo pointInfo, PriorityPoint point) {
public void render(PointInfo pointInfo, Point point) {
int p = point.x + point.y * width;
viewport.getPoint(point.x, point.y, pointInfo);
layer.fractal.calcPoint(pointInfo);
fractal.calcPoint(pointInfo);
int iter = (int) pointInfo.lastIter;
boolean inside = pointInfo.inside;
@ -86,7 +88,7 @@ public class Scene {
edgeMap[p] = inside ? 0 : iter;
if (!inside) {
colors[p].addSelf(layer.coloring.getColor(pointInfo));
colors[p].addSelf(coloring.getColor(pointInfo));
}
pixels[p] = colors[p].getRGB();
@ -150,7 +152,7 @@ public class Scene {
}
}
public void renderAntialias(PointInfo pointInfo, PriorityPoint point) {
public void renderAntialias(PointInfo pointInfo, Point point) {
int p = point.x + point.y * width;
if (mask[p] != 0) {
@ -166,7 +168,7 @@ public class Scene {
}
}
private void calcAntialiasPixel(PointInfo pointInfo, int p, PriorityPoint point) {
private void calcAntialiasPixel(PointInfo pointInfo, int p, Point point) {
int reach = pointInfo.antialiasReach;
double factor = 1.0 / pointInfo.antialiasFactor;
for (int x = -reach; x <= reach; x++) {
@ -176,11 +178,11 @@ public class Scene {
if ((x | y) != 0) {
viewport.getPoint(point.x + dx, point.y + dy, pointInfo);
layer.fractal.calcPoint(pointInfo);
fractal.calcPoint(pointInfo);
boolean inside = pointInfo.inside;
if (!inside) {
colors[p].addSelf(layer.coloring.getColor(pointInfo));
colors[p].addSelf(coloring.getColor(pointInfo));
}
}
}
@ -198,24 +200,20 @@ public class Scene {
}
public void render(int cpu) {
while (true) {
PriorityPoint point = scheduler.poll();
if (point == null) {
return;
for (int y = 0; y < height; y++) {
int dy = y * width;
for (int x = 0; x < width; x++) {
this.render(pointInfos[cpu], new Point(x, y));
}
this.render(pointInfos[cpu], point);
}
}
public void renderAntialias(int cpu) {
while (true) {
PriorityPoint point = scheduler.poll();
if (point == null) {
return;
}
this.renderAntialias(pointInfos[cpu], point);
for (int y = 0; y < height; y++) {
int dy = y * width;
for (int x = 0; x < width; x++) {
this.renderAntialias(pointInfos[cpu], new Point(x, y));
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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)));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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)));
}
}
}
}
}

View file

@ -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 + ")]";
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -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));
}
}
}
}
}

View file

@ -52,133 +52,4 @@ public class Color3fConst {
0x2C412C, 0x2C4130, 0x2C4134, 0x2C413C, 0x2C4141, 0x2C3C41, 0x2C3441, 0x2C3041, //
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, //
0x000000};
public static final Color3f[] DOS_COLORS = {new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.0f, 0.6666667f), //
new Color3f(0.0f, 0.6666667f, 0.0f), new Color3f(0.0f, 0.6666667f, 0.6666667f), //
new Color3f(0.6666667f, 0.0f, 0.0f), new Color3f(0.6666667f, 0.0f, 0.6666667f), //
new Color3f(0.6666667f, 0.33333334f, 0.0f), new Color3f(0.6666667f, 0.6666667f, 0.6666667f), //
new Color3f(0.33333334f, 0.33333334f, 0.33333334f), new Color3f(0.33333334f, 0.33333334f, 1.0f), //
new Color3f(0.33333334f, 1.0f, 0.33333334f), new Color3f(0.33333334f, 1.0f, 1.0f), //
new Color3f(1.0f, 0.33333334f, 0.33333334f), new Color3f(1.0f, 0.33333334f, 1.0f), //
new Color3f(1.0f, 1.0f, 0.33333334f), new Color3f(1.0f, 1.0f, 1.0f), //
new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.078431375f, 0.078431375f, 0.078431375f), //
new Color3f(0.1254902f, 0.1254902f, 0.1254902f), new Color3f(0.17254902f, 0.17254902f, 0.17254902f), //
new Color3f(0.21960784f, 0.21960784f, 0.21960784f), new Color3f(0.27058825f, 0.27058825f, 0.27058825f), //
new Color3f(0.31764707f, 0.31764707f, 0.31764707f), new Color3f(0.38039216f, 0.38039216f, 0.38039216f), //
new Color3f(0.44313726f, 0.44313726f, 0.44313726f), new Color3f(0.50980395f, 0.50980395f, 0.50980395f), //
new Color3f(0.57254905f, 0.57254905f, 0.57254905f), new Color3f(0.63529414f, 0.63529414f, 0.63529414f), //
new Color3f(0.7137255f, 0.7137255f, 0.7137255f), new Color3f(0.79607844f, 0.79607844f, 0.79607844f), //
new Color3f(0.8901961f, 0.8901961f, 0.8901961f), new Color3f(1.0f, 1.0f, 1.0f), //
new Color3f(0.0f, 0.0f, 1.0f), new Color3f(0.25490198f, 0.0f, 1.0f), //
new Color3f(0.49019608f, 0.0f, 1.0f), new Color3f(0.74509805f, 0.0f, 1.0f), //
new Color3f(1.0f, 0.0f, 1.0f), new Color3f(1.0f, 0.0f, 0.74509805f), //
new Color3f(1.0f, 0.0f, 0.49019608f), new Color3f(1.0f, 0.0f, 0.25490198f), //
new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.25490198f, 0.0f), //
new Color3f(1.0f, 0.49019608f, 0.0f), new Color3f(1.0f, 0.74509805f, 0.0f), //
new Color3f(1.0f, 1.0f, 0.0f), new Color3f(0.74509805f, 1.0f, 0.0f), //
new Color3f(0.49019608f, 1.0f, 0.0f), new Color3f(0.25490198f, 1.0f, 0.0f), //
new Color3f(0.0f, 1.0f, 0.0f), new Color3f(0.0f, 1.0f, 0.25490198f), //
new Color3f(0.0f, 1.0f, 0.49019608f), new Color3f(0.0f, 1.0f, 0.74509805f), //
new Color3f(0.0f, 1.0f, 1.0f), new Color3f(0.0f, 0.74509805f, 1.0f), //
new Color3f(0.0f, 0.49019608f, 1.0f), new Color3f(0.0f, 0.25490198f, 1.0f), //
new Color3f(0.49019608f, 0.49019608f, 1.0f), new Color3f(0.61960787f, 0.49019608f, 1.0f), //
new Color3f(0.74509805f, 0.49019608f, 1.0f), new Color3f(0.8745098f, 0.49019608f, 1.0f), //
new Color3f(1.0f, 0.49019608f, 1.0f), new Color3f(1.0f, 0.49019608f, 0.8745098f), //
new Color3f(1.0f, 0.49019608f, 0.74509805f), new Color3f(1.0f, 0.49019608f, 0.61960787f), //
new Color3f(1.0f, 0.49019608f, 0.49019608f), new Color3f(1.0f, 0.61960787f, 0.49019608f), //
new Color3f(1.0f, 0.74509805f, 0.49019608f), new Color3f(1.0f, 0.8745098f, 0.49019608f), //
new Color3f(1.0f, 1.0f, 0.49019608f), new Color3f(0.8745098f, 1.0f, 0.49019608f), //
new Color3f(0.74509805f, 1.0f, 0.49019608f), new Color3f(0.61960787f, 1.0f, 0.49019608f), //
new Color3f(0.49019608f, 1.0f, 0.49019608f), new Color3f(0.49019608f, 1.0f, 0.61960787f), //
new Color3f(0.49019608f, 1.0f, 0.74509805f), new Color3f(0.49019608f, 1.0f, 0.8745098f), //
new Color3f(0.49019608f, 1.0f, 1.0f), new Color3f(0.49019608f, 0.8745098f, 1.0f), //
new Color3f(0.49019608f, 0.74509805f, 1.0f), new Color3f(0.49019608f, 0.61960787f, 1.0f), //
new Color3f(0.7137255f, 0.7137255f, 1.0f), new Color3f(0.78039217f, 0.7137255f, 1.0f), //
new Color3f(0.85882354f, 0.7137255f, 1.0f), new Color3f(0.92156863f, 0.7137255f, 1.0f), //
new Color3f(1.0f, 0.7137255f, 1.0f), new Color3f(1.0f, 0.7137255f, 0.92156863f), //
new Color3f(1.0f, 0.7137255f, 0.85882354f), new Color3f(1.0f, 0.7137255f, 0.78039217f), //
new Color3f(1.0f, 0.7137255f, 0.7137255f), new Color3f(1.0f, 0.78039217f, 0.7137255f), //
new Color3f(1.0f, 0.85882354f, 0.7137255f), new Color3f(1.0f, 0.92156863f, 0.7137255f), //
new Color3f(1.0f, 1.0f, 0.7137255f), new Color3f(0.92156863f, 1.0f, 0.7137255f), //
new Color3f(0.85882354f, 1.0f, 0.7137255f), new Color3f(0.78039217f, 1.0f, 0.7137255f), //
new Color3f(0.7137255f, 1.0f, 0.7137255f), new Color3f(0.7137255f, 1.0f, 0.78039217f), //
new Color3f(0.7137255f, 1.0f, 0.85882354f), new Color3f(0.7137255f, 1.0f, 0.92156863f), //
new Color3f(0.7137255f, 1.0f, 1.0f), new Color3f(0.7137255f, 0.92156863f, 1.0f), //
new Color3f(0.7137255f, 0.85882354f, 1.0f), new Color3f(0.7137255f, 0.78039217f, 1.0f), //
new Color3f(0.0f, 0.0f, 0.44313726f), new Color3f(0.10980392f, 0.0f, 0.44313726f), //
new Color3f(0.21960784f, 0.0f, 0.44313726f), new Color3f(0.33333334f, 0.0f, 0.44313726f), //
new Color3f(0.44313726f, 0.0f, 0.44313726f), new Color3f(0.44313726f, 0.0f, 0.33333334f), //
new Color3f(0.44313726f, 0.0f, 0.21960784f), new Color3f(0.44313726f, 0.0f, 0.10980392f), //
new Color3f(0.44313726f, 0.0f, 0.0f), new Color3f(0.44313726f, 0.10980392f, 0.0f), //
new Color3f(0.44313726f, 0.21960784f, 0.0f), new Color3f(0.44313726f, 0.33333334f, 0.0f), //
new Color3f(0.44313726f, 0.44313726f, 0.0f), new Color3f(0.33333334f, 0.44313726f, 0.0f), //
new Color3f(0.21960784f, 0.44313726f, 0.0f), new Color3f(0.10980392f, 0.44313726f, 0.0f), //
new Color3f(0.0f, 0.44313726f, 0.0f), new Color3f(0.0f, 0.44313726f, 0.10980392f), //
new Color3f(0.0f, 0.44313726f, 0.21960784f), new Color3f(0.0f, 0.44313726f, 0.33333334f), //
new Color3f(0.0f, 0.44313726f, 0.44313726f), new Color3f(0.0f, 0.33333334f, 0.44313726f), //
new Color3f(0.0f, 0.21960784f, 0.44313726f), new Color3f(0.0f, 0.10980392f, 0.44313726f), //
new Color3f(0.21960784f, 0.21960784f, 0.44313726f), new Color3f(0.27058825f, 0.21960784f, 0.44313726f), //
new Color3f(0.33333334f, 0.21960784f, 0.44313726f), new Color3f(0.38039216f, 0.21960784f, 0.44313726f), //
new Color3f(0.44313726f, 0.21960784f, 0.44313726f), new Color3f(0.44313726f, 0.21960784f, 0.38039216f), //
new Color3f(0.44313726f, 0.21960784f, 0.33333334f), new Color3f(0.44313726f, 0.21960784f, 0.27058825f), //
new Color3f(0.44313726f, 0.21960784f, 0.21960784f), new Color3f(0.44313726f, 0.27058825f, 0.21960784f), //
new Color3f(0.44313726f, 0.33333334f, 0.21960784f), new Color3f(0.44313726f, 0.38039216f, 0.21960784f), //
new Color3f(0.44313726f, 0.44313726f, 0.21960784f), new Color3f(0.38039216f, 0.44313726f, 0.21960784f), //
new Color3f(0.33333334f, 0.44313726f, 0.21960784f), new Color3f(0.27058825f, 0.44313726f, 0.21960784f), //
new Color3f(0.21960784f, 0.44313726f, 0.21960784f), new Color3f(0.21960784f, 0.44313726f, 0.27058825f), //
new Color3f(0.21960784f, 0.44313726f, 0.33333334f), new Color3f(0.21960784f, 0.44313726f, 0.38039216f), //
new Color3f(0.21960784f, 0.44313726f, 0.44313726f), new Color3f(0.21960784f, 0.38039216f, 0.44313726f), //
new Color3f(0.21960784f, 0.33333334f, 0.44313726f), new Color3f(0.21960784f, 0.27058825f, 0.44313726f), //
new Color3f(0.31764707f, 0.31764707f, 0.44313726f), new Color3f(0.34901962f, 0.31764707f, 0.44313726f), //
new Color3f(0.38039216f, 0.31764707f, 0.44313726f), new Color3f(0.4117647f, 0.31764707f, 0.44313726f), //
new Color3f(0.44313726f, 0.31764707f, 0.44313726f), new Color3f(0.44313726f, 0.31764707f, 0.4117647f), //
new Color3f(0.44313726f, 0.31764707f, 0.38039216f), new Color3f(0.44313726f, 0.31764707f, 0.34901962f), //
new Color3f(0.44313726f, 0.31764707f, 0.31764707f), new Color3f(0.44313726f, 0.34901962f, 0.31764707f), //
new Color3f(0.44313726f, 0.38039216f, 0.31764707f), new Color3f(0.44313726f, 0.4117647f, 0.31764707f), //
new Color3f(0.44313726f, 0.44313726f, 0.31764707f), new Color3f(0.4117647f, 0.44313726f, 0.31764707f), //
new Color3f(0.38039216f, 0.44313726f, 0.31764707f), new Color3f(0.34901962f, 0.44313726f, 0.31764707f), //
new Color3f(0.31764707f, 0.44313726f, 0.31764707f), new Color3f(0.31764707f, 0.44313726f, 0.34901962f), //
new Color3f(0.31764707f, 0.44313726f, 0.38039216f), new Color3f(0.31764707f, 0.44313726f, 0.4117647f), //
new Color3f(0.31764707f, 0.44313726f, 0.44313726f), new Color3f(0.31764707f, 0.4117647f, 0.44313726f), //
new Color3f(0.31764707f, 0.38039216f, 0.44313726f), new Color3f(0.31764707f, 0.34901962f, 0.44313726f), //
new Color3f(0.0f, 0.0f, 0.25490198f), new Color3f(0.0627451f, 0.0f, 0.25490198f), //
new Color3f(0.1254902f, 0.0f, 0.25490198f), new Color3f(0.1882353f, 0.0f, 0.25490198f), //
new Color3f(0.25490198f, 0.0f, 0.25490198f), new Color3f(0.25490198f, 0.0f, 0.1882353f), //
new Color3f(0.25490198f, 0.0f, 0.1254902f), new Color3f(0.25490198f, 0.0f, 0.0627451f), //
new Color3f(0.25490198f, 0.0f, 0.0f), new Color3f(0.25490198f, 0.0627451f, 0.0f), //
new Color3f(0.25490198f, 0.1254902f, 0.0f), new Color3f(0.25490198f, 0.1882353f, 0.0f), //
new Color3f(0.25490198f, 0.25490198f, 0.0f), new Color3f(0.1882353f, 0.25490198f, 0.0f), //
new Color3f(0.1254902f, 0.25490198f, 0.0f), new Color3f(0.0627451f, 0.25490198f, 0.0f), //
new Color3f(0.0f, 0.25490198f, 0.0f), new Color3f(0.0f, 0.25490198f, 0.0627451f), //
new Color3f(0.0f, 0.25490198f, 0.1254902f), new Color3f(0.0f, 0.25490198f, 0.1882353f), //
new Color3f(0.0f, 0.25490198f, 0.25490198f), new Color3f(0.0f, 0.1882353f, 0.25490198f), //
new Color3f(0.0f, 0.1254902f, 0.25490198f), new Color3f(0.0f, 0.0627451f, 0.25490198f), //
new Color3f(0.1254902f, 0.1254902f, 0.25490198f), new Color3f(0.15686275f, 0.1254902f, 0.25490198f), //
new Color3f(0.1882353f, 0.1254902f, 0.25490198f), new Color3f(0.21960784f, 0.1254902f, 0.25490198f), //
new Color3f(0.25490198f, 0.1254902f, 0.25490198f), new Color3f(0.25490198f, 0.1254902f, 0.21960784f), //
new Color3f(0.25490198f, 0.1254902f, 0.1882353f), new Color3f(0.25490198f, 0.1254902f, 0.15686275f), //
new Color3f(0.25490198f, 0.1254902f, 0.1254902f), new Color3f(0.25490198f, 0.15686275f, 0.1254902f), //
new Color3f(0.25490198f, 0.1882353f, 0.1254902f), new Color3f(0.25490198f, 0.21960784f, 0.1254902f), //
new Color3f(0.25490198f, 0.25490198f, 0.1254902f), new Color3f(0.21960784f, 0.25490198f, 0.1254902f), //
new Color3f(0.1882353f, 0.25490198f, 0.1254902f), new Color3f(0.15686275f, 0.25490198f, 0.1254902f), //
new Color3f(0.1254902f, 0.25490198f, 0.1254902f), new Color3f(0.1254902f, 0.25490198f, 0.15686275f), //
new Color3f(0.1254902f, 0.25490198f, 0.1882353f), new Color3f(0.1254902f, 0.25490198f, 0.21960784f), //
new Color3f(0.1254902f, 0.25490198f, 0.25490198f), new Color3f(0.1254902f, 0.21960784f, 0.25490198f), //
new Color3f(0.1254902f, 0.1882353f, 0.25490198f), new Color3f(0.1254902f, 0.15686275f, 0.25490198f), //
new Color3f(0.17254902f, 0.17254902f, 0.25490198f), new Color3f(0.1882353f, 0.17254902f, 0.25490198f), //
new Color3f(0.20392157f, 0.17254902f, 0.25490198f), new Color3f(0.23529412f, 0.17254902f, 0.25490198f), //
new Color3f(0.25490198f, 0.17254902f, 0.25490198f), new Color3f(0.25490198f, 0.17254902f, 0.23529412f), //
new Color3f(0.25490198f, 0.17254902f, 0.20392157f), new Color3f(0.25490198f, 0.17254902f, 0.1882353f), //
new Color3f(0.25490198f, 0.17254902f, 0.17254902f), new Color3f(0.25490198f, 0.1882353f, 0.17254902f), //
new Color3f(0.25490198f, 0.20392157f, 0.17254902f), new Color3f(0.25490198f, 0.23529412f, 0.17254902f), //
new Color3f(0.25490198f, 0.25490198f, 0.17254902f), new Color3f(0.23529412f, 0.25490198f, 0.17254902f), //
new Color3f(0.20392157f, 0.25490198f, 0.17254902f), new Color3f(0.1882353f, 0.25490198f, 0.17254902f), //
new Color3f(0.17254902f, 0.25490198f, 0.17254902f), new Color3f(0.17254902f, 0.25490198f, 0.1882353f), //
new Color3f(0.17254902f, 0.25490198f, 0.20392157f), new Color3f(0.17254902f, 0.25490198f, 0.23529412f), //
new Color3f(0.17254902f, 0.25490198f, 0.25490198f), new Color3f(0.17254902f, 0.23529412f, 0.25490198f), //
new Color3f(0.17254902f, 0.20392157f, 0.25490198f), new Color3f(0.17254902f, 0.1882353f, 0.25490198f), //
new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.0f, 0.0f), //
new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.0f, 0.0f), //
new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.0f, 0.0f), //
new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.0f, 0.0f, 0.0f), //
new Color3f(0.0f, 0.0f, 0.0f)};
}

View file

@ -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];
}
}

View file

@ -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();
}
}

View file

@ -1,11 +0,0 @@
package digisoft.custom.swing;
/**
* @author Zom-B
* @since 1.0
* @date 2008/12/27
*/
public interface RefreshListener {
public void refreshing();
}

View file

@ -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();
}
}
}

View file

@ -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();
}
}
}

View file

@ -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);
}
}

View file

@ -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) {
}
}

View file

@ -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();
}
}
}