Skip to content

Add pygame.transform.bloom function #2872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fc76910
Add new API
damusss May 24, 2024
27041bc
Rename int to char
damusss May 24, 2024
20c91e4
Remove unused variable
damusss May 24, 2024
287843f
Remove another unused variable
damusss May 24, 2024
1119a28
Set default blur type to box
damusss May 24, 2024
0e17e93
Remove smooth argument, fix memory leak, address formatting
damusss May 25, 2024
df4b90b
Remove cast
damusss May 25, 2024
4bbe3ce
Fix format and docs
damusss May 25, 2024
2241c7c
Disallow 16 bit surfaces
damusss May 25, 2024
d03e500
Update docs
damusss May 25, 2024
014b629
Setup macro system for blur
damusss May 25, 2024
792f74b
Fix and fasten bright pass filtering
damusss May 25, 2024
f38cd45
Performance/code improvement
damusss May 25, 2024
e6035b5
Another improvement
damusss May 25, 2024
a74d6c3
Small fix
damusss May 25, 2024
5f922ae
Use a pixels-like buffer
damusss May 25, 2024
f6f2c24
Revert buffer, update docs, update arguments, add test
damusss May 26, 2024
9d4d911
Generate docs
damusss May 26, 2024
8d57023
Fix test
damusss May 26, 2024
c3f87ec
Add another test
damusss May 27, 2024
7064f30
Add comment
damusss May 27, 2024
cd20518
Merge branch 'main' into transform-bloom
damusss Jun 9, 2024
dd0ea3a
Fix stubs
damusss Jun 9, 2024
347e352
Update bytes per pixel with macro
damusss Jun 12, 2024
a875eda
docs
damusss Aug 3, 2024
6019631
Merge branch 'pygame-community:main' into transform-bloom
damusss Aug 3, 2024
937f7fc
Merge branch 'main' into transform-bloom
MyreMylar Oct 5, 2024
e0a5cba
fix documentation formatting
MyreMylar Oct 5, 2024
402f775
Update versionadded
damusss Oct 5, 2024
de35cc4
Explain parameters in docs
damusss Oct 6, 2024
f42aea1
Fix docs indenting
damusss Oct 6, 2024
0cf0a5f
Make it an actual parameter list
damusss Oct 6, 2024
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
10 changes: 9 additions & 1 deletion buildconfig/stubs/pygame/transform.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Union
from typing import Optional, Union, Literal

from pygame.color import Color
from pygame.surface import Surface
Expand Down Expand Up @@ -65,3 +65,11 @@ def gaussian_blur(
repeat_edge_pixels: bool = True,
dest_surface: Optional[Surface] = None
) -> Surface: ...
def bloom(
surface: Surface,
intensity: float = 1.0,
luminance_threshold: float = 0.5,
blur_radius: int = 5,
blur_type: Literal["gaussian", "box"] = "box",
dest_surface: Optional[Surface] = None
) -> Surface: ...
21 changes: 21 additions & 0 deletions docs/reST/ref/transform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,27 @@ Instead, always begin with the original image and scale to the desired size.)

.. ## pygame.transform.gaussian_blur ##

.. function:: bloom

| :sl:`apply the bloom effect to a surface`
| :sg:`bloom(surface, intensity=1, luminance_threshold=0.5, blur_radius=5, blur_type='box', dest_surface=None) -> Surface`

Returns a surface where the bright pixels are blurred and added to the original
surface resulting in a bloom effect.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this section I think some details on the expected parameter ranges would be useful, particularly on the valid values for blur_type, which I believe are gaussian and box. Without some guidance it is hard to know if values like 'intensity` should normally be in the range of 0-1000, or 0.0 to1.0.


This function does not work for indexed surfaces and for surfaces with less than
24 bits. An exception will be thrown if the input is an indexed surface or if it
has less than 24 bits.

An optional destination surface can be passed which is faster than creating a new
Surface. This destination surface must have the same dimensions (width, height) and
depth and format as the source Surface.

Using box blur will be faster than gaussian blur. A higher blur radius will be
smoother but will be slower.

.. versionadded:: 2.5.0

.. function:: average_surfaces

| :sl:`find the average surface from many surfaces.`
Expand Down
1 change: 1 addition & 0 deletions src_c/doc/transform_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define DOC_TRANSFORM_LAPLACIAN "laplacian(surface, dest_surface=None) -> Surface\nfind edges in a surface"
#define DOC_TRANSFORM_BOXBLUR "box_blur(surface, radius, repeat_edge_pixels=True, dest_surface=None) -> Surface\nblur a surface using box blur"
#define DOC_TRANSFORM_GAUSSIANBLUR "gaussian_blur(surface, radius, repeat_edge_pixels=True, dest_surface=None) -> Surface\nblur a surface using gaussian blur"
#define DOC_TRANSFORM_BLOOM "bloom(surface, intensity=1, luminance_threshold=0.5, blur_radius=5, blur_type='box', dest_surface=None) -> Surface\napply the bloom effect to a surface"
#define DOC_TRANSFORM_AVERAGESURFACES "average_surfaces(surfaces, dest_surface=None, palette_colors=1) -> Surface\nfind the average surface from many surfaces."
#define DOC_TRANSFORM_AVERAGECOLOR "average_color(surface, rect=None, consider_alpha=False) -> Color\nfinds the average color of a surface"
#define DOC_TRANSFORM_INVERT "invert(surface, dest_surface=None) -> Surface\ninverts the RGB elements of a surface"
Expand Down
Loading
Loading