From 89ff59ca6bec43ab232562f50004ea07580ba761 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Thu, 16 Jul 2026 13:50:06 -0700 Subject: [PATCH] Quantize rendered icons for better screen-image compressibility --- .../main/java/com/faceclaw/app/IconRenderer.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java index 53b0673b..80589f47 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java @@ -77,7 +77,7 @@ public final class IconRenderer { bitmap.getPixels(pixels, 0, size, 0, 0, size, size); byte[] gray = new byte[size * size]; for (int i = 0; i < pixels.length; i++) { - gray[i] = (byte) ((pixels[i] >>> 24) & 0xff); // alpha = coverage + gray[i] = (byte) quantizeCoverage((pixels[i] >>> 24) & 0xff); // alpha = coverage } return gray; } catch (Exception e) { @@ -86,6 +86,20 @@ public final class IconRenderer { } } + /** + * Snap antialiased coverage toward hard edges so the 4bpp frames sent + * over BLE deflate better: mostly-transparent and mostly-opaque pixels + * become exactly 0/255 (long runs, and 0 stays color-key transparent for + * bitBlt), and only genuinely half-covered edge pixels keep one mid gray. + * The packed frame then uses a 3-symbol alphabet instead of all 16 + * levels, at icon sizes this is visually near-identical. + */ + private static int quantizeCoverage(int alpha) { + if (alpha < 64) return 0; + if (alpha >= 192) return 255; + return 128; + } + private static void appendElement(Path path, String tag, String attrs) { switch (tag) { case "path": {