Skip to content

Commit

Permalink
scale image to avoid squinting
Browse files Browse the repository at this point in the history
  • Loading branch information
xdsopl committed Apr 25, 2024
1 parent 7fd95be commit d5fc531
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions app/src/main/java/xdsopl/robot36/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,43 @@ private Mode detectMode(ArrayList<Mode> modes, int line) {
return bestMode;
}

private void copyLines(boolean okay) {
if (!okay)
return;
private void copyUnscaled() {
for (int row = 0; row < pixelBuffer.height; ++row) {
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) {
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;
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<Mode> modes, float[] freqOffs, int[] pulses, int[] lines, int index) {
for (int i = 1; i < lines.length; ++i)
lines[i - 1] = lines[i];
Expand Down

0 comments on commit d5fc531

Please sign in to comment.