mirror of
https://code.videolan.org/videolan/vlc
synced 2024-09-28 23:09:59 +02:00
video filter refactor (trying to reuse functions)
Signed-off-by: Laurent Aimar <fenrir@videolan.org>
This commit is contained in:
parent
cda18d88ba
commit
5c3dd0a324
@ -33,6 +33,7 @@
|
||||
#include <vlc_common.h>
|
||||
#include <vlc_plugin.h>
|
||||
#include <vlc_filter.h>
|
||||
#include "filter_picture.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Module descriptor
|
||||
@ -248,15 +249,6 @@ static void Blend( filter_t *p_filter,
|
||||
/***********************************************************************
|
||||
* Utils
|
||||
***********************************************************************/
|
||||
static inline uint8_t vlc_uint8( int v )
|
||||
{
|
||||
if( v > 255 )
|
||||
return 255;
|
||||
else if( v < 0 )
|
||||
return 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
#define MAX_TRANS 255
|
||||
#define TRANS_BITS 8
|
||||
|
||||
@ -277,39 +269,6 @@ static inline int vlc_alpha( int t, int a )
|
||||
return (t * a) / 255;
|
||||
}
|
||||
|
||||
static inline void yuv_to_rgb( int *r, int *g, int *b,
|
||||
uint8_t y1, uint8_t u1, uint8_t v1 )
|
||||
{
|
||||
/* macros used for YUV pixel conversions */
|
||||
# define SCALEBITS 10
|
||||
# define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
# define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
||||
|
||||
int y, cb, cr, r_add, g_add, b_add;
|
||||
|
||||
cb = u1 - 128;
|
||||
cr = v1 - 128;
|
||||
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
|
||||
g_add = - FIX(0.34414*255.0/224.0) * cb
|
||||
- FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
|
||||
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
|
||||
y = (y1 - 16) * FIX(255.0/219.0);
|
||||
*r = vlc_uint8( (y + r_add) >> SCALEBITS );
|
||||
*g = vlc_uint8( (y + g_add) >> SCALEBITS );
|
||||
*b = vlc_uint8( (y + b_add) >> SCALEBITS );
|
||||
#undef FIX
|
||||
#undef ONE_HALF
|
||||
#undef SCALEBITS
|
||||
}
|
||||
|
||||
static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v,
|
||||
int r, int g, int b )
|
||||
{
|
||||
*y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 );
|
||||
*u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ;
|
||||
*v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ;
|
||||
}
|
||||
|
||||
static uint8_t *vlc_plane_start( int *pi_pitch,
|
||||
const picture_t *p_picture,
|
||||
int i_plane,
|
||||
|
@ -58,6 +58,12 @@ static inline int GetPackedYuvOffsets( vlc_fourcc_t i_chroma,
|
||||
*i_u_offset = 0;
|
||||
*i_v_offset = 2;
|
||||
return VLC_SUCCESS;
|
||||
case VLC_CODEC_VYUY:
|
||||
/* VYUY */
|
||||
*i_y_offset = 1;
|
||||
*i_u_offset = 2;
|
||||
*i_v_offset = 0;
|
||||
return VLC_SUCCESS;
|
||||
case VLC_CODEC_YUYV:
|
||||
/* YUYV */
|
||||
*i_y_offset = 0;
|
||||
@ -75,6 +81,67 @@ static inline int GetPackedYuvOffsets( vlc_fourcc_t i_chroma,
|
||||
}
|
||||
}
|
||||
|
||||
static inline int GetPackedRgbIndexes( const video_format_t *p_fmt, int *i_r_index,
|
||||
int *i_g_index, int *i_b_index )
|
||||
{
|
||||
if( p_fmt->i_chroma != VLC_CODEC_RGB24 && p_fmt->i_chroma != VLC_CODEC_RGB32 )
|
||||
return VLC_EGENERIC;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
const int i_mask_bits = p_fmt->i_chroma == VLC_CODEC_RGB24 ? 24 : 32;
|
||||
*i_r_index = ( i_mask_bits - p_fmt->i_lrshift ) / 8;
|
||||
*i_g_index = ( i_mask_bits - p_fmt->i_lgshift ) / 8;
|
||||
*i_b_index = ( i_mask_bits - p_fmt->i_lbshift ) / 8;
|
||||
#else
|
||||
*i_r_index = p_fmt->i_lrshift / 8;
|
||||
*i_g_index = p_fmt->i_lgshift / 8;
|
||||
*i_b_index = p_fmt->i_lbshift / 8;
|
||||
#endif
|
||||
return VLC_SUCCESS;
|
||||
}
|
||||
|
||||
static inline uint8_t vlc_uint8( int v )
|
||||
{
|
||||
if( v > 255 )
|
||||
return 255;
|
||||
else if( v < 0 )
|
||||
return 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline void yuv_to_rgb( int *r, int *g, int *b,
|
||||
uint8_t y1, uint8_t u1, uint8_t v1 )
|
||||
{
|
||||
/* macros used for YUV pixel conversions */
|
||||
# define SCALEBITS 10
|
||||
# define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
# define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
||||
|
||||
int y, cb, cr, r_add, g_add, b_add;
|
||||
|
||||
cb = u1 - 128;
|
||||
cr = v1 - 128;
|
||||
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
|
||||
g_add = - FIX(0.34414*255.0/224.0) * cb
|
||||
- FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
|
||||
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
|
||||
y = (y1 - 16) * FIX(255.0/219.0);
|
||||
*r = vlc_uint8( (y + r_add) >> SCALEBITS );
|
||||
*g = vlc_uint8( (y + g_add) >> SCALEBITS );
|
||||
*b = vlc_uint8( (y + b_add) >> SCALEBITS );
|
||||
#undef FIX
|
||||
#undef ONE_HALF
|
||||
#undef SCALEBITS
|
||||
}
|
||||
|
||||
static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v,
|
||||
int r, int g, int b )
|
||||
{
|
||||
*y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 );
|
||||
*u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ;
|
||||
*v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
@ -48,8 +48,6 @@ static void PackedYUVPosterize( picture_t *, picture_t *, int);
|
||||
static void RVPosterize( picture_t *, picture_t *, bool, int );
|
||||
static void YuvPosterization( uint8_t *, uint8_t *, uint8_t *, uint8_t *,
|
||||
uint8_t, uint8_t, uint8_t, uint8_t, int );
|
||||
static void yuv2rgb( uint8_t *, uint8_t *, uint8_t *,
|
||||
uint8_t, uint8_t, uint8_t);
|
||||
|
||||
static const char *const ppsz_filter_options[] = {
|
||||
"level", NULL
|
||||
@ -419,13 +417,13 @@ static void YuvPosterization( uint8_t* posterized_y1, uint8_t* posterized_y2,
|
||||
uint8_t* posterized_u, uint8_t* posterized_v,
|
||||
uint8_t y1, uint8_t y2, uint8_t u, uint8_t v,
|
||||
int i_level ) {
|
||||
uint8_t r1, g1, b1; /* for y1 new value */
|
||||
uint8_t r2, b2, g2; /* for y2 new value */
|
||||
uint8_t r3, g3, b3; /* for new values of u and v */
|
||||
int r1, g1, b1; /* for y1 new value */
|
||||
int r2, b2, g2; /* for y2 new value */
|
||||
int r3, g3, b3; /* for new values of u and v */
|
||||
/* fist convert YUV -> RGB */
|
||||
yuv2rgb( &r1, &g1, &b1, y1, u, v );
|
||||
yuv2rgb( &r2, &g2, &b2, y2, u, v );
|
||||
yuv2rgb( &r3, &g3, &b3, ( y1 + y2 ) / 2, u, v );
|
||||
yuv_to_rgb( &r1, &g1, &b1, y1, u, v );
|
||||
yuv_to_rgb( &r2, &g2, &b2, y1, u, v );
|
||||
yuv_to_rgb( &r3, &g3, &b3, ( y1 + y2 ) / 2, u, v );
|
||||
/* round RGB values to specified posterize level */
|
||||
r1 = POSTERIZE_PIXEL( r1, i_level );
|
||||
g1 = POSTERIZE_PIXEL( g1, i_level );
|
||||
@ -443,59 +441,6 @@ static void YuvPosterization( uint8_t* posterized_y1, uint8_t* posterized_y2,
|
||||
*posterized_v = ( ( 112 * r3 - 94 * g3 - 18 * b3 + 128 ) >> 8 ) + 128;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* yuv2rgb: Converts from YUV to RGB color space
|
||||
*****************************************************************************
|
||||
* This function converts YUV values to RGB values using function defined in:
|
||||
* http://msdn.microsoft.com/en-us/library/ms893078
|
||||
*****************************************************************************/
|
||||
static void yuv2rgb( uint8_t* r, uint8_t* g, uint8_t* b, uint8_t y,
|
||||
uint8_t u, uint8_t v )
|
||||
{
|
||||
int16_t c = y - 16;
|
||||
int16_t d = u - 128;
|
||||
int16_t e = v - 128;
|
||||
int16_t noclipped_r = ( 298 * c + 409 * e + 128 ) >> 8;
|
||||
if ( noclipped_r < 0 )
|
||||
{
|
||||
*r=0;
|
||||
}
|
||||
else if ( noclipped_r > 255 )
|
||||
{
|
||||
*r = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
*r = noclipped_r;
|
||||
}
|
||||
int16_t noclipped_g = ( 298 * c - 100 * d - 208 * e + 128 ) >> 8;
|
||||
if ( noclipped_g < 0 )
|
||||
{
|
||||
*g=0;
|
||||
}
|
||||
else if ( noclipped_g > 255 )
|
||||
{
|
||||
*g = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
*g = noclipped_g;
|
||||
}
|
||||
int16_t noclipped_b = ( 298 * c + 516 * d + 128 ) >> 8;
|
||||
if ( noclipped_b < 0 )
|
||||
{
|
||||
*b=0;
|
||||
}
|
||||
else if ( noclipped_b > 255 )
|
||||
{
|
||||
*b = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
*b = noclipped_b;
|
||||
}
|
||||
}
|
||||
|
||||
static int FilterCallback ( vlc_object_t *p_this, char const *psz_var,
|
||||
vlc_value_t oldval, vlc_value_t newval, void *p_data )
|
||||
{
|
||||
|
@ -42,8 +42,6 @@
|
||||
static int Create ( vlc_object_t * );
|
||||
static void Destroy ( vlc_object_t * );
|
||||
|
||||
static void vlc_rgb_index( int *, int *, int *, const video_format_t * );
|
||||
static void vlc_yuv_index( int *, int *, int *, const video_format_t * );
|
||||
static void RVSepia( picture_t *, picture_t *, int );
|
||||
static void PlanarI420Sepia( picture_t *, picture_t *, int);
|
||||
static void PackedYUVSepia( picture_t *, picture_t *, int);
|
||||
@ -207,96 +205,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
|
||||
return CopyInfoAndRelease( p_outpic, p_pic );
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Utils
|
||||
***********************************************************************/
|
||||
static inline uint8_t vlc_uint8( int v )
|
||||
{
|
||||
if( v > 255 )
|
||||
return 255;
|
||||
else if( v < 0 )
|
||||
return 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline void yuv_to_rgb( int *r, int *g, int *b,
|
||||
uint8_t y1, uint8_t u1, uint8_t v1 )
|
||||
{
|
||||
/* macros used for YUV pixel conversions */
|
||||
# define SCALEBITS 10
|
||||
# define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
# define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
||||
|
||||
int y, cb, cr, r_add, g_add, b_add;
|
||||
|
||||
cb = u1 - 128;
|
||||
cr = v1 - 128;
|
||||
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
|
||||
g_add = - FIX(0.34414*255.0/224.0) * cb
|
||||
- FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
|
||||
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
|
||||
y = (y1 - 16) * FIX(255.0/219.0);
|
||||
*r = vlc_uint8( (y + r_add) >> SCALEBITS );
|
||||
*g = vlc_uint8( (y + g_add) >> SCALEBITS );
|
||||
*b = vlc_uint8( (y + b_add) >> SCALEBITS );
|
||||
#undef FIX
|
||||
#undef ONE_HALF
|
||||
#undef SCALEBITS
|
||||
}
|
||||
|
||||
static void vlc_rgb_index( int *pi_rindex, int *pi_gindex, int *pi_bindex,
|
||||
const video_format_t *p_fmt )
|
||||
{
|
||||
if( p_fmt->i_chroma != VLC_CODEC_RGB24 && p_fmt->i_chroma != VLC_CODEC_RGB32 )
|
||||
return;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
const int i_mask_bits = p_fmt->i_chroma == VLC_CODEC_RGB24 ? 24 : 32;
|
||||
*pi_rindex = ( i_mask_bits - p_fmt->i_lrshift ) / 8;
|
||||
*pi_gindex = ( i_mask_bits - p_fmt->i_lgshift ) / 8;
|
||||
*pi_bindex = ( i_mask_bits - p_fmt->i_lbshift ) / 8;
|
||||
#else
|
||||
*pi_rindex = p_fmt->i_lrshift / 8;
|
||||
*pi_gindex = p_fmt->i_lgshift / 8;
|
||||
*pi_bindex = p_fmt->i_lbshift / 8;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void vlc_yuv_index( int *pi_y_index, int *pi_u_index, int *pi_v_index,
|
||||
const video_format_t *p_fmt )
|
||||
{
|
||||
if(
|
||||
p_fmt->i_chroma != VLC_CODEC_UYVY &&
|
||||
p_fmt->i_chroma != VLC_CODEC_VYUY &&
|
||||
p_fmt->i_chroma != VLC_CODEC_YUYV &&
|
||||
p_fmt->i_chroma != VLC_CODEC_YVYU )
|
||||
return;
|
||||
|
||||
switch( p_fmt->i_chroma )
|
||||
{
|
||||
case VLC_CODEC_UYVY:
|
||||
*pi_u_index = 0;
|
||||
*pi_y_index = 1;
|
||||
*pi_v_index = 2;
|
||||
break;
|
||||
case VLC_CODEC_VYUY:
|
||||
*pi_v_index = 0;
|
||||
*pi_y_index = 1;
|
||||
*pi_u_index = 2;
|
||||
break;
|
||||
case VLC_CODEC_YUYV:
|
||||
*pi_y_index = 0;
|
||||
*pi_u_index = 1;
|
||||
*pi_v_index = 3;
|
||||
break;
|
||||
case VLC_CODEC_YVYU:
|
||||
*pi_y_index = 0;
|
||||
*pi_v_index = 1;
|
||||
*pi_u_index = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* PlanarI420Sepia: Applies sepia to one frame of the planar I420 video
|
||||
*****************************************************************************
|
||||
@ -363,7 +271,8 @@ static void PackedYUVSepia( picture_t *p_pic, picture_t *p_outpic,
|
||||
uint8_t *p_in, *p_in_end, *p_line_start, *p_line_end, *p_out;
|
||||
int i_yindex = 1, i_uindex = 2, i_vindex = 0;
|
||||
|
||||
vlc_yuv_index( &i_yindex, &i_vindex, &i_uindex, &p_outpic->format );
|
||||
GetPackedYuvOffsets( p_outpic->format.i_chroma,
|
||||
&i_yindex, &i_uindex, &i_vindex );
|
||||
|
||||
p_in = p_pic->p[0].p_pixels;
|
||||
p_in_end = p_in + p_pic->p[0].i_visible_lines
|
||||
@ -403,7 +312,7 @@ static void RVSepia( picture_t *p_pic, picture_t *p_outpic, int i_intensity )
|
||||
bool b_isRV32 = p_pic->format.i_chroma == VLC_CODEC_RGB32;
|
||||
int i_rindex = 0, i_gindex = 1, i_bindex = 2;
|
||||
|
||||
vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_outpic->format );
|
||||
GetPackedRgbIndexes( &p_outpic->format, &i_rindex, &i_gindex, &i_bindex );
|
||||
|
||||
p_in = p_pic->p[0].p_pixels;
|
||||
p_in_end = p_in + p_pic->p[0].i_visible_lines
|
||||
|
Loading…
Reference in New Issue
Block a user