
    9i,                         S r SSKrSSKrSSKJrJr  SSKJrJ	r	  SSK
Jr  \R                  " \5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      rg)zDPlugin for multi-image freeimafe formats, like animated GIF and ico.    N   )Formatimage_as_uint   )fiIO_FLAGS)FreeimageFormatc                   t    \ rS rSrSrSrSr " S S\R                  5      r " S S\	R                  5      r
S	rg
)FreeimageMulti   z>Base class for freeimage formats that support multiple images.iIc                   6    \ rS rSrS	S jrS rS rS rS rSr	g)
FreeimageMulti.Reader   c                 
   [        U5      n[        R                  " U R                  R                  U R
                  R                  U5      U l        U R                  R                  U R                  R                  5       5        g N)
intr   create_multipage_bitmaprequestfilenameformatfif_bmload_from_filenameget_local_filenameselfflagss     ^/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/imageio/plugins/freeimagemulti.py_openFreeimageMulti.Reader._open   sW    JE11%%t{{DH HH''(G(G(IJ    c                 8    U R                   R                  5         g r   r   closer   s    r    _closeFreeimageMulti.Reader._close   s    HHNNr#   c                 ,    [        U R                  5      $ r   )lenr   r'   s    r    _get_length!FreeimageMulti.Reader._get_length"   s    txx= r#   c                     U R                   R                  U5      n UR                  5       UR                  5       4UR	                  5         $ ! UR	                  5         f = fr   )r   get_pageget_image_dataget_meta_datar&   r   indexsubs      r    	_get_dataFreeimageMulti.Reader._get_data%   sH    ((##E*C))+S->->-@@				s   A Ac                    U=(       d    SnUS:  d  U[        U R                  5      :  a
  [        5       eU R                  R                  U5      n UR	                  5       UR                  5         $ ! UR                  5         f = f)Nr   )r+   r   
IndexErrorr/   r1   r&   r2   s      r    _get_meta_data$FreeimageMulti.Reader._get_meta_data,   sa    JQEqyES]2 l"((##E*C((*				s   A1 1B)r   Nr   )
__name__
__module____qualname____firstlineno__r!   r(   r,   r5   r9   __static_attributes__ r#   r    Readerr      s    	K		!		r#   rB   c                   6    \ rS rSrS	S jrS rS rS rS rSr	g)
FreeimageMulti.Writer8   c                    [        U5      =U l        n[        R                  " U R                  R
                  U R                  R                  U5      U l        U R                  R                  U R                  R                  5       5        g r   )r   _flagsr   r   r   r   r   r   r   save_to_filenamer   r   s     r    r!   FreeimageMulti.Writer._open9   s^    "%e*,DK%11%%t{{DH HH%%dll&E&E&GHr#   c                 8    U R                   R                  5         g r   r%   r'   s    r    r(   FreeimageMulti.Writer._closeB   s    HHNNr#   c                    UR                   S:X  a  UR                  S   S:X  a  US S 2S S 2S4   n[        USS9n[        R                  " U R
                  R                  U R                  R                  5      nU R                  XU5      nU R
                  R                  U5        UR                  5         X4La  UR                  5         g g )N   r   r   r      )bitdepth)ndimshaper   r   create_bitmapr   	_filenamer   r   _append_bitmapappend_bitmapr&   )r   immetasub1sub2s        r    _append_data"FreeimageMulti.Writer._append_dataF   s    ww!| 11a[rA.B##DHH$6$6HD&&r6DHH""4(JJL

  r#   c                 l    UR                  U5        UR                  U5        UR                  U5        U$ r   )allocateset_image_dataset_meta_data)r   rV   rW   bitmaps       r    rT   $FreeimageMulti.Writer._append_bitmapU   s/    OOB!!"%  &Mr#   c                     g r   rA   )r   rW   s     r    _set_meta_data$FreeimageMulti.Writer._set_meta_data]   s    r#   )r   rG   Nr;   )
r<   r=   r>   r?   r!   r(   rZ   rT   rc   r@   rA   r#   r    WriterrD   8   s    	I				r#   re   rA   N)r<   r=   r>   r?   __doc___modes_fifr   rB   r	   re   r@   rA   r#   r    r   r      s2    HFD D&'' &r#   r   c                   "    \ rS rSrSrSrS rSrg)	MngFormata   zHAn Mng format based on the Freeimage library.

Read only. Seems broken.
   c                     g)NFrA   )r   r   s     r    
_can_writeMngFormat._can_writei   s    r#   rA   N)r<   r=   r>   r?   rf   rh   rn   r@   rA   r#   r    rj   rj   a   s    
 Dr#   rj   c                   F    \ rS rSrSrSr " S S\R                  5      rSrg)	IcoFormatm   aQ  An ICO format based on the Freeimage library.

This format supports grayscale, RGB and RGBA images.

The freeimage plugin requires a `freeimage` binary. If this binary
is not available on the system, it can be downloaded by either

- the command line script ``imageio_download_bin freeimage``
- the Python method ``imageio.plugins.freeimage.download()``

Parameters for reading
----------------------
makealpha : bool
    Convert to 32-bit and create an alpha channel from the AND-
    mask when loading. Default False. Note that this returns wrong
    results if the image was already RGBA.

r   c                       \ rS rSrSS jrSrg)IcoFormat.Reader   c                     [        U5      nU(       a  U[        R                  -  n[        R                  R                  X5      $ r   )r   r   ICO_MAKEALPHAr   rB   r!   )r   r   	makealphas      r    r!   IcoFormat.Reader._open   s5    JE///!((..t;;r#   rA   N)r   F)r<   r=   r>   r?   r!   r@   rA   r#   r    rB   rt      s    	<r#   rB   rA   N)	r<   r=   r>   r?   rf   rh   r   rB   r@   rA   r#   r    rq   rq   m   s     & D<&& <r#   rq   c                   p    \ rS rSrSrSr " S S\R                  5      r " S S\R                  5      rSr	g	)
	GifFormat   an  A format for reading and writing static and animated GIF, based
on the Freeimage library.

Images read with this format are always RGBA. Currently,
the alpha channel is ignored when saving RGB images with this
format.

The freeimage plugin requires a `freeimage` binary. If this binary
is not available on the system, it can be downloaded by either

- the command line script ``imageio_download_bin freeimage``
- the Python method ``imageio.plugins.freeimage.download()``

Parameters for reading
----------------------
playback : bool
    'Play' the GIF to generate each frame (as 32bpp) instead of
    returning raw frame data when loading. Default True.

Parameters for saving
---------------------
loop : int
    The number of iterations. Default 0 (meaning loop indefinitely)
duration : {float, list}
    The duration (in seconds) of each frame. Either specify one value
    that is used for all frames, or one value for each frame.
    Note that in the GIF format the duration/delay is expressed in
    hundredths of a second, which limits the precision of the duration.
fps : float
    The number of frames per second. If duration is not given, the
    duration for each frame is set to 1/fps. Default 10.
palettesize : int
    The number of colors to quantize the image to. Is rounded to
    the nearest power of two. Default 256.
quantizer : {'wu', 'nq'}
    The quantization algorithm:
        * wu - Wu, Xiaolin, Efficient Statistical Computations for
          Optimal Color Quantization
        * nq (neuqant) - Dekker A. H., Kohonen neural networks for
          optimal color quantization
subrectangles : bool
    If True, will try and optimize the GIF by storing only the
    rectangular parts of each frame that change with respect to the
    previous. Unfortunately, this option seems currently broken
    because FreeImage does not handle DisposalMethod correctly.
    Default False.
   c                   $    \ rS rSrSS jrS rSrg)GifFormat.Reader   c                     [        U5      nU(       a  U[        R                  -  n[        R                  R                  X5        g r   )r   r   GIF_PLAYBACKr   rB   r!   )r   r   playbacks      r    r!   GifFormat.Reader._open   s2    JE...!!''4r#   c                 J    [         R                  R                  X5      u  p#X#4$ r   )r   rB   r5   )r   r3   rV   rW   s       r    r5   GifFormat.Reader._get_data   s!    %,,66tCHB8Or#   rA   N)r   T)r<   r=   r>   r?   r!   r5   r@   rA   r#   r    rB   r      s    	5	r#   rB   c                   8    \ rS rSr       SS jrS rS rSrg)GifFormat.Writer   Nc                    US:  d  US:  a  [        S5      eUS;  a=  S[        [        R                  " S5      S-   5      -  n[        R                  SU-  5        XPl        SS	S
.R                  UR                  5       S 5      U l	        U R                  c  [        S5      eUc!  [        S[        U5      -  S-   5      /U l        Ox[        U[        5      (       a%  U Vs/ s H  n[        SU-  5      PM     snU l        O>[        U[        [        45      (       a  [        SU-  5      /U l        O[        SU-  5      e[        U5      U l        S U l        ["        R$                  R'                  X5        0 U l        S[        R*                  " U/5      R-                  [        R.                  5      0U R(                  S'   g s  snf )Nr      z!GIF quantize param must be 2..256)r      rN   r       @      r   r   g+?zDWarning: palettesize (%r) modified to a factor of two between 2-256.r   r   )wunqz(Invalid quantizer, must be "wu" or "nq".i  g      ?zInvalid value for duration: %rLoop	ANIMATION)
ValueErrorr   nplog2loggerwarning_palettesizegetlower
_quantizerfloat
_frametime
isinstancelistbool_subrectangles_prev_imr   re   r!   _metaarrayastypeuint32)	r   r   loopdurationfpspalettesize	quantizersubrectanglesds	            r    r!   GifFormat.Writer._open   s    Q+"3 !DEE"AA3rwws|e';#<<)+67 !,%&a044Y__5FMDO& !KLL#&teCj'83'>#?"@Hd++:B"C(Q3tax=("CHucl33#&th#7"8 !AH!LMM"&}"5D DM!!''4DJ $(//		:'DJJ{# #Ds   F>c                    UR                  5       n0 =oBS'   [        U R                  5      S:X  a   UR                  U R                  5        US   n[        U R                  5      nU[        U R
                  5      :  a  U R
                  U   nOU R
                  S   n[        R                  " U/5      R                  [        R                  5      US'   UR                  S:X  a!  UR                  S   S:X  a  US S 2S S 2S S24   nUnU R                  (       a  U R                  b  U R                  U R                  U5      u  p[        R                  " S/5      R                  [        R                  5      US'   [        R                  " US   /5      R                  [        R                   5      US	'   [        R                  " US   /5      R                  [        R                   5      US
'   Xpl        U=pU
R#                  U5        U
R%                  U5        UR                  S:X  a9  UR                  S   S:X  a&  U
R'                  U R(                  U R*                  5      n	U	R-                  U5        U	$ )Nr   r   r   	FrameTimerM   r   r   DisposalMethod	FrameLeftFrameTop)copyr+   r   updater   r   r   r   r   r   rP   rQ   r   r   _get_sub_rectanglesuint8uint16r]   r^   quantizer   r   r_   )r   rV   rW   r`   meta_ar3   ftim_uncroppedxyrY   rX   s              r    rT   GifFormat.Writer._append_bitmap  s   99;D)++F+&488}!DJJ'k*MEs4??++__U+__R("$((B4."7"7		"BF;ww!| 11bqb\L""t}}'@11$--D+-88QC=+?+?+I'(&(hh1w&7&>&>ryy&I{#%'XXr!ug%6%=%=bii%Hz"(M  DMM"#ww!| 1}}T__d6G6GHt$Kr#   c                    [         R                  " X!-
  5      nUR                  S:X  a  UR                  S5      n[         R                  " UR                  S5      5      n[         R                  " UR                  S5      5      nUR
                  (       aN  UR
                  (       a=  [        US   5      [        US   5      S-   pv[        US   5      [        US   5      S-   pOSu  pgSu  pX(U	2Xg24   Xh44$ )z
Calculate the minimal rectangles that need updating each frame.
Returns a two-element tuple containing the cropped images and a
list of x-y positions.
rM   r   r   r   r   )r   r   )r   absrP   sumargwheresizer   )
r   prevrV   diffXYx0x1y0y1s
             r    r   $GifFormat.Writer._get_sub_rectangles&  s     66")$DyyA~xx{DHHQK(ADHHQK(Avv!&&QqTC"JNBQqTC"JNBeRUl#bX--r#   )r   r   r   r   r   r   )r   r   N
   r   WuF)r<   r=   r>   r?   r!   rT   r   r@   rA   r#   r    re   r      s*     -	^#	J	.r#   re   rA   N)
r<   r=   r>   r?   rf   rh   r   rB   re   r@   rA   r#   r    r{   r{      s5    .` D&& m.&& m.r#   r{   )rf   loggingnumpyr   corer   r   
_freeimager   r   	freeimager	   	getLoggerr<   r   r   rj   rq   r{   rA   r#   r    <module>r      s_    K   ( $ &			8	$N_ Nb	 	< <>o. o.r#   