HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/PIL/__pycache__/BlpImagePlugin.cpython-38.pyc
U

tCf�8�@s�dZddlZddlmZddlmZmZdZdZdZ	dZ
dZdZdZ
d	d
�Zd!dd
�Zdd�Zdd�ZGdd�de�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�Ze�ejedd��e�ejd�e�de�e�d e�dS)"a�
Blizzard Mipmap Format (.blp)
Jerome Leclanche <jerome@leclan.ch>

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�	ImageFile���cCs*|d?d@d>|d?d@d>|d@d>fS)N��r��?r�)�ir
r
�4/usr/lib/python3/dist-packages/PIL/BlpImagePlugin.py�
unpack_5650srFc	Cs�t|�d}t�t�t�t�f}t|�D�]�}|d}t�d||�\}}}t|�\}	}
}t|�\}}
}td�D�]L}td�D�]<}|d@}|d?}d}|dkr�|	|
|}}}n�|dkr�||
|}}}n�|dk�r6||k�rd|	|d}d|
|
d}d||d}n$|	|d}|
|
d}||d}nR|dk�r�||k�r|d||	d}d|
|
d}d||d}nd	\}}}}|�r�||�||||g�q|||�|||g�q|qnq(|S)
�E
    input: one "row" of data (i.e. will produce 4*width pixels)
    �z<HHI�rr�rr)rrrr��len�	bytearray�range�structZunpack_fromr�extend)�data�alpha�blocks�ret�block�idx�color0�color1�bits�r0�g0�b0�r1�g1�b1�jrZcontrol�a�r�g�br
r
r�decode_dxt14sD



r/c	Cs�t|�d}t�t�t�t�f}t|�D�]�}|d}|||d�}t�d|�}t�d|d�\}}t�d|d�\}t|�\}	}
}t|�\}}
}td�D�]2}d}td�D�]}d||d	}||}|r�d}|dL}nd
}|dM}|d9}|d	d||?d
@}|dk�r"|	|
|}}}n�|dk�r>||
|}}}nv|d	k�rzd	|	|d
}d	|
|
d
}d	||d
}n:|d
k�r�d	||	d
}d	|
|
d
}d	||d
}||�||||g�q�q�q(|S)r�z<8B�<HHr�<I�rFrT��rrrr)rrrrr r#r!r"�coder$r%r&r'r(r)r*Zhighr�alphacode_indexr+�
color_coder,r-r.r
r
r�decode_dxt3ksH




r9c	Cs�t|�d}t�t�t�t�f}t|�D�]�}|d}|||d�}t�d|�\}}t�d|d�}|d|dd>B|dd>B|dd	>B}|d
|dd>B}	t�d|d�\}
}t�d
|d�\}t|
�\}
}}t|�\}}}td�D�]�}td�D�]�}dd||}|dk�r&|	|?d@}n0|dk�rF|	d?|d>d@B}n||d?d@}|d
k�rf|}nt|dk�rv|}nd||k�r�d|||d|d}n<|dk�r�d
}n,|dk�r�d}nd|||d|d}|dd||?d@}|d
k�r|
||}}}n�|dk�r*|||}}}nv|dk�rfd|
|d}d||d}d||d}n:|dk�r�d||
d}d||d}d||d}||�||||g�q�q�q(|S)zG
    input: one "row" of data (i.e. will produce 4 * width pixels)
    r0z<BBz<6Brrrrr�rrr1r2r3rr4�rr)rrrrr Za0Za1r#Z
alphacode1Z
alphacode2r!r"r6r$r%r&r'r(r)r*rr7Z	alphacoder+r8r,r-r.r
r
r�decode_dxt5�s^,










r<c@seZdZdS)�BLPFormatErrorN)�__name__�
__module__�__qualname__r
r
r
rr=�sr=c@s(eZdZdZdZdZdd�Zdd�ZdS)	�BlpImageFilez 
    Blizzard Mipmap Format
    ZBLPzBlizzard Mipmap FormatcCs||j�d�|_|��|jdkr,d}d|_n.|jdkrLd}|jrDdnd|_ntd|j��|d	|jd
|jd
dffg|_dS)Nr�BLP1�BLP1ZRGB�BLP2�BLP2ZRGBAzBad BLP magic %r�rrrr)	�fp�read�magic�_read_blp_header�mode�_blp_alpha_depthr=�size�tile)�self�decoderr
r
r�_open�s

