[FFmpeg-devel] [PATCH] lavfi: add xbr filter

Nicolas George george at nsup.org
Mon Oct 27 10:02:25 CET 2014


Le sextidi 6 brumaire, an CCXXIII, arwa arif a écrit :
> I have done all the changes except rgb to yuv conversion. I will most
> probably do it by tonight.

> +    /*Convert RGB to Y'UV*/
> +    int y = r * .299000 + g * .587000 + b * .114000;
> +    int u = r * -.168736 + g * -.331264 + b * .500000;
> +    int v = r * .500000 + g * -.418688 + b * -.081312;
> +
> +    /*Add HQx filters threshold & return*/
> +    return (y*48) + (u*7) + (v*6);

A bit of maths would greatly help simplifying the code here. I am too lazy
to make the computations myself, so according to PARI/GP, just copy-pasting
your formulas (and trimming useless zeros from the output to make it more
readable):

? y = r * .299000 + g * .587000 + b * .114000;
? u = r * -.168736 + g * -.331264 + b * .500000;
? v = r * .500000 + g * -.418688 + b * -.081312;
? (y*48) + (u*7) + (v*6)
%4 = 16.170848*r + (23.345024*g + 8.484128*b)

Since your numbers are all integers in the [-255;+255] range and your
computations are made on 32-bits integers, scaling everything by a factor K
would work for K between roughly 256 and 170000. Using 65536 seems like a
good choice:

return (1059773 * r + 1529939 * g + 556016 * b) >> 16;

Of course, in this kind of case, a comment must be added to explain where
the numbers come from.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141027/4cdb79d8/attachment.asc>


More information about the ffmpeg-devel mailing list