+
     i@  c                  s   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
Ht ^RIHtHt  ! R R]4      t ! R	 R
]4      t ! R R]4      tR R ltR)R R lltR R ltR R lt ! R R]4      tR R lt ! R R]P                  4      t ! R R]P4                  ]P6                  4      t ! R R]4      t ! R R ]4      t ! R! R"]P>                  4      t R# R$ lt!]PD                  ! ]PF                  ]]4       ]PH                  ! ]PF                  R%4       ]PJ                  ! R&]4       ]PJ                  ! R']4       ]PL                  ! ]PF                  ]!4       ]PN                  ! R(] 4       R# )*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)IO)Image	ImageFilec                  s    ] tR t^,t^ tRtR# )Format N)__name__
__module____qualname____firstlineno__JPEG__static_attributes__r       9/usr/lib64/python3.14/site-packages/PIL/BlpImagePlugin.pyr   r   ,   s    Dr   r   c                  s"    ] tR t^0t^t^t^tRtR# )Encodingr   N)r   r	   r
   r   UNCOMPRESSEDDXTZUNCOMPRESSED_RAW_BGRAr   r   r   r   r   r   0   s    L
Cr   r   c                  s"    ] tR t^6t^ t^t^tRtR# )AlphaEncodingr   N)r   r	   r
   r   DXT1DXT3DXT5r   r   r   r   r   r   6   s    DDDr   r   c                    V ^8  d   QhRRRR/# )   iintreturnztuple[int, int, int]r   format   "r   __annotate__r   <   s     L L# L. Lr   c                s|    V ^,	          ^,          ^,          V ^,	          ^?,          ^,          V ^,          ^,          3# )i   r   )r      &r   
