mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 16:22:22 +03:00
Merge 7ec13fedc7
into 329d6a6a62
This commit is contained in:
commit
69484bbe59
|
@ -388,6 +388,37 @@ class TestImage:
|
||||||
assert img_colors is not None
|
assert img_colors is not None
|
||||||
assert sorted(img_colors) == expected_colors
|
assert sorted(img_colors) == expected_colors
|
||||||
|
|
||||||
|
def test_alpha_composite_la(self) -> None:
|
||||||
|
# Arrange
|
||||||
|
expected_colors = sorted(
|
||||||
|
[
|
||||||
|
(3300, (255, 255)),
|
||||||
|
(1156, (170, 192)),
|
||||||
|
(1122, (128, 255)),
|
||||||
|
(1089, (0, 0)),
|
||||||
|
(1122, (255, 128)),
|
||||||
|
(1122, (0, 128)),
|
||||||
|
(1089, (0, 255)),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
dst = Image.new("LA", size=(100, 100), color=(0, 255))
|
||||||
|
draw = ImageDraw.Draw(dst)
|
||||||
|
draw.rectangle((0, 33, 100, 66), fill=(0, 128))
|
||||||
|
draw.rectangle((0, 67, 100, 100), fill=(0, 0))
|
||||||
|
src = Image.new("LA", size=(100, 100), color=(255, 255))
|
||||||
|
draw = ImageDraw.Draw(src)
|
||||||
|
draw.rectangle((33, 0, 66, 100), fill=(255, 128))
|
||||||
|
draw.rectangle((67, 0, 100, 100), fill=(255, 0))
|
||||||
|
|
||||||
|
# Act
|
||||||
|
img = Image.alpha_composite(dst, src)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
img_colors = img.getcolors()
|
||||||
|
assert img_colors is not None
|
||||||
|
assert sorted(img_colors) == expected_colors
|
||||||
|
|
||||||
def test_alpha_inplace(self) -> None:
|
def test_alpha_inplace(self) -> None:
|
||||||
src = Image.new("RGBA", (128, 128), "blue")
|
src = Image.new("RGBA", (128, 128), "blue")
|
||||||
|
|
||||||
|
|
|
@ -3566,9 +3566,8 @@ def alpha_composite(im1: Image, im2: Image) -> Image:
|
||||||
"""
|
"""
|
||||||
Alpha composite im2 over im1.
|
Alpha composite im2 over im1.
|
||||||
|
|
||||||
:param im1: The first image. Must have mode RGBA.
|
:param im1: The first image. Must have mode RGBA or LA.
|
||||||
:param im2: The second image. Must have mode RGBA, and the same size as
|
:param im2: The second image. Must have the same mode and size as the first image.
|
||||||
the first image.
|
|
||||||
:returns: An :py:class:`~PIL.Image.Image` object.
|
:returns: An :py:class:`~PIL.Image.Image` object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,12 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
/* Check arguments */
|
/* Check arguments */
|
||||||
if (!imDst || !imSrc || strcmp(imDst->mode, "RGBA") ||
|
if (!imDst || !imSrc ||
|
||||||
imDst->type != IMAGING_TYPE_UINT8 || imDst->bands != 4) {
|
(strcmp(imDst->mode, "RGBA") && strcmp(imDst->mode, "LA"))) {
|
||||||
return ImagingError_ModeError();
|
return ImagingError_ModeError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(imDst->mode, imSrc->mode) || imDst->type != imSrc->type ||
|
if (strcmp(imDst->mode, imSrc->mode) || imDst->xsize != imSrc->xsize ||
|
||||||
imDst->bands != imSrc->bands || imDst->xsize != imSrc->xsize ||
|
|
||||||
imDst->ysize != imSrc->ysize) {
|
imDst->ysize != imSrc->ysize) {
|
||||||
return ImagingError_Mismatch();
|
return ImagingError_Mismatch();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user