Commit 7c7f2f88 authored by Antoine Cellerier's avatar Antoine Cellerier

Some more filter work:

 * adjust.c, extract.c: packed YUV 422 support.
 * filter_picture.h: code shared by some "video filter2" filters.
 * erase.c: validate the picture chroma in the constructor.
parent 5a2dd0dd
This diff is collapsed.
......@@ -120,6 +120,23 @@ static int Create( vlc_object_t *p_this )
filter_sys_t *p_sys;
char *psz_filename;
switch( p_filter->fmt_in.video.i_chroma )
{
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
case VLC_FOURCC('J','4','2','0'):
case VLC_FOURCC('Y','V','1','2'):
case VLC_FOURCC('I','4','2','2'):
case VLC_FOURCC('J','4','2','2'):
break;
default:
msg_Err( p_filter, "Unsupported input chroma (%4s)",
(char*)&(p_filter->fmt_in.video.i_chroma) );
return VLC_EGENERIC;
}
/* Allocate structure */
p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
if( p_filter->p_sys == NULL )
......@@ -181,23 +198,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
picture_t *p_outpic;
if( !p_pic ) return NULL;
switch( p_pic->format.i_chroma )
{
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
case VLC_FOURCC('J','4','2','0'):
case VLC_FOURCC('Y','V','1','2'):
case VLC_FOURCC('I','4','2','2'):
case VLC_FOURCC('J','4','2','2'):
break;
default:
msg_Warn( p_filter, "Unsupported input chroma (%4s)",
(char*)&(p_pic->format.i_chroma) );
if( p_pic->pf_release )
p_pic->pf_release( p_pic );
return NULL;
}
p_outpic = p_filter->pf_vout_buffer_new( p_filter );
if( !p_outpic )
......
......@@ -29,6 +29,7 @@
#include <vlc_vout.h>
#include "vlc_filter.h"
#include "filter_picture.h"
#include "math.h"
......@@ -51,6 +52,7 @@ static void get_blue_from_yuv422( picture_t *, picture_t *, int, int, int );
static void make_projection_matrix( filter_t *, int color, int *matrix );
static void get_custom_from_yuv420( picture_t *, picture_t *, int, int, int, int * );
static void get_custom_from_yuv422( picture_t *, picture_t *, int, int, int, int * );
static void get_custom_from_packedyuv422( picture_t *, picture_t *, int * );
#define COMPONENT_TEXT N_("RGB component to extract")
......@@ -96,6 +98,26 @@ static int Create( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
switch( p_filter->fmt_in.video.i_chroma )
{
case VLC_FOURCC('I','4','2','0'):
case VLC_FOURCC('I','Y','U','V'):
case VLC_FOURCC('J','4','2','0'):
case VLC_FOURCC('Y','V','1','2'):
case VLC_FOURCC('I','4','2','2'):
case VLC_FOURCC('J','4','2','2'):
CASE_PACKED_YUV_422
break;
default:
/* We only want planar YUV 4:2:0 or 4:2:2 */
msg_Err( p_filter, "Unsupported input chroma (%4s)",
(char*)&(p_filter->fmt_in.video.i_chroma) );
return VLC_EGENERIC;
}
/* Allocate structure */
p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
if( p_filter->p_sys == NULL )
......@@ -118,17 +140,10 @@ static int Create( vlc_object_t *p_this )
FILTER_PREFIX "component" );
var_AddCallback( p_filter, FILTER_PREFIX "component",
ExtractCallback, p_filter->p_sys );
switch( p_filter->p_sys->i_color )
{
case RED:
case GREEN:
case BLUE:
break;
default:
make_projection_matrix( p_filter, p_filter->p_sys->i_color,
p_filter->p_sys->projection_matrix );
break;
}
/* Matrix won't be used for RED, GREEN or BLUE in planar formats */
make_projection_matrix( p_filter, p_filter->p_sys->i_color,
p_filter->p_sys->projection_matrix );
p_filter->pf_video_filter = Filter;
......@@ -216,6 +231,11 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
}
break;
CASE_PACKED_YUV_422
get_custom_from_packedyuv422( p_pic, p_outpic,
p_filter->p_sys->projection_matrix );
break;
default:
msg_Warn( p_filter, "Unsupported input chroma (%4s)",
(char*)&(p_pic->format.i_chroma) );
......@@ -392,6 +412,59 @@ static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
}
}
static void get_custom_from_packedyuv422( picture_t *p_inpic,
picture_t *p_outpic,
int *m )
{
int i_y_offset, i_u_offset, i_v_offset;
if( GetPackedYuvOffsets( p_inpic->format.i_chroma, &i_y_offset,
&i_u_offset, &i_v_offset ) != VLC_SUCCESS )
return;
uint8_t *yin = p_inpic->p->p_pixels + i_y_offset;
uint8_t *uin = p_inpic->p->p_pixels + i_u_offset;
uint8_t *vin = p_inpic->p->p_pixels + i_v_offset;
uint8_t *yout = p_outpic->p->p_pixels + i_y_offset;
uint8_t *uout = p_outpic->p->p_pixels + i_u_offset;
uint8_t *vout = p_outpic->p->p_pixels + i_v_offset;
const int i_pitch = p_inpic->p->i_pitch;
const int i_visible_pitch = p_inpic->p->i_visible_pitch;
const int i_visible_lines = p_inpic->p->i_visible_lines;
const uint8_t *yend = yin + i_visible_lines * i_pitch;
while( yin < yend )
{
const uint8_t *ylend = yin + i_visible_pitch;
while( yin < ylend )
{
*uout = crop( (*yin * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5])
/ 65536 + U );
uout += 4;
*vout = crop( (*yin * m[6] + (*uin-U) * m[7] + (*vin-V) * m[8])
/ 65536 + V );
vout += 4;
*yout = crop( (*yin * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
/ 65536 );
yin += 2;
yout += 2;
*yout = crop( (*yin * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
/ 65536 );
yin += 2;
yout += 2;
uin += 4;
vin += 4;
}
yin += i_pitch - i_visible_pitch;
yout += i_pitch - i_visible_pitch;
uin += i_pitch - i_visible_pitch;
uout += i_pitch - i_visible_pitch;
vin += i_pitch - i_visible_pitch;
vout += i_pitch - i_visible_pitch;
}
}
static void get_red_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
int yp, int up, int vp )
{
......@@ -699,17 +772,9 @@ static int ExtractCallback( vlc_object_t *p_this, char const *psz_var,
if( !strcmp( psz_var, FILTER_PREFIX "component" ) )
{
p_sys->i_color = newval.i_int;
switch( p_sys->i_color )
{
case RED:
case GREEN:
case BLUE:
break;
default:
make_projection_matrix( (filter_t *)p_this, p_sys->i_color,
p_sys->projection_matrix );
break;
}
/* Matrix won't be used for RED, GREEN or BLUE in planar formats */
make_projection_matrix( (filter_t *)p_this, p_sys->i_color,
p_sys->projection_matrix );
}
else
{
......
/*****************************************************************************
* filter_picture.h: Common picture functions for filters
*****************************************************************************
* Copyright (C) 2007 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*****************************************************************************/
#define CASE_PACKED_YUV_422 \
case VLC_FOURCC('I','U','Y','V'): \
case VLC_FOURCC('U','Y','V','Y'): \
case VLC_FOURCC('U','Y','N','V'): \
case VLC_FOURCC('Y','4','2','2'): \
case VLC_FOURCC('c','y','u','v'): \
case VLC_FOURCC('Y','U','Y','2'): \
case VLC_FOURCC('Y','U','N','V'): \
case VLC_FOURCC('Y','V','Y','U'):
static inline int GetPackedYuvOffsets( vlc_fourcc_t i_chroma,
int *i_y_offset, int *i_u_offset, int *i_v_offset )
{
switch( i_chroma )
{
case VLC_FOURCC('I','U','Y','V'): /* <-- FIXME: interlaced */
case VLC_FOURCC('U','Y','V','Y'):
case VLC_FOURCC('U','Y','N','V'):
case VLC_FOURCC('Y','4','2','2'):
case VLC_FOURCC('c','y','u','v'): /* <-- FIXME: reverted, whatever that means */
/* UYVY */
*i_y_offset = 1;
*i_u_offset = 0;
*i_v_offset = 2;
return VLC_SUCCESS;
case VLC_FOURCC('Y','U','Y','2'):
case VLC_FOURCC('Y','U','N','V'):
/* YUYV */
*i_y_offset = 0;
*i_u_offset = 1;
*i_v_offset = 3;
return VLC_SUCCESS;
case VLC_FOURCC('Y','V','Y','U'):
/* YVYU */
*i_y_offset = 0;
*i_u_offset = 3;
*i_v_offset = 1;
return VLC_SUCCESS;
default:
return VLC_EGENERIC;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment