
    i                     T   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZ d dlZd dlZd dlZdZej                   j#                         Ze%edk  xr  ej&                         ej(                  k(  Zd Z G d dej,                        Zedk(  r ej2                          yy)	    N)example_pathpngtostringF)   r      c                     | j                  t        |            }t        |      t        |      k7  ryt        |      D ]  \  }}|||   k7  s y y)z3Tests a given file to see if the magic hex matches.r      )readlen	enumerate)fmagic_hexesdatai	magic_hexs        a/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pygame/tests/image_test.py
test_magicr      sU    66#k"#D
4yC$$!+. 9Q     c                   6   e Zd Zd Zd Zd Zd Z ej                  e	d      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-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).ImageModuleTestc                 z   t         j                  j                  d      }| j                  |j                  d       t         j
                  j                  |      }| j                  |j                  d      d       | j                  |j                         d       | j                  |j                         d       y)z#see if we can load the pygame icon.pygame_icon.bmprbr   r   r      r          N)
pygamepkgdatagetResourceassertEqualmodeimage
load_basicget_at
get_height	get_widthselfr   surfs      r   testLoadIconzImageModuleTest.testLoadIcon!   s    NN&&'89&||&&q)V,n=*B/)2.r   c                    d}d}d}d}||z   ||z   g}t        j                  d      \  }}t        j                  |d      5 }t	        j
                  ddd	
      }	|	j                  ||       ddd       t        j                  j                  |      }
| j                  |
j                  d      |       | j                  |
j                  d      |       | j                  |
j                  d      |       | j                  |
j                  d      |       t        |d      5 }t        j                  j                  |      }
ddd       | j                  |
j                  d      |       | j                  |
j                  d      |       | j                  |
j                  d      |       | j                  |
j                  d      |       t        j                  |       y# 1 sw Y   {xY w# 1 sw Y   xY w)zBsee if we can load a png with color values in the proper channels.)   r   r   r   )r      r   r   )r   r      r   )n   x         .pngsuffixwbr   TalphaNr   )r	   r   r   r	   r	   r	   r   )tempfilemkstemposfdopenr   Writerwriter   r$   loadr"   r&   openremove)r*   reddish_pixelgreenish_pixelbluish_pixelgreyish_pixelpixel_arrayf_descriptorf_pathr   wr+   s              r   testLoadPNGzImageModuleTest.testLoadPNG,   s    ))',$~5|m7ST'//v>fYY|T* 	$a

1at,AGGA{#	$
 ||  (V,m<V,n=V,l;V,m< &$ 	(1<<$$Q'D	( 	V,m<V,n=V,l;V,m<
		&+	$ 	$	( 	(s   +G&$ G3&G03G<c                     t        d      }t        j                  j                  |      }t	        |d      5 }t        j                  j                  |      }ddd       y# 1 sw Y   yxY w)zto see if we can load a jpg.data/alien1.jpgr   N)r   r   r$   rC   rD   r)   s      r   testLoadJPGzImageModuleTest.testLoadJPGN   sU    *+||  #!T] 	(a<<$$Q'D	( 	( 	(s    A  A)c                 D   g d}|D ]  }| j                  |      5  t        t        |      d      5 }|j                         }t	        j
                  |      }t        j                  j                  |      }ddd       ddd        y# 1 sw Y   xY w# 1 sw Y   xY w)z*to see if we can load images with BytesIO.)zdata/alien1.pngrP   zdata/alien1.gifdata/asprite.bmp)fnamer   N)	subTestrD   r   r
   ioBytesIOr   r$   rC   )r*   filesrT   r   	img_bytesimg_filer$   s          r   testLoadBytesIOzImageModuleTest.testLoadBytesIOV   s    
  	8EE* 8,u-t4 8 !I!zz)4H"LL--h7E88 8	88 88 8s#   BAB
7B
BBB	z=SDL_image 2.0.5 and older has a big endian bug in jpeg savingc           	         ddl m}m ddz  dz  f}fd} |dd       |d      f |dd       |d      f |dd       |d	      f |dd       |d
dd      fg}t        j                  |dd      }|D ]  \  }}|j	                  ||        t        j                  dd      5 }|j                  }	ddd       t         j                  j                  |	       t         j                  j                  |	      }
d }dz  }|D ]O  \  }}|j                  ||f      j                  }| j                   ||
j                  |             ||             Q t        j                   |	       y# 1 sw Y   xY w)zJPG equivalent to issue #211 - color channel swapping

        Make sure the SDL surface color masks represent the rgb memory format
        required by the JPG library. The masks are machine endian dependent
        r   )ColorRect   r   c                 &     | z  |z        S N )square_xsquare_yr^   