unpack_565r!   <   s2    "W"a1f_$:QX!OKKr   c               $    V ^8  d   QhRRRRRR/# )r   databytesalphaboolr   1tuple[bytearray, bytearray, bytearray, bytearray]r   r   r   r   r   r   @   s$     6 6
6666r   c           	     s   \        V 4      ^,          p\        4       \        4       \        4       \        4       3p\        V4       EF  pV^,          p\        P                  ! RW4      w  rgp\        V4      w  rp\        V4      w  rp\        ^4       EFa  p\        ^4       EFM  pV^,          pV^,	          p^pV^ 8X  d   YTpppMV^8X  d   YTpppMV^8X  d{   Wg8  dG   ^V	,          V,           ^,          p^V
,          V,           ^,          p^V,          V,           ^,          pMW,           ^,          pW,           ^,          pW,           ^,          pMZV^8X  dT   Wg8  dG   ^V,          V	,           ^,          p^V,          V
,           ^,          p^V,          V,           ^,          pMRw  ppppV'       d   W?,          P                  XXXV.4       EK3  W?,          P                  XXX.4       EKP  	  EKd  	  EK  	  V# )=
input: one "row" of data (i.e. will produce 4*width pixels)
z<HHI)    r)   r)   r)   len	bytearrayrangestructZunpack_fromr!   extend)r#   r%   blocksretblock_indexidxcolor0color1bitsr0g0b0r1g1b1jr   Zcontrolargbs   &&                    r   decode_dxt1rB   @   s    Y!^F;	Y[)+
>CV}Ao%11&$D'
'
 qA1X (qya< b!qA!\ b!qA!\Vb[Q.Vb[Q.Vb[Q.WNWNWN\Vb[Q.Vb[Q.Vb[Q.%/
1aFMM1aA,/FMM1a),?   %X Jr   c               r   r   r#   r$   r   r'   r   r   r   r   r   r   y   s     2 2e 2 Q 2r   c           	     s`   \        V 4      ^,          p\        4       \        4       \        4       \        4       3p\        V4       EF  pV^,          pWV^,            p\        P                  ! RV4      p\        P                  ! RV^4      w  rx\        P                  ! RV^4      w  p	\        V4      w  rp\        V4      w  rp\        ^4       EFV  pRp\        ^4       EF@  p^V,          V,           ^,          pVV,          pV'       d   RpV^,          pMRpV^,          pV^,          pV	^^V,          V,           ,          ,	          ^,          pV^ 8X  d   YTpppMV^8X  d   YTpppMV^8X  dG   ^V
,          V,           ^,          p^V,          V,           ^,          p^V,          V,           ^,          pMLV^8X  dF   ^V,          V
,           ^,          p^V,          V,           ^,          p^V,          V,           ^,          pVV,          P                  XXXV.4       EKC  	  EKY  	  EK  	  V# )r(   z<8B<HH<IFTr*   )r#   r0   r1   r2   r3   blockr6   r4   r5   coder7   r8   r9   r:   r;   r<   r=   Zhighr   alphacode_indexr>   
color_coder?   r@   rA   s   &                        r   decode_dxt3rJ   y   s   
 Y"_F;	Y[)+
>CV}B38$!!%/++E5!<$$T5"5'
'
qAD1X#$q519"2) D!GADHAR"a1q519o5=
? b!qA!1_ b!qA!1_R"*AR"*AR"*A1_R"*AR"*AR"*AAq!Ql+5   %T Jr   c               r   rC   r   r   r   r   r   r      s     C Ce C Q Cr   c           	     s   \        V 4      ^,          p\        4       \        4       \        4       \        4       3p\        V4       EF  pV^,          pWV^,            p\        P                  ! RV4      w  rg\        P                  ! RV^4      pV^,          V^,          ^,          ,          V^,          ^,          ,          V^,          ^,          ,          p	V^ ,          V^,          ^,          ,          p
\        P                  ! RV^4      w  r\        P                  ! RV^4      w  p\        V4      w  rp\        V4      w  ppp\        ^4       EF   p\        ^4       EF  p^^V,          V,           ,          pV^8:  d   V
V,	          ^,          pM=V^8X  d    V
^,	          V	^,          ^,          ,          pMV	V^,
          ,	          ^,          pV^ 8X  d   TpM}V^8X  d   TpMsWg8  d.   ^V,
          V,          V^,
          V,          ,           ^,          pM@V^8X  d   ^ pM6V^8X  d   ^pM,^V,
          V,          V^,
          V,          ,           ^,          pV^^V,          V,           ,          ,	          ^,          pV^ 8X  d   YTpppMV^8X  d   TTTpppMV^8X  dG   ^V,          V,           ^,          p^V,          V,           ^,          p^V,          V,           ^,          pMLV^8X  dF   ^V,          V,           ^,          p^V,          V,           ^,          p^V,          V,           ^,          pVV,          P                  XXXV.4       EK  	  EK  	  EK  	  V# )z?
input: one "row" of data (i.e. will produce 4 * width pixels)
z<BBz<6BrD   rE   r*   )r#   r0   r1   r2   r3   rF   Za0Za1r6   Z
alphacode1Z
alphacode2r4   r5   rG   r7   r8   r9   r:   r;   r<   r=   r   rH   Z	alphacoder>   rI   r?   r@   rA   s   &                            r   decode_dxt5rK      s   
 Y"_F;	Y[)+
>CV}B38$##E51!!%2!WQ1-aB?47b=Q
!WQ1-
++E5!<$$T5"5'
'
BqA1X"#q1uqy/"b(!+!>$ FI$*!+r!1zQ$6N OI!+"0D!E MI>A!^AWi-2-Q"0DDJA!^A!^Ai-2-Q"0DDJA"a1q519o5=
? b!qA!1_ "b!qA!1_R"*AR"*AR"*A1_R"*AR"*AR"*AAq!Ql+O  # %v Jr   c                  s    ] tR t^tRtR# )BLPFormatErrorr   N)r   r	   r
   r   r   r   r   r   rL   rL      s    r   rL   c               r   )r   prefixr$   r   r&   r   r   r   r   r   r      s     1 1E 1d 1r   c                s$    V P                  R4      # )   BLP1)rN      BLP2)Z
startswith)rM   r    r   _acceptrP      s    /00r   c                  s.    ] tR t^tRtRtRtR R ltRtR# )BlpImageFilez
Blizzard Mipmap Format
BLPzBlizzard Mipmap Formatc                   V ^8  d   QhRR/# r   r   Noner   r   r   r   r   ZBlpImageFile.__annotate__  s     Q Qt Qr   c                	s   V P                   P                  ^4      V n        \        V P                  4      '       g$   R\	        V P                  4       2p\        V4      h\        P                  ! RV P                   P                  ^4      4      ^ ,          pV P                  R8X  d<   \        P                  ! RV P                   P                  ^4      4      ^ ,          ^ 8g  pM\        P                  ! RV P                   P                  ^4      4      ^ ,          p\        P                  ! RV P                   P                  ^4      4      ^ ,          ^ 8g  p\        P                  ! RV P                   P                  ^4      4      ^ ,          pV P                   P                  ^\        P                  4       \        P                  ! RV P                   P                  ^4      4      V n        V P                  R8X  di   \        P                  ! RV P                   P                  ^4      4      ^ ,          pV P                   P                  ^\        P                  4       W$V3p^pMVXVX3p^pV P                  P                  4       pV'       d   RMRV n        \        P                  ! VR
V P                   ,           Wv4      .V n        R	# )   zBad BLP magic <irN   rE   <b<IIRGBARGBNr)   r)   )fpreadmagicrP   reprrL   r.   unpackseekosZSEEK_CUR_sizedecode_moder   _Tilesizetile)	selfmsgZcompressionr%   ZencodingZalpha_encodingargsoffsetZdecoders	   &        r   _openZBlpImageFile._open  s   WW\\!_
tzz"""4

#3"45C %%mmD$'',,q/:1=:: MM$Q8;q@E}}T477<<?;A>HMM$Q8;q@E#]]4aA!DNGGLLBKK(]]5$'',,q/:
 :: }}T477<<?;A>HGGLLBKK(51DF5.ADF**##%$V%
__Wftyy.@&OP	r   )rf   rd   r_   ri   N)	r   r	   r
   r   __doc__r   Zformat_descriptionrn   r   r   r   r   rQ   rQ      s      F1Q Qr   rQ   c                  s    ] tR tRtRtR R lt]P                  R R l4       tR R lt	R	 R
 lt
R R ltR R ltRtR# )_BLPBaseDecoderi&  Tc               r   )r   bufferz$bytes | Image.SupportsArrayInterfacer   ztuple[int, int]r   r   r   r   r   _BLPBaseDecoder.__annotate__)  s      A o r   c                	s     V P                  4        V P                  4        R#   \        P                   d   pR p\	        T4      ThRp?ii ; i)zTruncated BLP fileN)ir)   )_read_header_loadr.   errorZOSError)rj   rq   Zerk   s   &&  r   re   Z_BLPBaseDecoder.decode)  sJ    	&JJL  || 	&&C#,A%	&s    $ AAAc               rS   rT   r   r   r   r   r   rr   3  s      t r   c                	s    R # Nr   rj   r    r   rt   Z_BLPBaseDecoder._load2  s    r   c               rS   rT   r   r   r   r   r   rr   6  s     G Gd Gr   c                	s    \         P                  ! R V P                  ^@4      4      V n        \         P                  ! R V P                  ^@4      4      V n        R# )<16IN)r.   ra   
_safe_read_offsets_lengthsrw   r    r   rs   Z_BLPBaseDecoder._read_header6  s8    fdoof.EFfdoof.EFr   c               r   )r   lengthr   r   r$   r   r   r   r   r   rr   :  s     5 5 5 5r   c                	sd    V P                   f   Q h\        P                  ! V P                   V4      # rv   )fdr   ry   )rj   r|   s   &&r   ry   Z_BLPBaseDecoder._safe_read:  s)    ww"""##DGGV44r   c               rS   )r   r   list[tuple[int, int, int, int]]r   r   r   r   r   rr   >  s      > r   c                	s    . p\        R 4       F@  p \        P                  ! RV P                  ^4      4      w  r4rVTP                  Y4YV34       KB  	  V#   \        P                   d      T# i ; i)i   <4B)r-   r.   ra   ry   ru   Zappend)rj   r1   r   rA   r@   r?   r>      &      r   _read_paletteZ_BLPBaseDecoder._read_palette>  sm    sA#]]5$//!2DE
a JJa|$  
 << 
