
    }f              
      @   d dl mZ d dlZddlmZmZmZ ddlmZ ddlm	Z
 ddlmZ ddlmZ dd	lmZ d
ddddddddd	Zd Z G d dej                  Zd Zd Z ej        ej        ee            ej        ej        d            ej        ej        d           dS )    )annotationsN   )Image	ImageFileImagePalette)i8)i16be)i32be)si16be)si32be)1r   )Lr   )Pr   )RGB   )CMYK   )LABr   )	)r   r   )r      )r   r   )   r   )r   r   )r   r   )   r   )r   r   )	   r   c                    | d d         dk    S )Nr   s   8BPS )prefixs    K/var/www/rtfcompare/venv/lib/python3.11/site-packages/PIL/PsdImagePlugin.py_acceptr   /   s    "1":      c                  ,    e Zd ZdZdZdZd Zd Zd ZdS )PsdImageFilePSDzAdobe PhotoshopFc                   | j         j        } |d          }t          |          rt          |d          dk    rd}t	          |          t          |d          }t          |d          }t          |d          }t
          ||f         \  }}||k    rd}t          |          |d	k    r
|dk    rd
}d}|| _        t          |d          t          |d          f| _	        t           |d                    }	|	r1 ||	          }
|dk    r |	dk    rt          j        d|
          | _        g | _        t           |d                    }	|	r"| j                                         |	z   }| j                                         |k     r |d           t           |d                    } |t           |d                              }t!          |          dz  s |d            |t           |d                              }
t!          |
          dz  r |d           | j                            |||
f           |dk    r
|
| j        d<   | j                                         |k     g | _        t           |d                    }	|	r| j                                         |	z   }t           |d                    }	|	rAt)          j        t-          j        | j         |	                    }t1          ||	          | _        | j                             |           t!          | j                  | _        | j        dk    | _        t9          | j         |d| j        z   |          | _        | j         | _        d| _         d| _!        d S )N   r   r   znot a PSD file         znot enough channelsr   RGBA      r   i   zRGB;Lr   i  icc_profile)r   r   )"fpreadr   i16SyntaxErrorMODESOSError_modei32_sizer   rawpalette	resourcestellr   lenappendinfolayersioBytesIOr   
_safe_read
_layerinfoseekn_framesis_animated	_maketilesizetile_fpframe
_min_frame)selfr,   smsgpsd_bitspsd_channelspsd_modemodechannelsrD   dataendidname_layer_datas                  r   _openzPsdImageFile._open<   sQ   w|
 DHHqzz 	#SAYY!^^"Cc"""q"::1bzzq"::(34hl""'C#,,5==\Q..DH
BZZQ+

 4477|| 	?4::Ds{{ts{{+/>>
 4477|| 	4',,..4'C',,..3&&Qa\\tBttAwwKK((D		A DGGGtCQLL))t99q= DGGG%%r4&6777::/3DIm, ',,..3&&  4477|| 	',,..4'CttAww<<D < j)=dgt)L)LMM(d;;GLLDK((=1,
 dgtVdi-?JJ	 7
r   c                    |                      |          sd S 	 | j        |dz
           \  }}}}|| _        || _        || _        | j        | _        ||fS # t          $ r}d}t          |          |d }~ww xY w)Nr   zno such layer)	_seek_checkr;   r1   rE   rG   rF   r+   
IndexErrorEOFError)rI   layerrT   rO   bboxrE   erK   s           r   r@   zPsdImageFile.seek   s    && 	F		'%)[%;"D$dDJDIDJhDG: 	' 	' 	'!C3--Q&	's   9A 
A4A//A4c                    | j         S N)rG   )rI   s    r   r7   zPsdImageFile.tell   s
    zr   N)	__name__
__module____qualname__formatformat_description!_close_exclusive_fp_after_loadingrV   r@   r7   r   r   r   r    r    7   sV        F*(-%R R Rh' ' '     r   r    c           	         g } fd}t           |d                    }|t          |          dz  k     rd}t          |          t          t          |                    D ]}t	           |d                    }t	           |d                    }t	           |d                    }	t	           |d                    }
g }t           |d                    }|dk    r_                     |dz  dz   t          j                   t           |d                    }                     |t          j                   t          |          D ]K}t           |d                    }|dk    rd	}nd
|         }|
                    |            |d           L|                                 |dgk    rd}n|g dk    rd}n|g dk    rd
}nd } |d           d}t           |d                    }|r܉                                 |z   }t           |d                    }|r#                     |dz
  t          j                   t           |d                    }|r                      |t          j                   t           |d                    }|r ||                              dd          }                     |           |
                    |||||
|	ff           t          |          D ]B\  }\  }}}g }|D ]+}t!           ||d          }|r|                    |           ,||||f||<   C|S )Nc                .    t          j        |           S r_   )r   r>   )rD   r+   s    r   r,   z_layerinfo.<locals>.read   s    #B---r   r      z4Layer block too short for number of layers requestedr      r%   i  Ar'   Rr   )BGrk   r   )rj   rl   rm   rk       r   zlatin-1replace)si16absr.   rangesi32r-   r@   r<   SEEK_CURr2   r9   sortr7   r   decode	enumeraterC   extend)r+   ct_bytesr;   r,   ctrK   _y0x0y1x1rO   ct_typesrD   typemrT   data_endlengthir\   rE   ts   `                      r   r?   r?      s   F. . . . . 
dd1ggB 3r77R<  D#3r77^^ <6 <6$$q'']]$$q'']]$$q'']]$$q'']] ttAww<<a<<GGHqL2%r{333ttAww<<DGGD"+&&&x 		 		AttAww<<Du}}4LKKNNNDGGGG 			C5==DD___$$DD)))))DDD 	R4477|| 	wwyy4'Ha\\F 2R[111a\\F -,,,Q[[F A tF||**9i@@GGHtTBB#345555 "+6!2!2 + +D$ 	 	A"aq))A A$d*q		Mr   c                   d }| j         }t           |d                    }|d         |d         z
  }|d         |d         z
  }|                                 }	|dk    rIg }t          |          D ]6}
||
         }|dk    r|dz  }|                    d||	|f           |	||z  z   }	7n|dk    rd}g } |||z  dz            }|                                 }	t          |          D ]X}
||
         }|dk    r|dz  }|                    d||	|f           t          |          D ]}|	t          ||          z   }	|dz  }Y|                     |	           |	dz  r |d           |S )	Nr   r   r   r   r   z;Ir4   packbits)r,   r-   r7   rs   r9   r@   )filerO   r\   rP   rE   r,   compressionxsizeysizeoffsetchannelr[   r   	bytecountys                  r   rC   rC      s   D9Ddd1gg,,KGd1gEGd1gEYY[[Fa X 	, 	,GMEv~~KKfe4555eem+FF	, 
		 DE)A-..	X 	 	GMEv~~KKT659:::5\\  #i"3"33Q 	IIfz QKr   z.psdzimage/vnd.adobe.photoshop)
__future__r   r<   rn   r   r   r   _binaryr   r	   r-   r
   r2   r   rq   r   rt   r/   r   r    r?   rC   register_openrc   register_extensionregister_mimer   r   r   <module>r      s~  $ # " " " " " 				 , , , , , , , , , ,       ! ! ! ! ! ! ! ! ! ! ! ! # # # # # # # # # # # # 	 	$! ! !k k k k k9& k k k\U U Up+ + +d  L'w ? ? ?  ,f 5 5 5  L')D E E E E Er   