%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/PIL/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/PIL/__pycache__/BlpImagePlugin.cpython-312.pyc

�

��e�<���dZddlmZddlZddlZddlmZddlmZddl	m
Z
mZGd�d	e�ZGd
�de�Z
Gd�d
e�Zd�Zd$d�Zd�Zd�ZGd�de�Zd�ZGd�dej�ZGd�dej.�ZGd�de�ZGd�de�ZGd�dej6�Zd�Ze
j<ej>ee�e
j@ej>d �e
jBd!e�e
jBd"e�e
jDej>e�e
jFd#e�y)%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.
�)�annotationsN)�IntEnum)�BytesIO�)�Image�	ImageFilec��eZdZdZy)�FormatrN)�__name__�
__module__�__qualname__�JPEG���4/usr/lib/python3/dist-packages/PIL/BlpImagePlugin.pyr
r
)s���Drr
c��eZdZdZdZdZy)�Encodingr��N)rrr
�UNCOMPRESSED�DXT�UNCOMPRESSED_RAW_BGRArrrrr-s���L�
�C��rrc��eZdZdZdZdZy)�
AlphaEncodingrr�N)rrr
�DXT1�DXT3�DXT5rrrrr3s���D��D��Drrc�<�|dz	dzdz|dz	dzdz|dzdzfS)N��r��?rr)�is r�
unpack_565r%9s2��
�"�W����"�a�1�f��_��$:�Q��X�!�O�K�Krc	���t|�dz}t�t�t�t�f}t|�D�]/}|dz}tjd||�\}}}t|�\}	}
}t|�\}}
}td�D]�}td�D]�}|dz}|dz	}d}|dk(r|	|
|}}}n�|dk(r||
|}}}nx|dk(r@||kDr"d|	z|zdz}d|
z|
zdz}d|z|zdz}nL|	|zdz}|
|
zdz}||zdz}n3|dk(r.||kDr"d|z|	zdz}d|
z|
zdz}d|z|zdz}nd	\}}}}|r||j
|g���||j
g�������2|S)
�E
    input: one "row" of data (i.e. will produce 4*width pixels)
    �z<HHI�rr�rr)rrrr��len�	bytearray�range�struct�unpack_fromr%�extend)�data�alpha�blocks�ret�block�idx�color0�color1�bits�r0�g0�b0�r1�g1�b1�jr$�control�a�r�g�bs                      r�decode_dxt1rG=s���
��Y�!�^�F��;�	��Y�[�)�+�
>�C��v��*-���a�i��%�1�1�&�$��D�������'�
��B����'�
��B���q�� 	-�A��1�X�
-����(���q�y�����a�<� �"�b�!�q�A���\� �"�b�!�q�A���\������V�b�[�Q�.����V�b�[�Q�.����V�b�[�Q�.���"�W��N���"�W��N���"�W��N����\������V�b�[�Q�.����V�b�[�Q�.����V�b�[�Q�.��%/�
��1�a�����F�M�M�1�a��A�,�/���F�M�M�1�a��)�,�?
-� 	-�*-�X�Jrc	�&�t|�dz}t�t�t�t�f}t|�D�]M}|dz}|||dz}tjd|�}tjd|d�\}}tjd|d�\}t|�\}	}
}t|�\}}
}td�D]�}d}td�D]�}d|z|zd	z}||}|rd}|dz}nd
}|dz}|dz}|d	d|z|zzz	d
z}|dk(r|	|
|}}}nY|dk(r||
|}}}nM|d	k(r"d	|	z|zd
z}d	|
z|
zd
z}d	|z|zd
z}n&|d
k(r!d	|z|	zd
z}d	|
z|
zd
z}d	|z|zd
z}||j
|g�������P|S)r'�z<8B�<HHr(�<I�r)FrT��rrrr+)r2r4r5r6r7r:r8r9�coder;r<r=r>r?r@rA�highr$�alphacode_indexrC�
color_coderDrErFs                        r�decode_dxt3rSts���
��Y�"�_�F��;�	��Y�[�)�+�
>�C��v��(,���b�j���S�3��8�$���!�!�%��/���+�+�E�5�!�<�����$�$�T�5�"�5�����'�
��B����'�
��B���q��	,�A��D��1�X�
,��#$�q�5�1�9��"2����)��� �D��!�G�A��D���H�A��R���"�a�1�q�5�1�9�o�5��=�
���?� �"�b�!�q�A��1�_� �"�b�!�q�A��1�_��R��"���*�A��R��"���*�A��R��"���*�A��1�_��R��"���*�A��R��"���*�A��R��"���*�A��A��
�
�q�!�Q��l�+�5
,�	,�(,�T�Jrc	�z�t|�dz}t�t�t�t�f}t|�D�]�}|dz}|||dz}tjd|�\}}tjd|d�}|d|ddzz|ddzz|dd	zz}|d
|ddzz}	tjd|d�\}
}tjd
|d�\}t|
�\}
}}t|�\}}}td�D�])}td�D�]}dd|z|zz}|dkr	|	|z	dz}n|dk(r|	dz	|dzdzz}n||dz
z	dz}|d
k(r|}nF|dk(r|}n>||kDrd|z
|z|dz
|zzdz}n$|dk(rd
}n|dk(rd}nd|z
|z|dz
|zzdz}|dd|z|zzz	dz}|d
k(r|
||}}}nY|dk(r|||}}}nM|dk(r"d|
z|zdz}d|z|zdz}d|z|zdz}n&|dk(r!d|z|
zdz}d|z|zdz}d|z|zdz}||j
|g�����,���|S)zG
    input: one "row" of data (i.e. will produce 4 * width pixels)
    rIz<BBz<6Brrr(r)r"�rrrJrKrLrrM�r*r+)r2r4r5r6r7�a0�a1r:�
