<s> '''<STR_LIT>''' <EOL> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> from ctypes import * <EOL> import struct <EOL> from pyglet . gl import * <EOL> from pyglet . image import CompressedImageData <EOL> from pyglet . image import codecs <EOL> from pyglet . image . codecs import s3tc <EOL> from pyglet . compat import izip_longest <EOL> class DDSException ( codecs . ImageDecodeException ) : <EOL> exception_priority = <NUM_LIT:0> <EOL> DDSD_CAPS = <NUM_LIT> <EOL> DDSD_HEIGHT = <NUM_LIT> <EOL> DDSD_WIDTH = <NUM_LIT> <EOL> DDSD_PITCH = <NUM_LIT> <EOL> DDSD_PIXELFORMAT = <NUM_LIT> <EOL> DDSD_MIPMAPCOUNT = <NUM_LIT> <EOL> DDSD_LINEARSIZE = <NUM_LIT> <EOL> DDSD_DEPTH = <NUM_LIT> <EOL> DDPF_ALPHAPIXELS = <NUM_LIT> <EOL> DDPF_FOURCC = <NUM_LIT> <EOL> DDPF_RGB = <NUM_LIT> <EOL> DDSCAPS_COMPLEX = <NUM_LIT> <EOL> DDSCAPS_TEXTURE = <NUM_LIT> <EOL> DDSCAPS_MIPMAP = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP_POSITIVEX = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP_NEGATIVEX = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP_POSITIVEY = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP_NEGATIVEY = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP_POSITIVEZ = <NUM_LIT> <EOL> DDSCAPS2_CUBEMAP_NEGATIVEZ = <NUM_LIT> <EOL> DDSCAPS2_VOLUME = <NUM_LIT> <EOL> class _filestruct ( object ) : <EOL> def __init__ ( self , data ) : <EOL> if len ( data ) < self . get_size ( ) : <EOL> raise DDSException ( '<STR_LIT>' ) <EOL> items = struct . unpack ( self . get_format ( ) , data ) <EOL> for field , value in izip_longest ( self . _fields , items , fillvalue = None ) : <EOL> setattr ( self , field [ <NUM_LIT:0> ] , value ) <EOL> def __repr__ ( self ) : <EOL> name = self . __class__ . __name__ <EOL> return '<STR_LIT>' % ( name , ( '<STR_LIT>' % ( '<STR_LIT:U+0020>' * ( len ( name ) + <NUM_LIT:1> ) ) ) . join ( [ '<STR_LIT>' % ( field [ <NUM_LIT:0> ] , repr ( getattr ( self , field [ <NUM_LIT:0> ] ) ) ) for field in self . _fields ] ) ) <EOL> @ classmethod <EOL> def get_format ( cls ) : <EOL> return '<STR_LIT:<>' + '<STR_LIT>' . join ( [ f [ <NUM_LIT:1> ] for f in cls . _fields ] ) <EOL> @ classmethod <EOL> def get_size ( cls ) : <EOL> return struct . calcsize ( cls . get_format ( ) ) <EOL> class DDSURFACEDESC2 ( _filestruct ) : <EOL> _fields = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) <EOL> ] <EOL> def __init__ ( self , data ) : <EOL> super ( DDSURFACEDESC2 , self ) . __init__ ( data ) <EOL> self . ddpfPixelFormat = DDPIXELFORMAT ( self . ddpfPixelFormat ) <EOL> class DDPIXELFORMAT ( _filestruct ) : <EOL> _fields = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:I>' ) <EOL> ] <EOL> _compression_formats = { <EOL> ( '<STR_LIT>' , False ) : ( GL_COMPRESSED_RGB_S3TC_DXT1_EXT , s3tc . decode_dxt1_rgb ) , <EOL> ( '<STR_LIT>' , True ) : ( GL_COMPRESSED_RGBA_S3TC_DXT1_EXT , s3tc . decode_dxt1_rgba ) , <EOL> ( '<STR_LIT>' , False ) : ( GL_COMPRESSED_RGBA_S3TC_DXT3_EXT , s3tc . decode_dxt3 ) , <EOL> ( '<STR_LIT>' , True ) : ( GL_COMPRESSED_RGBA_S3TC_DXT3_EXT , s3tc . decode_dxt3 ) , <EOL> ( '<STR_LIT>' , False ) : ( GL_COMPRESSED_RGBA_S3TC_DXT5_EXT , s3tc . decode_dxt5 ) , <EOL> ( '<STR_LIT>' , True ) : ( GL_COMPRESSED_RGBA_S3TC_DXT5_EXT , s3tc . decode_dxt5 ) , <EOL> } <EOL> def _check_error ( ) : <EOL> e = glGetError ( ) <EOL> if e != <NUM_LIT:0> : <EOL> print '<STR_LIT>' % e <EOL> class DDSImageDecoder ( codecs . ImageDecoder ) : <EOL> def get_file_extensions ( self ) : <EOL> return [ '<STR_LIT>' ] <EOL> def decode ( self , file , filename ) : <EOL> header = file . read ( DDSURFACEDESC2 . get_size ( ) ) <EOL> desc = DDSURFACEDESC2 ( header ) <EOL> if desc . dwMagic != '<STR_LIT>' or desc . dwSize != <NUM_LIT> : <EOL> raise DDSException ( '<STR_LIT>' ) <EOL> width = desc . dwWidth <EOL> height = desc . dwHeight <EOL> mipmaps = <NUM_LIT:1> <EOL> if desc . dwFlags & DDSD_DEPTH : <EOL> raise DDSException ( '<STR_LIT>' ) <EOL> if desc . dwFlags & DDSD_MIPMAPCOUNT : <EOL> mipmaps = desc . dwMipMapCount <EOL> if desc . ddpfPixelFormat . dwSize != <NUM_LIT:32> : <EOL> raise DDSException ( '<STR_LIT>' ) <EOL> if desc . dwCaps2 & DDSCAPS2_CUBEMAP : <EOL> raise DDSException ( '<STR_LIT>' ) <EOL> if not desc . ddpfPixelFormat . dwFlags & DDPF_FOURCC : <EOL> raise DDSException ( '<STR_LIT>' ) <EOL> has_alpha = desc . ddpfPixelFormat . dwRGBAlphaBitMask != <NUM_LIT:0> <EOL> format , decoder = _compression_formats . get ( <EOL> ( desc . ddpfPixelFormat . dwFourCC , has_alpha ) , None ) <EOL> if not format : <EOL> raise DDSException ( '<STR_LIT>' % desc . ddpfPixelFormat . dwFourCC ) <EOL> if format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT : <EOL> block_size = <NUM_LIT:8> <EOL> else : <EOL> block_size = <NUM_LIT:16> <EOL> datas = [ ] <EOL> w , h = width , height <EOL> for i in range ( mipmaps ) : <EOL> if not w and not h : <EOL> break <EOL> if not w : <EOL> w = <NUM_LIT:1> <EOL> if not h : <EOL> h = <NUM_LIT:1> <EOL> size = ( ( w + <NUM_LIT:3> ) / <NUM_LIT:4> ) * ( ( h + <NUM_LIT:3> ) / <NUM_LIT:4> ) * block_size <EOL> data = file . read ( size ) <EOL> datas . append ( data ) <EOL> w >>= <NUM_LIT:1> <EOL> h >>= <NUM_LIT:1> <EOL> image = CompressedImageData ( width , height , format , datas [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , decoder ) <EOL> level = <NUM_LIT:0> <EOL> for data in datas [ <NUM_LIT:1> : ] : <EOL> level += <NUM_LIT:1> <EOL> image . set_mipmap_data ( level , data ) <EOL> return image <EOL> def get_decoders ( ) : <EOL> return [ DDSImageDecoder ( ) ] <EOL> def get_encoders ( ) : <EOL> return [ ] </s>
