# # Extract the OUT-OF-RANGE pixel mask from the positive-control capture. # # With BT_TRANS_PROVOKE the sec port's translationTable[64..255] is 0xFF00, # so every pixel whose source index exceeded the 6-bit palette sets ALL the # high-byte head bits. Eng1 (0x0200) is sparse, so "Eng1 lit in provoke but # not in shipped" isolates the offenders exactly. # import sys from PIL import Image BOX = (8, 52, 648, 531) ENG1 = 0x0200 def words(path): im = Image.open(path).convert("RGB").crop(BOX) w, h = im.size px = im.load() return [[((px[x, y][0] >> 3) << 11) | ((px[x, y][1] >> 2) << 5) | (px[x, y][2] >> 3) for x in range(w)] for y in range(h)], w, h A, w, h = words(sys.argv[1]) # shipped B, _, _ = words(sys.argv[2]) # provoke out = Image.new("RGB", (w, h), (0, 0, 0)) op = out.load() runs = {} n = 0 for y in range(h): run = 0 for x in range(w): if (B[y][x] & ENG1) and not (A[y][x] & ENG1): op[x, y] = (255, 40, 0) n += 1 run += 1 else: if run: runs[run] = runs.get(run, 0) + 1 run = 0 if run: runs[run] = runs.get(run, 0) + 1 out.save(sys.argv[3]) print("out-of-range pixels: %d" % n) print("horizontal run lengths (len: count), longest first:") for k in sorted(runs, reverse=True)[:12]: print(" %3d px run x%d" % (k, runs[k]))