[vlc-devel] [PATCH 2/4] color extraction: factorize code
victorien.lecouviour.tuffet at gmail.com
victorien.lecouviour.tuffet at gmail.com
Tue Apr 4 18:52:23 CEST 2017
From: Victorien Le Couviour--Tuffet <victorien.lecouviour-tuffet at epitech.eu>
get_custom_from_yuv{40,422} => get_custom_from_yuv
---
modules/video_filter/extract.c | 150 +++++++++++++----------------------------
1 file changed, 46 insertions(+), 104 deletions(-)
diff --git a/modules/video_filter/extract.c b/modules/video_filter/extract.c
index f8bec40aee..a2b37fd4e1 100644
--- a/modules/video_filter/extract.c
+++ b/modules/video_filter/extract.c
@@ -48,8 +48,7 @@ static int ExtractCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
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_yuv( picture_t *, picture_t *, int, int, int, int const * );
static void get_custom_from_packedyuv422( picture_t *, picture_t *, int * );
@@ -183,16 +182,11 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
case VLC_CODEC_I420:
case VLC_CODEC_J420:
case VLC_CODEC_YV12:
- get_custom_from_yuv420( p_pic, p_outpic,
- Y_PLANE, U_PLANE, V_PLANE,
- p_sys->projection_matrix);
- break;
-
case VLC_CODEC_I422:
case VLC_CODEC_J422:
- get_custom_from_yuv422( p_pic, p_outpic,
- Y_PLANE, U_PLANE, V_PLANE,
- p_sys->projection_matrix);
+ get_custom_from_yuv(p_pic, p_outpic,
+ Y_PLANE, U_PLANE, V_PLANE,
+ p_sys->projection_matrix);
break;
CASE_PACKED_YUV_422
@@ -200,13 +194,13 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
p_sys->projection_matrix );
break;
- default:
- vlc_mutex_unlock( &p_sys->lock );
- msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
- (char*)&(p_pic->format.i_chroma) );
- picture_Release( p_pic );
- return NULL;
- }
+ default:
+ vlc_mutex_unlock( &p_sys->lock );
+ msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
+ (char*)&(p_pic->format.i_chroma) );
+ picture_Release( p_pic );
+ return NULL;
+ }
vlc_mutex_unlock( &p_sys->lock );
return CopyInfoAndRelease( p_outpic, p_pic );
@@ -229,6 +223,7 @@ static void mmult( double *res, double *a, double *b )
}
}
}
+
static void make_projection_matrix( filter_t *p_filter, int color, int *matrix )
{
double left_matrix[9] =
@@ -271,95 +266,42 @@ static void make_projection_matrix( filter_t *p_filter, int color, int *matrix )
msg_Dbg( p_filter, "%6d %6d %6d", matrix[6], matrix[7], matrix[8] );
}
-static void get_custom_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
- int yp, int up, int vp, int *m )
-{
- uint8_t *y1in = p_inpic->p[yp].p_pixels;
- uint8_t *y2in;
- uint8_t *uin = p_inpic->p[up].p_pixels;
- uint8_t *vin = p_inpic->p[vp].p_pixels;
-
- uint8_t *y1out = p_outpic->p[yp].p_pixels;
- uint8_t *y2out;
- uint8_t *uout = p_outpic->p[up].p_pixels;
- uint8_t *vout = p_outpic->p[vp].p_pixels;
-
- const int i_in_pitch = p_inpic->p[yp].i_pitch;
- const int i_out_pitch = p_outpic->p[yp].i_pitch;
-
- const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
- const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
- const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
-
- const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
- while( y1in < yend )
- {
- const uint8_t *y1end = y1in + i_visible_pitch;
- y2in = y1in + i_in_pitch;
- y2out = y1out + i_out_pitch;
- while( y1in < y1end )
- {
- *uout++ = vlc_uint8( (*y1in * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5])
- / 65536 + U );
- *vout++ = vlc_uint8( (*y1in * m[6] + (*uin-U) * m[7] + (*vin-V) * m[8])
- / 65536 + V );
- *y1out++ = vlc_uint8( (*y1in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
- / 65536 );
- *y1out++ = vlc_uint8( (*y1in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
- / 65536 );
- *y2out++ = vlc_uint8( (*y2in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
- / 65536 );
- *y2out++ = vlc_uint8( (*y2in++ * m[0] + (*uin++ - U) * m[1] + (*vin++ -V) * m[2])
- / 65536 );
- }
- y1in += 2*i_in_pitch - i_visible_pitch;
- y1out += 2*i_out_pitch - i_visible_pitch;
- uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
- uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
- vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
- vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
- }
-}
-
-static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
- int yp, int up, int vp, int *m )
+static void
+get_custom_from_yuv(picture_t *p_inpic, picture_t *p_outpic,
+ int yp, int up, int vp, int const *m)
{
- uint8_t *y1in = p_inpic->p[yp].p_pixels;
- uint8_t *uin = p_inpic->p[up].p_pixels;
- uint8_t *vin = p_inpic->p[vp].p_pixels;
-
- uint8_t *y1out = p_outpic->p[yp].p_pixels;
- uint8_t *uout = p_outpic->p[up].p_pixels;
- uint8_t *vout = p_outpic->p[vp].p_pixels;
-
- const int i_in_pitch = p_inpic->p[yp].i_pitch;
- const int i_out_pitch = p_outpic->p[yp].i_pitch;
-
- const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
- const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
- const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
-
- const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
- while( y1in < yend )
+ int const i_in_pitch = p_inpic->p[yp].i_pitch;
+ int const i_out_pitch = p_outpic->p[yp].i_pitch;
+ int const i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
+ int const i_visible_lines = p_inpic->p[yp].i_visible_lines;
+ int const i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
+ uint8_t *y_in[2] = { p_inpic->p[yp].p_pixels };
+ uint8_t *u_in = p_inpic->p[up].p_pixels;
+ uint8_t *v_in = p_inpic->p[vp].p_pixels;
+ uint8_t *y_out[2] = { p_outpic->p[yp].p_pixels };
+ uint8_t *u_out = p_outpic->p[up].p_pixels;
+ uint8_t *v_out = p_outpic->p[vp].p_pixels;
+ void *const y_end = y_in[0] + i_visible_lines * i_in_pitch;
+
+ while (y_in[0] < y_end)
{
- const uint8_t *y1end = y1in + i_visible_pitch;
- while( y1in < y1end )
- {
- *uout++ = vlc_uint8( (*y1in * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5])
- / 65536 + U );
- *vout++ = vlc_uint8( (*y1in * m[6] + (*uin-U) * m[7] + (*vin-V) * m[8])
- / 65536 + V );
- *y1out++ = vlc_uint8( (*y1in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
- / 65536 );
- *y1out++ = vlc_uint8( (*y1in++ * m[0] + (*uin++ -U) * m[1] + (*vin++ -V) * m[2])
- / 65536 );
- }
- y1in += i_in_pitch - i_visible_pitch;
- y1out += i_out_pitch - i_visible_pitch;
- uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
- uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
- vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
- vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
+ y_in[1] = y_in[0] + i_in_pitch;
+ y_out[1] = y_out[0] + i_out_pitch;
+ for (void *const y_row_end = y_in[0] + i_visible_pitch; y_in[0] < y_row_end; )
+ {
+ *u_out++ = vlc_uint8((*y_in[0] * m[3] + (*u_in - U) * m[4] + (*v_in - V) * m[5]) / 65536 + U); \
+ *v_out++ = vlc_uint8((*y_in[0] * m[6] + (*u_in - U) * m[7] + (*v_in - V) * m[8]) / 65536 + V); \
+ *y_out[0]++ = vlc_uint8((*y_in[0]++ * m[0] + (*u_in - U) * m[1] + (*v_in - V) * m[2]) / 65536); \
+ *y_out[0]++ = vlc_uint8((*y_in[0]++ * m[0] + (*u_in - U) * m[1] + (*v_in - V) * m[2]) / 65536); \
+ *y_out[1]++ = vlc_uint8((*y_in[1]++ * m[0] + (*u_in - U) * m[1] + (*v_in - V) * m[2]) / 65536); \
+ *y_out[1]++ = vlc_uint8((*y_in[1]++ * m[0] + (*u_in++ - U) * m[1] + (*v_in++ - V) * m[2]) / 65536); \
+ }
+ y_in[0] += 2 * i_in_pitch - i_visible_pitch;
+ y_out[0] += 2 * i_out_pitch - i_visible_pitch;
+ u_in += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
+ u_out += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
+ v_in += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
+ v_out += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
}
}
--
2.12.0
More information about the vlc-devel
mailing list