square_lens     r   as_rectz,ImageModuleTest.testSaveJPG.<locals>.as_rect   s#    :%x*'<j* r   redr	   greenbluer      @   r   z.jpgFr7   deleteNc                     d}t        j                  | j                  |z  | j                  |z  | j                  |z        S )N   )r   r]   rgb)cmasks     r   approxz+ImageModuleTest.testSaveJPG.<locals>.approx   s2    D<<d
ACC$Jd
CCr   )r   r]   r^   Surfacefillr=   NamedTemporaryFilenamer$   saverC   movetopleftr"   r&   r?   rE   )r*   r]   szrf   squaresr+   rectcolorr   temp_filenamejpg_surfru   offsetposnr^   re   s                 @@r   testSaveJPGzImageModuleTest.testSaveJPGf   s|    	' 
^Q^+	 Q]E%L)Q]E'N+Q]E&M*Q]E#sB/0	
 ~~b!R(" 	#KD%IIeT"	# ((uE 	#FFM	# 	$.<<$$]3	D q" 	KKD%99ff-.66DVHOOD$9:F5MJ	K 			- !	# 	#s   +E11E:c                 :   d}d}d}d}t        j                  dt         j                  d      }|j                  d|       |j                  d|       |j                  d	|       |j                  d
|       t	        j
                  dd      5 }|j                  }ddd       t         j                  j                  |       	 t        j                  |      }|j                         \  }	}
}}| j                  t        t        |            |       | j                  t        t        |            |       | j                  t        t        |            |       | j                  t        t        |            |       |j                  j                   s|j                  j#                          ~t%        j&                  |       y# 1 sw Y   -xY w# j                  j                   s|j                  j#                          ~t%        j&                  |       w xY w)Bsee if we can save a png with color values in the proper channels.)   r   r   r   )r      r   r   )r   r      r   )s   }         r	   r   r   r   r;   r   r   r      r5   Frl   Nfilename)r   rv   SRCALPHAset_atr=   rx   ry   r$   rz   r   ReaderasRGBA8r"   tuplenextfileclosedcloser?   rE   r*   rF   rG   rH   rI   r+   r   r   readerwidthheightpixelsmetadatas                r   testSavePNG32zImageModuleTest.testSavePNG32   s    ))',~~ffoor:FM*FN+FL)FM*((uE 	#FFM	# 	$.	%ZZ7F.4nn.>+E668 U4<0-@U4<0.AU4<0,?U4<0-@ ;;%%!!#IIm$+	# 	#$ ;;%%!!#IIm$s   GB;G GAHc                    d}d}d}d}t        j                  ddd      }|j                  d|       |j                  d	|       |j                  d
|       |j                  d|       t        j                  dd      5 }|j
                  }ddd       t         j                  j                  |       	 t        j                  |      }|j                         \  }	}
}}| j                  t        t        |            |       | j                  t        t        |            |       | j                  t        t        |            |       | j                  t        t        |            |       |j                  j                  s|j                  j!                          ~t#        j$                  |       y# 1 sw Y   -xY w# j                  j                  s|j                  j!                          ~t#        j$                  |       w xY w)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      r   r;   r   r   r5   Frl   Nr   )r   rv   r   r=   rx   ry   r$   rz   r   r   asRGB8r"   r   r   r   r   r   r?   rE   r   s                r   testSavePNG24zImageModuleTest.testSavePNG24   s    $$"'~~fa,FM*FN+FL)FM*((uE 	#FFM	# 	$.	%ZZ7F.4mmo+E668 U4<0-@U4<0.AU4<0,?U4<0-@ ;;%%!!#IIm$+	# 	#$ ;;%%!!#IIm$s   ?F75B;G 7GAHc                 F   g d}dt        |      f}t        j                  |d      }t        |      D ]  \  }}|j	                  d|f|        t        j                  dd      5 }|j                  }d	d	d	       t        j                  j                  |       	 t        j                  |
      }|j                         \  }	}
}}| j                  ||	|
f       | j                  t        t        t         |            |       |j"                  j$                  s|j"                  j'                          ~t)        j*                  |       y	# 1 sw Y   xY w# j"                  j$                  s|j"                  j'                          ~t)        j*                  |       w xY w)z)see if we can save an 8 bit png correctly))r   r   r   )r   r   r   )r   r   r   )      r   r	      depthr   r5   Frl   Nr   )r   r   rv   r   r   r=   rx   ry   r$   rz   r   r   r   r"   listmapr   r   r   r   r?   rE   )r*   
set_pixelssizer+   cntpixr   r   r   r   r   r   _s                r   testSavePNG8zImageModuleTest.testSavePNG8   sP    N
3z?#~~d!,!*- 	'HCKKC#&	' ((uE 	#FFM	# 	$.	%ZZ7F'-}}$E661TE6?3 T#eV"45zB ;;%%!!#IIm$)	# 	#" ;;%%!!#IIm$s   'EA(E EAF c                 p   t         j                  j                          d}d}d}d}t        j                  ddd      }|j	                  d|       |j	                  d|       |j	                  d	|       |j	                  d
|       t        j                  dd      5 }|j                  }ddd       t         j                  j                  |       	 t        j                  |      }|j                          |j                         }	| j                  t        t!        |	            |       | j                  t        t!        |	            |       | j                  t        t!        |	            |       | j                  t        t!        |	            |       |j"                  j$                  s|j"                  j'                          ~t)        j*                  |       y# 1 sw Y   8xY w# j"                  j$                  s|j"                  j'                          ~t)        j*                  |       w xY w)r   r   r   r   r   r   r   r   r	   r   r   r5   Frl   Nr   )r   displayinitrv   set_palette_atr=   rx   ry   r$   rz   r   r   r
   paletter"   r   r   r   r   r   r?   rE   )
