o
    e&                  
   @  s  d dl mZ d dlZd dlZddlmZ zd dlmZ dZe Z	e	
e W n eyE Z zddlmZ ee ZZ	W Y dZ[ndZ[ww ee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d,ed-ed.eZejd/kreed0< eed1< eed2< eed3< eed4< need0< eed1< eed2< eed3< eed4< d8d6d7ZdS )9    )annotationsN   )	deprecate)FFIz|
    struct Pixel_RGBA {
        unsigned char r,g,b,a;
    };
    struct Pixel_I16 {
        unsigned char l,r;
    };
    )DeferredErrorc                   @  s>   e Zd ZdddZdd Zdd Zdd	 ZeZeZd
d Z	dS )PyAccessFc                 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_ptrsreadonlyfficastr	   r
   r   sizexsizeysize_img_immodepalette_palette
_post_init)selfimgr   vals r!   ?/var/www/html/venv/lib/python3.10/site-packages/PIL/PyAccess.py__init__4   s   
zPyAccess.__init__c                 C  s   d S Nr!   )r   r!   r!   r"   r   H   s   zPyAccess._post_initc                 C  s   | j r	d}t||\}}|dk r| j| }|dk r| j| }| ||f\}}| jjdv ret|tt	fret
|dv re| jjdkrSt
|dkrK|d nd}|d	d }| j|| j}| jjdkre||f}| |||S )
a0  
        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

        :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   r&   r%      N)r   
ValueErrorr   r   check_xyr   r   
isinstancelisttuplelenr   getcolorr   	set_pixel)r   xycolormsgxyalphar!   r!   r"   __setitem__K   s(   


zPyAccess.__setitem__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   r)   	get_pixel)r   r0   r3   r4   r!   r!   r"   __getitem__n   s   

zPyAccess.__getitem__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   r(   )r   r0   r3   r4   r2   r!   r!   r"   r)      s
   2zPyAccess.check_xyNF)
__name__
__module____qualname__r#   r   r6   r8   putpixelgetpixelr)   r!   r!   r!   r"   r   3   s    
#r   c                   @  (   e Zd ZdZdd Z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_initc                 C  s   | j | | }|j|jfS r$   )rD   rar   r3   r4   pixelr!   r!   r"   r7      s   z_PyAccess32_2.get_pixelc                 C  s2   | j | | }t|d d|_t|d d|_d S )Nr   r'   r   )rD   minrI   rJ   r   r3   r4   r1   rL   r!   r!   r"   r/      s   z_PyAccess32_2.set_pixelNr:   r;   r<   __doc__r   r7   r/   r!   r!   r!   r"   r@      
    r@   c                   @  r?   )	_PyAccess32_3zARGB and friends, stored in the first three bytes of a 32 bit wordc                 O  rA   rB   rC   rE   r!   r!   r"   r      rH   z_PyAccess32_3._post_initc                 C  s   | j | | }|j|j|jfS r$   )rD   rI   gbrK   r!   r!   r"   r7         z_PyAccess32_3.get_pixelc                 C  sH   | j | | }t|d d|_t|d d|_t|d d|_d|_d S )Nr   r'   r      rD   rM   rI   rS   rT   rJ   rN   r!   r!   r"   r/      s
   
z_PyAccess32_3.set_pixelNrO   r!   r!   r!   r"   rR      rQ   rR   c                   @  r?   )	_PyAccess32_4z&RGBA etc, all 4 bytes of a 32 bit wordc                 O  rA   rB   rC   rE   r!   r!   r"   r      rH   z_PyAccess32_4._post_initc                 C  s"   | j | | }|j|j|j|jfS r$   )rD   rI   rS   rT   rJ   rK   r!   r!   r"   r7      s   z_PyAccess32_4.get_pixelc                 C  sR   | j | | }t|d d|_t|d d|_t|d d|_t|d d|_d S )Nr   r'   r   rV   r%   rW   rN   r!   r!   r"   r/      s
   z_PyAccess32_4.set_pixelNrO   r!   r!   r!   r"   rX      rQ   rX   c                   @  r?   )	
