Skip to content

Commit 80f474c

Browse files
authored
Merge pull request #2026 from yunline/transform.blur-8b
Raise `ValueError` when bluring an indexed surface.
2 parents 2d82a34 + 6f8c7e3 commit 80f474c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

docs/reST/ref/transform.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ Instead, always begin with the original image and scale to the desired size.)
211211
212212
Returns the blurred surface using box blur algorithm.
213213

214+
This function does not work for indexed surfaces.
215+
An exception will be thrown if the input is an indexed surface.
216+
214217
.. versionadded:: 2.2.0
215218

216219
.. ## pygame.transform.box_blur ##
@@ -223,6 +226,9 @@ Instead, always begin with the original image and scale to the desired size.)
223226
Returns the blurred surface using gaussian blur algorithm.
224227
Slower than `box_blur()`.
225228

229+
This function does not work for indexed surfaces.
230+
An exception will be thrown if the input is an indexed surface.
231+
226232
.. versionadded:: 2.2.0
227233

228234
.. ## pygame.transform.gaussian_blur ##

src_c/transform.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,10 @@ blur(pgSurfaceObject *srcobj, pgSurfaceObject *dstobj, int radius,
32423242

32433243
src = pgSurface_AsSurface(srcobj);
32443244

3245+
if (src->format->palette) {
3246+
return RAISE(PyExc_ValueError, "Indexed surfaces connot be blurred.");
3247+
}
3248+
32453249
if (!dstobj) {
32463250
retsurf = newsurf_fromsurf(src, src->w, src->h);
32473251
if (!retsurf)

test/transform_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,14 @@ def setUp(self):
14061406
def tearDown(self):
14071407
pygame.display.quit()
14081408

1409+
def test_blur_indexed_surface(self):
1410+
data_fname = example_path("data")
1411+
path = os.path.join(data_fname, "alien3.png")
1412+
sf = pygame.image.load(path) # Get an indexed surface.
1413+
1414+
self.assertRaises(ValueError, lambda: pygame.transform.box_blur(sf, 10))
1415+
self.assertRaises(ValueError, lambda: pygame.transform.gaussian_blur(sf, 10))
1416+
14091417
def test_box_blur(self):
14101418
data1 = {
14111419
(1, 29): (67, 58, 26, 255),

0 commit comments

Comments
 (0)