Write a PNG chunk to the output file, including length and checksum.
(outfile, tag, data=b"")
| 906 | |
| 907 | |
| 908 | def write_chunk(outfile, tag, data=b""): |
| 909 | """ |
| 910 | Write a PNG chunk to the output file, including length and |
| 911 | checksum. |
| 912 | """ |
| 913 | |
| 914 | data = bytes(data) |
| 915 | # http://www.w3.org/TR/PNG/#5Chunk-layout |
| 916 | outfile.write(struct.pack("!I", len(data))) |
| 917 | outfile.write(tag) |
| 918 | outfile.write(data) |
| 919 | checksum = zlib.crc32(tag) |
| 920 | checksum = zlib.crc32(data, checksum) |
| 921 | checksum &= 2**32 - 1 |
| 922 | outfile.write(struct.pack("!I", checksum)) |
| 923 | |
| 924 | |
| 925 | def write_chunks(out, chunks): |
no test coverage detected