
    \
jaW                        d dl T d dlT d dlmZ d dlmZ d dlT d dlT e	
                    dddddd	d
dddd          Ze	
                    ddddddddddd          ZereZneZeZd ZdZdZdZeZd ZeZd ZdZdZdZdZdZeZd Zd Z dZ!dZ"dZ#d Z$d!Z%d"Z&d#Z'dZ(dZ)dZ*eZ+d Z,dZ-dZ.eZ/d Z0dZ1dZ2dZ3 e4e	j
                  Z5e	
                    d$d%d&d'd(d)d*d+d,d-d           Z6e	
                    d$d%d&d'd(d)d*d+d,d-d          Z7e	
                    d$d%d&d'd(d)d*d+d,d-d          Z8e	
                    d$d%d&d'd(d)d*d+d,d-d          Z9e	
                    d$d%d&d'd(d)d*d+d,d-d           Z:e	
                    d$d%d&d'd(d)d*d+d,d-d!          Z;e	
                    d$d%d&d'd(d)d*d+d,d-d"          Z<e	
                    d$d%d&d'd(d)d*d+d,d-d#          Z=e	
                    d$d%d&d'd(d)d*d+d,d-d          Z>e	
                    d.d/d0d1d(d2d3d	d4d5d6          Z?e	
                    d$d%d&d'd(d)d*d+d,d-d7          Z@e	
                    d$d%d&d'd(d)d*d+d,d-d          ZAe	
                    d8d9d:d;d<d=d>d?dd@dA          ZBe	
                    d$d%d&d'd(d)d*d+d,d-dB          ZCe	
                    d$d%d&d'd(d)d*d+d,d-dC          ZDe	
                    d$d%d&d'd(d)d*d+d,d-dD          ZEe	
                    d$d%d&d'd(d)d*d+d,d-dE          ZFe	
                    d$d%d&d'd(d)d*d+d,d-dF          ZGe	
                    d$d%d&d'd(d)d*d+d,d-d          ZHe	
                    dGdHdIdJdKdLdMdNddCdO          ZIe	
                    dPdQdRdSd5dTdUdVdWdXdY          ZJe	
                    dZd[d\d]d^d_d`dadLdbdc          ZKe	
                    d$d%d&d'd(d)d*d+d,d-dd          ZLe	
                    dedfdgdJdhdidOdjdkdldm          ZMe	
                    dndodpddLdSdqdrdsdtdu          ZNe	
                    dvdwdxdJdydzd{d`d|d}d~          ZOe	
                    ddddddddddd          ZPe	
                    ddddddMddddd          ZQe	
                    dddddddYdddd          ZRe	
                    ddddddddddd          ZSe	
                    ddddddOddd7dd          ZT G d de	jU                  ZV G d de	jU                  ZW G d deXe	jU                  ZY G d de	jU                  ZZ G d de	jU                  Z[ G d de	jU                  Z\ G d de\e	jU                  Z] G d de	jU                  Z^ G d de^e	jU                  Z_ G d de	jU                  Z` G d de^e	jU                  Za G dĄ de^e	jU                  Zb G dƄ de^e	jU                  Zc G dȄ de	jU                  Zde	
                    ddddd*ddd]dVddЦ          Zee	
                    dddd'dddddddڦ          ZferefZgneeZge	
                    ddddddd!dddd          Zh G d de	jU                  Zi ei            Zj ejk        edeleg emej                      G d den          Zod ZpeNeQeQeReReTeTeTeOd	Zq G d der          Zsd ZtdS )    )*)_ole32)	_kernel32l   br ip  iF     ;      U   9      L   
   i}1i$_  i=C        y      h                  i                     i$oiN  iK        =   w   v         l   M i  iaA     '               	   i+|i  iaI     F                                 l   k3 i>  iG     %         H      l   --k ij  iC           5   &         iP<i'  i7M        1   B               l   #L ih  iF  .   6         C      i~
i  iA     d   q         i|i?q  i<G     a   7   _         l   `PG i3  iL                 b      !   iibV  iO        X      W   i0;i  iO                    iViM}  iL                          i|Wiz6  i@E  k         :   K   c                       e Zd Zde                                fde                                fde                                fde                                fde                                fgZdS )IPropertyBag2ReadWriteCountPropertiesGetPropertyInfo
LoadObjectN__name__
__module____qualname__com	STDMETHOD	_methods_     Q/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/image/codecs/wic.pyr   r   b   st        															IIIr   r   c                      e Zd Zde                                fde                                fde                                fde                                fde                                fde                                fde                                fde                                fd	e                                fd
e                                fg
ZdS )IWICPaletteInitializePredefinedInitializeCustomInitializeFromBitmapInitializeFromPaletteGetTypeGetColorCount	GetColorsIsBlackWhiteIsGrayscaleHasAlphaNr   r   r   r   r   r   q   s        										 																				'IIIr   r   c                       e Zd Zde                    e          fde                    ee          fde                     ee	          e          fde                                fgZ
dS )
IWICStreamInitializeFromIStreamInitializeFromFilenameInitializeFromMemoryInitializeFromIStreamRegionN)r   r   r   r   r   IStreamLPCWSTRDWORDPOINTERBYTEr   r   r   r   r   r      sy        	 	w			!	!	w	&	&	(		wwt}}e	,	,	.	&			IIIr   r   c                      e Zd Zde                    e          fde                    ee          fde                                fde                    e          fde                                fde                    e          fde                                fde                    eee e	e
                    fd	e                                fd
e                                fde                                fgZdS )IWICBitmapFrameEncode
InitializeSetSizeSetResolutionSetPixelFormatSetColorContexts
SetPaletteSetThumbnailWritePixelsWriteSourceCommitGetMetadataQueryWriterN)r   r   r   r   r   r   UINTREFWICPixelFormatGUIDr   r   r   r   r   r   r   r   r      s       		}	%	%	'		tT	"	"	$					,	-	-	/					{	#	#	%					tT4	7	7	9							!		+IIIr   r   c                      e Zd Zde                    ee          fde                                fde                                fde                                fde                                fde                                fde                                fde                     ee           ee	                    fd	e                                fd
e                                fg
Z
dS )IWICBitmapEncoderr   GetContainerFormatGetEncoderInfor   r   r   
SetPreviewCreateNewFramer   r   N)r   r   r   r   r   r   WICBitmapEncoderCacheOptionr   r   r   r   r   r   r   r   r      s        		z#>	?	?	A																				ww455ww}7M7M	N	N	P				!		'IIIr   r   c            
       b   e Zd Zde                                fde                                fde                                fde                                fde                                fde                                fde                                fde                                fgZd	S )
IWICComponentInfoGetComponentTypeGetCLSIDGetSigningStatus	GetAuthorGetVendorGUID
GetVersionGetSpecVersionGetFriendlyNameNr   r   r   r   r   r      s        																								IIIr   r   c            	       *   e Zd Zde                     eej                            fde                                fde                     ee                    fde                     ee                    fde                                fgZdS )IWICPixelFormatInfoGetFormatGUIDGetColorContextGetBitsPerPixelGetChannelCountGetChannelMaskN)	r   r   r   r   r   r   GUIDr   r   r   r   r   r   r      s        		wwsx((	)	)	+					wwt}}	%	%	'		wwt}}	%	%	'			IIIr   r   c                   >   e Zd Zde                     ee           ee                    fde                    e          fde                     ee           ee                    fde                                fde                    e	eee	          fgZ
dS )IWICBitmapSourceGetSizeGetPixelFormatGetResolutionCopyPalette
CopyPixelsN)r   r   r   r   r   r   r   r   DOUBLEc_void_pr   r   r   r   r   r      s        		wwt}}ggdmm	4	4	6		,	-	-	/		wwv	8	8	:					xtX	6	6	8IIIr   r   c            	           e Zd Zde                    eeeee	e
          fde                    ee ee                    fgZdS )IWICFormatConverterr   
CanConvertN)r   r   r   r   r   r   r   WICBitmapDitherTyper   r   WICBitmapPaletteTyper   BOOLr   r   r   r   r   r      sh        		')>@SU]_e+
- 
-	. 
	,.CWWT]]	S	S	U	IIIr   r   c                       e Zd Zde                                fde                                fde                    ee          fde                                fgZdS )IWICMetadataQueryReaderr   GetLocationGetMetadataByNameGetEnumeratorN)r   r   r   r   r   r   r   r   r   r   r   r   r     sg        								w	)	)	+				IIIr   r   c                       e Zd Zde                     ee                    fde                                fde                     ee                    fgZdS )IWICBitmapFrameDecodeGetMetadataQueryReaderGetColorContextsGetThumbnailN)	r   r   r   r   r   r   r   r   r   r   r   r   r   r     sl        	!	ww677	8	8	:					ww/00	1	1	3IIIr   r   c                   @    e Zd Zde                    ee          fgZdS )IWICBitmapFlipRotatorr   N)r   r   r   r   r   r   WICBitmapTransformOptionsr   r   r   r   r   r      s1        		')B	C	C	EIIIr   r   c                       e Zd Zde                                fde                                fde                                fgZdS )
IWICBitmapLockr   r   Nr   r   r   r   r   r   '  sN        									IIIr   r   c                      e Zd Zde                                fde                                fde                                fde                                fde                                fde                     ee                    fde                                fde                                fd	e                                fd
e                     ee                    fde                    e ee                    fgZ	dS )IWICBitmapDecoderQueryCapabilityr   r   GetDecoderInfor   r   
GetPreviewr   r   GetFrameCountGetFrameN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   2  s       																!	ww677	8	8	:											wwt}}	%	%	'		tWW%:;;	<	<	>+IIIr   r   l   HX i  iC  T         p   iEk{i  ivD  2         $   |         l   &Q iH=  iC  D   i               c                      e Zd Zde                    eej        ee e	e
                    fde                    ej        ee e	e
                    fde                                fde                    ej         e	e                    fde                                fde                     e	ej                   e	ej                   e	e                    fde                     e	e                    fde                     e	e                    fd	e                                fd
e                                fde                     e	e                    fde                     e	e                    fde                                fde                                fde                    eeee e	e                    fde                                fde                                fde                    eeeee e	e           e	e                    fde                                fde                                fde                                fde                                fde                                fde                                fde                                fgZdS )IWICImagingFactoryCreateDecoderFromFilenameCreateDecoderFromStreamCreateDecoderFromFileHandleCreateComponentInfoCreateDecoderCreateEncoderCreatePaletteCreateFormatConverterCreateBitmapScalerCreateBitmapClipperCreateBitmapFlipRotatorCreateStreamCreateColorContextCreateColorTransformerCreateBitmapCreateBitmapFromSourceCreateBitmapFromSourceRectCreateBitmapFromMemoryCreateBitmapFromHBITMAPCreateBitmapFromHICONCreateComponentEnumerator$CreateFastMetadataEncoderFromDecoder(CreateFastMetadataEncoderFromFrameDecodeCreateQueryWriterCreateQueryWriterFromReaderN)r   r   r   r   r   r   r   r   WICDecodeOptionsr   r   	pIUnknownr   r   r   r   r   r   r   r   r   WICBitmapCreateCacheOptionr   r   r   r   r   r   r  r  X  s       	$	w%1A77K\C]C]	^	^	`	"	s}h0@''J[B\B\	]	]	_	&				sx):!;!;	<	<	>					wwsx((''#(*;*;WWEV=W=W	X	X	Z		ww{++	,	,	.	 	ww233	4	4	6							"	ww455	6	6	8		wwz**	+	+	-				!				tT#8:TV]V]^hViVi	j	j	l	!			%			!	tT#8$ggdmmU\U\]gUhUh	i	i	k	"			 			$			/			3						&		c3IIIr   r  Nc                   `     e Zd ZdZ fdZd Zd Zd ZefdZ	d Z
d Zed	             Z xZS )

WICDecoderzWindows Imaging Component.
    This decoder is a replacement for GDI and GDI+ starting with Windows 7 with more features up to Windows 10.c                 n    t          t          |                                            t          | _        d S N)superImageDecoder__init___factory)self	__class__s    r   r*  zWICDecoder.__init__  s*    lD!!**,,, r   c                 
    g dS )N)
.bmp.jpg.jpeg.png.tif.tiffz.ico.jxrz.hdp.wdpr   r,  s    r   get_file_extensionszWICDecoder.get_file_extensions  s    aaaar   c                 Z   |                                 }t          j        t          t	          |                    }t          j        |          }t          ||t	          |                     t          j        |           t          	                                }t          j        |dt          |                     t                      }| j                            |d t           t          |                    }|dk    r(|                                 t%          d|p|z            ||fS )NTr   zWIC cannot load %r)readkernel32GlobalAllocGMEM_MOVEABLElen
GlobalLockmemmoveGlobalUnlockr   r"  ole32CreateStreamOnHGlobalbyrefr   r+  r	  WICDecodeMetadataCacheOnDemandReleaseImageDecodeException)	r,  filenamefiledatahglobptrstreamdecoderstatuss	            r   _load_bitmap_decoderzWICDecoder._load_bitmap_decoder  s    yy{{ $]CII>>!%((T3t99%%%e$$$ #E4v??? $%%66vtEcejkresesttQ;;NN&';x?O4'PQQQr   c                 h    t                      }|                    |t          |                     |S r'  )r   r   rD  )r,  bitmap_decoderframe_indexbitmaps       r   _get_bitmap_framezWICDecoder._get_bitmap_frame  s.    &((U6]];;;r   c                    t                      }t                      }|                    t          |          t          |                     t          |j                  }t          |j                  }t
                              ddddddddddd          }|                    t          |                     d}||k    rt                      }| j	        
                    t          |                     t                      }|                    ||t          |                     |s	t          }d}|                    ||t          ddt                      |                                 |}t%                      }	| j	                            t          |	                     |	                    |t(                     t+          |          |z  }
|
|z  }t-          |z              }|	                    d|
|t          |                     |	                                 |                                 t1          ||||          S )zWGet's image from bitmap, specifying target format, bitmap is released before returning.r   BGRABGRN)r   r   rD  intvaluer   r   r   r   r+  r  r   r   GUID_WICPixelFormat24bppBGRr   WICBitmapDitherTypeNoneWICBitmapPaletteTypeCustomrF  r   r  WICBitmapTransformFlipVerticalr>  r   r   	ImageData)r,  rT  
target_fmtwidthheightpffmt	converterconversion_possibleflipperstridebuffer_sizebuffers                r   	get_imagezWICDecoder.get_image  s   uU||U6]]333EK  V\"" XXaAq!Q1aA66eBii(((+--IM//i0@0@AAA"&&&  Z7J1K1KLLL ' 8
  5LdTUWqrrrNNF ())--eGnn===6#ABBBSE!vo$''4eFmmDDDV444r   c                 V    |                                  |                                  d S r'  )rF  )r,  rR  rM  s      r   _delete_bitmap_decoderz!WICDecoder._delete_bitmap_decoder  s*       r   c                     |st          |d          }|                     ||          \  }}|                     |d          }|                     |          }|                     ||           |S )Nrbr   )openrP  rU  rk  rm  )r,  rI  rH  rR  rM  rT  images          r   decodezWICDecoder.decode  st     	($''D!%!:!:8T!J!J''::v&&##NF;;;r   c                     	 t                      }|                     |t          |                     |j        }t	          j        t          |                     n# t          $ r d}Y nw xY w|S )z
            Uses a metadata name and reader to return a single value. Can be used to get metadata from images.
            If failure, returns 0.
            Also handles cleanup of PROPVARIANT.
        r   )PROPVARIANTr   rD  llValrB  PropVariantClearOSError)readermetadata_nameproprZ  s       r   get_property_valuezWICDecoder.get_property_value  sx    	==D$$]E$KK@@@JE"5;;//// 	 	 	EEE	 s   AA A+*A+)r   r   r   __doc__r*  r8  rP  rU  GUID_WICPixelFormat32bppBGRArk  rm  rr  staticmethodr{  __classcell__)r-  s   @r   r%  r%    s        s s! ! ! ! !b b b  ,  
 ,H 35 35 35 35j  
     \    r   r%  c                       t                      gS r'  )r%  r   r   r   get_decodersr        LL>r   )	r/  r0  r1  r3  r4  z.wmpr5  r6  r2  c                       e Zd Zd Zd ZdS )