r*   rF   rG   rH   rI   r+   r   r   r   r   s
             r   testSavePaletteAsPNG8z%ImageModuleTest.testSavePaletteAsPNG8  s    	#$"'~~fa+A}-A~.A|,A}-((uE 	#FFM	# 	$.	%ZZ7FKKMnn&G U4=1=AU4=1>BU4=1<@U4=1=A ;;%%!!#IIm$+	# 	#$ ;;%%!!#IIm$s   G CG-  G*-AH5c                    t        j                  d      }|j                  d       i }g d|d<   g d|d<   ddg|d	<   g d
}||D cg c]  }|j                          c}z   }|D ]  }	 d| }t         j                  j                  ||       t        |d      5 }| j                  d|ft        |||j                                  |f       d d d        t         j                  j                  |      }| j                  |j                  d      |j                  d             t        j                  |        y c c}w # 1 sw Y   uxY w# t        j                         w xY w)N
   r      r   r   r      r      jpg   P   N   G   r   B   M   bmp)r   r   r   ztmpimg.r   r	   r   )r   rv   rw   upperr$   rz   rD   r"   r   lowerrC   r&   r?   rE   )	r*   sr   formatsxfmtr   handles2s	            r   	test_savezImageModuleTest.test_save8  sE   NN8$	|	3	%3	% $<	%'81QWWY88 	)C)")#!!!]3 -. & $$C:fi		6L#Ms"S \\&&}5   6!2AHHV4DE 		-(+	) 9  		-(s+   D;)1E2E AE E		EE#c                 z   t        j                  d      }|j                  d       t        j                         }t         j
                  j                  ||       |j                  d       t         j
                  j                  |d      }| j                  |j                  d      |j                  d             y )Nr<   r   r   tgar   )r   rv   rw   rV   rW   r$   rz   seekrC   r"   r&   )r*   r   bytes_streamr   s       r   test_save_to_fileobjectz'ImageModuleTest.test_save_to_fileobject\  s    NN6"	|zz|!\*!\\|U3&)299V+<=r   c                    t        j                  d      }|j                  d       t        j                  dd      5 }|j
                  }d d d        	 t         j                  j                  |       t         j                  j                  |      }| j                  |j                  d      |j                  d             t        j                  |       y # 1 sw Y   xY w# t        j                         w xY wNr<   r   z.tgaFrl   r   )r   rv   rw   r=   rx   ry   r$   rz   rC   r"   r&   r?   rE   )r*   r   r   r   r   s        r   test_save_tgazImageModuleTest.test_save_tgaf  s    NN6"	|((uE 	#FFM	#	%LLa/""=1BRYYv.0@A IIm$	# 	# IIm$s   CA/C% C"%C<c                 (   t        j                  d      }|j                  d       t        j                  dd      5 }|j
                  }d d d        t        j                        }	 t         j                  j                  ||       t         j                  j                  |      }| j                  |j                  d      |j                  d             t        j                  |       y # 1 sw Y   xY w# t        j                  |       w xY wr   )r   rv   rw   r=   rx   ry   pathlibPathr$   rz   rC   r"   r&   r?   rE   )r*   r+   r   r   pathr   s         r   test_save_pathlibz!ImageModuleTest.test_save_pathlibt  s    ~~f%		,((uE 	#FFM	# ||M*	%LLdD)""4(BRYYv.F0CDIIm$	# 	# IIm$s   C.)A/C: .C7:Dc                    t        j                  d      }|j                  d       i }g d|d<   g d|d<   ddg|d	<   g d
}||D cg c]  }|j                          c}z   }t         j                  j                         }|d uxr |d   dz  |d   dz  z   |d   z   dk\  }|D ]  }t        j                  d|       \  }}	|s}|j                         dk(  rjt        j                  |d      5 }
| j                  t         j                        5  t         j                  j                  ||
|	       d d d        d d d        nt        j                  |d      5 }
t         j                  j                  ||
|	       |j                         |v rB|
j                  d       | j                  d|ft!        |
||j                                  |f       |
j#                          |
j                  d       t         j                  j%                  |
|	      }| j                  |j'                  d      |j'                  d             d d d        t        j(                  |	        y c c}w # 1 sw Y   7xY w# 1 sw Y   4xY w# 1 sw Y   @xY w)Nr   r   r   r   r   r   r   r   r   )r   r   r   r   r   i'  r	   d   r   i"N  .r6   r8   zr+br   )r   rv   rw   r   r$   get_sdl_image_versionr=   r>   r   r?   r@   assertRaiseserrorrz   r   r"   r   flushrC   r&   rE   )r*   r   r   r   r   SDL_Im_versionisAtLeastSDL_image_2_0_2r   tmp_filetmp_filenamer   r   s               r   ,test_save__to_fileobject_w_namehint_argumentz<ImageModuleTest.test_save__to_fileobject_w_namehint_argument  sO   NN8$	|	3	%3	% $<	%.81QWWY88;;= %3$$> $1%q(9C(??.QRBSSE   	$C%-%5%5qY%G"Hl+		u0DYYx. C&**6<<8 C))!V\BCC C YYx/ J6LL%%a>yy{i/ A((Hz&)CIIK:P'QSV&W LLNKKN**6<@B$$RYYv%68HIJ IIl#-	$ 9C CC CJ Js7   I . I2"I%0I2C'I>%I/*I22I;	>J	c                 <   t        j                  dt         j                  d      }|j                  d       |j	                  d       |j                         }|j                  d      }d}	 t         j                  j                  ||       t         j                  j                  |      }t        j                  |       |j                         }| j                  ||       | j                  ||j                  d             y# t        j                  |       w xY w)z3make sure the color key is not changed when saving.r   r   r   r   r   r   r   z
tmpimg.pngN)r   rv   r   rw   set_colorkeyget_colorkeyr&   r$   rz   rC   r?   rE   r"   )r*   r   	colorkey1p1r   r   	colorkey2s          r   test_save_colorkeyz"ImageModuleTest.test_save_colorkey  s    NN8V__b9	|	y!NN$	XXf$	%LLa/""=1BIIm$NN$	I.RYYv./ IIm$s   ,?D Dc                 6   dd l }t        d      }t        j                  j	                  t        d      d      }|j                  ||       	 t        j                  j                  |      }t        j                  |       y # t        j                  |       w xY w)Nr   rS   r   
   你好.bmp)
