mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-22 22:19:46 +03:00
Remove padding between interleaved PCX palette data (#9005)
This commit is contained in:
parent
7f7c27f66a
commit
8ccdc399df
BIN
Tests/images/p_4_planes.pcx
Normal file
BIN
Tests/images/p_4_planes.pcx
Normal file
Binary file not shown.
|
@ -37,6 +37,11 @@ def test_sanity(tmp_path: Path) -> None:
|
|||
im.save(f)
|
||||
|
||||
|
||||
def test_p_4_planes() -> None:
|
||||
with Image.open("Tests/images/p_4_planes.pcx") as im:
|
||||
assert im.getpixel((0, 0)) == 3
|
||||
|
||||
|
||||
def test_bad_image_size() -> None:
|
||||
with open("Tests/images/pil184.pcx", "rb") as fp:
|
||||
data = fp.read()
|
||||
|
|
|
@ -60,15 +60,25 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
|
|||
}
|
||||
|
||||
if (state->x >= state->bytes) {
|
||||
if (state->bytes % state->xsize && state->bytes > state->xsize) {
|
||||
int bands = state->bytes / state->xsize;
|
||||
int stride = state->bytes / bands;
|
||||
int bands;
|
||||
int xsize = 0;
|
||||
int stride = 0;
|
||||
if (state->bits == 2 || state->bits == 4) {
|
||||
xsize = (state->xsize + 7) / 8;
|
||||
bands = state->bits;
|
||||
stride = state->bytes / state->bits;
|
||||
} else {
|
||||
xsize = state->xsize;
|
||||
bands = state->bytes / state->xsize;
|
||||
if (bands != 0) {
|
||||
stride = state->bytes / bands;
|
||||
}
|
||||
}
|
||||
if (stride > xsize) {
|
||||
int i;
|
||||
for (i = 1; i < bands; i++) { // note -- skipping first band
|
||||
memmove(
|
||||
&state->buffer[i * state->xsize],
|
||||
&state->buffer[i * stride],
|
||||
state->xsize
|
||||
&state->buffer[i * xsize], &state->buffer[i * stride], xsize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user