From f7a69642a9993e17fa045b12cab55b0493a7f6db Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Wed, 30 May 2012 15:01:03 -0400 Subject: wcap: Convert argb to yv12 using integer math instead Drop from 8% in the profile to 1.8%. --- wcap/vpxenc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'wcap') diff --git a/wcap/vpxenc.c b/wcap/vpxenc.c index 793b73f7..5e9e34d9 100644 --- a/wcap/vpxenc.c +++ b/wcap/vpxenc.c @@ -335,27 +335,29 @@ static inline int rgb_to_yuv(uint32_t format, uint32_t p, int *u, int *v) break; } - y = 0.299 * r + 0.587 * g + 0.114 * b; + y = (19595 * r + 38469 * g + 7472 * b) >> 16; if (y > 255) y = 255; - *u += 0.713 * (r - y); - *v += 0.564 * (b - y); + *u += 46727 * (r - y); + *v += 36962 * (b - y); return y; } static inline int clamp_uv(int u) { - if (u < -512) + int clamp = (u >> 18) + 128; + + if (clamp < 0) return 0; - else if (u > 511) + else if (clamp > 255) return 255; else - return u / 4 + 128; + return clamp; } -static void convert_to_yv12(struct wcap_decoder *wcap, vpx_image_t *img) +void convert_to_yv12(struct wcap_decoder *wcap, vpx_image_t *img) { unsigned char *y1, *y2, *u, *v; uint32_t *p1, *p2, *end; -- cgit v1.2.3