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

transform.solid_overlay #2304

Merged

Conversation

ScriptLineStudios
Copy link
Member

closes #1847

import pygame

dis = pygame.display.set_mode((600, 600))

img = pygame.image.load("transparent_walt.png")
img = pygame.transform.solid_overlay(img, (0, 0, 0))

while True:
    dis.fill((100, 100, 100))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            raise SystemExit

    dis.blit(img, (30, 30))
    pygame.display.update()

produces:

Screenshot from 2023-07-11 14-01-26

@ScriptLineStudios ScriptLineStudios requested a review from a team as a code owner July 11, 2023 12:04
@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 11, 2023
@oddbookworm

This comment was marked as resolved.

@oddbookworm

This comment was marked as resolved.

@ankith26
Copy link
Member

That isn't really this PRs fault, though it's something I plan to tackle in the near future

src_c/doc/transform_doc.h Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
@itzpr3d4t0r
Copy link
Member

As per @ScriptLineStudios on Discord I'll take over this PR.

@itzpr3d4t0r itzpr3d4t0r requested a review from MyreMylar April 4, 2024 18:06
@MyreMylar MyreMylar closed this May 23, 2024
@MyreMylar MyreMylar reopened this May 23, 2024
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, LGTM.

All works locally for me, I like the keep_alpha flag and I can think of lots of uses for this in games. Also everything is passing CI now and the docs make sense.

I'm not sure there is much scope for SIMD in this transform either as it is a per pixel branch rather than any mathematical operation on every pixel.

Happy to see this go in.

@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner June 2, 2024 09:12
Copy link
Member

@damusss damusss left a comment

Choose a reason for hiding this comment

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

I think the message I sent on discord got lost, so I'm typing it here instead.
Basically providing a string color such as "green" raises a TypeError: invalid search_color argument, which is not expected as the argument supports ColorValue, and the error is also referring to a non existent parameter search_color

On a side note, I'd like for this function to have some kind of alpha threshold parameter, but it's fine if it doesn't (the first time I tested my image had an alpha of 6 which I wasn't aware of, and I had to open an image editing program to bring it to 0 before trying again.)

Copy link
Member

@damusss damusss left a comment

Choose a reason for hiding this comment

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

the search_color in the error is still present but this is such a small nitpick that I'm approving anyways. I'm gonna let some SR or SC member merge it as this is new api. LGTM, and works locally.

@@ -20,6 +20,7 @@ def rotate(surface: Surface, angle: float) -> Surface: ...
def rotozoom(surface: Surface, angle: float, scale: float) -> Surface: ...
def scale2x(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ...
def grayscale(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ...
def solid_overlay(surface: Surface, color: ColorValue, dest_surface: Optional[Surface] = None, keep_alpha: bool = False) -> Surface: ...
Copy link
Member

Choose a reason for hiding this comment

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

This line is too long, maybe you could re-format this file with black/ruff?

Copy link
Member

Choose a reason for hiding this comment

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

This should be fixed now thanks.

}
}

SDL_UnlockSurface(newsurf);
Copy link
Member

Choose a reason for hiding this comment

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

Why is it an unmatched lock here?

Copy link
Member

Choose a reason for hiding this comment

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

This is the original sin lol, always been there so it became invisible to my eyes, should be fixed now.

src_c/transform.c Outdated Show resolved Hide resolved
Locking/Unlocking should now be more correct. Previously we supported any Bpp surfaces in the general path but realistically only 16 bit surfaces are left after the filtering we do before, hence the simplifications.
@damusss
Copy link
Member

damusss commented Oct 1, 2024

@itzpr3d4t0r after typing.py, ColorValue isn't available anymore. If you can you can update the branch and replace ColorValue with ColorLike from pygame.typing

@itzpr3d4t0r
Copy link
Member

@itzpr3d4t0r after typing.py, ColorValue isn't available anymore. If you can you can update the branch and replace ColorValue with ColorLike from pygame.typing

I'm not sure i can do it right atm. I've always committed from github because of commit permissions being broken in my ide for some reason... so I'm afraid someone else has to do it.

@MyreMylar MyreMylar merged commit d628234 into pygame-community:main Oct 5, 2024
25 checks passed
@bilhox bilhox added this to the 2.5.2 milestone Oct 5, 2024
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.solid_overlay()
9 participants