ó
    {ñ:iDM  ã                   óÚ  • S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKrSSK	r	SSK
r
SSKJrJr  SSKrSSKrSSKrSSKJr  SSKrSSKJr  SSKJr  \R2                  " \5      r/ SQrS	 rS
 rS rS!S jr  " S S\!5      r" " S S5      r# " S S\#5      r$ " S S\#5      r% " S S\%5      r&S r'0 r(\'" 5         \&" 5       r)S r*S r+S r,\RZ                  S 5       r.S r/S r0S r1S"S jr2S  r3g)#z(
Utilities for comparing image results.
é    N)ÚPath)ÚTemporaryDirectoryÚTemporaryFile)ÚImage)Úcbook)ÚImageComparisonFailure)Úcalculate_rmsÚcomparable_formatsÚcompare_imagesc                 óV   • [         R                  R                  U 5      u  p#U SU U 3$ )zI
Make a new filename by inserting *purpose* before the file's extension.
Ú-)ÚosÚpathÚsplitext)ÚfnameÚpurposeÚbaseÚexts       Ú]/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/matplotlib/testing/compare.pyÚmake_test_filenamer      s/   € ô —‘× Ñ  Ó'�I€DØˆV�1�W�I˜c˜UÐ#Ð#ó    c                  ód   • [        [        R                  " 5       S5      n U R                  SSS9  U $ )NÚ
test_cacheT)ÚparentsÚexist_ok)r   ÚmplÚget_cachedirÚmkdir)Ú	cache_dirs    r   Ú_get_cache_pathr    &   s-   € Ü”S×%Ò%Ó'¨Ó6€IØ‡O�O˜D¨4€OÑ0ØÐr   c                  ó(   • [        [        5       5      $ ©N)Ústrr    © r   r   Úget_cache_dirr%   ,   s   € ÜŒÓ Ó!Ð!r   c                 ó�  • [         R                  " SS9n[        U S5       n UR                  U5      nU(       d  OUR	                  U5        M,  S S S 5        [        U 5      R                  S:X  aW  UR	                  [        [        R                  " S5      R                  5      R                  S5      5        UR                  5       $ [        U 5      R                  S:X  aG  UR	                  [        [        R                  " S5      R                  5      R                  S5      5        UR                  5       $ ! , (       d  f       Nî= f)	NF)ÚusedforsecurityÚrbz.pdfÚgszutf-8ú.svgÚinkscape)ÚhashlibÚsha256ÚopenÚreadÚupdater   Úsuffixr#   r   Ú_get_executable_infoÚversionÚencodeÚ	hexdigest)r   Ú
block_sizer-   ÚfdÚdatas        r   Úget_file_hashr9   0   sô   € Ü�^Š^¨EÑ2€FÜ	ˆd�DÔ	˜RØØ—7‘7˜:Ó&ˆDÞØØ�M‰M˜$Ôñ	 ÷ 
ô ˆDƒz×Ñ˜FÓ"Ø�‰”cœ#×2Ò2°4Ó8×@Ñ@ÓA×HÑHÈÓQÔRð ×ÑÓÐô 
ˆd‹×	Ñ	˜fÓ	$Ø�‰”cœ#×2Ò2°:Ó>×FÑFÓG×NÑNÈwÓWÔXà×ÑÓÐ÷ 
Õ	ús   ¡.D7Ä7
Ec                   ó   • \ rS rSrSrg)Ú_ConverterErroréA   r$   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r$   r   r   r;   r;   A   s   † Úr   r;   c                   ó&   • \ rS rSrS rS rS rSrg)Ú
_ConverteréE   c                 óR   • S U l         [        R                  " U R                  5        g r"   )Ú_procÚatexitÚregisterÚ__del__)Úselfs    r   Ú__init__Ú_Converter.__init__F   s   € ØˆŒ
ô
 	�Š˜Ÿ™Õ%r   c                 ób  • U R                   (       až  U R                   R                  5         U R                   R                  5         [        S U R                   R                  U R                   R
                  U R                   R                  /5       H  nUR                  5         M     S U l         g g r"   )rF   ÚkillÚwaitÚfilterÚstdinÚstdoutÚstderrÚclose)rJ   Ústreams     r   rI   Ú_Converter.__del__N   sz   € Ø�:�:Ø�J‰J�O‰OÔØ�J‰J�O‰OÔÜ  ¨¯
©
×(8Ñ(8Ø(,¯
©
×(9Ñ(9Ø(,¯
©
×(9Ñ(9ð(;ö <�ð —‘–ñ<ð ˆD�Jð r   c                 ó(  • [        5       n U R                  R                  R                  S5      nU(       d(  [	        [
        R                  " [        U5      5      5      eUR                  U5        UR                  U5      (       a  [        U5      $ Mˆ  )z!Read until the prompt is reached.é   )
Ú	bytearrayrF   rR   r/   r;   r   ÚfsdecodeÚbytesÚextendÚendswith)rJ   Ú
terminatorÚbufÚcs       r   Ú_read_untilÚ_Converter._read_untilX   sj   € ä‹kˆØØ—
‘
×!Ñ!×&Ñ& qÓ)ˆAÞÜ%¤b§k¢k´%¸³*Ó&=Ó>Ð>Ø�J‰J�qŒMØ�|‰|˜J×'Ñ'Ü˜S“zÐ!ñ r   ©rF   N)r=   r>   r?   r@   rK   rI   ra   rA   r$   r   r   rC   rC   E   s   † ò&òõ	"r   rC   c                   ó   • \ rS rSrS rSrg)Ú_GSConverteréd   c                 óÊ  • U R                   (       dl  [        R                  " [        R                  " S5      R
                  SSSS/[        R                  [        R                  S9U l          U R                  S5        S
 nU R                   R                  R                  SU" U5      -   S-   U" U5      -   S-   5        U R                   R                  R                  5         U R                  S5      nUR                  S5      (       a  U R                  S5      OSnU(       d$  [        R                   R#                  U5      (       do  U(       a  [%        US S 5      OS	nU R                   R                  R                  SU-  5        ['        XV-   R)                  [*        R,                  " 5       S5      5      eg ! [         a!  n[        SUR                  S	    35      S eS nAff = f)Nr)   z	-dNOSAFERz	-dNOPAUSEz	-dEPSCropz-sDEVICE=png16m)rQ   rR   s   
GSzFailed to start Ghostscript:

r   c                 óŽ   • [         R                  " U 5      R                  SS5      R                  SS5      R                  SS5      $ )Nó   \s   \\ó   (s   \(ó   )s   \))r   ÚfsencodeÚreplace)Únames    r   Úencode_and_escapeÚ0_GSConverter.__call__.<locals>.encode_and_escapeq   s7   € Ü—K’K Ó%ß‘W˜U GÓ,ß‘W˜T 6Ó*ß‘W˜T 6Ó*ð,r   s   << /OutputFile (s   ) >> setpagedevice (s   ) run flush
)ó   GS<s   GS>rq   ó   >r   éÿÿÿÿs   pop
rm   )rF   Ú
subprocessÚPopenr   r2   Ú
executableÚPIPEra   r;   ÚOSErrorÚargsrQ   ÚwriteÚflushr]   r   r   ÚexistsÚintr   ÚdecodeÚsysÚgetfilesystemencoding)rJ   ÚorigÚdestÚero   ÚerrÚstackÚ
stack_sizes           r   Ú__call__Ú_GSConverter.__call__e   s¡  € Ø�z�zÜ#×)Ò)Ü×)Ò)¨$Ó/×:Ñ:Ø˜k¨;Ð8IðKô !—o‘o¬j¯o©oñ	?ˆDŒJð
XØ× Ñ  Ô)ò	,ð 	�
‰
×Ñ×ÑØÙ Ó%ñ&à%ñ&ñ   Ó%ñ&ð ñ	ô	 ð 	�
‰
×Ñ×ÑÔ à×ÑÐ/Ó0ˆØ*-¯,©,°v×*>Ñ*>�× Ñ  Ô&ÀCˆÞœŸ™Ÿ™ t×,Ñ,Þ,1œ˜U 3 B˜Zœ°qˆJØ�J‰J×Ñ×"Ñ" 8¨jÑ#8Ô9ä(Ø‘×$Ñ$¤S×%>Ò%>Ó%@À)ÓLóNð Nð	 -øô' #ó XÜÐ @ÀÇÁÈÁÀÐLÓMÐSWÐWûðXús   Á-F7 Æ7
G"ÇGÇG"rc   N)r=   r>   r?   r@   r‡   rA   r$   r   r   re   re   d   s   † õ!Nr   re   c                   ó.   ^ • \ rS rSrS rU 4S jrSrU =r$ )Ú_SVGConverteré‰   c           	      óÔ  • [         R                  " S5      R                  R                  S:  nU(       a  SOSn[	        U S5      (       d:  [        5       U l        [        R                  " U R                  U R                  5        U R                  (       a  U R                  R                  5       Gb;  U R                  b}  U R                  R                  5       bb  [        S U R                  R                  U R                  R                  U R                  R                  /5       H  nUR!                  5         M     0 ["        R$                  ESU R                  R&                  S.En[)        5       n[*        R,                  " U(       a  / SQOSS	/[*        R.                  [*        R.                  UX`R                  R&                  S
9U l
        XpR                  l         U R1                  U5        [9        U R                  R&                  ["        R:                  " S5      5      n	[9        U R                  R&                  ["        R:                  " S5      5      n
 U	R=                  [9        U5      R?                  5       5        U R                  R                  RE                  U(       a  SOS5        U R                  R                  RG                  5          U R1                  U5        ["        RT                  " U	5        [@        RV                  " X¢5        g ! [2         a!  n[5        SUR6                  S   -   5      UeS nAff = f! [4         a    [@        RB                  " X5         Náf = f! [2         a{  nU R                  R                  RI                  S5        [K        U R                  R                  RM                  5       RO                  [P        RR                  " 5       S5      5      UeS nAff = f)Nr+   rX   s   
>s   > Ú_tmpdirÚ )ÚDISPLAYÚINKSCAPE_PROFILE_DIR)r+   z--without-guiú--shellr‘   )rQ   rR   rS   ÚenvÚcwdz/Failed to start Inkscape in interactive mode:

r   s   f.svgs   f.pngs   f.svg --export-png=f.png
s;   file-open:f.svg;export-filename:f.png;export-do;file-close
rm   ),r   r2   r3   ÚmajorÚhasattrr   r�   ÚweakrefÚfinalizerI   rF   ÚpollrP   rQ   rR   rS   rT   r   Úenvironrn   r   rt   ru   rw   ra   r;   rx   ry   r   rZ   Ú
symlink_toÚresolveÚshutilÚcopyfilerz   r{   Úseekr   r/   r~   r   r€   ÚremoveÚmove)rJ   r�   r‚   Úold_inkscaper^   rU   r’   rS   r„   Úinkscape_origÚinkscape_dests              r   r‡   Ú_SVGConverter.__call__Š   sî  € Ü×/Ò/°
Ó;×CÑC×IÑIÈAÑMˆÞ+‘V°ˆ
Ü�t˜Y×'Ñ'Ü-Ó/ˆDŒLô ×Ò˜TŸ\™\¨4¯<©<Ô8Ø—
—
Ø—:‘:—?‘?Ó$Ò0Ø�z‰zÑ%¨$¯*©*¯/©/Ó*;Ñ*GÜ$ T¨D¯J©J×,<Ñ,<Ø,0¯J©J×,=Ñ,=Ø,0¯J©J×,=Ñ,=ð,?ö @�Fð —L‘L–Nñ@ð
Ü—*‘*ð
ð à(,¯©×(9Ñ(9ò
ˆCô #“_ˆFÜ#×)Ò)Þ<HÓ8Ø˜YÐ'Ü —o‘o¬j¯o©oÀfØŸ\™\×.Ñ.ñ	0ˆDŒJð !'�J‰JÔð,Ø× Ñ  Ô,ô ˜TŸ\™\×.Ñ.´·²¸HÓ0EÓFˆÜ˜TŸ\™\×.Ñ.´·²¸HÓ0EÓFˆð	1Ø×$Ñ$¤T¨$£Z×%7Ñ%7Ó%9Ô:ð 	�
‰
×Ñ×ÑÞ-9Ñ)ØKô	Mð 	�
‰
×Ñ×ÑÔ ð		FØ×Ñ˜ZÔ(ô 	�	Š	�-Ô Ü�Š�MÕ(øô; #ó ,ÜØGØ—h‘h˜q‘kñ"ó#à(+ð,ûð,ûô ó 	1Ü�OŠO˜DÖ0ð	1ûô ó 	Fð �J‰J×Ñ×"Ñ" 1Ô%Ü(Ø—
‘
×!Ñ!×&Ñ&Ó(×/Ñ/Ü×-Ò-Ó/°ó<ó=àBEðFûð	FúsC   ÇL É(L< ËM" Ì
L9ÌL4Ì4L9Ì< MÍMÍ"
O'Í,A6O"Ï"O'c                 óz   >• [         TU ]  5         [        U S5      (       a  U R                  R	                  5         g g )Nr�   )ÚsuperrI   r•   r�   Úcleanup)rJ   Ú	__class__s    €r   rI   Ú_SVGConverter.__del__Ñ   s/   ø€ Ü‰‰ÔÜ�4˜×#Ñ#Ø�L‰L× Ñ Õ"ð $r   )rF   r�   )r=   r>   r?   r@   r‡   rI   rA   Ú__classcell__©r¨   s   @r   rŠ   rŠ   ‰   s   ø† òE)÷N#ó #r   rŠ   c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )Ú _SVGWithMatplotlibFontsConverteré×   zÊ
A SVG converter which explicitly adds the fonts shipped by Matplotlib to
Inkspace's font search path, to better support `svg.fonttype = "none"`
(which is in particular used by certain mathtext tests).
c                 óô   >• [        U S5      (       dX  [        5       U l        [        R                  " [
        R                  " S5      [        U R                  R                  S5      5        [        TU ])  X5      $ )Nr�   z	fonts/ttfÚfonts)r•   r   r�   rœ   Úcopytreer   Ú_get_data_pathr   rn   r¦   r‡   )rJ   r�   r‚   r¨   s      €r   r‡   Ú)_SVGWithMatplotlibFontsConverter.__call__Þ   sW   ø€ Ü�t˜Y×'Ñ'Ü-Ó/ˆDŒLÜ�OŠOœE×0Ò0°Ó=Ü  §¡×!2Ñ!2°GÓ<ô>ä‰wÑ Ó+Ð+r   )r�   )r=   r>   r?   r@   Ú__doc__r‡   rA   rª   r«   s   @r   r­   r­   ×   s   ø† ñ÷,ó ,r   r­   c                  ó  •  [         R                  " S5        [        5       =[        S'   [        S'    [         R                  " S5        [        5       [        S'   g ! [         R                   a     N?f = f! [         R                   a     g f = f)Nr)   ÚpdfÚepsr+   Úsvg)r   r2   re   Ú	converterÚExecutableNotFoundErrorrŠ   r$   r   r   Ú_update_converterr»   æ   s�   € ð=Ü× Ò  Ô&ô /;«nÐ<Œ	�%Ñœ9 UÑ+ð+Ü× Ò  Ô,ô )›?Œ	�%Òøô ×&Ñ&ó Ùðûô ×&Ñ&ó Ùðús"   ‚A ³A5 ÁA2Á1A2Á5BÂBc                  ó   • S/[         Q$ )z�
Return the list of file formats that `.compare_images` can compare
on this system.

Returns
-------
list of str
    E.g. ``['png', 'pdf', 'svg', 'eps']``.

Úpng)r¹   r$   r   r   r
   r
   ü   s   € ð Ð”IÐÐr   c                 ó4  • [        U 5      nUR                  5       (       d  [        U S35      eUR                  SS [        ;  a#  SSKnUR                  SUR                   S35        UR                  UR                   SUR                  SS  S3-  nUR                  5       (       a7  UR                  5       R                  UR                  5       R                  :  Ga.  U(       a
  [        5       OSnUbr  [        5         [        U5      nXVUR                  -   -  nUR                  5       (       a7  [        R                  S	U 5        [         R"                  " Xt5        [%        U5      $ [        R                  S
U 5        [        UR                  SS    nUR                  S:X  a2  UR'                  5       n	[(        R*                  " SU	5      (       a  [,        nU" X$5        Ub-  [        R                  SU 5        [         R"                  " UW5        [%        U5      $ )a�  
Convert the named file to png; return the name of the created file.

If *cache* is True, the result of the conversion is cached in
`matplotlib.get_cachedir() + '/test_cache/'`.  The caching is based on a
hash of the exact contents of the input file.  Old cache entries are
automatically deleted as needed to keep the size of the cache capped to
twice the size of all baseline images.
z does not existrX   Nr   zDon't know how to convert z files to pngÚ_z.pngz"For %s: reusing cached conversion.zFor %s: converting to png.r*   z9style="[^"]*font(|-size|-weight|-family|-variant|-style):z"For %s: caching conversion result.)r   r|   rx   r1   r¹   ÚpytestÚskipÚparentÚstemÚstatÚst_mtimer    Ú'_register_conversion_cache_cleaner_oncer9   Ú_logÚdebugrœ   r�   r#   Ú	read_textÚreÚsearchÚ$_svg_with_matplotlib_fonts_converter)
ÚfilenameÚcacher   rÀ   Únewpathr   Ú
hash_valueÚcached_pathÚconvertÚcontentss
             r   rÒ   rÒ   
  s«  € ô �‹>€DØ�;‰;�=‰=Ü˜˜˜oÐ.Ó/Ð/Ø‡{�{�1�2€œiÓ'ÛØ�‰Ð0°·±°¸]ÐKÔLØ�k‰k˜tŸy™y˜k¨¨4¯;©;°q°r¨?Ð*;¸4Ð@Ñ@€Gð �>‰>×Ñ˜wŸ|™|›~×6Ñ6¸¿¹»×9MÑ9MÔMÞ).”OÔ%°Dˆ	àÑ Ü3Ô5Ü& tÓ,ˆJØ#°G·N±NÑ'BÑCˆKØ×!Ñ!×#Ñ#Ü—
‘
Ð?ÀÔJÜ—’ Ô5Ü˜7“|Ð#ä�
‰
Ð/°Ô:Ü˜DŸK™K¨¨˜OÑ,ˆØ�;‰;˜&Ó Ø—~‘~Ó'ˆHô �yŠyð MØ÷ñ ô ?�Ù�ÔàÑ Ü�J‰JÐ;¸XÔFÜ�OŠO˜G [Ô1äˆw‹<Ðr   c                  óX  ^• [        S [        [        R                  5      R                  R                  S5       5       5      n SU -  n[        R                  " [        5       5         [        5       R                  S5       Vs0 s H  o"UR                  5       _M     snm[        S TR                  5        5       5      n[        TU4S jSS9nX1:”  a9  UR                  5       nUTU   R                  -  nUR                  5         X1:”  a  M9  S S S 5        g s  snf ! , (       d  f       g = f)	Nc              3   óV   #   • U  H  nUR                  5       R                  v •  M!     g 7fr"   )rÄ   Úst_size)Ú.0r   s     r   Ú	<genexpr>Ú*_clean_conversion_cache.<locals>.<genexpr>K  s$   é € ð OâMˆDð 	�	‰	‹×ÖÚMùs   ‚')z**/baseline_images/**/*é   Ú*c              3   ó8   #   • U  H  oR                   v •  M     g 7fr"   )rÖ   )r×   rÄ   s     r   rØ   rÙ   U  s   é € ÐFÒ2E¨$ŸžÒ2Eùs   ‚c                 ó"   >• TU    R                   $ r"   )Úst_atime)r   Ú
cache_stats    €r   Ú<lambda>Ú)_clean_conversion_cache.<locals>.<lambda>W  s   ø€ ¨°DÑ)9×)BÒ)Br   T)ÚkeyÚreverse)Úsumr   r   Ú__file__rÂ   Úglobr   Ú
_lock_pathr    rÄ   ÚvaluesÚsortedÚpoprÖ   Úunlink)Úbaseline_images_sizeÚmax_cache_sizer   Ú
cache_sizeÚpaths_by_atimerß   s        @r   Ú_clean_conversion_cacherð   H  s  ø€ ô ñ OäœŸ™Ó&×-Ñ-×2Ñ2Ð3LÔMóOó OÐð
 Ð-Ñ-€Nä	×	Ò	œ/Ó+Õ	,ä*9Ó*;×*@Ñ*@ÀÔ*EóGÚ*E $�$—)‘)“+ÒÑ*EñGˆ
äÑF°*×2CÑ2CÔ2EÓFÓFˆ
ÜØÔBØñˆð Ó)Ø!×%Ñ%Ó'ˆDØ˜* TÑ*×2Ñ2Ñ2ˆJØ�K‰KŒMð Õ)÷ 
-Ð	,ùòG÷ 
-Õ	,ús   Á'DÂDÂA.DÄDÄ
D)c                  ó8   • [         R                  " [        5        g r"   )rG   rH   rð   r$   r   r   rÆ   rÆ   _  s   € ä
‡O‚OÔ+Õ,r   c                 ó  • U SS S:X  az  USS S:X  aq  UR                   u  pEnUR                   u  pxn	U[        US-  US-  -
  5      [        US-  US-  -   5      2[        US-  US-  -
  5      [        US-  US-  -   5      24   nX4$ )Niùÿÿÿéüÿÿÿr·   r¶   rÚ   )Úshaper}   )
Úactual_pathÚactual_imageÚexpected_pathÚexpected_imageÚawÚahÚadÚewÚehÚeds
             r   Úcrop_to_samerÿ   d  s±   € ð �2�bÐ˜UÓ" }°R¸Ð';¸uÓ'DØ!×'Ñ'‰
ˆ�Ø#×)Ñ)‰
ˆ�Ø#¤C¨¨Q©°°a±©Ó$8¼Ø�‰F�R˜!‘V‰Oó:ð %Ü! " q¡&¨2°©6¡/Ó2´3°r¸A±vÀÀQÁ±Ó3GÐGð%Hñ IˆàÐ'Ð'r   c                 óø   • U R                   UR                   :w  a%  [        SU R                    SUR                    35      e[        R                  " X-
  R	                  [
        5      S-  R                  5       5      $ )zJ
Calculate the per-pixel errors, then compute the root mean square error.
ú(Image sizes do not match expected size: ú actual size rÚ   )rô   r   ÚnpÚsqrtÚastypeÚfloatÚmean)rø   rö   s     r   r	   r	   o  sw   € ð ×Ñ˜|×1Ñ1Ó1Ü$Ø6°~×7KÑ7KÐ6Lð MØ'×-Ñ-Ð.ð0ó1ð 	1ô �7Š7�^Ñ2×:Ñ:¼5ÓAÀQÑF×LÑLÓNÓOÐOr   c                 óÐ   • [         R                  " U 5      nUR                  S:w  d  UR                  5       S   S   S:X  a  UR	                  S5      n[
        R                  " U5      $ )NÚRGBAé   r   éÿ   ÚRGB)r   r.   ÚmodeÚ
getextremarÒ   r  Úasarray)r   Úimgs     r   Ú_load_imager    sR   € Ü
�*Š*�TÓ
€Cð ‡x�x�6Ó˜SŸ^™^Ó-¨aÑ0°Ñ3°sÓ:Ø�k‰k˜%Ó ˆÜ�:Š:�c‹?Ðr   c           
      ó  • [         R                  " U5      n[         R                  R                  U5      (       d  [	        SU S35      e[         R
                  " U5      R                  S:X  a  [	        SU S35      e[         R                  " U 5      n [         R                  R                  U 5      (       d  [        SU < S35      eU R                  S5      S   nUS	:w  a  [        US
S9n[        U S
S9n [        U 5      n[        U5      n[        XX5      u  pe[        US5      nUS::  a  [        R                  " XV5      (       a  gUR                  [        R                   5      nUR                  [        R                   5      n[#        XV5      nX‚::  a  g[%        XU5        ['        U[)        U 5      [)        U5      [)        U5      US9n	U(       d5  / SQn
SR+                  U
 Vs/ s H  o»R,                  " S0 U	D6PM     sn5      n	U	$ s  snf )a“  
Compare two "image" files checking differences within a tolerance.

The two given filenames may point to files which are convertible to
PNG via the `.converter` dictionary. The underlying RMS is calculated
with the `.calculate_rms` function.

Parameters
----------
expected : str
    The filename of the expected image.
actual : str
    The filename of the actual image.
tol : float
    The tolerance (a color value difference, where 255 is the
    maximal difference).  The test fails if the average pixel
    difference is greater than this value.
in_decorator : bool
    Determines the output format. If called from image_comparison
    decorator, this should be True. (default=False)

Returns
-------
None or dict or str
    Return *None* if the images are equal within the given tolerance.

    If the images differ, the return value depends on  *in_decorator*.
    If *in_decorator* is true, a dict with the following entries is
    returned:

    - *rms*: The RMS of the image difference.
    - *expected*: The filename of the expected image.
    - *actual*: The filename of the actual image.
    - *diff_image*: The filename of the difference image.
    - *tol*: The comparison tolerance.

    Otherwise, a human-readable multi-line string representation of this
    information is returned.

Examples
--------
::

    img1 = "./baseline/plot.png"
    img2 = "./output/plot.png"
    compare_images(img1, img2, 0.001)

zOutput image z does not exist.r   zOutput image file z
 is empty.zBaseline image Ú.rs   r½   T)rÎ   zfailed-diffN)ÚrmsÚexpectedÚactualÚdiffÚtol)z!Error: Image files did not match.zRMS Value: {rms}zExpected:  
    {expected}zActual:    
    {actual}zDifference:
    {diff}zTolerance: 
    {tol}z
  r$   )r   Úfspathr   r|   Ú	ExceptionrÄ   rÖ   rx   ÚsplitrÒ   r  rÿ   r   r  Úarray_equalr  Úint16r	   Úsave_diff_imageÚdictr#   ÚjoinÚformat)r  r  r  Úin_decoratorÚ	extensionrø   rö   Ú
diff_imager  ÚresultsÚtemplateÚlines               r   r   r   ‰  sÈ  € ôb �YŠY�vÓ€FÜ�7‰7�>‰>˜&×!Ñ!Ü˜-¨ xÐ/?Ð@ÓAÐAÜ	‡w‚wˆvƒ×Ñ !Ó#ÜÐ,¨V¨H°JÐ?Ó@Ð@ô �yŠy˜Ó"€HÜ�7‰7�>‰>˜(×#Ñ#Ü˜¨¡|Ð3CÐDÓEÐEØ—‘˜sÓ# BÑ'€IØ�EÓÜ˜ tÑ,ˆÜ˜8¨4Ñ0ˆô ! Ó*€NÜ˜vÓ&€Lä#/Ø˜hó$8Ñ €Lô $ F¨MÓ:€Jà
ˆaƒxÜ�>Š>˜.×7Ñ7Øð $×*Ñ*¬2¯8©8Ó4€NØ×&Ñ&¤r§x¡xÓ0€Lä
˜Ó
5€Cà
ƒzØä�H jÔ1ä�s¤S¨£]Ü˜f›+¬C°
«OÀñF€Gö ò0ˆð —+‘+Á(ÓKÂ(¸$Ÿ{š{Ñ5¨WÔ5Á(ÑKÓLˆØ€Nùò Ls   Ç$Hc                 ó`  • [        U 5      n[        U5      n[        XX5      u  pC[        R                  " U[        5      n[        R                  " U[        5      nUR
                  UR
                  :w  a%  [        SUR
                   SUR
                   35      e[        R                  " X4-
  5      nUS-  n[        R                  " USS5      R                  [        R                  5      nUR
                  S   S:X  a  SUSS2SS2S	4'   [        R                  " U5      R                  US
S9  g)z«
Parameters
----------
expected : str
    File path of expected image.
actual : str
    File path of actual image.
output : str
    File path to save difference image to.
r  r  é
   r   r  rÚ   é   Nr
  r½   )r!  )r  rÿ   r  Úarrayr  rô   r   ÚabsÚclipr  Úuint8r   Ú	fromarrayÚsave)r  r  Úoutputrø   rö   Úabs_diffs         r   r  r  ñ  s  € ô ! Ó*€NÜ˜vÓ&€LÜ#/Ø˜hó$8Ñ €Lä—X’X˜n¬eÓ4€NÜ—8’8˜L¬%Ó0€LØ×Ñ˜|×1Ñ1Ó1Ü$Ø6°~×7KÑ7KÐ6Lð MØ'×-Ñ-Ð.ð0ó1ð 	1ô �vŠv�nÑ3Ó4€Hð ��N€HÜ�wŠw�x  CÓ(×/Ñ/´·±Ó9€Hà‡~�~�aÑ˜AÓØˆ’’A�q�Ñä	‡O‚O�HÓ×"Ñ" 6°%Ð"Ò8r   )i   )F)4r´   rG   Ú	functoolsr,   Úloggingr   Úpathlibr   rœ   rt   r   Útempfiler   r   r–   rÊ   Únumpyr  ÚPILr   Ú
matplotlibr   r   Úmatplotlib.testing.exceptionsr   Ú	getLoggerr=   rÇ   Ú__all__r   r    r%   r9   r  r;   rC   re   rŠ   r­   r»   r¹   rÌ   r
   rÒ   rð   rÎ   rÆ   rÿ   r	   r  r   r  r$   r   r   Ú<module>r=     s  ðñó Û Û Û Û 	Ý Û Û Û 
ß 6Û Û 	ã Ý ã Ý Ý @à×Ò˜Ó"€â
C€ò$òò"ôô"	�iô 	÷"ñ "ô>"N�:ô "NôJK#�Jô K#ô\, }ô ,ò+ð" €	Ù Ô Ù'GÓ'IÐ $òò;ò|ð. ‡�ñ-ó ð-ò(ò	Pò ôeóP9r   