Skip to content

Commit

Permalink
Merge pull request #4908 from radarhere/effect_spread
Browse files Browse the repository at this point in the history
Fixed effect_spread bug for zero distance
  • Loading branch information
radarhere authored Sep 9, 2020
2 parents 9e6dabf + 272f519 commit 6a630fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
11 changes: 11 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ def test_effect_spread(self):
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):
Expand Down
26 changes: 17 additions & 9 deletions src/libImaging/Effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,23 @@ ImagingEffectSpread(Imaging imIn, int distance)
}

#define SPREAD(type, image)\
for (y = 0; y < imOut->ysize; y++) {\
for (x = 0; x < imOut->xsize; x++) {\
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) {\
imOut->image[yy][xx] = imIn->image[y][x];\
imOut->image[y][x] = imIn->image[yy][xx];\
} else {\
imOut->image[y][x] = imIn->image[y][x];\
if (distance == 0) {\
for (y = 0; y < imOut->ysize; y++) {\
for (x = 0; x < imOut->xsize; x++) {\
imOut->image[y][x] = imIn->image[y][x];\
}\
}\
} else {\
for (y = 0; y < imOut->ysize; y++) {\
for (x = 0; x < imOut->xsize; x++) {\
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) {\
imOut->image[yy][xx] = imIn->image[y][x];\
imOut->image[y][x] = imIn->image[yy][xx];\
} else {\
imOut->image[y][x] = imIn->image[y][x];\
}\
}\
}\
}
Expand Down

0 comments on commit 6a630fd

Please sign in to comment.