Class PixelAssertions

java.lang.Object
eu.svjatoslav.sixth.e3d.headless.PixelAssertions

public final class PixelAssertions extends Object
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 Details

    • unpaintedFraction

      public static double unpaintedFraction(BufferedImage image, int backgroundRgb)
      Fraction of pixels in the whole image that still equal the background color (i.e. nothing was painted there).
      Parameters:
      image - the rendered image
      backgroundRgb - 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 image
      backgroundRgb - 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

      public static long countPainted(BufferedImage image, int backgroundRgb)
      Counts pixels in the whole image that differ from the background color.
      Parameters:
      image - the rendered image
      backgroundRgb - the background color (RGB, alpha ignored)
      Returns:
      number of painted pixels
    • countColor

      public static long countColor(BufferedImage image, int rgb)
      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 image
      rgb - the color to count (alpha ignored)
      Returns:
      number of matching pixels
    • dumpPixelGrid

      public static String dumpPixelGrid(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. Samples every stride pixels, formatted as RRGGBB hex, one row per line.
      Parameters:
      image - the rendered image
      cx - center X in pixels
      cy - center Y in pixels
      radius - grid extends this many samples in each direction
      stride - pixels between samples
      Returns:
      multi-line hex grid string