o
    uX                     @   sx   d dl 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ImageEnhancec                   @   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   K/var/www/jaguar/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   r/   r0   r1   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)   r2   r   r4   r   r   )r   getrgbr/   r    copy	transposer   FLIP_TOP_BOTTOMnewr0   intr1   floatrangeputpixelresize	compositecroppaste)r   r	   r/   
reflection
backgroundstartsteps	incrementmaskyval
alpha_maskreflection_heightr@   r   r   r   r   M   s*   
"zReflection.processN)r,   r-   r.   r*   r   r   r   r   r+   C   s    
r+   c                	       sx   e Zd ZdZdZejZejZ	ej
Z
ejZej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 )	Transposez&
    Rotates or flips the image.

    auto)r4      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)superrM   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  )	AUTOrU   _getexif_EXIF_ORIENTATION_STEPS
IndexErrorKeyError	TypeErrorAttributeErrorr8   )r   r	   orientationopsmethodr   r   r   r      s   zTranspose.process)r   r   r   r   rY   r   FLIP_LEFT_RIGHTFLIP_HORIZONTALr9   FLIP_VERTICAL	ROTATE_90
ROTATE_180
ROTATE_270rU   r[   r   r   __classcell__r   r   rW   r   rM   q   s(    rM   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rr5   )      ?r   )r4   r   )r   rt   )rt   rt   )r4   rt   )r   r4   )rt   r4   )r4   r4   c                 C   s   | t j v rt j|  } | S )zANormalizes anchor values (strings or tuples) to tuples.

        )rj   _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RIGHTru   staticmethodrx   r   r   r   r   rj      s.    rj   c                   @   r   )	
MakeOpaquez
    Pastes the provided image onto an image of a solid color. Used for when you
    want to make transparent images opaque.

    r2   r2   r2   c                 C   s
   || _ d S r   )r/   )r   r/   r   r   r   r      s   
zMakeOpaque.__init__c                 C   s,   | d}td|j| j}||| |S )Nr   )r    r   r:   r0   r/   rB   )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   listr   objectr   r+   rM   rj   r   r   r   r   r   <module>   s    0.<'