From d5fc531bde3f2ee8cd164de5550dc08683c31ef4 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Thu, 25 Apr 2024 21:58:11 +0200 Subject: [PATCH] scale image to avoid squinting --- app/src/main/java/xdsopl/robot36/Decoder.java | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/xdsopl/robot36/Decoder.java b/app/src/main/java/xdsopl/robot36/Decoder.java index e6dc31b..02ee45d 100644 --- a/app/src/main/java/xdsopl/robot36/Decoder.java +++ b/app/src/main/java/xdsopl/robot36/Decoder.java @@ -130,18 +130,43 @@ public class Decoder { return bestMode; } - private void copyLines(boolean okay) { - if (!okay) - return; + private void copyUnscaled() { for (int row = 0; row < pixelBuffer.height; ++row) { - System.arraycopy(pixelBuffer.pixels, row * pixelBuffer.width, scopeBuffer.pixels, scopeBuffer.width * scopeBuffer.line, pixelBuffer.width); - Arrays.fill(scopeBuffer.pixels, scopeBuffer.width * scopeBuffer.line + pixelBuffer.width, scopeBuffer.width * scopeBuffer.line + scopeBuffer.width, 0); - System.arraycopy(pixelBuffer.pixels, row * pixelBuffer.width, scopeBuffer.pixels, scopeBuffer.width * (scopeBuffer.line + scopeBuffer.height / 2), pixelBuffer.width); - Arrays.fill(scopeBuffer.pixels, scopeBuffer.width * (scopeBuffer.line + scopeBuffer.height / 2) + pixelBuffer.width, scopeBuffer.width * (scopeBuffer.line + scopeBuffer.height / 2) + scopeBuffer.width, 0); + int line = scopeBuffer.width * scopeBuffer.line; + System.arraycopy(pixelBuffer.pixels, row * pixelBuffer.width, scopeBuffer.pixels, line, pixelBuffer.width); + Arrays.fill(scopeBuffer.pixels, line + pixelBuffer.width, line + scopeBuffer.width, 0); + System.arraycopy(scopeBuffer.pixels, line, scopeBuffer.pixels, scopeBuffer.width * (scopeBuffer.line + scopeBuffer.height / 2), scopeBuffer.width); scopeBuffer.line = (scopeBuffer.line + 1) % (scopeBuffer.height / 2); } } + private void copyScaled(int scale) { + for (int row = 0; row < pixelBuffer.height; ++row) { + int line = scopeBuffer.width * scopeBuffer.line; + for (int col = 0; col < pixelBuffer.width; ++col) + for (int i = 0; i < scale; ++i) + scopeBuffer.pixels[line + col * scale + i] = pixelBuffer.pixels[pixelBuffer.width * row + col]; + Arrays.fill(scopeBuffer.pixels, line + pixelBuffer.width * scale, line + scopeBuffer.width, 0); + System.arraycopy(scopeBuffer.pixels, line, scopeBuffer.pixels, scopeBuffer.width * (scopeBuffer.line + scopeBuffer.height / 2), scopeBuffer.width); + scopeBuffer.line = (scopeBuffer.line + 1) % (scopeBuffer.height / 2); + for (int i = 0; i < scale; ++i) { + System.arraycopy(scopeBuffer.pixels, line, scopeBuffer.pixels, scopeBuffer.width * scopeBuffer.line, scopeBuffer.width); + System.arraycopy(scopeBuffer.pixels, line, scopeBuffer.pixels, scopeBuffer.width * (scopeBuffer.line + scopeBuffer.height / 2), scopeBuffer.width); + scopeBuffer.line = (scopeBuffer.line + 1) % (scopeBuffer.height / 2); + } + } + } + + private void copyLines(boolean okay) { + if (!okay || pixelBuffer.width <= 0) + return; + int scale = scopeBuffer.width / pixelBuffer.width; + if (scale == 1) + copyUnscaled(); + else + copyScaled(scale); + } + private boolean processSyncPulse(ArrayList modes, float[] freqOffs, int[] pulses, int[] lines, int index) { for (int i = 1; i < lines.length; ++i) lines[i - 1] = lines[i];