ó
üÌoLc           @   s‡  e  d  k r¦ d d l Z d d l Z e j j e j j e ƒ ƒ d Z e j j e ƒ \ Z Z	 e	 d k oƒ e j j e ƒ d d k Z
 e
 r£ e j j d e ƒ n  n e  j d ƒ Z
 e
 rÚ d d l m Z m Z m Z n d d l m Z m Z m Z d d l Z d d l Z d d l Z d d	 l m Z m Z d d l Z d d l Z d
 „  Z d e j f d „  ƒ  YZ e  d  k rƒe j ƒ  n  d S(   t   __main__iÿÿÿÿNi    t   testsi   t   pygames   pygame.tests.(   t   test_not_implementedt   example_patht   unittest(   t   xrange_t   ord_c         C   sp   |  j  t | ƒ ƒ } t | ƒ t | ƒ k r1 d Sx8 t t | ƒ ƒ D]$ } | | t | | ƒ k rD d SqD Wd S(   s9    tests a given file to see if the magic hex matches.
    i    i   (   t   readt   lent   rangeR   (   t   ft	   magic_hext   datat   i(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt
   test_magic   s    t   ImageModuleTestc           B   s}   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z RS(   c         C   s€   t  j j d ƒ } |  j | j d ƒ t  j j | ƒ } |  j | j d	 ƒ d
 ƒ |  j | j ƒ  d ƒ |  j | j	 ƒ  d ƒ d S(   s-    see if we can load the pygame icon.
        s   pygame_icon.bmpt   rbi    i   i   iÿ   i    N(   i    i    (   i   i   i   iÿ   (
   R   t   pkgdatat   getResourcet   assertEqualt   modet   imaget
   load_basict   get_att
   get_heightt	   get_width(   t   selfR   t   surf(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   testLoadIcon)   s    c         C   sC   t  d ƒ } t j j | ƒ } t | d ƒ } t j j | ƒ } d S(   s#    see if we can load a png.
        s   data/alien1.pngR   N(   R   R   R   t   loadt   open(   R   R   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   testLoadPNG5   s    c         C   sC   t  d ƒ } t j j | ƒ } t | d ƒ } t j j | ƒ } d S(   s#    see if we can load a jpg.
        s   data/alien1.jpgR   N(   R   R   R   R   R   (   R   R   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   testLoadJPGA   s    c         C   s_  t  j d ƒ } | j d ƒ i  } d d d d g | d <d d d	 d
 g | d <d d d g | d <d d g | d <d d d d g } | g  | D] } | j ƒ  ^ q } x² | D]ª } z“ d d | f } t  j j | | ƒ |  j d | f t t | d ƒ | | j	 ƒ  ƒ | f ƒ t  j j
 | ƒ } |  j | j d ƒ | j d ƒ ƒ Wd  t j | ƒ Xq­ Wd  S(   Ni
   i   iÿ   iØ   ià   t   jpgi‰   iP   iN   iG   t   pngi    t   tgaiB   iM   t   bmps   %s.%st   tmpimgi   R   (   i
   i
   (   i   i   i   (   i    i    (   i    i    (   R   t   Surfacet   fillt   upperR   t   saveR   R   R   t   lowerR   t   assertEqualsR   t   ost   remove(   R   t   sR   t   formatst   xt   fmtt   temp_filenamet   s2(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt	   test_saveR   s$    #8&c         C   sÆ   t  j d t  j d ƒ } | j d ƒ | j d	 ƒ | j ƒ  } | j d
 ƒ } d } z) t  j j | | ƒ t  j j	 | ƒ } Wd t
 j | ƒ X| j ƒ  } |  j | | ƒ |  j | | j d ƒ ƒ d S(   s=    make sure the color key is not changed when saving.
        i
   i    i   i    s
   tmpimg.pngN(   i
   i
   (   i   i   i   (   i    i    i    (   i    i    (   i    i    (   R   R'   t   SRCALPHAR(   t   set_colorkeyt   get_colorkeyR   R   R*   R   R-   R.   R   (   R   R/   t	   colorkey1t   p1R3   R4   t	   colorkey2(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   test_save_colorkeyt   s    c      	   C   sñ   |  j  t | ƒ t | ƒ ƒ d } | | k rí x¼ t d t | ƒ | ƒ D]Ÿ } t | | t | ƒ ƒ } | | | !} | | | !} | | k rG | | | !}	 d | | t | ƒ | j d ƒ | j d ƒ |	 j d ƒ f }
 |  j |
 ƒ qG qG Wn  d  S(   Ni   i    s5   string difference in %d to %d of %d:
%s
%s
source:
%st   hex(   R   R	   R   t   mint   encodet   fail(   R   t   string1t   string2t   source_stringt
   block_sizet   block_startt	   block_endt   block1t   block2t   source_blockt   msg(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   assertPremultipliedAreEqual   s    =c         C   st  d „  } t  j d t  j d ƒ } x… t | j ƒ  ƒ D]q } xh t | j ƒ  ƒ D]T } | | | j ƒ  } | j | | f | d d | d d | d d | f ƒ qM Wq4 W| j ƒ  } | | ƒ |  j t  j	 j
 | d ƒ t  j	 j
 | d ƒ t  j	 j
 | d ƒ ƒ |  j t  j	 j
 | d	 ƒ t  j	 j
 | d
 ƒ t  j	 j
 | d
 ƒ ƒ t  j d d d ƒ } |  j t t  j	 j
 | d ƒ d S(   sS    test to make sure we can export a surface to a premultiplied alpha string
        c         S   s¯   x¨ t  |  j ƒ  ƒ D]” } x‹ t  |  j ƒ  ƒ D]w } |  j | | f ƒ } | d | d d | d | d d | d | d d | d f } |  j | | f | ƒ q, Wq Wd  S(   Ni    i   iÿ   i   i   (   R   R   R   R   t   set_at(   t   surface_to_modifyR1   t   yt   colort   premult_color(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   convertRGBAtoPremultipliedž   s    i   i    i   i   i   t   RGBA_PREMULTt   RGBAt   ARGB_PREMULTt   ARGBi    i   N(   i   i   (   i   i   (   R   R'   R6   R   R   R   RL   t   copyRK   R   t   tostringt   assertRaisest
   ValueError(   R   RQ   t   test_surfaceR1   RN   R   t   premultiplied_copyt   no_alpha_surface(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   test_to_string__premultipliedš   s     	
B
c         C   su  d „  } d „  } d „  } t  j d d t  j d d ƒ} xÑ t d ƒ D]Ã } xº t d	 ƒ D]¬ } | d	 d
 } | j | d | f | | | | f ƒ | j | d	 | f | | | | f ƒ | j | d | f | | | | f ƒ | j | d | f | | | | f ƒ qY WqF W|  j | | | ƒ ƒ t  j j | d ƒ } | | | ƒ ƒ } t  j j | | j	 ƒ  d ƒ }	 |  j | | |	 ƒ ƒ t  j j | d ƒ } | | ƒ }
 t  j j |
 | j	 ƒ  d ƒ } |  j | | | ƒ ƒ t  j j | d ƒ }
 | |
 ƒ } t  j j | | j	 ƒ  d ƒ } |  j | | | ƒ ƒ t  j j | d ƒ }
 t  j j |
 | j	 ƒ  d ƒ } |  j | | | ƒ ƒ d S(   s@    see if fromstring, and tostring methods are symmetric.
        c         S   s    |  j  ƒ  | j  ƒ  k s0 |  j ƒ  | j ƒ  k r4 t Sxe t |  j ƒ  ƒ D]Q } xH t | j  ƒ  ƒ D]4 } |  j | | f ƒ | j | | f ƒ k r` t Sq` WqG Wt S(   N(   R   R   t   FalseR   R   t   True(   t   surf_at   surf_bRN   R1   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   AreSurfacesIdentical¾   s    0*c         S   sÁ   t  j  d |  ƒ } t | ƒ d } x’ t | ƒ D]„ } | | d d } | | d d | | d d <| | d d | | d d <| | d d | | d d <| | | d d <q/ W| j ƒ  S(   Nt   Bi   i   i   i   i    (   t   arrayR	   R   RW   (   t   str_buft   byte_buft	   num_quadsR   t   alpha(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   RotateRGBAtoARGBÈ   s    c         S   sÁ   t  j  d |  ƒ } t | ƒ d } x’ t | ƒ D]„ } | | d d } | | d d | | d d <| | d d | | d d <| | d d | | d d <| | | d d <q/ W| j ƒ  S(   NRc   i   i    i   i   i   (   Rd   R	   R   RW   (   Re   Rf   Rg   R   Rh   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   RotateARGBtoRGBAÔ   s    i@   i   t   flagst   depthi    i   i   i    RS   RU   N(   i@   i   (
   R   R'   R6   R   RL   t   assert_R   RW   t
   fromstringt   get_size(   R   Rb   Ri   Rj   RZ   R   t   jt	   intensityt   rgba_buft   test_rotate_functionst   argb_buft   test_from_argb_stringt   test_to_argb_stringt   test_to_from_argb_string(    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   test_fromstring__and_tostringº   s6    	
		&&&.c         C   s   |  j  ƒ  d  S(   N(   R@   (   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   todo_test_frombuffer  s    c         C   s   |  j  ƒ  d  S(   N(   R@   (   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   todo_test_get_extended  s    c         C   s   |  j  ƒ  d  S(   N(   R@   (   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   todo_test_load_basic%  s    c         C   s   |  j  ƒ  d  S(   N(   R@   (   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   todo_test_load_extended/  s    c         C   s   |  j  ƒ  d  S(   N(   R@   (   R   (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   todo_test_save_extended7  s    (   t   __name__t
   __module__R   R    R!   R5   R<   RK   R]   Rx   Ry   Rz   R{   R|   R}   (    (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyR   (   s   				"			 	M			
	(   R~   t   sysR-   t   patht   splitt   abspatht   __file__t   pkg_dirt
   parent_dirt   pkg_namet   is_pygame_pkgt   insertt
   startswitht   pygame.tests.test_utilsR   R   R   t   test.test_utilsR   t   pygame.imaget   pygame.pkgdatat   pygame.compatR   R   Rd   R   t   TestCaseR   t   main(    (    (    s8   C:\Python27\Lib\site-packages\pygame\tests\image_test.pyt   <module>   s*   "$	ÿ 