
    iP                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlZd dlZd dl	 g fdZ
	 	 	 ddZ G d de j                        Z G d	 d
e j                        Zedk(  r e j                           yy)    N)
test_utils)example_path)*c                    | j                         dd  }t        j                  j                  |      }|j	                  | d       t        j                  j                          t        j                  j                          d}d}|rt        j                  j                         }|D ]  }|j                  t        k(  rd}|j                  t        k(  s,|j                  t        t        fv r|j                  t        k(  r|dz  }|j                  t        k(  r|dz  }||   } |j	                  | d       t        j                  j                          t        j                  j                          |j                  t        fv sd} |rt        j                  j!                          t        j                  j#                          y )N   r   r   Tr   F   )get_rectpygamedisplayset_modeblitflipeventpumpgettypeQUITKEYDOWNkeyK_sK_aK_ESCAPEquitinit)simagessizescreengoingidxeventses           e/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pygame/tests/transform_test.py
show_imager%      sI   ::<D^^$$T*F
KK6
NN
LLE
C
!!# 	"Avv~vv 55S#J&uu|quu|qsAKK6*NN'')LL%%'UUxj(!E	" " NN
NN    c                    |j                         |j                         }}|r| j                  |       	 |\  }}	}
	 |\  }}}d}t	        |      D ]  }t	        |      D ]o  }|j                  ||f      }t        |d   |z
        |k  t        |d   |	z
        |k  z  t        |d   |
z
        |k  z  sU|r| j                  ||f|       |dz  }q  |S # t        $ r
 |\  }}	}
}Y w xY w# t        $ r
 |\  }}}}Y w xY w)zKgiven the color it makes return_surf only have areas with the given colour.r   r	   r   )	get_width
get_heightfill
ValueErrorrangeget_atabsset_at)return_surfsurfcolor	threshold
diff_colorchange_returnwidthheightrgbatrtgtbtasimilaryxc1s                       r$   r3   r3   +   s.    NN$doo&76E$1a
B G6] u 	AaV$BBqEAI#BqEAI(;<BqEAIQS@ST &&1vr21	 N+  
1a
  BBs"   C C) C&%C&)C<;C<c                       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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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(d' Z)d( Z*y))*TransformModuleTestc                    t        j                  d      }|j                  d       | j                  |j	                         d       t        j                  d      }|j                  d       t         j
                  j                  |d      }|j                         }| j                  |j	                         |j	                                | j                  |j	                         |j	                                y)z%see if set_alpha information is kept.    rH   7   @   rK   N)r   Surface	set_alphaassertEqual	get_alpha	transformscalecopyselfr   s2s3s       r$   test_scale__alphaz%TransformModuleTest.test_scale__alphaU   s     NN8$	B+NN8$	B##Ax0VVX77r&   c                    t        j                  d      }t         j                  j                  |d      }|j	                         }t         j                  j                  |d|      }t         j                  j                  |d|       | j                  t        t         j                  j                  |d|       t        j                  d      }t         j                  j                  |d      }|j	                         }t         j                  j                  |d|      }| j                  t        t         j                  j                  |d|       y)z7see if the destination surface can be passed in to use.rG   rJ   )surfacer   dest_surface)!   rK   N)r   rL   rP   rQ   rR   assertRaisesr+   smoothscalerS   s       r$   test_scale__destinationz+TransformModuleTest.test_scale__destinationc   s    NN8$##Ax0WWY ##AH2#Nq(B/ 	*f&6&6&<&<a2NNN8$))!X6WWY ))!(QS)T 	*f&6&6&B&BAxQSTr&   c                 ~   t        j                  d      }t         j                  j                  |t        j                  dd            }t         j                  j                  |t        j                  dd            }| j                  d|j                                | j                  d|j                                y )NrG   rK   rJ   )r   rL   rP   rQ   Vector2r]   rN   get_sizerS   s       r$   test_scale__vector2z'TransformModuleTest.test_scale__vector2{   s    NN8$##Av~~b"'=>))!V^^B-CD2;;=12;;=1r&   c                 *   t         j                  j                  t        j                  d      d      }| j	                  |j                         d       t         j                  j                  |d      }| j	                  |j                         d       y )N   re   r   )r   rP   rQ   rL   rN   ra   )rT   tmp_surfaces     r$   "test_scale__zero_surface_transformz6TransformModuleTest.test_scale__zero_surface_transform   sm    &&,,V^^J-GP--/8&&,,[*E--/<r&   c                    t        j                  d      }t         j                  j                  |d      }| j	                  d|j                                t         j                  j                  |d      }| j	                  d|j                                t        j                  d      }t         j                  j                  |d|       y NrG   r   rJ   )g       @g      ?)factor)rK   0   )rZ   )r   rL   rP   scale_byrN   ra   rT   r   rU   dests       r$   test_scale_byz!TransformModuleTest.test_scale_by   s    NN8$&&q!,2;;=1&&q&<2;;=1~~h'!!!Zd!Cr&   c                    t        j                  d      }t         j                  j                  |d      }| j	                  d|j                                t         j                  j                  |d      }| j	                  d|j                                t        j                  d      }t         j                  j                  |d|       y ri   )r   rL   rP   smoothscale_byrN   ra   rm   s       r$   test_smoothscale_byz'TransformModuleTest.test_smoothscale_by   s    NN8$,,Q22;;=1,,Qz,B2;;=1~~h''':D'Ir&   c                 
   t        j                  d      }|j                  d       t         j                  j	                  |      }| j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       t        j                  dd      }t         j                  j	                  ||       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       t        j                  dd      }|j                  d	       t         j                  j	                  ||       | j                  t         j                  j                  |      d   d
       | j                  t         j                  j                  |      d   d
       | j                  t         j                  j                  |      d   d
       t        j                  dd      }|j                  d       t         j                  j	                  ||       | j                  t         j                  j                  |      d   ddg       | j                  t         j                  j                  |      d   ddg       | j                  t         j                  j                  |      d   ddg       t        j                  dd
      }|j                  d       t        j                  dd
      }t         j                  j	                  ||       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       t        j                  dd      }|j                  d       t        j                  dd      }t         j                  j	                  ||       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       | j                  t         j                  j                  |      d   d       y )NrG      r   r   r   L   r	   r   rH   depth)"      A      ){   r}   r}   r}   z      H   )r   rL   r*   rP   	grayscalerN   average_colorassertInrm   s       r$   test_grayscalez"TransformModuleTest.test_grayscale   s   NN8$	{''*))77;A>C))77;A>C))77;A>C~~hb1""1d+))77=a@"E))77=a@"E))77=a@"E~~hb1	|""1d+))77=a@"E))77=a@"E))77=a@"E~~hb1	""1d+f&&44T:1=SzJf&&44T:1=SzJf&&44T:1=SzJNN82.	{~~hb1""1d+))77=a@"E))77=a@"E))77=a@"ENN82.	{~~hb1""1d+))77=a@"E))77=a@"E))77=a@"Er&   c           	      *   dx\  }}}d}d}d}t        j                  |t         j                  d      }t        j                  |t         j                  d      }t        j                  |t         j                  d      }	|j                  |       |	j                  |       t         j                  j                  d |||d d      }
