"""Convert frame_*.bmp written by capture_swap.dll to PNG (stdlib only).""" import os, struct, sys, zlib def convert(path): b = open(path, 'rb').read() off = struct.unpack_from('I', len(x)) + t + x + struct.pack('>I', zlib.crc32(t + x) & 0xffffffff) out = path[:-4] + '.png' open(out, 'wb').write(b'\x89PNG\r\n\x1a\n' + ch(b'IHDR', struct.pack('>IIBBBBB', w, h, 8, 2, 0, 0, 0)) + ch(b'IDAT', zlib.compress(b''.join(rows), 6)) + ch(b'IEND', b'')) return out if __name__ == '__main__': for f in sorted(os.listdir(sys.argv[1])): if f.endswith('.bmp'): convert(os.path.join(sys.argv[1], f))