Skip to content
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

pygame.transform.pixelate #2354

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

oddbookworm
Copy link
Member

@oddbookworm oddbookworm commented Jul 27, 2023

Addressing #2302

TODO:

  • tests

@oddbookworm oddbookworm requested a review from a team as a code owner July 27, 2023 03:47
@oddbookworm oddbookworm linked an issue Jul 27, 2023 that may be closed by this pull request
@yunline yunline added New API This pull request may need extra debate as it adds a new class or function to pygame transform pygame.transform labels Jul 27, 2023
Copy link
Member

@novialriptide novialriptide left a comment

Choose a reason for hiding this comment

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

Works great.

Before & After

Code

import pygame

screen = pygame.display.set_mode((500, 500))
creeper = pygame.image.load("creeper.jpg")
creeper = pygame.transform.scale_by(creeper, 0.5)
creeper = pygame.transform.pixelate(creeper, 50)

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

    screen.fill((0, 0, 0))
    screen.blit(creeper, (0, 0))
    pygame.display.update()
original screenshot

creeper

src_c/transform.c Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
@Starbuck5
Copy link
Member

Starbuck5 commented Oct 15, 2023

Could this effect be replicated with a smoothscale down and a scale up? It could even do that in C code, and it might be faster because those are SIMD optimized?

Initial testing is promising that it replicates the effect, I didn't test performance.

@MyreMylar
Copy link
Member

Could this effect be replicated with a smoothscale down and a scale up? It could even do that in C code, and it might be faster because those are SIMD optimized?

Initial testing is promising that it replicates the effect, I didn't test performance.

Shouldn't even need smoothscale for this, a bit of math with pixel_size versus the smallest dimension of the original image then two calls to SDL_SoftStretch should probably do it I'd have thought? Unless smoothscale is now faster than SDL_SoftStretch after recent SIMD-ifying?

Would probably be worth a look at least to see if it is faster than this current method.

@Starbuck5 Starbuck5 marked this pull request as draft November 19, 2023 10:28
@Starbuck5
Copy link
Member

I've converted this to a draft due to large open questions about how the implementation should work.

@oddbookworm
Copy link
Member Author

I'll revive this soon, I promise

@oddbookworm oddbookworm marked this pull request as ready for review December 18, 2023 04:12
@MyreMylar MyreMylar requested a review from a team as a code owner June 2, 2024 10:52
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.

OK, all looks great to me now. I gave it the full walt.png test:

image

And it performed as expected. Tests and docs make sense and I like the reuse of existing scaling functions. All in all this is neat! 👍

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.

pygame.transform.pixelate
5 participants