I pre-populated a spritesheet with all 242 unique pure-black-and-white transformations of the sprites allowed by the rules. Then each frame, I compare each 8x8-pixel region in the source image against all 242 sprites to find the best fit. For the "best fit" heuristic, I sum `f0 += src - dst` and `f1 += abs(src - dest)` for each pixel, add `abs(f0) + f1` to get the error, and pick the sprite with the lowest error value.