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 38 commits into
base: main
Choose a base branch
from

Conversation

damusss
Copy link
Member

@damusss damusss commented May 24, 2024

I implemented the bloom algorithm to add it to pygame.transform.
I also added documentation and stubs.

I think this is the best implementation. This is the steps, if someone needs them to review:

  • Create a bright pass filter surface
  • Iterate the source surface and keep only the pixels with the luminance within the threshold
  • Run either the box or blur algorithm
  • On the lines where the blurred color is applied, also blit it to the original surface with additive blend

Please tell me if there are any C improvements, structure improvements or performance improvements.

@damusss damusss requested a review from a team as a code owner May 24, 2024 20:41
@damusss damusss requested a review from a team as a code owner May 25, 2024 11:28
@itzpr3d4t0r itzpr3d4t0r added New API This pull request may need extra debate as it adds a new class or function to pygame transform pygame.transform labels May 26, 2024
@robertpfeiffer
Copy link
Contributor

I see no reason not to merge this, but I think this might be more flexible as three separate operations: Threshold, blur, and blit. At least, I think this could be more useful as a function that computes the bloom overlay with a black or transparent background.

@damusss
Copy link
Member Author

damusss commented May 27, 2024

I see no reason not to merge this, but I think this might be more flexible as three separate operations: Threshold, blur, and blit. At least, I think this could be more useful as a function that computes the bloom overlay with a black or transparent background.

Maybe it would be more flexible but not more performant as the blit is implemented within the blur using only 2 loops. I'd like for @itzpr3d4t0r to have a word about what you mentioned. I can always modify it as requested.

@damusss
Copy link
Member Author

damusss commented May 27, 2024

To add to what I just said, what i think would be best is to keep bloom as a function and maybe add the luminance filter as another function that can reuse the same code this pull request is using.

Co-authored-by: Dan Lawrence <[email protected]>
Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

I gave this the full walt test:

image

with this test program:

import pygame


display_surf = pygame.display.set_mode((1280, 600))
display_surf.fill((255, 255, 255))

walt = pygame.image.load("images/walt.png").convert_alpha()

walt_2 = pygame.transform.bloom(
    walt, blur_radius=2, intensity=1.5, luminance_threshold=0.6
)
walt_3 = pygame.transform.bloom(
    walt, blur_radius=15, intensity=4, luminance_threshold=0.4, blur_type="box"
)

pygame.init()

clock = pygame.time.Clock()

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    display_surf.fill((255, 255, 255))
    display_surf.blit(walt, (0, 100))
    display_surf.blit(walt_2, (417, 100))
    display_surf.blit(walt_3, (834, 100))

    pygame.display.flip()

    clock.tick(60)

I think it is a useful effect that developers will use. They'll probably use it, and all of the blurs more if we can eventually get them SIMD accelerated in some manner, but I have no problem adding this among them. Especially as it is reusing a lot of the code from the blurs.

My main criticism is that the input parameters are quite loosely defined right now in the documentation with no expected ranges, and not much description of what they effect in the output.

@damusss
Copy link
Member Author

damusss commented Oct 5, 2024

My main criticism is that the input parameters are quite loosely defined right now in the documentation with no expected ranges, and not much description of what they effect in the output.

you have a point. I'll improve the documentation and explain what each argument does

Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

Nice docs, LGTM 👍

@damusss damusss requested review from Starbuck5 and ankith26 June 5, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New API This pull request may need extra debate as it adds a new class or function to pygame transform pygame.transform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants