mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
add hardlight and softlight chops
This commit is contained in:
parent
319f5409fe
commit
705140cc2c
|
@ -363,7 +363,7 @@ def test_subtract_modulo_no_clip():
|
|||
new = ImageChops.subtract_modulo(im1, im2)
|
||||
|
||||
# Assert
|
||||
assert new.getpixel((50, 50)) == (241, 167, 127)
|
||||
self.assertEqual(new.getpixel((50, 50)), (241, 167, 127))
|
||||
|
||||
|
||||
def test_softlight(self):
|
||||
|
@ -392,19 +392,6 @@ def test_hardlight(self):
|
|||
self.assertEqual(new.getpixel((15, 100)), (1, 1, 2))
|
||||
|
||||
|
||||
def test_overlay(self):
|
||||
# Arrange
|
||||
im1 = Image.open("Tests/images/hopper.png")
|
||||
im2 = Image.open("Tests/images/hopper-XYZ.png")
|
||||
|
||||
# Act
|
||||
new = ImageChops.overlay(im1, im2)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(new.getpixel((64, 64)), (159, 50, 27))
|
||||
self.assertEqual(new.getpixel((15, 100)), (1, 1, 2))
|
||||
|
||||
|
||||
def test_logical():
|
||||
def table(op, a, b):
|
||||
out = []
|
||||
|
|
|
@ -138,6 +138,27 @@ def screen(image1, image2):
|
|||
image2.load()
|
||||
return image1._new(image1.im.chop_screen(image2.im))
|
||||
|
||||
def softlight(image1, image2):
|
||||
"""
|
||||
Superimposes two images on top of each other using the Soft Light algorithm
|
||||
|
||||
:rtype: :py:class:`~PIL.Image.Image`
|
||||
"""
|
||||
|
||||
image1.load()
|
||||
image2.load()
|
||||
return image1._new(image1.im.chop_softlight(image2.im))
|
||||
|
||||
def hardlight(image1, image2):
|
||||
"""
|
||||
Superimposes two images on top of each other using the Hard Light algorithm
|
||||
|
||||
:rtype: :py:class:`~PIL.Image.Image`
|
||||
"""
|
||||
|
||||
image1.load()
|
||||
image2.load()
|
||||
return image1._new(image1.im.chop_hardlight(image2.im))
|
||||
|
||||
def softlight(image1, image2):
|
||||
"""
|
||||
|
|
|
@ -148,27 +148,27 @@ ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2)
|
|||
}
|
||||
|
||||
Imaging
|
||||
ImagingChopSoftLight(Imaging imIn1, Imaging imIn2)
|
||||
ImagingChopSoftLight(Imaging imIn1, Imaging imIn2)
|
||||
{
|
||||
// CHOP2( ( ( (255-in1[x]) * (in1[x]*in2[x]) ) / 65536) +
|
||||
// ((in1[x] * (255 - ((255 - in1[1]) * (255 - in2[x]) / 255 ) )) / 255), NULL );
|
||||
CHOP2( (((255-in1[x]) * (in1[x]*in2[x]) ) / 65536) +
|
||||
CHOP2( (((255-in1[x]) * (in1[x]*in2[x]) ) / 65536) +
|
||||
(in1[x] * ( 255 - ( (255 - in1[x]) * (255 - in2[x] ) / 255) )) / 255
|
||||
, NULL );
|
||||
}
|
||||
|
||||
Imaging
|
||||
ImagingChopHardLight(Imaging imIn1, Imaging imIn2)
|
||||
ImagingChopHardLight(Imaging imIn1, Imaging imIn2)
|
||||
{
|
||||
CHOP2( (in2[x]<128) ? ( (in1[x]*in2[x])/127)
|
||||
: 255 - ( ((255-in2[x]) * (255-in1[x])) / 127)
|
||||
CHOP2( (in2[x]<128) ? ( (in1[x]*in2[x])/127)
|
||||
: 255 - ( ((255-in2[x]) * (255-in1[x])) / 127)
|
||||
, NULL);
|
||||
}
|
||||
|
||||
Imaging
|
||||
ImagingOverlay(Imaging imIn1, Imaging imIn2)
|
||||
ImagingOverlay(Imaging imIn1, Imaging imIn2)
|
||||
{
|
||||
CHOP2( (in1[x]<128) ? ( (in1[x]*in2[x])/127)
|
||||
: 255 - ( ((255-in1[x]) * (255-in2[x])) / 127)
|
||||
CHOP2( (in1[x]<128) ? ( (in1[x]*in2[x])/127)
|
||||
: 255 - ( ((255-in1[x]) * (255-in2[x])) / 127)
|
||||
, NULL);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user