"""Writes the synthetic pictures the external vectors are encoded from: planar samples of a fixed pattern, so the inputs are the same on every machine and hold no captured content. python3 -I yuv.py [] is 420, 422, 444 (planes Y, Cb, Cr) or rgb (planes R, G, B). Samples above 8 bits are two bytes, little-endian. moves the pattern right by that many columns, the second view of a stereo pair. """ import sys def main(out, w, h, frames, layout, depth, shift=0): w, h, frames, depth, shift = int(w), int(h), int(frames), int(depth), int(shift) top = (1 << depth) - 1 if layout == "rgb": planes = [(1, 1)] * 3 else: sub = {"420": (2, 2), "422": (2, 1), "444": (1, 1)}[layout] planes = [(1, 1), sub, sub] data = bytearray() for f in range(frames): for p, (sx, sy) in enumerate(planes): pw, ph = (w + sx - 1) // sx, (h + sy - 1) // sy for y in range(ph): for x in range(pw): xs = (x * sx - shift) % w # a diagonal ramp, a checker and a moving bar, per plane v = (xs * 3 + y * sy * 5 + f * 7 + p * 40) * (top // 255 if top > 255 else 1) if ((xs // 8) + (y * sy // 8) + p) % 2: v += top // 6 if (xs + f * 4) % w < 6: v = top - v % (top // 4 + 1) v %= top + 1 data += bytes([v]) if depth <= 8 else v.to_bytes(2, "little") with open(out, "wb") as fh: fh.write(data) if __name__ == "__main__": main(*sys.argv[1:])