Package eu.svjatoslav.sixth.e3d.headless
Class GoldenImage
java.lang.Object
eu.svjatoslav.sixth.e3d.headless.GoldenImage
Golden-image comparison: render a scene, compare against a committed
reference PNG, fail when the picture drifts.
A pixel counts as different when any RGB channel differs by more than a per-channel tolerance; a comparison fails when the fraction of differing pixels exceeds a threshold. Both are parameters — shading and antialiasing make exact matches fragile, but "the floor lost 30% of its pixels" must not pass.
Example:
BufferedImage actual = Snapshot.render(scene, lighting, pose, 640, 480);
GoldenImage.Result r = GoldenImage.compare(actual, new File("goldens/house.png"), 8, 0.01);
if (!r.passed) {
GoldenImage.saveDiff(actual, new File("goldens/house.png"), "/tmp/diff.png");
throw new AssertionError(r.toString());
}
Command line (for scripts):
java eu.svjatoslav.sixth.e3d.headless.GoldenImage actual.png golden.png [tolerance] [maxDiffFraction] exit code 0 = match, 1 = differ, 2 = usage/io error
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOutcome of one comparison. -
Method Summary
Modifier and TypeMethodDescriptionstatic GoldenImage.Resultcompare(BufferedImage actual, File goldenFile, int channelTolerance, double maxDiffFraction) Compares an image against a golden PNG file.static voidCLI: compares two PNGs.static voidsaveDiff(BufferedImage actual, File goldenFile, String outPath) Writes a visual diff image: matching pixels dimmed, differing pixels highlighted red.
-
Method Details
-
compare
public static GoldenImage.Result compare(BufferedImage actual, File goldenFile, int channelTolerance, double maxDiffFraction) throws IOException Compares an image against a golden PNG file.- Parameters:
actual- the rendered imagegoldenFile- the reference PNGchannelTolerance- per-channel (R/G/B) tolerance, 0 = exactmaxDiffFraction- maximum allowed fraction of differing pixels (0..1)- Returns:
- the comparison result
- Throws:
IOException- on read failure or size mismatch
-
saveDiff
public static void saveDiff(BufferedImage actual, File goldenFile, String outPath) throws IOException Writes a visual diff image: matching pixels dimmed, differing pixels highlighted red. Handy for inspecting a failed comparison.- Parameters:
actual- the rendered imagegoldenFile- the reference PNGoutPath- where to write the diff PNG- Throws:
IOException- on read/write failure or size mismatch
-
main
CLI: compares two PNGs. Exit 0 = match, 1 = differ, 2 = error.- Parameters:
args- actual.png golden.png [channelTolerance] [maxDiffFraction]
-