WICEncoderc                 $    d t           D             S )Nc                     g | ]}|S r   r   ).0exts     r   
<listcomp>z2WICEncoder.get_file_extensions.<locals>.<listcomp>&  s    666666r   )extension_to_containerr7  s    r   r8  zWICEncoder.get_file_extensions%  s    6656666r   c                 $   |                                 }t                      }t                      }t                      }t	                      }|r%t
          j                            |          d         pd}t          	                    |t                    }	t                              t          |                     |	t          k    r
d}
t          }n+t!          |j                  dk    r
d}
t          }n	d}
t$          }|j        t!          |
          z  }|                    |
|           }||j        z  }|rGt-                      }t/          j        d dt          |                     |                    |           n|                    |t6                     t                              |	d t          |                     |                    |t<                     |                    t          |          t          |                     |                    |           |                     |j        |j                   |!                    t          |                     tD          |z  #                    tI          |                    }|%                    |j        |||           |&                                 |&                                 |rtO                      }|(                    t          |          d           |j)        }|*                    dtV          d            tE          |z              }tY                      }|-                    t          |          |t          |                     |j.        |k    r|/                    |           nta          d|            |1                                 |1                                 |1                                 |1                                 |1                                 d S )	Nr   r2  rX  r   rW  Tr   z>Failed to read all of the data from stream attempting to save )2get_image_datar   r   r   r   ospathsplitextr  getGUID_ContainerFormatPngr+  r  rD  GUID_ContainerFormatJpegr[  r>  formatr}  ra  get_datarb  r   rB  rC  r   r   GENERIC_WRITEr  r   WICBitmapEncoderNoCacher   r   r   r   from_buffer	bytearrayr   r   STATSTGStatcbSizeSeekSTREAM_SEEK_SETULONGr   rZ  writeprintrF  )r,  rq  rI  rH  	wicstreamencoderframeproperty_bagr  	containerrd  default_formatpitch
image_datasizeistreamrJ  stsstream_sizebufwrittens                        r   encodezWICEncoder.encode(  sn   $$&&LL	#%%%''$9BG,,X66q9Df +..s4KLL	eI..///000C8NN 5<  A%%!<!=c#hh&^^C%00
u|# 	FiiG'dE'NNCCC++G4444,,X}EEEy$g???9&=>>>uU||U<-@-@AAA&&&ek5<000U>22333t((:)>)>??%,tT::: 	))CLLsQ'''*KLLOT222+%((CggGLLs[%..AAA}++

3]W[]]^^^OOr   N)r   r   r   r8  r  r   r   r   r  r  $  s7        7 7 7Q Q Q Q Qr   r  c                       t                      gS r'  )r  r   r   r   get_encodersr  |  r  r   )upyglet.imagepyglet.image.codecspyglet.libs.win32r   rB  r   r;  pyglet.libs.win32.constantspyglet.libs.win32.typesr   r   CLSID_WICImagingFactory1CLSID_WICImagingFactory2WINDOWS_8_OR_GREATERCLSID_WICImagingFactoryr   r#  WICBitmapNoCacheWICBitmapCacheOnDemandWICBitmapCacheOnLoad&WICBITMAPCREATECACHEOPTION_FORCE_DWORDr   r]  r   WICBitmapTransformRotate0WICBitmapTransformRotate90WICBitmapTransformRotate180WICBitmapTransformRotate270 WICBitmapTransformFlipHorizontalr^  r   r\  WICBitmapDitherTypeSolidWICBitmapDitherTypeOrdered4x4WICBitmapDitherTypeOrdered8x8WICBitmapDitherTypeOrdered16x16WICBitmapDitherTypeSpiral4x4WICBitmapDitherTypeSpiral8x8 WICBitmapDitherTypeDualSpiral4x4 WICBitmapDitherTypeDualSpiral8x8!WICBitmapDitherTypeErrorDiffusionWICBITMAPDITHERTYPE_FORCE_DWORD%WICBITMAPTRANSFORMOPTIONS_FORCE_DWORDr!  rE  WICDecodeMetadataCacheOnLoad"WICMETADATACACHEOPTION_FORCE_DWORDr   WICBitmapEncoderCacheInMemoryWICBitmapEncoderCacheTempFiler  'WICBITMAPENCODERCACHEOPTION_FORCE_DWORDr   r   GUID_WICPixelFormatDontCareGUID_WICPixelFormat1bppIndexedGUID_WICPixelFormat2bppIndexedGUID_WICPixelFormat4bppIndexedGUID_WICPixelFormat8bppIndexedGUID_WICPixelFormatBlackWhiteGUID_WICPixelFormat2bppGrayGUID_WICPixelFormat4bppGrayGUID_WICPixelFormat8bppGrayGUID_WICPixelFormat8bppAlphaGUID_WICPixelFormat16bppBGR555GUID_WICPixelFormat16bppBGR565 GUID_WICPixelFormat16bppBGRA5551GUID_WICPixelFormat16bppGrayr[  GUID_WICPixelFormat24bppRGBGUID_WICPixelFormat32bppBGRr}  GUID_WICPixelFormat32bppPBGRAGUID_WICPixelFormat32bppRGBGUID_WICPixelFormat32bppRGBAGUID_WICPixelFormat32bppPRGBAGUID_WICPixelFormat48bppRGBGUID_WICPixelFormat48bppBGRGUID_ContainerFormatBmpr  GUID_ContainerFormatIcor  GUID_ContainerFormatTiffGUID_ContainerFormatGifGUID_ContainerFormatWmpr"  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   IID_IWICImagingFactory1IID_IWICImagingFactory2IID_IWICImagingFactoryIID_IWICPixelFormatInfor  r+  CoCreateInstanceCLSCTX_INPROC_SERVERrD  r)  r%  r  r  ImageEncoderr  r  r   r   r   <module>r     s3       ! ! ! ! - - - - - - 3 3 3 3 3 3 ) ) ) ) % % % % 88JdDRVX\^bdhjmnn 88JdDRVX\^bdhjnoo   766!    )3 &       ! ! #&  !%     #  # "% " " #&  #&  $' !", (2 % !" " %/ ""  #  #  *4 '  )) !hhz664tUY[_aegkmqrr !$*ffdDRVX\^bdhjnpt!u!u !$*ffdDRVX\^bdhjnpt!u!u !$*ffdDRVX\^bdhjnpt!u!u !$*ffdDRVX\^bdhjnpt!u!u  #VVT4QUW[]acgimos t t !hhz664tUY[_aegkmqrr !hhz664tUY[_aegkmqrr !hhz664tUY[_aegkmqrr "xx
FFD$PTVZ\`bfhlnrss !$*ffdDRVX\^bdhjnpt!u!u !$*ffdDRVX\^bdhjnpt!u!u #&88JdTXZ^`dfjlprv#w#w  "xx
FFD$PTVZ\`bfhlnrss !hhz664tUY[_aegkmqrr !hhz664tUY[_aegkmqrr !hhz664tUY[_aegkmqrr "xx
FFD$PTVZ\`bfhlnrss  #VVT4QUW[]acgimos t t !hhz664tUY[_aegk'+- - "xx
FFD$PTVZ\`bfhlnrss  #VVT4QUW[]acgimos t t !hhz664tUY[_aegkmqrr !hhz664tUY[_aegkmqrr ((:vvtT4QUW[]acgimnn ((:vvtT4QUW[]acgimnn ((:vvtT4QUW[]acgimnn 88JdDRVX\^bdhjnoo 88JdDRVX\^bdhjnoo ((:vvtT4QUW[]acgimnn ((:vvtT4QUW[]acgimnn     CM       #-   2
 
 
 
 
#- 
 
 
    CM   6       2       *    +S]       s}       *CM   
 
 
 
 
cm 
 
 
    ,cm       ,cm       !3=          6 ((:vvtT4QUW[]acgimnn ((:vvtT4QUW[]acgimnn  544((:vvtT4QUW[]acgimnn 4 4 4 4 4 4 4 4n   .+-uX	( ( (x x x x x x x xv  
 $$%$%####
 
 U U U U U U U Up    r   