o
    2j                  
   @   s   d dl Z d dl mZ e ee Ze jdejdedede	dB fddZ
e je jejd	d
de jdejfddZe je jG dd dZ	e je jG dd dZe Ze e je jej  e jZ	 eeZesodS eej qf)    N)uintc_formatwidthheightreturnc                 C   s,   | t jkrd S ttt}|| || |S N)libAV_PIX_FMT_NONEVideoFormat__new___cinit_bypass_sentinel_init)r   r   r   format r   J/var/www/html/whisper/venv/lib/python3.10/site-packages/av/video/format.pyget_video_format   s
   
r   F)checknamec                 C   s$   t | }|t jkrtd|  |S )z3Wrapper for lib.av_get_pix_fmt with error checking.znot a pixel format: %r)r   av_get_pix_fmtr	   
ValueError)r   pix_fmtr   r   r   get_pix_fmt   s   

r   c                   @   s   e Zd ZdZd)ddZejdejde	de	fdd	Z
d
d Zdd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zed d! Zejd*d"ejfd#d$Zejd*d%ejfd&d'Zd(S )+r
   zM

    >>> format = VideoFormat('rgb24')
    >>> format.name
    'rgb24'

    r   c                 C   s\   |t u rd S t|tr!tt|}| |j|p|j|p|j d S t	|}| ||| d S r   )
r   
isinstancer
   cythoncastr   r   r   r   r   )selfr   r   r   otherr   r   r   r   	__cinit__)   s   
zVideoFormat.__cinit__r   r   r   c                 C   s"   || _ t|| _|| _|| _d S r   )r   r   av_pix_fmt_desc_getptrr   r   )r   r   r   r   r   r   r   r   5   s   
zVideoFormat._initc              	   C   sL   | j s| jrd| jj d| j d| j  d| j d	S d| jj d| j dS )Nz<av. z, x>)r   r   	__class____name__r   r   r   r   r   __repr__<   s   (zVideoFormat.__repr__c                 C   s
   t | jS r   )intr   r%   r   r   r   __int__B   s   
zVideoFormat.__int__c                 C   s   t t| jjS )z#Canonical name of the pixel format.)r   r   strr   r   r%   r   r   r   r   E   s   zVideoFormat.namec                    s   t  fddt jjD S )Nc                 3   s    | ]}t  |V  qd S r   )VideoFormatComponent).0ir%   r   r   	<genexpr>L   s    

z)VideoFormat.components.<locals>.<genexpr>)tupleranger   nb_componentsr%   r   r%   r   
componentsJ   s   
zVideoFormat.componentsc                 C      t | jS r   )r   av_get_bits_per_pixelr   r%   r   r   r   bits_per_pixelP      zVideoFormat.bits_per_pixelc                 C   r2   r   )r   av_get_padded_bits_per_pixelr   r%   r   r   r   padded_bits_per_pixelT   r5   z!VideoFormat.padded_bits_per_pixelc                 C      t | jjtj@ S )zPixel format is big-endian.)boolr   flagsr   AV_PIX_FMT_FLAG_BEr%   r   r   r   is_big_endianX      zVideoFormat.is_big_endianc                 C   r8   )zJPixel format has a palette in data[1], values are indexes in this palette.)r9   r   r:   r   AV_PIX_FMT_FLAG_PALr%   r   r   r   has_palette]   r=   zVideoFormat.has_palettec                 C   r8   )z9All values of a component are bit-wise packed end to end.)r9   r   r:   r   AV_PIX_FMT_FLAG_BITSTREAMr%   r   r   r   is_bit_streamb   r=   zVideoFormat.is_bit_streamc                 C   r8   )z<At least one pixel component is not in the first data plane.)r9   r   r:   r   AV_PIX_FMT_FLAG_PLANARr%   r   r   r   	is_planarg   r=   zVideoFormat.is_planarc                 C   r8   )zFThe pixel format contains RGB-like data (as opposed to YUV/grayscale).)r9   r   r:   r   AV_PIX_FMT_FLAG_RGBr%   r   r   r   is_rgbl   r=   zVideoFormat.is_rgbc                 C   r8   )z%The pixel format contains Bayer data.)r9   r   r:   r   AV_PIX_FMT_FLAG_BAYERr%   r   r   r   is_bayerq   r=   zVideoFormat.is_bayer
luma_widthc                 C   "   |p| j }|r| | jj?  S dS )zchroma_width(luma_width=0)

        Width of a chroma plane relative to a luma plane.

        :param int luma_width: Width of the luma plane; defaults to ``self.width``.

        r   )r   r   log2_chroma_w)r   rH   r   r   r   chroma_widthv      
	zVideoFormat.chroma_widthluma_heightc                 C   rI   )zchroma_height(luma_height=0)

        Height of a chroma plane relative to a luma plane.

        :param int luma_height: Height of the luma plane; defaults to ``self.height``.

        r   )r   r   log2_chroma_h)r   rM   r   r   r   chroma_height   rL   zVideoFormat.chroma_heightN)r   r   )r   )r$   
__module____qualname____doc__r   r   cfuncr   AVPixelFormatcuintr   r&   r(   propertyr   r1   r4   r7   r<   r?   rA   rC   rE   rG   ccallr'   rK   rO   r   r   r   r   r
      s>    










r
   c                   @   st   e Zd ZdedejfddZedd Zedd Z	ed	d
 Z
edd Zedd Zedd Zedd ZdS )r*   r   indexc                 C   s$   || _ || _t|jj| | _d S r   )r   rX   r   addressr   comp)r   r   rX   r   r   r   r      s   zVideoFormatComponent.__cinit__c                 C      | j jS )z5The index of the plane which contains this component.)r   planer%   r   r   r   r\         zVideoFormatComponent.planec                 C   r[   )z Number of bits in the component.)r   depthr%   r   r   r   bits   r]   zVideoFormatComponent.bitsc                 C   s0   | j dkr| jjjdkp| j dko| jjjdkS )z#Is this component an alpha channel?            )rX   r   r   r0   r%   r   r   r   is_alpha   s   zVideoFormatComponent.is_alphac                 C   s0   | j dko| jjjdkp| jjjdkp| jj S )z!Is this component a luma channel?r   r`   ra   )rX   r   r   r0   rE   r%   r   r   r   is_luma   s   
zVideoFormatComponent.is_lumac                 C   s(   | j dks
| j dko| jjjp| jjjS )z#Is this component a chroma channel?r`   ra   )rX   r   r   rJ   rN   r%   r   r   r   	is_chroma   s   zVideoFormatComponent.is_chromac                 C      | j r| j S | jjS )zqThe width of this component's plane.

        Requires the parent :class:`VideoFormat` to have a width.

        )rf   r   rK   r   r%   r   r   r   r         zVideoFormatComponent.widthc                 C   rg   )zsThe height of this component's plane.

        Requires the parent :class:`VideoFormat` to have a height.

        )rf   r   rO   r   r%   r   r   r   r      rh   zVideoFormatComponent.heightN)r$   rP   rQ   r
   r   size_tr   rV   r\   r_   rd   re   rf   r   r   r   r   r   r   r*      s     





r*   )r   r   rU   declareobjectr   rS   r   rT   r
   r   	exceptvalr	   p_const_charr   finalcclassr*   setnamespointerconstAVPixFmtDescriptorNULLdescav_pix_fmt_desc_nextaddr   r   r   r   r   <module>   s<    	o:
