o
    ^oiR                     @   s:   d dl mZmZ dd Zdd ZeejdeZdd Zd	S )
   )Image	ImageModec                 C   s(   t | j}| j\}}|| t|j S )z Return the number of color values in the input image --
        this is the number of pixels times the band count
        of the image.
    )r   ZgetmodemodesizelenZbands)imageZmode_descriptorwidthheight r
   _/var/www/html/kuke-dev/django-kuke/venv/lib/python3.10/site-packages/pilkit/processors/utils.pycolor_count   s   
r   c                    sJ   ddl mm} tt|   fdd|  D }|fdd|D  S )z0 Calculate the entropy of an images' histogram.     )log2fsumc                 3   s    | ]}|  V  qd S )Nr
   ).0Zhistocol)histosumr
   r   	<genexpr>   s    z'histogram_entropy_py.<locals>.<genexpr>c                 3   s$    | ]}|d kr| | V  qdS )g        Nr
   )r   p)r   r
   r   r      s   " )mathr   r   floatr   Z	histogram)r   r   Z	histonormr
   )r   r   r   histogram_entropy_py   s   r   Zentropyc                 C   s$   |    | jdu r| S | | jjS )z1 Convert a palette image to a non-palette image. N)loadpaletteconvertr   )r   r
   r
   r   resolve_palette   s   
r   N)libr   r   r   r   getattrZhistogram_entropyr   r
   r
   r
   r   <module>   s
    		