Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Tests/test_imagechops.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def test_sanity(self):
ImageChops.blend(im, im, 0.5)
ImageChops.composite(im, im, im)

ImageChops.softlight(im, im)
ImageChops.hardlight(im, im)
ImageChops.soft_light(im, im)
ImageChops.hard_light(im, im)
ImageChops.overlay(im, im)

ImageChops.offset(im, 10)
Expand Down Expand Up @@ -345,25 +345,25 @@ def test_subtract_modulo_no_clip(self):
# Assert
self.assertEqual(new.getpixel((50, 50)), (241, 167, 127))

def test_softlight(self):
def test_soft_light(self):
# Arrange
im1 = Image.open("Tests/images/hopper.png")
im2 = Image.open("Tests/images/hopper-XYZ.png")

# Act
new = ImageChops.softlight(im1, im2)
new = ImageChops.soft_light(im1, im2)

# Assert
self.assertEqual(new.getpixel((64, 64)), (163, 54, 32))
self.assertEqual(new.getpixel((15, 100)), (1, 1, 3))

def test_hardlight(self):
def test_hard_light(self):
# Arrange
im1 = Image.open("Tests/images/hopper.png")
im2 = Image.open("Tests/images/hopper-XYZ.png")

# Act
new = ImageChops.hardlight(im1, im2)
new = ImageChops.hard_light(im1, im2)

# Assert
self.assertEqual(new.getpixel((64, 64)), (144, 50, 27))
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImageChops.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def screen(image1, image2):
return image1._new(image1.im.chop_screen(image2.im))


def softlight(image1, image2):
def soft_light(image1, image2):
"""
Superimposes two images on top of each other using the Soft Light algorithm

Expand All @@ -151,7 +151,7 @@ def softlight(image1, image2):
return image1._new(image1.im.chop_softlight(image2.im))


def hardlight(image1, image2):
def hard_light(image1, image2):
"""
Superimposes two images on top of each other using the Hard Light algorithm

Expand Down
20 changes: 9 additions & 11 deletions src/libImaging/Chops.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,25 @@ 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);
}
}