@@ -22,16 +22,16 @@ void SharpYuvComputeConversionMatrix(const SharpYuvColorSpace* yuv_color_space,
2222 const float kr = yuv_color_space -> kr ;
2323 const float kb = yuv_color_space -> kb ;
2424 const float kg = 1.0f - kr - kb ;
25- const float cr = 0.5f / (1.0f - kb );
26- const float cb = 0.5f / (1.0f - kr );
25+ const float cb = 0.5f / (1.0f - kb );
26+ const float cr = 0.5f / (1.0f - kr );
2727
2828 const int shift = yuv_color_space -> bit_depth - 8 ;
2929
3030 const float denom = (float )((1 << yuv_color_space -> bit_depth ) - 1 );
3131 float scale_y = 1.0f ;
3232 float add_y = 0.0f ;
33- float scale_u = cr ;
34- float scale_v = cb ;
33+ float scale_u = cb ;
34+ float scale_v = cr ;
3535 float add_uv = (float )(128 << shift );
3636 assert (yuv_color_space -> bit_depth >= 8 );
3737
@@ -59,31 +59,35 @@ void SharpYuvComputeConversionMatrix(const SharpYuvColorSpace* yuv_color_space,
5959}
6060
6161// Matrices are in YUV_FIX fixed point precision.
62- // WebP's matrix, similar but not identical to kRec601LimitedMatrix.
62+ // WebP's matrix, similar but not identical to kRec601LimitedMatrix
63+ // Derived using the following formulas:
64+ // Y = 0.2569 * R + 0.5044 * G + 0.0979 * B + 16
65+ // U = -0.1483 * R - 0.2911 * G + 0.4394 * B + 128
66+ // V = 0.4394 * R - 0.3679 * G - 0.0715 * B + 128
6367static const SharpYuvConversionMatrix kWebpMatrix = {
6468 {16839 , 33059 , 6420 , 16 << 16 },
6569 {-9719 , -19081 , 28800 , 128 << 16 },
6670 {28800 , -24116 , -4684 , 128 << 16 },
6771};
68- // Kr=0.2990f Kb=0.1140f bits =8 range=kSharpYuvRangeLimited
72+ // Kr=0.2990f Kb=0.1140f bit_depth =8 range=kSharpYuvRangeLimited
6973static const SharpYuvConversionMatrix kRec601LimitedMatrix = {
7074 {16829 , 33039 , 6416 , 16 << 16 },
7175 {-9714 , -19071 , 28784 , 128 << 16 },
7276 {28784 , -24103 , -4681 , 128 << 16 },
7377};
74- // Kr=0.2990f Kb=0.1140f bits =8 range=kSharpYuvRangeFull
78+ // Kr=0.2990f Kb=0.1140f bit_depth =8 range=kSharpYuvRangeFull
7579static const SharpYuvConversionMatrix kRec601FullMatrix = {
7680 {19595 , 38470 , 7471 , 0 },
7781 {-11058 , -21710 , 32768 , 128 << 16 },
7882 {32768 , -27439 , -5329 , 128 << 16 },
7983};
80- // Kr=0.2126f Kb=0.0722f bits =8 range=kSharpYuvRangeLimited
84+ // Kr=0.2126f Kb=0.0722f bit_depth =8 range=kSharpYuvRangeLimited
8185static const SharpYuvConversionMatrix kRec709LimitedMatrix = {
8286 {11966 , 40254 , 4064 , 16 << 16 },
8387 {-6596 , -22189 , 28784 , 128 << 16 },
8488 {28784 , -26145 , -2639 , 128 << 16 },
8589};
86- // Kr=0.2126f Kb=0.0722f bits =8 range=kSharpYuvRangeFull
90+ // Kr=0.2126f Kb=0.0722f bit_depth =8 range=kSharpYuvRangeFull
8791static const SharpYuvConversionMatrix kRec709FullMatrix = {
8892 {13933 , 46871 , 4732 , 0 },
8993 {-7509 , -25259 , 32768 , 128 << 16 },
0 commit comments