Unable to Surface.convert(32) some 1-bit images.

Dean Serenevy avatarDean Serenevy created an issue

I am having a problem with convert(32) where some png images can fail to load. I am encountering this with 1-bit pngs where both colors in the color palette are black (this is the only significant difference I can detect between the two attached images).

Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> pygame.__version__
'1.9.1release'
>>> im = pygame.image.load("city.png")
>>> im.get_palette()
((0, 0, 0, 255), (255, 255, 255, 255))
>>> im2 = pygame.image.load("brick.png")
>>> im2.get_palette()
((0, 0, 0, 255), (0, 0, 0, 255))
>>> pygame.display.init()
>>> pygame.display.set_mode((640,480))
<Surface(640x480x32 SW)>
>>> im.convert(32)
<Surface(24x24x32 SW)>
>>> im2.convert(32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pygame.error: Empty destination palette

Also reported at Kivy bug 516: https://github.com/kivy/kivy/issues/516

Comments (3)

  1. illume
    • changed status to open

    Thanks for the detailed bug report!

    A workaround might be to blit the surface to another surface first... and see if that helps.

    Next step, I need to convert the test you have there into a unit test. If you have some spare time to do that, it would be very helpful for fixing the bug.

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.