Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

i422_yuy2.c

00001 /*****************************************************************************
00002  * i422_yuy2.c : YUV to YUV conversion module for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000, 2001 the VideoLAN team
00005  * $Id: i422_yuy2.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  * 
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <string.h>                                            /* strerror() */
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 
00030 #include <vlc/vlc.h>
00031 #include <vlc/vout.h>
00032 
00033 #include "i422_yuy2.h"
00034 
00035 #define SRC_FOURCC  "I422"
00036 #if defined (MODULE_NAME_IS_i422_yuy2)
00037 #    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
00038 #else
00039 #    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
00040 #endif
00041 
00042 /*****************************************************************************
00043  * Local and extern prototypes.
00044  *****************************************************************************/
00045 static int  Activate ( vlc_object_t * );
00046 
00047 static void I422_YUY2           ( vout_thread_t *, picture_t *, picture_t * );
00048 static void I422_YVYU           ( vout_thread_t *, picture_t *, picture_t * );
00049 static void I422_UYVY           ( vout_thread_t *, picture_t *, picture_t * );
00050 static void I422_IUYV           ( vout_thread_t *, picture_t *, picture_t * );
00051 static void I422_cyuv           ( vout_thread_t *, picture_t *, picture_t * );
00052 #if defined (MODULE_NAME_IS_i422_yuy2)
00053 static void I422_Y211           ( vout_thread_t *, picture_t *, picture_t * );
00054 static void I422_Y211           ( vout_thread_t *, picture_t *, picture_t * );
00055 static void I422_YV12           ( vout_thread_t *, picture_t *, picture_t * );
00056 #endif
00057 
00058 /*****************************************************************************
00059  * Module descriptor
00060  *****************************************************************************/
00061 vlc_module_begin();
00062 #if defined (MODULE_NAME_IS_i422_yuy2)
00063     set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
00064     set_capability( "chroma", 80 );
00065 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
00066     set_description( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) );
00067     set_capability( "chroma", 100 );
00068     add_requirement( MMX );
00069 #endif
00070     set_callbacks( Activate, NULL );
00071 vlc_module_end();
00072 
00073 /*****************************************************************************
00074  * Activate: allocate a chroma function
00075  *****************************************************************************
00076  * This function allocates and initializes a chroma function
00077  *****************************************************************************/
00078 static int Activate( vlc_object_t *p_this )
00079 {
00080     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00081 
00082     if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
00083     {
00084         return -1;
00085     }
00086 
00087     switch( p_vout->render.i_chroma )
00088     {
00089         case VLC_FOURCC('I','4','2','2'):
00090             switch( p_vout->output.i_chroma )
00091             {
00092                 case VLC_FOURCC('Y','U','Y','2'):
00093                 case VLC_FOURCC('Y','U','N','V'):
00094                     p_vout->chroma.pf_convert = I422_YUY2;
00095                     break;
00096 
00097                 case VLC_FOURCC('Y','V','Y','U'):
00098                     p_vout->chroma.pf_convert = I422_YVYU;
00099                     break;
00100 
00101                 case VLC_FOURCC('U','Y','V','Y'):
00102                 case VLC_FOURCC('U','Y','N','V'):
00103                 case VLC_FOURCC('Y','4','2','2'):
00104                     p_vout->chroma.pf_convert = I422_UYVY;
00105                     break;
00106 
00107                 case VLC_FOURCC('I','U','Y','V'):
00108                     p_vout->chroma.pf_convert = I422_IUYV;
00109                     break;
00110 
00111                 case VLC_FOURCC('c','y','u','v'):
00112                     p_vout->chroma.pf_convert = I422_cyuv;
00113                     break;
00114 
00115 #if defined (MODULE_NAME_IS_i422_yuy2)
00116                 case VLC_FOURCC('Y','2','1','1'):
00117                     p_vout->chroma.pf_convert = I422_Y211;
00118                     break;
00119 
00120                 case VLC_FOURCC('Y','V','1','2'):
00121                     p_vout->chroma.pf_convert = I422_YV12;
00122                     break;
00123 #endif
00124 
00125                 default:
00126                     return -1;
00127             }
00128             break;
00129 
00130         default:
00131             return -1;
00132     }
00133     
00134     return 0; 
00135 }
00136 
00137 /* Following functions are local */
00138 
00139 /*****************************************************************************
00140  * I422_YUY2: planar YUV 4:2:2 to packed YUY2 4:2:2
00141  *****************************************************************************/
00142 static void I422_YUY2( vout_thread_t *p_vout, picture_t *p_source,
00143                                               picture_t *p_dest )
00144 {
00145     uint8_t *p_line = p_dest->p->p_pixels;
00146     uint8_t *p_y = p_source->Y_PIXELS;
00147     uint8_t *p_u = p_source->U_PIXELS;
00148     uint8_t *p_v = p_source->V_PIXELS;
00149 
00150     int i_x, i_y;
00151 
00152     for( i_y = p_vout->render.i_height ; i_y-- ; )
00153     {
00154         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
00155         {
00156 #if defined (MODULE_NAME_IS_i422_yuy2)
00157             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
00158             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
00159             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
00160             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
00161 #else
00162             __asm__( ".align 8" MMX_YUV422_YUYV
00163                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
00164 
00165             p_line += 16; p_y += 8; p_u += 4; p_v += 4;
00166 #endif
00167         }
00168     }
00169 }
00170 
00171 /*****************************************************************************
00172  * I422_YVYU: planar YUV 4:2:2 to packed YVYU 4:2:2
00173  *****************************************************************************/
00174 static void I422_YVYU( vout_thread_t *p_vout, picture_t *p_source,
00175                                               picture_t *p_dest )
00176 {
00177     uint8_t *p_line = p_dest->p->p_pixels;
00178     uint8_t *p_y = p_source->Y_PIXELS;
00179     uint8_t *p_u = p_source->U_PIXELS;
00180     uint8_t *p_v = p_source->V_PIXELS;
00181 
00182     int i_x, i_y;
00183 
00184     for( i_y = p_vout->render.i_height ; i_y-- ; )
00185     {
00186         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
00187         {
00188 #if defined (MODULE_NAME_IS_i422_yuy2)
00189             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
00190             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
00191             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
00192             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
00193 #else
00194             __asm__( ".align 8" MMX_YUV422_YVYU
00195                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
00196 
00197             p_line += 16; p_y += 8; p_u += 4; p_v += 4;
00198 #endif
00199         }
00200     }
00201 }
00202 
00203 /*****************************************************************************
00204  * I422_UYVY: planar YUV 4:2:2 to packed UYVY 4:2:2
00205  *****************************************************************************/
00206 static void I422_UYVY( vout_thread_t *p_vout, picture_t *p_source,
00207                                               picture_t *p_dest )
00208 {
00209     uint8_t *p_line = p_dest->p->p_pixels;
00210     uint8_t *p_y = p_source->Y_PIXELS;
00211     uint8_t *p_u = p_source->U_PIXELS;
00212     uint8_t *p_v = p_source->V_PIXELS;
00213 
00214     int i_x, i_y;
00215 
00216     for( i_y = p_vout->render.i_height ; i_y-- ; )
00217     {
00218         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
00219         {
00220 #if defined (MODULE_NAME_IS_i422_yuy2)
00221             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00222             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00223             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00224             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00225 #else
00226             __asm__( ".align 8" MMX_YUV422_UYVY
00227                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
00228 
00229             p_line += 16; p_y += 8; p_u += 4; p_v += 4;
00230 #endif
00231         }
00232     }
00233 }
00234 
00235 /*****************************************************************************
00236  * I422_IUYV: planar YUV 4:2:2 to interleaved packed IUYV 4:2:2
00237  *****************************************************************************/
00238 static void I422_IUYV( vout_thread_t *p_vout, picture_t *p_source,
00239                                               picture_t *p_dest )
00240 {
00241     /* FIXME: TODO ! */
00242     msg_Err( p_vout, "I422_IUYV unimplemented, please harass <[email protected]>" );
00243 }
00244 
00245 /*****************************************************************************
00246  * I422_cyuv: planar YUV 4:2:2 to upside-down packed UYVY 4:2:2
00247  *****************************************************************************/
00248 static void I422_cyuv( vout_thread_t *p_vout, picture_t *p_source,
00249                                               picture_t *p_dest )
00250 {
00251     uint8_t *p_line = p_dest->p->p_pixels + p_dest->p->i_visible_lines * p_dest->p->i_pitch;
00252     uint8_t *p_y = p_source->Y_PIXELS;
00253     uint8_t *p_u = p_source->U_PIXELS;
00254     uint8_t *p_v = p_source->V_PIXELS;
00255 
00256     int i_x, i_y;
00257 
00258     for( i_y = p_vout->render.i_height ; i_y-- ; )
00259     {
00260         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
00261         {
00262             p_line -= 2 * p_dest->p->i_pitch;
00263 
00264 #if defined (MODULE_NAME_IS_i422_yuy2)
00265             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00266             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00267             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00268             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
00269 #else
00270             __asm__( ".align 8" MMX_YUV422_UYVY
00271                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
00272 
00273             p_line += 16; p_y += 8; p_u += 4; p_v += 4;
00274 #endif
00275         }
00276     }
00277 }
00278 
00279 /*****************************************************************************
00280  * I422_Y211: planar YUV 4:2:2 to packed YUYV 2:1:1
00281  *****************************************************************************/
00282 #if defined (MODULE_NAME_IS_i422_yuy2)
00283 static void I422_Y211( vout_thread_t *p_vout, picture_t *p_source,
00284                                               picture_t *p_dest )
00285 {
00286     uint8_t *p_line = p_dest->p->p_pixels + p_dest->p->i_visible_lines * p_dest->p->i_pitch;
00287     uint8_t *p_y = p_source->Y_PIXELS;
00288     uint8_t *p_u = p_source->U_PIXELS;
00289     uint8_t *p_v = p_source->V_PIXELS;
00290 
00291     int i_x, i_y;
00292 
00293     for( i_y = p_vout->render.i_height ; i_y-- ; )
00294     {
00295         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
00296         {
00297             C_YUV422_Y211( p_line, p_y, p_u, p_v );
00298             C_YUV422_Y211( p_line, p_y, p_u, p_v );
00299         }
00300     }
00301 }
00302 #endif
00303 
00304 
00305 /*****************************************************************************
00306  * I422_YV12: planar YUV 4:2:2 to planar YV12
00307  *****************************************************************************/
00308 #if defined (MODULE_NAME_IS_i422_yuy2)
00309 static void I422_YV12( vout_thread_t *p_vout, picture_t *p_source,
00310                                               picture_t *p_dest )
00311 {
00312     uint16_t i_dpy = p_dest->p[Y_PLANE].i_pitch;
00313     uint16_t i_spy = p_source->p[Y_PLANE].i_pitch;
00314     uint16_t i_dpuv = p_dest->p[U_PLANE].i_pitch;
00315     uint16_t i_spuv = p_source->p[U_PLANE].i_pitch;
00316     uint16_t i_width = p_vout->render.i_width;
00317     uint16_t i_y = p_vout->render.i_height;
00318     uint8_t *p_dy = p_dest->Y_PIXELS + (i_y-1)*i_dpy;
00319     uint8_t *p_y = p_source->Y_PIXELS + (i_y-1)*i_spy;
00320     uint8_t *p_du = p_dest->U_PIXELS + (i_y/2-1)*i_dpuv;
00321     uint8_t *p_u = p_source->U_PIXELS + (i_y-1)*i_spuv;
00322     uint8_t *p_dv = p_dest->V_PIXELS + (i_y/2-1)*i_dpuv;
00323     uint8_t *p_v = p_source->V_PIXELS + (i_y-1)*i_spuv;
00324     i_y /= 2;
00325 
00326     for ( ; i_y--; )
00327     {
00328         memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
00329         memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
00330         memcpy(p_du, p_u, i_width/2); p_du -= i_dpuv; p_u -= 2*i_spuv;
00331         memcpy(p_dv, p_v, i_width/2); p_dv -= i_dpuv; p_v -= 2*i_spuv;
00332     }
00333 
00334 }
00335 #endif

Generated on Tue Dec 20 10:14:51 2005 for vlc-0.8.4a by  doxygen 1.4.2