Skip to content

Commit

Permalink
Bitmap update optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Oct 18, 2024
1 parent e4f1089 commit 32e8624
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ public void widgetDisposed(DisposeEvent e) {
list.add(window);
iter.next();
}
int index = iter.getIndex();
for (DebugWindow w : list) {
int index = iter.getIndex();
w.update(iter);
iter.setIndex(index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
Expand Down Expand Up @@ -158,9 +157,6 @@ public void paintControl(PaintEvent e) {
e.gc.setAdvanced(true);
e.gc.setAntialias(SWT.ON);
e.gc.setInterpolation(SWT.OFF);
if (image.isDisposed()) {
image = new Image(e.display, imageData);
}
Point canvasSize = canvas.getSize();
e.gc.drawImage(image, 0, 0, imageSize.x, imageSize.y, 0, 0, canvasSize.x, canvasSize.y);
}
Expand All @@ -185,6 +181,7 @@ public void widgetDisposed(DisposeEvent e) {
}

void trace(KeywordIterator iter) {
traceMode = 0;
if (iter.hasNextNumber()) {
traceMode = iter.nextNumber() & 15;
switch (traceMode & 7) {
Expand Down Expand Up @@ -304,13 +301,11 @@ public void update(KeywordIterator iter) {
imageData.setPixel(x, y, color);
}
}
image.dispose();
canvas.redraw();
update();
break;

case "UPDATE":
image.dispose();
canvas.redraw();
update();
break;

case "SAVE":
Expand Down Expand Up @@ -339,6 +334,12 @@ public void update(KeywordIterator iter) {
}
}

void update() {
image.dispose();
image = new Image(canvas.getDisplay(), imageData);
canvas.redraw();
}

void colorMode(String cmd, KeywordIterator iter) {
colorMode = ColorMode.valueOf(cmd.toUpperCase());
if (iter.hasNext()) {
Expand Down Expand Up @@ -427,15 +428,13 @@ else if (++y >= imageData.height) {
y = 0;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (++x >= imageData.width) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -450,15 +449,13 @@ else if (++y >= imageData.height) {
y = 0;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (--x < 0) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -473,15 +470,13 @@ else if (--y < 0) {
y = imageData.height - 1;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (++x >= imageData.width) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -496,14 +491,12 @@ else if (--y < 0) {
y = imageData.height - 1;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
if (--x < 0) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -518,15 +511,13 @@ else if (++x >= imageData.width) {
x = 0;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (++y >= imageData.height) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -541,15 +532,13 @@ else if (++x >= imageData.width) {
x = 0;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (--y < 0) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -564,15 +553,13 @@ else if (--x < 0) {
x = imageData.width - 1;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (++y >= imageData.height) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
Expand All @@ -586,91 +573,60 @@ else if (--x < 0) {
x = imageData.width - 1;
}
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
imageData.setPixel(x, y, color);
if (--y < 0) {
if (autoUpdate && rate == -1) {
image.dispose();
canvas.redraw();
update();
}
}
break;
}

if (autoUpdate && rate != -1) {
if (rateCount++ >= rate) {
image.dispose();
canvas.redraw();
update();
rateCount = 0;
}
}
}

void scrollLeft() {
Image target = new Image(display, imageData);

GC gc = new GC(target);
try {
Image temp = new Image(display, imageData);
gc.drawImage(temp, 1, 0, imageData.width - 1, imageData.height, 0, 0, imageData.width - 1, imageData.height);
gc.drawImage(temp, 0, 0, 1, imageData.height, imageData.width - 1, 0, 1, imageData.height);
temp.dispose();
} finally {
gc.dispose();
for (int x = 1; x < imageData.width; x++) {
for (int y = 0; y < imageData.height; y++) {
int pixel = imageData.getPixel(x, y);
imageData.setPixel(x - 1, y, pixel);
}
}

imageData = target.getImageData();
}

void scrollRight() {
Image target = new Image(display, imageData);

GC gc = new GC(target);
try {
Image temp = new Image(display, imageData);
gc.drawImage(temp, 0, 0, imageData.width - 1, imageData.height, 1, 0, imageData.width - 1, imageData.height);
gc.drawImage(temp, imageData.width - 1, 0, 1, imageData.height, 0, 0, 1, imageData.height);
temp.dispose();
} finally {
gc.dispose();
for (int x = imageData.width - 1; x >= 1; x--) {
for (int y = 0; y < imageData.height; y++) {
int pixel = imageData.getPixel(x - 1, y);
imageData.setPixel(x, y, pixel);
}
}

imageData = target.getImageData();
}

void scrollDown() {
Image target = new Image(display, imageData);

GC gc = new GC(target);
try {
Image temp = new Image(display, imageData);
gc.drawImage(temp, 0, 0, imageData.width, imageData.height - 1, 0, 1, imageData.width, imageData.height - 1);
gc.drawImage(temp, 0, imageData.height - 1, imageData.width, 1, 0, 0, imageData.width, 1);
temp.dispose();
} finally {
gc.dispose();
for (int y = imageData.height - 1; y >= 1; y--) {
for (int x = 0; x < imageData.width; x++) {
int pixel = imageData.getPixel(x, y - 1);
imageData.setPixel(x, y, pixel);
}
}

imageData = target.getImageData();
}

void scrollUp() {
Image target = new Image(display, imageData);

GC gc = new GC(target);
try {
Image temp = new Image(display, imageData);
gc.drawImage(temp, 0, 1, imageData.width, imageData.height - 1, 0, 0, imageData.width, imageData.height - 1);
gc.drawImage(temp, 0, 0, imageData.width, 1, 0, imageData.height - 1, imageData.width, 1);
temp.dispose();
} finally {
gc.dispose();
for (int y = 1; y < imageData.height; y++) {
for (int x = 0; x < imageData.width; x++) {
int pixel = imageData.getPixel(x, y);
imageData.setPixel(x, y - 1, pixel);
}
}

imageData = target.getImageData();
}

static String[] data = new String[] {
Expand Down

0 comments on commit 32e8624

Please sign in to comment.