Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
BlpImagePlugin.cpython-313.pyc144 linesDownload Raw Back to __pycache__
1�

2v�j�B����SrSSKJr SSKrSSKrSSKrSSKJr SSKJ	r	 SSK3Jr SSKJ
r
Jr "S	S4\5r"SS\5r"S
S\5rS%SjrS&S'SjjrS(SjrS(Sjr"SS\5rS)Sjr"SS\R5r"SS\R4\R65r"SS\5r"SS\5r"SS\R>5r S*S jr!\
RD"\RF\\5 \
RH"\RFS!5 \
RJ"S"\5 \
RJ"S#\5 \
RL"\RF\!5 \
RN"S$\ 5 g)+a�5Blizzard Mipmap Format (.blp)6Jerome Leclanche <jerome@leclan.ch>7 8The contents of this file are hereby released in the public domain (CC0)9Full text of the CC0 license:10  https://creativecommons.org/publicdomain/zero/1.0/11 12BLP1 files, used mostly in Warcraft III, are not fully supported.13All types of BLP2 files used in World of Warcraft are supported.14 15The BLP file structure consists of a header, up to 16 mipmaps of the16texture17 18Texture sizes must be powers of two, though the two dimensions do19not have to be equal; 512x256 is valid, but 512x200 is not.20The first mipmap (mipmap #0) is the full size image; each subsequent21mipmap halves both dimensions. The final mipmap should be 1x1.22 23BLP files come in many different flavours:24* JPEG-compressed (type == 0) - only supported for BLP1.25* RAW images (type == 1, encoding == 1). Each mipmap is stored as an26  array of 8-bit values, one per pixel, left to right, top to bottom.27  Each value is an index to the palette.28* DXT-compressed (type == 1, encoding == 2):29- DXT1 compression is used if alpha_encoding == 0.30  - An additional alpha bit is used if alpha_depth == 1.31  - DXT3 compression is used if alpha_encoding == 1.32  - DXT5 compression is used if alpha_encoding == 7.33�)�annotationsN)�IntEnum)�BytesIO)�IO�)�Image�	ImageFilec��\rSrSrSrSrg)�Format�,r�N)�__name__�34__module__�__qualname__�__firstlineno__�JPEG�__static_attributes__r
��XD:\code\apps\devtools\python\user_packages\Python313\site-packages\PIL/BlpImagePlugin.pyrr,s���Drrc� �\rSrSrSrSrSrSrg)�Encoding�0r��r
N)rrrr�UNCOMPRESSED�DXT�UNCOMPRESSED_RAW_BGRArr
rrrr0s���L�35�C��rrc� �\rSrSrSrSrSrSrg)�
AlphaEncoding�6rr�r
N)rrrr�DXT1�DXT3�DXT5rr
rrrr6s���D��D��Drrc�<�US-	S-S-US-	S-S-US-S-4$)N��r��?rr
)�is r�36unpack_565r+<s2��
�"�W����"�a�1�f��_��$:�Q��X�!�O�K�Krc	���[U5S-n[5[5[5[54n[U5GH4nUS-n[R"SX5upgn[U5up�n[U5up�n[S5H�n[S5H�nUS-nUS-	nSnUS:XaX�UnnnO�US:XaX�UnnnOwUS:Xa=Xg:�a"SU	-U-S-nSU37-U
-S-nSU-U-S-nOJX�-S-nX�-S-nX�-S-nO4US:Xa.Xg:�a"SU-U	-S-nSU
-U38-S-nSU-U-S-nOS	unnnnU(aX?R
WWWU/5 M�X?R
WWW/5 M� M� GM7 U$)39�=40input: one "row" of data (i.e. will produce 4*width pixels)41�z<HHI�rr��rr)rrrr��len�	bytearray�range�struct�unpack_fromr+�extend)�data�alpha�blocks�ret�block_index�idx�color0�color1�bits�r0�g0�b0�r1�g1�b1�jr*�control�a�r�g�bs                      r�decode_dxt1rM@s�����Y�!�^�F��;�	��Y�[�)�+�42>�C��V�}���A�o��%�1�1�&�$�D������'�43�����'�44����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�.��%/�45��1�a����F�M�M�1�a��A�,�/��F�M�M�1�a��)�,�?��%�X�Jrc	�>�[U5S-n[5[5[5[54n[U5GHXnUS-nXUS-n[R"SU5n[R"SUS5upx[R"SUS5un	[U5up�n[U5up�n[S5H�nSn[S5H�nSU-U-S	-nUUnU(aSnUS-nOS46nUS-nUS-nU	S	SU-U---	S
-nUS:XaX�UnnnO[US:XaX�UnnnOOUS	:Xa"S	U47-U
-S
-nS	U-U-S
-nS	U-U-S
-nO'US
:Xa!S	U
-U48-S
-nS	U-U-S
-nS	U-U-S
-nUUR
WWWU/5 M� M� GM[ U$)r-�z<8B�<HHr.�<I�r/FrT��rrrr1)r8r:r;r<r=�blockr@r>r?�coderArBrCrDrErFrG�highr*�alphacode_indexrI�49color_coderJrKrLs                         r�decode_dxt3rZys���50��Y�"�_�F��;�	��Y�[�)�+�51>�C��V�}���B����3��8�$���!�!�%��/���+�+�E�5�!�<����$�$�T�5�"�5�����'�52�����'�53����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��=�54���?� �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	��[U5S-n[5[5[5[54n[U5GHnUS-nXUS-n[R"SU5upg[R"SUS5nUSUSS--USS--USS	--n	US55USS--n56[R"SUS5up�[R"S
US5un
[U5up�n[U5unnn[S5GH5n[S5GH!nSSU-U--nUS::a	U57U-	S-nO US:XaU58S-	U	S-S--nOU	US-59-	S-nUS60:XaUnOIUS:XaUnO@Xg:�aSU-61U-US-62U--S-nO&US:XaS63nOUS:XaSnOSU-64U-US-65U--S-nU
SSU-U---	S-nUS66:XaX�UnnnO\US:XaUUUnnnOOUS:Xa"SU-U-S-nSU-U-S-nSU-U-S-nO'US:Xa!SU-U-S-nSU-U-S-nSU-U-S-nUUR
WWWU/5 GM$ GM8 GM U$)z?67input: one "row" of data (i.e. will produce 4 * width pixels)68rOz<BBz<6Brrr.r/r(�rrrPrQrRr!rS�r0r1)r8r:r;r<r=rU�a0�a1r@�69alphacode1�70alphacode2r>r?rVrArBrCrDrErFrGr*rX�	alphacoderIrYrJrKrLs                             r�decode_dxt5rc�s���71��Y�"�_�F��;�	��Y�[�)�+�72>�C��V�}���B����3��8�$���#�#�E�5�1����!�!�%���2���!�W��Q��1��-��a��B��?�4��7�b�=�Q�73��!�W��Q��1��-�74��+�+�E�5�!�<����$�$�T�5�"�5�����'�75�����'�76��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��=�77���?� �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��#%�v�Jrc��\rSrSrSrg)�BLPFormatError��r
N)rrrrrr
rrrere�s��rrec�$�URS5$)N)�BLP1�BLP2)�78startswith)�prefixs r�_acceptrl�s�����/�0�0rc�*�\rSrSrSrSrSrSSjrSrg)	�BlpImageFile��z79Blizzard Mipmap Format80�BLPzBlizzard Mipmap Formatc�h�URceURRS5Ul[UR5(d#S[	UR53n[U5e[R"SURRS55SnURS:Xa7[R"SURRS55SS:gnO�[R"SURRS55Sn[R"SURRS55SS:gn[R"SURRS55SnURRS[R5 [R"S	URRS8155UlURS:Xad[R"SURRS55SnURRS[R5 X$U4nSnOUWUW4nSnURR5nU(aS
OSUl
[R"USUR -Xv5/Ulg)Nr/zBad BLP magic �<irrhrQ�<br�<IIr.���RGBA�RGB�rr)�fp�read�magicrl�reprrer5�unpack�seek�os�SEEK_CUR�_size�decode�_moder	�_Tile�size�tile)	�self�msg�compressionr9�encoding�alpha_encoding�args�offset�decoders	         r�_open�BlpImageFile._opens����w�w�"�"�"��W�W�\�\�!�_��82��t�z�z�"�"�"�4��83�84�#3�"4�5�C� ��%�%��m�m�D�$�'�'�,�,�q�/�:�1�=���:�:�� ��M�M�$������Q��8��;�q�@�E��}�}�T�4�7�7�<�<��?�;�A�>�H��M�M�$������Q��8��;�q�@�E�#�]�]�4������a��A�!�D�N��G�G�L�L��B�K�K�(��]�]�5�$�'�'�,�,�q�/�:��85��:�:�� ��}�}�T�4�7�7�<�<��?�;�A�>�H��G�G�L�L��B�K�K�(��5�1�D��F���5�.�A�D��F��*�*�#�#�%��$�V�%��86��_�_�W�f�t�y�y�.@�&�O�P��	r)r�r�r|r�N��return�None)	rrrr�__doc__�format�format_descriptionr�rr
rrrnrn�s����F�1�� Qrrnc�~�\rSrSrSrSSjr\RSSj5rSSjr	S
Sjr87SSjrSSjrS	r
g88)�_BLPBaseDecoderi'Tc��UR5 UR5 g![RanSn[	U5UeSnAff=f)NzTruncated BLP file)�����r)�_read_header�_loadr5�error�OSError)r��buffer�er�s    rr��_BLPBaseDecoder.decode*sH��	&������J�J�L����|�|�	&�&�C��#�,�A�%��	&�s� #�A89�A�A90c��g�Nr
�r�s rr��_BLPBaseDecoder._load3s��rc��[R"SURS55Ul[R"SURS55Ulg)N�<16I�@)r5r~�91_safe_read�_offsets�_lengthsr�s rr��_BLPBaseDecoder._read_header7s8���
�
�f�d�o�o�f�.E�F��
��
�
�f�d�o�o�f�.E�F��
rc�b�URce[R"URU5$r�)�fdr	r�)r��lengths  rr��_BLPBaseDecoder._safe_read;s)���w�w�"�"�"��#�#�D�G�G�V�4�4rc���/n[S5H@n[R"SURS55up4pVURX4XV45 MB U$![Ra  U$f=f)N��<4Br/)r4r5r~r�r��append)r�r;r*rLrKrJrIs       r�
_read_palette�_BLPBaseDecoder._read_palette?sm�����s��A�
�#�]�]�5�$�/�/�!�2D�E�92��a�
�J�J��a�|�$���93���<�<�
���94�
�s�)A�A-�,A-c�B�[5n[URURS55n[R95"SUR
S55unXupgp�X�U4n96U(aX�4-
n97URU985 MS![Ra U$f=f)Nr�<Br)	r3rr�r�r5r~r{r�r7)r��paletter9r8�_datar�rLrKrJrI�ds           r�99_read_bgra�_BLPBaseDecoder._read_bgraIs����{�������
�
�a�(8�9�:���
�"�M�M�$��100�101�1�
�>�	��!��J�A�!�"#���A���T�	���K�K��N����<�<�
����
�s�(B�B�B)r�r�N)r�z$bytes | Image.SupportsArrayInterfacer�ztuple[int, int]r�)r��intr��bytes)r��list[tuple[int, int, int, int]])r�r�r9�boolr�r3)rrrr�	_pulls_fdr��abc�abstractmethodr�r�r�r�r�rr
rrr�r�'sS���I��	���
��
�G�5���6��?C��	�rr�c�(�\rSrSrSSjrSSjrSrg)�BLP1Decoderi[c���URuUlUlnUR[R:XaUR5 gURS:XafURS;a3UR
5nURX!5nURU5 gS[UR53n[U5eS[UR53n[U5e)Nr)r/r(zUnsupported BLP encoding zUnsupported BLP compression )r��_compression�	_encodingrr�_decode_jpeg_streamr�r��102set_as_rawr}re)r�r9r�r8r�s     rr��BLP1Decoder._load\s���37�9�9�0���4�>�5�������+��$�$�&�
�
�
�!�
#��~�~��'��,�,�.�����w�6������%�1�$�t�~�~�2F�1G�H��$�S�)�)�0��d�n�n�1E�0F�G�C� ��%�%rc���SSKJn [R"SUR	S55unUR	U5nUR103ceUR	URSUR104R5-1055 UR	URS5nX4-nU"[U55n[R"UR5 URS:XaWURSRn[!U["5(deURSR%USS4S9/UlUR'UR)S5R+5S	5 g)106Nr)�
JpegImageFilerQr/r�CMYK)r�rx�BGR)�JpegImagePluginr�r5r~r�r�r��tellr�rr�_decompression_bomb_checkr��moder�r��107isinstance�tuple�_replacer��convert�tobytes)r�r��jpeg_header_size�jpeg_headerr8�imager�s       rr��BLP1Decoder._decode_jpeg_streamns��2�$�m�m�D�$�/�/�!�2D�E��	��o�o�&6�7���w�w�"�"�"�����
�
�a�(�4�7�7�<�<�>�9�:����t�}�}�Q�/�0���!���g�d�m�,��
�'�'��108�109�3��:�:����:�:�a�=�%�%�D��d�E�*�*�*�*��*�*�Q�-�0�0�t�A�w��6G�0�H�I�E�J�����
�
�e�,�4�4�6��>r)r�r�Nr�)rrrrr�r�rr
rrr�r�[s��&�$?rr�c��\rSrSrSSjrSrg)�BLP2Decoderi�c���URuUlUlolUR	5nUR110ceUR111R
URS5 URS:XGaOUR[R:XaURX!5nGOAUR[R:XGa�[5nUR[R:XasURR S-S-S-n[#URR$S-S-5H)n['UR)U5U5HnX6-
nM	 M+ GO�UR[R*:XaqURR S-S-S-n[#URR$S-S-5H(n[-UR)U55HnX6-
nM	 M* O�UR[R.:XaqURR S-S-S-n[#URR$S-S-5H(n[1UR)U55HnX6-
nM	 M* OiS[3UR53n[5U5eS[3UR53n[5U5eS	[3UR53n[5U5eUR7U5 g)112Nrrrr/r.rOzUnsupported alpha encoding zUnknown BLP encoding zUnknown BLP compression )r�r�r��_alpha_encodingr�r�rr�rrr�rr3rr"�state�xsizer4�ysizerMr�r#rZr$rcr}rer�)r�r9r�r8�linesize�ybr�r�s        rr��BLP2Decoder._load�sw��IM���F���4�>�5�2F��$�$�&���w�w�"�"�"������T�]�]�1�%�&�����!��~�~��!6�!6�6����w�6�����8�<�<�/� �{���'�'�=�+=�+=�=� $�113�114� 0� 0�1� 4��:�Q�>�H�#�T�Z�Z�%5�%5��%9�a�$?�@��!,�T�_�_�X�-F��!N�A� �I�D�"O�A��)�)�]�-?�-?�?� $�115�116� 0� 0�1� 4��:�R�?�H�#�T�Z�Z�%5�%5��%9�a�$?�@��!,�T�_�_�X�-F�!G�A� �I�D�"H�A��)�)�]�-?�-?�?� $�117�118� 0� 0�1� 4��:�R�?�H�#�T�Z�Z�%5�%5��%9�a�$?�@��!,�T�_�_�X�-F�!G�A� �I�D�"H�A�8��T�=Q�=Q�8R�7S�T�C�(��-�-�-�d�4�>�>�.B�-C�D��$�S�)�)�-�T�$�2C�2C�-D�,E�F�C� ��%�%�����r)r�r�r�Nr�)rrrrr�rr
rrr�r��s��,rr�c�,�\rSrSrSrSSjrSSjrSrg)	�119BLPEncoderi�Tc	�<�SnURceURRSS5n[[U5S-5H.nX#S-US-S-upEpgU[R120"SXeXG5-
nM0 [U5S:aUS-
n[U5S:aMU$)Nrrwr/rr�is)�im�121getpaletter4r2r5�pack)r�r8r�r*rJrKrLrIs        r�_write_palette�BLPEncoder._write_palette�s������w�w�"�"�"��'�'�$�$�V�V�4���s�7�|�q�(�)�A� �Q��!�a�%�1��5�J�A�!��F�K�K��q�Q�2�2�D�*��$�i�'�!��K��D��$�i�'�!��rc122���UR5nS[U5-n[R"SU/SQ76nURceURR123upVU[R"SXV-/SQ76-
nXB-
n[
U5HIn[
U5H7nU[R"SURRX�455-
nM9 MK [U5SU4$)N�r�)rrrrrrrrrrrrrrrr�r)r�r2r5r�r�r�r4�getpixel)	r��bufsize�palette_datar�r8�w�h�y�xs	         r�encode�BLPEncoder.encode�s����*�*�,�� �3�|�#4�4���{�{�6�6�8�Y�8���w�w�"�"�"��w�w�|�|�������F�A�E�8�Y�8�8������q��A��1�X������D�$�'�'�*:�*:�A�6�*B�C�C�����4�y�!�T�!�!rr
N)r�r�)r�r�r�ztuple[int, int, bytes])rrrr�124_pushes_fdr�r�rr
rrr�r��s���J�	�"rr�c125��URS:wa
Sn[U5eURRS5S:XaSOSnUR	U5 UR126ceUR	[R"SS55 UR127RS	:XaSOS128nUS:Xa'UR	[R"SU55 O�UR	[R"S[R55 UR	[R"SU55 UR	[R"SS12955 UR	[R"SS13055 UR	[R"S
/URQ765 US:XaLUR	[R"SS55 UR	[R"SS13155 [R"X[R"SSUR-S132UR5/5 g)N�PzUnsupported BLP image mode�blp_version�BLP1rhrirrrrwrz<Lrsrtr(rpry)r��133ValueError�encoderinfo�get�writer�r5r�rrr�r	�_saver�)r�rz�filenamer�r|�alpha_depths      rrr�s���	�w�w�#�~�*����o���~�~�)�)�-�8�F�B�G��E��H�H�U�O�
�:�:�!�!�!��H�H�V�[�[��q�
!�"��z�z���&�0�!�a�K����134������T�;�/�0�135������T�8�#8�#8�9�:�136������T�;�/�0�137������T�1�%�&�138������T�1�%�&��H�H�V�[�[��
)����
)�*����139������T�1�%�&�140������T�1�%�&�
�O�O�B�Y�_�_�U�F�R�W�W�4D�a����Q�R�Srz.blpr�BLP2rp)r*r�r�ztuple[int, int, int])F)r8r�r9r�r��1tuple[bytearray, bytearray, bytearray, bytearray])r8r�r�r	)rkr�r�r�)r�zImage.Imagerzz	IO[bytes]rzstr | bytesr�r�)(r��141__future__rr�r�r5�enumr�ior�typingr�rr	rrrr+rMrZrc�NotImplementedErrorrerlrn�ABC�	PyDecoderr�r�r��	PyEncoderr�r�
register_openr��register_extension�register_decoder�
register_save�register_encoderr
rr�<module>rsg���>#�142�	�
�����
�W�
��w��
�G�
�L�143 %�6�144�6��6�6�6�r2�jC�L	�(�	�1�(Q�9�&�&�(Q�V1�c�g�g�y�2�2�1�h"?�/�"?�J-�/�-�`"��$�$�"�BT�6���L�'�'��w�?�����,�,�f�5����v�{�+����v�{�+����L�'�'��/����u�j�)r
codekingpro/portable-devtools · Team Ai