
    th:                     &   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 ddl	m
Z ddlmZ  ej        d          Z ej        d          ZdZej                            d          rd dlZd	D ]Z ej        e          eZ nd
Zd ZddZ G d d          Zd Z G d dej                  ZddZ ej        ej        ee            ej        ej        e            ej         ej        ddg            ej!        ej        d           dS )    N   )Image	ImageFile)i32le)	deprecatez^%%([^:]*):[ \t]*(.*)[ \t]*$z^%[%!\w]([^:]*)[ \t]*$win)gswin32cgswin64cgsFc                      t           rdS t          j                            d          s5	 t	          j        ddgt          j                   dS # t          $ r Y nw xY wdS )NTr   r   z	--version)stdoutF)gs_windows_binarysysplatform
startswith
subprocess
check_callDEVNULLOSError     f/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/PIL/EpsImagePlugin.pyhas_ghostscriptr   4   sv     t<""5)) 	!4"5j>PQQQQ4 	 	 	D	 5s   "A 
AAc                 R   | d         \  }} }}|\  }}	t          |          pd}|d         |z  |d         |z  f}d|d         z  |	d         |	d         z
  z  d|d         z  |	d         |	d         z
  z  f}
t          j                    \  }}t          j        |           d}t          |d          r,t          j                            |j                  r|j        }nt          j                    \  }}t          j        |           |}t          |d          5 }|
                    dt          j                   |                                }|
                    d           |}|dk    rS|                    t          |d	                    }|sn-|t!          |          z  }|                    |           |dk    Sddd           n# 1 swxY w Y   |rd
nd}ddd|z  d|
z  dddd| d| d|	d           d|	d           dd|ddg}t$          ^t$          sM	 t          j        |           |rt          j        |           n# t(          $ r Y nw xY wd}t)          |          t$          |d<   	 d}t*          j                            d          r-t1          j                    }|xj        t0          j        z  c_        t1          j        ||           t;          j	        |          }|                                 	 t          j        |           |rt          j        |           nQ# t(          $ r Y nEw xY w# 	 t          j        |           |rt          j        |           w w # t(          $ r Y w w xY wxY w|j                                         }|                                 |S )z!Render an image using Ghostscriptr   r   g      R@      Nnamewbi  pngalphappmrawr   z-qz-g%dx%dz-r%fx%fz-dBATCHz	-dNOPAUSEz-dSAFERz	-sDEVICE=z-sOutputFile=z-c z
 translatez-fshowpagez%Unable to locate Ghostscript on pathsr   )startupinfo)!inttempfilemkstemposclosehasattrpathexistsr   openseekioSEEK_ENDtellreadminlenwriter   unlinkr   r   r   r   r   STARTUPINFOdwFlagsSTARTF_USESHOWWINDOWr   r   loadimcopy)tilesizefpscaletransparencydecoderoffsetdatalengthbboxresout_fdoutfileinfile_tempinfilein_fdffsize
lengthfilesdevicecommandmsgr#   out_imr:   s                             r   GhostscriptrT   A   sA    #'q'GT64LFD JJO!E GeOT!Wu_-D 	tAw$q'DG+,tAw$q'DG+,C
 &((OFGHVKr6 rw~~bg66 %-//{

 +t$$ 	GGAr{###GGIIE GGAJJJJq..GGC
J7788 c!ff$



 q..	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 (5ZZXF 	DCF!!!G8**tAwh***#G( $  			'""" +Ik***    :C#,,&
<""5)) 	C$022K:#BBg;????G$$	Ig '	+&&& 	 	 	D			Ig '	+&&&&' 	 	 	D	 
		B
LLNNNIsh   B%G		GG*I 
II1BL9 >*L) )
L65L69M7;*M'%M7'
M41M73M44M7c                   2    e Zd ZdZd Zej        fdZd ZdS )PSFilez
    Wrapper for bytesio object that treats either CR or LF as end of line.
    This class is no longer used internally, but kept for backwards compatibility.
    c                 F    t          ddd           || _        d | _        d S )NrV      zSIf you need the functionality of this class you will need to implement it yourself.)action)r   r>   char)selfr>   s     r   __init__zPSFile.__init__   s8    6	
 	
 	
 	
 			r   c                 J    d | _         | j                            ||           d S N)rZ   r>   r-   )r[   rB   whences      r   r-   zPSFile.seek   s%    	VV$$$$$r   c                    | j         pdg}d | _         | j                            d          }|dvrQt          |          rB|                    |           | j                            d          }|dvrt          |          B| j                            d          | _         | j         dv rd | _         d                    |                              d          S )Nr   r      
