|
1 | 1 | # SPDX-FileCopyrightText: 2022 Radomir Dopieralski
|
2 | 2 | # SPDX-FileCopyrightText: 2023 Matt Land
|
| 3 | +# SPDX-FileCopyrightText: 2024 Channing Ramos |
3 | 4 | #
|
4 | 5 | # SPDX-License-Identifier: MIT
|
5 | 6 |
|
|
10 | 11 | Load pixel values (indices or colors) into a bitmap and colors into a palette
|
11 | 12 | from a PNG file.
|
12 | 13 |
|
13 |
| -* Author(s): Radomir Dopieralski, Matt Land |
| 14 | +* Author(s): Radomir Dopieralski, Matt Land, Channing Ramos |
14 | 15 |
|
15 | 16 | """
|
16 | 17 |
|
@@ -48,7 +49,7 @@ def load(
|
48 | 49 | :param object palette: Type to store the palette. Must have API similar to
|
49 | 50 | `displayio.Palette`. Will be skipped if None.
|
50 | 51 | """
|
51 |
| - # pylint: disable=too-many-locals,too-many-branches |
| 52 | + # pylint: disable=too-many-locals,too-many-branches, consider-using-enumerate, too-many-statements |
52 | 53 | header = file.read(8)
|
53 | 54 | if header != b"\x89PNG\r\n\x1a\n":
|
54 | 55 | raise ValueError("Not a PNG file")
|
@@ -86,6 +87,14 @@ def load(
|
86 | 87 | pal = palette(pal_size)
|
87 | 88 | for i in range(pal_size):
|
88 | 89 | pal[i] = file.read(3)
|
| 90 | + elif chunk == b"tRNS": |
| 91 | + if size > len(pal): |
| 92 | + raise ValueError("More transparency entries than palette entries") |
| 93 | + trns_data = file.read(size) |
| 94 | + for i in range(len(trns_data)): |
| 95 | + if trns_data[i] == 0: |
| 96 | + pal.make_transparent(i) |
| 97 | + del trns_data |
89 | 98 | elif chunk == b"IDAT":
|
90 | 99 | data.extend(file.read(size))
|
91 | 100 | elif chunk == b"IEND":
|
|
0 commit comments