+
    KiQ  c                   s$   R t ^ RIt^ RIt^ RIHt ^ RIHt  ^ RItRtRt
Rt]P                  ! R4      t]P                  ! 4         ! R R]4      t ! R	 R
]4      t ! R R]4      t ! R R]4      t ! R R4      t. ROtR#   ]	 d    RtRt Lpi ; i)a  
The MIT License (MIT)

Copyright (c) 2015-2016 Fadhil Mandaga
Copyright (c) 2019-2025 James Lu <james@overdrivenetworks.com>
Copyright (c) 2025 Hoang Cao Tri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
N)BytesIO)ImageTFZ
icoextractc                   s    ] tR t^4tRtRtR# )IconExtractorErrorz2Superclass for exceptions raised by IconExtractor. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       B/usr/lib/python3.14/site-packages/lutris/util/wine/extract_icon.pyr   r   4   s    <r   r   c                   s    ] tR t^8tRtRtR# )IconNotFoundErrorzRException raised when extracting an icon index or resource ID that does not exist.r   Nr   r   r   r   r   r   8   s    \r   r   c                   s    ] tR t^<tRtRtR# )NoIconsAvailableErrorz>Exception raised when the input program has no icon resources.r   Nr   r   r   r   r   r   <   s    Hr   r   c                   s    ] tR t^@tRtRtR# )InvalidIconDefinitionErrorzEException raised when the input program has an invalid icon resource.r   Nr   r   r   r   r   r   @   s    Or   r   c                   sJ   a  ] tR t^Dt o RR ltRV 3R lR lltR	R ltRtV tR# )
IconExtractorNc                s   \         P                  ! WRR7      V n        V P                  P                  \         P                  R,          4       \        V P                  R4      '       g   \        R4      h\        V P                  P                  P                  4       Uu/ uF  q3P                  VbK  	  ppVP                  \         P                  R,          4      V n        V P                  '       g   \        R4      hVP                  \         P                  R,          4      V n        \        V P                  P                   P                  4       UUu/ uF  w  rVVP"                  P$                  VbK  	  uppV n        V P                  P                   P                   Uu/ uF+  pVP                  VP                   P                  ^ ,          bK-  	  upV n        R	# u upi u uppi u upi )
z
Loads an executable from the given `filename` or `data` (raw bytes).
As with pefile, if both `filename` and `data` are given, `filename` takes precedence.

