B .^7@sdZddlZddlmZddlmZmZdZdZdZ dZ dZ dZ dZ d d Zd!d d ZddZddZGdddeZGdddejZGdddejZGdddeZGdddeZeejeddeejdedeed edS)"a Blizzard Mipmap Format (.blp) Jerome Leclanche The contents of this file are hereby released in the public domain (CC0) Full text of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/ BLP1 files, used mostly in Warcraft III, are not fully supported. All types of BLP2 files used in World of Warcraft are supported. The BLP file structure consists of a header, up to 16 mipmaps of the texture Texture sizes must be powers of two, though the two dimensions do not have to be equal; 512x256 is valid, but 512x200 is not. The first mipmap (mipmap #0) is the full size image; each subsequent mipmap halves both dimensions. The final mipmap should be 1x1. BLP files come in many different flavours: * JPEG-compressed (type == 0) - only supported for BLP1. * RAW images (type == 1, encoding == 1). Each mipmap is stored as an array of 8-bit values, one per pixel, left to right, top to bottom. Each value is an index to the palette. * DXT-compressed (type == 1, encoding == 2): - DXT1 compression is used if alpha_encoding == 0. - An additional alpha bit is used if alpha_depth == 1. - DXT3 compression is used if alpha_encoding == 1. - DXT5 compression is used if alpha_encoding == 7. N)BytesIO)Image ImageFilecCs*|d?d@d>|d?d@d>|d@d>fS)N r?r)ir r 6/tmp/pip-install-mwhup7aw/Pillow/PIL/BlpImagePlugin.py unpack_5650srFc Cst|d}ttttf}xt|D]}|d}td||\}}}t|\} } } t|\} } }x`tdD]R}xJtdD]<}|d@}|d?}d}|dkr| | | }}}n|dkr| | |}}}n|dkrB||krd| | d}d| | d}d| |d}n$| | d}| | d}| |d}nR|dkr||krd| | d}d| | d}d|| d}n d \}}}}|r||||||gq|||||gqWqvWq,W|S) zE input: one "row" of data (i.e. will produce 4*width pixels) zB|dd>B|dd >B}|d |d d>B} td |d\} } td |d\} t| \} }}t| \}}}xtdD]}xtdD]}dd||}|dkr2| |?d@}n0|dkrR| d?|d >d@B}n||d?d@}|d krr|}nt|d kr|}nd||krd|||d |d}n<|dkrd }n,|dkrd}nd|||d |d}| dd||?d@}|d kr| ||}}}n|d kr6|||}}}nv|dkrrd| |d}d||d}d||d}n:|dkrd|| d}d||d}d||d}||||||gqWqWq,W|S)zG input: one "row" of data (i.e. will produce 4 * width pixels) r0zr?__doc__formatformat_descriptionrMrFr r r rr@s r@c@s(eZdZdZddZddZddZdS) _BLPBaseDecoderTcCsRy.|jd|jd|_||Wntjk rLtdYnXdS)NrrzTruncated Blp file)rr) fdseekrDrErF_loadrerrorOSError)rKbufferr r rdecodes  z_BLPBaseDecoder.decodec Csfg}x\tdD]P}y td|jd\}}}}Wntjk rJPYnX|||||fqW|S)Nz<4Br)rrrOr\rDr_append)rKrrr.r-r,r+r r r _read_palette!s z_BLPBaseDecoder._read_palettecCstd|jd\|_td|jd\|_td|jd\|_td|jd\|_td|jd\|_td|jd|_ |j dkrtd|jd\|_td|jd\|_ td|jd |_ td|jd |_ dS) Nzr?Z _pulls_fdrbrerFr r r rr[s  r[c@seZdZddZddZdS) BLP1Decoderc Cs|jtkr|n|jdkr|jdkrt}|}t|j|j d}xVyt d|d\}Wnt j k r~PYnX||\}}}}| |||gqNW|t|qtd|jntd|jdS)Nr)rr rzr?r^rhr r r rrf>srfc@seZdZddZdS) BLP2Decoderc Cs:|}t}|j|jd|jdkr|jtkrt|j |j d}xVyt d| d\}Wnt j k r~PYnX||\}}}}||||fqNWq(|jtkr |jtkr&|jdddd} xLt|jdddD]2} x,t|j | t|jdD]} || 7}qWqWn|jtkr|jdddd} xt|jdddD]*} x"t|j | D]} || 7}qvWq`Wnx|jtkr|jdddd} xTt|jdddD]*} x"t|j | D]} || 7}qWqWntd |jntd |jntd |j|t|dS) Nrrzr?r^r r r rrqisrqcCs|dddkS)Nr)sBLP1sBLP2r )pr r rrzz.blprArB)F)rXriorrrrgrrrsZ"BLP_ENCODING_UNCOMPRESSED_RAW_BGRArtrvrwrr/r8r;NotImplementedErrorr<r@Z PyDecoderr[rfrqZ register_openrYZregister_extensionZregister_decoderr r r rs0  75F**+5