Ë
    Eü´j .  ã                   óš   — d Z ddlZddlZddlmZmZmZ  ej                  e	«      Z
dZ G d„ de«      Z G d„ de«      Zd	„ Z G d
„ d«      Zy)z"
PIL formats for multiple images.
é    Né   )ÚPillowFormatÚimage_as_uintÚndarray_to_pilc                   ó   — e Zd ZdZdZy)Ú
TIFFFormatÚizTIFF format (Pillow)N)Ú__name__Ú
__module__Ú__qualname__Ú_modesÚ_description© ó    úY/root/workspace/ytshorts/venv/lib/python3.12/site-packages/imageio/plugins/pillowmulti.pyr   r      s   „ Ø€FØ)�Lr   r   c                   óB   — e Zd ZdZdZdZ G d„ dej                  «      Zy)Ú	GIFFormatz(See :mod:`imageio.plugins.pillow_legacy`ÚiIz Static and animated gif (Pillow)c                   ó,   — e Zd Z	 	 	 	 	 	 dd„Zd„ Zd„ Zy)úGIFFormat.WriterNc           	      óü  — ddl m} t        d„ |j                  d«      D «       «      \  }}	}
|dk(  r|	dk\  rt	        d|› d�«      ‚t        |«      }|d	k  s|d
kD  rt        d«      ‚|dvr<d	t        t        j                  d«      dz   «      z  }t        j                  d|z  «       |€dt        |«      z  | _        nEt        |t        t        f«      r|D �cg c]  }t        |«      ‘Œ c}| _        nt        |«      | _        t        |«      }|dk  s|t        d«      k(  rd}t        |«      }t        |«      }|rdnd	| _        | j"                  j%                  «       }t'        ||||t        |«      «      | _        y c c}w )Nr   )Ú__version__c              3   ó2   K  — | ]  }t        |«      –— Œ y ­w©N)Úint)Ú.0Úxs     r   ú	<genexpr>z)GIFFormat.Writer._open.<locals>.<genexpr>)   s   è ø€ Ò'R°1¬¨A¯Ñ'Rùs   ‚ú.é
   r   zPillow vzŽ is not supported by ImageIO's legacy pillow plugin when writing GIFs. Consider switching to the new plugin or downgrading to `pillow<10.1.0`.é   é   z!GIF quantize param must be 2..256)r!   é   é   é   é    é@   é€   r"   r(   g+‡ÙÎ÷ï?zDWarning: palettesize (%r) modified to a factor of two between 2-256.g      ð?Úinf)ÚPILr   ÚtupleÚsplitÚImportErrorr   Ú
ValueErrorÚnpÚlog2ÚloggerÚwarningÚfloatÚ	_durationÚ
isinstanceÚlistÚboolÚ_disposeÚrequestÚget_fileÚ	GifWriterÚ_writer)ÚselfÚloopÚdurationÚfpsÚpalettesizeÚ	quantizerÚsubrectanglesÚpillow_versionÚmajorÚminorÚpatchÚdÚfps                r   Ú_openzGIFFormat.Writer._open   su  € õ :ä"'Ñ'R¸×8LÑ8LÈSÓ8QÔ'RÓ"RÑˆE�5˜%Ø˜Š{˜u¨šzÜ!Ø˜~Ð.ð /@ð @óð ô ˜kÓ*ˆKØ˜QŠ +°Ò"3Ü Ð!DÓEÐEØÐ"AÑAØ¤3¤r§w¡w¨s£|°eÑ';Ó#<Ñ<�Ü—‘ð)Ø+6ñ7ôð
 ÐØ!$¤u¨S£zÑ!1�•Ü˜H¤t¬U mÔ4Ø4<Ö!=¨q¤%¨¥(Ò!=�•ä!& x£�”ä˜“;ˆDØ�qŠy˜D¤E¨%£LÒ0Ø�Ü�t“9ˆDä  Ó/ˆMÙ!.™A°AˆDŒMð —‘×&Ñ&Ó(ˆBÜ$Ø�M 4¨´C¸Ó4DóˆD�Lùò ">s   ÃE9c                 ó8   — | j                   j                  «        y r   )r<   Úclose©r=   s    r   Ú_closezGIFFormat.Writer._closeQ   s   € Ø�L‰L×ÑÕ r   c                 ó`  — t        |d¬«      }|j                  dk(  r|j                  d   dk(  r|d d …d d …df   }| j                  }t	        |t
        «      r/|t        t        |«      dz
  | j                  j                  «         }| j                  }| j                  j                  |||«       y )Nr$   )Úbitdepthé   éÿÿÿÿr   r   )r   ÚndimÚshaper4   r5   r6   ÚminÚlenr<   Ú_countr8   Ú	add_image)r=   ÚimÚmetar?   Údisposes        r   Ú_append_datazGIFFormat.Writer._append_dataT   s�   € Ü˜r¨AÔ.ˆBØ�w‰w˜!Š| §¡¨¡°Ò 1Øšš1˜a˜‘[�Ø—~‘~ˆHÜ˜(¤DÔ)Ø#¤C¬¨H«¸Ñ(9¸4¿<¹<×;NÑ;NÓ$OÑP�Ø—m‘mˆGØ�L‰L×"Ñ" 2 x°Ô9àr   )r   Nr    r"   r   F)r
   r   r   rJ   rN   r\   r   r   r   ÚWriterr      s&   „ ð ØØØØØó1	òf	!ó
	r   r]   N)r
   r   r   Ú__doc__r   r   r   r]   r   r   r   r   r      s#   „ Ù2à€FØ5€LôA�×$Ñ$õ Ar   r   c                 ó(   — | j                  dd¬«      S )Nr!   Úlittle)Ú	byteorder)Úto_bytes)r	   s    r   ÚintToBinrc   a   s   € Ø�:‰:�a 8ˆ:Ó,Ð,r   c                   ób   — e Zd ZdZ	 	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	dd	„Z
