diff --git a/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java b/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java index a6e68403..918864c5 100644 --- a/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java +++ b/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java @@ -2,7 +2,6 @@ import java.awt.*; import java.util.Arrays; -import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import mpo.dayon.common.capture.Capture; @@ -132,7 +131,7 @@ private void mainLoop() throws InterruptedException { fireOnRawCaptured(captureId, pixels); // debugging purpose (!) final CaptureTile[] dirty = computeDirtyTiles(captureId, pixels, captureFactory.getDimension()); - if (!Arrays.stream(dirty).allMatch(Objects::isNull)) { + if (dirty != null) { final Capture capture = new Capture(captureId, reset.get(), skipped, 0, captureFactory.getDimension(), TILE_DIMENSION, dirty); fireOnCaptured(capture); // might update the capture (i.e., merging with previous not sent yet) updatePreviousCapture(capture); @@ -184,7 +183,7 @@ private CaptureTile[] computeDirtyTiles(int captureId, byte[] capture, Dimension previousCapture = new long[length]; resetPreviousCapture(); } - CaptureTile[] dirty = new CaptureTile[length]; + CaptureTile[] dirty = null; int tileId = 0; for (int ty = 0; ty < captureDimension.height; ty += TILE_DIMENSION.height) { final int th = min(captureDimension.height - ty, TILE_DIMENSION.height); @@ -194,6 +193,9 @@ private CaptureTile[] computeDirtyTiles(int captureId, byte[] capture, Dimension final byte[] tileData = createTile(capture, captureDimension.width, offset, tw, th); final long cs = CaptureTile.computeChecksum(tileData, 0, tileData.length); if (cs != previousCapture[tileId]) { + if (dirty == null) { + dirty = new CaptureTile[length]; + } dirty[tileId] = new CaptureTile(captureId, tileId, cs, new Position(tx, ty), tw, th, tileData); } ++tileId; diff --git a/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java b/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java index 068dde57..83ffd708 100644 --- a/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java +++ b/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java @@ -127,8 +127,4 @@ private void increaseBuffer(int newCount) { buffer = Arrays.copyOf(buffer, Math.max(buffer.length << 1, newCount)); } } - - public final MemByteBuffer copy() { - return new MemByteBuffer(buffer); - } } diff --git a/src/main/java/mpo/dayon/common/capture/Capture.java b/src/main/java/mpo/dayon/common/capture/Capture.java index 653eefc1..288fea95 100644 --- a/src/main/java/mpo/dayon/common/capture/Capture.java +++ b/src/main/java/mpo/dayon/common/capture/Capture.java @@ -43,8 +43,8 @@ public Capture(int captureId, boolean reset, int skipped, int merged, Dimension this.reset = reset; this.skipped = new AtomicInteger(skipped); this.merged = new AtomicInteger(merged); - this.captureDimension = new Dimension(captureDimension); - this.tileDimension = new Dimension(tileDimension); + this.captureDimension = captureDimension; + this.tileDimension = tileDimension; this.dirty = dirty.clone(); } diff --git a/src/main/java/mpo/dayon/common/capture/CaptureTile.java b/src/main/java/mpo/dayon/common/capture/CaptureTile.java index 778a5253..38b9629f 100644 --- a/src/main/java/mpo/dayon/common/capture/CaptureTile.java +++ b/src/main/java/mpo/dayon/common/capture/CaptureTile.java @@ -68,7 +68,7 @@ public CaptureTile(int captureId, int id, XYWH xywh, MemByteBuffer capture) { this.position = new Position(xywh.x, xywh.y); this.width = xywh.w; this.height = xywh.h; - this.capture = capture.copy(); + this.capture = capture; if (width * height != capture.size()) { throw new IllegalArgumentException("Ouch!"); } @@ -149,7 +149,7 @@ public int getHeight() { } public MemByteBuffer getCapture() { - return capture.copy(); + return capture; } /** diff --git a/src/main/java/mpo/dayon/common/compressor/CompressorEngineConfiguration.java b/src/main/java/mpo/dayon/common/compressor/CompressorEngineConfiguration.java index ff3d3332..2b6ddea2 100644 --- a/src/main/java/mpo/dayon/common/compressor/CompressorEngineConfiguration.java +++ b/src/main/java/mpo/dayon/common/compressor/CompressorEngineConfiguration.java @@ -31,11 +31,7 @@ public class CompressorEngineConfiguration extends Configuration { */ public CompressorEngineConfiguration() { final Preferences prefs = Preferences.getPreferences(); - - // Note: did not exist in version = 0 => no migration is required. - - this.method = prefs.getEnumPreference(PREF_METHOD, CompressionMethod.XZ, CompressionMethod.values()); - + this.method = prefs.getEnumPreference(PREF_METHOD, CompressionMethod.ZIP, CompressionMethod.values()); this.useCache = prefs.getBooleanPreference(PREF_USE_CACHE, true); this.maxSize = prefs.getIntPreference(PREF_CACHE_MAX_SIZE, RegularTileCache.DEFAULT_MAX_SIZE); this.purgeSize = prefs.getIntPreference(PREF_CACHE_PURGE_SIZE, RegularTileCache.DEFAULT_PURGE_SIZE); diff --git a/src/main/java/mpo/dayon/common/network/message/NetworkCaptureMessage.java b/src/main/java/mpo/dayon/common/network/message/NetworkCaptureMessage.java index c7e9addb..b85fa0a7 100644 --- a/src/main/java/mpo/dayon/common/network/message/NetworkCaptureMessage.java +++ b/src/main/java/mpo/dayon/common/network/message/NetworkCaptureMessage.java @@ -98,7 +98,7 @@ public static NetworkCaptureMessage unmarshall(ObjectInputStream in) throws IOEx } public MemByteBuffer getPayload() { - return payload.copy(); + return payload; } public String toString() { diff --git a/src/main/java/mpo/dayon/common/squeeze/XzZipper.java b/src/main/java/mpo/dayon/common/squeeze/XzZipper.java index 67e1cf48..4ce644bd 100644 --- a/src/main/java/mpo/dayon/common/squeeze/XzZipper.java +++ b/src/main/java/mpo/dayon/common/squeeze/XzZipper.java @@ -6,10 +6,21 @@ import java.io.*; public class XzZipper implements Zipper { - @Override + + private final FilterOptions options; + + XzZipper() { + try { + options = new LZMA2Options(3); + } catch (UnsupportedOptionsException e) { + throw new IllegalArgumentException(e); + } + } + + @Override public MemByteBuffer zip(MemByteBuffer unCompressed) throws IOException { try (MemByteBuffer compressed = new MemByteBuffer()) { - try (XZOutputStream xzOutputStream = new XZOutputStream(compressed, new LZMA2Options(6))) { + try (XZOutputStream xzOutputStream = new XZOutputStream(compressed, options)) { xzOutputStream.write(unCompressed.getInternal(), 0, unCompressed.size()); xzOutputStream.flush(); }