latin-1)rZ   r>   r1   r3   appendjoindecode)r[   rO   cs      r   readlinezPSFile.readline   s    Y#	GLLOOSVVHHQKKKQA SVV GLLOO	9DIxx{{!!),,,r   N)	__name__
__module____qualname____doc__r\   r.   SEEK_SETr-   rg   r   r   r   rV   rV      sW         
   #%+ % % % %- - - - -r   rV   c                 j    | d d         dk    p%t          |           dk    ot          |           dk    S )N      %!PS   P )r3   i32)prefixs    r   _acceptrs      s5    "1": TS[[A%5%S#f++:STr   c                   B    e Zd ZdZdZdZdddddZd	 Zd
 ZddZ	d Z
dS )EpsImageFilez.EPS File Parser for the Python Imaging LibraryEPSzEncapsulated PostscriptLLABRGBCMYK)r   r   r   rn   c                                            j                  \  }} j                            |           d _        d  _        t          d          }t          |          }d}d} fd}	  j                            d          }|dk    r	|dk    rnn]|dv r|dk    r5nQ|dk    r:|d         t          d	          k    rd
}	t          |	          |r |             d}d}|d         ||<   |dz  }|r|d         t          d	          k    s|d d         dk    r |             d}t          |d |         d          }
	 t                              |
          }n)# t          j        $ r}d
}	t          |	          |d }~ww xY w|r|                    dd          \  }}| j        |<   |dk    ro	 d |                                D             }|d         |d         z
  |d         |d         z
  f _        dd j        z   |||ffg _        n# t&          $ r Y n
w xY wnt(                              |
          }|rA|                    d          }|d d         dk    r|dd           j        d<   nd j        |<   n|
