Skip to content

Commit bbe1eff

Browse files
authored
Merge pull request #8082 from Yay295/patch-4
2 parents 8b14ed7 + 82d9926 commit bbe1eff

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/PIL/PngImagePlugin.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,22 +1050,22 @@ def getxmp(self):
10501050
# PNG writer
10511051

10521052
_OUTMODES = {
1053-
# supported PIL modes, and corresponding rawmodes/bits/color combinations
1054-
"1": ("1", b"\x01\x00"),
1055-
"L;1": ("L;1", b"\x01\x00"),
1056-
"L;2": ("L;2", b"\x02\x00"),
1057-
"L;4": ("L;4", b"\x04\x00"),
1058-
"L": ("L", b"\x08\x00"),
1059-
"LA": ("LA", b"\x08\x04"),
1060-
"I": ("I;16B", b"\x10\x00"),
1061-
"I;16": ("I;16B", b"\x10\x00"),
1062-
"I;16B": ("I;16B", b"\x10\x00"),
1063-
"P;1": ("P;1", b"\x01\x03"),
1064-
"P;2": ("P;2", b"\x02\x03"),
1065-
"P;4": ("P;4", b"\x04\x03"),
1066-
"P": ("P", b"\x08\x03"),
1067-
"RGB": ("RGB", b"\x08\x02"),
1068-
"RGBA": ("RGBA", b"\x08\x06"),
1053+
# supported PIL modes, and corresponding rawmode, bit depth and color type
1054+
"1": ("1", b"\x01", b"\x00"),
1055+
"L;1": ("L;1", b"\x01", b"\x00"),
1056+
"L;2": ("L;2", b"\x02", b"\x00"),
1057+
"L;4": ("L;4", b"\x04", b"\x00"),
1058+
"L": ("L", b"\x08", b"\x00"),
1059+
"LA": ("LA", b"\x08", b"\x04"),
1060+
"I": ("I;16B", b"\x10", b"\x00"),
1061+
"I;16": ("I;16B", b"\x10", b"\x00"),
1062+
"I;16B": ("I;16B", b"\x10", b"\x00"),
1063+
"P;1": ("P;1", b"\x01", b"\x03"),
1064+
"P;2": ("P;2", b"\x02", b"\x03"),
1065+
"P;4": ("P;4", b"\x04", b"\x03"),
1066+
"P": ("P", b"\x08", b"\x03"),
1067+
"RGB": ("RGB", b"\x08", b"\x02"),
1068+
"RGBA": ("RGBA", b"\x08", b"\x06"),
10691069
}
10701070

10711071

@@ -1294,7 +1294,7 @@ def _save(im, fp, filename, chunk=putchunk, save_all=False):
12941294

12951295
# get the corresponding PNG mode
12961296
try:
1297-
rawmode, mode = _OUTMODES[mode]
1297+
rawmode, bit_depth, color_type = _OUTMODES[mode]
12981298
except KeyError as e:
12991299
msg = f"cannot write mode {mode} as PNG"
13001300
raise OSError(msg) from e
@@ -1309,7 +1309,8 @@ def _save(im, fp, filename, chunk=putchunk, save_all=False):
13091309
b"IHDR",
13101310
o32(size[0]), # 0: size
13111311
o32(size[1]),
1312-
mode, # 8: depth/type
1312+
bit_depth,
1313+
color_type,
13131314
b"\0", # 10: compression
13141315
b"\0", # 11: filter category
13151316
b"\0", # 12: interlace flag

0 commit comments

Comments
 (0)