If the executable has contains no icons, this will raise `NoIconsAvailableError`.
T)ZnamedataZ	fast_loadZIMAGE_DIRECTORY_ENTRY_RESOURCEDIRECTORY_ENTRY_RESOURCEzFile has no resourcesZRT_GROUP_ICONz File has no group icon resourcesZRT_ICONN)pefileZPE_peZparse_data_directoriesZDIRECTORY_ENTRYZhasattrr   Zreversedr   entriesZidZgetZRESOURCE_TYPEgroupiconres	rticonresZ	enumerate	directorystructName_group_icons_icons)selfZfilenamer   ZrsrcZ	resourcesZidxZentryZicon_entry_lists   &&&     r   __init__ZIconExtractor.__init__E   sx    99(F''(>(>?_(`atxx!;<<'(?@@
 088Y8Y8a8a/bc/btWWd]/b	c%MM&*>*>*OP   '(JKK"v';';I'FG GPPTPaPaPkPkPsPsFtuFt
U\\..3Ftu $(>>#;#;#C#C
#C  9 9 A A! DD#C
 d v
s    G"G##1G)c                s    < V ^8  d   QhRS[ /# )i   index)Zint)Zformat__classdict__s   "r   Z__annotate__ZIconExtractor.__annotate__e   s     7 7s 7r   c                s    V P                   P                  P                  V,          pTP
                  P                  pRpTP
                  P                  '       dJ   TP                  P                  ^ ,          pTP
                  P                  p\        P                  RT4       TP                  P
                  P                  pT P                  P                  YRP                  P
                  P                  4      pT P                  P                  T4      pT P                  P!                  \"        Yg4      p\        P                  RTTTP$                  T4       TP&                  '       d&   \)        R\+        TP&                  4      ,          4      h. p	TP-                  4       p
\/        TP$                  4       EF  pT P                  P!                  \0        YjR Yz,           4      pYP-                  4       ,          p
\        P                  RY4       T P2                  TP4                  ,          pT P                  P                  TP                  P
                  P                  TP                  P
                  P                  4      p\        P                  RTP4                  TP                  P
                  4       T	P7                  Y34       EK  	  T	#   \         d    \	        RT 24      Rhi ; i)zp
Returns the specified group icon in the binary.

Result is a list of (group icon structure, icon data) tuples.
zNo icon exists at index NzPicking first language %sz)Group icon %d has ID %s and %d images: %sz<Invalid group icon definition (got Reserved=%s instead of 0)zGot group icon entry %d: %szGot icon data for ID %d: %s)r   r   r   Z
IndexErrorr   r   r   ZDataIsDirectoryloggerZdebugr   ZOffsetToDatar   Zget_dataZSizeZget_offset_from_rvaZ__unpack_data__GRPICONDIR_FORMATZCountZReservedr   ZhexZsizeofZrangeGRPICONDIRENTRY_FORMATr   ZIDZappend)r   r   Z	groupiconZresource_idZ	icon_langZrvaZgrp_icon_dataZfile_offsetZgrp_icon_dirZ	grp_iconsZicon_offsetZgrp_icon_indexgrp_iconZ
icon_entry	icon_datas   &&             r   	_get_iconZIconExtractor._get_icone   sQ   	R))33;;EBI  &&++	+++!++33A6I!((--ILL4i@ nn##00))#~~/D/D/I/IJhh2237xx//0A=^7	
    ,NQTUaUjUjQkk  	"))+#L$6$67Nxx//&l(C[E^H ??,,KLL6QX[[1J))*//*@*@*M*MzOeOeOjOjkILL6Z__E[E[\h23 8 _  	R#&>ug$FGTQ	Rs   'K K2c           
     s   V P                  4       pRpRpV Fx  w  rVVP                  ;'       g    RpVP                  ;'       g    RpVP                  ;'       g    ^ p	Wq8X  d	   W8X  d   RMV	^
,          Wx,          ,           p
W8  g   Ks  T
pWV3pKz  	  V'       g   R# \	        4       ;_uu_ 4       pVP                  R\        P                  ! R^^4      ,           V^ ,          P                  4       R,          ,           \        P                  ! R^4      ,           V^,          ,           4       VP                  ^ 4       \        P                  ! V4      uuRRR4       #   + '       g   i     R# ; i)	zl
Extract best matching icon closest to specified size

Returns PIL Image object or None if extraction fails
Ni   s     z<HH:Ni   Nz<Iii   )r&   ZWidthZHeightZBitCountr    Zwriter   ZpackZ__pack__Zseekr   Zopen)r   ZsizeZiconsZ
best_scoreZiconr$   r%   ZwidthZheightZ	bit_countZscoreZbuffers   &&          r   get_best_iconZIconExtractor.get_best_icon   s,     
#(HNN))cE__++F ))//RI"'-FNW)WY/^c^lImE!"
 , $)  YY&LL++eQ*+ Q  "3'( ++dB'( q'
 KKN::f% YYY s   /B"EE-	)r   r   r   r   r   )NN)i    )i   )	r   r   r   r   r   r&   r'   r
   Z__classdictcell__)r    s   @r   r   r   D   s      
@7 7r% %r   r   )ZGRPICONDIRENTRY)zB,WidthzB,HeightzB,ColorCountz
B,ReservedzH,Planesz
H,BitCountzI,BytesInReszH,ID)Z
GRPICONDIR)z
H,ReservedzH,TypezH,Count)r   r   r   r   )r	   Zloggingr   Zior    ZPILr   r   ZPEFILE_AVAILABLEZImportErrorr#   r"   Z	getLoggerr!   ZbasicConfigZ	Exceptionr   r   r   r   r   Z__all__r   r   r   <module>r(      s   6    
  H 			<	(    = =]* ]I. IP!3 P D iA  Fs   B BB