Package eu.svjatoslav.sixth.e3d.headless
Class PixelAssertions
java.lang.Object
eu.svjatoslav.sixth.e3d.headless.PixelAssertions
Pixel-level assertions for headless render verification.
The recurring question in rasterizer debugging is "did this region of
the screen actually get painted?" These helpers answer it against a
BufferedImage produced by Snapshot, treating one chosen
background color as "unpainted". All methods are static and return data
rather than throwing, so callers decide how to report failures.
Example — assert the floor rendered (no holes from clipping):
BufferedImage image = Snapshot.render(scene, lighting, pose, 640, 480);
double holes = PixelAssertions.unpaintedFraction(image, 0x00000000,
0.15, 0.45, 0.85, 1.0); // lower-center band
if (holes > 0.05)
throw new AssertionError("floor has holes: " + holes);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic longcountColor(BufferedImage image, int rgb) Counts pixels equal (in RGB) to the given color.static longcountPainted(BufferedImage image, int backgroundRgb) Counts pixels in the whole image that differ from the background color.static StringdumpPixelGrid(BufferedImage image, int cx, int cy, int radius, int stride) Dumps a grid of pixel colors around a point as text, for eyeballing gradients/edges in a failing render.static doubleunpaintedFraction(BufferedImage image, int backgroundRgb) Fraction of pixels in the whole image that still equal the background color (i.e.static doubleunpaintedFraction(BufferedImage image, int backgroundRgb, double x0, double y0, double x1, double y1) Fraction of pixels inside a relative rectangle that still equal the background color.
-
Method Details
-
unpaintedFraction
Fraction of pixels in the whole image that still equal the background color (i.e. nothing was painted there).- Parameters:
image- the rendered imagebackgroundRgb- the background color (RGB, alpha ignored)- Returns:
- fraction in [0, 1]
-
unpaintedFraction
public static double unpaintedFraction(BufferedImage image, int backgroundRgb, double x0, double y0, double x1, double y1) Fraction of pixels inside a relative rectangle that still equal the background color.- Parameters:
image- the rendered imagebackgroundRgb- the background color (RGB, alpha ignored)x0- left edge, fraction of width (0..1)y0- top edge, fraction of height (0..1)x1- right edge, fraction of width (0..1)y1- bottom edge, fraction of height (0..1)- Returns:
- fraction in [0, 1]
-
countPainted
Counts pixels in the whole image that differ from the background color.- Parameters:
image- the rendered imagebackgroundRgb- the background color (RGB, alpha ignored)- Returns:
- number of painted pixels
-
countColor
Counts pixels equal (in RGB) to the given color. Useful with flat test colors: "how much of the red triangle made it to the screen?"- Parameters:
image- the rendered imagergb- the color to count (alpha ignored)- Returns:
- number of matching pixels
-
dumpPixelGrid
Dumps a grid of pixel colors around a point as text, for eyeballing gradients/edges in a failing render. Samples everystridepixels, formatted as RRGGBB hex, one row per line.- Parameters:
image- the rendered imagecx- center X in pixelscy- center Y in pixelsradius- grid extends this many samples in each directionstride- pixels between samples- Returns:
- multi-line hex grid string
-