o
    Ëf[*                  
   @  sB  U d dl mZ d dlZd dlZd dlmZ ddlmZ ded< zd dl	m
Z
 d	Ze
 Zee W n eyP Z zdd
lmZ ee Z
ZW Y dZ[ndZ[ww eeZer^ddlmZ G dd d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G dd deZG dd deZ G dd deZ!G d d! d!eZ"i d"ed#ed$ed%ed&ed'ed(ed)ed*ed+ed,ed-ed.ed/ed0ed1e"d2e Z#ej$d3kree#d4< ee#d5< ee#d6< e e#d7< e!e#d8< nee#d4< ee#d5< ee#d6< e!e#d7< e e#d8< dBdCd@dAZdS )D    )annotationsN)TYPE_CHECKING   )	deprecatetypeFFI)r   z|
    struct Pixel_RGBA {
        unsigned char r,g,b,a;
    };
    struct Pixel_I16 {
        unsigned char l,r;
    };
    )DeferredError)Imagec                   @  s\   e Zd Zd d!dd	Zd"d
dZd#ddZd$ddZeZeZd%ddZ	d&ddZ
d'ddZdS )(PyAccessFimgImage.ImagereadonlyboolreturnNonec                 C  s   t dd t|jj}|| _td|d | _td|d | _td|d | _	|jj
\| _| _|| _|j| _| jjdv rB|j| _|   d S )	Nr
      zunsigned char **image8zint **image32imagePPA)r   dictimunsafe_ptrsr   fficastr   r   r   sizexsizeysize_img_immodepalette_palette
_post_init)selfr   r   vals r(   G/var/www/html/humari/myenv/lib/python3.10/site-packages/PIL/PyAccess.py__init__9   s   
zPyAccess.__init__c                 C  s   d S Nr(   )r&   r(   r(   r)   r%   M   s   zPyAccess._post_initxytuple[int, int] | list[int]color#float | tuple[int, ...] | list[int]c                 C  s   | j r	d}t||\}}|dk r| j| }|dk r| j| }| ||f\}}| jjdv rgt|tt	frgt
|dv rg| jjdkrSt
|dkrK|d nd}|d	d }| j|| j}| jjdkre||fn|}| |||S )
a  
        Modifies the pixel at x,y. The color is given as a single
        numerical value for single band images, and a tuple for
        multi-band images. In addition to this, RGB and RGBA tuples
        are accepted for P and PA images.

        :param xy: The pixel coordinate, given as (x, y). See
           :ref:`coordinate-system`.
        :param color: The pixel value.
        z%Attempt to putpixel a read only imager   r   )      r   r1   r0      N)r   
ValueErrorr   r   check_xyr!   r"   
isinstancelisttuplelenr$   getcolorr    	set_pixel)r&   r,   r.   msgxyalphapalette_indexr(   r(   r)   __setitem__P   s&   

zPyAccess.__setitem__float | tuple[int, ...]c                 C  sJ   |\}}|dk r| j | }|dk r| j| }| ||f\}}| ||S )aq  
        Returns the pixel at x,y. The pixel is returned as a single
        value for single band images or a tuple for multiple band
        images

        :param xy: The pixel coordinate, given as (x, y). See
          :ref:`coordinate-system`.
        :returns: a pixel value for single band images, a tuple of
          pixel values for multiband images.
        r   )r   r   r4   	get_pixel)r&   r,   r<   r=   r(   r(   r)   __getitem__w   s   

zPyAccess.__getitem__tuple[int, int]c                 C  sJ   |\}}d|  kr| j k rn nd|  kr| jk s#n d}t||S )Nr   zpixel location out of range)r   r   r3   )r&   r,   r<   r=   r;   r(   r(   r)   r4      s
   2zPyAccess.check_xyr<   intr=   c                 C     t  r+   NotImplementedErrorr&   r<   r=   r(   r(   r)   rB      s   zPyAccess.get_pixelc                 C  rF   r+   rG   r&   r<   r=   r.   r(   r(   r)   r:      s   zPyAccess.set_pixelNF)r   r   r   r   r   r   )r   r   )r,   r-   r.   r/   r   r   )r,   r-   r   rA   )r,   rD   r   rD   )r<   rE   r=   rE   r   rA   )r<   rE   r=   rE   r.   r/   r   r   )__name__
__module____qualname__r*   r%   r@   rC   putpixelgetpixelr4   rB   r:   r(   r(   r(   r)   r
   8   s    


'

r
   c                   @  *   e Zd ZdZdd Zdd	d
Zdd ZdS )_PyAccess32_2z7PA, LA, stored in first and last bytes of a 32 bit wordc                 O     t d| j| _d S Nzstruct Pixel_RGBA **r   r   r   pixelsr&   argskwargsr(   r(   r)   r%         z_PyAccess32_2._post_initr<   rE   r=   r   rD   c                 C  s   | j | | }|j|jfS r+   )rV   rar&   r<   r=   pixelr(   r(   r)   rB      s   z_PyAccess32_2.get_pixelc                 C  s2   | j | | }t|d d|_t|d d|_d S )Nr   r2   r   )rV   minr[   r\   r&   r<   r=   r.   r^   r(   r(   r)   r:      s   z_PyAccess32_2.set_pixelN)r<   rE   r=   rE   r   rD   rL   rM   rN   __doc__r%   rB   r:   r(   r(   r(   r)   rR      
    
rR   c                   @  rQ   )_PyAccess32_3zARGB and friends, stored in the first three bytes of a 32 bit wordc                 O  rS   rT   rU   rW   r(   r(   r)   r%      rZ   z_PyAccess32_3._post_initr<   rE   r=   r   tuple[int, int, int]c                 C  s   | j | | }|j|j|jfS r+   )rV   r[   gbr]   r(   r(   r)   rB         z_PyAccess32_3.get_pixelc                 C  sH   | j | | }t|d d|_t|d d|_t|d d|_d|_d S )Nr   r2   r      rV   r_   r[   rf   rg   r\   r`   r(   r(   r)   r:      s
   
z_PyAccess32_3.set_pixelN)r<   rE   r=   rE   r   re   ra   r(   r(   r(   r)   rd      rc   rd   c                   @  rQ   )_PyAccess32_4z&RGBA etc, all 4 bytes of a 32 bit wordc                 O  rS   rT   rU   rW   r(   r(   r)   r%      rZ   z_PyAccess32_4._post_initr<   rE   r=   r   tuple[int, int, int, int]c                 C  s"   | j | | }|j|j|j|jfS r+   )rV   r[   rf   rg   r\   r]   r(   r(   r)   rB      s   z_PyAccess32_4.get_pixelc                 C  sR   | j | | }t|d d|_t|d d|_t|d d|_t|d d|_d S )Nr   r2   r   ri   r0   rj   r`   r(   r(   r)   r:      s
   z_PyAccess32_4.set_pixelN)r<   rE   r=   rE   r   rl   ra   r(   r(   r(   r)   rk      rc   rk   c                   @  *   e Zd ZdZdd Zddd	Zd
d ZdS )
_PyAccess8z%1, L, P, 8 bit images stored as uint8c                 O     | j | _d S r+   )r   rV   rW   r(   r(   r)   r%         z_PyAccess8._post_initr<   rE   r=   r   c                 C     | j | | S r+   rV   rI   r(   r(   r)   rB         z_PyAccess8.get_pixelc                 C  H   zt |d| j| |< W d S  ty#   t |d d| j| |< Y d S w )Nr2   r   r_   rV   	TypeErrorrJ   r(   r(   r)   r:      
   z_PyAccess8.set_pixelNr<   rE   r=   rE   r   rE   ra   r(   r(   r(   r)   rn      
    
rn   c                   @  rm   )_PyAccessI16_Nz0I;16 access, native bitendian without conversionc                 O  rS   )Nzunsigned short **r   r   r   rV   rW   r(   r(   r)   r%      rZ   z_PyAccessI16_N._post_initr<   rE   r=   r   c                 C  rq   r+   rr   rI   r(   r(   r)   rB      rs   z_PyAccessI16_N.get_pixelc                 C  rt   )N  r   ru   rJ   r(   r(   r)   r:      rw   z_PyAccessI16_N.set_pixelNrx   ra   r(   r(   r(   r)   rz      ry   rz   c                   @  rm   )_PyAccessI16_LzI;16L access, with conversionc                 O  rS   Nzstruct Pixel_I16 **r{   rW   r(   r(   r)   r%      rZ   z_PyAccessI16_L._post_initr<   rE   r=   r   c                 C  s   | j | | }|j|jd  S N   rV   lr[   r]   r(   r(   r)   rB      rh   z_PyAccessI16_L.get_pixelc                 C  sV   | j | | }zt|d}W n ty   t|d d}Y nw |d@ |_|d? |_d S )Nr|   r   r2      )rV   r_   rv   r   r[   r`   r(   r(   r)   r:        
z_PyAccessI16_L.set_pixelNrx   ra   r(   r(   r(   r)   r}      rc   r}   c                   @  rm   )_PyAccessI16_BzI;16B access, with conversionc                 O  rS   r~   r{   rW   r(   r(   r)   r%     rZ   z_PyAccessI16_B._post_initr<   rE   r=   r   c                 C  s   | j | | }|jd |j S r   r   r]   r(   r(   r)   rB     rh   z_PyAccessI16_B.get_pixelc                 C  sV   | j | | }zt|d}W n ty   t|d d}Y nw |d? |_|d@ |_d S )Nr|   r   r   r2   )rV   r_   	Exceptionr   r[   r`   r(   r(   r)   r:     r   z_PyAccessI16_B.set_pixelNrx   ra   r(   r(   r(   r)   r     rc   r   c                   @  rm   )_PyAccessI32_Nz"Signed Int32 access, native endianc                 O  ro   r+   r   rV   rW   r(   r(   r)   r%   %  rp   z_PyAccessI32_N._post_initr<   rE   r=   r   c                 C  rq   r+   rr   rI   r(   r(   r)   rB   (  rs   z_PyAccessI32_N.get_pixelc                 C  s   || j | |< d S r+   rr   rJ   r(   r(   r)   r:   +  s   z_PyAccessI32_N.set_pixelNrx   ra   r(   r(   r(   r)   r   "  ry   r   c                   @  s2   e Zd ZdZdd Zdd Zdd
dZdd ZdS )_PyAccessI32_Swapz,I;32L/B access, with byteswapping conversionc                 O  ro   r+   r   rW   r(   r(   r)   r%   2  rp   z_PyAccessI32_Swap._post_initc                 C  s\   t d|}t d|}|d |d |d |d f\|d< |d< |d< |d< t d|d S )Nzint *zunsigned char *r0   ri   r   r   )r   newr   )r&   iorigcharsr(   r(   r)   reverse5  s   4z_PyAccessI32_Swap.reverser<   rE   r=   r   c                 C  s   |  | j| | S r+   r   rV   rI   r(   r(   r)   rB   ;  rZ   z_PyAccessI32_Swap.get_pixelc                 C  s   |  || j| |< d S r+   r   rJ   r(   r(   r)   r:   >  s   z_PyAccessI32_Swap.set_pixelNrx   )rL   rM   rN   rb   r%   r   rB   r:   r(   r(   r(   r)   r   /  s    
r   c                   @  rQ   )
_PyAccessFz32 bit float accessc                 O  rS   )Nzfloat **rU   rW   r(   r(   r)   r%   E  rZ   z_PyAccessF._post_initr<   rE   r=   r   floatc                 C  rq   r+   rr   rI   r(   r(   r)   rB   H  rs   z_PyAccessF.get_pixelc                 C  s<   z
|| j | |< W d S  ty   |d | j | |< Y d S w )Nr   )rV   rv   rJ   r(   r(   r)   r:   K  s
   z_PyAccessF.set_pixelN)r<   rE   r=   rE   r   r   ra   r(   r(   r(   r)   r   B  ry   r   1Lr   zI;16NLALar   RGBLABHSVYCbCrRGBARGBaRGBXCMYKFIlittlezI;16zI;16LzI;16BzI;32LzI;32BFr   r   r   r   r   PyAccess | Nonec                 C  s.   t | jd }|std| j d S || |S )NzPyAccess Not Implemented: %s)mode_mapgetr"   loggerdebug)r   r   access_typer(   r(   r)   r   x  s
   
r   rK   )r   r   r   r   r   r   )%
__future__r   loggingsystypingr   
_deprecater   __annotations__cffir   defsr   cdefImportErrorex_utilr   r   	getLoggerrL   r    r	   r
   rR   rd   rk   rn   rz   r}   r   r   r   r   r   	byteorderr(   r(   r(   r)   <module>   s   
e	

