Ë
    ¦üàgÍ  ã                  óH   — d dl mZ d dlZd dlmZ ddlmZ  G d„ d«      ZeZy)é    )ÚannotationsN)Úcached_propertyé   )ÚImagec                  óÄ   — e Zd Z	 d	 	 	 	 	 dd„Zedd„«       Zedd„«       Zedd„«       Zedd„«       Zedd„«       Z	edd„«       Z
edd	„«       Zedd
„«       Zedd„«       Zy)ÚStatNc                ó  — t        |t        j                  «      r|j                  |«      | _        n%t        |t        «      r|| _        nd}t        |«      ‚t	        t        t        | j                  «      dz  «      «      | _        y)a
  
        Calculate statistics for the given image. If a mask is included,
        only the regions covered by that mask are included in the
        statistics. You can also pass in a previously calculated histogram.

        :param image: A PIL image, or a precalculated histogram.

            .. note::

                For a PIL image, calculations rely on the
                :py:meth:`~PIL.Image.Image.histogram` method. The pixel counts are
                grouped into 256 bins, even if the image has more than 8 bits per
                channel. So ``I`` and ``F`` mode images have a maximum ``mean``,
                ``median`` and ``rms`` of 255, and cannot have an ``extrema`` maximum
                of more than 255.

        :param mask: An optional mask.
        z$first argument must be image or listé   N)	Ú
isinstancer   Ú	histogramÚhÚlistÚ	TypeErrorÚrangeÚlenÚbands)ÚselfÚimage_or_listÚmaskÚmsgs       úK/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/PIL/ImageStat.pyÚ__init__zStat.__init__    sb   € ô* �m¤U§[¡[Ô1Ø"×,Ñ,¨TÓ2ˆD�FÜ˜¤tÔ,Ø"ˆD�Fà8ˆCÜ˜C“.Ð Üœ%¤ D§F¡F£¨sÑ 2Ó3Ó4ˆ�
ó    c                ó–   — dd„}t        dt        | j                  «      d«      D �cg c]  } || j                  |d «      ‘Œ c}S c c}w )au  
        Min/max values for each band in the image.

        .. note::
            This relies on the :py:meth:`~PIL.Image.Image.histogram` method, and
            simply returns the low and high bins used. This is correct for
            images with 8 bits per channel, but fails for other modes such as
            ``I`` or ``F``. Instead, use :py:meth:`~PIL.Image.Image.getextrema` to
            return per-band extrema for the image. This is more correct and
            efficient because, for non-8-bit modes, the histogram method uses
            :py:meth:`~PIL.Image.Image.getextrema` to determine the bins used.
        c                ó‚   — d\  }}t        d«      D ]  }| |   sŒ	|} n t        ddd«      D ]  }| |   sŒ	|} ||fS  ||fS )N)éÿ   r   r
   r   éÿÿÿÿ)r   )r   Úres_minÚres_maxÚis       r   ÚminmaxzStat.extrema.<locals>.minmaxM   so   € Ø%ÑˆG�WÜ˜3“Zò �Ø˜Q“<Ø�GÙðô ˜3  BÓ'ò �Ø˜Q“<Ø�GØØ˜GÐ#Ð#ð	ð ˜GÐ#Ð#r   r   r
   N)r   ú	list[int]Úreturnztuple[int, int])r   r   r   )r   r!   r    s      r   ÚextremazStat.extrema>   s=   € ó
	$ô -2°!´S¸¿¹³[À#Ó,FÖG q‘�t—v‘v˜a˜b�zÕ"ÒGÐGùÒGs   §Ac           	     óš   — t        dt        | j                  «      d«      D �cg c]  }t        | j                  ||dz    «      ‘Œ c}S c c}w )z2Total number of pixels for each band in the image.r   r
   )r   r   r   Úsum©r   r    s     r   Úcountz
