Ë
    ÷GìjX  ã                   óP  — 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 d dlZd dlm	Z
 ddlmZ ddlmZ ddlmZ  ej"                  dd	¬
«       ej$                  ddd ej&                  e«      ddd¬«       ej$                  ddddd¬«       ej$                  dddedd¬«       ej$                  dddedd¬«       ej$                  dddedd ¬«       ej$                  d!d"ddd#¬«       ej$                  d$d%ddd&¬«       ej$                  d'd(d)eeeefd*d+¬,«       ej$                  d-d.e¬/«       ej$                  d0d1ed2¬3«       ej,                  d4e¬/«       ej,                  d5e¬/«      d6ed7ed4ed5ed8ed9dfd:„«       «       «       «       «       «       «       «       «       «       «       «       «       Zy);é    N)ÚIO)ÚImageé   )Úremove)Únew_session)Úsessions_namesÚbzfor a byte stream as input)ÚnameÚhelpz-mz--modelÚu2netTz
model name)ÚdefaultÚtypeÚshow_defaultÚshow_choicesr   z-az--alpha-mattingzuse alpha matting)Úis_flagr   r   z-afz$--alpha-matting-foreground-thresholdéð   ztrimap fg threshold)r   r   r   r   z-abz$--alpha-matting-background-thresholdé
   ztrimap bg thresholdz-aez--alpha-matting-erode-sizez
erode sizez-omz--only-maskzoutput only the maskz-ppmz--post-process-maskzpost process the maskz-bgcz	--bgcolor)r   r   r   r   é   zABackground color (R G B A) to replace the removed background with)r   r   Únargsr   z-xz--extras)r   z-oz--output_specifierzCprintf-style specifier for output filenames (e.g. 'output-%d.png')))r   r   Úimage_widthÚimage_heightÚmodelÚextrasÚoutput_specifierÚreturnc                 ó8  ‡‡‡‡‡‡	‡
‡— 	 ‰j                  t        j                  |«      «       t	        | fi ‰¤ŽŠ‰‰z  dz  Š‰r�t
        j                  j                  t
        j                  j                  t
        j                  j                  ‰«      «      «      }t
        j                  j                  |«      st        j                  |d¬«       dt        dt        fd„Š
d„ Š	ˆˆ	ˆˆˆ
ˆˆˆfd„}t        j                   |«       «       y	# t        $ r Y Œêw xY w)
a¾  
    Command-line interface for processing images by removing the background using a specified model and generating a mask.

    This CLI command takes several options and arguments to configure the background removal process and save the processed images.

    Parameters:
        model (str): The name of the model to use for background removal.
        extras (str): Additional options in JSON format that can be passed to customize the background removal process.
        image_width (int): The width of the input images in pixels.
        image_height (int): The height of the input images in pixels.
        output_specifier (str): A printf-style specifier for the output filenames. If specified, the processed images will be saved to the specified output directory with filenames generated using the specifier.
        **kwargs: Additional keyword arguments that can be used to customize the background removal process.

    Returns:
        None
    é   T)Úexist_okÚimgr   c                 óp   — t        j                  «       }| j                  |d¬«       |j                  «       S )NÚPNG©Úformat)ÚioÚBytesIOÚsaveÚgetvalue)r   Úbuffs     ú\C:\Users\Stabi\Downloads\virtual-tryon(1)\venv\Lib\site-packages\rembg/commands/b_command.pyÚimg_to_byte_arrayz$b_command.<locals>.img_to_byte_array‰   s)   € Ü�z‰z‹|ˆØ�‰�˜eˆÔ$Ø�}‰}‹Ðó    c               “   ó¢  ‡K  — t        j                  «       } t        j                  «       }t        j                  |«      Š| j	                  ˆfd„t
        j                  «      ƒ d {  –—†  | j                  t         j                  j                  t
        j                  «      ƒ d {  –—† \  }}t        j                  |||| «      }||fS 7 Œc7 Œ%­w)Nc                  ó   •— ‰ S )N© )Úprotocols   €r)   Ú<lambda>z9b_command.<locals>.connect_stdin_stdout.<locals>.<lambda>“   s   ø€ ©Xr+   )ÚasyncioÚget_event_loopÚStreamReaderÚStreamReaderProtocolÚconnect_read_pipeÚsysÚstdinÚconnect_write_pipeÚstreamsÚFlowControlMixinÚstdoutÚStreamWriter)ÚloopÚreaderÚw_transportÚ
