<s> '''<STR_LIT:U+0020>''' <EOL> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> import os . path <EOL> from pyglet . gl import * <EOL> from pyglet . image import * <EOL> from pyglet . image . codecs import * <EOL> import Image <EOL> class PILImageDecoder ( ImageDecoder ) : <EOL> def get_file_extensions ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def decode ( self , file , filename ) : <EOL> try : <EOL> image = Image . open ( file ) <EOL> except Exception , e : <EOL> raise ImageDecodeException ( <EOL> '<STR_LIT>' % ( filename or file , e ) ) <EOL> image = image . transpose ( Image . FLIP_TOP_BOTTOM ) <EOL> if image . mode in ( '<STR_LIT:1>' , '<STR_LIT:P>' ) : <EOL> image = image . convert ( ) <EOL> if image . mode not in ( '<STR_LIT:L>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise ImageDecodeException ( '<STR_LIT>' % image . mode ) <EOL> type = GL_UNSIGNED_BYTE <EOL> width , height = image . size <EOL> return ImageData ( width , height , image . mode , image . tostring ( ) ) <EOL> class PILImageEncoder ( ImageEncoder ) : <EOL> def get_file_extensions ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def encode ( self , image , file , filename ) : <EOL> pil_format = ( filename and os . path . splitext ( filename ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] ) or '<STR_LIT>' <EOL> if pil_format . lower ( ) == '<STR_LIT>' : <EOL> pil_format = '<STR_LIT>' <EOL> image = image . get_image_data ( ) <EOL> format = image . format <EOL> if format != '<STR_LIT>' : <EOL> format = '<STR_LIT>' <EOL> pitch = - ( image . width * len ( format ) ) <EOL> pil_image = Image . fromstring ( <EOL> format , ( image . width , image . height ) , image . get_data ( format , pitch ) ) <EOL> try : <EOL> pil_image . save ( file , pil_format ) <EOL> except Exception , e : <EOL> raise ImageEncodeException ( e ) <EOL> def get_decoders ( ) : <EOL> return [ PILImageDecoder ( ) ] <EOL> def get_encoders ( ) : <EOL> return [ PILImageEncoder ( ) ] </s>
