[vlc-devel] [PATCH] color extraction: get_custom_from_yuv{420{, _10}, 422} factorized to get_custom_from_yuv
victorien.lecouviour.tuffet at gmail.com
victorien.lecouviour.tuffet at gmail.com
Tue Apr 4 13:09:14 CEST 2017
From: Psilokos <victorien.lecouviour-tuffet at epitech.eu>
---
modules/video_filter/extract.c | 169 +++++++++++++++--------------------------
1 file changed, 62 insertions(+), 107 deletions(-)
diff --git a/modules/video_filter/extract.c b/modules/video_filter/extract.c
index ba52e235c6..d1506717fa 100644
--- a/modules/video_filter/extract.c
+++ b/modules/video_filter/extract.c
@@ -52,7 +52,7 @@ static void get_custom_from_yuv420( picture_t *, picture_t *, int, int, int, int
static void get_custom_from_yuv420_10( 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 * );
-
+static void get_custom_from_yuv(picture_t *, picture_t *, int const, int const, int const , int const *);
#define COMPONENT_TEXT N_("RGB component to extract")
#define COMPONENT_LONGTEXT N_("RGB component to extract. 0 for Red, 1 for Green and 2 for Blue.")
@@ -186,23 +186,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);
- break;
-
case VLC_CODEC_I420_10L:
case VLC_CODEC_I420_10B:
- get_custom_from_yuv420_10( p_pic, p_outpic,
- Y_PLANE, U_PLANE, V_PLANE,
- p_sys->projection_matrix);
+ case VLC_CODEC_I422:
+ case VLC_CODEC_J422:
+ get_custom_from_yuv(p_pic ,p_outpic, Y_PLANE, U_PLANE, V_PLANE, p_sys->projection_matrix);
break;
CASE_PACKED_YUV_422
@@ -284,103 +272,70 @@ 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 )
+#define IS_420_10(fmt) (fmt == VLC_CODEC_I420_10L || fmt == VLC_CODEC_I420_10B)
+
+#define GET_OUT \
+ do \
+ { \
+ *(*u_out)++ = range((*y_in[0] * m[3] + (**u_in - u) * m[4] + (**v_in - v) * m[5]) / 65536 + u); \
+ *(*v_out)++ = range((*y_in[0] * m[6] + (**u_in - u) * m[7] + (**v_in - v) * m[8]) / 65536 + v); \
+ *y_out[0]++ = range((*y_in[0]++ * m[0] + (**u_in - u) * m[1] + (**v_in - v) * m[2]) / 65536); \
+ *y_out[0]++ = range((*y_in[0]++ * m[0] + (**u_in - u) * m[1] + (**v_in - v) * m[2]) / 65536); \
+ *y_out[1]++ = range((*y_in[1]++ * m[0] + (**u_in - u) * m[1] + (**v_in - v) * m[2]) / 65536); \
+ *y_out[1]++ = range((*y_in[1]++ * m[0] + (*(*u_in)++ - u) * m[1] + (*(*v_in)++ - v) * m[2]) / 65536); \
+ } while (0);
+
+static inline void
+get_out_yuv_8b(uint8_t *y_in[2], uint8_t *y_out[2],
+ uint8_t **u_in, uint8_t **u_out,
+ uint8_t **v_in, uint8_t **v_out,
+ uint16_t const u, uint16_t const v,
+ int const *m, uint16_t(*range)(int))
{
- 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-U8) * m[4] + (*vin-V8) * m[5])
- / 65536 + U8 );
- *vout++ = vlc_uint8( (*y1in * m[6] + (*uin-U8) * m[7] + (*vin-V8) * m[8])
- / 65536 + V8 );
- *y1out++ = vlc_uint8( (*y1in++ * m[0] + (*uin-U8) * m[1] + (*vin-V8) * m[2])
- / 65536 );
- *y1out++ = vlc_uint8( (*y1in++ * m[0] + (*uin-U8) * m[1] + (*vin-V8) * m[2])
- / 65536 );
- *y2out++ = vlc_uint8( (*y2in++ * m[0] + (*uin-U8) * m[1] + (*vin-V8) * m[2])
- / 65536 );
- *y2out++ = vlc_uint8( (*y2in++ * m[0] + (*uin++ - U8) * m[1] + (*vin++ -V8) * 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;
- }
+ GET_OUT;
}
-static void get_custom_from_yuv420_10( picture_t *p_inpic, picture_t *p_outpic,
- int yp, int up, int vp, int *m )
+static inline void
+get_out_yuv_10b(uint16_t *y_in[2], uint16_t *y_out[2],
+ uint16_t **u_in, uint16_t **u_out,
+ uint16_t **v_in, uint16_t **v_out,
+ uint16_t const u, uint16_t const v,
+ int const *m, uint16_t(*range)(int))
{
- uint16_t *y1in = p_inpic->p[yp].p_pixels;
- uint16_t *y2in;
- uint16_t *uin = p_inpic->p[up].p_pixels;
- uint16_t *vin = p_inpic->p[vp].p_pixels;
-
- uint16_t *y1out = p_outpic->p[yp].p_pixels;
- uint16_t *y2out;
- uint16_t *uout = p_outpic->p[up].p_pixels;
- uint16_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;
+ GET_OUT;
+}
- const uint16_t *yend = (uint8_t*)y1in + i_visible_lines * i_in_pitch;
- while( y1in < yend )
+static void
+get_custom_from_yuv(picture_t *p_inpic, picture_t *p_outpic,
+ int const yp, int const up, int const vp, int const *m)
+{
+ 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 uint16_t *y1end = (uint8_t*)y1in + i_visible_pitch;
- y2in = (uint8_t*)y1in + i_in_pitch;
- y2out = (uint8_t*)y1out + i_out_pitch;
- while( y1in < y1end )
- {
- *uout++ = vlc_uint10( (*y1in * m[3] + (*uin-U10) * m[4] + (*vin-V10) * m[5])
- / 65536 + U10 );
- *vout++ = vlc_uint10( (*y1in * m[6] + (*uin-U10) * m[7] + (*vin-V10) * m[8])
- / 65536 + V10);
- *y1out++ = vlc_uint10( (*y1in++ * m[0] + (*uin-U10) * m[1] + (*vin-V10) * m[2])
- / 65536 );
- *y1out++ = vlc_uint10( (*y1in++ * m[0] + (*uin-U10) * m[1] + (*vin-V10) * m[2])
- / 65536 );
- *y2out++ = vlc_uint10( (*y2in++ * m[0] + (*uin-U10) * m[1] + (*vin-V10) * m[2])
- / 65536 );
- *y2out++ = vlc_uint10( (*y2in++ * m[0] + (*uin++ - U10) * m[1] + (*vin++ -V10) * m[2])
- / 65536 );
- }
- y1in = (uint8_t*)y1in + (2*i_in_pitch - i_visible_pitch);
- y1out = (uint8_t*)y1out + (2*i_out_pitch - i_visible_pitch);
- uin = (uint8_t*)uin + (p_inpic->p[up].i_pitch - i_uv_visible_pitch);
- uout = (uint8_t*)uout + (p_outpic->p[up].i_pitch - i_uv_visible_pitch);
- vin = (uint8_t*)vin + (p_inpic->p[vp].i_pitch - i_uv_visible_pitch);
- vout = (uint8_t*)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; )
+ !IS_420_10(p_inpic->format.i_chroma)
+ ? get_out_yuv_8b(y_in, y_out, &u_in, &u_out, &v_in, &v_out, U8, V8, m, &vlc_uint8)
+ : get_out_yuv_10b(y_in, y_out, &u_in, &u_out, &v_in, &v_out, U10, V10, m, &vlc_uint10);
+ 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