w_protocolÚwriterr/   s        @r)   Úconnect_stdin_stdoutz'b_command.<locals>.connect_stdin_stdoutŽ   s©   øè ø€ Ü×%Ñ%Ó'ˆÜ×%Ñ%Ó'ˆÜ×/Ñ/°Ó7ˆà×$Ñ$Ó%5´s·y±yÓA×AÐAØ(,×(?Ñ(?Ü�O‰O×,Ñ,¬c¯j©jó)
÷ #
Ñˆ�Zô ×%Ñ% k°:¸vÀtÓLˆØ�vˆ~Ðð 	Bøð#
ús$   ƒA$CÁ'CÁ(?CÂ'CÂ($CÃCc               “   ód  •K  —  ‰«       ƒ d {  –—† \  } }d}	 	 | j                  ‰«      ƒ d {  –—† }|sy t        j                  d‰	‰f|«      }t        |fd‰i‰¤Ž}‰r|j	                  ‰|z  d¬«       n|j                   ‰
|«      «       |dz  }Œz7 Œ„7 Œf# t        j                  $ r Y y w xY w­w)Nr   ÚRGBÚsessionr!   r"   é   )ÚreadexactlyÚPILImageÚ	frombytesr   r&   Úwriter1   ÚIncompleteReadError)r>   rA   ÚidxÚ	img_bytesr   ÚoutputÚbytes_per_imgrB   r   r   r*   Úkwargsr   rE   s         €€€€€€€€r)   Úmainzb_command.<locals>.main›   sÇ   øè ø€ Ù3Ó5×5‰ˆ�àˆØðØ"(×"4Ñ"4°]Ó"C×C�	Ù Øä×(Ñ(¨°¸lÐ0KÈYÓW�Ü Ñ?¨WÐ?¸Ñ?�á#Ø—K‘KÐ!1°CÑ!7À�KÕGà—L‘LÑ!2°6Ó!:Ô;à�q‘�ð ð 6øð
 Dùô ×.Ñ.ò ÙðüsM   ƒB0ŽB�
B0šB ®B¯B µB0¶AB ÂB0ÂB ÂB-Â*B0Â,B-Â-B0N)ÚupdateÚjsonÚloadsÚ	Exceptionr   ÚosÚpathÚdirnameÚabspathÚ
expanduserÚisdirÚmakedirsrH   Úbytesr1   Úrun)r   r   r   r   r   rP   Ú
output_dirrQ   rO   rB   r*   rE   s     ````  @@@@r)   Ú	b_commandr`      sÚ   ÿ€ ðRØ�‰”d—j‘j Ó(Ô)ô ˜%Ñ* 6Ñ*€GØ ,Ñ.°Ñ2€MáÜ—W‘W—_‘_Ü�G‰G�O‰OœBŸG™G×.Ñ.Ð/?Ó@ÓAó
ˆ
ô �w‰w�}‰}˜ZÔ(Ü�K‰K˜
¨TÕ2ðœxð ¬Eó ò
÷ó ô, ‡K�K‘“Õøôm ò Ùðús   Š$D Ä	DÄD)r1   r$   rS   rV   r6   Útypingr   ÚclickÚ	PIL.Imager   rH   Úbgr   Úsession_factoryr   Úsessionsr   ÚcommandÚoptionÚChoiceÚintÚstrÚargumentr`   r.   r+   r)   Ú<module>rm      s@  ðÛ Û 	Û Û 	Û 
Ý ã Ý 'å Ý )Ý %ð €‡�Ø	Ø	%ôð €‡�ØØØØ	ˆ�‰�nÓ	%ØØØ	ôð €‡�ØØØØØ	ôð €‡�Ø	Ø*ØØ	ØØ	ôð €‡�Ø	Ø*ØØ	ØØ	ôð €‡�Ø	Ø ØØ	ØØ	ôð €‡�Ø	ØØØØ	ôð €‡�Ø
ØØØØ	 ôð €‡�Ø
ØØØ
ˆs�C˜Ð	Ø
Ø	Lôð €‡�ˆd�J SÔ)Ø€‡�ØØØ	Ø	Nô	ð €‡�ØØ	ôð €‡�ØØ	ôðPØðPàðPð ðPð ð	Pð
 ðPð 
òPó	ó	óó *óóóóóóóóó	ñbPr+   