+
    UBi@                       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                      ] tR t^,t^ tRtR# )Format N)__name__
__module____qualname____firstlineno__JPEG__static_attributes__r
       7/usr/lib/python3.14/site-packages/PIL/BlpImagePlugin.pyr	   r	   ,   s    Dr   r	   c                  "    ] tR t^0t^t^t^tRtR# )Encodingr
   N)r   r   r   r   UNCOMPRESSEDDXTUNCOMPRESSED_RAW_BGRAr   r
   r   r   r   r   0   s    L
Cr   r   c                  "    ] 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
   )formats   "r   __annotate__r#   <   s     L L# L. Lr   c                |    V ^,	          ^,          ^,          V ^,	          ^?,          ^,          V ^,          ^,          3# )   r
   )r   s   &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"   s   "r   r#   r#   @   s$     6 6
6666r   c           	        \        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structunpack_fromr&   extend)r(   r*   blocksretblock_indexidxcolor0color1bitsr0g0b0r1g1b1jr   controlargbs   &&                    r   decode_dxt1rJ   @   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                    V ^8  d   QhRRRR/# r   r(   r)   r!   r,   r
   )r"   s   "r   r#   r#   y   s     2 2e 2 Q 2r   c           	     `   \        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<IFTr0   )r(   r7   r8   r9   r:   blockr=   r;   r<   coder>   r?   r@   rA   rB   rC   rD   highr   alphacode_indexrF   
color_coderG   rH   rI   s   &                        r   decode_dxt3rU   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                    V ^8  d   QhRRRR/# rL   r
   )r"   s   "r   r#   r#      s     C Ce C Q Cr   c           	        \        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<6BrN   rO   r0   )r(   r7   r8   r9   r:   rP   a0a1r=   
alphacode1
alphacode2r;   r<   rQ   r>   r?   r@   rA   rB   rC   rD   r   rS   	alphacoderF   rT   rG   rH   rI   s   &                            r   decode_dxt5r]      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                      ] tR t^tRtR# )BLPFormatErrorr
   N)r   r   r   r   r   r
   r   r   r_   r_      s    r   r_   c                    V ^8  d   QhRRRR/# )r   prefixr)   r!   r+   r
   )r"   s   "r   r#   r#      s     1 1E 1d 1r   c                $    V P                  R4      # )   BLP1)rc      BLP2)
startswith)ra   s   &r   _acceptrf      s    /00r   c                  .    ] 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"   s   "r   r#   BlpImageFile.__annotate__  s     Q Qt Qr   c                	   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 <irc   rO   <b<IIRGBARGBNr/   r/   )fpreadmagicrf   reprr_   r4   unpackseekosSEEK_CUR_sizedecode_moder   _Tilesizetile)	selfmsgcompressionr*   encodingalpha_encodingargsoffsetdecoders	   &        r   _open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   )r   r~   rx   r   N)	r   r   r   r   __doc__r"   format_descriptionr   r   r
   r   r   rh   rh      s      F1Q Qr   rh   c                      ] 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                    V ^8  d   QhRRRR/# )r   bufferz$bytes | Image.SupportsArrayInterfacer!   ztuple[int, int]r
   )r"   s   "r   r#   _BLPBaseDecoder.__annotate__)  s      A o r   c                	     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)r/   )_read_header_loadr4   errorOSError)r   r   er   s   &&  r   r   _BLPBaseDecoder.decode)  sJ    	&JJL  || 	&&C#,A%	&s    $ AAAc                   V ^8  d   QhRR/# rk   r
   )r"   s   "r   r#   r   3  s      t r   c                	    R # Nr
   r   s   &r   r   _BLPBaseDecoder._load2  s    r   c                   V ^8  d   QhRR/# rk   r
   )r"   s   "r   r#   r   6  s     G Gd Gr   c                	    \         P                  ! R V P                  ^@4      4      V n        \         P                  ! R V P                  ^@4      4      V n        R# )<16IN)r4   rz   
_safe_read_offsets_lengthsr   s   &r   r   _BLPBaseDecoder._read_header6  s8    fdoof.EFfdoof.EFr   c                    V ^8  d   QhRRRR/# )r   lengthr    r!   r)   r
   )r"   s   "r   r#   r   :  s     5 5 5 5r   c                	d    V P                   f   Q h\        P                  ! V P                   V4      # r   )fdr   r   )r   r   s   &&r   r   _BLPBaseDecoder._safe_read:  s)    ww"""##DGGV44r   c                   V ^8  d   QhRR/# )r   r!   list[tuple[int, int, int, int]]r
   )r"   s   "r   r#   r   >  s      > r   c                	    . p\        R 4       F@  p \        P                  ! RV P                  ^4      4      w  r4rVTP                  Y4YV34       KB  	  V#   \        P                   d      T# i ; i)   <4B)r3   r4   rz   r   r   append)r   r8   r   rI   rH   rG   rF   s   &      r   _read_palette_BLPBaseDecoder._read_palette>  sm    sA#]]5$//!2DE
a JJa|$  
 << 
s   )AA.-A.c               $    V ^8  d   QhRRRRRR/# )r   paletter   r*   r+   r!   r2   r
   )r"   s   "r   r#   r   H  s$      6?C	r   c                	^   \        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)	r2   r   r   r   r4   rz   rw   r   r6   )r   r   r*   r(   _datar   rI   rH   rG   rF   ds   &&&        r   
_read_bgra_BLPBaseDecoder._read_bgraH  s     {a(89:"MM$

1>	 !JA!"#AT	KKN <<  s   (B B,+B,)r   r   N)r   r   r   r   	_pulls_fdr   abcabstractmethodr   r   r   r   r   r   r
   r   r   r   r   &  s@    I 	 G5 r   r   c                  .    ] tR tRtR R ltR R ltRtR# )BLP1DecoderiZ  c                   V ^8  d   QhRR/# rk   r
   )r"   s   "r   r#   BLP1Decoder.__annotate__[  s     & &t &r   c                	   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)ro      )r   _compression	_encodingr	   r   _decode_jpeg_streamr   r   
set_as_rawry   r_   )r   r*   r   r(   r   s   &    r   r   BLP1Decoder._load[  s    379904>5+$$&!#~~',,.w6%1$t~~2F1GH$S))0dnn1E0FGC %%r   c                   V ^8  d   QhRR/# rk   r
   )r"   s   "r   r#   r   m  s     ? ?T ?r   c                	*   ^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   )JpegImageFilerO   NCMYK)r   rt   BGR)JpegImagePluginr   r4   rz   r   r   r   tellr   r   r   _decompression_bomb_checkr   moder   r   
isinstancetuple_replacer   converttobytes)r   r   jpeg_header_sizejpeg_headerr(   imager   s   &      r   r   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   r   r   r   r
   r   r   r   r   Z  s    &$? ?r   r   c                  "    ] tR tRtR R ltRtR# )BLP2Decoderi  c                   V ^8  d   QhRR/# rk   r
   )r"   s   "r   r#   BLP2Decoder.__annotate__  s     , ,t ,r   c                	   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 )r   r   r   _alpha_encodingr   r   r{   r   r   r   r   r   r2   r   r   statexsizer3   ysizerJ   r   r   rU   r   r]   ry   r_   r   )r   r*   r   r(   linesizeybr   r   s   &       r   r   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   r   r   r
   r   r   r   r     s    , ,r   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	
BLPEncoderi  Tc                   V ^8  d   QhRR/# )r   r!   r)   r
   )r"   s   "r   r#   BLPEncoder.__annotate__  s     	 	 	r   c           	     	R   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   rs   r   i   s       )im
getpaletter3   r1   r4   pack)r   r(   r   r   rG   rH   rI   rF   s   &       r   _write_paletteBLPEncoder._write_palette  s    ww"""''$$VV4s7|q()A Q!a%15JA!FKKqQ22D * $i'!KDr   c                    V ^8  d   QhRRRR/# )r   bufsizer    r!   ztuple[int, int, bytes]r
   )r"   s   "r   r#   r     s     " "c "&< "r   c           
     	   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# )   r   r   )r/   r/   r/   r/   r/   r/   r/   r/   r/   r/   r/   r/   r/   r/   r/   )r   r1   r4   r   r   r   r3   getpixel)	r   r   palette_datar   r(   whyxs	   &&       r   encode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   
_pushes_fdr   r   r   r
   r   r   r   r     s    J	" "r   r   c               (    V ^8  d   QhRRRRRRRR/# )	r   r   zImage.Imagerv   z	IO[bytes]filenamezstr | bytesr!   rl   r
   )r"   s   "r   r#   r#     s.     T Tk Ty TK TD Tr   c           
        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# )PzUnsupported BLP image modeblp_versionBLP1rc   rd   Nrp   rs   z<Lrq   rr   ri   ru   )r   
ValueErrorencoderinfogetwriter   r4   r   r   r   r   r   _saver   )r   rv   r  r   rx   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  BLP2ri   )F)(r   
__future__r   r   r|   r4   enumr   ior   typingr    r   r   r	   r   r   r&   rJ   rU   r]   NotImplementedErrorr_   rf   rh   ABC	PyDecoderr   r   r   	PyEncoderr   r  register_openr"   register_extensionregister_decoderregister_save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   