kmonsoor / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Unsupported PNG color type: 3 #653

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not sure if this is an authority, but according to:
http://www.w3.org/TR/PNG-Chunks.html
"Color type is a single-byte integer that describes the interpretation of the 
image data. Color type codes represent sums of the following values: 1 (palette 
used), 2 (color used), and 4 (alpha channel used). Valid values are 0, 2, 3, 4, 
and 6."

Of course, in image/codecs/pypng.py, the if/elif blocks only support types 0, 
2, 4, and 6. (Are palettes not supported?)

What steps will reproduce the problem?
1. Get a PNG image with type 3, such as 
http://cdn1.iconfinder.com/data/icons/black-animal-icons/16/Scorpion_scorpio_rob
ot_with.png
2. pyglet.image.load(filename, decoder=PNGImageDecoder())

Paste in the traceback or error message:
ImageDecodeException: PyPNG cannot read '(filename)': unknown PNG colour type 3

pyglet 1.1 with Python 2.5: Paste in the output of `python -m pyglet.info`
Other: Paste in the output of tools/gl_info.py (included in source distro):
Output of `python -m pyglet.info` attached as pygl.txt. gl_info.py didn't yield 
any output.

Any additional info (platform/language/hardware) that may be relevant?
Windows 7 32-bit, pyglet-1.2alpha1, ActiveState Python 2.7, AVbin 10

Original issue reported on code.google.com by hills....@gmail.com on 19 Jun 2013 at 2:32

Attachments:

GoogleCodeExporter commented 9 years ago
You can use the OS decoder (not using pypng):

$ python
Python 2.7.3 (default, Jul 24 2012, 10:05:39) 
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyglet
>>> pyglet.image.load("Scorpion_scorpio_robot_with.png")
<ImageData 16x16>
>>> pyglet.version
'1.2alpha1'
>>> 

Doc says: "This use is not recommended unless your application has to work 
around specific deficiences in an operating system decoder".

That said... yes, I think we should support palettes or at least write a note 
in the docs saying we don't support them :)

Original comment by useboxnet on 21 Jul 2013 at 9:41

GoogleCodeExporter commented 9 years ago
I've added palette support to pypng:

http://code.google.com/p/pyglet/source/detail?r=fbc3d38787c66063ca76e84efb189065
30dc2d61

It has some limitations though: doesn't support transparent colour and the 
image is converted from indexed to RGB. Write is not supported.

Also I'm not sure the background colour implementation is 100% correct, I can't 
find a way to test it.

Can you give it a go?

Original comment by useboxnet on 21 Jul 2013 at 11:22

GoogleCodeExporter commented 9 years ago

Original comment by useboxnet on 21 Jul 2013 at 11:23

GoogleCodeExporter commented 9 years ago
OK, it turns out it wasn't that difficult. I've added transparent support too:

http://code.google.com/p/pyglet/source/detail?r=b210ac020f016fc178de641cdbe8508f
cb426fc0

Still... if you need transparent colours is easier to convert to RGBA ;)

So now the indexed image is converted to RGB or RGBA if there's a transparent 
colour. No write support.

That should do it!

Original comment by useboxnet on 21 Jul 2013 at 1:20