s   )AA.-A.c               r"   )r   paletter~   r%   r&   r   r,   r   r   r   r   r   rr   H  s$      6?C	r   c                	s^   \        4       p\        V P                  V P                  ^ ,          4      4      p  \        P
                  ! RVP                  ^4      4      w  pY,          w  rgrYT3p
T'       d
   Y3,          p
TP                  T
4       K]    \        P                   d     T# i ; i)r)   <B)	r,   r   ry   r{   r.   ra   r^   ru   r/   )rj   r   r%   r#   Z_datarm   rA   r@   r?   r>   ds   &&&        r   
_read_bgraZ_BLPBaseDecoder._read_bgraH  s     {a(89:"MM$

1>	 !JA!"#AT	KKN <<  s   (B B,+B,)r{   rz   N)r   r	   r
   r   Z	_pulls_fdre   abcZabstractmethodrt   rs   ry   r   r   r   r   r   r   rp   rp   &  s@    I 	 G5 r   rp   c                  s.    ] tR tRtR R ltR R ltRtR# )BLP1DecoderiZ  c               rS   rT   r   r   r   r   r   BLP1Decoder.__annotate__[  s     & &t &r   c                	s   V P                   w  V n        V n        pV P                  \        P                  8X  d   V P                  4        R# V P                  ^8X  di   V P                  R9   d5   V P                  4       pV P                  W!4      pV P                  V4       R# R\        V P                  4       2p\        V4      hR\        V P                  4       2p\        V4      h)   zUnsupported BLP encoding zUnsupported BLP compression N)rV   i   )rl   _compression	_encodingr   r   _decode_jpeg_streamr   r   
set_as_rawr`   rL   )rj   r%   r   r#   rk   s   &    r   rt   ZBLP1Decoder._load[  s    379904>5+$$&!#~~',,.w6%1$t~~2F1GH$S))0dnn1E0FGC %%r   c               rS   rT   r   r   r   r   r   r   m  s     ? ?T ?r   c                	s*   ^RI Hp \        P                  ! RV P	                  ^4      4      w  pV P	                  V4      pV P
                  f   Q hV P	                  V P                  ^ ,          V P
                  P                  4       ,
          4       V P	                  V P                  ^ ,          4      pW4,           pV! \        V4      4      p\        P                  ! VP                  4       VP                  R8X  dh   VP                  ^ ,          P                  p\!        V\"        4      '       g   Q hVP                  ^ ,          P%                  V^ ,          R3R7      .Vn        V P'                  VP)                  R4      P+                  4       R4       R# )r   )JpegImageFilerE   NZCMYK)rl   r[   ZBGR)ZJpegImagePluginr   r.   ra   ry   r}   rz   Ztellr{   r   r   Z_decompression_bomb_checkrh   moderi   rl   Z
isinstanceZtupleZ_replacer   ZconvertZtobytes)rj   r   Zjpeg_header_sizeZjpeg_headerr#   Zimagerl   r   r   r   ZBLP1Decoder._decode_jpeg_streamm  s   2$mmD$//!2DE	oo&67ww"""a(477<<>9:t}}Q/0!gdm,''

3::::a=%%DdE******Q-00tAw6G0HIEJe,446>r   )r   r   N)r   r	   r
   r   rt   r   r   r   r   r   r   r   Z  s    &$? ?r   r   c                  s"    ] tR tRtR R ltRtR# )BLP2Decoderi  c               rS   rT   r   r   r   r   r   ZBLP2Decoder.__annotate__  s     , ,t ,r   c                	s   V P                   w  V n        V n        qn        V P	                  4       pV P
                  f   Q hV P
                  P                  V P                  ^ ,          4       V P                  ^8X  Ed   V P                  \        P                  8X  d   V P                  W!4      pEMV P                  \        P                  8X  Ed)   \        4       pV P                  \        P                  8X  d   V P                  P                   ^,           ^,          ^,          p\#        V P                  P$                  ^,           ^,          4       F-  p\'        V P)                  V4      V4       F  pW6,          pK  	  K/  	  EMV P                  \        P*                  8X  d   V P                  P                   ^,           ^,          ^,          p\#        V P                  P$                  ^,           ^,          4       F,  p\-        V P)                  V4      4       F  pW6,          pK  	  K.  	  EMV P                  \        P.                  8X  d   V P                  P                   ^,           ^,          ^,          p\#        V P                  P$                  ^,           ^,          4       F,  p\1        V P)                  V4      4       F  pW6,          pK  	  K.  	  MiR\3        V P                  4       2p\5        V4      hR\3        V P                  4       2p\5        V4      hR\3        V P                  4       2p\5        V4      hV P7                  V4       R # )NzUnsupported alpha encoding zUnknown BLP encoding zUnknown BLP compression )rl   r   r   _alpha_encodingr   r}   rb   rz   r   r   r   r   r,   r   r   ZstateZxsizer-   ZysizerB   ry   r   rJ   r   rK   r`   rL   r   )rj   r%   r   r#   ZlinesizeZybr   rk      &       r   rt   ZBLP2Decoder._load  sw   IMF4>52F$$&ww"""T]]1%&! ~~!6!66w68<</ {''=+=+== $

 0 01 4:Q>H#TZZ%5%5%9a$?@!,T__X-F!NA ID "O A ))]-?-?? $

 0 01 4:R?H#TZZ%5%5%9a$?@!,T__X-F!GA ID "H A ))]-?-?? $

 0 01 4:R?H#TZZ%5%5%9a$?@!,T__X-F!GA ID "H A 8T=Q=Q8R7STC(---d4>>.B-CD$S)) -T$2C2C-D,EFC %%r   )r   r   r   N)r   r	   r
   r   rt   r   r   r   r   r   r     s    , ,r   r   c                  s2    ] tR tRtRtR R ltR R ltRtR# )	