| j                  ||z  |
       t         j                  j                  d |d |d d|	      }
| j                  ||z  |
       y )	NrG      r   r   r      r   r   r   
   r   r   r   rH   r   rZ   rY   search_colorr3   	set_colorset_behaviorrZ   rY   r   r3   r   r   search_surf)r   rL   SRCALPHAr*   rP   r3   rN   )rT   whr   r3   original_colorthreshold_colororiginal_surfacerZ   third_surfacepixels_within_thresholds              r$   $test_threshold__honors_third_surfacez8TransformModuleTest.test_threshold__honors_third_surface   s    ! A %	)* ">>$D~~dFOOR@ tV__bA 	n-?+
 #)"2"2"<"<$( #= #
 	Q 78 #)"2"2"<"<$% #= #
 	Q 78r&   c           	         dx\  }}}d}d}d}d}d}t        j                  |t         j                  d      }	t        j                  |t         j                  d      }
t        j                  |t         j                  d      }|	j                  |       |j                  |       |
j                  |       d}t         j                  j                  |
|	d	||||
      }| j                  ||z  |       |
j                         }|j                  }| j                  ||       t        j                  |      D ]D  }| j                  |
j                  |      |       | j                  |
j                  |      |       F y	)zthe pixels within the threshold.

        All pixels not within threshold are changed to set_color.
        So there should be none changed in this test.
        rG   r   r   r{   r{   r{   rI   r   ru   r   r   r   rH   r	   Nr   )r   rL   r   r*   rP   r3   rN   r
   r   r   rect_area_ptsassertNotEqualr-   rT   r   r   r   r3   r   original_dest_colorr   r   r1   	dest_surfr   $THRESHOLD_BEHAVIOR_FROM_SEARCH_COLORr   	dest_rect	dest_sizepts                    r$   #test_threshold_dest_surf_not_changez7TransformModuleTest.test_threshold_dest_surf_not_change  sc    ! A$	).*%	~~dFOOR8NN4"=	nnT6??B?		.!)*+
 01,"("2"2"<"<"=# #= #
 	Q 78 &&(	NN	y)
 **95 	HB	 0 0 4i@Y--b13FG	Hr&   c                    dx\  }}}d}d}d}d}d}t        j                  |t         j                  d      }	t        j                  |t         j                  d      }
t        j                  |t         j                  d      }|	j                  |       |j                  |       |
j                  |       d}t         j                  j                  |
|	d	|||
      }| j                  d|       |
j                         }|j                  }| j                  ||       t        j                  |      D ]#  }| j                  |
j                  |      |       % y	)z1Lowering the threshold, expecting changed surfacerG   r   r   r   r   r   rH   r	   Nr   r   r   r   r   )r   rL   r   r*   rP   r3   rN   r
   r   r   r   r-   r   s                    r$   $test_threshold_dest_surf_all_changedz8TransformModuleTest.test_threshold_dest_surf_all_changed@  s:    ! A$	).*%	~~dFOOR8NN4"=	nnT6??B?		.!)*+/0,"("2"2"<"<=# #= #
 	34&&(	NN	y) **95 	>BY--b19=	>r&   c                 H   d}t        j                  |t         j                  d      }t        j                  |t         j                  d      }d}d}|j                  |       |j	                  d|       |j	                  d|       | j                  t        t         j                  j                  d||       d}| j                  t        t         j                  j                  d|||	       d
}t         j                  j                  d|||      }| j                  |d       y)z(counts the colors, and not changes them.rG   rH   rI   rI   rI   ru   r   r   r   ru   r   rz      Nr   )r   r   )rZ   rY   r   r   
r   rL   r   r*   r/   r\   	TypeErrorrP   r3   rN   )	rT   	surf_sizer1   r   r   r   #THRESHOLD_BEHAVIOR_FROM_SEARCH_SURFTHRESHOLD_BEHAVIOR_COUNTnum_threshold_pixelss	            r$   test_threshold_countz(TransformModuleTest.test_threshold_countg  s   	~~i"=nnYD(*		.!FL)G\* 	v''114|	
 /0+&&< 	 	
 $% %//99%1	  :  
 	-q1r&   c           
      *   d}t        j                  |t         j                  d      }t        j                  |t         j                  d      }t        j                  |t         j                  d      }d}d}|j                  |       |j                  |       |j	                  d|       |j	                  d|       |j                  |       d}| j                  t        t         j                  j                  |||||       t        j                  d	t         j                  d      }| j                  t        t         j                  j                  ||d d ||
       | j                  t        t         j                  j                  ||d d ||
       t         j                  j                  ||d d ||      }	d}