shutilr   r?   r   joincopyr   r$   rC   rE   )r*   r   origtempims        r   test_load_unicode_pathz&ImageModuleTest.test_load_unicode_path  sg    ./ww||L0,?D$	""4(BIIdOBIIdOs   B Bc                    t        j                  ddd      }	 t        |d      5 }	 d d d        t        j                  |       | j                  t        j                  j                  |             	 t         j                  j                  ||       | j                  t        j                  j                  |      d       	 t        j                  |       y # 1 sw Y   xY w# t
        $ r t        j                  d      w xY w# t
        $ r Y y w xY w# 	 t        j                  |       w # t
        $ r Y w w xY wxY w)Nr   r   r   rM   zthe path cannot be openedr   )r   rv   rD   r?   rE   OSErrorunittestSkipTestassertFalser   existsr$   rz   assertGreatergetsize)r*   	temp_filer  r   s       r   _unicode_savezImageModuleTest._unicode_save  s   ^^Ha,	Ai% IIi  		23	LLb),rwwy92>		)$   	A##$?@@	A  		)$ sd   C% CC% 3AD D C"C% %D	DDD=D.-D=.	D:7D=9D::D=c                 &    | j                  d       y)z(save unicode object with non-ASCII charsr   N)r  r*   s    r   test_save_unicode_pathz&ImageModuleTest.test_save_unicode_path  s    <(r   c           
         | j                  t        |      t        |             d}||k7  rt        dt        |      |      D ]  }t        ||z   t        |            }||| }||| }||k7  s+||| }	d||t        |      t	        j
                  |      t	        j
                  |      t	        j
                  |	      fz  }
| j                  |
        y y )N   r   z5string difference in %d to %d of %d:
