ó
k4Vdc           @   sV  d  Z  d Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 m Z m Z d d l m Z m Z d d	 l m Z d
 d d     YZ e d k rRe j j e j j e j  d d  Z e j j e  s t d   d e _ e e d d  Z d d l Z e j   Z d e j  f GHe j! e  GHn  d S(   s   3.3.0s@   
Image functionality sliced out of canvas.py for generalization
i’’’’N(   t	   rl_config(   t   pdfutils(   t   pdfdoc(   t   import_zlibt
   haveImagest
   getBytesIOt   isStr(   t   fp_strt   asciiBase85Encode(   t   aspectRatioFixt   PDFImagec           B   sq   e  Z d  Z d d d d  Z d   Z d   Z d   Z d   Z d   Z	 e
 d  Z e
 d	 d
  Z d   Z RS(   sł   Wrapper around different "image sources".  You can make images
    from a PIL Image object, a filename (in which case it uses PIL),
    an image we previously cached (optimisation, hardly used these
    days) or a JPEG (which PDF supports natively).i    c         C   sq   | |  _  | |  _ | |  _ | |  _ | |  _ d  |  _ | |  _ d |  _ d |  _	 g  |  _
 d  |  _ |  j   d  S(   Nt	   DeviceRGBi   (   t   imaget   xt   yt   widtht   heightt   Nonet   filenamet   imageCachingt
   colorSpacet   bitsPerComponentt   filterst   sourcet   getImageData(   t   selfR   R   R   R   R   t   caching(    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   __init__   s    											c         C   s7   t  |  j d  } z |  j |  } Wd  | j   X| S(   Nt   rb(   t   openR   t   _jpg_imagedatat   close(   R   t   fpt   result(    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   jpg_imagedata*   s
    c         C   sņ   t  j |  } d |  _ | d | d } } | d d k rF d } n | d d k r_ d } n d } | j d  g  } | j d	 | | | t j r d
 p d f  | j   } t j rČ t |  } n  t  j	 | |  | j d  | | | f S(   Nt   JPEGi    i   i   t
   DeviceGrayi   R   t
   DeviceCMYKs,   BI /W %d /H %d /BPC 8 /CS /%s /F [%s/DCT] IDs   /A85 t    t   EI(
   R   t   readJPEGInfoR   t   seekt   appendR    t   useA85t   readR   t   _chunker(   R   t	   imageFilet   infot   imgwidtht	   imgheightR   t	   imagedatat   data(    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyR   4   s"    			,	c         C   s   |  j  } t j |  sE t   } | s+ d  St s5 d  St j |  n  t j j |  d t	 j
 rg d pj d } t | d  j   } t t t j |   } | S(   Ni    s   .a85s   .binR   (   R   R   t   cachedImageExistsR   R   t   cacheImageFilet   ost   patht   splitextR    R+   R   t	   readlinest   listt   mapt   strt   strip(   R   R   t   zlibt
   cachednameR2   (    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   cache_imagedataJ   s    		  )c         C   sŃ  |  j  } | j d k r; | j } | j d  |  j |  Sd |  _ t   } | sW d  Sd } | j d k r | } d } d } ni | j d k r« | } d	 } d
 } d
 } n? | j d k rĻ | } d	 } d
 } n | j d  } d } d } | j	 \ } }	 d | |	 | | t
 j rd pd f g }
 t | d  r<| j n | j   } | | | d d ?} t |  | |	 k st d   | j |  } t
 j r§t |  } n  t j | |
  |
 j d  |
 | |	 f S(   NR#   i    t   PILi   t   CMYKR%   i   t   1R$   i   t   Lt   RGBi   s,   BI /W %d /H %d /BPC %d /CS /%s /F [%s/Fl] IDs   /A85 R&   t   tobytesi   s   Wrong amount of data for imageR'   (   R   t   formatR    R)   R   R   R   t   modet   convertt   sizeR    R+   t   hasattrRF   t   tostringt   lent   AssertionErrort   compressR   R   R-   R*   (   R   R   R    R>   t   bpct   myimageR   t   bppR0   R1   R2   t   rawt	   rowstrideR3   (    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   PIL_imagedataY   sJ    				 			+$"	c         C   sj   |  j  s! t j | d d } n |  j   } | d j   } t | d  } t | d  } | | | f S(   Nt   returnInMemoryi   i   (   R   R   R5   R@   t   splitt   int(   R   R   R2   t   wordsR0   R1   (    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   non_jpg_imagedata   s    	c         C   s%  |  j  } t |  r | |  _ t j j |  d d k rx y |  j   \ } } } Wq |  j |  \ } } } q Xqā |  j |  \ } } } nO d d l } | j	 d d	 !d
 k rĶ |  j
   \ } } } n |  j   \ } } } | |  _ | |  _ | |  _ |  j p	| |  _ |  j p| |  _ d S(   s1   Gets data, height, width - whatever type of imagei   s   .jpgs   .JPGs   .jpegs   .JPEGi’’’’Ni    i   t   java(   s   .jpgs   .JPGs   .jpegs   .JPEG(   R   R   R   R6   R7   R8   R"   RZ   t   syst   platformt   JAVA_imagedataRU   t	   imageDataR0   R1   R   R   (   R   t   preserveAspectRatioR   R2   R0   R1   R\   (    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyR      s$    					t   swc   
   	   C   sš   |  j  } |  j } | d k  s* | d k  r. t St | | |  j |  j | | |  j |  j  \ } } |  _  |  _ } | j s | | } n  | j	 j
 d t |  j   t |  j | |  f  x! |  j D] }	 | j	 j
 |	  qĀ W| j	 j
 d  t S(   sŲ   Draw an Image into the specified rectangle.  If width and
        height are omitted, they are calculated from the image size.
        Also allow file names as well as images.  This allows a
        caching mechanismgķµ ÷Ę°>s   q %s 0 0 %s cmt   Q(   R   R   t   FalseR	   R   R   R0   R1   t   bottomupt   _codeR*   R   R_   t   True(
   R   t   canvasR`   t   anchorR   R   R   R   t   scaledt   line(    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   drawInlineImage¬   s    		 B	 2c         C   s   t  j   } d | d <d | d <|  j | d <|  j | d <d | d <t  j |  j  | d	 <d
 j |  j d d ! d
 } t  j d | d |  } | j	 |  S(   st   Allow it to be used within pdfdoc framework.  This only
        defines how it is stored, not how it is drawn later.s   /XObjectt   Types   /Imaget   Subtypet   Widtht   Heighti   t   BitsPerComponentt
   ColorSpaces   
i   i’’’’t
   dictionaryt   content(
   R   t   PDFDictionaryR   R   t   PDFNameR   t   joinR_   t	   PDFStreamRG   (   R   t   documentt   dictRs   t   strm(    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyRG   ¾   s    


N(   t   __name__t
   __module__t   __doc__R   R   R"   R   R@   RU   RZ   Rc   R   Rk   RG   (    (    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyR
      s   	
			/	
t   __main__t   tests   pythonpowered.gifs   image not foundi   id   s   source=(    ("   t   __version__R}   R6   t	   reportlabR    t   reportlab.pdfbaseR   R   t   reportlab.lib.utilsR   R   R   R   t   reportlab.lib.rl_accelR   R   t   reportlab.lib.boxstuffR	   R
   R{   R7   Rv   t   dirnamet   __file__t   srcfilet   isfileRN   t
   LongFormatt   imgt   pprintt   PDFDocumentt   docR   RG   (    (    (    sh   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/pdfgen/pdfimages.pyt   <module>   s,   "ŗ			