
    \j                        d dl Z d dlmZ d dlmZ d dlmZ  e j                  e	 e	             Z
e j                  e j                   G d de                    Ze j                  e j                   G d d                    Zy)	    N)libav)SideData)	uintptr_tc                   h    e Zd Zdedej
                  fdZd Zd Zdej                  fdZ
d Zd Zy	)
MotionVectorsframeindexc                     t        j                  | |||       i | _        | j                  j                  t        j                  t        j                        z  | _	        y N)
r   __init___vectorsptrsizecythonsizeoflibAVMotionVector_len)selfsentinelr   r	   s       L/root/.hermes/venv/lib/python3.12/site-packages/av/sidedata/motionvectors.pyr   zMotionVectors.__init__   s@    $%7HHMMV]]33E3E%FF	    c           	          d| j                   j                   dt        |        dt        j                  t
        | j                   j                        ddS )Nz<av.sidedata.MotionVectors z
 bytes of z vectors at 0x0x>)r   r   lenr   castr   datar   s    r   __repr__zMotionVectors.__repr__   sJ    )$((-- 9d)N6;;y$((--+PQS*TTUW	
r   c                     | j                   S r   )r   r   s    r   __len__zMotionVectors.__len__   s    yyr   c                     	 | j                   |   S # t        $ r Y nw xY w|| j                  k\  rt        |      t	        t
        | |      x}| j                   |<   |S r   )r   KeyErrorr   
IndexErrorMotionVector_cinit_bypass_sentinel)r   r	   vectors      r   __getitem__zMotionVectors.__getitem__   si    	=='' 		 DIIU##(4"D%)
 	
u% s    	c              #   N   K   t        | j                        D ]	  }| |     yw)z Iterate over all motion vectors.N)ranger   )r   is     r   __iter__zMotionVectors.__iter__(   s'     tyy! 	Aq'M	s   #%c                 V    ddl }|j                  | |j                  g dd            S )z
        Convert motion vectors to a NumPy structured array.

        Returns a NumPy array with fields corresponding to the AVMotionVector structure.
        r   N))sourceint32)wuint8)hr2   )src_xint16)src_yr5   )dst_xr5   )dst_yr5   )flagsuint64)motion_xr0   )motion_yr0   )motion_scaleuint16T)align)dtype)numpy
frombufferr@   )r   nps     r   
to_ndarrayzMotionVectors.to_ndarray-   s;     	}}((     
 	
r   N)__name__
__module____qualname__Framer   intr   r    r"   
Py_ssize_tr)   r-   rD    r   r   r   r   	   sB    G Gfjj G

!2!2 

r   r   c                       e Zd ZdZdedej                  fdZd Ze	d        Z
e	d        Ze	d        Ze	d	        Ze	d
        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Zy)r&   z
    Represents a single motion vector from video frame data.

    Motion vectors describe the motion of a block of pixels between frames.
    parentr	   c                     |t         urt        d      || _        t        j                  t        j
                  t        j                     |j                  j                        }||z   | _        y )Nz(cannot manually instantiate MotionVector)
r'   RuntimeErrorrM   r   r   pointerr   r   r   r   )r   r   rM   r	   bases        r   r   zMotionVector.__init__S   sU    11IJJ39;;NN3--.

4
 %<r   c                     d| j                    d| j                   d| j                   d| j                   d| j                   d| j
                   dS )Nz<av.sidedata.MotionVector xz from (,z) to (z)>)r1   r3   r4   r6   r7   r8   r   s    r   r    zMotionVector.__repr__\   sP    ($&& :ZZL$**VDJJ<qBP	
r   c                 .    | j                   j                  S r   )r   r/   r   s    r   r/   zMotionVector.sourceb   s    xxr   c                 .    | j                   j                  S r   )r   r1   r   s    r   r1   zMotionVector.wf       xxzzr   c                 .    | j                   j                  S r   )r   r3   r   s    r   r3   zMotionVector.hj   rW   r   c                 .    | j                   j                  S r   )r   r4   r   s    r   r4   zMotionVector.src_xn       xx~~r   c                 .    | j                   j                  S r   )r   r6   r   s    r   r6   zMotionVector.src_yr   rZ   r   c                 .    | j                   j                  S r   )r   r7   r   s    r   r7   zMotionVector.dst_xv   rZ   r   c                 .    | j                   j                  S r   )r   r8   r   s    r   r8   zMotionVector.dst_yz   rZ   r   c                 .    | j                   j                  S r   )r   r;   r   s    r   r;   zMotionVector.motion_x~       xx   r   c                 .    | j                   j                  S r   )r   r<   r   s    r   r<   zMotionVector.motion_y   r_   r   c                 .    | j                   j                  S r   )r   r=   r   s    r   r=   zMotionVector.motion_scale   s    xx$$$r   N)rE   rF   rG   __doc__r   r   rI   r   r    propertyr/   r1   r3   r4   r6   r7   r8   r;   r<   r=   rK   r   r   r&   r&   J   s       vzz  
               ! ! ! ! % %r   r&   )r   cython.cimportsr   r   $cython.cimports.av.sidedata.sidedatar   cython.cimports.libc.stdintr   declareobjectr'   finalcclassr   r&   rK   r   r   <module>rk      s{     ( 9 1'9  <
H <
  <
~ <% <%  <%r   