Skip to content

Commit 60cfddf

Browse files
authored
Blur with zero size surface won't raise a ValueError
1 parent 3822a18 commit 60cfddf

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

docs/reST/ref/transform.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ Instead, always begin with the original image and scale to the desired size.)
245245
.. versionchanged:: 2.3.0
246246
Passing the calling surface as destination surface raises a ``ValueError``
247247

248+
.. versionchanged:: 2.5.0
249+
A surface with either width or height equal to 0 won't raise a ``ValueError``
250+
248251
.. ## pygame.transform.box_blur ##
249252
250253
.. function:: gaussian_blur
@@ -271,6 +274,9 @@ Instead, always begin with the original image and scale to the desired size.)
271274
Now the standard deviation of the Gaussian kernel is equal to the radius.
272275
Blur results will be slightly different.
273276

277+
.. versionchanged:: 2.5.0
278+
A surface with either width or height equal to 0 won't raise a ``ValueError``
279+
274280
.. ## pygame.transform.gaussian_blur ##
275281
276282
.. function:: average_surfaces

src_c/transform.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,10 @@ blur(pgSurfaceObject *srcobj, pgSurfaceObject *dstobj, int radius,
32663266
retsurf = pgSurface_AsSurface(dstobj);
32673267
}
32683268

3269+
if (retsurf->w == 0 || retsurf->h == 0) {
3270+
return retsurf;
3271+
}
3272+
32693273
Uint8 *ret_start = retsurf->pixels;
32703274
Uint8 *ret_end = ret_start + retsurf->h * retsurf->pitch;
32713275
Uint8 *src_start = src->pixels;

test/transform_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,19 @@ def test_gaussian_blur(self):
16001600
for pos in data2:
16011601
self.assertTrue(sf_b2.get_at(pos) == data2[pos])
16021602

1603+
def test_blur_zero_size_surface(self):
1604+
surface = pygame.Surface((0, 0))
1605+
self.assertEqual(pygame.transform.box_blur(surface).get_size(), (0, 0))
1606+
self.assertEqual(pygame.transform.gaussian_blur(surface).get_size(), (0, 0))
1607+
1608+
surface = pygame.Surface((20, 0))
1609+
self.assertEqual(pygame.transform.box_blur(surface).get_size(), (20, 0))
1610+
self.assertEqual(pygame.transform.gaussian_blur(surface).get_size(), (20, 0))
1611+
1612+
surface = pygame.Surface((0, 20))
1613+
self.assertEqual(pygame.transform.box_blur(surface).get_size(), (0, 20))
1614+
self.assertEqual(pygame.transform.gaussian_blur(surface).get_size(), (0, 20))
1615+
16031616
def test_flip(self):
16041617
"""honors the set_color key on the returned surface from flip."""
16051618
image_loaded = pygame.image.load(example_path("data/chimp.png"))

0 commit comments

Comments
 (0)