zBlpImageFile._opencCs�t�d|j�d��\|_t�d|j�d��\|_t�d|j�d��\|_t�d|j�d��\|_t�d|j�d��\|_t�d|j�d��|_	|j
dkr�t�d|j�d��\|_t�d|j�d��\|_t�d|j�d	��|_t�d|j�d	��|_
dS�
Nz<irz<brz<IIrrBz<16I�@)r�unpackrGrH�_blp_compression�
_blp_encodingrL�_blp_alpha_encoding�	_blp_mipsZ_sizerI�_blp_subtype�_blp_offsets�_blp_lengths�rOr
r
rrJs
zBlpImageFile._read_blp_headerN)r>r?r@�__doc__�formatZformat_descriptionrQrJr
r
r
rrA�s
rAc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_BLPBaseDecoderTcCsRz.|j�d�|j�d�|_|��|��Wntjk
rLtd��YnXdS)NrrzTruncated Blp filerF)	�fd�seekrHrIrJ�_loadr�error�OSError)rO�bufferr
r
r�decodesz_BLPBaseDecoder.decodecCst�|j|�S)N)r�
_safe_readr`)rOZlengthr
r
rrg!sz_BLPBaseDecoder._safe_readc	Csdg}td�D]R}zt�d|�d��\}}}}Wntjk
rJYq`YnX|�||||f�q|S)N�z<4Br)rrrTrgrc�append)rOrrr.r-r,r+r
r
r�
_read_palette$sz_BLPBaseDecoder._read_palettecCs�t�d|�d��\|_t�d|�d��\|_t�d|�d��\|_t�d|�d��\|_t�d|�d��\|_t�d|�d��|_|j	dkr�t�d|�d��\|_t�d|�d��\|_
t�d|�d	��|_t�d|�d	��|_dSrR)
rrTrgrUrVrLrWrXrMrIrYrZr[r\r
r
rrJ.s
z _BLPBaseDecoder._read_blp_headerN)r>r?r@Z	_pulls_fdrfrgrjrJr
r
r
rr_s


r_c@seZdZdd�Zdd�ZdS)�BLP1Decoderc	Cs�|jtkr|��n�|jdkr�|jdkr�t�}|��}t|�|jd��}zt	�
d|�d��\}Wnt	jk
r|Yq�YnX||\}}}}|�
|||g�qJ|�t|��q�td|j��ntd|j��dS)Nr)rrr�<BzUnsupported BLP encoding %rzUnsupported BLP compression %r)rU�BLP_FORMAT_JPEG�_decode_jpeg_streamrVrrjrrgr[rrTrHrcr�
set_as_raw�bytesr=)	rOr�palette�_data�offsetr.r-r,r+r
r
rrbBs(




��zBLP1Decoder._loadcCs�ddlm}t�d|�d��\}|�|�}|�|jd|j���|�|jd�}||}t	|�}||�}t
�|j�|j
|_
|j|_|j|_dS)Nr)�
JpegImageFiler2r)ZPIL.JpegImagePluginrtrrTrgrZr`�tellr[rrZ_decompression_bomb_checkrMrNrGrK)rOrtZjpeg_header_sizeZjpeg_headerrZimager
r
rrn]s
zBLP1Decoder._decode_jpeg_streamN)r>r?r@rbrnr
r
r
rrkAsrkc@seZdZdd�ZdS)�BLP2DecodercCs|��}t�}|j�|jd�|jdk�r�|jtkr�t|�	|j
d��}zt�d|�
d��\}Wntjk
r|Yq�YnX||\}}}}|�|||f�qJ�q|jtk�r�|jtk�r|jdddd}	t|jddd�D],}
t|�	|	�t|j�d�D]}||7}�qq�n�|jtk�rx|jdddd}	t|jddd�D]$}
t|�	|	��D]}||7}�qb�qPnn|jtk�r�|jdddd}	t|jddd�D]$}
t|�	|	��D]}||7}�qq�ntd	|j��ntd
|j��ntd|j��|�t|��dS)Nrrrlrrr)rr0zUnsupported alpha encoding %rzUnknown BLP encoding %rzUnknown BLP compression %r)rjrr`rarZrUrV�BLP_ENCODING_UNCOMPRESSEDrrgr[rrTrHrcr�BLP_ENCODING_DXTrW�BLP_ALPHA_ENCODING_DXT1rMrr/�boolrL�BLP_ALPHA_ENCODING_DXT3r9�BLP_ALPHA_ENCODING_DXT5r<r=rorp)rOrqrrrrsr.r-r,r+ZlinesizeZyb�dr
r
rrbnsJ

�
�zBLP2Decoder._loadN)r>r?r@rbr
r
r
rrvmsrvcCs|dd�dkS)Nr)rBrDr
)�pr
r
r�<lambda>��rz.blprCrE)F)r]r�ior�rrrmrwrxZ"BLP_ENCODING_UNCOMPRESSED_RAW_BGRAryr{r|rr/r9r<�NotImplementedErrorr=rAZ	PyDecoderr_rkrvZ
register_openr^Zregister_extensionZregister_decoderr
r
r
r�<module>s6
75F*-,5