Fixed effect_spread bug for zero distance

This commit is contained in:
Andrew Murray 2020-09-08 18:51:58 +10:00
parent 9e6dabf0e5
commit c83ffc6aea
2 changed files with 21 additions and 6 deletions

View File

@ -454,6 +454,17 @@ class TestImage:
with Image.open("Tests/images/effect_spread.png") as im3:
assert_image_similar(im2, im3, 110)
def test_effect_spread_zero(self):
# Arrange
im = hopper()
distance = 0
# Act
im2 = im.effect_spread(distance)
# Assert
assert_image_equal(im, im2)
def test_check_size(self):
# Checking that the _check_size function throws value errors when we want it to
with pytest.raises(ValueError):

View File

@ -133,6 +133,9 @@ ImagingEffectSpread(Imaging imIn, int distance)
#define SPREAD(type, image)\
for (y = 0; y < imOut->ysize; y++) {\
for (x = 0; x < imOut->xsize; x++) {\
if (distance == 0) {\
imOut->image[y][x] = imIn->image[y][x];\
} else {\
int xx = x + (rand() % distance) - distance/2;\
int yy = y + (rand() % distance) - distance/2;\
if (xx >= 0 && xx < imIn->xsize && yy >= 0 && yy < imIn->ysize) {\
@ -142,6 +145,7 @@ ImagingEffectSpread(Imaging imIn, int distance)
imOut->image[y][x] = imIn->image[y][x];\
}\
}\
}\
}
if (imIn->image8) {