MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / hb_rgb2yuv

Function hb_rgb2yuv

libhb/common.c:6663–6685  ·  view source on GitHub ↗

* hb_rgb2yuv ********************************************************************** * Converts an RGB pixel to a limited range Bt.601 YCrCb pixel. * * This conversion is lossy (due to rounding and clamping). * * Algorithm: * http://en.wikipedia.org/w/index.php?title=YCbCr&oldid=361987695#Technical_details *********************************************************************/

Source from the content-addressed store, hash-verified

6661 * http://en.wikipedia.org/w/index.php?title=YCbCr&oldid=361987695#Technical_details
6662 *********************************************************************/
6663int hb_rgb2yuv(int rgb)
6664{
6665 double r, g, b;
6666 int y, Cr, Cb;
6667
6668 r = (rgb >> 16) & 0xff;
6669 g = (rgb >> 8) & 0xff;
6670 b = (rgb ) & 0xff;
6671
6672 y = 16. + ( 0.257 * r) + (0.504 * g) + (0.098 * b);
6673 Cb = 128. + (-0.148 * r) - (0.291 * g) + (0.439 * b);
6674 Cr = 128. + ( 0.439 * r) - (0.368 * g) - (0.071 * b);
6675
6676 y = (y < 0) ? 0 : y;
6677 Cb = (Cb < 0) ? 0 : Cb;
6678 Cr = (Cr < 0) ? 0 : Cr;
6679
6680 y = (y > 255) ? 255 : y;
6681 Cb = (Cb > 255) ? 255 : Cb;
6682 Cr = (Cr > 255) ? 255 : Cr;
6683
6684 return (y << 16) | (Cr << 8) | Cb;
6685}
6686
6687int hb_rgb2yuv_bt709(int rgb)
6688{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected