<commit_before>/*****************************************************************************
 * i420_yuy2.c : YUV to YUV conversion module for vlc
 *****************************************************************************
 * Copyright (C) 2000, 2001 VLC authors and VideoLAN
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_filter.h>
#include <vlc_cpu.h>

#if defined (MODULE_NAME_IS_i420_yuy2_altivec) && defined(HAVE_ALTIVEC_H)
#   include <altivec.h>
#endif

#include "i420_yuy2.h"

#define SRC_FOURCC  "I420,IYUV,YV12"

#if defined (MODULE_NAME_IS_i420_yuy2)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
#    define VLC_TARGET
#elif defined (MODULE_NAME_IS_i420_yuy2_mmx)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
#    define VLC_TARGET VLC_MMX
#elif defined (MODULE_NAME_IS_i420_yuy2_sse2)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
#    define VLC_TARGET VLC_SSE
#elif defined (MODULE_NAME_IS_i420_yuy2_altivec)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422"
#    define VLC_TARGET
#endif

/*****************************************************************************
 * Local and extern prototypes.
 *****************************************************************************/
static int  Activate ( vlc_object_t * );

static void I420_YUY2           ( filter_t *, picture_t *, picture_t * );
static void I420_YVYU           ( filter_t *, picture_t *, picture_t * );
static void I420_UYVY           ( filter_t *, picture_t *, picture_t * );
static picture_t *I420_YUY2_Filter    ( filter_t *, picture_t * );
static picture_t *I420_YVYU_Filter    ( filter_t *, picture_t * );
static picture_t *I420_UYVY_Filter    ( filter_t *, picture_t * );
#if !defined (MODULE_NAME_IS_i420_yuy2_altivec)
static void I420_IUYV           ( filter_t *, picture_t *, picture_t * );
static void I420_cyuv           ( filter_t *, picture_t *, picture_t * );
static picture_t *I420_IUYV_Filter    ( filter_t *, picture_t * );
static picture_t *I420_cyuv_Filter    ( filter_t *, picture_t * );
#endif
#if defined (MODULE_NAME_IS_i420_yuy2)
static void I420_Y211           ( filter_t *, picture_t *, picture_t * );
static picture_t *I420_Y211_Filter    ( filter_t *, picture_t * );
#endif

#ifdef MODULE_NAME_IS_i420_yuy2_mmx
/* Initialize MMX-specific constants */
static const uint64_t i_00ffw = 0x00ff00ff00ff00ffULL;
static const uint64_t i_80w   = 0x0000000080808080ULL;
#endif

/*****************************************************************************
 * Module descriptor.
 *****************************************************************************/
vlc_module_begin ()
#if defined (MODULE_NAME_IS_i420_yuy2)
    set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
    set_capability( "video filter2", 80 )
