Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PIL/BlpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class BLPEncoder(ImageFile.PyEncoder):
def _write_palette(self) -> bytes:
data = b""
assert self.im is not None
palette = self.im.getpalette("RGBA", "RGBA")
palette = self.im.getpalette("RGBA")
for i in range(len(palette) // 4):
r, g, b, a = palette[i * 4 : (i + 1) * 4]
data += struct.pack("<4B", b, g, r, a)
Expand Down
8 changes: 3 additions & 5 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,7 @@ def load(self) -> core.PixelAccess | None:
elif self.palette.mode != mode:
# If the palette rawmode is different to the mode,
# then update the Python palette data
self.palette.palette = self.im.getpalette(
self.palette.mode, self.palette.mode
)
self.palette.palette = self.im.getpalette(self.palette.mode)

if self._im is not None:
return self.im.pixel_access(self.readonly)
Expand Down Expand Up @@ -1346,7 +1344,7 @@ def quantize(
from . import ImagePalette

mode = im.im.getpalettemode()
palette_data = im.im.getpalette(mode, mode)[: colors * len(mode)]
palette_data = im.im.getpalette(mode)[: colors * len(mode)]
im.palette = ImagePalette.ImagePalette(mode, palette_data)

return im
Expand Down Expand Up @@ -2230,7 +2228,7 @@ def remap_palette(
palette_mode = self.im.getpalettemode()
if palette_mode == "RGBA":
bands = 4
source_palette = self.im.getpalette(palette_mode, palette_mode)
source_palette = self.im.getpalette(palette_mode)
else: # L-mode
source_palette = bytearray(i // 3 for i in range(768))
elif len(source_palette) > 768:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
if im.mode == "P":
# colour palette
fp.write(o8(12))
palette = im.im.getpalette("RGB", "RGB")
palette = im.im.getpalette("RGB")
palette += b"\x00" * (768 - len(palette))
fp.write(palette) # 768 bytes
elif im.mode == "L":
Expand Down
5 changes: 4 additions & 1 deletion src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,13 @@ _getpalette(ImagingObject *self, PyObject *args) {
ImagingShuffler pack;

char *mode_name = "RGB";
char *rawmode_name = "RGB";
char *rawmode_name = NULL;
if (!PyArg_ParseTuple(args, "|ss", &mode_name, &rawmode_name)) {
return NULL;
}
if (rawmode_name == NULL) {
rawmode_name = mode_name;
}

if (!self->image->palette) {
PyErr_SetString(PyExc_ValueError, no_palette);
Expand Down
Loading