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

Certain PNGs load incorrectly. #3036

Open
Starbuck5 opened this issue Aug 5, 2024 · 2 comments
Open

Certain PNGs load incorrectly. #3036

Starbuck5 opened this issue Aug 5, 2024 · 2 comments
Labels
bug Not working as intended image pygame.image

Comments

@Starbuck5
Copy link
Member

Reported by @geometrian on discord

1_img_okay.png:
1_img_okay

2_img_broken.png
2_img_broken

Inside pygame-ce however, image 1 load correctly and image 2 does not.

image

Basic display script:

import pygame

pygame.init()

im1 = pygame.image.load("1_img_okay.png")
print("load 1 finished")
im2 = pygame.image.load("2_img_broken.png")

print(im1.get_at((20,20)), im2.get_at((20,20)))
print(im1, im1.get_shifts())
print(im2, im2.get_shifts())

running = True

screen = pygame.display.set_mode((500,500))
print(screen, screen.get_shifts())

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill("grey")
    screen.blit(im1, (0,0))
    screen.blit(im2, (im1.get_width(),0))

    pygame.display.flip()

pygame.quit()
@Starbuck5 Starbuck5 added bug Not working as intended image pygame.image labels Aug 5, 2024
@Starbuck5
Copy link
Member Author

I've been looking into this for several days now, and this is a problem with how SDL_image is interfacing with libpng to load images.

Using SDL_image prebuilts (which use stb-image for PNGs), this problem goes away. Using our prebuilts (with libpng) the error is present.

pngcheck output on the broken image:

File: 2_img_broken.png (1379 bytes)
  chunk IHDR at offset 0x0000c, length 13
    64 x 64 image, 8-bit grayscale, non-interlaced
  chunk tRNS at offset 0x00025, length 2
    gray = 0x00ff
  chunk IDAT at offset 0x00033, length 1282
    zlib: deflated, 8K window, maximum compression
    row filters (0 none, 1 sub, 2 up, 3 avg, 4 paeth):
      1 1 2 1 2 1 2 1 4 2 1 2 1 2 4 2 4 1 2 1 2 4 2 4 4
      2 4 2 4 2 4 2 4 1 2 4 2 1 2 4 1 2 4 2 1 2 1 2 4 1
      2 1 2 1 2 4 1 2 1 2 1 2 1 2 (64 out of 64)
  chunk eXIf at offset 0x00541, length 14: EXIF metadata, big-endian (MM) format
  chunk IEND at offset 0x0055b, length 0
No errors detected in 2_img_broken.png (5 chunks, 66.3% compression).

This is a grayscale image with alpha transparency provided by a colorkey, basically. This is the erroring case.

@Starbuck5
Copy link
Member Author

Alright, it's fixed in SDL_image now!

We'll need to wait for them to put out a new patch release with the fix, or we could use the git version of SDL_image since we control builds on all platforms. (It's just we're not used to using git versions).

It would also be good to add this image to our test suite to prevent regressions here.

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

No branches or pull requests

1 participant