alphacode1�
alphacode2r8r9rOr;r<r=r>r?r@rAr$rQ�	alphacoderCrRrDrErFs                            r�decode_dxt5r\�s���
��Y�"�_�F��;�	��Y�[�)�+�
>�C��v��9,���b�j���S�3��8�$���#�#�E�5�1���B��!�!�%���2���!�W��Q��1��-��a��B��?�4��7�b�=�Q�
��!�W��Q��1��-�
��+�+�E�5�!�<�����$�$�T�5�"�5�����'�
��B����'�
��B���q��(	,�A��1�X�'
,��"#�q�1�u�q�y�/��"�b�(�!+��!>�$� F�I�$��*�!+�r�!1�z�Q��$�6N� O�I�!+��"�0D�!E�� M�I���>��A��!�^��A��"�W��i�-�2�-��Q��"�0D�D��J�A��!�^��A��!�^��A��i�-�2�-��Q��"�0D�D��J�A�"�a�1�q�5�1�9�o�5��=�
���?� �"�b�!�q�A��1�_� �"�b�!�q�A��1�_��R��"���*�A��R��"���*�A��R��"���*�A��1�_��R��"���*�A��R��"���*�A��R��"���*�A��A��
�
�q�!�Q��l�+�O'
,�(	,�#9,�v�Jrc��eZdZy)�BLPFormatErrorN)rrr
rrrr^r^�s��rr^c��|dddvS)Nr)��BLP1�BLP2r)�prefixs r�_acceptrd�s���"�1�:�+�+�+rc��eZdZdZdZdZd�Zy)�BlpImageFilez 
    Blizzard Mipmap Format
    �BLPzBlizzard Mipmap Formatc���|jjd�|_|jjdtj
�t
jd|jjd��\|_|jjdtj
�t
jd|jjd��|_	|jdvr|jj�}n#d	t|j���}t|��|jrd
nd|_
|d|jzd
|jd
dffg|_y)Nr)r"�<brr�<IIr(r`zBad BLP magic �RGBA�RGB�rrr)�fp�read�magic�seek�os�SEEK_CURr/�unpack�_blp_alpha_depth�_size�decode�reprr^�_mode�size�mode�tile)�self�decoder�msgs   r�_openzBlpImageFile._open�s����W�W�\�\�!�_��
������Q����$�#)�=�=��t�w�w�|�|�A��#G� ��	������Q����$��]�]�5�$�'�'�,�,�q�/�:��
��:�:�+�+��j�j�'�'�)�G�"�4��
�
�#3�"4�5�C� ��%�%�#�4�4�V�%��
��v��	�	�1�1�t�y�y�!�Q�6G�H�I��	rN)rrr
�__doc__�format�format_descriptionr�rrrrfrf�s����F�1��Jrrfc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�_BLPBaseDecoderTc��	|j�|j�y#tj$r}d}t	|�|�d}~wwxYw)NzTruncated BLP file)���r)�_read_blp_header�_loadr/�error�OSError)r}�buffer�ers    rrwz_BLPBaseDecoder.decodesH��	&��!�!�#��J�J�L����|�|�	&�&�C��#�,�A�%��	&�s� #�A	�A�A	c��|jjd�tjd|j	d��\|_tjd|j	d��\|_tjd|j	d��\|_tjd|j	d��\|_|jjdtj�tjd|j	d��|_t|t�rVtjd|j	d��\|_|jjdtj�tjd|j	d��|_tjd|j	d��|_y)	Nr)�<irirrjr(�<16I�@)�fdrqr/rt�
_safe_read�_blp_compression�
_blp_encodingru�_blp_alpha_encodingrrrsrz�
isinstance�BLP1Decoder�_blp_offsets�_blp_lengths)r}s rr�z _BLPBaseDecoder._read_blp_headers5�������Q��#)�=�=��t���q�7I�#J� ��	� &�
�
�d�D�O�O�A�4F� G���	�#)�=�=��t���q�7I�#J� ��	�&,�m�m�D�$�/�/�!�:L�&M�#��	!������Q����$��M�M�%�����);�<��	��d�K�(�$*�M�M�$�����8J�$K�!�T�
��G�G�L�L��B�K�K�(�"�M�M�&�$�/�/�&�2I�J���"�M�M�&�$�/�/�&�2I�J��rc�B�tj|j|�S)N)rr�r�)r}�lengths  rr�z_BLPBaseDecoder._safe_read1s���#�#�D�G�G�V�4�4rc���g}td�D]B}	tjd|jd��\}}}}|j||||f��D|S#tj$rY|SwxYw)N��<4Br))r.r/rtr�r��append)r}r5r$rFrErDrCs       r�
_read_palettez_BLPBaseDecoder._read_palette4sz�����s��	%�A�
�#�]�]�5�$�/�/�!�2D�E�
��1�a��
�J�J��1�a��|�$�	%��
���<�<�
���
�
�s�*A�A-�,A-c�P�t�}t|j|jd��}		t	j
d|j
d��\}||\}}}}|||f}	|jr|	|fz
}	|j|	��[#tj$rY|SwxYw)Nr�<Br)
r-rr�r�r/rtror�rur1)
r}�paletter2�_data�offsetrFrErDrC�ds
          r�
