o
    Wf                     @  s   d dl mZ d dlZd dlm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
ddddddZG dd dejZdddddddZd&d"d#Zeeje eeje eejg d$ eejd% dS )'    )annotationsN)IO   )Image	ImageFileImagePalette)i16le)o8)o16leP1LLAzBGR;5BGRBGRA))r      )   r   )r   r   )r      )   r   )r      )r       c                   @  s(   e Zd ZdZdZd
ddZd
ddZd	S )TgaImageFileTGATargareturnNonec                 C  s  | j d usJ | j d}|d }|d }|d }|d }|d }t|dt|df| _|d	vsB| jd dksB| jd dksB|d
vrHd}t||dv r_d| _|dkrWd| _n)|dkr^d| _n!|dv rk|rgdnd| _n|dv rzd| _|dkryd| _nd}t||d@ }|dv | _|dv rd}n|dv rd}nd}t||| jd< |d@ rd| jd < |r| j || jd!< |rt|d"t|d#|d$ }	}
}|dkrt	
d%d&|	 | j d|
  | _n3|d'krt	
d(d)|	 | j d"|
  | _n|dkrt	
d*d+|	 | j d,|
  | _nd-}t|z5t|d$@ |f }|d@ r4dd.| j | j  |||ffg| _W d S d/d.| j | j  |d|ffg| _W d S  tyR   Y d S w )0N   r   r   r   r            )r   r   )r   r   r   r   r   znot a TGA file)r      r   r   r   )r   	   r   )r   
   RGBr   RGBAzunknown TGA mode0   )r   r%   )r   r%   )r   r   zunknown TGA orientationorientationr   tga_rlecompression
id_sectionr         zBGR;15s     r   r   s      r   s          zunknown TGA map depthr   r   raw)fpreadi16_sizesizeSyntaxError_mode_flip_horizontallyinfor   r/   paletteMODEStelltileKeyError)selfsid_lencolormaptype	imagetypedepthflagsmsgr'   startr4   mapdepthrawmode rI   z/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_CUSTOMER_APIS/venv/lib/python3.10/site-packages/PIL/TgaImagePlugin.py_open5   s   


 

zTgaImageFile._openc                 C  s.   | j r| jd us
J | jtjj| _d S d S )N)r7   im	transposer   	TransposeFLIP_LEFT_RIGHT)r>   rI   rI   rJ   load_end   s   zTgaImageFile.load_endN)r   r   )__name__
__module____qualname__formatformat_descriptionrK   rP   rI   rI   rI   rJ   r   1   s
    
kr   )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$   rL   Image.Imager0   	IO[bytes]filenamestrr   r   c              
   C  s*  zt | j \}}}}W n ty# } zd| j d}t||d }~ww d| jv r/| jd }	n| jd| jd}
|
dk}	|	rD|d7 }| jd| jdd}t|}|d	kred	}|d d	 }t	d
 |r| j
d usnJ | j
dd}t|d d}}nd\}}| jdv rd}nd}| jd| jdd}|dkr|dB }|t|t| t| td t| t| td td t| jd  t| jd  t| t|  |r|| |r|| |	rt| |dd| j d||ffg nt| |dd| j d|d|ffg |d d S )Nzcannot write mode z as TGArler)   r(   r   r*       z-id_section has been trimmed to 255 charactersr#   r   r   r   r.   )r   r$   r   r'   r&   r   r   r/   s           TRUEVISION-XFILE. )SAVEmoder=   OSErrorencoderinfogetr8   lenwarningswarnrL   
getpalettewriter	   o16r4   r   _save)rL   r0   rX   rH   bitsrA   rB   erE   rZ   r)   r*   r@   r9   colormaplengthcolormapentryrD   r'   rI   rI   rJ   rh      s   



	


rh   )z.tgaz.icbz.vdaz.vstzimage/x-tga)rL   rV   r0   rW   rX   rY   r   r   )
__future__r   rc   typingr   r[   r   r   r   _binaryr   r2   r	   r
   rg   r:   r   r]   rh   register_openrT   register_saveregister_extensionsregister_mimerI   rI   rI   rJ   <module>   s8   	{

M