mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
Added rounding when converting P and PA
This commit is contained in:
parent
24f0bbf5ec
commit
bb6212a332
|
@ -93,7 +93,7 @@ def test_trns_p(tmp_path):
|
||||||
f = str(tmp_path / "temp.png")
|
f = str(tmp_path / "temp.png")
|
||||||
|
|
||||||
im_l = im.convert("L")
|
im_l = im.convert("L")
|
||||||
assert im_l.info["transparency"] == 0 # undone
|
assert im_l.info["transparency"] == 1 # undone
|
||||||
im_l.save(f)
|
im_l.save(f)
|
||||||
|
|
||||||
im_rgb = im.convert("RGB")
|
im_rgb = im.convert("RGB")
|
||||||
|
@ -170,6 +170,20 @@ def test_trns_RGB(tmp_path):
|
||||||
im_p.save(f)
|
im_p.save(f)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("convert_mode", ("L", "LA", "I"))
|
||||||
|
def test_l_macro_rounding(convert_mode):
|
||||||
|
for mode in ("P", "PA"):
|
||||||
|
im = Image.new(mode, (1, 1))
|
||||||
|
im.palette.getcolor((0, 1, 2))
|
||||||
|
|
||||||
|
converted_im = im.convert(convert_mode)
|
||||||
|
px = converted_im.load()
|
||||||
|
converted_color = px[0, 0]
|
||||||
|
if convert_mode == "LA":
|
||||||
|
converted_color = converted_color[0]
|
||||||
|
assert converted_color == 1
|
||||||
|
|
||||||
|
|
||||||
def test_gif_with_rgba_palette_to_p():
|
def test_gif_with_rgba_palette_to_p():
|
||||||
# See https://github.com/python-pillow/Pillow/issues/2433
|
# See https://github.com/python-pillow/Pillow/issues/2433
|
||||||
with Image.open("Tests/images/hopper.gif") as im:
|
with Image.open("Tests/images/hopper.gif") as im:
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ p2l(UINT8 *out, const UINT8 *in, int xsize, const UINT8 *palette) {
|
||||||
int x;
|
int x;
|
||||||
/* FIXME: precalculate greyscale palette? */
|
/* FIXME: precalculate greyscale palette? */
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
*out++ = L(&palette[in[x] * 4]) / 1000;
|
*out++ = L24(&palette[in[x] * 4]) >> 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,7 +1022,7 @@ pa2l(UINT8 *out, const UINT8 *in, int xsize, const UINT8 *palette) {
|
||||||
int x;
|
int x;
|
||||||
/* FIXME: precalculate greyscale palette? */
|
/* FIXME: precalculate greyscale palette? */
|
||||||
for (x = 0; x < xsize; x++, in += 4) {
|
for (x = 0; x < xsize; x++, in += 4) {
|
||||||
*out++ = L(&palette[in[0] * 4]) / 1000;
|
*out++ = L24(&palette[in[0] * 4]) >> 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1044,7 +1044,7 @@ p2la(UINT8 *out, const UINT8 *in, int xsize, const UINT8 *palette) {
|
||||||
/* FIXME: precalculate greyscale palette? */
|
/* FIXME: precalculate greyscale palette? */
|
||||||
for (x = 0; x < xsize; x++, out += 4) {
|
for (x = 0; x < xsize; x++, out += 4) {
|
||||||
const UINT8 *rgba = &palette[*in++ * 4];
|
const UINT8 *rgba = &palette[*in++ * 4];
|
||||||
out[0] = out[1] = out[2] = L(rgba) / 1000;
|
out[0] = out[1] = out[2] = L24(rgba) >> 16;
|
||||||
out[3] = rgba[3];
|
out[3] = rgba[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1054,7 +1054,7 @@ pa2la(UINT8 *out, const UINT8 *in, int xsize, const UINT8 *palette) {
|
||||||
int x;
|
int x;
|
||||||
/* FIXME: precalculate greyscale palette? */
|
/* FIXME: precalculate greyscale palette? */
|
||||||
for (x = 0; x < xsize; x++, in += 4, out += 4) {
|
for (x = 0; x < xsize; x++, in += 4, out += 4) {
|
||||||
out[0] = out[1] = out[2] = L(&palette[in[0] * 4]) / 1000;
|
out[0] = out[1] = out[2] = L24(&palette[in[0] * 4]) >> 16;
|
||||||
out[3] = in[3];
|
out[3] = in[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1063,7 +1063,7 @@ static void
|
||||||
p2i(UINT8 *out_, const UINT8 *in, int xsize, const UINT8 *palette) {
|
p2i(UINT8 *out_, const UINT8 *in, int xsize, const UINT8 *palette) {
|
||||||
int x;
|
int x;
|
||||||
for (x = 0; x < xsize; x++, out_ += 4) {
|
for (x = 0; x < xsize; x++, out_ += 4) {
|
||||||
INT32 v = L(&palette[in[x] * 4]) / 1000;
|
INT32 v = L24(&palette[in[x] * 4]) >> 16;
|
||||||
memcpy(out_, &v, sizeof(v));
|
memcpy(out_, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1073,7 +1073,7 @@ pa2i(UINT8 *out_, const UINT8 *in, int xsize, const UINT8 *palette) {
|
||||||
int x;
|
int x;
|
||||||
INT32 *out = (INT32 *)out_;
|
INT32 *out = (INT32 *)out_;
|
||||||
for (x = 0; x < xsize; x++, in += 4) {
|
for (x = 0; x < xsize; x++, in += 4) {
|
||||||
*out++ = L(&palette[in[0] * 4]) / 1000;
|
*out++ = L24(&palette[in[0] * 4]) >> 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user