|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright Contributors to the OpenImageIO project. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# https://github.com/AcademySoftwareFoundation/OpenImageIO |
| 6 | + |
| 7 | +import struct |
| 8 | + |
| 9 | + |
| 10 | +MAGIC = 0x5380F634 |
| 11 | +WIDTH = 2 |
| 12 | +HEIGHT = 1 |
| 13 | +RED_CHANNEL = 0x80 |
| 14 | +GREEN_CHANNEL = 0x40 |
| 15 | + |
| 16 | +UNCOMPRESSED = 0 |
| 17 | +PURE_RUN_LENGTH = 1 |
| 18 | +MIXED_RUN_LENGTH = 2 |
| 19 | + |
| 20 | + |
| 21 | +def header(): |
| 22 | + comment = b"Malformed channel packet regression" |
| 23 | + return struct.pack(">If80s4sHHfHH", MAGIC, 1.0, comment, b"PICT", |
| 24 | + WIDTH, HEIGHT, 1.0, 0, 0) |
| 25 | + |
| 26 | + |
| 27 | +def channel_packet(chained, size, encoding, channel): |
| 28 | + return bytes((chained, size, encoding, channel)) |
| 29 | + |
| 30 | + |
| 31 | +def write_pic(filename, encoding, red_payload, green_payload): |
| 32 | + with open(filename, "wb") as out: |
| 33 | + out.write(header()) |
| 34 | + out.write(channel_packet(1, 16, encoding, RED_CHANNEL)) |
| 35 | + out.write(channel_packet(0, 8, encoding, GREEN_CHANNEL)) |
| 36 | + out.write(red_payload) |
| 37 | + out.write(green_payload) |
| 38 | + |
| 39 | + |
| 40 | +write_pic("inconsistent-bpc-uncompressed.pic", UNCOMPRESSED, |
| 41 | + b"\x00\x10\x00\x20", b"\x30\x40") |
| 42 | +write_pic("inconsistent-bpc-pure-rle.pic", PURE_RUN_LENGTH, |
| 43 | + b"\x02\x00\x10", b"\x02\x30") |
| 44 | +write_pic("inconsistent-bpc-mixed-rle.pic", MIXED_RUN_LENGTH, |
| 45 | + b"\x01\x00\x10\x00\x20", b"\x01\x30\x40") |
0 commit comments