3 }\$@s|ddlZddlZddlmZejeZdZeZej eGddde Z Gddde Z Gdd d e Z Gd d d e ZGd d d e ZGddde ZGddde ZGddde ZGddde ZGddde ZGddde Zeeee e e e e e e eeeeeedZejdkrFeed<eed<eed<eed<eed <n(eed<eed<eed<eed<eed <d$d"d#ZdS)%N)FFIz` struct Pixel_RGBA { unsigned char r,g,b,a; }; struct Pixel_I16 { unsigned char l,r; }; c@s>eZdZd ddZddZddZdd ZeZeZd d Z d S)PyAccessFcCst|jj}||_tjd|d|_tjd|d|_tjd|d|_|jj \|_ |_ |j|_ |j j dkrt|j|_|jdS)Nzunsigned char **image8zint **image32imageP)dictZimZ unsafe_ptrsreadonlyfficastrrrsizexsizeysize_immodeZpalette_palette _post_init)selfimgr valsrd/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-i584jbuk/Pillow/PIL/PyAccess.py__init__.s  zPyAccess.__init__cCsdS)Nr)rrrrr@szPyAccess._post_initcCs|jrtd|\}}|dkr(|j|}|dkr:|j|}|j||f\}}|jjdkr~t|tt fr~t |dkr~|j j |}|j |||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 imagerr)rr)r ValueErrorr rcheck_xyrr isinstancelisttuplelenrZgetcolor set_pixel)rxycolorxyrrr __setitem__Cs     zPyAccess.__setitem__cCsJ|\}}|dkr|j|}|dkr,|j|}|j||f\}}|j||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 rr get_pixel)rr"r$r%rrr __getitem__]s   zPyAccess.__getitem__cCsH|\}}d|ko|jkno:d|ko6|jknsDtd|S)Nrzpixel location out of range)r rr)rr"r$r%rrrrss4zPyAccess.check_xyN)F) __name__ __module__ __qualname__rrr&r(ZputpixelZgetpixelrrrrrr,s rc@s(eZdZdZddZddZddZdS) _PyAccess32_2z9 PA, LA, stored in first and last bytes of a 32 bit word cOstjd|j|_dS)Nzstruct Pixel_RGBA **)r r rpixels)rargskwargsrrrr|sz_PyAccess32_2._post_initcCs|j||}|j|jfS)N)r-ra)rr$r%pixelrrrr'sz_PyAccess32_2.get_pixelcCs2|j||}t|dd|_t|dd|_dS)Nr)r-minr0r1)rr$r%r#r2rrrr!sz_PyAccess32_2.set_pixelN)r)r*r+__doc__rr'r!rrrrr,zsr,c@s(eZdZdZddZddZddZdS) _PyAccess32_3zC RGB and friends, stored in the first three bytes of a 32 bit word cOstjd|j|_dS)Nzstruct Pixel_RGBA **)r r rr-)rr.r/rrrrsz_PyAccess32_3._post_initcCs|j||}|j|j|jfS)N)r-r0gb)rr$r%r2rrrr'sz_PyAccess32_3.get_pixelcCsH|j||}t|dd|_t|dd|_t|dd|_d|_dS)Nrr3r4)r-r5r0r8r9r1)rr$r%r#r2rrrr!s z_PyAccess32_3.set_pixelN)r)r*r+r6rr'r!rrrrr7sr7c@s(eZdZdZddZddZddZdS) _PyAccess32_4z( RGBA etc, all 4 bytes of a 32 bit word cOstjd|j|_dS)Nzstruct Pixel_RGBA **)r r rr-)rr.r/rrrrsz_PyAccess32_4._post_initcCs"|j||}|j|j|j|jfS)N)r-r0r8r9r1)rr$r%r2rrrr'sz_PyAccess32_4.get_pixelcCsR|j||}t|dd|_t|dd|_t|dd|_t|dd|_dS)Nrr3r4r:r)r-r5r0r8r9r1)rr$r%r#r2rrrr!s z_PyAccess32_4.set_pixelN)r)r*r+r6rr'r!rrrrr;sr;c@s(eZdZdZddZddZddZdS) _PyAccess8z' 1, L, P, 8 bit images stored as uint8 cOs |j|_dS)N)rr-)rr.r/rrrrsz_PyAccess8._post_initcCs|j||S)N)r-)rr$r%rrrr'sz_PyAccess8.get_pixelc CsJyt|d|j||<Wn,tk rDt|dd|j||<YnXdS)Nr3r)r5r- TypeError)rr$r%r#rrrr!sz_PyAccess8.set_pixelN)r)r*r+r6rr'r!rrrrr<sr<c@s(eZdZdZddZddZddZdS) _PyAccessI16_Nz2 I;16 access, native bitendian without conversion cOstjd|j|_dS)Nzunsigned short **)r r rr-)rr.r/rrrrsz_PyAccessI16_N._post_initcCs|j||S)N)r-)rr$r%rrrr'sz_PyAccessI16_N.get_pixelc CsJyt|d|j||<Wn,tk rDt|dd|j||<YnXdS)Nir)r5r-r=)rr$r%r#rrrr!sz_PyAccessI16_N.set_pixelN)r)r*r+r6rr'r!rrrrr>sr>c@s(eZdZdZddZddZddZdS) _PyAccessI16_Lz I;16L access, with conversion cOstjd|j|_dS)Nzstruct Pixel_I16 **)r r rr-)rr.r/rrrrsz_PyAccessI16_L._post_initcCs|j||}|j|jdS)N)r-lr0)rr$r%r2rrrr'sz_PyAccessI16_L.get_pixelc CsX|j||}yt|d}Wn"tk r>t|dd}YnX|d@|_|d?|_dS)Nirr3)r-r5r=rAr0)rr$r%r#r2rrrr!s z_PyAccessI16_L.set_pixelN)r)r*r+r6rr'r!rrrrr?sr?c@s(eZdZdZddZddZddZdS) _PyAccessI16_Bz I;16B access, with conversion cOstjd|j|_dS)Nzstruct Pixel_I16 **)r r rr-)rr.r/rrrrsz_PyAccessI16_B._post_initcCs|j||}|jd|jS)Nr@)r-rAr0)rr$r%r2rrrr'sz_PyAccessI16_B.get_pixelc CsX|j||}yt|d}Wn"tk r>t|dd}YnX|d?|_|d@|_dS)NirrBr3)r-r5 ExceptionrAr0)rr$r%r#r2rrrr!s z_PyAccessI16_B.set_pixelN)r)r*r+r6rr'r!rrrrrCsrCc@s(eZdZdZddZddZddZdS) _PyAccessI32_Nz$ Signed Int32 access, native endian cOs |j|_dS)N)rr-)rr.r/rrrrsz_PyAccessI32_N._post_initcCs|j||S)N)r-)rr$r%rrrr'sz_PyAccessI32_N.get_pixelcCs||j||<dS)N)r-)rr$r%r#rrrr!sz_PyAccessI32_N.set_pixelN)r)r*r+r6rr'r!rrrrrEsrEc@s0eZdZdZddZddZddZdd Zd S) _PyAccessI32_Swapz. I;32L/B access, with byteswapping conversion cOs |j|_dS)N)rr-)rr.r/rrrrsz_PyAccessI32_Swap._post_initcCs\tjd|}tjd|}|d|d|d|df\|d<|d<|d<|d<tjd|dS)Nzint *zunsigned char *rr:r4r)r newr )riorigcharsrrrreverse s    (z_PyAccessI32_Swap.reversecCs|j|j||S)N)rKr-)rr$r%rrrr'sz_PyAccessI32_Swap.get_pixelcCs|j||j||<dS)N)rKr-)rr$r%r#rrrr!sz_PyAccessI32_Swap.set_pixelN)r)r*r+r6rrKr'r!rrrrrFs rFc@s(eZdZdZddZddZddZdS) _PyAccessFz 32 bit float access cOstjd|j|_dS)Nzfloat **)r r rr-)rr.r/rrrrsz_PyAccessF._post_initcCs|j||S)N)r-)rr$r%rrrr'sz_PyAccessF.get_pixelc Cs>y||j||<Wn&tk r8|d|j||<YnXdS)Nr)r-r=)rr$r%r#rrrr! sz_PyAccessF.set_pixelN)r)r*r+r6rr'r!rrrrrLsrL)1LrZLAZLaZPAZRGBZLABZHSVZYCbCrZRGBAZRGBaZRGBXZCMYKFIlittlezI;16zI;16LzI;16BzI;32LzI;32BFcCs.tj|jd}|s$tjd|jdS|||S)NzPyAccess Not Implemented: %s)mode_mapgetrloggerdebug)rr Z access_typerrrrGKs rG)F)loggingsysZcffir getLoggerr)rTZdefsr Zcdefobjectrr,r7r;r<r>r?rCrErFrLrR byteorderrGrrrrsZ   N