BLPEncoderi  Tc               rS   )r   r   r$   r   r   r   r   r   BLPEncoder.__annotate__  s     	 	 	r   c           	     	sR   R pV P                   f   Q hV P                   P                  RR4      p\        \        V4      ^,          4       F>  pW#^,          V^,           ^,           w  rErgV\        P
                  ! RWeWG4      ,          pK@  	  \        V4      R8  d   VR,          pK  V# )r   rZ   r   i   s       )imZ
getpaletter-   r+   r.   pack)rj   r#   r   r   r?   r@   rA   r>   r   r   _write_paletteZBLPEncoder._write_palette  s    ww"""''$$VV4s7|q()A Q!a%15JA!FKKqQ22D * $i'!KDr   c               r   )r   bufsizer   r   ztuple[int, int, bytes]r   r   r   r   r   r     s     " "c "&< "r   c           
     	s   V P                  4       p^\        V4      ,           p\        P                  ! RV.RO5!  pV P                  f   Q hV P                  P
                  w  rVV\        P                  ! RWV,          .RO5!  ,          pWB,          p\        V4       FM  p\        V4       F;  pV\        P                  ! RV P                  P                  W34      4      ,          pK=  	  KO  	  \        V4      ^ V3# )i   rx   r   )r)   r)   r)   r)   r)   r)   r)   r)   r)   r)   r)   r)   r)   r)   r)   )r   r+   r.   r   r   rh   r-   Zgetpixel)	rj   r   Zpalette_datarm   r#   ZwZhZyZxs	   &&       r   encodeZBLPEncoder.encode  s    **, 3|#44{{668Y8ww"""ww||FAE8Y88qA1XD$''*:*:A6*BCC   4y!T!!r   r   N)r   r	   r
   r   Z
