ó
O'—^c           @  sQ  d  d l  m Z d  d l Z d  d l Z d  d l m Z e j e ƒ Z d Z	 e ƒ  Z
 e
 j e	 ƒ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ i e d 6e d 6e d 6e d 6e d 6e d  6e d! 6e d" 6e d# 6e d$ 6e d% 6e d& 6e d' 6e d( 6e d) 6e d* 6Z e j d+ k re e d, <e e d- <e e d. <e e d/ <e e d0 <n2 e e d, <e e d- <e e d. <e e d/ <e e d0 <e d1 „ Z d S(2   iÿÿÿÿ(   t   print_functionN(   t   FFIs`   
struct Pixel_RGBA {
    unsigned char r,g,b,a;
};
struct Pixel_I16 {
    unsigned char l,r;
};
t   PyAccessc           B  sD   e  Z e d  „ Z d „  Z d „  Z d „  Z e Z e Z d „  Z	 RS(   c         C  sš   t  | j j ƒ } | |  _ t j d | d ƒ |  _ t j d | d ƒ |  _ t j d | d ƒ |  _ | d |  _	 | d |  _
 | j |  _ |  j ƒ  d  S(   Ns   unsigned char **t   image8s   int **t   image32t   imaget   xsizet   ysize(   t   dictt   imt   unsafe_ptrst   readonlyt   ffit   castR   R   R   R   R   t   _imt
   _post_init(   t   selft   imgR   t   vals(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyt   __init__0   s    	c         C  s   d  S(   N(    (   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   A   s    c         C  s@   |  j  r t d ƒ ‚ n  |  j | ƒ \ } } |  j | | | ƒ S(   s  
        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).
        :param value: The pixel value.
        s%   Attempt to putpixel a read only image(   R   t
   ValueErrort   check_xyt	   set_pixel(   R   t   xyt   colort   xt   y(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyt   __setitem__D   s    		c         C  s%   |  j  | ƒ \ } } |  j | | ƒ S(   sI  
        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).
        :returns: a pixel value for single band images, a tuple of
          pixel values for multiband images.
        (   R   t	   get_pixel(   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyt   __getitem__R   s    c         C  s]   | \ } } d | k o& |  j  k  n oG d | k oE |  j k  n sY t d ƒ ‚ n  | S(   Ni    s   pixel location out of range(   R   R   R   (   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   c   s    >(
   t   __name__t
   __module__t   FalseR   R   R   R   t   putpixelt   getpixelR   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   .   s   			t   _PyAccess32_2c           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s9    PA, LA, stored in first and last bytes of a 32 bit word c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   struct Pixel_RGBA **(   R   R   R   t   pixels(   R   t   argst   kwargs(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   l   s    c         C  s!   |  j  | | } | j | j f S(   N(   R$   t   rt   a(   R   R   R   t   pixel(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   o   s    c         C  sA   |  j  | | } t | d d ƒ | _ t | d d ƒ | _ d  S(   Ni    iÿ   i   (   R$   t   minR'   R(   (   R   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   s   s    (   R   R   t   __doc__R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR#   j   s   		t   _PyAccess32_3c           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sC    RGB and friends, stored in the first three bytes of a 32 bit word c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   struct Pixel_RGBA **(   R   R   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   }   s    c         C  s'   |  j  | | } | j | j | j f S(   N(   R$   R'   t   gt   b(   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   €   s    c         C  sW   |  j  | | } t | d d ƒ | _ t | d d ƒ | _ t | d d ƒ | _ d  S(   Ni    iÿ   i   i   (   R$   R*   R'   R-   R.   (   R   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   „   s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR,   z   s   		t   _PyAccess32_4c           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s(    RGBA etc, all 4 bytes of a 32 bit word c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   struct Pixel_RGBA **(   R   R   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   Ž   s    c         C  s-   |  j  | | } | j | j | j | j f S(   N(   R$   R'   R-   R.   R(   (   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ‘   s    c         C  sm   |  j  | | } t | d d ƒ | _ t | d d ƒ | _ t | d d ƒ | _ t | d d ƒ | _ d  S(   Ni    iÿ   i   i   i   (   R$   R*   R'   R-   R.   R(   (   R   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   •   s
    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR/   Œ   s   		t
   _PyAccess8c           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s'    1, L, P, 8 bit images stored as uint8 c         O  s   |  j  |  _ d  S(   N(   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR       s    c         C  s   |  j  | | S(   N(   R$   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   £   s    c         C  sJ   y t  | d ƒ |  j | | <Wn% t  | d d ƒ |  j | | <n Xd  S(   Niÿ   i    (   R*   R$   (   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ¦   s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR0   ž   s   		t   _PyAccessI16_Nc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s2    I;16 access, native bitendian without conversion c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   unsigned short **(   R   R   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ±   s    c         C  s   |  j  | | S(   N(   R$   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ´   s    c         C  sJ   y t  | d ƒ |  j | | <Wn% t  | d d ƒ |  j | | <n Xd  S(   Niÿÿ  i    (   R*   R$   (   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ·   s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR1   ¯   s   		t   _PyAccessI16_Lc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s    I;16L access, with conversion c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   struct Pixel_I16 **(   R   R   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   Â   s    c         C  s#   |  j  | | } | j | j d S(   Ni   (   R$   t   lR'   (   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   Å   s    c         C  si   |  j  | | } y t | d ƒ } Wn$ t k
 rJ t | d d ƒ } n X| d @| _ | d ?| _ d  S(   Niÿÿ  i    iÿ   i   (   R$   R*   t	   TypeErrorR3   R'   (   R   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   É   s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR2   À   s   		t   _PyAccessI16_Bc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s    I;16B access, with conversion c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   struct Pixel_I16 **(   R   R   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   Ö   s    c         C  s#   |  j  | | } | j d | j S(   Ni   (   R$   R3   R'   (   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   Ù   s    c         C  s_   |  j  | | } y t | d ƒ } Wn t | d d ƒ } n X| d ?| _ | d @| _ d  S(   Niÿÿ  i    i   iÿ   (   R$   R*   R3   R'   (   R   R   R   R   R)   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   Ý   s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR5   Ô   s   		t   _PyAccessI32_Nc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s$    Signed Int32 access, native endian c         O  s   |  j  |  _ d  S(   N(   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ê   s    c         C  s   |  j  | | S(   N(   R$   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   í   s    c         C  s   | |  j  | | <d  S(   N(   R$   (   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ð   s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR6   è   s   		t   _PyAccessI32_Swapc           B  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s.    I;32L/B access, with byteswapping conversion c         O  s   |  j  |  _ d  S(   N(   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   ö   s    c         C  sv   t  j d | ƒ } t  j d | ƒ } | d | d | d | d f \ | d <| d <| d <| d <t  j d | ƒ d S(   Ns   int *s   unsigned char *i   i   i   i    (   R   t   newR   (   R   t   it   origt   chars(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyt   reverseù   s
    0c         C  s   |  j  |  j | | ƒ S(   N(   R<   R$   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR      s    c         C  s   |  j  | ƒ |  j | | <d  S(   N(   R<   R$   (   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR     s    (   R   R   R+   R   R<   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR7   ô   s
   			t
   _PyAccessFc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s    32 bit float access c         O  s   t  j d |  j ƒ |  _ d  S(   Ns   float **(   R   R   R   R$   (   R   R%   R&   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR   	  s    c         C  s   |  j  | | S(   N(   R$   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR     s    c         C  s8   y | |  j  | | <Wn | d |  j  | | <n Xd  S(   Ni    (   R$   (   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR     s    (   R   R   R+   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR=     s   		t   1t   Lt   Pt   LAt   Lat   PAt   RGBt   LABt   HSVt   YCbCrt   RGBAt   RGBat   RGBXt   CMYKt   Ft   It   littles   I;16s   I;16Ls   I;16Bs   I;32Ls   I;32Bc         C  s?   t  j |  j d  ƒ } | s2 t j d |  j ƒ d  S| |  | ƒ S(   Ns   PyAccess Not Implemented: %s(   t   mode_mapt   gett   modet   Nonet   loggert   debug(   R   R   t   access_type(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyR8   :  s
    (   t
   __future__R    t   loggingt   syst   cffiR   t	   getLoggerR   RS   t   defsR   t   cdeft   objectR   R#   R,   R/   R0   R1   R2   R5   R6   R7   R=   RO   t	   byteorderR    R8   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/PyAccess.pyt   <module>   s\   
	<










