tools/capture.sh <scene-or-scenario> <out.png> renders the real client in a throwaway tidewall-capture-* Docker container (debian:13, Xvfb, Mesa software rendering), with no network, no host display, GPU or audio, and removes the container afterwards. The tidewall-capture image rebuilds only when its recipe changes. Forward+ through Lavapipe is the default, matching the game; CAPTURE_RENDERER=compatibility uses OpenGL through llvmpipe. The script fails if Godot silently falls back to another renderer, and fails on a blank frame, judged by ImageStats (luminance variance and colour count). make capture-test renders the shore test scene with both renderers and proves an empty scene is rejected. ImageStats has unit tests in make check. CLAUDE.md now requires a capture for visual issues, and requires that it be opened and looked at. Closes #7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.6 KiB
GDScript
46 lines
1.6 KiB
GDScript
## Measures a captured image, so a blank or broken render fails automatically.
|
|
## A capture still has to be looked at by a person or agent; this only catches the
|
|
## obvious failures.
|
|
class_name ImageStats
|
|
extends RefCounted
|
|
|
|
## Below this luminance variance (on a 0..1 scale) an image counts as blank.
|
|
const BLANK_VARIANCE: float = 0.0005
|
|
## A real scene has far more distinct colours than a cleared or broken frame.
|
|
const BLANK_MAX_COLOURS: int = 16
|
|
## Sampling stride, in pixels. Enough for a 1280x720 frame in milliseconds.
|
|
const STRIDE: int = 4
|
|
|
|
|
|
## Returns mean and variance of luminance, and the number of distinct sampled colours.
|
|
static func measure(image: Image) -> Dictionary:
|
|
var source: Image = image
|
|
if source.is_compressed():
|
|
source = image.duplicate() as Image
|
|
source.decompress()
|
|
var sum: float = 0.0
|
|
var sum_squares: float = 0.0
|
|
var samples: int = 0
|
|
var colours: Dictionary = {}
|
|
for y: int in range(0, source.get_height(), STRIDE):
|
|
for x: int in range(0, source.get_width(), STRIDE):
|
|
var colour: Color = source.get_pixel(x, y)
|
|
var luminance: float = colour.get_luminance()
|
|
sum += luminance
|
|
sum_squares += luminance * luminance
|
|
samples += 1
|
|
colours[colour.to_rgba32()] = true
|
|
if samples == 0:
|
|
return {"samples": 0, "mean": 0.0, "variance": 0.0, "colours": 0}
|
|
var mean: float = sum / samples
|
|
return {
|
|
"samples": samples,
|
|
"mean": mean,
|
|
"variance": maxf(sum_squares / samples - mean * mean, 0.0),
|
|
"colours": colours.size(),
|
|
}
|
|
|
|
|
|
static func is_blank(stats: Dictionary) -> bool:
|
|
return stats["variance"] < BLANK_VARIANCE or stats["colours"] <= BLANK_MAX_COLOURS
|