public
Created

Fix Pyglet textures loading as greyscale in OS-X due to issues in the Quartz loader

  • Download Gist
fix_codecs.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
import sys
 
import pyglet
 
# on OS-X 10.7 (lion)
# the Quartz codec is buggered in Pyglet
if sys.platform == 'darwin':
# clear the existing codecs
pyglet.image.codecs._decoders = []
pyglet.image.codecs._decoder_extensions = {}
pyglet.image.codecs._decoder_animation_extensions = {}
pyglet.image.codecs._encoders = []
pyglet.image.codecs._encoder_extensions = {}
 
# just fallback to PIL
try:
import pyglet.image.codecs.pil
pyglet.image.codecs.add_encoders(pyglet.image.codecs.pil)
pyglet.image.codecs.add_decoders(pyglet.image.codecs.pil)
except ImportError:
pass
 
# Compressed texture in DDS format
try:
from pyglet.image.codecs import dds
pyglet.image.codecs.add_encoders(dds)
pyglet.image.codecs.add_decoders(dds)
except ImportError:
pass
 
# Fallback: PNG loader (slow)
try:
import pyglet.image.codecs.png
pyglet.image.codecs.add_encoders(pyglet.image.codecs.png)
pyglet.image.codecs.add_decoders(pyglet.image.codecs.png)
except ImportError:
pass
 
# Fallback: BMP loader (slow)
try:
import pyglet.image.codecs.bmp
pyglet.image.codecs.add_encoders(pyglet.image.codecs.bmp)
pyglet.image.codecs.add_decoders(pyglet.image.codecs.bmp)
except ImportError:
pass

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.