o
    2j1                  
   @   s4  d dl mZ d dlZd dlm  mZ d dlmZ d dl	m
Z
mZ d dlmZ G dd deZG dd	 d	eZG d
d deZG dd deZG dd deZejejdededejdejfddZejejdedejdejfddZejdeejdejdejfddZejejG dd dZdS )     )IntEnumN)	err_check)VideoFormatget_pix_fmt)alloc_video_framec                   @   s   e Zd ZU eZded< eZded< eZ	ded< e
Zded< eZd	ed
< eZded< eZded< eZded< eZded< eZded< eZded< dS )InterpolationzFast bilinearFAST_BILINEARBilinearBILINEARz2-tap cubic B-splineBICUBICExperimentalXzNearest neighbor / pointPOINTzArea averagingAREAzBicubic luma / Bilinear chromaBICUBLINzGaussian approximationGAUSSzUnwindowed SincSINCz3-tap sinc/sincLANCZOSzUnwindowed natural cubic splineSPLINEN)__name__
__module____qualname__SWS_FAST_BILINEARr   __annotations__SWS_BILINEARr
   SWS_BICUBICr   SWS_Xr   	SWS_POINTr   SWS_AREAr   SWS_BICUBLINr   	SWS_GAUSSr   SWS_SINCr   SWS_LANCZOSr   
SWS_SPLINEr    r$   r$   O/var/www/html/whisper/venv/lib/python3.10/site-packages/av/video/reformatter.pyr   
   s   
 r   c                   @   sD   e Zd ZeZeZeZe	Z
eZeZeZeZeZeZe	ZeZeZeZdS )
ColorspaceN)r   r   r   SWS_CS_ITU709ITU709
SWS_CS_FCCFCCSWS_CS_ITU601ITU601SWS_CS_ITU624ITU624SWS_CS_SMPTE170M	SMPTE170MSWS_CS_SMPTE240M	SMPTE240MSWS_CS_DEFAULTDEFAULTitu709fccitu601itu624	smpte170m	smpte240mdefaultr$   r$   r$   r%   r&      s    r&   c                   @   sF   e Zd ZU ejZded< ejZded< ej	Z
ded< ejZded< d	S )

ColorRangeUnspecifiedUNSPECIFIEDz%MPEG (limited) YUV range, 219*2^(n-8)MPEGzJPEG (full) YUV range, 2^n-1JPEGzNot part of ABINBN)r   r   r   libAVCOL_RANGE_UNSPECIFIEDr>   r   AVCOL_RANGE_MPEGr?   AVCOL_RANGE_JPEGr@   AVCOL_RANGE_NBrA   r$   r$   r$   r%   r<   *   s
   
 r<   c                   @   s   e Zd ZU dZejZded< ejZ	ded< ej
Zded< ejZded	< ejZd
ed< ejZded< ejZded< ejZded< ejZded< ejZded< ejZded< ejZded< ejZded< ej Z!ded< ej"Z#ded< ej$Z%d ed!< ej&Z'd"ed#< d$S )%ColorTrczuTransfer characteristic (gamma curve) of a video frame.

    Maps to FFmpeg's ``AVColorTransferCharacteristic``.
    zBT.709BT709r=   r>   zGamma 2.2 (BT.470M)GAMMA22zGamma 2.8 (BT.470BG)GAMMA28z