d
„ Zdd„Zd„ Zdd„Zy)r;   z³Class that for helping write the animated GIF file. This is based on
    code from images2gif.py (part of visvis). The version here is modified
    to allow streamed writing.
    c                 óŽ   — || _         || _        || _        || _        || _        d | _        d | _        d| _        ddlm	} || _	        y )Nr   )Úgetdata)
rI   Úopt_subrectangleÚopt_loopÚopt_quantizerÚopt_palette_sizeÚ_previous_imageÚ_global_paletterW   ÚPIL.GifImagePluginrf   )r=   Úfilerg   rh   ri   rj   rf   s          r   Ú__init__zGifWriter.__init__k   sK   € ð ˆŒà 0ˆÔØ ˆŒØ*ˆÔØ 0ˆÔà#ˆÔØ#ˆÔØˆŒå.àˆ�r   c                 óŠ  — |d}}| j                   r| j                  |«      \  }}| j                  || j                  | j                  «      }ddlm}  ||«      d   d   }| j                  dk(  r$| j                  ||| j                  «       || _
        | j                  |||||«       || _        | xj                  dz  c_        y )N©r   r   r   )Ú	getheaderrQ   r   )rg   ÚgetSubRectangleÚconverToPILri   rj   rm   rr   rW   Úwrite_headerrh   rl   Úwrite_imagerk   )	r=   rY   r?   r[   Úim_rectÚrectÚim_pilrr   Úpalettes	            r   rX   zGifWriter.add_image‚   s»   € à˜F�ˆØ× Ò Ø ×0Ñ0°Ó4‰MˆG�TØ×!Ñ! '¨4×+=Ñ+=¸t×?TÑ?TÓUˆõ
 	1á˜FÓ# AÑ& qÑ)ˆð �;‰;˜!ÒØ×Ñ˜f g¨t¯}©}Ô=Ø#*ˆDÔ Ø×Ñ˜ ¨$°¸'ÔBð  "ˆÔØ�Š�qÑŽr   c                 óê   — | j                  |«      }| j                  |«      }| j                  j                  |«       | j                  j                  |«       | j                  j                  |«       y r   )ÚgetheaderAnimÚ	getAppExtrI   Úwrite)r=   rY   ÚglobalPaletter>   ÚheaderÚappexts         r   ru   zGifWriter.write_header›   sP   € à×#Ñ# BÓ'ˆØ—‘ Ó%ˆà�‰�‰�fÔØ�‰�‰�mÔ$Ø�‰�‰�fÕr   c                 óX   — | j                   j                  dj                  d«      «       y )Nú;úutf-8)rI   r~   ÚencoderM   s    r   rL   zGifWriter.close¤   s   € Ø�‰�‰�c—j‘j Ó)Õ*r   c                 ó:  — | j                   }| j                  |«      }d}|r3t        |«      dk  r%||j                  d«      z  }|rt        |«      dk  rŒ%t        |«      dk(  sJ ‚| j	                  ||«      }	| j                  ||«      }
|| j                  k7  s|dk7  rE|j                  |
«       |j                  |	«       |j                  |«       |j                  d«       n"|j                  |
«       |j                  |«       |D ]  }|j                  |«       Œ y )Nr   é   r   r!   ó   )rI   rf   rV   ÚpopÚgetImageDescriptorÚgetGraphicsControlExtrl   r~   )r=   rY   rz   rx   r?   r[   rI   ÚdataÚimdesÚlidÚgraphextrH   s               r   rv   zGifWriter.write_image§   s   € Ø�W‰Wˆð �|‰|˜BÓˆØˆÙ”s˜5“z B’Ø�T—X‘X˜a“[Ñ ˆEñ ”s˜5“z B“ä�5‹z˜RÒÐÐð ×%Ñ% b¨$Ó/ˆØ×-Ñ-¨h¸Ó@ˆð �t×+Ñ+Ò+°¸A²à�H‰H�XÔØ�H‰H�SŒMØ�H‰H�WÔØ�H‰H�WÕð �H‰H�XÔØ�H‰H�UŒOð ò 	ˆAØ�H‰H�Q�Kñ	r   c                 ó€   — d}|t        |j                  d   «      z  }|t        |j                  d   «      z  }|dz  }|S )z4Get animation header. To replace PILs getheader()[0]s   GIF89ar   r   s   ‡  ©rc   Úsize)r=   rY   Úbbs      r   r|   zGifWriter.getheaderAnimÈ   sD   € àˆØ
Œh�r—w‘w˜q‘zÓ"Ñ"ˆØ
Œh�r—w‘w˜q‘zÓ"Ñ"ˆØ
ˆoÑˆØˆ	r   Nc                 óÌ   — |€d}d}|t        |d   «      z  }|t        |d   «      z  }|t        |j                  d   «      z  }|t        |j                  d   «      z  }|dz  }|S )a‹  Used for the local color table properties per image.
        Otherwise global color table applies to all frames irrespective of
        whether additional colors comes in play that require a redefined
        palette. Still a maximum of 256 color per frame, obviously.

        Written by Ant1 on 2010-08-22
        Modified by Alex Robinson in Janurari 2011 to implement subrectangles.
        rq   ó   ,r   r   ó   ‡r‘   )r=   rY   Úxyr“   s       r   rŠ   zGifWriter.getImageDescriptorÐ   s{   € ð ˆ:ØˆBð ˆð 	Œh�r˜!‘u‹oÑˆØ
Œh�r˜!‘u‹oÑˆØ
Œh�r—w‘w˜q‘zÓ"Ñ"ˆØ
Œh�r—w‘w˜q‘zÓ"Ñ"ˆð 	ˆg‰ˆð ˆ	r   c                 ól   — |dk(  ry|dk(  rd}d}|dk7  rd}|dz  }|dz  }|t        |«      z  }|dz  }|S )	z|Application extension. This part specifies the amount of loops.
        If loop is 0 or inf, it goes on infinitely.
        r   r   r   iÿÿ  s   !ÿs   NETSCAPE2.0s   ó    )rc   )r=   r>   r“   s      r   r}   zGifWriter.getAppExtî   s[   € ð �1Š9ØØ�1Š9ØˆDØˆØ�1Š9Ø ˆBØ�.Ñ ˆBØ�+ÑˆBØ”(˜4“.Ñ ˆBØ�'‰MˆBØˆ	r   c                 óž   — d}|t        |dz  dz  «      j                  d«      z  }|t        t        |dz  dz   «      «      z  }|dz  }|dz  }|S )ab  Graphics Control Extension. A sort of header at the start of
        each image. Specifies duration and transparency.

        Dispose
        -------
          * 0 - No disposal specified.
          * 1 - Do not dispose. The graphic is to be left in place.
          * 2 - Restore to background color. The area used by the graphic
            must be restored to the background color.
          * 3 - Restore to previous. The decoder is required to restore the
            area overwritten by the graphic with what was there prior to
            rendering the graphic.
          * 4-7 -To be defined.
        s   !ùrQ   r!   r„   éd   g      à?r™   )Úchrr…   rc   r   )r=   r?   r[   r“   s       r   r‹   zGifWriter.getGraphicsControlExtÿ   sb   € ð  ˆØ
Œc�7˜Q‘; 1Ñ$Ó%×,Ñ,¨WÓ5Ñ5ˆð 	Œh”s˜8 c™>¨CÑ/Ó0Ó1Ñ1ˆØ
ˆg‰ˆØ
ˆg‰ˆØˆ	r   c                 ó   — | j                   dk(  r|dfS | j                  }t        j                  ||z
  «      }|j                  dk(  r|j                  d«      }t        j                  |j                  d«      «      }t        j                  |j                  d«      «      }|j                  rK|j                  r?t        |d   «      t        |d   dz   «      }}t        |d   «      t        |d   dz   «      }	}n
