[vlc-devel] [PATCH 1/2] 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 18:12:48 CEST 2017
From: Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com>
---
modules/video_filter/sharpen.c | 104 +++++++++++++++++++++++++++++------------
1 file changed, 74 insertions(+), 30 deletions(-)
diff --git a/modules/video_filter/sharpen.c b/modules/video_filter/sharpen.c
index e578e7f0dc..bc572445c3 100644
--- a/modules/video_filter/sharpen.c
+++ b/modules/video_filter/sharpen.c
@@ -119,7 +119,10 @@ 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;
}
@@ -132,7 +135,7 @@ static int Create( vlc_object_t *p_this )
p_filter->pf_video_filter = Filter;
config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
- p_filter->p_cfg );
+ p_filter->p_cfg );
float sigma = var_CreateGetFloatCommand( p_filter, FILTER_PREFIX "sigma" );
init_precalc_table(p_filter->p_sys, sigma);
@@ -167,6 +170,69 @@ static void Destroy( vlc_object_t *p_this )
* until it is displayed and switch the two rendering buffers, preparing next
* frame.
*****************************************************************************/
+
+#define IS_10BITS_PIX_SZ(fmt) (fmt == VLC_CODEC_I420_10L || fmt == VLC_CODEC_I420_10B)
+
+#define CAST_TO_REAL_SZ(addr) ((data_t *)(addr))
+
+#define FILTER_PIX_SZ() \
+ do \
+ { \
+ unsigned data_sz = sizeof(data_t); \
+ \
+ for( unsigned i = 1; i < i_visible_lines - 1; i++ ) \
+ { \
+ *CAST_TO_REAL_SZ(p_out + i * i_out_pitch) = *CAST_TO_REAL_SZ(p_src + i * i_src_pitch); \
+ \
+ for( unsigned j = data_sz; j < i_visible_pitch - 1; j += data_sz ) \
+ { \
+ pix = (*CAST_TO_REAL_SZ(p_src + (i - 1) * i_src_pitch + j - data_sz) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i - 1) * i_src_pitch + j ) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i - 1) * i_src_pitch + j + data_sz) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i ) * i_src_pitch + j - data_sz) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i ) * i_src_pitch + j ) << v[1]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i ) * i_src_pitch + j + data_sz) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i + 1) * i_src_pitch + j - data_sz) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i + 1) * i_src_pitch + j ) * v[0]) + \
+ (*CAST_TO_REAL_SZ(p_src + (i + 1) * i_src_pitch + j + data_sz) * v[0]); \
+ \
+ pix = pix >= 0 ? VLC_CLIP(pix, 0, maxval) : -VLC_CLIP(pix * -1, 0, maxval); \
+ *CAST_TO_REAL_SZ(p_out + i * i_out_pitch + j) = \
+ VLC_CLIP( *CAST_TO_REAL_SZ(p_src + i * i_src_pitch + j) + ((pix * sigma) >> 20), 0, maxval); \
+ } \
+ *CAST_TO_REAL_SZ(p_out + i * i_out_pitch + i_visible_pitch - data_sz) = \
+ *CAST_TO_REAL_SZ(p_src + i * i_src_pitch + i_visible_pitch - data_sz); \
+ } \
+ memcpy(&p_out[(i_visible_lines - 1) * i_out_pitch], \
+ &p_src[(i_visible_lines - 1) * i_src_pitch], i_visible_pitch); \
+ } while (0);
+
+static inline void filter_8b_pix_sz( uint8_t *restrict p_out,
+ uint8_t *restrict p_src,
+ int i_src_pitch ,int i_out_pitch, int pix,
+ const int v[2],
+ const unsigned i_visible_lines,
+ const unsigned i_visible_pitch,
+ const int sigma, const int maxval )
+{
+ typedef uint8_t data_t;
+
+ FILTER_PIX_SZ();
+}
+
+static inline void filter_10b_pix_sz( uint8_t *restrict p_out,
+ uint8_t *restrict p_src,
+ int i_src_pitch ,int i_out_pitch,
+ int pix, const int v[2],
+ const unsigned i_visible_lines,
+ const unsigned i_visible_pitch,
+ const int sigma, const int maxval )
+{
+ typedef uint16_t data_t;
+
+ FILTER_PIX_SZ();
+}
+
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{
picture_t *p_outpic;
@@ -175,8 +241,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
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);
@@ -199,32 +264,11 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
memcpy(p_out, p_src, i_visible_pitch);
- for( unsigned i = 1; i < i_visible_lines - 1; i++ )
- {
- 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];
- }
- memcpy(&p_out[(i_visible_lines - 1) * i_out_pitch],
- &p_src[(i_visible_lines - 1) * i_src_pitch], i_visible_pitch);
+ !IS_10BITS_PIX_SZ(p_pic->format.i_chroma)
+ ? filter_8b_pix_sz(p_out, p_src, i_src_pitch, i_out_pitch, pix, v,
+ i_visible_lines, i_visible_pitch, sigma, 255)
+ : filter_10b_pix_sz(p_out, p_src, i_src_pitch, i_out_pitch, pix, v,
+ i_visible_lines, i_visible_pitch, sigma, 1023);
vlc_mutex_unlock( &p_filter->p_sys->lock );
--
2.12.0
More information about the vlc-devel
mailing list