o
    	&zh                     @   s|   d dl mZmZmZmZ G dd deZG dd deZG dd deZ	G dd	 d	eZ
G d
d deZG dd deZdS )    )Image
ImageColorImageEnhancegetattrsafec                   @   s   e Zd ZdZdd ZdS )ProcessorPipelinea  
    A :class:`list` of other processors. This class allows any object that
    knows how to deal with a single processor to deal with a list of them.
    For example::

        processed_image = ProcessorPipeline([ProcessorA(), ProcessorB()]).process(image)

    c                 C   s   | D ]}| |}q|S N)process)selfimgproc r   Q/var/www/html/kangema/venv/lib/python3.10/site-packages/pilkit/processors/base.pyr      s   zProcessorPipeline.processN)__name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                   @   "   e Zd ZdZdddZdd ZdS )	Adjustz
    Performs color, brightness, contrast, and sharpness enhancements on the
    image. See :mod:`PIL.ImageEnhance` for more imformation.

          ?c                 C   s   || _ || _|| _|| _dS )a  
        :param color: A number between 0 and 1 that specifies the saturation
            of the image. 0 corresponds to a completely desaturated image
            (black and white) and 1 to the original color.
            See :class:`PIL.ImageEnhance.Color`
        :param brightness: A number representing the brightness; 0 results in
            a completely black image whereas 1 corresponds to the brightness
            of the original. See :class:`PIL.ImageEnhance.Brightness`
        :param contrast: A number representing the contrast; 0 results in a
            completely gray image whereas 1 corresponds to the contrast of
            the original. See :class:`PIL.ImageEnhance.Contrast`
        :param sharpness: A number representing the sharpness; 0 results in a
            blurred image; 1 corresponds to the original sharpness; 2
            results in a sharpened image. See
            :class:`PIL.ImageEnhance.Sharpness`

        N)color
brightnesscontrast	sharpness)r	   r   r   r   r   r   r   r   __init__   s   
zAdjust.__init__c              	   C   s   | d }}dD ];}t| | }|dkrDztt|||}W n	 ty+   Y q	w |dv rDtd| d d | dd  }q	|S )NRGBA)Color
BrightnessContrast	Sharpnessr   )r   r         )	convertgetattrlowerr   enhance
ValueErrorr   mergesplit)r	   r
   originalnamefactorr   r   r   r   0   s   zAdjust.processN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    
r   c                   @   s"   e Zd ZdZd
ddZdd Zd	S )
Reflectionz.
    Creates an image with a reflection.

    #FFFFFF        333333?c                 C   s   || _ || _|| _d S r   )background_colorsizeopacity)r	   r0   r1   r2   r   r   r   r   H   s   
zReflection.__init__c                 C   s<  t | j}|d}| tj}t	d|j
|}tdd| j  }td| j
 }d| t| }t	dd}tdD ]}	|	|k rLt|	| | }
nd}
|d|	f|
 q=||j
}t|||}t|j
d | j
 }|dd|j
d |f}t	d|j
d |j
d | f|}||d ||d|j
d f |S )Nr      L)   r3   r   r5   r   r   )r   getrgbr0   r!   copy	transpose	TransposeFLIP_VERTICALr   newr1   intr2   floatrangeputpixelresize	compositecroppaste)r	   r
   r0   
reflection
backgroundstartsteps	incrementmaskyval
alpha_maskreflection_heightrB   r   r   r   r   M   s*   
"zReflection.processN)r-   r.   r/   r+   r   r   r   r   r,   C   s    
r,   c                	       s   e Zd ZdZdZeeddZeeddZeeddZ	eed	d
Z
eeddZegZg ege
gegeegege	ege	gdZ fddZdd Z  ZS )r:   z&
    Rotates or flips the image.

    autozTranspose.FLIP_LEFT_RIGHTFLIP_LEFT_RIGHTzTranspose.FLIP_TOP_BOTTOMFLIP_TOP_BOTTOMzTranspose.ROTATE_90	ROTATE_90zTranspose.ROTATE_180
ROTATE_180zTranspose.ROTATE_270
ROTATE_270)r5      r   r                c                    s    t t|   |r|| _dS dS )a  
        Possible arguments:
            - Transpose.AUTO
            - Transpose.FLIP_HORIZONTAL
            - Transpose.FLIP_VERTICAL
            - Transpose.ROTATE_90
            - Transpose.ROTATE_180
            - Transpose.ROTATE_270

        The order of the arguments dictates the order in which the
        Transposition steps are taken.

        If Transpose.AUTO is present, all other arguments are ignored, and
        the processor will attempt to rotate the image according to the
        EXIF Orientation data.

        N)superr:   r   methods)r	   args	__class__r   r   r      s   
zTranspose.__init__c                 C   sd   | j | jv r#z| d }| j| }W n ttttfy"   g }Y nw | j}|D ]}||}q(|S )Ni  )	AUTOr[   _getexif_EXIF_ORIENTATION_STEPS
IndexErrorKeyError	TypeErrorAttributeErrorr9   )r	   r
   orientationopsmethodr   r   r   r      s   zTranspose.process)r   r   r   r   r_   r   r   FLIP_HORIZONTALr;   rR   rS   rT   r[   ra   r   r   __classcell__r   r   r]   r   r:   q   s(    r:   c                   @   sh   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Zedededede
dededede	di	Zedd ZdS )AnchorzQ
    Defines all the anchor points needed by the various processor classes.

    tlttrblbbrclrr6   )      ?r   )r5   r   )r   ru   )ru   ru   )r5   ru   )r   r5   )ru   r5   )r5   r5   c                 C   s   | t j v rt j|  } | S )zANormalizes anchor values (strings or tuples) to tuples.

        )rk   _ANCHOR_PTSkeys)anchorr   r   r   	get_tuple   s   
zAnchor.get_tupleN)r   r   r   r   TOP_LEFTTOP	TOP_RIGHTBOTTOM_LEFTBOTTOMBOTTOM_RIGHTCENTERLEFTRIGHTrv   staticmethodry   r   r   r   r   rk      s.    rk   c                   @   r   )	
MakeOpaquez
    Pastes the provided image onto an image of a solid color. Used for when you
    want to make transparent images opaque.

    r3   r3   r3   c                 C   s
   || _ d S r   )r0   )r	   r0   r   r   r   r      s   
zMakeOpaque.__init__c                 C   s,   | d}td|j| j}||| |S )Nr   )r!   r   r<   r1   r0   rD   )r	   r
   new_imgr   r   r   r      s   
zMakeOpaque.processN)r   r+   r   r   r   r   r      s    
r   N)
pilkit.libr   r   r   r   listr   objectr   r,   r:   rk   r   r   r   r   r   <module>   s    0.<'