[vlc-devel] [PATCH v2 1/1] video-filtering_sharpening: add YUV 4:2:0 10b support
victorien.lecouviour.tuffet at gmail.com
victorien.lecouviour.tuffet at gmail.com
Wed Apr 5 20:41:35 CEST 2017
From: Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com>
I removed the clip function 'cause it was designed for 8bits channels and it's not needed anymore.
I removed the locks 'cause they were useless, the SharpenCallback and the precalc_table 'cause they weren't used.
---
modules/video_filter/sharpen.c | 163 ++++++++++++++---------------------------
1 file changed, 56 insertions(+), 107 deletions(-)
diff --git a/modules/video_filter/sharpen.c b/modules/video_filter/sharpen.c
index e578e7f0dc..20e01f1eaa 100644
--- a/modules/video_filter/sharpen.c
+++ b/modules/video_filter/sharpen.c
@@ -53,8 +53,6 @@ static int Create ( vlc_object_t * );
static void Destroy ( vlc_object_t * );
static picture_t *Filter( filter_t *, picture_t * );
-static int SharpenCallback( vlc_object_t *, char const *,
- vlc_value_t, vlc_value_t, void * );
#define SHARPEN_HELP N_("Augment contrast between contours.")
#define FILTER_PREFIX "sharpen-"
@@ -80,35 +78,6 @@ static const char *const ppsz_filter_options[] = {
};
/*****************************************************************************
- * filter_sys_t: Sharpen video filter descriptor
- *****************************************************************************
- * This structure is part of the video output thread descriptor.
- * It describes the Sharpen specific properties of an output thread.
- *****************************************************************************/
-
-struct filter_sys_t
-{
- vlc_mutex_t lock;
- int tab_precalc[512];
-};
-
-/*****************************************************************************
- * clip: avoid negative value and value > 255
- *****************************************************************************/
-inline static int32_t clip( int32_t a )
-{
- return (a > 255) ? 255 : (a < 0) ? 0 : a;
-}
-
-static void init_precalc_table(filter_sys_t *p_filter, float sigma)
-{
- for(int i = 0; i < 512; ++i)
- {
- p_filter->tab_precalc[i] = (i - 256) * sigma;
- }
-}
-
-/*****************************************************************************
* Create: allocates Sharpen video thread output method
*****************************************************************************
* This function allocates and initializes a Sharpen vout method.
@@ -119,27 +88,18 @@ static int Create( vlc_object_t *p_this )
const vlc_fourcc_t fourcc = p_filter->fmt_in.video.i_chroma;
const vlc_chroma_description_t *p_chroma = vlc_fourcc_GetChromaDescription( fourcc );
- if( !p_chroma || p_chroma->plane_count != 3 || p_chroma->pixel_size != 1 ) {
+ if( !p_chroma || p_chroma->plane_count != 3 ||
+ (p_chroma->pixel_size != 1 &&
+ p_filter->fmt_in.video.i_chroma != VLC_CODEC_I420_10L &&
+ p_filter->fmt_in.video.i_chroma != VLC_CODEC_I420_10B)) {
msg_Err( p_filter, "Unsupported chroma (%4.4s)", (char*)&fourcc );
return VLC_EGENERIC;
}
- /* Allocate structure */
- p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
- if( p_filter->p_sys == NULL )
- return VLC_ENOMEM;
-
p_filter->pf_video_filter = Filter;
config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
- p_filter->p_cfg );
-
- float sigma = var_CreateGetFloatCommand( p_filter, FILTER_PREFIX "sigma" );
- init_precalc_table(p_filter->p_sys, sigma);
-
- vlc_mutex_init( &p_filter->p_sys->lock );
- var_AddCallback( p_filter, FILTER_PREFIX "sigma",
- SharpenCallback, p_filter->p_sys );
+ p_filter->p_cfg );
return VLC_SUCCESS;
}
@@ -150,14 +110,8 @@ static int Create( vlc_object_t *p_this )
*****************************************************************************
* Terminate an output method created by SharpenCreateOutputMethod
*****************************************************************************/
-static void Destroy( vlc_object_t *p_this )
+static void Destroy( __attribute__ (( unused )) vlc_object_t *p_this )
{
- filter_t *p_filter = (filter_t *)p_this;
- filter_sys_t *p_sys = p_filter->p_sys;
-
- var_DelCallback( p_filter, FILTER_PREFIX "sigma", SharpenCallback, p_sys );
- vlc_mutex_destroy( &p_sys->lock );
- free( p_sys );
}
/*****************************************************************************
@@ -167,16 +121,51 @@ static void Destroy( vlc_object_t *p_this )
* until it is displayed and switch the two rendering buffers, preparing next
* frame.
*****************************************************************************/
+
+#define IS_YUV_420_10BITS(fmt) (fmt == VLC_CODEC_I420_10L || fmt == VLC_CODEC_I420_10B)
+
+#define SHARPEN_FRAME(maxval) \
+ do \
+ { \
+ data_t *restrict p_src = (data_t *)p_pic->p[Y_PLANE].p_pixels; \
+ data_t *restrict p_out = (data_t *)p_outpic->p[Y_PLANE].p_pixels; \
+ const unsigned data_sz = sizeof(data_t); \
+ const int i_src_line_len = p_outpic->p[Y_PLANE].i_pitch / data_sz; \
+ const int i_out_line_len = p_pic->p[Y_PLANE].i_pitch / data_sz; \
+ \
+ memcpy(p_out, p_src, i_visible_pitch); \
+ \
+ for( unsigned i = 1; i < i_visible_lines - 1; i++ ) \
+ { \
+ p_out[i * i_out_line_len] = p_src[i * i_src_line_len]; \
+ \
+ for( unsigned j = data_sz; j < i_visible_pitch - 1; j++ ) \
+ { \
+ pix = (p_src[(i - 1) * i_src_line_len + j - 1] * v[0]) + \
+ (p_src[(i - 1) * i_src_line_len + j ] * v[0]) + \
+ (p_src[(i - 1) * i_src_line_len + j + 1] * v[0]) + \
+ (p_src[(i ) * i_src_line_len + j - 1] * v[0]) + \
+ (p_src[(i ) * i_src_line_len + j ] << v[1]) + \
+ (p_src[(i ) * i_src_line_len + j + 1] * v[0]) + \
+ (p_src[(i + 1) * i_src_line_len + j - 1] * v[0]) + \
+ (p_src[(i + 1) * i_src_line_len + j ] * v[0]) + \
+ (p_src[(i + 1) * i_src_line_len + j + 1] * v[0]); \
+ \
+ pix = pix >= 0 ? VLC_CLIP(pix, 0, maxval) : -VLC_CLIP(pix * -1, 0, maxval); \
+ p_out[i * i_out_line_len + j] = VLC_CLIP( p_src[i * i_src_line_len + j] + ((pix * sigma) >> 20), 0, maxval); \
+ } \
+ p_out[i * i_out_line_len + i_visible_pitch / 2 - 1] = \
+ p_src[i * i_src_line_len + i_visible_pitch / 2 - 1]; \
+ } \
+ memcpy(&p_out[(i_visible_lines - 1) * i_out_line_len], \
+ &p_src[(i_visible_lines - 1) * i_src_line_len], i_visible_pitch); \
+ } while (0);
+
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{
picture_t *p_outpic;
- uint8_t *restrict p_src = NULL;
- uint8_t *restrict p_out = NULL;
- int i_src_pitch;
- int i_out_pitch;
int pix;
- const int v1 = -1;
- const int v2 = 3; /* 2^3 = 8 */
+ const int v[2] = { -1, 3 /* 2^3 = 8 */ };
const unsigned i_visible_lines = p_pic->p[Y_PLANE].i_visible_lines;
const unsigned i_visible_pitch = p_pic->p[Y_PLANE].i_visible_pitch;
const int sigma = var_GetFloat( p_filter, FILTER_PREFIX "sigma" ) * (1 << 20);
@@ -188,61 +177,21 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
return NULL;
}
- /* process the Y plane */
- p_src = p_pic->p[Y_PLANE].p_pixels;
- p_out = p_outpic->p[Y_PLANE].p_pixels;
- i_src_pitch = p_pic->p[Y_PLANE].i_pitch;
- i_out_pitch = p_outpic->p[Y_PLANE].i_pitch;
-
- /* perform convolution only on Y plane. Avoid border line. */
- vlc_mutex_lock( &p_filter->p_sys->lock );
-
- memcpy(p_out, p_src, i_visible_pitch);
-
- for( unsigned i = 1; i < i_visible_lines - 1; i++ )
+ if (!IS_YUV_420_10BITS(p_pic->format.i_chroma))
{
- p_out[i * i_out_pitch] = p_src[i * i_src_pitch];
-
- for( unsigned j = 1; j < i_visible_pitch - 1; j++ )
- {
- pix = (p_src[(i - 1) * i_src_pitch + j - 1] * v1) +
- (p_src[(i - 1) * i_src_pitch + j ] * v1) +
- (p_src[(i - 1) * i_src_pitch + j + 1] * v1) +
- (p_src[(i ) * i_src_pitch + j - 1] * v1) +
- (p_src[(i ) * i_src_pitch + j ] << v2) +
- (p_src[(i ) * i_src_pitch + j + 1] * v1) +
- (p_src[(i + 1) * i_src_pitch + j - 1] * v1) +
- (p_src[(i + 1) * i_src_pitch + j ] * v1) +
- (p_src[(i + 1) * i_src_pitch + j + 1] * v1);
-
- pix = pix >= 0 ? clip(pix) : -clip(pix * -1);
- p_out[i * i_out_pitch + j] = clip( p_src[i * i_src_pitch + j]
- + ((pix * sigma) >> 20));
- }
-
- p_out[i * i_out_pitch + i_visible_pitch - 1] =
- p_src[i * i_src_pitch + i_visible_pitch - 1];
+ typedef uint8_t data_t;
+
+ SHARPEN_FRAME(255);
}
- memcpy(&p_out[(i_visible_lines - 1) * i_out_pitch],
- &p_src[(i_visible_lines - 1) * i_src_pitch], i_visible_pitch);
+ else
+ {
+ typedef uint16_t data_t;
- vlc_mutex_unlock( &p_filter->p_sys->lock );
+ SHARPEN_FRAME(1023);
+ }
plane_CopyPixels( &p_outpic->p[U_PLANE], &p_pic->p[U_PLANE] );
plane_CopyPixels( &p_outpic->p[V_PLANE], &p_pic->p[V_PLANE] );
return CopyInfoAndRelease( p_outpic, p_pic );
}
-
-static int SharpenCallback( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval,
- void *p_data )
-{
- VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
- filter_sys_t *p_sys = (filter_sys_t *)p_data;
-
- vlc_mutex_lock( &p_sys->lock );
- init_precalc_table( p_sys, VLC_CLIP( newval.f_float, 0.f, 2.f ) );
- vlc_mutex_unlock( &p_sys->lock );
- return VLC_SUCCESS;
-}
--
2.12.0
More information about the vlc-devel
mailing list