
    }f                    f   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ej                  ZdddddddZd%d"Z ej        ej        e            ej        ej        e            ej        ej        g d#            ej        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                  &    e Zd ZdZdZddZddZdS )	TgaImageFileTGATargareturnNonec                   | j         J | j                             d          }|d         }|d         }|d         }|d         }|d         }t          |d          t          |d          f| _        |d	vs&| j        d         dk    s| j        d         dk    s|d
vrd}t          |          |dv r#d| _        |dk    rd| _        nH|dk    rd| _        n:|dv r|rdnd| _        n*|dv rd| _        |dk    rd| _        nd}t          |          |dz  }|dv | _        |dv rd}n|dv rd}nd}t          |          || j        d<   |dz  r
d| j        d <   |r"| j                             |          | j        d!<   |rt          |d"          t          |d#          |d$         }}
}	|dk    r<t          j
        d%d&|	z  | j                             d|
z            z             | _        n|d'k    r<t          j
        d(d)|	z  | j                             d"|
z            z             | _        nS|dk    r<t          j
        d*d+|	z  | j                             d,|
z            z             | _        nd-}t          |          	 t          |d$z  |f         }|dz  r0dd.| j        z   | j                                         |||ffg| _        d S d/d.| j        z   | j                                         |d|ffg| _        d S # t          $ r Y d S w xY 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   r2   paletteMODEStelltileKeyError)selfsid_lencolormaptype	imagetypedepthflagsmsgr*   startr7   mapdepthrawmodes                K/var/www/rtfcompare/venv/lib/python3.11/site-packages/PIL/TgaImagePlugin.py_openzTgaImageFile._open5   s   w"""GLL1taD	""BZZQ+
 &&y|q  y|q  ..."Cc""" DJzz 

"!
&   ,5#DJJ'!!DJ{{#
$Cc""" dl"-"=,&&KKI%%KK+Cc"""#.	- q= 	1'0DIm$ 	;&*gll6&:&:DIl# 	'$'1IIs1ayy!A$4E2~~+/i%/$',,q4x2H2HH    R+/9u,tw||AH/E/EE    R+/I-QX0F0FF    .!#&&&	Y]E23G1}  "* +u5				 * ![1				  	 	 	DD	s   9AK0  .K0 0
K>=K>c                    | j         r9| j        J | j                            t          j        j                  | _        d S d S )N)r:   im	transposer   	TransposeFLIP_LEFT_RIGHT)rA   s    rL   load_endzTgaImageFile.load_end   sH    " 	I7&&&g''(GHHDGGG	I 	I    N)r   r   )__name__
__module____qualname__formatformat_descriptionrM   rS    rT   rL   r   r   1   sR        F i i i iVI I I I I IrT   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&   r'   rO   Image.Imager3   	IO[bytes]filenamestrr   r   c           
        	 t           | j                 \  }}}}n-# t          $ r }d| j         d}t          |          |d }~ww xY wd| j        v r| j        d         }	n9| j                            d| j                            d                    }
|
dk    }	|	r|dz  }| j                            d| j                            dd                    }t          |          }|d	k    r d	}|d d	         }t          j	        d
           |r9| j
        J | j
                            dd          }t          |          dz  d}}nd\  }}| j        dv rd}nd}| j                            d| j                            dd                    }|dk    r|dz  }|                    t          |          t          |          z   t          |          z   t          d          z   t          |          z   t          |          z   t          d          z   t          d          z   t          | j        d                   z   t          | j        d                   z   t          |          z   t          |          z              |r|                    |           |r|                    |           |	r&t!          j        | |dd| j        z   d||ffg           n&t!          j        | |dd| j        z   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   r1   )r   r'   r   r*   r)   r   r   r2   s           TRUEVISION-XFILE. )SAVEmoder@   OSErrorencoderinfogetr;   lenwarningswarnrO   
getpalettewriter
   o16r7   r   _save)rO   r3   r]   rK   bitsrD   rE   erH   r`   r,   r-   rC   r<   colormaplengthcolormapentryrG   r*   s                     rL   rn   rn      s\   "15bg.|YY " " "327333cll!" nU#n((M8R8RSSY&
 Q	##L"'++lB2O2OPPJ__F||%
EFFF -u   %""5%00(+G(92(,%	w.  .$$]BGKKr4R4RSSKQHH
6


\

	
Y--	 a&&	 n

		
 ]

	 a&&	 a&&	 bgaj//	 bgaj//		 T((
	 U))	    
 

 
i"'!11w6LMN	
 	
 	
 	
 	eVbg-q7A{2KLM	
 	
 	

 HH9:::::s    
A?A)z.tgaz.icbz.vdaz.vstzimage/x-tga)rO   r[   r3   r\   r]   r^   r   r   )
__future__r   ri   typingr   ra   r   r   r   _binaryr	   r5   r
   r   rm   r=   r   rc   rn   register_openrX   register_saveregister_extensionsregister_mimerZ   rT   rL   <module>rz      s  $ # " " " " "        , , , , , , , , , , ! ! ! ! ! !       ! ! ! ! ! ! 		 		 rI rI rI rI rI9& rI rI rIv 
	
	 E; E; E; E;Z  L' 6 6 6  L' / / /  ,-/O/O/O P P P  L' 7 7 7 7 7rT   