%s
%s
source:
%s)r"   r   rangeminbinasciihexlifyfail)r*   string1string2source_string
block_sizeblock_start	block_endblock1block2source_blockmsgs              r   assertPremultipliedAreEqualz+ImageModuleTest.assertPremultipliedAreEqual  s    Ws7|4
g$QGjA #j 8#g,G	 Y7 Y7V##0Y#GLS'%L$,,V4$,,V4$,,\:  IIcN## r   c           	         d }t        j                  dt         j                  d      }t        |j	                               D ]`  }t        |j                               D ]B  }|||j	                         z  z   }|j                  ||f|dz  dz  |dz  dz  |dz  dz  |f       D b |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       y)zItest to make sure we can export a surface to a premultiplied alpha stringc                 $   t        | j                               D ]t  }t        | j                               D ]V  }| j                  ||f      }|d   |d   z  dz  |d   |d   z  dz  |d   |d   z  dz  |d   f}| j	                  ||f|       X v y )Nr   r   r   r	   r   )r  r(   r'   r&   r   )surface_to_modifyr   yr   premult_colors        r   convertRGBAtoPremultipliedzQImageModuleTest.test_to_string__premultiplied.<locals>.convertRGBAtoPremultiplied  s    ,6689 	D0;;=> DA-44aV<Ea58+c1a58+c1a58+c1a	%M &,,aV]CD	Dr   )   r*  r      r*        RGBA_PREMULTRGBAARGB_PREMULTARGBr   r   N)r   rv   r   r  r(   r'   r   r   r#  r$   r   r   
ValueError)r*   r)  test_surfacer   r'  r   premultiplied_copyno_alpha_surfaces           r   test_to_string__premultipliedz-ImageModuleTest.test_to_string__premultiplied  s   
	D ~~j&//2F|--/0 	A<2245 L22444##Fa!es]QVsNQVsNAN	 *..0"#56((LL!!,?LL!!"4f=LL!!,7	

 	((LL!!,?LL!!"4f=LL!!,7	
 ">>*a<--/?	
r   Nc           
         |j                         |j                         }}| j                  ||j                         |       | j                  ||j                         |       | j                  |j                         |j                         |       | j                  |j	                         |j	                         |       | j                  |j                         |j                         |       | j                  |j                         |j                         |       | j                  |j                         |j                         |       | j                  |j                         |j                         |       | j                  |j                         |j                         |       |j                  }|j                  }t        |      D ];  }t        |      D ]+  }	| j                   ||	|f       ||	|f      d||	|fz         - = y )Nz%s (pixel: %d, %d))r(   r'   r"   get_sizeget_rectr   	get_alpha	get_flagsget_bitsizeget_bytesizer&   r  )
r*   surf_asurf_br"  a_widtha_heightsurf_a_get_atsurf_b_get_atr'  r   s
             r   _assertSurfaceEqualz#ImageModuleTest._assertSurfaceEqual$  s   ",,.0A0A0C 	&"2"2"4c:6#4#4#6<*FOO,=sC*FOO,=sC,,.0C0C0EsK))+V-=-=-?E))+V-=-=-?E++-v/A/A/CSI,,.0C0C0EsK x 	A7^   !1a&)!1a&)(CA;6	r   c           
         ddl }d}|j                  |d      }|j                  |d      }d }t        j                  dt        j
                  d      }t        d	      D ]  }t        d
      D ]v  }|d
z  dz   }	|j                  |dz   |f|	|||f       |j                  |d
z   |f||	||f       |j                  |dz   |f|||	|f       |j                  |dz   |f||||	f       x  | j                  ||d       |D ]  }
t        j                  j                  ||
d         } ||
d   |
d    ||
d   |
d   |            }t        j                  j                  ||j                         |
d         }| j                  ||d|
d    d|
d    d        |D ]  }
t        j                  j                  ||
d         } ||
d   |
d   |      }t        j                  j                  ||j                         |
d         }| j                  ||d|
d    d|
d    d        |D ]h  }t        j                  j                  ||      }t        j                  j                  ||j                         |      }| j                  ||d| d       j y)z9Ensure methods tostring() and fromstring() are symmetric.r   N)r/  r1  BGRAr   c                    t        |       D ci c]  \  }}||
 }}}t        |      D ci c]  \  }}||
 }}}t        j                  d|      }t        |      dz  }t        |      D ]_  }	|	dz  }