d\  }}d\  }}	|||	…||…f   ||ffS )ar  Calculate the minimal rectangle that need updating. Returns
        a two-element tuple containing the cropped image and an x-y tuple.

        Calculating the subrectangles takes extra time, obviously. However,
        if the image sizes were reduced, the actual writing of the GIF
        goes faster. In some cases applying this method produces a GIF faster.
        r   rq   rQ   r!   r   rR   )r   r!   )	rW   rk   r/   ÚabsrS   ÚsumÚargwherer’   r   )
r=   rY   ÚprevÚdiffÚXÚYÚx0Úx1Úy0Úy1s
             r   rs   zGifWriter.getSubRectangle  sö   € ð �;‰;˜!ÒØ�v�:Ðà×#Ñ#ˆô �v‰v�b˜4‘iÓ ˆØ�9‰9˜Š>Ø—8‘8˜A“;ˆDä�K‰K˜Ÿ™ ›Ó$ˆÜ�K‰K˜Ÿ™ ›Ó$ˆà�6Š6�a—f’fÜ˜˜1™“Y¤ A b¡E¨A¡I£�ˆBÜ˜˜1™“Y¤ A b¡E¨A¡I£�‰Bà‰FˆB�Ø‰FˆB�à�"�R�%˜˜B˜�,Ñ " b Ð)Ð)r   c                 ó(  — t        |d«      }|dv r4d}|j                  d«      }t        ||«      }|j                  ||¬«      }|S |dv r=|dk(  r|j                  d«      }n|j                  d«      }|j                  ||¬	«      }|S t	        d
