- Introduce `shiftRadius` to allow positional tolerances by searching a local neighborhood, absorbing sub-pixel shifts and MSAA quirks. - Introduce `blurRadius` to apply local area averaging, ignoring high-frequency noise like hardware dithering. - Enhance `ImageDiffResult` to include an `averageError` array and a 10-bin `errorHistogram` for actionable failure debugging. - Update Android JNI bindings (`ImageDiff.java` and `ImageDiff.cpp`) to propagate the new error distribution statistics to Java callers. - Update C++ unit tests to cover the new heuristic options. - Document the new parameters and JSON result format in README.md. - Add synthetic image generation tests in `tools/diffimg/tests/` to validate the CLI tool's handling of spatial shifts and dithering.
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import math
|
|
|
|
def write_ppm(filename, width, height, pixels):
|
|
with open(filename, 'w') as f:
|
|
f.write(f"P3\n{width} {height}\n255\n")
|
|
for y in range(height):
|
|
for x in range(width):
|
|
r, g, b = pixels[y][x]
|
|
f.write(f"{r} {g} {b} ")
|
|
f.write("\n")
|
|
|
|
def create_ref():
|
|
pixels = [[(0,0,0) for _ in range(64)] for _ in range(64)]
|
|
for y in range(64):
|
|
for x in range(64):
|
|
dx = x - 31.5
|
|
dy = y - 31.5
|
|
if math.sqrt(dx*dx + dy*dy) < 15:
|
|
pixels[y][x] = (255, 255, 255)
|
|
return pixels
|
|
|
|
def create_shifted():
|
|
pixels = [[(0,0,0) for _ in range(64)] for _ in range(64)]
|
|
for y in range(64):
|
|
for x in range(64):
|
|
dx = (x - 1) - 31.5
|
|
dy = y - 31.5
|
|
if math.sqrt(dx*dx + dy*dy) < 15:
|
|
pixels[y][x] = (255, 255, 255)
|
|
return pixels
|
|
|
|
def create_dithered():
|
|
pixels = create_ref()
|
|
for y in range(64):
|
|
for x in range(64):
|
|
r, g, b = pixels[y][x]
|
|
if r == 255:
|
|
if (x + y) % 2 == 0:
|
|
pixels[y][x] = (200, 200, 200)
|
|
else:
|
|
pixels[y][x] = (255, 255, 255)
|
|
return pixels
|
|
|
|
if __name__ == '__main__':
|
|
write_ppm('ref.ppm', 64, 64, create_ref())
|
|
write_ppm('cand_shift.ppm', 64, 64, create_shifted())
|
|
write_ppm('cand_blur.ppm', 64, 64, create_dithered())
|
|
print("PPM Images generated successfully.")
|