||
|d   z      }||
|d   z      }||
|d   z      }||
|d   z      }|||
|d   z   <   |||
|d   z   <   |||
|d   z   <   |||
|d   z   <   a t	        |      S c c}}w c c}}w )NBr   RGA)r   arrayr   r  r   )fmt1fmt2str_bufvkpos_fmt1pos_fmt2byte_buf	num_quadsr   i4rI  rJ  rH  rK  s                  r   convertz>ImageModuleTest.test_fromstring__and_tostring.<locals>.convertG  s(   )249A19H9)249A19H9{{30HH*I9% 	1UR(3-/0R(3-/0R(3-/0R(3-/0/0hsm+,/0hsm+,/0hsm+,/0hsm+,	1 H%% :9s
   CCrk   r*  r   )flagsr   r*  r_      zfailing with identical surfacesr	   zconverting z to z and back is not symmetricz failedz6tostring/fromstring functions are not symmetric with 'z' format)	itertoolspermutationscombinationsr   rv   r   r  r   rD  r$   r   
fromstringr8  )r*   r[  fmtsfmt_permutationsfmt_combinationsrW  r3  r   j	intensitypairfmt1_buffmt1_convert_buftest_convert_two_wayfmt2_convert_buftest_convert_one_wayr   test_buftest_to_from_fmt_strings                      r   test_fromstring__and_tostringz-ImageModuleTest.test_fromstring__and_tostring>  s    	'$11$:$11$:	&$ ~~ivbQs 	GA2Y GFRK	##QUAJAq!0DE##QVQK!Y11EF##QVQK!Q	11EF##QVQK!Q91EFG	G 	  ,(I	
 % 	D||,,\47CH&Qa'$q'47H"E  $*<<#:#: ,"7"7"947$  $$$d1gYd47)3MN	 % 	D||,,\47CH&tAwQB#)<<#:#: ,"7"7"947$  $$$d1gYd47)7;	  	C||,,\3?H&,ll&=&=,//13'# $$'##&%x1	r   c           	      *   t        j                  dd      }t        d      D ]  }t        d      D ]v  }|dz  dz   }|j                  |dz   |f||||f       |j                  |dz   |f||||f       |j                  |dz   |f||||f       |j                  |dz   |f||||f       x  d	}t         j                  j                  ||      }t         j                  j                  ||j                         |      }| j                  ||d
| d       y )NrX  r   r   r*  r_   rZ  r   r   RGBz6tostring/fromstring functions are not symmetric with "z" format)	r   rv   r  r   r$   r   r^  r8  rD  )r*   r3  r   rb  rc  r   fmt_bufrk  s           r   test_tostring_depth_24z&ImageModuleTest.test_tostring_depth_24  s1   ~~ir:s 	GA2Y GFRK	##QUAJAq!0DE##QVQK!Y11EF##QVQK!Q	11EF##QVQK!Q91EFG	G ,,''c:"(,,"9"9\**,c#
 	  #DSER	
r   c                 r   t         j                  j                          t        g d      }t         j                  j                  |dd      }|j                  g d       | j                  |j                  d      t        j                  ddd             | j                  |j                  d	      t        j                  ddd             | j                  |j                  d
      t        j                  ddd             | j                  |j                  d      t        j                  ddd             y)z+test reading pixel data from a bytes buffer)r   r   r   r   r	   r	   r	   r	   r   r   r   r   r   r   r   r   r   r   P))r   r   r  )r   r   r   r   )2      r  r   r   r   r  r<   r   r   r   r   r   rt  ru  N)
r   r   r   	bytearrayr$   
frombufferset_paletter"   r&   r]   )r*   eight_bit_palette_buffereight_bit_surfs      r   test_frombuffer_8bitz$ImageModuleTest.test_frombuffer_8bit  s    #,<$
   001I6SVW""F	
 	..v6S"b8QR..v6S#s8ST..v6Q18MN..v6Rb8QRr   c                    t        g d      }t        j                  j                  |dd      }| j	                  |j                  d      t        j                  ddd             | j	                  |j                  d      t        j                  ddd             | j	                  |j                  d	      t        j                  d
d
d
             | j	                  |j                  d      t        j                  ddd             y )N)0r   r   r  r   r   r  r   r   r  r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rt  ru  r  rt  ru  r  rt  ru  r  rt  ru  r  rr  rn  r   r   r   r  r<   rv  r   rw  rt  ru  rx  r   r$   ry  r"   r&   r]   )r*   
rgb_bufferrgb_surfs      r   test_frombuffer_RGBz#ImageModuleTest.test_frombuffer_RGB      13

j <<**:vuE0&,,sB2KL0&,,sC2MN0&,,q!Q2GH0&,,r32KLr   c                    t        g d      }t        j                  j                  |dd      }| j	                  |j                  d      t        j                  ddd             | j	                  |j                  d      t        j                  ddd             | j	                  |j                  d	      t        j                  d
d
d
             | j	                  |j                  d      t        j                  ddd             y )N)0r  r   r   r  r   r   r  r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  ru  rt  r  ru  rt  r  ru  rt  r  ru  rt  rr  BGRr   r   r   r  r<   rv  r   rw  rt  ru  r  )r*   
bgr_bufferbgr_surfs      r   test_frombuffer_BGRz#ImageModuleTest.test_frombuffer_BGR  r  r   c           	         t        g d      }t        j                  j                  |dd      }| j	                  |j                  d      t        j                  dddd             | j	                  |j                  d	      t        j                  dddd
             | j	                  |j                  d      t        j                  dddd             | j	                  |j                  d      t        j                  dddd             y )N@r   r   r  ru  r   r   r  ru  r   r   r  ru  r   r   r  ru  r   r   r      r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   O   r   r   r   r  r   r   r   r  r   r   r   r  rt  ru  r  r   rt  ru  r  r   rt  ru  r  r   rt  ru  r  r   rr  rF  r   r  r   r   ru  r<   r  rv  r   r  rw  rt  r  )r*   bgra_buffer	bgra_surfs      r   test_frombuffer_BGRAz$ImageModuleTest.test_frombuffer_BGRA-  s    AC