_read_bgraz_BLPBaseDecoder._read_bgra>s����{�������(9�(9�!�(<�=�>���
�"�M�M�$��
�
�1�
�>�	��!���J�A�q�!�Q��A�q�	�A��$�$��a�T�	���K�K��N����<�<�
����
�s�'B�B%�$B%N)	rrr
�	_pulls_fdrwr�r�r�r�rrrr�r�s!���I��K�&5��
rr�c��eZdZd�Zd�Zy)r�c��|jtjk(r|j�y|jdk(rm|jdvr<|j�}|j
|�}|jt|��ydt|j���}t|��dt|j���}t|��)Nr)r)r"zUnsupported BLP encoding zUnsupported BLP compression )r�r
r�_decode_jpeg_streamr�r�r��
set_as_raw�bytesrxr^)r}r�r2rs    rr�zBLP1Decoder._loadOs���� � �F�K�K�/��$�$�&�
�
"�
"�a�
'��!�!�V�+��,�,�.�����w�/������d��,�1�$�t�7I�7I�2J�1K�L��$�S�)�)�0��d�6H�6H�1I�0J�K�C� ��%�%rc��ddlm}tjd|j	d��\}|j	|�}|j	|j
d|jj�z
�|j	|jd�}||z}t|�}||�}tj|j�|jdk(r%|jd\}}}}	||||	ddffg|_|jd�j!�\}
}}tj"d|||
f�}|j%|j'��y)Nr)�
JpegImageFilerKr)r�CMYKrl)�JpegImagePluginr�r/rtr�r�r��tellr�rr�_decompression_bomb_checkrzr{r|�convert�split�merger��tobytes)
r}r��jpeg_header_size�jpeg_headerr2�image�decoder_name�extentsr��argsrDrErFs
             rr�zBLP1Decoder._decode_jpeg_stream_s"��2�$�m�m�D�$�/�/�!�2D�E��	��o�o�&6�7������)�)�!�,�t�w�w�|�|�~�=�>����t�0�0��3�4���T�!���t�}���d�#��
�'�'��
�
�3��:�:���27�*�*�Q�-�/�L�'�6�4�'��&�4��7�F�:K�L�M�E�J��-�-��&�,�,�.���1�a����E�A�q�!�9�-������
�
��(rN)rrr
r�r�rrrr�r�Ns��&� )rr�c��eZdZd�Zy)�BLP2Decoderc�d�|j�}|jj|jd�|jdk(�r+|j
tjk(r|j|�}�n|j
tjk(�r�t�}|jtjk(rv|jddzdzdz}t|jddzdz�D];}t!|j#|�t%|j&���D]}||z
}�	�=�nc|jtj(k(r`|jddzdzdz}t|jddzdz�D]&}t+|j#|��D]}||z
}�	�(n�|jtj,k(r`|jddzdzdz}t|jddzdz�D]&}t/|j#|��D]}||z
}�	�(nidt1|j���}t3|��d	t1|j
���}t3|��d
t1|j���}t3|��|j5t7|��y)Nrrrr)r()r3rIzUnsupported alpha encoding zUnknown BLP encoding zUnknown BLP compression )r�r�rqr�r�r�rrr�rr-r�rrrzr.rGr��boolrurrSrr\rxr^r�r�)r}r�r2�linesize�ybr�rs       rr�zBLP2Decoder._loadss}���$�$�&�������T�&�&�q�)�*�� � �A�%��!�!�X�%:�%:�:����w�/���#�#�x�|�|�3� �{���+�+�}�/A�/A�A� $�	�	�!��q� 0�Q�6��:�H�#�T�Y�Y�q�\�A�%5�!�$;�<�&��!,� �O�O�H�5�T�$�BW�BW�=X�"�&�A�!�A�I�D�&�&��-�-��1C�1C�C� $�	�	�!��q� 0�Q�6��;�H�#�T�Y�Y�q�\�A�%5�!�$;�<�&��!,�T�_�_�X�-F�!G�&�A� �A�I�D�&�&��-�-��1C�1C�C� $�	�	�!��q� 0�Q�6��;�H�#�T�Y�Y�q�\�A�%5�!�$;�<�&��!,�T�_�_�X�-F�!G�&�A� �A�I�D�&�&�8��T�=U�=U�8V�7W�X�C�(��-�-�-�d�4�3E�3E�.F�-G�H��$�S�)�)�-�T�$�2G�2G�-H�,I�J�C� ��%�%�����d��$rN)rrr
r�rrrr�r�rs��+%rr�c��eZdZdZd�Zd�Zy)�
BLPEncoderTc	��d}|jjdd�}tt|�dz�D]1}||dz|dzdz\}}}}|t	j
d||||�z
}�3t|�dkr|dz
}t|�dkr�|S)Nrrkr)rr�is)�im�
getpaletter.r,r/�pack)r}r2r�r$rDrErFrCs        r�_write_palettezBLPEncoder._write_palette�s������'�'�$�$�V�V�4���s�7�|�q�(�)�	3�A� ��Q��!�a�%�1��5�J�A�q�!�Q��F�K�K��q�!�Q��2�2�D�	3��$�i�'�!��K��D��$�i�'�!��rc
��|j�}dt|�z}tjd|gd���}|jj
\}}|tjd||zgd���z
}||z
}t
|�D]F}t
|�D]6}|tjd|jj||f��z
}�8�Ht|�d|fS)N�r�)rrrrrrrrrrrrrrrr�r)r�r,r/r�r�rzr.�getpixel)	r}�bufsize�palette_datar�r2�w�h�y�xs	         r�encodezBLPEncoder.encode�s����*�*�,�� �3�|�#4�4���{�{�6�6�8�Y�8���w�w�|�|���1�����F�A��E�8�Y�8�8�������q��	D�A��1�X�
D������D�$�'�'�*:�*:�A�q�6�*B�C�C��
D�	D��4�y�!�T�!�!rN)rrr
�
_pushes_fdr�r�rrrr�r��s���J��"rr�c���|jdk7r
d}t|��|jjd�dk(rdnd}|j	|�|j	tjdd��|j	tjd	tj��|j	tjd	|jjd
k(rdnd��|j	tjd	d��|j	tjd	d��|j	tjdg|j����|dk(rJ|j	tjdd
��|j	tjdd��tj||dd|jzd|jfg�y)N�PzUnsupported BLP image mode�blp_version�BLP1rarbr�rrirkrrjr"rgrm)
r{�
ValueError�encoderinfo�get�writer/r�rrr�rzr�_save)r�rn�filenamerrps     rr�r��sK��	�w�w�#�~�*����o���~�~�)�)�-�8�F�B�G��E��H�H�U�O��H�H�V�[�[��q�
!�"��H�H�V�[�[��x�4�4�
5�6��H�H�V�[�[��B�J�J�O�O�v�$=�q�1�
E�F��H�H�V�[�[��q�
!�"��H�H�V�[�[��q�
!�"��H�H�V�[�[��
)����
)�*����
������T�1�%�&�
������T�1�%�&�
�O�O�B��e�V�b�g�g�%5�q�"�'�'�B�C�Drz.blpr��BLP2rg)F)$r��
__future__rrrr/�enumr�ior�rrr
rrr%rGrSr\�NotImplementedErrorr^rdrf�	PyDecoderr�r�r��	PyEncoderr�r��
register_openr��register_extension�register_decoder�
register_save�register_encoderrrr�<module>r�sH���<#�	�
����
�W�
��w��
�G�
�L�4�n2�jC�L	�(�	�,�J�9�&�&�J�69�i�)�)�9�x!)�/�!)�H,%�/�,%�^"��$�$�"�>E�*����L�'�'��w�?������,�,�f�5�����v�{�+�����v�{�+�����L�'�'��/�����u�j�)r

Zerion Mini Shell 1.0