yuy2_i422.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:11k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * yuy2_i422.c : Packed YUV 4:2:2 to Planar YUV conversion module for vlc
  3.  *****************************************************************************
  4.  * Copyright (C) 2007 the VideoLAN team
  5.  * $Id: 03d47fd54168608c77965a26eb8e96c1bbe341df $
  6.  *
  7.  * Authors: Antoine Cellerier <dionoea at videolan dot org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #ifdef HAVE_CONFIG_H
  27. # include "config.h"
  28. #endif
  29. #include <vlc_common.h>
  30. #include <vlc_plugin.h>
  31. #include <vlc_filter.h>
  32. #include <vlc_vout.h>
  33. #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
  34. #define DEST_FOURCC  "I422"
  35. /*****************************************************************************
  36.  * Local and extern prototypes.
  37.  *****************************************************************************/
  38. static int  Activate ( vlc_object_t * );
  39. static void YUY2_I422           ( filter_t *, picture_t *, picture_t * );
  40. static void YVYU_I422           ( filter_t *, picture_t *, picture_t * );
  41. static void UYVY_I422           ( filter_t *, picture_t *, picture_t * );
  42. static void cyuv_I422           ( filter_t *, picture_t *, picture_t * );
  43. static picture_t *YUY2_I422_Filter    ( filter_t *, picture_t * );
  44. static picture_t *YVYU_I422_Filter    ( filter_t *, picture_t * );
  45. static picture_t *UYVY_I422_Filter    ( filter_t *, picture_t * );
  46. static picture_t *cyuv_I422_Filter    ( filter_t *, picture_t * );
  47. /*****************************************************************************
  48.  * Module descriptor
  49.  *****************************************************************************/
  50. vlc_module_begin ()
  51.     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
  52.     set_capability( "video filter2", 80 )
  53.     set_callbacks( Activate, NULL )
  54. vlc_module_end ()
  55. /*****************************************************************************
  56.  * Activate: allocate a chroma function
  57.  *****************************************************************************
  58.  * This function allocates and initializes a chroma function
  59.  *****************************************************************************/
  60. static int Activate( vlc_object_t *p_this )
  61. {
  62.     filter_t *p_filter = (filter_t *)p_this;
  63.     if( p_filter->fmt_in.video.i_width & 1
  64.      || p_filter->fmt_in.video.i_height & 1 )
  65.     {
  66.         return -1;
  67.     }
  68.     if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
  69.      || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
  70.         return -1;
  71.     switch( p_filter->fmt_out.video.i_chroma )
  72.     {
  73.         case VLC_FOURCC('I','4','2','2'):
  74.             switch( p_filter->fmt_in.video.i_chroma )
  75.             {
  76.                 case VLC_FOURCC('Y','U','Y','2'):
  77.                 case VLC_FOURCC('Y','U','N','V'):
  78.                     p_filter->pf_video_filter = YUY2_I422_Filter;
  79.                     break;
  80.                 case VLC_FOURCC('Y','V','Y','U'):
  81.                     p_filter->pf_video_filter = YVYU_I422_Filter;
  82.                     break;
  83.                 case VLC_FOURCC('U','Y','V','Y'):
  84.                 case VLC_FOURCC('U','Y','N','V'):
  85.                 case VLC_FOURCC('Y','4','2','2'):
  86.                     p_filter->pf_video_filter = UYVY_I422_Filter;
  87.                     break;
  88.                 case VLC_FOURCC('c','y','u','v'):
  89.                     p_filter->pf_video_filter = cyuv_I422_Filter;
  90.                     break;
  91.                 default:
  92.                     return -1;
  93.             }
  94.             break;
  95.         default:
  96.             return -1;
  97.     }
  98.     return 0;
  99. }
  100. /* Following functions are local */
  101. VIDEO_FILTER_WRAPPER( YUY2_I422 )
  102. VIDEO_FILTER_WRAPPER( YVYU_I422 )
  103. VIDEO_FILTER_WRAPPER( UYVY_I422 )
  104. VIDEO_FILTER_WRAPPER( cyuv_I422 )
  105. /*****************************************************************************
  106.  * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
  107.  *****************************************************************************/
  108. static void YUY2_I422( filter_t *p_filter, picture_t *p_source,
  109.                                            picture_t *p_dest )
  110. {
  111.     uint8_t *p_line = p_source->p->p_pixels;
  112.     uint8_t *p_y = p_dest->Y_PIXELS;
  113.     uint8_t *p_u = p_dest->U_PIXELS;
  114.     uint8_t *p_v = p_dest->V_PIXELS;
  115.     int i_x, i_y;
  116.     const int i_dest_margin = p_dest->p[0].i_pitch
  117.                                  - p_dest->p[0].i_visible_pitch;
  118.     const int i_dest_margin_c = p_dest->p[1].i_pitch
  119.                                  - p_dest->p[1].i_visible_pitch;
  120.     const int i_source_margin = p_source->p->i_pitch
  121.                                - p_source->p->i_visible_pitch;
  122.     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
  123.     {
  124.         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
  125.         {
  126. #define C_YUYV_YUV422( p_line, p_y, p_u, p_v )      
  127.             *p_y++ = *p_line++; *p_u++ = *p_line++; 
  128.             *p_y++ = *p_line++; *p_v++ = *p_line++
  129.             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
  130.             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
  131.             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
  132.             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
  133.         }
  134.         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
  135.         {
  136.             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
  137.         }
  138.         p_line += i_source_margin;
  139.         p_y += i_dest_margin;
  140.         p_u += i_dest_margin_c;
  141.         p_v += i_dest_margin_c;
  142.     }
  143. }
  144. /*****************************************************************************
  145.  * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
  146.  *****************************************************************************/
  147. static void YVYU_I422( filter_t *p_filter, picture_t *p_source,
  148.                                            picture_t *p_dest )
  149. {
  150.     uint8_t *p_line = p_source->p->p_pixels;
  151.     uint8_t *p_y = p_dest->Y_PIXELS;
  152.     uint8_t *p_u = p_dest->U_PIXELS;
  153.     uint8_t *p_v = p_dest->V_PIXELS;
  154.     int i_x, i_y;
  155.     const int i_dest_margin = p_dest->p[0].i_pitch
  156.                                  - p_dest->p[0].i_visible_pitch;
  157.     const int i_dest_margin_c = p_dest->p[1].i_pitch
  158.                                  - p_dest->p[1].i_visible_pitch;
  159.     const int i_source_margin = p_source->p->i_pitch
  160.                                - p_source->p->i_visible_pitch;
  161.     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
  162.     {
  163.         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
  164.         {
  165. #define C_YVYU_YUV422( p_line, p_y, p_u, p_v )      
  166.             *p_y++ = *p_line++; *p_v++ = *p_line++; 
  167.             *p_y++ = *p_line++; *p_u++ = *p_line++
  168.             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
  169.             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
  170.             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
  171.             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
  172.         }
  173.         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
  174.         {
  175.             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
  176.         }
  177.         p_line += i_source_margin;
  178.         p_y += i_dest_margin;
  179.         p_u += i_dest_margin_c;
  180.         p_v += i_dest_margin_c;
  181.     }
  182. }
  183. /*****************************************************************************
  184.  * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
  185.  *****************************************************************************/
  186. static void UYVY_I422( filter_t *p_filter, picture_t *p_source,
  187.                                            picture_t *p_dest )
  188. {
  189.     uint8_t *p_line = p_source->p->p_pixels;
  190.     uint8_t *p_y = p_dest->Y_PIXELS;
  191.     uint8_t *p_u = p_dest->U_PIXELS;
  192.     uint8_t *p_v = p_dest->V_PIXELS;
  193.     int i_x, i_y;
  194.     const int i_dest_margin = p_dest->p[0].i_pitch
  195.                                  - p_dest->p[0].i_visible_pitch;
  196.     const int i_dest_margin_c = p_dest->p[1].i_pitch
  197.                                  - p_dest->p[1].i_visible_pitch;
  198.     const int i_source_margin = p_source->p->i_pitch
  199.                                - p_source->p->i_visible_pitch;
  200.     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
  201.     {
  202.         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
  203.         {
  204. #define C_UYVY_YUV422( p_line, p_y, p_u, p_v )      
  205.             *p_u++ = *p_line++; *p_y++ = *p_line++; 
  206.             *p_v++ = *p_line++; *p_y++ = *p_line++
  207.             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
  208.             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
  209.             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
  210.             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
  211.         }
  212.         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
  213.         {
  214.             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
  215.         }
  216.         p_line += i_source_margin;
  217.         p_y += i_dest_margin;
  218.         p_u += i_dest_margin_c;
  219.         p_v += i_dest_margin_c;
  220.     }
  221. }
  222. /*****************************************************************************
  223.  * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
  224.  * FIXME
  225.  *****************************************************************************/
  226. static void cyuv_I422( filter_t *p_filter, picture_t *p_source,
  227.                                            picture_t *p_dest )
  228. {
  229.     uint8_t *p_line = p_source->p->p_pixels;
  230.     uint8_t *p_y = p_dest->Y_PIXELS;
  231.     uint8_t *p_u = p_dest->U_PIXELS;
  232.     uint8_t *p_v = p_dest->V_PIXELS;
  233.     int i_x, i_y;
  234.     const int i_dest_margin = p_dest->p[0].i_pitch
  235.                                  - p_dest->p[0].i_visible_pitch;
  236.     const int i_dest_margin_c = p_dest->p[1].i_pitch
  237.                                  - p_dest->p[1].i_visible_pitch;
  238.     const int i_source_margin = p_source->p->i_pitch
  239.                                - p_source->p->i_visible_pitch;
  240.     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
  241.     {
  242.         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
  243.         {
  244. #define C_cyuv_YUV422( p_line, p_y, p_u, p_v )      
  245.             *p_y++ = *p_line++; *p_v++ = *p_line++; 
  246.             *p_y++ = *p_line++; *p_u++ = *p_line++
  247.             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
  248.             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
  249.             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
  250.             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
  251.         }
  252.         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
  253.         {
  254.             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
  255.         }
  256.         p_line += i_source_margin;
  257.         p_y += i_dest_margin;
  258.         p_u += i_dest_margin_c;
  259.         p_v += i_dest_margin_c;
  260.     }
  261. }