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 all 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
8 changes: 8 additions & 0 deletions buildconfig/stubs/pygame/transform.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def gaussian_blur(
repeat_edge_pixels: bool = True,
dest_surface: Optional[Surface] = None
) -> Surface: ...
def bloom(
surface: Surface,
blur_radius: int,
intensity: float,
luminance_threshold: float = 0.5,
blur_type: Literal["gaussian", "box"] = "gaussian",
dest_surface: Optional[Surface] = None
) -> Surface: ...
def hsl(
surface: Surface,
hue: float = 0,
Expand Down
36 changes: 36 additions & 0 deletions docs/reST/ref/transform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,42 @@ 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, blur_radius, intensity, luminance_threshold=0.5, blur_type='gaussian', dest_surface=None) -> Surface`

Returns a surface where the bright pixels are blurred and added to the original
surface resulting in a bloom effect. The alpha of the pixels is preserved.

:param Surface surface: The input surface. Does not work for indexed surfaces
and for surfaces with less than 24 bits. A ``ValueError`` will be throw in that case.

:param int blur_radius: The radius (in pixels) that the selected blur will use.
Cannot be less than ``0`` and a value of ``0`` won't modify the surface.

:param float intensity: Acts as a brightness multiplier for the luminance filter.
Values less or equal to zero won't modify the surface. Values greater or equal
to ``255`` will produce the same result, making the bright parts completely white.

:param float luminance_threshold: Luminance is a property of each pixel in the range 0-1
(regardless of alpha). The luminance threshold selects the minimum luminance
required for a pixel to be considered bright. A value of ``0`` will allow every
pixel while a value of ``1`` will discard every pixel and won't modify the surface.

:param str blur_type: Specifies the blur to use. Allowed values are ``"box"`` and ``"gaussian"``.

:param Surface dest_surface: An optional destination surface 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.

.. note:: A higher blur radius will be smoother but will be slower. The default
gaussian blur will be more precise but box blur is many times faster, which
is preferred for real-time effects. Using real-time bloom on very big surfaces
is generally not advised, caching is preferred.

.. versionadded:: 2.5.2

.. 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, blur_radius, intensity, luminance_threshold=0.5, blur_type='gaussian', 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) -> tuple\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