o
    6>g                  
   @  s  U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	 ddl
mZ ddlmZ ered dlZd dlZddl
mZ d	ed
< e	ejjejjf Ze	ejjejjf Ze	ejjejjf Ze	ejjejjf Zded< ddgddggZejdd dd eD ]H\ZZz3ded< edkrd dlmZmZ d dlmZmZmZ nedkrd dl mZmZ d dl!mZmZmZ W n e"e#fy   Y q|w dZ$eZ% ndZ$dZ%d;d<d!d"Z&d=d&d'Z'd>d)d*Z(d?d/d0Z)d@d3d4Z*e$rG d5d6 d6eZ+dAd7d8Z,dBd9d:Z-dS )C    )annotationsN)BytesIO)TYPE_CHECKINGAnyCallableUnion   )Image)is_path)	ImageFiletypeQBufferz
str | None
qt_version6PyQt6side6PySide6c                 C  s   | d t jv S )Nr   )sysmodules)version r   >/var/www/html/venv/lib/python3.10/site-packages/PIL/ImageQt.py<lambda>.   s    r   T)keyreversez#Callable[[int, int, int, int], int]qRgba)r   	QIODevice)QImageQPixmapr   F   rintgbareturnc                 C  s   t | |||d@ S )zA(Internal) Turns an RGB color into a Qt compatible color integer.l    )r   )r    r"   r#   r$   r   r   r   rgbB   s   r&   imQImage | QPixmapImageFile.ImageFilec                 C  s   t  }tdkrzttd}W n ty   ttd}Y nw t}|t|d |  r2| |d n| |d t }|	|
  |  |d t|S )z1
    :param im: QImage or PIL ImageQt object
    r   OpenModeFlagOpenMode	ReadWritepngppmr   )r   r   getattrr   AttributeErroropenhasAlphaChannelsaver   writedatacloseseekr	   )r'   bufferqt_openmoder#   r   r   r   
fromqimageI   s"   

r:   r   c                 C     t | S N)r:   r'   r   r   r   fromqpixmapf      r>   byteswidthmodestrc                   sv   ddddd| }|| }t |d\}}||rdnd  d s% S  fddtt  D }d	|S )
zE
    converts each scanline of data from 8 bit to 32 bit aligned
    r         )1LPI;16r      c                   s,   g | ]} | |d    d  qS )r       r   .0ir@   bytes_per_lineextra_paddingr   r   
<listcomp>|   s    zalign8to32.<locals>.<listcomp>    )divmodrangelenjoin)r@   rA   rB   bits_per_pixelbits_per_linefull_bytes_per_lineremaining_bits_per_linenew_datar   rO   r   
align8to32j   s   

r]   Image.Image | str | QByteArraydict[str, Any]c           	        s  d }d }d}t | drt|  d} t| rt| } d}t| tjs%J tdkr.tt	dnt	}| j
dkr;t|d}n| j
d	krOt|d
}dd tdD }no| j
dkrst|d
}|    d uscJ  fddtdt dD }nK| j
dkr| d} | dd}t|d}n5| j
dkr| dd}t|d}n$| j
dkr| dd } t|d}n|r|   dt| j
 }t|| j}|pt|  |d | j
}|r|   ||||dS )NFtoUtf8zutf-8Tr   FormatrF   Format_MonorG   Format_Indexed8c                 S  s   g | ]}t |||qS r   r&   rL   r   r   r   rR      s    z$_toqclass_helper.<locals>.<listcomp>   rH   c                   s    g | ]}t  ||d    qS )   rd   rL   paletter   r   rR      s     r   rf   RGBRGBArawBGRAFormat_RGB32Format_ARGB32rI   c                 S  s   | d S )Nre   r   )rN   r   r   r   r      s    z"_toqclass_helper.<locals>.<lambda>Format_Grayscale16zunsupported image mode )r5   sizeformat
colortable)hasattrrC   r`   r
   r	   r1   
isinstancer   r/   r   rB   rU   
getpaletterV   converttobytespointr6   repr
ValueErrorrp   r]   )	r'   r5   rr   exclusive_fp	qt_formatrq   msgrp   __datar   rg   r   _toqclass_helper   sN   






 



r   c                      s   e Zd Zd fddZ  ZS )ImageQtr'   r^   r%   Nonec                   sX   t |}|d | _t | j|d d |d d |d  |d r*| |d  dS dS )z
            An PIL image wrapper for Qt.  This is a subclass of PyQt's QImage
            class.

            :param im: A PIL Image object, or a file name (given either as
                Python string or a PyQt string object).
            r5   rp   r   r   rq   rr   N)r   _ImageQt__datasuper__init__setColorTable)selfr'   im_data	__class__r   r   r      s   


zImageQt.__init__)r'   r^   r%   r   )__name__
__module____qualname__r   __classcell__r   r   r   r   r      s    r   c                 C  r;   r<   )r   r=   r   r   r   toqimage   r?   r   c                 C  s*   t | }ttd|}tdkr|  |S )N	fromImager   )r   r/   r   r   detach)r'   qimagepixmapr   r   r   	toqpixmap   s
   r   )r   )
r    r!   r"   r!   r#   r!   r$   r!   r%   r!   )r'   r(   r%   r)   )r'   r   r%   r)   )r@   r@   rA   r!   rB   rC   r%   r@   )r'   r^   r%   r_   )r'   r^   r%   r   )r'   r^   r%   r   ).
__future__r   r   ior   typingr   r   r   r    r	   _utilr
   r   r   r   __annotations__QtCore
QByteArrayr   QtGuir   r   qt_versionssortr   	qt_modulePyQt6.QtCorer   PyQt6.QtGuir   PySide6.QtCorePySide6.QtGuiImportErrorRuntimeErrorqt_is_installedr   r&   r:   r>   r]   r   r   r   r   r   r   r   r   <module>   s^   



3
