ó
‚™xTc           @   s”   d  d l  m Z d  d l m Z m Z d  d l m Z d  d l Z d  d l Z d Z	 d „  Z
 d d d „  ƒ  YZ e d	 k r� e
 e j d
 ƒ n  d S(   iÿÿÿÿ(   t   division(   t   Sorryt   Usage(   t   StringIONs—  labelit.png file_name [output_file] [bin=1|2]

  Convert an X-ray detector image to PNG format.

  Input file is a detector image (CBF, ADSC, MAR, etc.).  If the name of the
  output file is not specified, it will be identical to the image file but
  with the extension replaced by '.png'.

  bin argument: 1 ( default, same-sized png  as detector )
                2 ( bin detector pixels 2x2 for display )c         C   sH  t  |  ƒ d k s< t  |  ƒ d k s< d |  k s< d |  k rK t t ƒ ‚ n  d } t  |  ƒ d k r™ |  d j d ƒ d k r™ |  d d d	 k r™ d } n  |  d } d  } t  |  ƒ d k rÈ |  d } n  | d  k rý t j j t j j | ƒ d ƒ d
 } n  t	 | | ƒ } | j
 j ƒ  t | d ƒ j | j ƒ  j ƒ  ƒ d | GHd  S(   Ni    i   s   -larget   helpi   i   s   bin=i   t   2s   .pngt   wbs   Wrote %s(   t   lenR   t   usage_messaget   findt   Nonet   ost   patht   basenamet   splitextt   convert_imaget   imgt   show_headert   opent   writet   outputt   getvalue(   t   argst   graphics_bint   img_filet   output_filet   C(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/detector_image_as_png.pyt   run   s    <?	
)"R   c           B   s   e  Z d  d „ Z d „  Z RS(   i   c   
      C   s  d d l  m } d d l m } d d  l } y | | ƒ } Wn% | k
 rc } t t | ƒ ƒ ‚ n X| j ƒ  | |  _ | j	 d k r� d } n  | j
 d | d	 d ƒ } | j d
 d
 d ƒ | j d ƒ | j d d ƒ | j ƒ  | j }	 | j d | j ƒ  | j ƒ  f |	 ƒ |  _ d  S(   Niÿÿÿÿ(   t   SlipViewerImageFactory(   t   ImageExceptions
   Pilatus-6Ms
   Pilatus-2Ms   Pilatus-300Ki   t   binningt
   brightnessg        i    t   color_schemet   RGB(   s
   Pilatus-6Ms
   Pilatus-2Ms   Pilatus-300K(   t+   rstbx.slip_viewer.slip_viewer_image_factoryR   t   iotbx.detectorsR   t   ImageR   t   strt   readR   t
   vendortypet   get_flex_imaget	   setWindowt   spot_conventiont   adjustt   prep_stringt   export_stringt
   fromstringt   ex_size2t   ex_size1t   imageout(
   t   selft	   file_nameR   t   ImageFactoryR   R$   R   t   et   flex_imgt   data_string(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/detector_image_as_png.pyt   __init__(   s(    
		
		c         C   s    t  ƒ  } |  j j | d ƒ | S(   Nt   PNG(   R   R1   t   save(   R2   t   out(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/detector_image_as_png.pyR   >   s    	(   t   __name__t
   __module__R8   R   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/detector_image_as_png.pyR   &   s   t   __main__i   (    (   t
   __future__R    t   libtbx.utilsR   R   t	   cStringIOR   R   t   sysR   R   R   R<   t   argv(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/detector_image_as_png.pyt   <module>   s   	