pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
766 stars 120 forks source link

``pygame.transform.hsl`` only working when loading an image and converting it with ``convert`` #2947

Closed bilhox closed 1 week ago

bilhox commented 1 week ago

Environment:

pygame-ce 2.5.0 (SDL 2.30.3, Python 3.12.0)
Platform:               Windows-11-10.0.22631-SP0
System:                 Windows
System Version:         10.0.22631
Processor:              AMD64 Family 23 Model 104 Stepping 1, AuthenticAMD
Architecture:           Bits: 64bit     Linkage: WindowsPE

Python:                 CPython 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
pygame version:         2.5.0
SDL versions:           Linked: 2.30.3  Compiled: 2.30.3
SDL Mixer versions:     Linked: 2.8.0   Compiled: 2.8.0
SDL Font versions:      Linked: 2.22.0  Compiled: 2.22.0
SDL Image versions:     Linked: 2.8.2   Compiled: 2.8.2
Freetype versions:      Linked: 2.11.1  Compiled: 2.11.1

Display Driver:         windows
Mixer Driver:           Mixer Not Initialized

Current behavior:

We get a black surface when we try to use pygame.transform.hsl on an image loaded with pygame.image.load. Without converting it it's still black, and when converting it with convert_alpha it's still not working. However, it works when using convert.

Expected behavior:

It should work in any ways you load an image.

Steps to reproduce:

In the code below, test the result with each case of image loading (they are commented).

Test code

import pygame

pygame.init()

screen = pygame.display.set_mode(pygame.Vector2(1920, 1080) * 2/3, vsync=1)

# surf = pygame.image.load("image_path").convert_alpha()
# surf = pygame.image.load("image_path").convert()
# surf = pygame.image.load("image_path")

surf = pygame.transform.hsl(surf, 30, 0.5, 0.3)
surf = pygame.transform.scale_by(surf, 2/3)

running = True
clock = pygame.Clock()

while running:

    dt = clock.tick() / 1000

    keys = pygame.key.get_pressed()

    screen.blit(surf, (0, 0))

    pygame.display.flip()
    pygame.display.set_caption(f"FPS : {round(clock.get_fps(), 2)}")

    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
            pygame.quit()
            running = False

This is a test image to use : image