pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Possibly unreachable blit code

Open itzpr3d4t0r opened this issue 11 months ago • 1 comments
trafficstars

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 avatar Dec 01 '24 11:12 itzpr3d4t0r