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

Possibly unreachable blit code #3247

Open
itzpr3d4t0r opened this issue Dec 1, 2024 · 1 comment
Open

Possibly unreachable blit code #3247

itzpr3d4t0r opened this issue Dec 1, 2024 · 1 comment
Labels
bug Not working as intended Surface pygame.Surface

Comments

@itzpr3d4t0r
Copy link
Member

itzpr3d4t0r commented Dec 1, 2024

Alongside the many blitters in Pygame, we have a function called alphablit_colorkey:

alphablit_colorkey implementation.

It seems this blitter should be used with a surface that has both an alpha channel and a colorkey set. However, it doesn't appear to work as expected.

Here’s a minimal example where it should work:

import pygame

pygame.init()


screen = pygame.display.set_mode((800, 600))

surf = pygame.Surface((100, 100), flags=pygame.SRCALPHA)
print(surf.get_flags(), surf)
surf.fill((255, 0, 0, 128))
surf.set_colorkey((255, 0, 0, 255))
print(surf.get_flags(), surf)


screen.blit(surf, (100, 100))

I added print statements in alphablit_colorkey and the fallback SDL blitter to debug this. Here's the output:

65536 <Surface(100x100x32, global_alpha=255)>
69632 <Surface(100x100x32, colorkey=(255, 0, 0, 255), global_alpha=255)>
SDL_BlitSurface

From the output, it seems the default SDL blitter is used instead of alphablit_colorkey.

Is this a bug, or am I missing a condition that triggers alphablit_colorkey?

@itzpr3d4t0r itzpr3d4t0r added bug Not working as intended Surface pygame.Surface labels Dec 1, 2024
@damusss
Copy link
Member

damusss commented Dec 1, 2024

From what I can understand reading the code, that c function is only called when either the surface has no blend mode or when it has no alpha channel. this is my understanding of:

 if (info.src_blend != SDL_BLENDMODE_NONE &&
                        src->format->Amask) {
				...
				} else if (info.src_has_colorkey) {
						alphablit_colorkey(&info);

which isn't exactly what you said, so perhaps I read it wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended Surface pygame.Surface
Projects
None yet
Development

No branches or pull requests

2 participants