| j                  |	|
       |j                  |       t         j                  j                  ||d d ||d      }	| j                  |	d       y )NrG   rH   r   r   r   r   r   )r   r   )   r[   r   )rZ   rY   r   r   r   r   T)r   r   r   r   inverse_setr   )rT   r   r1   r   r   r   r   r   different_sized_surfr   num_pixels_withins              r$   test_threshold_search_surfz.TransformModuleTest.test_threshold_search_surf  s   	~~i"=nnYDNN9foorB	*(		.!~&FL)G\*& /0+ 	&&<# 	 	
  &~~hL&& <# 	 		
 	&&<, 	 		
  &//99"<#  :  
 -/@A~&%//99<#  :  
 	-q1r&   c           	         d}t        j                  |t         j                  d      }t        j                  |t         j                  d      }|}|}d}d}d}d}	d}
|j                  |
       |j	                  d|       |j	                  d	|       |j                  |
       |j	                  d|       |j	                  d	|       d}t         j
                  j                  ||||||d
      }| j                  |d       | j                  |j                  d      |       | j                  |j                  d	      |       | j                  |j                  d      |
       y)z9changes the pixels within the threshold, and not outside.rG   rH   r   )r   r   r   r   )   r   r   ru   r	   r   r   r   )r   r3   r   r   r   r   )r   r   N)	r   rL   r   r*   r/   rP   r3   rN   r-   )rT   r   
_dest_surf_surfr   r1   r   r3   r   r   r   r   r   s                r$   test_threshold_inverse_setz.TransformModuleTest.test_threshold_inverse_set  sG   	^^IvC
y&//2>	( 	(	*		.!FL)G\*~&.,//0,%//99%=  :  
 	-q1))&19=))'2I> 	))&1>Br&   c                 H   t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }|j                  d      }|j                  dd       |j                  d      }|j                  d      }|j                  d      }|j                  dd       |j                  dd       |j                  dd	       |j                  dd
       |j                  dd       | j	                  |j                  d      d       | j	                  |j                  d      d       | j	                  d|j                         |j                         f       d}d}d}	d}
t         j                  j                  ||||	||
      }| j	                  |d       t         j                  j                  ||d|	||
      }| j	                  |d       | j	                  |j                  d      |       y )Nr   r   r   r   r   r   )rH   r   r   )r   r   r   )r[      r   )   r   )?   =   r   )p      r   )   r   r   r	   r	   )rz   r   r   )rH   r   r   ru   )r[   r   r   ru   ru   ru   ru   ru   )   r   r   ru   )r   r   r   ru   r	   r   r   )(   r   r   )	r   rL   r*   r/   rN   r-   	get_flagsrP   r3   )rT   results1rU   rV   s4rB   similar_colorr4   r   r   r   s               r$   test_threshold_non_src_alphaz0TransformModuleTest.test_threshold_non_src_alpha  s   )^^H%^^H%^^H%^^H%GGI
		&+&GGJGGIGGI
		&+&
		&+&
		&,'
		&+&
		&+&6*,<=6*,<=",,.",,.!AB,%
+/0,%//99&% =  :  
 	-q1%//99$% =  :  
 	-q1v.
