<s> '''<STR_LIT>''' <EOL> import re <EOL> from base64 import b64decode <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> from kivy . event import EventDispatcher <EOL> from kivy . core import core_register_libs <EOL> from kivy . logger import Logger <EOL> from kivy . cache import Cache <EOL> from kivy . clock import Clock <EOL> from kivy . atlas import Atlas <EOL> from kivy . resources import resource_find <EOL> from kivy . utils import platform <EOL> from kivy . compat import string_types <EOL> from kivy . setupconfig import USE_SDL2 <EOL> import zipfile <EOL> from io import BytesIO <EOL> Texture = TextureRegion = None <EOL> Cache . register ( '<STR_LIT>' , timeout = <NUM_LIT> ) <EOL> Cache . register ( '<STR_LIT>' ) <EOL> class ImageData ( object ) : <EOL> '''<STR_LIT>''' <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> _supported_fmts = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , width , height , fmt , data , source = None , <EOL> flip_vertical = True , source_image = None , <EOL> rowlength = <NUM_LIT:0> ) : <EOL> assert fmt in ImageData . _supported_fmts <EOL> self . fmt = fmt <EOL> self . mipmaps = { } <EOL> self . add_mipmap ( <NUM_LIT:0> , width , height , data , rowlength ) <EOL> self . source = source <EOL> self . flip_vertical = flip_vertical <EOL> self . source_image = source_image <EOL> def release_data ( self ) : <EOL> mm = self . mipmaps <EOL> for item in mm . values ( ) : <EOL> item [ <NUM_LIT:2> ] = None <EOL> self . source_image = None <EOL> @ property <EOL> def width ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . mipmaps [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> @ property <EOL> def height ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . mipmaps [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> @ property <EOL> def data ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . mipmaps [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> @ property <EOL> def rowlength ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . mipmaps [ <NUM_LIT:0> ] [ <NUM_LIT:3> ] <EOL> @ property <EOL> def size ( self ) : <EOL> '''<STR_LIT>''' <EOL> mm = self . mipmaps [ <NUM_LIT:0> ] <EOL> return mm [ <NUM_LIT:0> ] , mm [ <NUM_LIT:1> ] <EOL> @ property <EOL> def have_mipmap ( self ) : <EOL> return len ( self . mipmaps ) > <NUM_LIT:1> <EOL> def __repr__ ( self ) : <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> self . width , self . height , self . fmt , <EOL> self . source , len ( self . mipmaps ) ) ) <EOL> def add_mipmap ( self , level , width , height , data , rowlength ) : <EOL> '''<STR_LIT>''' <EOL> self . mipmaps [ level ] = [ int ( width ) , int ( height ) , data , rowlength ] <EOL> def get_mipmap ( self , level ) : <EOL> '''<STR_LIT>''' <EOL> if level == <NUM_LIT:0> : <EOL> return ( self . width , self . height , self . data , self . rowlength ) <EOL> assert ( level < len ( self . mipmaps ) ) <EOL> return self . mipmaps [ level ] <EOL> def iterate_mipmaps ( self ) : <EOL> '''<STR_LIT>''' <EOL> mm = self . mipmaps <EOL> for x in range ( len ( mm ) ) : <EOL> item = mm . get ( x , None ) <EOL> if item is None : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> yield x , item [ <NUM_LIT:0> ] , item [ <NUM_LIT:1> ] , item [ <NUM_LIT:2> ] , item [ <NUM_LIT:3> ] <EOL> class ImageLoaderBase ( object ) : <EOL> '''<STR_LIT>''' <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:filename>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , filename , ** kwargs ) : <EOL> self . _mipmap = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . keep_data = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . _nocache = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . _ext = kwargs . get ( '<STR_LIT>' ) <EOL> self . _inline = kwargs . get ( '<STR_LIT>' ) <EOL> self . filename = filename <EOL> if self . _inline : <EOL> self . _data = self . load ( kwargs . get ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . _data = self . load ( filename ) <EOL> self . _textures = None <EOL> def load ( self , filename ) : <EOL> '''<STR_LIT>''' <EOL> return None <EOL> @ staticmethod <EOL> def can_save ( ) : <EOL> '''<STR_LIT>''' <EOL> return False <EOL> @ staticmethod <EOL> def can_load_memory ( ) : <EOL> '''<STR_LIT>''' <EOL> return False <EOL> @ staticmethod <EOL> def save ( ) : <EOL> raise NotImplementedError ( ) <EOL> def populate ( self ) : <EOL> self . _textures = [ ] <EOL> fname = self . filename <EOL> if __debug__ : <EOL> Logger . trace ( '<STR_LIT>' % <EOL> ( fname , len ( self . _data ) ) ) <EOL> for count in range ( len ( self . _data ) ) : <EOL> chr = type ( fname ) <EOL> uid = chr ( u'<STR_LIT>' ) % ( fname , self . _mipmap , count ) <EOL> texture = Cache . get ( '<STR_LIT>' , uid ) <EOL> if texture is None : <EOL> imagedata = self . _data [ count ] <EOL> source = '<STR_LIT>' . format ( <EOL> '<STR_LIT>' if fname . endswith ( '<STR_LIT>' ) else '<STR_LIT>' , <EOL> self . _nocache ) <EOL> imagedata . source = chr ( source ) + uid <EOL> texture = Texture . create_from_data ( <EOL> imagedata , mipmap = self . _mipmap ) <EOL> if not self . _nocache : <EOL> Cache . append ( '<STR_LIT>' , uid , texture ) <EOL> if imagedata . flip_vertical : <EOL> texture . flip_vertical ( ) <EOL> self . _textures . append ( texture ) <EOL> if not self . keep_data : <EOL> self . _data [ count ] . release_data ( ) <EOL> @ property <EOL> def width ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _data [ <NUM_LIT:0> ] . width <EOL> @ property <EOL> def height ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _data [ <NUM_LIT:0> ] . height <EOL> @ property <EOL> def size ( self ) : <EOL> '''<STR_LIT>''' <EOL> return ( self . _data [ <NUM_LIT:0> ] . width , self . _data [ <NUM_LIT:0> ] . height ) <EOL> @ property <EOL> def texture ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _textures is None : <EOL> self . populate ( ) <EOL> if self . _textures is None : <EOL> return None <EOL> return self . _textures [ <NUM_LIT:0> ] <EOL> @ property <EOL> def textures ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _textures is None : <EOL> self . populate ( ) <EOL> return self . _textures <EOL> @ property <EOL> def nocache ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _nocache <EOL> class ImageLoader ( object ) : <EOL> loaders = [ ] <EOL> @ staticmethod <EOL> def zip_loader ( filename , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> _file = BytesIO ( open ( filename , '<STR_LIT:rb>' ) . read ( ) ) <EOL> z = zipfile . ZipFile ( _file ) <EOL> image_data = [ ] <EOL> znamelist = z . namelist ( ) <EOL> znamelist . sort ( ) <EOL> image = None <EOL> for zfilename in znamelist : <EOL> try : <EOL> tmpfile = BytesIO ( z . read ( zfilename ) ) <EOL> ext = zfilename . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] . lower ( ) <EOL> im = None <EOL> for loader in ImageLoader . loaders : <EOL> if ( ext not in loader . extensions ( ) <EOL> or not loader . can_load_memory ( ) ) : <EOL> continue <EOL> Logger . debug ( '<STR_LIT>' % <EOL> ( loader . __name__ [ <NUM_LIT:11> : ] , zfilename , filename ) ) <EOL> try : <EOL> im = loader ( zfilename , ext = ext , rawdata = tmpfile , <EOL> inline = True , ** kwargs ) <EOL> except : <EOL> continue <EOL> break <EOL> if im is not None : <EOL> image_data . append ( im . _data [ <NUM_LIT:0> ] ) <EOL> image = im <EOL> except : <EOL> Logger . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( zfilename , filename ) ) <EOL> z . close ( ) <EOL> if len ( image_data ) == <NUM_LIT:0> : <EOL> raise Exception ( '<STR_LIT>' % filename ) <EOL> image . _data = image_data <EOL> image . filename = filename <EOL> return image <EOL> @ staticmethod <EOL> def register ( defcls ) : <EOL> ImageLoader . loaders . append ( defcls ) <EOL> @ staticmethod <EOL> def load ( filename , ** kwargs ) : <EOL> if filename [ : <NUM_LIT:8> ] == '<STR_LIT>' : <EOL> rfn = filename [ <NUM_LIT:8> : ] <EOL> try : <EOL> rfn , uid = rfn . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % filename ) <EOL> atlas = Cache . get ( '<STR_LIT>' , rfn ) <EOL> if atlas : <EOL> texture = atlas [ uid ] <EOL> fn = '<STR_LIT>' % ( rfn , uid ) <EOL> cid = '<STR_LIT>' . format ( fn , False , <NUM_LIT:0> ) <EOL> Cache . append ( '<STR_LIT>' , cid , texture ) <EOL> return Image ( texture ) <EOL> afn = rfn <EOL> if not afn . endswith ( '<STR_LIT>' ) : <EOL> afn += '<STR_LIT>' <EOL> afn = resource_find ( afn ) <EOL> if not afn : <EOL> raise Exception ( '<STR_LIT>' % afn ) <EOL> atlas = Atlas ( afn ) <EOL> Cache . append ( '<STR_LIT>' , rfn , atlas ) <EOL> for nid , texture in atlas . textures . items ( ) : <EOL> fn = '<STR_LIT>' % ( rfn , nid ) <EOL> cid = '<STR_LIT>' . format ( fn , False , <NUM_LIT:0> ) <EOL> Cache . append ( '<STR_LIT>' , cid , texture ) <EOL> return Image ( atlas [ uid ] ) <EOL> ext = filename . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] . lower ( ) <EOL> if filename . startswith ( ( ( '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> ext = ext . split ( '<STR_LIT:?>' ) [ <NUM_LIT:0> ] <EOL> filename = resource_find ( filename ) <EOL> if ext == '<STR_LIT>' : <EOL> return ImageLoader . zip_loader ( filename ) <EOL> else : <EOL> im = None <EOL> for loader in ImageLoader . loaders : <EOL> if ext not in loader . extensions ( ) : <EOL> continue <EOL> Logger . debug ( '<STR_LIT>' % <EOL> ( loader . __name__ [ <NUM_LIT:11> : ] , filename ) ) <EOL> im = loader ( filename , ** kwargs ) <EOL> break <EOL> if im is None : <EOL> raise Exception ( '<STR_LIT>' % ext ) <EOL> return im <EOL> class Image ( EventDispatcher ) : <EOL> '''<STR_LIT>''' <EOL> copy_attributes = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> data_uri_re = re . compile ( r'<STR_LIT>' ) <EOL> def __init__ ( self , arg , ** kwargs ) : <EOL> self . register_event_type ( '<STR_LIT>' ) <EOL> super ( Image , self ) . __init__ ( ) <EOL> self . _mipmap = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . _keep_data = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . _nocache = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . _size = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> self . _image = None <EOL> self . _filename = None <EOL> self . _texture = None <EOL> self . _anim_available = False <EOL> self . _anim_index = <NUM_LIT:0> <EOL> self . _anim_delay = <NUM_LIT:0> <EOL> self . anim_delay = kwargs . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . _iteration_done = False <EOL> if isinstance ( arg , Image ) : <EOL> for attr in Image . copy_attributes : <EOL> self . __setattr__ ( attr , arg . __getattribute__ ( attr ) ) <EOL> elif type ( arg ) in ( Texture , TextureRegion ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . textures = [ ] <EOL> self . textures . append ( arg ) <EOL> self . _texture = arg <EOL> self . _size = self . texture . size <EOL> elif isinstance ( arg , ImageLoaderBase ) : <EOL> self . image = arg <EOL> elif isinstance ( arg , BytesIO ) : <EOL> ext = kwargs . get ( '<STR_LIT>' , None ) <EOL> if not ext : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> filename = kwargs . get ( '<STR_LIT:filename>' ) <EOL> if not filename : <EOL> self . _nocache = True <EOL> filename = '<STR_LIT>' <EOL> self . load_memory ( arg , ext , filename ) <EOL> elif isinstance ( arg , string_types ) : <EOL> groups = self . data_uri_re . findall ( arg ) <EOL> if groups : <EOL> self . _nocache = True <EOL> imtype , optstr , data = groups [ <NUM_LIT:0> ] <EOL> options = [ o for o in optstr . split ( '<STR_LIT:;>' ) if o ] <EOL> ext = imtype <EOL> isb64 = '<STR_LIT>' in options <EOL> if data : <EOL> if isb64 : <EOL> data = b64decode ( data ) <EOL> self . load_memory ( BytesIO ( data ) , ext ) <EOL> else : <EOL> self . filename = arg <EOL> else : <EOL> raise Exception ( '<STR_LIT>' . format ( arg ) ) <EOL> def remove_from_cache ( self ) : <EOL> '''<STR_LIT>''' <EOL> count = <NUM_LIT:0> <EOL> f = self . filename <EOL> pat = type ( f ) ( u'<STR_LIT>' ) <EOL> uid = pat % ( f , self . _mipmap , count ) <EOL> Cache . remove ( "<STR_LIT>" , uid ) <EOL> while Cache . get ( "<STR_LIT>" , uid ) : <EOL> Cache . remove ( "<STR_LIT>" , uid ) <EOL> count += <NUM_LIT:1> <EOL> uid = pat % ( f , self . _mipmap , count ) <EOL> def _anim ( self , * largs ) : <EOL> if not self . _image : <EOL> return <EOL> textures = self . image . textures <EOL> if self . _anim_index >= len ( textures ) : <EOL> self . _anim_index = <NUM_LIT:0> <EOL> self . _texture = self . image . textures [ self . _anim_index ] <EOL> self . dispatch ( '<STR_LIT>' ) <EOL> self . _anim_index += <NUM_LIT:1> <EOL> self . _anim_index %= len ( self . _image . textures ) <EOL> def anim_reset ( self , allow_anim ) : <EOL> '''<STR_LIT>''' <EOL> Clock . unschedule ( self . _anim ) <EOL> if allow_anim and self . _anim_available and self . _anim_delay >= <NUM_LIT:0> : <EOL> Clock . schedule_interval ( self . _anim , self . anim_delay ) <EOL> self . _anim ( ) <EOL> def _get_anim_delay ( self ) : <EOL> return self . _anim_delay <EOL> def _set_anim_delay ( self , x ) : <EOL> if self . _anim_delay == x : <EOL> return <EOL> self . _anim_delay = x <EOL> if self . _anim_available : <EOL> Clock . unschedule ( self . _anim ) <EOL> if self . _anim_delay >= <NUM_LIT:0> : <EOL> Clock . schedule_interval ( self . _anim , self . _anim_delay ) <EOL> anim_delay = property ( _get_anim_delay , _set_anim_delay ) <EOL> '''<STR_LIT>''' <EOL> @ property <EOL> def anim_available ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _anim_available <EOL> @ property <EOL> def anim_index ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _anim_index <EOL> def _img_iterate ( self , * largs ) : <EOL> if not self . image or self . _iteration_done : <EOL> return <EOL> self . _iteration_done = True <EOL> imgcount = len ( self . image . textures ) <EOL> if imgcount > <NUM_LIT:1> : <EOL> self . _anim_available = True <EOL> self . anim_reset ( True ) <EOL> self . _texture = self . image . textures [ <NUM_LIT:0> ] <EOL> def on_texture ( self , * largs ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> @ staticmethod <EOL> def load ( filename , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> kwargs . setdefault ( '<STR_LIT>' , False ) <EOL> return Image ( filename , ** kwargs ) <EOL> def _get_image ( self ) : <EOL> return self . _image <EOL> def _set_image ( self , image ) : <EOL> self . _image = image <EOL> if hasattr ( image , '<STR_LIT:filename>' ) : <EOL> self . _filename = image . filename <EOL> if image : <EOL> self . _size = ( self . image . width , self . image . height ) <EOL> image = property ( _get_image , _set_image , <EOL> doc = '<STR_LIT>' ) <EOL> def _get_filename ( self ) : <EOL> return self . _filename <EOL> def _set_filename ( self , value ) : <EOL> if value is None or value == self . _filename : <EOL> return <EOL> self . _filename = value <EOL> f = self . filename <EOL> uid = type ( f ) ( u'<STR_LIT>' ) % ( f , self . _mipmap , <NUM_LIT:0> ) <EOL> image = Cache . get ( '<STR_LIT>' , uid ) <EOL> if image : <EOL> self . image = image <EOL> if ( image . __class__ != self . __class__ and <EOL> not image . keep_data and self . _keep_data ) : <EOL> self . remove_from_cache ( ) <EOL> self . _filename = '<STR_LIT>' <EOL> self . _set_filename ( value ) <EOL> else : <EOL> self . _texture = None <EOL> self . _img_iterate ( ) <EOL> return <EOL> else : <EOL> _texture = Cache . get ( '<STR_LIT>' , uid ) <EOL> if _texture : <EOL> self . _texture = _texture <EOL> return <EOL> tmpfilename = self . _filename <EOL> image = ImageLoader . load ( <EOL> self . _filename , keep_data = self . _keep_data , <EOL> mipmap = self . _mipmap , nocache = self . _nocache ) <EOL> self . _filename = tmpfilename <EOL> if isinstance ( image , Texture ) : <EOL> self . _texture = image <EOL> self . _size = image . size <EOL> else : <EOL> self . image = image <EOL> if not self . _nocache : <EOL> Cache . append ( '<STR_LIT>' , uid , self . image ) <EOL> filename = property ( _get_filename , _set_filename , <EOL> doc = '<STR_LIT>' ) <EOL> def load_memory ( self , data , ext , filename = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> self . _filename = filename <EOL> loaders = [ loader for loader in ImageLoader . loaders if <EOL> loader . can_load_memory ( ) and <EOL> ext in loader . extensions ( ) ] <EOL> if not loaders : <EOL> raise Exception ( '<STR_LIT>' . format ( ext ) ) <EOL> image = loaders [ <NUM_LIT:0> ] ( filename , ext = ext , rawdata = data , inline = True , <EOL> nocache = self . _nocache , mipmap = self . _mipmap , <EOL> keep_data = self . _keep_data ) <EOL> if isinstance ( image , Texture ) : <EOL> self . _texture = image <EOL> self . _size = image . size <EOL> else : <EOL> self . image = image <EOL> @ property <EOL> def size ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _size <EOL> @ property <EOL> def width ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _size [ <NUM_LIT:0> ] <EOL> @ property <EOL> def height ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _size [ <NUM_LIT:1> ] <EOL> @ property <EOL> def texture ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . image : <EOL> if not self . _iteration_done : <EOL> self . _img_iterate ( ) <EOL> return self . _texture <EOL> @ property <EOL> def nocache ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _nocache <EOL> def save ( self , filename , flipped = False ) : <EOL> '''<STR_LIT>''' <EOL> pixels = None <EOL> size = None <EOL> loaders = [ x for x in ImageLoader . loaders if x . can_save ( ) ] <EOL> if not loaders : <EOL> return False <EOL> loader = loaders [ <NUM_LIT:0> ] <EOL> if self . image : <EOL> data = self . image . _data [ <NUM_LIT:0> ] <EOL> if data . data is not None : <EOL> if data . fmt not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> size = data . width , data . height <EOL> pixels = data . data <EOL> else : <EOL> self . populate ( ) <EOL> if pixels is None and self . _texture : <EOL> size = self . _texture . size <EOL> pixels = self . _texture . pixels <EOL> if pixels is None : <EOL> return False <EOL> l_pixels = len ( pixels ) <EOL> if l_pixels == size [ <NUM_LIT:0> ] * size [ <NUM_LIT:1> ] * <NUM_LIT:3> : <EOL> fmt = '<STR_LIT>' <EOL> elif l_pixels == size [ <NUM_LIT:0> ] * size [ <NUM_LIT:1> ] * <NUM_LIT:4> : <EOL> fmt = '<STR_LIT>' <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return loader . save ( filename , size [ <NUM_LIT:0> ] , size [ <NUM_LIT:1> ] , fmt , pixels , flipped ) <EOL> def read_pixel ( self , x , y ) : <EOL> '''<STR_LIT>''' <EOL> data = self . image . _data [ <NUM_LIT:0> ] <EOL> if data . data is None : <EOL> raise EOFError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> x , y = int ( x ) , int ( y ) <EOL> if not ( <NUM_LIT:0> <= x < data . width and <NUM_LIT:0> <= y < data . height ) : <EOL> raise IndexError ( '<STR_LIT>' % ( x , y ) ) <EOL> assert data . fmt in ImageData . _supported_fmts <EOL> size = <NUM_LIT:3> if data . fmt in ( '<STR_LIT>' , '<STR_LIT>' ) else <NUM_LIT:4> <EOL> index = y * data . width * size + x * size <EOL> raw = bytearray ( data . data [ index : index + size ] ) <EOL> color = [ c / <NUM_LIT> for c in raw ] <EOL> if data . fmt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> color [ <NUM_LIT:0> ] , color [ <NUM_LIT:2> ] = color [ <NUM_LIT:2> ] , color [ <NUM_LIT:0> ] <EOL> return color <EOL> def load ( filename ) : <EOL> '''<STR_LIT>''' <EOL> return Image . load ( filename ) <EOL> image_libs = [ ] <EOL> if platform in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> image_libs += [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> image_libs += [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> if USE_SDL2 : <EOL> image_libs += [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> else : <EOL> image_libs += [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> image_libs += [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> libs_loaded = core_register_libs ( '<STR_LIT:image>' , image_libs ) <EOL> from os import environ <EOL> if not '<STR_LIT>' in environ and not libs_loaded : <EOL> import sys <EOL> Logger . critical ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> from kivy . graphics . texture import Texture , TextureRegion </s>