d         d	k    rnd}	t+          |	          |d d         dk    r{|d|                             d d          }d |d d         D             \  }}}}|dk    rd _        n+|dk    r$	  j        |          _        n# t.          $ r Y nw xY wn||f _        d S d} |              j        sd }	t+          |	          d S )!Nry      r   Tc                  p    dj         vrd} t          |           dj         vrd} t          |           d S )NPS-Adobez'EPS header missing "%!PS-Adobe" commentBoundingBoxz*EPS header missing "%%BoundingBox" comment)infoSyntaxError)rR   r[   s    r   check_required_header_commentsz:EpsImageFile._open.<locals>.check_required_header_comments   sK    **?!#&&&DI--B!#&&& .-r   r   r   ra   %not an EPS fileF   s   %%EndCommentsrb   r   r   c                 F    g | ]}t          t          |                    S r   )r$   float).0is     r   
<listcomp>z&EpsImageFile._open.<locals>.<listcomp>1  s$    "D"D"DQ3uQxx=="D"D"Dr   r   epsr   r      r~   	    zbad EPS headerrX   s   %ImageData:   c                 ,    g | ]}t          |          S r   )r$   )r   values     r   r   z&EpsImageFile._open.<locals>.<listcomp>V  s+     5 5 5#(CJJ5 5 5r   rn   1z!cannot determine EPS bounding box)_find_offsetr>   r-   mode_size	bytearray
memoryviewr1   ordr   strsplitmatchreerrorgroupr   r=   r<   	Exceptionfieldr   mode_map
ValueError)r[   rD   rB   byte_arrbytes_mv
bytes_readreading_commentsr   byterR   rO   mekvboximage_data_valuescolumnsrows	bit_depthmode_ids   `                    r   _openzEpsImageFile._open   sC   ,,TW55 	V	
S>>h''
	' 	' 	' 	' 	'q	7<<??Ds{{?? # ?? #
 $$  {c#hh../)#...+ 5::<<</4, &'
'+Aw$a
 O A;#c((**hssm?O.O.O22444',$*-y992AAAx 2 2 2+C%c**12  +771a==DAq#$DIaLM))
! #E"D!''))"D"D"DC),Q#a&#a&3q6/)IDJ!&(:FVSM R)DII  ) ! ! ! D! * AA +GGAJJRaR5J..45abbEDIj11+-DIaLL1 .%cll*#2#.00 %-R
]$;$A$A$$J$J!5 5,=bqb,A5 5 51y' >> #DII!^^$(M'$:		%    $d]
Jcq	f 	'&(((z 	5C#,,	 	s=   E   F/FF5AH 
H H :L 
LLc                 `   |                     d          }|dk    r7|                    dt          j                   |                                }d}nYt          |          dk    r5|                     d          }t          |          }t          |d          }nd}t          |          ||fS )Nrn   ro   r   rp   r   r   )r1   r-   r.   r/   r0   rq   r   )r[   r>   rO   rD   rB   rR   s         r   r   zEpsImageFile._find_offseto  s    GGAJJ<<GGAr{###WWYYFFFVVz!! 

AVVFAYYFF#Cc"""v~r   r   Fc                     | j         rPt          | j         | j        | j        ||          | _        | j        j        | _        | j        j        | _        g | _         t          j                            |           S r^   )	r<   rT   r=   r>   r:   r   r   r   r9   )r[   r?   r@   s      r   r9   zEpsImageFile.load  s\    9 	!$)TYUUDGDIDJDI{%%%r   c                     d S r^   r   )r[   argskwargss      r   	load_seekzEpsImageFile.load_seek  s	     	r   Nr   F)rh   ri   rj   rk   formatformat_descriptionr   r   r   r9   r   r   r   r   ru   ru      s{        88F25Uv66HM M M^  .& & & &    r   ru   c                 J   |                                   | j        dk    rd}n-| j        dk    rd}n| j        dk    rd}nd}t          |          |r|                    d           |                    d	           |                    d
| j        z             |                    d           |                    d           |                    d           |                    d| j        z             |                    d|z             |                    d           |                    d           |                    d| j        d         |d         z  z             |                    d| j        z             |                    d| j        z             |                    d| j        d         | j        d         | j        d         fz             |                    d           |                    |d         dz              t          |d          r|                                 t          j        | |dd| j        z   ddfg           |                    d           |                    d            t          |d          r|                                 dS dS )!z*EPS Writer for the Python Imaging Library.rw   )r   r   s   imagery   )r   r   s   false 3 colorimagerz   )r   rn   s   false 4 colorimagezimage mode is not supporteds   %!PS-Adobe-3.0 EPSF-3.0
s   %%Creator: PIL 0.1 EpsEncode
s   %%%%BoundingBox: 0 0 %d %d
s   %%Pages: 1
s   %%EndComments
s   %%Page: 1 1
s   %%ImageData: %d %d s   %d %d 0 1 1 "%s"
s   gsave
s   10 dict begin
s   /buf %d string def
r   r   s   %d %d scale
s   %d %d 8
s   [%d 0 0 -%d 0 %d]
s+   { currentfile buf readhexstring pop } bind
r      
flushr   r   Ns   
%%%%EndBinary
s   grestore end
)	r9   r   r   r4   r=   r)   r   r   _save)r:   r>   filenamer   operatorrR   s         r   r   r     s    GGIII 
w#~~#	E		0	F		0+oo
 
3
-...
2333
027:;;;
!!!
#$$$
!"""
'"'1222
&1222 HHZHH   HH$
Xa[(@ABBBHH'(((HH\BG#$$$HH#rwqz271:rwqz&JJKKKHH<===HHXa[5 !!!r7 



OBeVbg%5q$?@AAAHH!"""HHr7 





 r   z.psz.epszapplication/postscriptr   )r   )"r.   r'   r   r   r   r%   r   r   r   _binaryr   rq   
_deprecater   compiler   r   r   r   r   shutilbinarywhichr   rT   rV   rs   ru   r   register_openr   register_saveregister_extensionsregister_mimer   r   r   <module>r      s  . 
			 				 				     



          ! ! ! ! ! ! ! ! ! ! ! !
 	
233
,-- <5!! "MMM0 " "6<+ &E , "
 
 
f f f fR"- "- "- "- "- "- "- "-JU U Uz z z z z9& z z z@. . . .h  L'w ? ? ?  L' / / /  ,-v ? ? ?  L')A B B B B Br   