mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Allow LA to be used as a mask in paste()
This commit is contained in:
parent
e2b007f0c2
commit
7d3274518d
|
@ -67,6 +67,16 @@ class TestImagingPaste:
|
|||
],
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def gradient_LA(self):
|
||||
return Image.merge(
|
||||
"LA",
|
||||
[
|
||||
self.gradient_L,
|
||||
self.gradient_L.transpose(Image.Transpose.ROTATE_90),
|
||||
],
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def gradient_RGBA(self):
|
||||
return Image.merge(
|
||||
|
@ -145,6 +155,28 @@ class TestImagingPaste:
|
|||
],
|
||||
)
|
||||
|
||||
def test_image_mask_LA(self):
|
||||
for mode in ("RGBA", "RGB", "L"):
|
||||
im = Image.new(mode, (200, 200), "white")
|
||||
im2 = getattr(self, "gradient_" + mode)
|
||||
|
||||
self.assert_9points_paste(
|
||||
im,
|
||||
im2,
|
||||
self.gradient_LA,
|
||||
[
|
||||
(128, 191, 255, 191),
|
||||
(112, 207, 206, 111),
|
||||
(128, 254, 128, 1),
|
||||
(208, 208, 239, 239),
|
||||
(192, 191, 191, 191),
|
||||
(207, 207, 112, 113),
|
||||
(255, 255, 255, 255),
|
||||
(239, 207, 207, 239),
|
||||
(255, 191, 128, 191),
|
||||
],
|
||||
)
|
||||
|
||||
def test_image_mask_RGBA(self):
|
||||
for mode in ("RGBA", "RGB", "L"):
|
||||
im = Image.new(mode, (200, 200), "white")
|
||||
|
|
|
@ -385,7 +385,7 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
|
||||
self.im = self._prev_im
|
||||
self.mode = self.im.mode
|
||||
if frame_im.mode == "RGBA":
|
||||
if frame_im.mode in ("LA", "RGBA"):
|
||||
self.im.paste(frame_im, self.dispose_extent, frame_im)
|
||||
else:
|
||||
self.im.paste(frame_im, self.dispose_extent)
|
||||
|
|
|
@ -1566,8 +1566,8 @@ class Image:
|
|||
also use color strings as supported by the ImageColor module.
|
||||
|
||||
If a mask is given, this method updates only the regions
|
||||
indicated by the mask. You can use either "1", "L" or "RGBA"
|
||||
images (in the latter case, the alpha band is used as mask).
|
||||
indicated by the mask. You can use either "1", "L", "LA", "RGBA"
|
||||
or "RGBa" images (if present, the alpha band is used as mask).
|
||||
Where the mask is 255, the given image is copied as is. Where
|
||||
the mask is 0, the current value is preserved. Intermediate
|
||||
values will mix the two images together, including their alpha
|
||||
|
@ -1615,7 +1615,7 @@ class Image:
|
|||
elif isImageType(im):
|
||||
im.load()
|
||||
if self.mode != im.mode:
|
||||
if self.mode != "RGB" or im.mode not in ("RGBA", "RGBa"):
|
||||
if self.mode != "RGB" or im.mode not in ("LA", "RGBA", "RGBa"):
|
||||
# should use an adapter for this!
|
||||
im = im.convert(self.mode)
|
||||
im = im.im
|
||||
|
|
|
@ -295,7 +295,7 @@ ImagingPaste(
|
|||
paste_mask_L(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
|
||||
ImagingSectionLeave(&cookie);
|
||||
|
||||
} else if (strcmp(imMask->mode, "RGBA") == 0) {
|
||||
} else if (strcmp(imMask->mode, "LA") == 0 || strcmp(imMask->mode, "RGBA") == 0) {
|
||||
ImagingSectionEnter(&cookie);
|
||||
paste_mask_RGBA(
|
||||
imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
|
||||
|
|
Loading…
Reference in New Issue
Block a user