;r&   c           	         dx\  }}}t        j                  |t         j                  d      }t        j                  |t         j                  d      }|j                  d       g d}g d}t	        t        d            D ]P  }|d d  }	|d d  }
d|	|<   d|
|<   t         j                  j                  d ||	|
d d	      }| j                  ||z  |       R y )
N)r   r   rH   r   )r   r   r   r   )   r   r   r   rgb-   2   )r   r   )	r   rL   r   r*   r,   lenrP   r3   rN   )rT   r   r   r   r   rZ   threshold_color_templatethreshold_templateposr   r3   r   s               r$   test_threshold__uneven_colorsz1TransformModuleTest.test_threshold__uneven_colors?  s      A!>>$D~~dFOOR@a #/ ) U$ 	=C6q9O*1-I#%OC IcN&,&6&6&@&@  'A '# QU$;<!	=r&   c           
          ddl m} t        j                  dt        d      }t        j                  dt        d      }d}| j                  t        |||ddd|	       y
)z>raises an error when set_behavior=2 and set_color is not None.r   r3   rG   rH   r      r   r   r   r   r   rt   r   Npygame.transformr3   r   rL   r   r\   r   )rT   r3   r   rU   r   s        r$   test_threshold_set_behavior2z0TransformModuleTest.test_threshold_set_behavior2`  sZ    .^^Hh3^^Hh3./+%"!< 	 		
r&   c           
         ddl m} t        j                  dt        d      }t        j                  dt        d      }d}| j                  t        |d|ddd|	       | j                  t        |||ddd|	        |d|ddd|	       y)
zrraises an error when set_behavior=1
        and set_color is not None,
        and dest_surf is not None.
        r   r   rG   rH   Nr   r   r   r   r   )rT   r3   r   rU   r   s        r$   test_threshold_set_behavior0z0TransformModuleTest.test_threshold_set_behavior0r  s    
 	/^^Hh3^^Hh3#$ %"1 	 		
 	%"1 	 		
 	%"1	
r&   c           	         ddl m} t        j                  dt        d      }t        j                  dt        d      }d}d}|j                  |       |j                  |       d} |||dd	d
|d      }| j                  ||j                         |j                         z         | j                  |j                  d      |       y
)z9Set similar pixels in 'dest_surf' to color in the 'surf'.r   r   rG   rH   )r   r   r   ru   ru   ru   ru   r   r   r   Nr	   )rZ   rY   r   r3   r   r   r   r   )
r   r3   r   rL   r   r*   rN   r)   r(   r-   )rT   r3   r1   r   
surf_color
dest_colorr   r   s           r$   test_threshold_from_surfacez/TransformModuleTest.test_threshold_from_surface  s    .~~h"5NN8Xr:	&
$
		*z"./+("%"< 
 	 )"6"6"89;N;N;P"P	
 	))&1:>r&   c           	         ddl m} t        j                  dt        d      }t        j                  dt        d      }t        j                  dt        d      }d}|j                  d       |j                  dd	       d} |d
|ddd
|      }| j                  ||j                         |j                         z  dz
         |j                  d       |j                  d       |j                  d       |j                  dd	        |d
|ddd
|      }| j                  ||j                         |j                         z  dz
          |d
|d
dd
||      }| j                  ||j                         |j                         z  dz
          |d
|ddd
|      }| j                  |d        |d
|d
dd
||      }| j                  |d       y
) r   r   rG   rH   r   r   )r   r   r   r   )   r   r   Nr   r   r   r	   )   r   r   r   r	   r	   r	   )   r   r   r   )
r   r3   r   rL   r   r*   r/   rN   r)   r(   )rT   r3   r   rU   rV   r   r   r   s           r$   test_threshold__surfacez+TransformModuleTest.test_threshold__surface  s   .^^Hh3^^Hh3^^FHb1./+@ 	
		&/*#$ (%"1 
 	-",,.0PTU/UV
 	 
 
 
		&/*("oy$8P 
 	-",,.0PTU/UV  )"dIt-Er 
 	-",,.0PTU/UV  )"oy$8P 
 	-q1  )"dIt-Er 
 	-q1r&   c                    d}d}d}d}d}t        j                  |||      }t        j                  |||      }t        j                  |||      }|j                  d       |j                  d       |j                  d       t        j                  j                  ||d|d	|
      }	| j                  |t        j                         | j                  |t         j                         | j                  |	|       | j                  |j                  d      |       | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       y	)z-Ensure threshold accepts subclassed surfaces.)   r   r   rH   )Z   P   F   ru   )r   r   r   r   )r   r   r   r   N)rZ   rY   r3   r   r   r   r   )r   SurfaceSubclassr*   r   rP   r3   assertIsInstancerL   rN   r-   get_bitsizera   r   )
rT   expected_sizeexpected_flagsexpected_depthexpected_colorexpected_countrY   rZ   search_surfacecounts
             r$   "test_threshold__subclassed_surfacez6TransformModuleTest.test_threshold__subclassed_surface  s]    *,,>>
 "11>>
 $33>>
 	\"/*L)  **%$& + 
 	lFNN;lJ,F,FG/,,V4nE113^D..0-@//1>Br&   c                    d}t        j                  ||f      }t        j                  ||f      }|j                  d       t         j                  j	                  |ddd       t         j                  j	                  |ddd       t         j
                  j                  ||       | j                  |j                  d      d	       | j                  |j                  d      d
       | j                  |j                  d      d
       | j                  |j                  d      d
       t         j
                  j                  |      }| j                  |j                  d      d	       | j                  |j                  d      d
       | j                  |j                  d      d
       | j                  |j                  d      d
       y)r   rH   r   r   r   rt   r   r   r   r   r   r   r   r   r   r   r   r   ru   ru   r   r   ru   N)	r   rL   r*   drawlinerP   	laplacianrN   r-   )rT   SIZEr   rU   s       r$   test_laplacianz"TransformModuleTest.test_laplacian1  si    ^^T4L)^^T4L)
['8< 	['8<""2r*
 	6*N;7+-=>7+-=>8,.>? ''+6*N;7+-=>7+-=>8,.>?r&   c                    t         j                  j                          	 t         j                  j	                  t        t        j                  j                  dd                  }d}t        j                  ||fdd      }t         j                  j                  ||       | j                  |j                  d      d       | j                  |j                  d	      d
       | j                  |j                  d      d
       | j                  |j                  d      d
       t         j                  j                  |      }| j                  |j                  d      d       | j                  |j                  d	      d
       | j                  |j                  d      d
       | j                  |j                  d      d
       t         j                  j                          y# t         j                  j                          w xY w)r   datazlaplacian.pngrH   r   r|   )rY   rZ   r   r  r  r  r
  r  N)r   r   r   imageloadr   ospathjoinrL   rP   r  rN   r-   r   )rT   surf_1r  surf_2s       r$   test_laplacian__24_big_endianz1TransformModuleTest.test_laplacian__24_big_endianO  s   	"\\&&RWW\\&/BCF D^^T4L!R8F &&vF&K
 V]]62NCV]]735EFV]]735EFV]]846FG %%//7FV]]62NCV]]735EFV]]735EFV]]846FGNN!FNN!s   F)G( ( Hc                 @   d}t        j                  ||f      }t        j                  ||f      }t        j                  ||f      }|j                  d       |j                  d       |j                  d       |||g}||g}t         j                  j	                  |      }| j                  |j                  d      d       | j                  t        t         j                  j                  d       | j                  t        t         j                  j                  g        | j                  t        t         j                  j                  dg       | j                  t        t         j                  j                  |dg       | j                  t        t         j                  j                  d|g       | j                  t        t         j                  j                  ||dg       | j                  t        t         j                  j                  d |||fD               y	)
r   rH   r  )r   r   r   )r      r   r   )r      r   ru   r	   c              3       K   | ]  }|  y wN ).0r   s     r$   	<genexpr>z<TransformModuleTest.test_average_surfaces.<locals>.<genexpr>  s     :S1:Ss   N)	r   rL   r*   rP   average_surfacesrN   r-   r\   r   )rT   r  r   rU   rV   surfacessrs          r$   test_average_surfacesz)TransformModuleTest.test_average_surfacess  s    ^^T4L)^^T4L)^^T4L)


B<8..x86*,=>)V%5%5%F%FJ)V%5%5%F%FK)V%5%5%F%FL)V%5%5%F%FQP)V%5%5%F%FBP)V%5%5%F%FRQRTv''88:Sr2rl:S	
r&   c                    d}d}t        j                  ||fd|      }t        j                  ||fd|      }t        j                  ||fd|      }|j                  d       |j                  d       |j                  d       |||g}t         j                  j	                  |      }| j                  |j                         |j                                | j                  |j                         |j                                | j                  |j                         |j                                	 | j                  |j                  d      d       y )	NrH   r|   r   )r   r   r   ru   )r   r   r   ru   )r   r  r   ru   r   )r   5   r   ru   )r   rL   r*   rP   r%  rN   	get_masksr   
get_lossesprint
get_shiftsr-   )rT   r  rx   r   rU   rV   r&  r'  s           r$   test_average_surfaces__24z-TransformModuleTest.test_average_surfaces__24  s	   ^^T4L!U3^^T4L!U3^^T4L!U3
!"
!"
"#B<..x888"--/: 	6*,=>r&   c                    t         j                  j                          	 t         j                  j	                  t        t        j                  j                  dd                  }|j                         }||g}| j                  |j                  d      d       | j                  |j                  d      d       t         j                  j                  |      }| j                  |j                         |j                                | j                  |j                         |j                                | j                  |j!                         |j!                                | j                  |j                  d      d       t         j                  j#                          y # t         j                  j#                          w xY w)Nr  zBGR.pngr   r  )r   r   r   r  r  r   r  r  r  rR   rN   r-   rP   r%  r+  r   r,  r   )rT   r  r  r&  surf_avs        r$   $test_average_surfaces__24_big_endianz8TransformModuleTest.test_average_surfaces__24_big_endian  s?   	"\\&&|BGGLL4S'TUF[[]F'HV]]624DEV]]624DE&&77AGW..0&2B2B2DEW..0&2B2B2DEW//163D3D3FGW^^F35EFNN!FNN!s   E&F% % Gc                 X   d}d}d}d}g }dD ];  }t        j                  |||      }|j                  |       |j                  |       = t        j
                  j                  |      }| j                  |t        j                         | j                  |t         j                         | j                  |j                  d      |       | j                  |j                         |       | j                  |j                         |       | j                  |j                         |       y)z4Ensure average_surfaces accepts subclassed surfaces.)      r   rH   )r   r   r   ru   ))r   <   r   )r6  r   r6  r   N)r   r   r*   appendr   rP   r%  r   rL   assertNotIsInstancerN   r-   r   ra   r   )	rT   r   r   r   r  r&  r2   r   rY   s	            r$   *test_average_surfaces__subclassed_surfacesz>TransformModuleTest.test_average_surfaces__subclassed_surfaces  s     *1 	E**~~A FF5MOOA	 ""33H=gv~~6  **D*DE/@,,.?))+];**,n=r&   c                    d}d}d}d}g }dD ];  }t        j                  |||      }|j                  |       |j                  |       = |j	                         }t
        j                  j                  ||      }	| j                  |	t
        j                         | j                  |	t         j                         | j                  |	|       | j                  |	j                  d      |       | j                  |	j                         |       | j                  |	j                         |       | j                  |	j                         |       y)	zAEnsure average_surfaces accepts a destination subclassed surface.)r      r   rH   )r  r  r  ru   ))r   r   r   )r   r   r   r   )r&  rZ   r   N)r   r   r*   r7  popr   rP   r%  r   rL   assertIsrN   r-   r   ra   r   )
rT   r   r   r   r  r&  r2   r   expected_dest_surfacerZ   s
             r$   5test_average_surfaces__subclassed_destination_surfacezITransformModuleTest.test_average_surfaces__subclassed_destination_surface  s,    *? 	E**~~A FF5MOOA	 !) ''88,A 9 
 	lFNN;lJ,F,FGl$9:,,V4nE113^D..0-@//1>Br&   c                    dD ]  }| j                  d| d      5  t        j                  dd|      }|j                  d       |j                  dd       | j	                  t        j
                  j                  |      d	       t        j
                  j                  |d
      }| j	                  |d       ddd        y# 1 sw Y   xY w)r   )r|   rH   zTesting z-bit surfacerG   r   )r   d      )r   r   rA  r   r   r   rH   )r   K      r   r   r   r   rH   rY   rect)r   rA  rB  r   N)subTestr   rL   r*   rN   rP   r   )rT   ir   	avg_colors       r$   test_average_colorz&TransformModuleTest.test_average_color  s     	>A<89 >NN8Q2}%}n5  !1!1!?!?!BOT #,,::O ; 	   ,<=> >	>> >s   BCC	c                 ^   t        j                  dt         j                  d      }|j                  d       |j                  dd       | j	                  t         j
                  j                  |d      d       t         j
                  j                  |d	d
      }| j	                  |d       y)r   rG   rH   r   rA  rB  ru   )r   r   rA  ru   rC  Tconsider_alpha)r   rD  rE  ru   rF  rY   rH  rP  Nr   rL   r   r*   rN   rP   r   rT   r   rK  s      r$   6test_average_color_considering_alpha_all_pixels_opaquezJTransformModuleTest.test_average_color_considering_alpha_all_pixels_opaque  s    NN8V__b9	!"	!>2**1T*BDU	

 $$22OD 3 
	 	$67r&   c                 ^   t        j                  dt         j                  d      }|j                  d       |j                  dd       | j	                  t         j
                  j                  |d      d       t         j
                  j                  |dd	      }| j	                  |d       y
)r   rG   rH   rN  )r   r   rA  re   rC  TrO  )r   S         rQ  NrR  rS  s      r$   $test_average_color_considering_alphaz8TransformModuleTest.test_average_color_considering_alpha  s    NN8V__b9	!"	!>2 	**1T*BDU	

 $$22N4 3 
	 	$67r&   c                    d}d}d}t        j                  d      }d}|j                  d|       |j                  d|       | j                  |j	                  d      |       | j                  |j	                  d      |       | j                  |j	                  d      |       t        dd	      D ]  }|d
z  dk(  r"| j                  |j	                  d      |       nM|dk(  r"| j                  |j	                  d      |       n&|dk(  r!| j                  |j	                  d      |       |dz  }t         j                  j                  |d      } | j                  |j	                  d      |       y )N)r   r   ru   ru   r  r   )r   r   r   )r   r   )r   r   r      r   r	   r   r   )rY   angle)r   rL   r/   rN   r-   r,   rP   rotate)rT   blueredblackcanvasrotationrJ  s          r$   test_rotatezTransformModuleTest.test_rotate&  sE   'fd#fc"v.6v.5v.4q! 
	GA1uz  v!6>a  v!6=a  v!6<NH%%,,V2,FF
	G 	v.6r&   c                     t        j                  d      }t        j                  d      }t         j                  j                  |d       t         j                  j                  |d       y )N)r   r	   )r	   r   *   )r   rL   rP   r]  )rT   canvas1canvas2s      r$   test_rotate_of_0_sized_surfacez2TransformModuleTest.test_rotate_of_0_sized_surfaceC  sJ    ..(..(,,r&   c                 x   d\  }}t        j                  ||ft         j                        }t        t	        j
                  ||            }|D ]  \  }}|j                  ||        dD ]"  }t         j                  j                  ||      }$ |D ](  \  }}| j                  |j                  |      |k(         * y )NrG   )r   i)r   rL   r   listr   gradientr/   rP   r]  
assertTruer-   )rT   r   r   r   rk  r   r2   rb  s           r$   #test_rotate__lossless_at_90_degreesz7TransformModuleTest.test_rotate__lossless_at_90_degreesJ  s    1NNAq66??3
++Aq12! 	 IBHHR	  " 	5H  ''84A	5 " 	3IBOOAHHRLE12	3r&   c                    d\  }}t        j                  ||ft         j                  d      }t         j                  j	                  |      }t         j                  j	                  |      }| j                  |j                         j                  d       | j                  |j                         j                  d       y )NrG   rH   )rY   rJ   )r   rL   r   rP   scale2xrN   r
   r   )rT   r   r   r   r   rU   s         r$   test_scale2xz TransformModuleTest.test_scale2xY  s     1NNAq66??B7 %%a(%%a%0++X6++X6r&   c                    d\  }}t        j                  ||ft         j                  d      }|j                  d       t         j                  j                  |d|dz  |dz  f|dz         t         j                  j                  ||dz  |dz  f      }t         j                  j                  ||dz  |dz  f      }t         j                  j                  ||dz  |dz  f      }| j                  |j                         j                  d       t        j                  |j                               D ]2  }| j                  |j                  |      |j                  |             4 y )	NrG   rH   r   rt   r   r   r[  rd   )r   rL   r   r*   r  circlerP   rQ   rN   r
   r   r   r   r-   )rT   r   r   r   rU   s2_2r   r   s           r$   test_scale2xrawz#TransformModuleTest.test_scale2xrawj  s"   1NNAq66??B7	y1kAFAF+;a1fF##AAq1u~6%%b1q5!a%.9##AAq1u~6--z:**4==?; 	=BT[[_biim<	=r&   c                 f    t         j                  j                         }| j                  |dv        y )N)GENERICMMXSSE)r   rP   get_smoothscale_backendrl  )rT   filter_types     r$   test_get_smoothscale_backendz0TransformModuleTest.test_get_smoothscale_backendy  s(    &&>>@'@@Ar&   c                 P   t         j                  j                         }t         j                  j                  d       t         j                  j                         }| j	                  |d       t         j                  j                  |       d }| j                  t        |       d }| j                  t        |       d }| j                  t        |       |dk7  rd }| j                  t        |       t         j                  j                         }| j	                  ||       y )Nrv  )backendc                  B    t         j                  j                  d       y )Nmmxr   rP   set_smoothscale_backendr"  r&   r$   changez@TransformModuleTest.test_set_smoothscale_backend.<locals>.change  s    44U;r&   c                  D    t         j                  j                  d       y )Nrv  )tr  r"  r&   r$   r  z@TransformModuleTest.test_set_smoothscale_backend.<locals>.change  s    44y4Ar&   c                  B    t         j                  j                  d       y )Nr	   r  r"  r&   r$   r  z@TransformModuleTest.test_set_smoothscale_backend.<locals>.change  s    44Q7r&   rx  c                  B    t         j                  j                  d       y )Nrx  r  r"  r&   r$   r  z@TransformModuleTest.test_set_smoothscale_backend.<locals>.change  s      88?r&   )r   rP   ry  r  rN   r\   r+   r   )rT   original_typerz  r  s       r$   test_set_smoothscale_backendz0TransformModuleTest.test_set_smoothscale_backend  s    ((@@B00;&&>>@i0 	000G	< 	*f-	B 	)V,	8 	)V,E!@ j&1&&>>@m4r&   c                 &
   t        j                  d      }t         j                  j                  |dd       t         j                  j                  |dd       t         j                  j                  |dd       t         j                  j                  |dd	       t        j                  d
d
dd      }t         j
                  j                  ||      }| j                  |j                         d       t        d      D ]^  }t        d      D ]N  }|dk  r$| j                  |j                  ||f      d       ,| j                  |j                  ||f      d       P ` | j                  |j                         d       t        d      D ]  }t        d      D ]  }|dk  r(|dk  r#| j                  |j                  ||f      d       |dcxk  r|k  r&n n#| j                  |j                  ||f      d       |dcxkD  r|kD  r&n n#| j                  |j                  ||f      d       |dkD  s|dkD  s| j                  |j                  ||f      d         t        j                  d
d
dd      }|j                         j                  |_        t         j
                  j                  ||      }| j                  |j                         d       t        d      D ]  }t        d      D ]  }|dk  r(|dk  r#| j                  |j                  ||f      d       |dcxk  r|k  r&n n#| j                  |j                  ||f      d       |dcxkD  r|kD  r&n n#| j                  |j                  ||f      d       |dkD  s|dkD  s| j                  |j                  ||f      d         t        j                  ddd
d
      }t         j
                  j                  ||      }| j                  |j                         d       t        j                  d
