ó
È4ec           @   sA  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 d/ <n2 e e d+ <e e d, <e e d- <e e d. <e e d/ <e d0 „ Z d S(1   iÿÿÿÿN(   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 ƒ |  _ | j j	 \ |  _
 |  _ | j |  _ |  j j d k r« | j |  _ n  |  j ƒ  d  S(   Ns   unsigned char **t   image8s   int **t   image32t   imaget   P(   t   dictt   imt   unsafe_ptrst   readonlyt   ffit   castR   R   R   t   sizet   xsizet   ysizet   _imt   modet   palettet   _palettet
   _post_init(   t   selft   imgR	   t   vals(    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyt   __init__,   s    	c         C   s   d  S(   N(    (   R   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   >   s    c         C   sØ   |  j  r t d ƒ ‚ n  | \ } } | d k  r@ |  j | } n  | d k  r\ |  j | } n  |  j | | f ƒ \ } } |  j j d k rÅ t | t t	 f ƒ rÅ t
 | ƒ d k rÅ |  j j | ƒ } n  |  j | | | ƒ S(   s0  
        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.
        s%   Attempt to putpixel a read only imagei    R   i   i   (   i   i   (   R	   t
   ValueErrorR   R   t   check_xyR   R   t
   isinstancet   listt   tuplet   lenR   t   getcolort	   set_pixel(   R   t   xyt   colort   xt   y(    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyt   __setitem__A   s    
	c         C   so   | \ } } | d k  r( |  j  | } n  | d k  rD |  j | } n  |  j | | f ƒ \ } } |  j | | ƒ S(   sq  
        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.
        i    (   R   R   R   t	   get_pixel(   R   R    R"   R#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyt   __getitem__^   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#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   t   s    >(
   t   __name__t
   __module__t   FalseR   R   R$   R&   t   putpixelt   getpixelR   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/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(    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   ~   s    c         C   s!   |  j  | | } | j | j f S(   N(   R-   t   rt   a(   R   R"   R#   t   pixel(    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%      s    c         C   sA   |  j  | | } t | d d ƒ | _ t | d d ƒ | _ d  S(   Ni    iÿ   i   (   R-   t   minR0   R1   (   R   R"   R#   R!   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   …   s    (   R'   R(   t   __doc__R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR,   {   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR      s    c         C   s'   |  j  | | } | j | j | j f S(   N(   R-   R0   t   gt   b(   R   R"   R#   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%   ’   s    c         C   s`   |  j  | | } t | d d ƒ | _ t | d d ƒ | _ t | d d ƒ | _ d | _ d  S(   Ni    iÿ   i   i   (   R-   R3   R0   R6   R7   R1   (   R   R"   R#   R!   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   –   s
    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR5   Œ   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   ¢   s    c         C   s-   |  j  | | } | j | j | j | j f S(   N(   R-   R0   R6   R7   R1   (   R   R"   R#   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/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-   R3   R0   R6   R7   R1   (   R   R"   R#   R!   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   ©   s
    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR8   Ÿ   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   µ   s    c         C   s   |  j  | | S(   N(   R-   (   R   R"   R#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%   ¸   s    c         C   sT   y t  | d ƒ |  j | | <Wn/ t k
 rO t  | d d ƒ |  j | | <n Xd  S(   Niÿ   i    (   R3   R-   t	   TypeError(   R   R"   R#   R!   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   »   s    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR9   ²   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   Ç   s    c         C   s   |  j  | | S(   N(   R-   (   R   R"   R#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%   Ê   s    c         C   sT   y t  | d ƒ |  j | | <Wn/ t k
 rO t  | d d ƒ |  j | | <n Xd  S(   Niÿÿ  i    (   R3   R-   R:   (   R   R"   R#   R!   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   Í   s    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR;   Ä   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   Ù   s    c         C   s#   |  j  | | } | j | j d S(   Ni   (   R-   t   lR0   (   R   R"   R#   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/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-   R3   R:   R=   R0   (   R   R"   R#   R!   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   à   s    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR<   Ö   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   î   s    c         C   s#   |  j  | | } | j d | j S(   Ni   (   R-   R=   R0   (   R   R"   R#   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/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-   R3   t	   ExceptionR=   R0   (   R   R"   R#   R!   R2   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   õ   s    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR>   ë   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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR     s    c         C   s   |  j  | | S(   N(   R-   (   R   R"   R#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%     s    c         C   s   | |  j  | | <d  S(   N(   R-   (   R   R"   R#   R!   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   	  s    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR@      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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/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(    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyt   reverse  s    >c         C   s   |  j  |  j | | ƒ S(   N(   RF   R-   (   R   R"   R#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%     s    c         C   s   |  j  | ƒ |  j | | <d  S(   N(   RF   R-   (   R   R"   R#   R!   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR     s    (   R'   R(   R4   R   RF   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyRA     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/   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   #  s    c         C   s   |  j  | | S(   N(   R-   (   R   R"   R#   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR%   &  s    c         C   sB   y | |  j  | | <Wn& t k
 r= | d |  j  | | <n Xd  S(   Ni    (   R-   R:   (   R   R"   R#   R!   (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyR   )  s    (   R'   R(   R4   R   R%   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyRG      s   		t   1t   LR   t   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   getR   t   Nonet   loggert   debug(   R   R	   t   access_type(    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyRB   U  s
    (   t   loggingt   syst   cffiR    t	   getLoggerR'   R[   t   defsR
   t   cdeft   objectR   R,   R5   R8   R9   R;   R<   R>   R@   RA   RG   RX   t	   byteorderR)   RB   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/PIL/PyAccess.pyt   <module>   s\   
	P









