Ë
    T]j97  ã                   ó”   — d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d„ Zd„ Z G d„ d	«      Zdd
„Zdd„Zdd„Zdd„Zdd„Zy)é    N)Úpartial)ÚBytesIO)ÚImageÚ
ImageChopsÚImageFilter)Úutilsc                 óÌ   — t        j                  | «      }t        j                  |«      }|r,t        ||z  dz
  «      dk  r||dz  k\  r||fS |dz  }|||z
  fS ||kD  rd|fS |dfS )zË
    Calculate the entropy of two slices (from the start and end of an axis),
    returning a tuple containing the amount that should be added to the start
    and removed from the end of the axis.

    é   g{®Gáz„?é   r   )r   Úimage_entropyÚabs)Ústart_sliceÚ	end_sliceÚsliceÚ
differenceÚstart_entropyÚend_entropyÚ
half_slices          úQ/var/www/zogu/zoguvenv/lib/python3.12/site-packages/easy_thumbnails/processors.pyÚ_compare_entropyr   
   s†   € ô ×'Ñ'¨Ó4€MÜ×%Ñ% iÓ0€KÙ”s˜=¨;Ñ6¸Ñ:Ó;¸dÒBà˜ ™Ò"Ø˜%�<ÐØ˜a‘Zˆ
Ø˜5 :Ñ-Ð-Ð-Ø�{Ò"Ø�%ˆxˆà�aˆxˆó    c               #   ój   K  — t        d«      D ]!  } t        j                  | d«      D ]  }|–— Œ Œ# y­w)z=
    Iterable to map a 16 bit grayscale image to 8 bits.
    é   N)ÚrangeÚ	itertoolsÚrepeat)ÚiÚjs     r   Ú_points_tabler      s<   è ø€ ô �3‹Zò ˆÜ×!Ñ! ! SÓ)ò 	ˆAØ‹Gñ	ñùs   ‚13c                   ó0   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zd„ Zˆ xZS )Ú
FrameAwarec                 óF   •— t        |dd«      dkD  rt        ‰| �	  | «      S |S )NÚn_framesr
   )ÚgetattrÚsuperÚ__new__)ÚclsÚimÚ	__class__s     €r   r&   zFrameAware.__new__)   s(   ø€ Ü�2�z 1Ó%¨Ò)Ü‘7‘? 3Ó'Ð'Øˆ	r   c                 ó   — || _         y ©N)r(   )Úselfr(   s     r   Ú__init__zFrameAware.__init__.   s	   € Øˆ�r   c                 óN  — g }t        | j                  j                  «      D ]4  }| j                  j                  |«       |j	                   ||i |¤Ž«       Œ6 t        «       }|d   j                  || j                  j                  d|dd  ¬«       t        j                  |«      S )Nr   Tr
   ©ÚformatÚsave_allÚappend_images)