J LL++KH	))&16<<BS3QR))&16<<S#s3ST))&16<<1a3LM))&16<<CS3QRr   c           	         t        g d      }t        j                  j                  |dd      }| j	                  |j                  d      t        j                  dddd             | j	                  |j                  d      t        j                  dddd             | j	                  |j                  d	      t        j                  d
d
d
d             | j	                  |j                  d      t        j                  dddd             y )N)@r   r   r  r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rt  ru  r  r   rt  ru  r  r   rt  ru  r  r   rt  ru  r  r   rr  RGBXr   r   r   r  r<   rv  r   rw  rt  ru  r  )r*   rgbx_buffer	rgbx_surfs      r   test_frombuffer_RGBXz$ImageModuleTest.test_frombuffer_RGBXy  s    AC
J LL++KH	))&16<<RS3QR))&16<<S#s3ST))&16<<1a3MN))&16<<CS3QRr   c           	         t        g d      }t        j                  j                  |dd      }| j	                  |j                  d      t        j                  dddd             | j	                  |j                  d	      t        j                  dddd
             | j	                  |j                  d      t        j                  dddd             | j	                  |j                  d      t        j                  dddd             y )Nr  rr  r/  r   r   r   r  ru  r<   r  rv  r   r  rw  rt  r  )r*   rgba_buffer	rgba_surfs      r   test_frombuffer_RGBAz$ImageModuleTest.test_frombuffer_RGBA      AC
J LL++KH	))&16<<RS3QR))&16<<S#s3ST))&16<<1a3LM))&16<<CS3QRr   c           	         t        g d      }t        j                  j                  |dd      }| j	                  |j                  d      t        j                  dddd             | j	                  |j                  d	      t        j                  dddd
             | j	                  |j                  d      t        j                  dddd             | j	                  |j                  d      t        j                  dddd             y )N)@ru  r   r   r  ru  r   r   r  ru  r   r   r  ru  r   r   r  r  r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   r  r   r   r   r   rt  ru  r  r   rt  ru  r  r   rt  ru  r  r   rt  ru  r  rr  r1  r   r   r   r  ru  r<   r  rv  r   r  rw  rt  r  )r*   argb_buffer	argb_surfs      r   test_frombuffer_ARGBz$ImageModuleTest.test_frombuffer_ARGB  r  r   c                    g }|j                  d       t        j                  d      \  }}t        j                  |d      5 }t        j                  ddd      }|j                  ||       d d d        	 t        j                  j                  |      }d}| j                  t        j                  j                         |       t        j                  |       y # 1 sw Y   oxY w# t        j                  $ r d	}Y gw xY w)
N)ru  ru  ru  r   r   r   r   r   r5   r6   r8   r   r	   Tr9   F)appendr=   r>   r?   r@   r   rA   rB   r   r$   rC   r   r"   get_extendedrE   )r*   	raw_imagerK   rL   r   rM   r+   loadeds           r   test_get_extendedz!ImageModuleTest.test_get_extended]  s    	AB'//v>fYY|T* 	%d

1at,AGGD)$	%	<<$$V,DF 	224f=
		&	% 	% || 	F	s   +C7!C( C%(D ?D c                    t         j                  j                         s.| j                  t         j                  j	                                y d}t
        }t        }t         j                  j	                         }| j                  ||       | j                  t        |      |       |D ]  }| j                  ||        y )Nr   )
r   r$   r  assertIsNoner   r   intassertIsInstancer"   r   )r*   expected_lengthexpected_typeexpected_item_typeversionitems         r   test_get_sdl_image_versionz*ImageModuleTest.test_get_sdl_image_versionq  s     ||((*fll@@BCO!M!$ll88:G!!'=9S\?; @%%d,>?@r   c                 ,   t         j                  j                  t        d            }| j	                  |j                  d      d       t         j                  j                  d      }| j	                  |j                  d       t         j                  j                  |      }| j	                  |j                  d      d       | j	                  |j                         d       | j	                  |j                         d       |j                          y)	zGto see if we can load bmp from files and/or file-like objects in memoryrS   r   r   r   r   r   r   r   r   r   N)r   r$   r%   r   r"   r&   r    r!   r#   r'   r(   r   )r*   r   r   r+   s       r   test_load_basiczImageModuleTest.test_load_basic  s     LL##L1C$DE&)+?@ NN&&'89&||&&q)V,n=*B/)2.		r   c                 j   g d}|D ]  \  }}|j                  d      rt        r| j                  d|j                  d      d    d|z   |      5  t        j
                  j                  t        d|z               }| j                  |j                  d	      |       d
d
d
        y
# 1 sw Y   xY w)aK  can load different format images.

        We test loading the following file types:
            bmp, png, jpg, gif (non-animated), pcx, tga (uncompressed), tif, xpm, ppm, pgm
        Following file types are tested when using SDL 2
            svg, pnm, webp
        All the loaded images are smaller than 32 x 32 pixels.
        ))zasprite.bmpr  )zlaplacian.png)r   r   F   r   )zred.jpg)   r   r   r   )zblue.gif)r   r   r   r   )z	green.pcx)r   r   r   r   )z
