Support conversion from RGB to La

This commit is contained in:
Andrew Murray 2024-03-26 19:57:17 +11:00
parent ab8f465f1a
commit e79d1746f2
3 changed files with 11 additions and 3 deletions

View File

@ -187,6 +187,10 @@ def test_trns_RGB(tmp_path: Path) -> None:
assert "transparency" not in im_la.info
im_la.save(f)
im_la = im.convert("La")
assert "transparency" not in im_la.info
assert im_la.getpixel((0, 0)) == (0, 0)
im_p = im.convert("P")
assert "transparency" in im_p.info
im_p.save(f)

View File

@ -979,7 +979,7 @@ class Image:
# transparency handling
if has_transparency:
if (self.mode in ("1", "L", "I", "I;16") and mode in ("LA", "RGBA")) or (
self.mode == "RGB" and mode in ("LA", "RGBa", "RGBA")
self.mode == "RGB" and mode in ("La", "LA", "RGBa", "RGBA")
):
# Use transparent conversion to promote from transparent
# color to an alpha channel.

View File

@ -501,7 +501,7 @@ rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) {
/*
* Conversion of RGB + single transparent color either to
* RGBA or LA, where any pixel matching the color will have the alpha channel set to 0, or
* RGBa, where any pixel matching the color will have all channels set to 0
* RGBa or La, where any pixel matching the color will have all channels set to 0
*/
static void
@ -942,6 +942,7 @@ static struct {
{"RGB", "1", rgb2bit},
{"RGB", "L", rgb2l},
{"RGB", "LA", rgb2la},
{"RGB", "La", rgb2la},
{"RGB", "I", rgb2i},
{"RGB", "F", rgb2f},
{"RGB", "BGR;15", rgb2bgr15},
@ -1698,9 +1699,12 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
if (strcmp(mode, "RGBa") == 0) {
premultiplied = 1;
}
} else if (strcmp(imIn->mode, "RGB") == 0 && strcmp(mode, "LA") == 0) {
} else if (strcmp(imIn->mode, "RGB") == 0 && (strcmp(mode, "LA") == 0 || strcmp(mode, "La") == 0)) {
convert = rgb2la;
source_transparency = 1;
if (strcmp(mode, "La") == 0) {
premultiplied = 1;
}
} else if ((strcmp(imIn->mode, "1") == 0 ||
strcmp(imIn->mode, "I") == 0 ||
strcmp(imIn->mode, "I;16") == 0 ||