<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> from kivy . logger import Logger <EOL> from kivy . core . image import ImageLoaderBase , ImageData , ImageLoader <EOL> from os . path import isfile <EOL> try : <EOL> import pygame <EOL> except : <EOL> raise <EOL> class ImageLoaderPygame ( ImageLoaderBase ) : <EOL> '''<STR_LIT>''' <EOL> @ staticmethod <EOL> def extensions ( ) : <EOL> '''<STR_LIT>''' <EOL> if pygame . image . get_extended ( ) == <NUM_LIT:0> : <EOL> return ( '<STR_LIT>' , ) <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> @ staticmethod <EOL> def can_save ( ) : <EOL> return True <EOL> @ staticmethod <EOL> def can_load_memory ( ) : <EOL> return True <EOL> def load ( self , filename ) : <EOL> if not filename : <EOL> import traceback <EOL> traceback . print_stack ( ) <EOL> return <EOL> try : <EOL> im = None <EOL> if self . _inline : <EOL> im = pygame . image . load ( filename , '<STR_LIT>' . format ( self . _ext ) ) <EOL> elif isfile ( filename ) : <EOL> with open ( filename , '<STR_LIT:rb>' ) as fd : <EOL> im = pygame . image . load ( fd ) <EOL> elif isinstance ( filename , bytes ) : <EOL> try : <EOL> fname = filename . decode ( ) <EOL> if isfile ( fname ) : <EOL> with open ( fname , '<STR_LIT:rb>' ) as fd : <EOL> im = pygame . image . load ( fd ) <EOL> except UnicodeDecodeError : <EOL> pass <EOL> if im is None : <EOL> im = pygame . image . load ( filename ) <EOL> except : <EOL> raise <EOL> fmt = '<STR_LIT>' <EOL> if im . get_bytesize ( ) == <NUM_LIT:3> : <EOL> fmt = '<STR_LIT>' <EOL> elif im . get_bytesize ( ) == <NUM_LIT:4> : <EOL> fmt = '<STR_LIT>' <EOL> if fmt not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> imc = im . convert ( <NUM_LIT:32> ) <EOL> fmt = '<STR_LIT>' <EOL> except : <EOL> try : <EOL> imc = im . convert_alpha ( ) <EOL> fmt = '<STR_LIT>' <EOL> except : <EOL> Logger . warning ( <EOL> '<STR_LIT>' % <EOL> ( filename , im . fmt ) ) <EOL> raise <EOL> im = imc <EOL> if not self . _inline : <EOL> self . filename = filename <EOL> data = pygame . image . tostring ( im , fmt . upper ( ) ) <EOL> return [ ImageData ( im . get_width ( ) , im . get_height ( ) , <EOL> fmt , data , source = filename ) ] <EOL> @ staticmethod <EOL> def save ( filename , width , height , fmt , pixels , flipped ) : <EOL> surface = pygame . image . fromstring ( <EOL> pixels , ( width , height ) , fmt . upper ( ) , flipped ) <EOL> pygame . image . save ( surface , filename ) <EOL> return True <EOL> ImageLoader . register ( ImageLoaderPygame ) </s>