Stat.count[   s=   € ô 38¸¼3¸t¿v¹v»;ÈÓ2LÖM¨Q”�D—F‘F˜1˜q 3™wÐ'Õ(ÒMÐMùÒMs   £"Ac                óÊ   — g }t        dt        | j                  «      d«      D ]=  }d}t        d«      D ]  }||| j                  ||z      z  z  }Œ |j                  |«       Œ? |S )z-Sum of all pixels for each band in the image.r   r
   ç        )r   r   r   Úappend)r   Úvr    Ú	layer_sumÚjs        r   r&   zStat.sum`   so   € ð ˆÜ�qœ#˜dŸf™f›+ sÓ+ò 	 ˆAØˆIÜ˜3“Zò /�Ø˜Q §¡¨¨A©¡Ñ.Ñ.‘	ð/à�H‰H�YÕð		 ð
 ˆr   c           	     óâ   — g }t        dt        | j                  «      d«      D ]I  }d}t        d«      D ]&  }||dz  t        | j                  ||z      «      z  z  }Œ( |j	                  |«       ŒK |S )z5Squared sum of all pixels for each band in the image.r   r
   r*   é   )r   r   r   Úfloatr+   )r   r,   r    Úsum2r.   s        r   r2   z	Stat.sum2l   sw   € ð ˆÜ�qœ#˜dŸf™f›+ sÓ+ò 	ˆAØˆDÜ˜3“Zò 6�Ø˜˜A™¤ t§v¡v¨a°!©e¡}Ó!5Ñ5Ñ5‘ð6à�H‰H�T�Nð		ð
 ˆr   c                óz   — | j                   D �cg c]!  }| j                  |   | j                  |   z  ‘Œ# c}S c c}w )zAAverage (arithmetic mean) pixel level for each band in the image.)r   r&   r(   r'   s     r   Úmeanz	Stat.meanx   s1   € ð 6:·Z±ZÖ@°�—‘˜‘˜dŸj™j¨™mÓ+Ò@Ð@ùÒ@s   �&8c                óØ   — g }| j                   D ]X  }d}| j                  |   dz  }|dz  }t        d«      D ]  }|| j                  ||z      z   }||kD  sŒ n |j	                  «       ŒZ |S )z.Median pixel level for each band in the image.r   r0   r
   )r   r(   r   r   r+   )r   r,   r    ÚsÚhalfÚbr.   s          r   ÚmedianzStat.median}   sƒ   € ð ˆØ—‘ò 	ˆAØˆAØ—:‘:˜a‘= AÑ%ˆDØ�C‘ˆAÜ˜3“Zò �Ø˜Ÿ™˜q 1™u™Ñ%�Ø�t“8Ùðð �H‰H�Q�Kð	ð ˆr   c                ó    — | j                   D �cg c]4  }t        j                  | j                  |   | j                  |   z  «      ‘Œ6 c}S c c}w )z2RMS (root-mean-square) for each band in the image.)r   ÚmathÚsqrtr2   r(   r'   s     r   ÚrmszStat.rms�   s<   € ð BFÇÁÖL¸A”—	‘	˜$Ÿ)™) A™,¨¯©°A©Ñ6Õ7ÒLÐLùÒLs   �9Ac                óÀ   — | j                   D �cg c]D  }| j                  |   | j                  |   dz  | j                  |   z  z
  | j                  |   z  ‘ŒF c}S c c}w )z$Variance for each band in the image.g       @)r   r2   r&   r(   r'   s     r   ÚvarzStat.var’   s\   € ð
 —Z‘Zö
àð �Y‰Y�q‰\˜TŸX™X a™[¨CÑ/°4·:±:¸a±=Ñ@Ñ@ÀDÇJÁJÈqÁMÓQò
ð 	
ùò 
s   �A	Ac                ó€   — | j                   D �cg c]$  }t        j                  | j                  |   «      ‘Œ& c}S c c}w )z.Standard deviation for each band in the image.)r   r;   r<   r?   r'   s     r   ÚstddevzStat.stddevš   s-   € ð 15·
±
Ö;¨1”—	‘	˜$Ÿ(™( 1™+Õ&Ò;Ð;ùÒ;s   �);)N)r   zImage.Image | list[int]r   zImage.Image | Noner#   ÚNone)r#   zlist[tuple[int, int]])r#   r"   )r#   zlist[float])Ú__name__Ú
__module__Ú__qualname__r   r   r$   r(   r&   r2   r4   r9   r=   r?   rA   © r   r   r   r      sÞ   „ àQUð5Ø4ð5Ø<Nð5à	ó5ð< òHó ðHð8 òNó ðNð ò	ó ð	ð ò	ó ð	ð òAó ðAð òó ðð òMó ðMð ò
ó ð
ð ò<ó ñ<r   r   )	Ú
__future__r   r;   Ú	functoolsr   Ú r   r   ÚGlobalrF   r   r   ú<module>rK      s'   ðõ. #ã Ý %å ÷~<ñ ~<ðB 
�r   