d
dd      }t         j
                  j                  ||      }| j                  |j                         d       t        j                  dddd      }t         j
                  j                  ||      }| j                  |j                         d       t        j                  dddd      }t         j
                  j                  ||      }| j                  |j                         d       y )Nr	  rt   )r   r   r   r   )r   ru   r   )r   r   r   r   )r   r   ru   )r   r   r   r   )ru   ru   r   r   r   r   r  )r  r   r   r   rG  r   r   )r   r  i  )r   rL   r  rH  RectrP   choprN   ra   r,   r-   r
   center)rT   r   rH  test_surfacerB   rA   s         r$   	test_chopzTransformModuleTest.test_chop  sj   !>>(3);G);H);H)=:JK{{1aB''',,-=tD..0':r 	QA1X Qq5$$\%8%8!Q%@+N$$\%8%8!Q%@-P	Q	Q 	)224h?r 		UA2Y Ur6a"f$$%5%<%<aV%DkRr:A:$$%5%<%<aV%DkRr:A:$$%5%<%<aV%DkRr6a"f$$%5%<%<aV%DmTU		U {{1aR(&//188'',,5ED,Q..0(;r 		QA2Y Qq5QU$$\%8%8!Q%@+Nq919$$\%8%8!Q%@+Nq919$$\%8%8!Q%@+Nq5QU$$\%8%8!Q%@-PQ		Q {{2r1a('',,-=tD..0(;{{1aR('',,-=tD..0&9{{1b"b)'',,-=tD..0':{{3R,'',,-=tD..0(;r&   c           	         t        j                  d      }t         j                  j                  |d       t         j                  j	                  |dd      }t         j                  j	                  |dd      }| j                  |j                         t        j                  dddd             | j                  |j                         t        j                  dddd             y )N)r   r   )r   r   r   r	   )rY   r\  rQ   r   )r   rL   rP   rQ   rotozoomrN   r
   r  )rT   r   r   rU   s       r$   test_rotozoomz!TransformModuleTest.test_rotozoom  s     NN7#q'*&&q"a0&&q!&DAq!Q(?@Aq!Q(?@r&   c           	      L   d }| j                  t        |       d }| j                  t        |       d }| j                  t        |       t        j                  dd      }|j	                  t        j
                  ddd      t        j                  dddd             |j	                  t        j
                  d	d	d	      t        j                  dddd             t        d
d      D cg c]  }d|z  	 c}D ]  }t        j                  j                  ||df      }| j                  |j                  |dz  df      t        j
                  ddd             | j                  |j                         |df        t        j                  dd      }|j	                  t        j
                  ddd      t        j                  dddd             |j	                  t        j
                  d	d	d	      t        j                  dddd             t        ddd      D ]  }t        j                  j                  ||df      }	| j                  |	j                  |dz  df      t        j
                  ddd             | j                  |	j                         |df        yc c}w )zOTests the stated boundaries, sizing, and color blending of smoothscale functionc                  r    t        j                  dd      } t         j                  j                  | d      }y )Nr	  rz   rw   r   r   rL   rP   r]   starting_surfacesmoothscaled_surfaces     r$   smoothscale_low_bppzATransformModuleTest.test_smoothscale.<locals>.smoothscale_low_bpp  /    %~~hbA#)#3#3#?#? ($ r&   c                  r    t        j                  dd      } t         j                  j                  | d      }y )Nr	  rk   rw   r   r  r  s     r$   smoothscale_high_bppzBTransformModuleTest.test_smoothscale.<locals>.smoothscale_high_bpp  r  r&   c                  r    t        j                  dd      } t         j                  j                  | d      }y )Nr	  rH   rw   )r  r  r  s     r$   smoothscale_invalid_scalezGTransformModuleTest.test_smoothscale.<locals>.smoothscale_invalid_scale  r  r&   )r   r	   rH   rw   r   r	   ru   r      r      )   r	   re   r   r   N)r\   r+   r   rL   r*   Colorr  r,   rP   r]   rN   r-   ra   )
rT   r  r  r  two_pixel_surfacerB   kbigger_surfacetwo_five_six_surfsmaller_surfaces
             r$   test_smoothscalez$TransformModuleTest.test_smoothscale  sG   *	 	*&9:	 	*&:;	 	*&?@ #NN6<v||Aq!4fkk!Q16MNv||Cc:FKK1aQR<ST %a,1!Q$, 	@A#--99:KaQRVTN%%qAvqk2FLLc34O ^446A?	@ #NN82>v||Aq!4fkk!QQ6OPv||Cc:FKKQPSUV<WXq"a 	AA$..::;LqRSfUO&&a!}5v||Cc7R _557!Q@	A -s   +J!N)+__name__
__module____qualname__rW   r^   rb   rg   ro   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r(  r/  r2  r9  r?  rL  rT  rY  rc  rh  rm  rp  rt  r{  r  r  r  r  r"  r&   r$   rE   rE   T   s    8U02=
D
J+FZ>9@0Hd%>N$2LQ2f*CZ0<d=B
$(
T?6S2j#CJ@<""H
:?2"(>0C:> 8 8(7:-37"=B$5L<<|A,@Ar&   rE   c                   $    e Zd Zd Zd Zd Zd Zy)TransformDisplayModuleTestc                 ~    t         j                  j                          t         j                  j                  d       y )N)i@  rB  )r   r   r   r   rT   s    r$   setUpz TransformDisplayModuleTest.setUp>  s$    
+r&   c                 @    t         j                  j                          y r!  )r   r   r   r  s    r$   tearDownz#TransformDisplayModuleTest.tearDownB  s    r&   c                 r   t         j                  j                  t        d            }t        j                  |j                         dd      }|j                  |d       |j                         }| j                  |j                         t         j                  z         | j                  |j                         t         j                  z         t        j                  |j                         dd      }t        j                  |j                         dd      }|j                  d       |j                  d       |j                  d      }|j                  |t               t         j                  j!                  |dd      }|j                  d      }|j                  |t               t         j                  j!                  |dd      }|j                  |d       |j                  |d       | j#                  |j                  d      |j                  d             | j#                  |j                  d      d       |j                  d       |j                  d       |j                  |d       |j                  |d       | j#                  |j                  d      |j                  d             y	)
z;honors the set_color key on the returned surface from flip.data/chimp.pngr   rH   r   r   r	   )rY   flip_xflip_yr   N)r   r  r  r   rL   ra   r   convertassertFalser   r   r*   r-   set_colorkeyRLEACCELrP   r   rN   )	rT   image_loadedr  image_convertedr1   surf2colorkeytimagetimage_converteds	            r$   	test_flipz$TransformDisplayModuleTest.test_flipE  s   ||((6F)GH|4462>

<(&..0*V__<=224vFG~~enn.26u~~/B7		/"

?#<<'8X.!!&&ua3"))&1$$Xx8!++00#Aa 1 

 			&&!

5&! 	V,ell6.BCf-/CD 			/"

?#		"F+

?F+V,ell6.BCr&   c                    t         j                  j                  t        d            }t        j                  |j                         t         j                  d      }|j                  |d       t        j                  |j                         dd      }t        j                  |j                         dd      }|j                  d      }|j                  |t               t         j                  j                  |dd      }| j                  |j                         t         j                  z         | j                  |j                         t         j                  z         |j                  d       |j                  d       |j                  |d       |j                  |d       | j!                  |j                  d      |j                  d             | j!                  |j                  d      d       y)	z8returns a surface with the same properties as the input.r  rH   r   r   r	   r   r  N)r   r  r  r   rL   ra   r   r   r-   r  r  rP   r   rl  r   r*   rN   )rT   r  image_alphar1   r  r  timage_alphas          r$   test_flip_alphaz*TransformDisplayModuleTest.test_flip_alphaq  si   ||((6F)GHnn\%:%:%<foorRv.~~l335q"=|4462>%%f-  84'',,[!Q?--/&//AB..06??BC 			/"

?#		,'

;'V,ell6.BCf-/?@r&   N)r  r  r  r  r  r  r  r"  r&   r$   r  r  =  s    ,*DXAr&   r  __main__)r   r   T)unittestr  platformpygame.testsr   pygame.tests.test_utilsr   r   r   pygame.localsr%   r3   TestCaserE   r  r  mainr"  r&   r$   <module>r     s     	  # 0     D &RfA(++ fAR'KA!2!2 KA\ zHMMO r&   