pygame icon indicating copy to clipboard operation
pygame copied to clipboard

Colors come out weird with _sdl2.Texture.update()

Open distantforest1 opened this issue 3 years ago • 4 comments

Environment:

  • Operating system: Windows 10
  • Python version: 3.9.6
  • SDL version: 2.0.18
  • PyGame version: 2.1.2
  • Relevant hardware: nVidia GeForce RTX 2080 Ti

Current behavior:

The colours of certain images come out different than expected when using _sdl2.Texture.update. Possibly something to do with image formats. This is using the _sdl2 module.

Expected behavior:

Correctly rendered colours for the image.

Screenshots

The left image is the incorrect one, while the right is correct. The left is using texture.update() to add a surface to a texture, the right is using the texture.from_surface image

The original image: lildragon01

Steps to reproduce:

  1. Load png image as surface with pygame.image.load
  2. Create sdl2 Texture
  3. Draw surface onto texture with Texture.update()

Test code

import sys, pygame
from pygame import _sdl2


window = _sdl2.Window(size=(1048, 512))
renderer = _sdl2.Renderer(window)

surf = pygame.image.load("lildragon01.png")
# surf = pygame.image.load("lildragon01.bmp") # bmps also come out garbled

# The texture comes out weird with this
texture = _sdl2.Texture(renderer, size=(512, 512))
texture.update(surf, area=surf.get_rect())

# The colours come out correctly with this
texture2 = _sdl2.Texture.from_surface(renderer, surf)


while True:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            sys.exit()

        if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
            sys.exit()

    renderer.clear()
    texture.draw(dstrect=surf.get_rect())
    texture2.draw(dstrect=(512,0, surf.get_width(), surf.get_height()))

    renderer.present()

Zip with the source, BMP and PNG if you'd like to test:

wrongcoloursdl.zip

Additionally BMPs comes out like this as well: image

distantforest1 avatar Jan 07 '22 15:01 distantforest1

Another early adopter!

Oh yeah, and a problem too. I'll look into it sometime.

Be aware of course that the API is unstable. I've written out some of my ideas for changes here: https://github.com/pygame/pygame/issues/2691

Starbuck5 avatar Jan 08 '22 08:01 Starbuck5

Yep all good, I'm used to moving code and I think I'll be here for a couple years if things go well anyway. Also the _sdl2 module is too awesome to not use! haha. Anyway thought I should post some of the issues I find. Should I be posting them here? (Thanks for the link btw)

distantforest1 avatar Jan 08 '22 09:01 distantforest1

I think the best approach would be to open the new issue for every bug you encounter, and then we group them with the same tag. Because GitHub is not really a best place for "megathreads". But yea, you should definitely post those issues because that is important for the fix

MightyJosip avatar Jan 10 '22 10:01 MightyJosip

aah, your (art) is good!

00001H avatar Jun 19 '22 13:06 00001H