|z  «      ‚)zÿConvert image to Paletted PIL image.

        PIL used to not do a very good job at quantization, but I guess
        this has improved a lot (at least in Pillow). I don't think we need
        neuqant (and we can add it later if we really want).
        Úgif)ÚnqÚneuquantr    ÚRGBA)Úcolors)r   r   r!   r!   ÚRGB)r®   ÚmethodzInvalid value for quantizer: %r)r   ÚconvertÚNeuQuantÚquantizer.   )r=   rY   rB   Úpalette_sizery   Únq_samplefacÚ
nqInstances          r   rt   zGifWriter.converToPIL9  s­   € ô    EÓ*ˆàÐ*Ñ*àˆLØ—^‘^ FÓ+ˆFÜ! &¨,Ó7ˆJØ×(Ñ(¨¸Ð(ÓEˆFð ˆð ˜)Ñ#à˜AŠ~ØŸ™¨Ó/‘àŸ™¨Ó.�Ø—_‘_¨LÀ�_ÓKˆFð ˆô Ð>ÀÑJÓKÐKr   )Tr   r   r"   r   )gš™™™™™¹?r!   )r"   )r
   r   r   r^   ro   rX   ru   rL   rv   r|   rŠ   r}   r‹   rs   rt   r   r   r   r;   r;   e   sN   „ ñð ØØØóò.ò2ò+òòBóò<ó"ò4*ô@r   r;   )r^   ÚloggingÚnumpyr/   Úpillow_legacyr   r   r   Ú	getLoggerr
   r1   r²   r   r   rc   r;   r   r   r   ú<module>r»      s[   ðñó ã ç FÑ Fà	ˆ×	Ñ	˜8Ó	$€à€ô*�ô *ô
I�ô IòX-÷mò mr   