
    ^j                    2   d Z ddlmZ ddlZddlmZmZmZm	Z	m
Z
 ddlmZ  G d de          Z e            Zej        Zej        Zej        Zej        Zej        Z G d d	e	          Z G d
 de
          Z G d de          Z G d de          Zd ZdS )a  Collection of image encoders and decoders.

Modules must subclass ImageDecoder and ImageEncoder for each method of
decoding/encoding they support.

Modules must also implement the two functions::

    def get_decoders():
        # Return a list of ImageDecoder instances or []
        return []

    def get_encoders():
        # Return a list of ImageEncoder instances or []
        return []

    )annotationsN)CodecRegistryDecoderEncoderDecodeExceptionEncodeException)compat_platformc                  :     e Zd ZdZ fdZ fdZddZd Z xZS )_ImageCodecRegistryzBSubclass of CodecRegistry that adds support for animation methods.c                V    i | _         t                                                       d S N)_decoder_animation_extensionssuper__init__)self	__class__s    W/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/image/codecs/__init__.pyr   z_ImageCodecRegistry.__init__   s'    -/*    c                   t                                          |           |                                D ]L}|                                D ]5}|| j        vr
g | j        |<   | j        |                             |           6MdS )z;Override the default method to also add animation decoders.N)r   add_decodersget_decodersget_animation_file_extensionsr   append)r   moduledecoder	extensionr   s       r   r   z _ImageCodecRegistry.add_decoders    s    V$$$**,, 	N 	NG$BBDD N N	D$FFFDFD6yA29=DDWMMMMN	N 	Nr   Nc                    |rRt           j                            |          d                                         }| j                            |g           S | j        S )zGet a list of animation decoders. If a `filename` is provided, only
           decoders supporting that extension will be returned. An empty list
           will be return if no encoders for that extension are available.
           )ospathsplitextlowerr   get	_decoders)r   filenamer   s      r   get_animation_decodersz*_ImageCodecRegistry.get_animation_decoders)   sT    
  	I((2215;;==I599)RHHH~r   c                   d }|                      |          D ]E}	  |j        ||fi |c S # t          $ r%}|s|}|r|                    d           Y d }~>d }~ww xY w|                                  D ]:}	  |j        ||fi |c S # t          $ r |r|                    d           Y 7w xY w|sd| }t          |          |)Nr   z*No decoders available for this file type: )r&   decode_animationr   seek)r   r%   filekwargsfirst_exceptionr   emsgs           r   r(   z$_ImageCodecRegistry.decode_animation3   s8   228<< 	! 	!G!/w/$II&IIIII" ! ! !& (&'O !IIaLLL	! 2244 	! 	!G!/w/$II&IIIII" ! ! ! !IIaLLL!  	'IxIIC!#&&&s&   ,
AAA5B!B*)B*r   )	__name__
__module____qualname____doc__r   r   r&   r(   __classcell__)r   s   @r   r   r      s        LL    N N N N N         r   r   c                      e Zd ZdS )ImageDecodeExceptionNr/   r0   r1    r   r   r5   r5   T           Dr   r5   c                      e Zd ZdS )ImageEncodeExceptionNr6   r7   r   r   r:   r:   X   r8   r   r:   c                  *    e Zd Zd	dZd Zd Zd
dZdS )ImageDecoderreturn	list[str]c                    g S )zbReturn a list of accepted file extensions, e.g. ['.gif', '.flc']
        Lower-case only.
        r7   r   s    r   r   z*ImageDecoder.get_animation_file_extensions^   s	     	r   c                    t                      )zDecode the given file object and return an instance of `Image`.
        Throws ImageDecodeException if there is an error.  filename
        can be a file type hint.
        NotImplementedErrorr   r%   r*   s      r   decodezImageDecoder.decoded   s    
 "###r   c                     t          d          )zDecode the given file object and return an instance of :py:class:`~pyglet.image.Animation`.
        Throws ImageDecodeException if there is an error.  filename
        can be a file type hint.
        z&This decoder cannot decode animations.)r5   rD   s      r   r(   zImageDecoder.decode_animationk   s    
 ##KLLLr   strc                    d                     | j        j        |                                 |                                 z             S )Nz{}{})formatr   r/   r   get_file_extensionsr@   s    r   __repr__zImageDecoder.__repr__r   sB    }}T^4#AACC#7799 :; ; 	;r   N)r=   r>   r=   rG   )r/   r0   r1   r   rE   r(   rK   r7   r   r   r<   r<   \   s]           $ $ $M M M; ; ; ; ; ;r   r<   c                      e Zd Zd ZddZdS )ImageEncoderc                    t                      )zpEncode the given image to the given file.  filename
        provides a hint to the file format desired.
        rB   )r   imager%   r*   s       r   encodezImageEncoder.encodez   s     "###r   r=   rG   c                F    | j         j         |                                  S r   )r   r/   rJ   r@   s    r   rK   zImageEncoder.__repr__   s$    .)G4+C+C+E+EGGGr   NrL   )r/   r0   r1   rQ   rK   r7   r   r   rN   rN   x   s=        $ $ $H H H H H Hr   rN   c                 8   	 ddl m}  t                              |            t                              |            n# t
          $ r Y nw xY wt          dk    rL	 ddl m} t                              |           t                              |           n# t
          $ r Y nw xY wt          dv rTddlm	} |rL	 ddl m
} t                              |           t                              |           n# t
          $ r Y nw xY wt          dv rL	 ddl m} t                              |           t                              |           n# t
          $ r Y nw xY wt          j        d	          rL	 dd
l m} t                              |           t                              |           n# t
          $ r Y nw xY w	 ddl m} t                              |           t                              |           n# t
          $ r Y nw xY w	 ddl m} t                              |           t                              |           n# t
          $ r Y nw xY w	 ddl m} t                              |           t                              |           d S # t
          $ r Y d S w xY w)Nr   )ddsdarwin)quartz)win32cygwin)WINDOWS_7_OR_GREATER)wic)gdipluslinux)
gdkpixbuf2)pil)png)bmp)pyglet.image.codecsrT   registryadd_encodersr   ImportErrorr	   rV   pyglet.libs.win32.constantsrY   rZ   r[   
startswithr]   r^   r_   r`   )	rT   rV   rY   rZ   r[   r]   r^   r_   r`   s	            r   add_default_codecsrg      so   
++++++c"""c""""    (""	222222!!&)))!!&)))) 	 	 	D	 ---DDDDDD 	333333%%c***%%c****    ---	333333!!'***!!'**** 	 	 	D	 !'** 	666666!!*---!!*---- 	 	 	D	++++++c"""c""""   ++++++c"""c""""   ++++++c"""c"""""   s   := 
A
	A
:B 
B! B!6:C1 1
C>=C>:E 
EE+:F& &
F32F37:G2 2
G?>G?:H> >
I
I:J 
JJ)r2   
__future__r   os.pathr   pyglet.utilr   r   r   r   r   pygletr	   r   rb   r   rc   r&   r   get_encodersr5   r:   r<   rN   rg   r7   r   r   <module>rm      s     # " " " " "  Y Y Y Y Y Y Y Y Y Y Y Y Y Y " " " " " "0 0 0 0 0- 0 0 0f   $$!8 $$	 	 	 	 	? 	 	 		 	 	 	 	? 	 	 	; ; ; ; ;7 ; ; ;8	H 	H 	H 	H 	H7 	H 	H 	HH H H H Hr   