# define vlc_CPU_capable() (true)
#elif defined (MODULE_NAME_IS_i420_yuy2_mmx)
    set_description( N_("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
    set_capability( "video filter2", 160 )
# define vlc_CPU_capable() vlc_CPU_MMX()
#elif defined (MODULE_NAME_IS_i420_yuy2_sse2)
    set_description( N_("SSE2 conversions from " SRC_FOURCC " to " DEST_FOURCC) )
    set_capability( "video filter2", 250 )
# define vlc_CPU_capable() vlc_CPU_SSE2()
#elif defined (MODULE_NAME_IS_i420_yuy2_altivec)
    set_description(
            _("AltiVec conversions from " SRC_FOURCC " to " DEST_FOURCC) );
    set_capability( "video filter2", 250 )
# define vlc_CPU_capable() vlc_CPU_ALTIVEC()
#endif
    set_callbacks( Activate, NULL )
vlc_module_end ()

/*****************************************************************************
 * Activate: allocate a chroma function
 *****************************************************************************
 * This function allocates and initializes a chroma function
 *****************************************************************************/
static int Activate( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t *)p_this;

    if( !vlc_CPU_capable() )
        return VLC_EGENERIC;
    if( p_filter->fmt_in.video.i_width & 1
     || p_filter->fmt_in.video.i_height & 1 )
    {
        return -1;
    }

    if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
       || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height
       || p_filter->fmt_in.video.orientation != p_filter->fmt_out.video.orientation )
        return -1;

    switch( p_filter->fmt_in.video.i_chroma )
    {
        case VLC_CODEC_YV12:
        case VLC_CODEC_I420:
            switch( p_filter->fmt_out.video.i_chroma )
            {
                case VLC_CODEC_YUYV:
                    p_filter->pf_video_filter = I420_YUY2_Filter;
                    break;

                case VLC_CODEC_YVYU:
                    p_filter->pf_video_filter = I420_YVYU_Filter;
                    break;

                case VLC_CODEC_UYVY:
                    p_filter->pf_video_filter = I420_UYVY_Filter;
                    break;
#if !defined (MODULE_NAME_IS_i420_yuy2_altivec)
                case VLC_FOURCC('I','U','Y','V'):
                    p_filter->pf_video_filter = I420_IUYV_Filter;
                    break;

                case VLC_CODEC_CYUV:
                    p_filter->pf_video_filter = I420_cyuv_Filter;
                    break;
#endif

#if defined (MODULE_NAME_IS_i420_yuy2)
                case VLC_CODEC_Y211:
                    p_filter->pf_video_filter = I420_Y211_Filter;
                    break;
#endif<commit_msg>i420_yuy2: I420 and YV12 are not the same<commit_after>/*****************************************************************************
 * i420_yuy2.c : YUV to YUV conversion module for vlc
 *****************************************************************************
 * Copyright (C) 2000, 2001 VLC authors and VideoLAN
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_filter.h>
#include <vlc_cpu.h>

#if defined (MODULE_NAME_IS_i420_yuy2_altivec) && defined(HAVE_ALTIVEC_H)
#   include <altivec.h>
#endif

#include "i420_yuy2.h"

#define SRC_FOURCC  "I420,IYUV,YV12"

#if defined (MODULE_NAME_IS_i420_yuy2)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
#    define VLC_TARGET
#elif defined (MODULE_NAME_IS_i420_yuy2_mmx)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
#    define VLC_TARGET VLC_MMX
#elif defined (MODULE_NAME_IS_i420_yuy2_sse2)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
#    define VLC_TARGET VLC_SSE
#elif defined (MODULE_NAME_IS_i420_yuy2_altivec)
#    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422"
#    define VLC_TARGET
#endif

/*****************************************************************************
 * Local and extern prototypes.
 *****************************************************************************/
static int  Activate ( vlc_object_t * );

static void I420_YUY2           ( filter_t *, picture_t *, picture_t * );
static void I420_YVYU           ( filter_t *, picture_t *, picture_t * );
static void I420_UYVY           ( filter_t *, picture_t *, picture_t * );
static picture_t *I420_YUY2_Filter    ( filter_t *, picture_t * );
static picture_t *I420_YVYU_Filter    ( filter_t *, picture_t * );
static picture_t *I420_UYVY_Filter    ( filter_t *, picture_t * );
#if !defined (MODULE_NAME_IS_i420_yuy2_altivec)
static void I420_IUYV           ( filter_t *, picture_t *, picture_t * );
static void I420_cyuv           ( filter_t *, picture_t *, picture_t * );
static picture_t *I420_IUYV_Filter    ( filter_t *, picture_t * );
static picture_t *I420_cyuv_Filter    ( filter_t *, picture_t * );
#endif
#if defined (MODULE_NAME_IS_i420_yuy2)
static void I420_Y211           ( filter_t *, picture_t *, picture_t * );
static picture_t *I420_Y211_Filter    ( filter_t *, picture_t * );
#endif

#ifdef MODULE_NAME_IS_i420_yuy2_mmx
/* Initialize MMX-specific constants */
static const uint64_t i_00ffw = 0x00ff00ff00ff00ffULL;
static const uint64_t i_80w   = 0x0000000080808080ULL;
#endif

/*****************************************************************************
 * Module descriptor.
 *****************************************************************************/
vlc_module_begin ()
#if defined (MODULE_NAME_IS_i420_yuy2)
    set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
    set_capability( "video filter2", 80 )
# define vlc_CPU_capable() (true)
#elif defined (MODULE_NAME_IS_i420_yuy2_mmx)
    set_description( N_("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
    set_capability( "video filter2", 160 )
# define vlc_CPU_capable() vlc_CPU_MMX()
#elif defined (MODULE_NAME_IS_i420_yuy2_sse2)
    set_description( N_("SSE2 conversions from " SRC_FOURCC " to " DEST_FOURCC) )
    set_capability( "video filter2", 250 )
# define vlc_CPU_capable() vlc_CPU_SSE2()
#elif defined (MODULE_NAME_IS_i420_yuy2_altivec)
    set_description(
            _("AltiVec conversions from " SRC_FOURCC " to " DEST_FOURCC) );
    set_capability( "video filter2", 250 )
# define vlc_CPU_capable() vlc_CPU_ALTIVEC()
#endif
    set_callbacks( Activate, NULL )
vlc_module_end ()

/*****************************************************************************
 * Activate: allocate a chroma function
 *****************************************************************************
 * This function allocates and initializes a chroma function
 *****************************************************************************/
static int Activate( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t *)p_this;

    if( !vlc_CPU_capable() )
        return VLC_EGENERIC;
    if( p_filter->fmt_in.video.i_width & 1
     || p_filter->fmt_in.video.i_height & 1 )
    {
        return -1;
    }

    if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
       || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height
       || p_filter->fmt_in.video.orientation != p_filter->fmt_out.video.orientation )
        return -1;

    switch( p_filter->fmt_in.video.i_chroma )
    {
//        case VLC_CODEC_YV12: FIXME invert U and V in the filters :)
        case VLC_CODEC_I420:
            switch( p_filter->fmt_out.video.i_chroma )
            {
                case VLC_CODEC_YUYV:
                    p_filter->pf_video_filter = I420_YUY2_Filter;
                    break;

                case VLC_CODEC_YVYU:
                    p_filter->pf_video_filter = I420_YVYU_Filter;
                    break;

                case VLC_CODEC_UYVY:
                    p_filter->pf_video_filter = I420_UYVY_Filter;
                    break;
#if !defined (MODULE_NAME_IS_i420_yuy2_altivec)
                case VLC_FOURCC('I','U','Y','V'):
                    p_filter->pf_video_filter = I420_IUYV_Filter;
                    break;

                case VLC_CODEC_CYUV:
                    p_filter->pf_video_filter = I420_cyuv_Filter;
                    break;
#endif

#if defined (MODULE_NAME_IS_i420_yuy2)
                case VLC_CODEC_Y211:
                    p_filter->pf_video_filter = I420_Y211_Filter;
                    break;
#endif
{'fraction_non_alphanumeric': 0.21854205607476634, 'fraction_numerical': 0.0365607476635514, 'mean_word_length': 3.8906764168190127, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2741266', 'n_tokens_mistral': 4793, 'n_tokens_neox': 4321, 'n_words': 936}