SMPTE 170Mr0   
SMPTE 240Mr2   LinearLINEARzLogarithmic (100:1 range)LOGz"Logarithmic (100*sqrt(10):1 range)LOG_SQRTzIEC 61966-2-4 (sRGB)IEC61966_2_4zBT.1361 extended colour gamut
BT1361_ECGzIEC 61966-2-1 (sYCC)IEC61966_2_1zBT.2020 10-bit	BT2020_10zBT.2020 12-bit	BT2020_12zSMPTE 2084 (PQ, HDR10)	SMPTE2084zSMPTE 428-1SMPTE428zARIB STD-B67 (HLG)ARIB_STD_B67N)(r   r   r   __doc__rB   AVCOL_TRC_BT709rH   r   AVCOL_TRC_UNSPECIFIEDr>   AVCOL_TRC_GAMMA22rI   AVCOL_TRC_GAMMA28rJ   AVCOL_TRC_SMPTE170Mr0   AVCOL_TRC_SMPTE240Mr2   AVCOL_TRC_LINEARrM   AVCOL_TRC_LOGrN   AVCOL_TRC_LOG_SQRTrO   AVCOL_TRC_IEC61966_2_4rP   AVCOL_TRC_BT1361_ECGrQ   AVCOL_TRC_IEC61966_2_1rR   AVCOL_TRC_BT2020_10rS   AVCOL_TRC_BT2020_12rT   AVCOL_TRC_SMPTE2084rU   AVCOL_TRC_SMPTE428rV   AVCOL_TRC_ARIB_STD_B67rW   r$   r$   r$   r%   rG   1   s&   
 rG   c                   @   s   e Zd ZU dZejZded< ejZ	ded< ej
Zded< ejZded	< ejZd
ed< ejZded< ejZded< ejZded< ejZded< ejZded< ejZded< ejZded< dS )ColorPrimarieszRColor primaries of a video frame.

    Maps to FFmpeg's ``AVColorPrimaries``.
    zBT.709 / sRGB / sYCCrH   r=   r>   zBT.470MBT470MzBT.470BG / BT.601-6 625BT470BGzSMPTE 170M / BT.601-6 525r0   rK   r2   zGeneric film (Illuminant C)FILMzBT.2020 / BT.2100BT2020zSMPTE 428-1 / XYZrV   zSMPTE 431-2 (DCI-P3)SMPTE431zSMPTE 432-1 (Display P3)SMPTE432zEBU 3213-E / JEDEC P22EBU3213N)r   r   r   rX   rB   AVCOL_PRI_BT709rH   r   AVCOL_PRI_UNSPECIFIEDr>   AVCOL_PRI_BT470Mrk   AVCOL_PRI_BT470BGrl   AVCOL_PRI_SMPTE170Mr0   AVCOL_PRI_SMPTE240Mr2   AVCOL_PRI_FILMrm   AVCOL_PRI_BT2020rn   AVCOL_PRI_SMPTE428rV   AVCOL_PRI_SMPTE431ro   AVCOL_PRI_SMPTE432rp   AVCOL_PRI_EBU3213rq   r$   r$   r$   r%   rj   J   s   
 rj   value
enum_classr;   returnc                 C   sT   | d u r|S t | |r| jS t | tr| S t | tr||  jS td|  d|j )NzCannot convert z to )
isinstancer~   intstr
ValueErrorr   )r~   r   r;   r$   r$   r%   _resolve_enum_value^   s   



r   formatc                 C   s,   | d u r|S t | trtt| jS t| S N)r   r   cythoncastpix_fmtr   )r   r;   r$   r$   r%   _resolve_formato   s
   
r   frame
colorspacecolor_rangec                 C   sn   |t jkrtt j|| _|tkrt j| _dS |t	kr!t j
| _dS |tkr+t j| _dS |tkr5t j| _dS dS )zCSet AVFrame colorspace/range from SWS_CS_* and AVColorRange values.N)rB   rC   r   r   AVColorRanger   r'   AVCOL_SPC_BT709r   r)   AVCOL_SPC_FCCr+   AVCOL_SPC_SMPTE170Mr1   AVCOL_SPC_SMPTE240M)r   r   r   r$   r$   r%   _set_frame_colorspacey   s   
r   c                   @   s   e Zd ZdZdd Z											ddefddZejdedej	d	ej	d
e
jdej	dej	dej	dej	dej	dej	dej	dejdejdej	fddZdS )VideoReformatterzAn object for reformatting size and pixel format of :class:`.VideoFrame`.

    It is most efficient to have a reformatter object for each set of parameters
    you will use as calling :meth:`reformat` will reconfigure the internal object.

    c                 C   s<   t j tt | j W d    d S 1 sw   Y  d S r   )r   nogilsws_free_contextaddressptr)selfr$   r$   r%   __dealloc__   s   "zVideoReformatter.__dealloc__Nr   c                 C   s   t ||jj}t|t|jj}t|t|jj}t|tt}t|t	d}t|	t	d}t|