_PyAccess8z%1, L, P, 8 bit images stored as uint8c                 O     | j | _d S r$   )r	   rD   rE   r!   r!   r"   r         z_PyAccess8._post_initc                 C     | j | | S r$   rD   r   r3   r4   r!   r!   r"   r7         z_PyAccess8.get_pixelc                 C  H   zt |d| j| |< W d S  ty#   t |d d| j| |< Y d S w )Nr'   r   rM   rD   	TypeErrorr   r3   r4   r1   r!   r!   r"   r/      
   z_PyAccess8.set_pixelNrO   r!   r!   r!   r"   rY      
    rY   c                   @  r?   )	_PyAccessI16_Nz0I;16 access, native bitendian without conversionc                 O  rA   )Nzunsigned short **r   r   r   rD   rE   r!   r!   r"   r      rH   z_PyAccessI16_N._post_initc                 C  r\   r$   r]   r^   r!   r!   r"   r7      r_   z_PyAccessI16_N.get_pixelc                 C  r`   )N  r   ra   rc   r!   r!   r"   r/      rd   z_PyAccessI16_N.set_pixelNrO   r!   r!   r!   r"   rf      re   rf   c                   @  r?   )	_PyAccessI16_LzI;16L access, with conversionc                 O  rA   Nzstruct Pixel_I16 **rg   rE   r!   r!   r"   r      rH   z_PyAccessI16_L._post_initc                 C  s   | j | | }|j|jd  S N   rD   lrI   rK   r!   r!   r"   r7      rU   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 )Nrh   r   r'      )rD   rM   rb   rn   rI   rN   r!   r!   r"   r/         
z_PyAccessI16_L.set_pixelNrO   r!   r!   r!   r"   ri      rQ   ri   c                   @  r?   )	_PyAccessI16_BzI;16B access, with conversionc                 O  rA   rj   rg   rE   r!   r!   r"   r      rH   z_PyAccessI16_B._post_initc                 C  s   | j | | }|jd |j S rk   rm   rK   r!   r!   r"   r7     rU   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 )Nrh   r   ro   r'   )rD   rM   	Exceptionrn   rI   rN   r!   r!   r"   r/     rp   z_PyAccessI16_B.set_pixelNrO   r!   r!   r!   r"   rq      rQ   rq   c                   @  r?   )	_PyAccessI32_Nz"Signed Int32 access, native endianc                 O  rZ   r$   r
   rD   rE   r!   r!   r"   r     r[   z_PyAccessI32_N._post_initc                 C  r\   r$   r]   r^   r!   r!   r"   r7     r_   z_PyAccessI32_N.get_pixelc                 C  s   || j | |< d S r$   r]   rc   r!   r!   r"   r/     s   z_PyAccessI32_N.set_pixelNrO   r!   r!   r!   r"   rs     re   rs   c                   @  s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_PyAccessI32_Swapz,I;32L/B access, with byteswapping conversionc                 O  rZ   r$   rt   rE   r!   r!   r"   r   !  r[   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 *r%   rV   r   r   )r   newr   )r   iorigcharsr!   r!   r"   reverse$  s   4z_PyAccessI32_Swap.reversec                 C  s   |  | j| | S r$   rz   rD   r^   r!   r!   r"   r7   *  rH   z_PyAccessI32_Swap.get_pixelc                 C  s   |  || j| |< d S r$   r{   rc   r!   r!   r"   r/   -  s   z_PyAccessI32_Swap.set_pixelN)r:   r;   r<   rP   r   rz   r7   r/   r!   r!   r!   r"   ru     s    ru   c                   @  r?   )	
_PyAccessFz32 bit float accessc                 O  rA   )Nzfloat **rC   rE   r!   r!   r"   r   4  rH   z_PyAccessF._post_initc                 C  r\   r$   r]   r^   r!   r!   r"   r7   7  r_   z_PyAccessF.get_pixelc                 C  s<   z
|| j | |< W d S  ty   |d | j | |< Y d S w )Nr   )rD   rb   rc   r!   r!   r"   r/   :  s
   z_PyAccessF.set_pixelNrO   r!   r!   r!   r"   r|   1  re   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;32BFc                 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"   rv   g  s
   
rv   r9   ) 
__future__r   loggingsys
_deprecater   cffir   defsr   cdefImportErrorex_utilr   rv   	getLoggerr:   r   r   r@   rR   rX   rY   rf   ri   rq   rs   ru   r|   r   	byteorderr!   r!   r!   r"   <module>   s   
Y	