yellow.tga)r   r   r   r   )zturquoise.tif)r   r   r   r   )z
purple.xpm)r   r   r   r   )z	black.ppm)r   r   r   r   )zgrey.pgm)r2   r2   r2   r   )zteal.svg)r   rj   rj   r   )zcrimson.pnm)r/   r  <   r   )zscarlet.webp)ro      5   r   svgzTest loading a r   zexamples/data/)r   expected_colorzdata/r   N)
endswithsdl_image_svg_jpeg_save_bugrU   splitr   r$   load_extendedr   r"   r&   )r*   filename_expected_colorr   r  r+   s        r   test_load_extendedz"ImageModuleTest.test_load_extended  s    #
  )@ 	F$Hn  ',G !(.."5b"9!:;)H4-   F
 ||11,w?Q2RS  V!4nEF F	FF Fs   AB))B2	c                     t        j                  t        d            }t        j                  j                  |      }| j                  |j                  d      d       y)z$works loading using a Path argument.rS   r   r  N)r   r   r   r   r$   r  r"   r&   )r*   r   r+   s      r   test_load_pathlibz!ImageModuleTest.test_load_pathlib  sD    ||L);<=||))$/V,.BCr   c                 \   t        j                  d      }|j                  d       ddg}||D cg c]  }|j                          c}z  }i }g d|d<   g d|d<   ddg}||D cg c]  }|j                          c}z  }|D ]  }d	| }t         j                  j                  ||       t        |d
      5 }| j                  dt        |||j                                         d d d        t         j                  j                  |      }| j                  |j                  d      |j                  d             t        j                  |        |D ]?  }| j                  t         j                  t         j                  j
                  |d	|        A y c c}w c c}w # 1 sw Y   xY w)N)r   r   r   r   r   r   r   r   r   z
temp_file.r   r	   r   )r   rv   rw   r   r$   save_extendedrD   r"   r   r   rC   r&   r?   rE   r   r   )	r*   r+   passing_formatsr   r   failing_formatstemp_file_namer   loaded_files	            r   test_save_extendedz"ImageModuleTest.test_save_extended  s   ~~f%		, %.?CCCIIKCC	3	%3	% %.?CCCIIKCC # 	&C)#/NLL&&t^<nd+ Pt   Zi		6L%MOP
 !,,++N;K[//7V9LMIIn%	& # 	Cfll88$*SE@R	1 D DP Ps   F%F7.F""F+	c                     dd l }t        d      D ]U  }|j                  j                  |j                  j
                  |      }|D ]  }| j                  ||j                           W y )Nr   r   )pygame.threadsr  threadstmapr$   rC   r  rv   )r*   imagesr   r   surfsr   s         r   threads_loadzImageModuleTest.threads_load  s[    r 	9ANN''(9(96BE 9%%a89	9r   c                 ^    | j                  t        j                  t        d                   y )Nz
data/*.pngr  globr   r  s    r   test_load_png_threadsz%ImageModuleTest.test_load_png_threads      $))L$>?@r   c                 ^    | j                  t        j                  t        d                   y )Nz
data/*.jpgr  r  s    r   test_load_jpg_threadsz%ImageModuleTest.test_load_jpg_threads  r  r   c                 ^    | j                  t        j                  t        d                   y )Nz
data/*.bmpr  r  s    r   test_load_bmp_threadsz%ImageModuleTest.test_load_bmp_threads  r  r   c                 ^    | j                  t        j                  t        d                   y )Nz
data/*.gifr  r  s    r   test_load_gif_threadsz%ImageModuleTest.test_load_gif_threads  r  r   c                 l    t        t        j                  d       t        t        j                  d       y )N	frombytestobytes)getattrr   r$   r  s    r   test_from_to_bytes_existsz)ImageModuleTest.test_from_to_bytes_exists  s    k*i(r   ra   )0__name__
__module____qualname__r,   rN   rQ   r[   r  skipIfr  r   r   r   r   r   r   r   r   r   r   r   r  r  r  r#  r6  rD  rl  rp  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rb   r   r   r   r       s   	/ D(8  X__#G;!	;!z#%J#%J%@%%N")H>%%($T0(	*)#.&
R4Ob
,S :Mx:MxJSXJSXJSXJSX(@$*&FPD D9AAAA)r   r   __main__)rL  r  rV   r?   r=   r  r  r   pygame.tests.test_utilsr   r   r   r   pygame.imagepygame.pkgdatar  r$   r   _sdl_image_verget_sdl_byteorder
BIG_ENDIANr   TestCaser   r  mainrb   r   r   <module>r     s      	 	     ? ? + +# 335)#W(@(@(@(BfFWFW(W  
^)h'' ^)B' zHMMO r   