o
    sh                  
   @  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 ddl	m
Z
 ddlmZ d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)AnyCallableUnion   )Image)is_pathF)	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/construction_image-detection-poc/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      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   rgbC   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   
fromqimageJ   s"   

r9   r   c                 C     t | S N)r9   r&   r   r   r   fromqpixmapg      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?   r@   rA   bits_per_pixelbits_per_linefull_bytes_per_lineremaining_bits_per_linenew_datar   rN   r   
align8to32k   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   FormatrE   Format_MonorF   Format_Indexed8c                 S  s   g | ]}t |||qS r   r%   rK   r   r   r   rQ      s    z$_toqclass_helper.<locals>.<listcomp>   rG   c                   s    g | ]}t  ||d    qS )   rc   rK   paletter   r   rQ      s     r   re   RGBRGBArawBGRAFormat_RGB32Format_ARGB32rH   c                 S  s   | d S )Nrd   r   )rM   r   r   r   r      s    z"_toqclass_helper.<locals>.<lambda>Format_Grayscale16zunsupported image mode )r4   sizeformat
colortable)hasattrrB   r_   r	   r   r0   
isinstancer   r.   r   rA   rT   
getpaletterU   converttobytespointr5   repr
ValueErrorro   r\   )	r&   r4   rq   exclusive_fp	qt_formatrp   msgro   __datar   rf   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).
            r4   ro   r   r   rp   rq   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?   r@   r    rA   rB   r$   r?   )r&   r]   r$   r^   )r&   r]   r$   r   )r&   r]   r$   r   ).
__future__r   r   ior   typingr   r   r    r   _utilr	   TYPE_CHECKINGr   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%   r9   r=   r\   r~   r   r   r   r   r   r   r   <module>   s`   



3
