Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): require substantial alpha silhouettes

[._.]/ Adam Eivy0c69fedef417
diff --git a/server/lib/imageFrameStats.js b/server/lib/imageFrameStats.js
index ecec6671f5..6b7f5bcbe9 100644
--- a/server/lib/imageFrameStats.js
+++ b/server/lib/imageFrameStats.js
@@ -58,6 +58,11 @@ export const MIN_JUDGEABLE_PIXELS = 256;
// meaningful silhouette.
export const ALPHA_COVERAGE_FLOOR = 255 * 0.005;
+// A silhouette needs a substantial minority of the alpha distribution to be
+// present, not merely one-pixel speckle. This is the binary-mask stdev for a
+// 5% minority and keeps alpha noise from rescuing a flat colour fill.
+export const ALPHA_SILHOUETTE_STDEV_FLOOR = 255 * Math.sqrt(0.05 * 0.95);
+
export const FRAME_REASON = {
SOLID_FILL: 'solid-fill',
FULLY_TRANSPARENT: 'fully-transparent',
@@ -129,7 +134,7 @@ export async function describeFrameStats(input) {
alpha
&& !stats.isOpaque
&& alpha.max > alpha.min
- && alpha.stdev >= SOLID_FILL_STDEV_EPSILON
+ && alpha.stdev >= ALPHA_SILHOUETTE_STDEV_FLOOR
&& alpha.mean >= ALPHA_COVERAGE_FLOOR
&& alpha.mean <= 255 - ALPHA_COVERAGE_FLOOR,
);
diff --git a/server/lib/imageFrameStats.test.js b/server/lib/imageFrameStats.test.js
index 1405f97d47..7c99ddc505 100644
--- a/server/lib/imageFrameStats.test.js
+++ b/server/lib/imageFrameStats.test.js
@@ -105,21 +105,27 @@ describe('describeFrameStats', () => {
expect(isDegenerateFrame(stats)).toBe(false);
});
- it('rejects an RGBA frame with only a few visible pixels', async () => {
+ it('rejects a solid RGBA fill with only a few transparent pixels', async () => {
const buf = await fromPixels((x, y) => (
- x === 0 && y === 0 ? [255, 255, 255, 255] : [0, 0, 0, 0]
+ x < 41 && y === 0 ? [40, 40, 40, 0] : [40, 40, 40, 255]
), { channels: 4 });
const stats = await describeFrameStats(buf);
expect(stats.ok).toBe(false);
- expect(stats.reason).toBe(FRAME_REASON.NEAR_EMPTY);
+ expect(stats.reason).toBe(FRAME_REASON.SOLID_FILL);
});
- it('rejects a flat RGBA frame with only a few transparent pixels', async () => {
+ it('rejects an RGBA frame with only a few visible pixels', async () => {
const buf = await fromPixels((x, y) => (
- x < 2 && y === 0 ? [40, 40, 40, 0] : [40, 40, 40, 255]
+ x === 0 && y === 0 ? [255, 255, 255, 255] : [0, 0, 0, 0]
), { channels: 4 });
const stats = await describeFrameStats(buf);
expect(stats.ok).toBe(false);
+ expect(stats.reason).toBe(FRAME_REASON.NEAR_EMPTY);
+ });
+
+ it('rejects a fully opaque RGBA solid fill', async () => {
+ const stats = await describeFrameStats(await solid({ r: 0, g: 0, b: 0, alpha: 1 }, 4));
+ expect(stats.ok).toBe(false);
expect(stats.reason).toBe(FRAME_REASON.SOLID_FILL);
});