
    \
j}1              	       	   d dl mZ d dlT d dlT d dlT d dlT d dlmZ d dlm	Z
 ej        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dZdZdZdZdZdZ dZ! G d de"          Z# G d de"          Z$ G d de"          Z% G d de"          Z& G d  d!e"          Z' e(e)          Z* e(e+          Z,e-ej.        _/        e0e0e+e-e0gej.        _1        e-ej2        _/        e0e0gej2        _1        e-ej3        _/        e0e0gej3        _1        e-ej4        _/        e-e-e-e- e(e5          e0gej4        _1        e-ej6        _/        e0e0gej6        _1        e-ej7        _/        e0ee)e-e0gej7        _1        e-ej8        _/        e9e0e0gej8        _1        d"ej:        _/        e0gej:        _1        e-ej;        _/        e-e0gej;        _1        e-ej<        _/        e0gej<        _1        e-ej=        _/        e0e9e-e0e0e0e0gej=        _1        e-ej>        _/        e?e9e@gej>        _1        e-ejA        _/        e0e-gejA        _1        e-ejB        _/        e0e*gejB        _1        e-ejC        _/        e0e)e0e*gejC        _1        e-ejD        _/        e0 e(e           e(e          gejD        _1        e-ejE        _/        e0e0gejE        _1        e-ejF        _/        e0e0gejF        _1        e-ejG        _/        e0eHeHe0gejG        _1        e-ejI        _/        e0eHe,gejI        _1        e-ejJ        _/        e0e-gejJ        _1        e-ejK        _/        e0e0e,gejK        _1        e-ejL        _/        e0e,gejL        _1        e-ejM        _/        e0e0e+gejM        _1        e-ejN        _/        e0e0e+gejN        _1        e-ejO        _/        e0e9e-e0e0e0e0e*e*g	ejO        _1        e-ejP        _/        e0gejP        _1        e-ejQ        _/        e0e0e-gejQ        _1        e-ejR        _/        e0e-gejR        _1        e-ejS        _/        e0e-gejS        _1        e-ejT        _/        e0e-gejT        _1        e-ejU        _/        e0gejU        _1        d"ejV        _/         e(eW          gejV        _1        e-ejX        _/        e0e0e0gejX        _1         G d# d$eY          ZZd% Z[d& Z\d' Z] e]             d"S )(    )	pIUnknown)*)	_kernel32)_ole32i i i i i i i i i	  i
 & i  i0 i@4 i             i Q  c                   *    e Zd ZdefdefdefdefgZdS )GdiplusStartupInputGdiplusVersionDebugEventCallbackSuppressBackgroundThreadSuppressExternalCodecsN)__name__
__module____qualname__c_uint32c_void_pBOOL_fields_     U/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/image/codecs/gdiplus.pyr   r   H   s5        	8$	x(	#T*	!4(	HHHr   r   c                       e Zd ZdefdefgZdS )GdiplusStartupOutputNotificationHookProcNotificationUnhookProcN)r   r   r   r   _fieldsr   r   r   r   r   Q   s%        	*	!8,GGGr   r   c            	       Z    e Zd Zdefdefdefdefd ee          fd ee          fgZdS )
BitmapDataWidthHeightStridePixelFormatScan0ReservedN)r   r   r   c_uintc_intPOINTERc_byter   r   r   r   r!   r!   X   sU        	&	6	5		''&//"	WWV__%HHHr   r!   c                   *    e Zd ZdefdefdefdefgZdS )RectXYr"   r#   N)r   r   r   r)   r   r   r   r   r-   r-   c   s3        	e	e	%	5	HHHr   r-   c                   *    e Zd ZdefdefdefdefgZdS )PropertyItemidlengthtypevalueN)r   r   r   r(   c_ulongc_shortr   r   r   r   r   r1   r1   l   s4        	v	7		(	HHHr   r1   Nc                   H    e Zd Zd Zd Zd Zed             Zd Zd Z	d Z
dS )	GDIPlusDecoderc                 
    g dS )N)z.bmp.gifz.jpgz.jpegz.exifz.pngz.tifz.tiffr   selfs    r   get_file_extensionsz"GDIPlusDecoder.get_file_extensions   s       	r   c                     dgS )Nr;   r   r<   s    r   get_animation_file_extensionsz,GDIPlusDecoder.get_animation_file_extensions   s     xr   c                 Z   |                                 }t          j        t          t	          |                    }t          j        |          }t          ||t	          |                     t          j        |           t                      | _	        t          j        |dt          | j	                             t                      }t                              | j	        t          |                    }|dk    r-| j	                                         t#          d|p|z            |S )NTr   zGDI+ cannot load %r)readkernel32GlobalAllocGMEM_MOVEABLElen
GlobalLockmemmoveGlobalUnlockr   streamole32CreateStreamOnHGlobalbyrefr   gdiplusGdipCreateBitmapFromStreamReleaseImageDecodeException)r=   filefilenamedatahglobptrbitmapstatuss           r   _load_bitmapzGDIPlusDecoder._load_bitmap   s    yy{{ $]CII>>!%((T3t99%%%e$$$  kk#E4t{1C1CDDD 33DKvOOQ;;K!!!&'<@PD'QRRRr   c           	         t                      }t                      }t                              | t          |          t          |                     t	          |j                  }t	          |j                  }t                      }t                              | t          |                     |j        }d}|t          k    rd}nE|t          k    rn9|t          k    rn-|t          t          t          t          fv rt          }n	d}t          }t                      }d|_        d|_        ||_        ||_        t)                      }t                              | t          |          t,          |t          |                     t/          |j        |z            }t3          ||j        t7          |                     t                              | t          |                     t;          |||||j                   S )NBGRABGRr   )REALrN   GdipGetImageDimensionrM   intr5   r)   GdipGetImagePixelFormatPixelFormat24bppRGBPixelFormat32bppRGBPixelFormat32bppARGBPixelFormat16bppARGB1555PixelFormat32bppPARGBPixelFormat64bppARGBPixelFormat64bppPARGBr-   r.   r/   r"   r#   r!   GdipBitmapLockBitsImageLockModeReadcreate_string_bufferr$   rH   r&   rF   GdipBitmapUnlockBits	ImageData)rW   widthheightpffmtrectbitmap_databuffers           r   
_get_imagezGDIPlusDecoder._get_image   s    %%feEllE&MMJJJEK  V\"" WW''b		:::X $$$CC&&&''',.C(*?A A A%BBC$B vv
 ll""65;;8I2uU`OaOabbb &k&86&ABB)3v;;777 	$$VU;-?-?@@@Vk6H5HIIIr   c                 l    t                               |           | j                                         d S N)rN   GdipDisposeImagerJ   rP   )r=   rW   s     r   _delete_bitmapzGDIPlusDecoder._delete_bitmap  s0      (((r   c                     |                      ||          }|                     |          }|                     |           |S rv   )rY   rt   rx   )r=   rR   rS   rW   images        r   decodezGDIPlusDecoder.decode  sA    ""422''F###r   c                    |                      ||          }t                      }t                              |t	          |                     |j        dk     r$|                     |           t          d          t          |j        z              }t          	                    |||j                   t                      }t          
                    ||t	          |                     t          }t                      }t                              ||t	          |                     t          |j                  }	t          |	t          t                               j        }
t                              |||j        |	           |
j        t)          t*                    z  }t          |
j        t          t*          |z                      j        }g }t-          |j                  D ]i}t                              |||           |                     |          }||         }|dk    rd}|                    t5          ||dz                       j|                     |           t7          |          S )Nr   zImage has no frame dimensions
   g      Y@)rY   r(   rN    GdipImageGetFrameDimensionsCountrM   r5   rx   rQ   r   GdipImageGetFrameDimensionsListGdipImageGetFrameCountPropertyTagFrameDelayGdipGetPropertyItemSizec_buffercastr*   r1   contentsGdipGetPropertyItemr3   sizeofc_longrangeGdipImageSelectActiveFramert   appendAnimationFrame	Animation)r=   rR   rS   rW   dimension_count
dimensionsframe_countprop_id	prop_sizeprop_buffer	prop_itemn_delaysdelaysframesirz   delays                    r   decode_animationzGDIPlusDecoder.decode_animation  s   ""422 ((009O9OPPP 1$$'''&'FGGG !6699
//
ODYZZZhh&&vz5;M;MNNN'HH	''y9I9IJJJy//gl&;&;<<E	##FGY_kRRR#vf~~5iowv/@'A'ABBK{()) 	= 	=A..vz1EEEOOF++E1IEzzMM.d
;;<<<<F###   r   N)r   r   r   r>   r@   rY   staticmethodrt   rx   r{   r   r   r   r   r9   r9      s            
  , ,J ,J \,J\  
  (! (! (! (! (!r   r9   c                       t                      gS rv   )r9   r   r   r   get_decodersr   D  s    r   c                      g S rv   r   r   r   r   get_encodersr   H  s    Ir   c                      t                      } t                      }d|_        t                      }t                              t          |           t          |          t          |                     d S )Nr   )r6   r   r   r   rN   GdiplusStartuprM   )token
startup_instartup_outs      r   initr   L  s]    IIE$&&J !J&((K5<<z):):E+<N<NOOOOOr   )^pyglet.libs.win32.comr   pyglet.imagepyglet.image.codecspyglet.libs.win32.constantspyglet.libs.win32.typespyglet.libs.win32r   rC   r   rK   windllrN   c_floatr]   PixelFormat1bppIndexedPixelFormat4bppIndexedPixelFormat8bppIndexedPixelFormat16bppGrayScalePixelFormat16bppRGB555PixelFormat16bppRGB565rd   ra   rb   rc   re   PixelFormat48bppRGBrf   rg   PixelFormatMaxri   ImageLockModeWriteImageLockModeUserInputBufr   	Structurer   r   r!   r-   r1   r*   INTINT_PTRUINTUINT_PTRr)   rh   restyper   argtypesrk   GdipCloneStringFormatGdipCreateBitmapFromScan0BYTErO   GdipCreateFontGdipCreateFontFamilyFromName	c_wchar_pGdipCreateMatrixGdipCreateSolidFillrw   GdipDrawStringGdipGetFamilyNameLONG_PTRc_wchar	GdipFlush GdipGetFontCollectionFamilyCountGdipGetFontCollectionFamilyListr^   GdipGetImageGraphicsContextr`   r   r(   r   GdipGraphicsClearr   r~   r   r   GdipMeasureStringGdipNewPrivateFontCollectionGdipPrivateAddMemoryFontGdipSetPageUnitGdipSetStringFormatFlagsGdipSetTextRenderingHint%GdipStringFormatGetGenericTypographicGdiplusShutdownULONGr   ImageDecoderr9   r   r   r   r   r   r   <module>r      sG  H , + + + + +     ! ! ! ! ) ) ) ) % % % % 3 3 3 3 3 3 - - - - - - ." " " # " " " " " # " # # $         )       9              9       9    '#,,74== &+  "'/4&Q  #',  $)18(<  %(-  %*2H)=  &,1 ! ).3UE5''RV--Ya-b ! *-2 " */7.B " +!&  #+T3x"H  /4 $ ,1:Hh0O $ -#'   %-J  !&+  #(-x'8  $#(   %-J  !!&  #+YxS[]e"f  $)  !&.	7%C  "!  &.  38 ( 05=w4G ( 127 ' /4<c8W3U ' 0(-  %*2GGDMM774==)Q  &.3 # +08(/C # ,*/  ',4h+?  (&+  #(0&&('K  $*/  ',4fh+G  ($)  !&.%6  ").  &+3Xx*H  '38 ( 05=x4H ( 127 ' /4<h3M ' 0-2 " */74.H " +$)  !&.	5(HV^`hjqsz%{  "/4 $ ,19
 $ -+0   (-5x,G   )"'  $,e#4   +0   (-5u,=   )+0   (-5u,=   )8= - 5:B - 6"&  $+GENN#3   !&  #+Xx"@  B! B! B! B! B!\ B! B! B!J    P P P r   