aboutsummaryrefslogtreecommitdiff
path: root/test-rig/Pixhash.java
diff options
context:
space:
mode:
authorLena <lena@omega>2026-01-01 00:00:00 +0000
committerLena <lena@omega>2026-06-24 22:14:50 +0300
commiteb0c8951196c637e44daf3c0617b131b997d5d2c (patch)
tree2f83b6a41cee745467e53fc401942b82cea286ea /test-rig/Pixhash.java
downloadscrcpy-android-0.1.tar.gz
scrcpy-android: mirror an Android device over wireless ADB0.1
Native Java app for Android 12+ that mirrors another Android device over wireless ADB, forwarding video, audio, touch input, and clipboard. Bundles a pinned scrcpy-server.jar and the vendored libadb-android stack. Supports h264/h265/av1 video and raw/opus audio with in-app codec selection. No NDK, no Kotlin. Includes JVM unit tests and a Docker-based emulator e2e rig.
Diffstat (limited to 'test-rig/Pixhash.java')
-rw-r--r--test-rig/Pixhash.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/test-rig/Pixhash.java b/test-rig/Pixhash.java
new file mode 100644
index 0000000..47ab8b8
--- /dev/null
+++ b/test-rig/Pixhash.java
@@ -0,0 +1,54 @@
+// Verify that a screencap PNG is non-uniform - i.e., MediaCodec
+// actually painted something. Exits 0 if the image has at least
+// `--min` percent of pixels that differ from pixel (0,0); 1 otherwise.
+//
+// java test-rig/Pixhash.java <png> # default min=5%
+// java test-rig/Pixhash.java <png> --min 1
+//
+// We avoid AWT's BufferedImage because some headless JDKs ship without
+// it; ImageIO is in java.desktop which IS present in the openjdk-17-jdk
+// package in our image, so it's fine.
+
+import java.io.File;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+
+public final class Pixhash {
+
+ public static void main(String[] args) throws IOException {
+ if (args.length < 1) {
+ System.err.println("usage: java Pixhash.java <png> [--min N]");
+ System.exit(2);
+ }
+ double minPercent = 5.0;
+ for (int i = 1; i < args.length; i++) {
+ if ("--min".equals(args[i]) && i + 1 < args.length) {
+ minPercent = Double.parseDouble(args[++i]);
+ }
+ }
+
+ BufferedImage img = ImageIO.read(new File(args[0]));
+ if (img == null) {
+ System.err.println("pixhash: could not read " + args[0]);
+ System.exit(2);
+ }
+
+ int w = img.getWidth(), h = img.getHeight();
+ int ref = img.getRGB(0, 0);
+ long total = (long) w * h;
+ long diff = 0;
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ if (img.getRGB(x, y) != ref) diff++;
+ }
+ }
+ double pct = 100.0 * diff / total;
+ System.out.printf("pixhash: %d/%d differ from (0,0)=%08x => %.2f%%%n",
+ diff, total, ref, pct);
+ if (pct < minPercent) {
+ System.err.printf("pixhash: only %.2f%% differ, need %.2f%%%n", pct, minPercent);
+ System.exit(1);
+ }
+ }
+}