_pushes_fdr   r   r   r   r   r   r   r     s    J	" "r   r   c               s(    V ^8  d   QhRRRRRRRR/# )	r   r   zImage.Imager]   z	IO[bytes]filenamezstr | bytesr   rU   r   r   r   r   r   r     s.     T Tk Ty TK TD Tr   c           
     s   V P                   R 8w  d   Rp\        V4      hV P                  P                  R4      R8X  d   RMRpVP	                  V4       V P
                  f   Q hVP	                  \        P                  ! R^4      4       V P
                  P                   R8X  d   ^M^ pVR8X  d(   VP	                  \        P                  ! R	V4      4       MVP	                  \        P                  ! R
\        P                  4      4       VP	                  \        P                  ! R
V4      4       VP	                  \        P                  ! R
^ 4      4       VP	                  \        P                  ! R
^ 4      4       VP	                  \        P                  ! R.V P                  O5!  4       VR8X  dM   VP	                  \        P                  ! R^4      4       VP	                  \        P                  ! R^ 4      4       \        P                  ! W\        P                  ! RRV P                  ,           ^ V P                   4      .4       R# )ZPzUnsupported BLP image modeZblp_versionBLP1rN   rO   NrW   rZ   z<LrX   rY   rR   r\   )r   Z
ValueErrorZencoderinfoZgetZwriter   r.   r   r   r   rh   r   _saverg   )r   r]   r   rk   r_   Zalpha_depths   &&&   r   r   r     s   	ww#~*o~~))-8FBGEHHUO::!!!HHV[[q!"zz&0!aK
T;/0
T8#8#89:
T;/0
T1%&
T1%&HHV[[))*
T1%&
T1%&OOBY__UFRWW4DaQRSr   z.blpr   ZBLP2rR   )F)(ro   Z
__future__r    r   rc   r.   Zenumr   Zior   Ztypingr   Z r   r   r   r   r   r!   rB   rJ   rK   ZNotImplementedErrorrL   rP   rQ   ZABCZ	PyDecoderrp   r   r   Z	PyEncoderr   r   Zregister_openr   Zregister_extensionZregister_decoderZregister_saveZregister_encoderr   r   r   <module>r      sJ  > # 
 	     W w G L6r2jCL	( 	1'Q9&& 'QT1cggy22 1h"?/ "?J-/ -`"$$ "BT6   L''w ?   ,,f 5   v{ +   v{ +   L'' /   uj )r   