r   r(   r#   ÚseekÚappendr   Úsaver0   r   Úopen)r,   ÚmethodÚargsÚkwargsÚ
new_framesr   Úwrite_tos          r   Úapply_to_frameszFrameAware.apply_to_frames1   s–   € Øˆ
Ü�t—w‘w×'Ñ'Ó(ò 	7ˆAØ�G‰G�L‰L˜ŒOØ×Ñ™f dÐ5¨fÑ5Õ6ð	7ô “9ˆØ�1‰×ÑØ˜TŸW™WŸ^™^°dÈ*ÐUVÐUWÈ.ð 	ô 	
ô �z‰z˜(Ó#Ð#r   c                 óZ   — t        | j                  |«      }t        | j                  |«      S r+   )r$   r(   r   r<   )r,   Úkeyr7   s      r   Ú__getattr__zFrameAware.__getattr__<   s%   € Ü˜Ÿ™ #Ó&ˆÜ�t×+Ñ+¨VÓ4Ð4r   )Ú__name__Ú
__module__Ú__qualname__r&   r-   r<   r?   Ú__classcell__)r)   s   @r   r!   r!   (   s   ø„ ôò
ò	$ö5r   r!   c                 óì  — | j                   dk(  r,t        | «      j                  t        t	        «       «      d«      } t        j                  | «      }| j                   dv }| j                   }|s|rd}nd}|�rT|�rLt        | dd«      s`| j                   dk7  rt        | «      j                  d«      } t        j                  d| j                  |«      }|j                  | | ¬«       |} näg }t        | j                  «      D ]�  }	| j                  |	«       | j                   dk7  rt        | «      j                  d«      } t        j                  d| j                  |«      }|j                  | | ¬«       |j!                  |«       Œƒ t#        «       }
|d	   j%                  |
| j&                  d
|dd ¬«       t        j(                  |
«      S |dz   }| j                   |k7  rt        | «      j                  |«      } | S )a:  
    Convert images to the correct color space.

    A passive option (i.e. always processed) of this method is that all images
    (unless grayscale) are converted to RGB colorspace.

    This processor should be listed before :func:`scale_and_crop` so palette is
    changed before the image is resized.

    bw
        Make the thumbnail grayscale (not really just black & white).

    replace_alpha
        Replace any transparency layer with a solid color. For example,
        ``replace_alpha='#fff'`` would replace the transparency layer with
        white.

    ÚIÚL)rF   ÚLAÚRGBÚis_animatedFÚRGBA©Úmaskr   Tr
   Nr/   ÚA)Úmoder!   ÚpointÚlistr   r   Úis_transparentr$   Úconvertr   ÚnewÚsizeÚpaster   r#   r3   r4   r   r5   r0   r6   )r(   ÚbwÚreplace_alphar9   rQ   Úis_grayscaleÚnew_modeÚbaseÚframesr   r;   s              r   Ú
colorspacer\   A   s­  € ð& 
‡w�w�#‚~ô ˜‹^×!Ñ!¤$¤}£Ó"7¸Ó=ˆä×)Ñ)¨"Ó-€NØ—7‘7˜kÐ)€LØ�w‰w€HÙ‘rØ‰àˆâÚÜ˜2˜}¨eÔ4Ø—7‘7˜fÒ$Ü# B›×/Ñ/°Ó7�BÜ—y‘y ¨¯©°-Ó@�Ø—
‘
˜2 B�
Ô'Ø‘à�Ü˜rŸ{™{Ó+ò (�AØ—G‘G˜A”JØ—w‘w &Ò(Ü'¨›^×3Ñ3°FÓ;˜Ü Ÿ9™9 V¨R¯W©W°mÓD�DØ—J‘J˜r¨�JÔ+Ø—M‘M $Õ'ð(ô #›9�Ø�q‘	—‘Ø R§Y¡Y¸ÈVÐTUÐTVÈZð ô ô —z‘z (Ó+Ð+à #‘~ˆHà	‡w�w�(ÒÜ˜‹^×#Ñ# HÓ-ˆØ€Ir   c                 óÆ  — |rÞt        j                  | «      rFt        j                  d| j                  d«      }|j                  | | j                  «       d   ¬«       n| j                  d«      }|j                  d«      }t        j                  d| j                  d«      }t        j                  ||«      j                  «       }|rt        | «      j                  |«      } | S )a$  
    Remove any unnecessary whitespace from the edges of the source image.

    This processor should be listed before :func:`scale_and_crop` so the
    whitespace is removed from the source image before it is resized.

    autocrop
        Activates the autocrop method for this image.

    rF   éÿ   éÿÿÿÿrK   )r   rQ   r   rS   rT   rU   ÚsplitrR   r   r   Úgetbboxr!   Úcrop)r(   Úautocropr9   Úno_alpharV   ÚbgÚbboxs          r   rc   rc      s±   € ñ ä×Ñ Ô#Ü—y‘y  b§g¡g°Ó5ˆHØ�N‰N˜2 B§H¡H£J¨r¡NˆNÕ3à—z‘z #“ˆHà×Ñ˜cÓ"ˆô �Y‰Y�s˜BŸG™G SÓ)ˆÜ×$Ñ$ R¨Ó,×4Ñ4Ó6ˆÙÜ˜B“×$Ñ$ TÓ*ˆBØ€Ir   c           	      óò	  — | j                   D �cg c]  }t        |«      ‘Œ c}\  }}	|D �cg c]  }t        |«      ‘Œ c}\  }
}|s|
r|s!t        |dk(  rdn|
|z  |	dk(  rdn||	z  «      }n t	        |dk(  rdn|
|z  |	dk(  rdn||	z  «      }|
st        ||z  «      }
n|st        |	|z  «      }|r4|st        ||z  «      }
t        |	|z  «      }d}|dt        |«      z   dz  z  }	 t        j                  j                  }|dk  s|dkD  rJ|rHt        | «      j                  t        t        ||z  «      «      t        t        |	|z  «      «      f|¬«      } |�ru| j                   \  }}	t        |t	        ||
«      z
  «      }t        |	t	        |	|«      z
  «      }|dk7  �r0|s|�r+t        |t        «      r(t        j                   d|«      }|r|j#                  «       }|r"|D �cg c]  }|s|dk(  rt        |«      nd	‘Œ }}nd
}t        |
dz  «      t        |dz  «      }}t        ||d   z  dz  «      }t        |	|d   z  dz  «      }t        dt	        ||
z
  ||z
  «      «      t        dt	        |	|z
  ||z
  «      «      g}|j%                  t        t	        ||d   |
z   «      «      «       |j%                  t        t	        |	|d   |z   «      «      «       t        |t        «      xr t        j                   d|«      }|rÄt'        d|j#                  «       «      rª|j#                  «       \  }}}}|rGt	        t        |
«      t        |«      z  dz  |«      }|r||z
  |d<   ||z
  |d<   n||d<   |||z
  z
  |d<   |�r>t	        t        |«      t        |«      z  dz  |«      }|r||z
  |d<   |	|z
  |d<   �n||d<   |	||z
  z
  |d<   nõ|dk(  rðdx}}||	} }|rot	        |t        |dz  d«      «      }!| j)                  |d||!z   |	f«      }"| j)                  ||!z
  d||	f«      }#t+        |"|#|!|«      \  }$}%||$z  }||%z  }||$z
  |%z
  }|rŒo|rot	        |t        |dz  d«      «      }!| j)                  d||||!z   f«      }"| j)                  d| |!z
  || f«      }#t+        |"|#|!|«      \  }$}%||$z  }| |%z  } ||$z
  |%z
  }|rŒo|||| f}t        | «      j)                  |«      } | S c c}w c c}w # t        $ r t        j                  }Y �Œôw xY wc c}w )aD	  
    Handle scaling and cropping the source image.

    Images can be scaled / cropped against a single dimension by using zero
    as the placeholder in the size. For example, ``size=(100, 0)`` will cause
    the image to be resized to 100 pixels wide, keeping the aspect ratio of
    the source image.

    crop
        Crop the source image height or width to exactly match the requested
        thumbnail size (the default is to proportionally resize the source
        image to fit within the requested thumbnail size).

        By default, the image is centered before being cropped. To crop from
        the edges, pass a comma separated string containing the ``x`` and ``y``
        percentage offsets (negative values go from the right/bottom). Some
        examples follow:

        * ``crop="0,0"`` will crop from the left and top edges.

        * ``crop="-10,-0"`` will crop from the right edge (with a 10% offset)
          and the bottom edge.

        * ``crop=",0"`` will keep the default behavior for the x axis
          (horizontally centering the image) and crop from the top edge.

        The image can also be "smart cropped" by using ``crop="smart"``. The
        image is incrementally cropped down to the requested size by removing
        slices from edges with the least entropy.

        Finally, you can use ``crop="scale"`` to simply scale the image so that
        at least one dimension fits within the size dimensions given (you may
        want to use the upscale option too).

    upscale
        Allow upscaling of the source image during scaling.

    zoom
        A percentage to zoom in on the scaled image. For example, a zoom of
        ``40`` will clip 20% off each side of the source image before
        thumbnailing.

    target
        Set the focal point as a percentage for the image if it needs to be
        cropped (defaults to ``(50, 50)``).

        For example, ``target="10,20"`` will set the focal point as 10% and 20%
        from the left and top of the image, respectively. If the image needs to
        be cropped, it will trim off the right and bottom edges until the focal
        point is centered.

        Can either be set as a two-item tuple such as ``(20, 30)`` or a comma
        separated string such as ``"20,10"``.

        A null value such as ``(20, None)`` or ``",60"`` will default to 50%.
    r   g      ð?Téd   g      Y@)ÚresampleÚscalez(\d+)?,(\d+)?$é2   )rk   rk   r   r
   z(?:(-?)(\d+))?,(?:(-?)(\d+))?$Né   Úsmarté   é
   )rT   ÚfloatÚintÚmaxÚminÚroundr   Ú
ResamplingÚLANCZOSÚAttributeErrorÚ	ANTIALIASr!   ÚresizeÚ
isinstanceÚstrÚreÚmatchÚgroupsr4   Úfilterrb   r   )&r(   rT   rb   ÚupscaleÚzoomÚtargetr9   ÚvÚsource_xÚsource_yÚtarget_xÚtarget_yrj   ÚImage__Resampling__LANCZOSÚdiff_xÚdiff_yÚnÚfocal_pointÚhalftarget_xÚhalftarget_yÚfocal_point_xÚfocal_point_yÚboxÚ	edge_cropÚx_rightÚx_cropÚy_bottomÚy_cropÚoffsetÚleftÚtopÚrightÚbottomr   ÚstartÚendÚaddÚremoves&                                         r   Úscale_and_cropr    œ   sX  € ðt -/¯G©GÖ4 qœ% �(Ò4Ñ€HˆhØ*.Ö/ Qœ#˜a�&Ò/Ñ€Hˆhá‘8¡8ÜØ˜q’=‰C h°Ñ&9Ø˜q’=‰C h°Ñ&9ó
‰ô
 Ø˜q’=‰C h°Ñ&9Ø˜q’=‰C h°Ñ&9ó
ˆñ Ü˜ EÑ)Ó*‰ÙÜ˜ EÑ)Ó*ˆáÙÜ˜X¨Ñ-Ó.ˆHÜ˜X¨Ñ-Ó.ˆHØˆDØ�#œ˜D›	‘/ UÑ*Ñ*ˆð5ä%*×%5Ñ%5×%=Ñ%=Ð"ð
 ˆs‚{�u˜s’{¡wô ˜‹^×"Ñ"Ü”�x %Ñ'Ó(Ó)¬3¬u°XÀÑ5EÓ/FÓ+GÐHØ/ð #ó 
ˆò
 àŸW™WÑˆ�(ä�X¤ H¨hÓ 7Ñ7Ó8ˆÜ�X¤ H¨hÓ 7Ñ7Ó8ˆØ�7‹?¡ª&Ü˜&¤#Ô&ÜŸ™Ð"3°VÓ<�ÙØ#Ÿ]™]›_�FÙØHNÖOÀ1©!¨q°Aªvœs 1œv¸BÑ>ÐO�ÑOà$�ä),¨X¸©\Ó):¼CÀÈ1ÁÓ<M˜,ˆLÜ ¨;°q©>Ñ 9¸CÑ ?Ó@ˆMÜ ¨;°q©>Ñ 9¸CÑ ?Ó@ˆMä�A”s˜8 hÑ.°ÀÑ0LÓMÓNÜ�A”s˜8 hÑ.°ÀÑ0LÓMÓNðˆCð �J‰J”sœ3˜x¨¨Q©°(Ñ):Ó;Ó<Ô=Ø�J‰J”sœ3˜x¨¨Q©°(Ñ):Ó;Ó<Ô=ä" 4¬Ó-ò ´"·(±(Ø1°4ó3ˆIñ œV D¨)×*:Ñ*:Ó*<Ô=Ø4=×4DÑ4DÓ4FÑ1�˜ ¨6ÙÜ ¤ X£´°V³Ñ!<ÀÑ!CÀVÓL�FÙØ!'¨&¡˜˜A™Ø!)¨FÑ!2˜˜Ašà!'˜˜A™Ø!)¨V°f©_Ñ!=˜˜A™ÚÜ ¤ X£´°V³Ñ!<ÀÑ!CÀVÓL�FÙØ!'¨&¡˜˜A™Ø!)¨FÑ!2˜˜A›à!'˜˜A™Ø!)¨V°f©_Ñ!=˜˜Ašà˜’Ø���sØ (¨(�v�ÙÜ ¬¨F°a©K¸Ó(<Ó=�EØŸG™G T¨1¨d°U©l¸HÐ$EÓF�EØŸ'™' 5¨5¡=°!°U¸HÐ"EÓF�CÜ"2°5¸#¸uÀfÓ"M‘K�C˜Ø˜C‘K�DØ˜V‘O�EØ# c™\¨FÑ2�Fò ñ Ü ¬¨F°a©K¸Ó(<Ó=�EØŸG™G Q¨¨X°s¸U±{Ð$CÓD�EØŸ'™' 1 f¨u¡n°hÀÐ"GÓH�CÜ"2°5¸#¸uÀfÓ"M‘K�C˜Ø˜3‘J�CØ˜fÑ$�FØ# c™\¨FÑ2�Fò ð ˜S %¨Ð0�ä˜B“×$Ñ$ SÓ)ˆBØ€Iùòc 5ùÚ/øô< ò 5ä%*§_¡_Ó"ð5üò0 Ps"   �S
«SÃ"S ÇS4ÓS1Ó0S1c                 ó®   — |r(t        | «      j                  t        j                  «      } |r(t        | «      j                  t        j                  «      } | S )zÿ
    Pass the source image through post-processing filters.

    sharpen
        Sharpen the thumbnail image (using the PIL sharpen filter)

    detail
        Add detail to the image, like a mild *sharpen* (using the PIL
        ``detail`` filter).

    )r!   r   r   ÚDETAILÚSHARPEN)r(   ÚdetailÚsharpenr9   s       r   Úfiltersr¦   J  sC   € ñ Ü˜‹^×"Ñ"¤;×#5Ñ#5Ó6ˆÙÜ˜‹^×"Ñ"¤;×#6Ñ#6Ó7ˆØ€Ir   c                 óÌ  — |s| S |d   r|d   s| S | j                   \  }}||d   k\  r
||d   k\  r| S t        | fd|i|¤Ž} t        j                  d||«      }|j                  | j                  k7  r|j                  | j                  «      }|d   |z
  dz  |d   |z
  dz  f}t        | dd«      s|j                  | |«       |S g }t        | j                  «      D ]F  }	| j                  |	«       |j                  «       }
|
j                  | |«       |j                  |
«       ŒH t        «       }|d   j                  || j                  d|dd	 ¬
«       t        j                   |«      S )zŸ
    Add borders of a certain color to make the resized image fit exactly within
    the dimensions given.

    background
        Background color to use
    r   r
   rW   rH   r   rI   FTNr/   )rT   r\   r   rS   rN   rR   r$   rU   r   r#   r3   Úcopyr4   r   r5   r0   r6   )r(   rT   Ú
backgroundr9   ÚxÚyÚnew_imr—   r[   r   Úcopied_new_imr;   s               r   r©   r©   ]  sc  € ñ àˆ	Ø�Š7˜$˜qš'àˆ	Ø�7‰7�D€A€qØˆD�‰G‚|˜˜T !™Wšð ˆ	Ü	�BÑ	; jÐ	;°FÑ	;€BÜ�Y‰Y�u˜d JÓ/€FØ‡{�{�b—g‘gÒØ—‘ §¡Ó(ˆØ�1‰g˜‰k˜aÑ $ q¡'¨A¡+°!Ñ!3Ð3€Fä�2�} eÔ,Ø�‰�R˜Ô ØˆàˆÜ�r—{‘{Ó#ò 	)ˆAØ�G‰G�AŒJØ"ŸK™K›MˆMØ×Ñ  FÔ+Ø�M‰M˜-Õ(ð		)ô
 “9ˆØˆq‰	�‰Ø˜RŸY™Y°ÀVÈAÈBÀZð 	ô 	
ô �z‰z˜(Ó#Ð#r   )FF)F)FFNNr+   )r   r|   Ú	functoolsr   Úior   ÚPILr   r   r   Úeasy_thumbnailsr   r   r   r!   r\   rc   r    r¦   r©   © r   r   ú<module>r³      sJ   ðÛ Û 	Ý Ý ç .Ñ .Ý !òò*÷5ñ 5ó2;ó|ó:kó\ô&'$r   