t
d}t|td}|dur;|nd}|durC|n|jj}|durM|n|jj}|
du}|du}| ||||||||||||||S )aw  Create a new :class:`VideoFrame` with the given width/height/format/colorspace.

        Returns the same frame untouched if nothing needs to be done to it.

        :param int width: New width, or ``None`` for the same width.
        :param int height: New height, or ``None`` for the same height.
        :param format: New format, or ``None`` for the same format.
        :type  format: :class:`.VideoFormat` or ``str``
        :param src_colorspace: Current colorspace, or ``None`` for the frame colorspace.
        :type  src_colorspace: :class:`Colorspace` or ``str``
        :param dst_colorspace: Desired colorspace, or ``None`` for the frame colorspace.
        :type  dst_colorspace: :class:`Colorspace` or ``str``
        :param interpolation: The interpolation method to use, or ``None`` for ``BILINEAR``.
        :type  interpolation: :class:`Interpolation` or ``str``
        :param src_color_range: Current color range, or ``None`` for the ``UNSPECIFIED``.
        :type  src_color_range: :class:`ColorRange` or ``str``
        :param dst_color_range: Desired color range, or ``None`` for the ``UNSPECIFIED``.
        :type  dst_color_range: :class:`ColorRange` or ``str``
        :param dst_color_trc: Desired transfer characteristic to tag on the output frame,
            or ``None`` to preserve the source frame's value. This sets frame metadata only;
            it does not perform a pixel-level transfer function conversion.
        :type  dst_color_trc: :class:`ColorTrc` or ``int``
        :param dst_color_primaries: Desired color primaries to tag on the output frame,
            or ``None`` to preserve the source frame's value.
        :type  dst_color_primaries: :class:`ColorPrimaries` or ``int``
        :param int threads: How many threads to use for scaling, or ``0`` for automatic
            selection based on the number of available CPUs. Defaults to ``0`` (auto).

        r   N)r   r   r   r   r&   r   r   r   r   r<   rG   rj   widthheight	_reformat)r   r   r   r   r   src_colorspacedst_colorspaceinterpolationsrc_color_rangedst_color_rangedst_color_trcdst_color_primariesthreadsc_dst_formatc_src_colorspacec_dst_colorspacec_interpolationc_src_color_rangec_dst_color_rangec_dst_color_trcc_dst_color_primaries	c_threadsc_widthc_heightset_dst_color_trcset_dst_color_primariesr$   r$   r%   reformat   sJ   ,

zVideoReformatter.reformatr   r   
dst_formatr   r   r   r   r   r   r   r   r   r   c                 C   s  |j jdk r
tdttj|j j}||kr1||j jkr1||j jkr1||kr1||	kr1|s1|s1|S |j j	rVt
 }tt|j |j d |j|_|  |}ttj|j j}| j tjkrjt | _ | j tjkrjtd|| j _ttj|| j _t
 }|| |||| |j j}|j j}t|j || t|j ||	 tj t| j |j |j }W d    n1 sw   Y  ||j _||j _t| |rttj|
|j _|rttj||j _|S )Nr   zFrame does not have format set.zCould not allocate SwsContext) r   r   r   r   r   rB   AVPixelFormatr   r   hw_frames_ctxr   r   av_hwframe_transfer_datapts_init_user_attributesNULLsws_alloc_contextMemoryErrorr   uintflags_copy_internal_attributes_initr   r   r   r   sws_scale_frameAVColorTransferCharacteristic	color_trcAVColorPrimariescolor_primaries)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
src_formatframe_sw	new_frameframe_src_colorspaceframe_src_color_rangeretr$   r$   r%   r      s`   
zVideoReformatter._reformat)NNNNNNNNNNN)r   r   r   rX   r   
VideoFramer   r   cfuncr   rB   r   bintr   r$   r$   r$   r%   r      s^    
U	
r   ) enumr   r   cython.cimports.libavcimportslibavrB   cython.cimports.av.errorr   cython.cimports.av.video.formatr   r   cython.cimports.av.video.framer   r   r&   r<   rG   rj   r   inlineobjectr   r   r   r   pointerAVFramer   finalcclassr   r$   r$   r$   r%   <module>   sH    
