[NORMATIVE] Film grain scale parameter
BUG=aomedia:1400
Change-Id: I9cf4f0de4fb15295e4acbd8b511d93abd7897165
diff --git a/aom_dsp/grain_synthesis.c b/aom_dsp/grain_synthesis.c
index cd6cbf0..dad0170 100644
--- a/aom_dsp/grain_synthesis.c
+++ b/aom_dsp/grain_synthesis.c
@@ -386,6 +386,7 @@
int luma_block_size_y, int luma_block_size_x, int luma_grain_stride,
int left_pad, int top_pad, int right_pad, int bottom_pad) {
int bit_depth = params->bit_depth;
+ int gauss_sec_shift = 12 - bit_depth + params->grain_scale_shift;
int num_pos_luma = 2 * params->ar_coeff_lag * (params->ar_coeff_lag + 1);
int rounding_offset = (1 << (params->ar_coeff_shift - 1));
@@ -394,8 +395,8 @@
for (int j = 0; j < luma_block_size_x; j++)
luma_grain_block[i * luma_grain_stride + j] =
(gaussian_sequence[get_random_number(gauss_bits)] +
- ((1 << (12 - bit_depth)) >> 1)) >>
- (12 - bit_depth);
+ ((1 << gauss_sec_shift) >> 1)) >>
+ gauss_sec_shift;
for (int i = top_pad; i < luma_block_size_y - bottom_pad; i++)
for (int j = left_pad; j < luma_block_size_x - right_pad; j++) {
@@ -421,6 +422,7 @@
int chroma_block_size_x, int chroma_grain_stride, int left_pad, int top_pad,
int right_pad, int bottom_pad) {
int bit_depth = params->bit_depth;
+ int gauss_sec_shift = 12 - bit_depth + params->grain_scale_shift;
int num_pos_chroma =
2 * params->ar_coeff_lag * (params->ar_coeff_lag + 1) + 1;
@@ -430,12 +432,12 @@
for (int j = 0; j < chroma_block_size_x; j++) {
cb_grain_block[i * chroma_grain_stride + j] =
(gaussian_sequence[get_random_number(gauss_bits)] +
- ((1 << (12 - bit_depth)) >> 1)) >>
- (12 - bit_depth);
+ ((1 << gauss_sec_shift) >> 1)) >>
+ gauss_sec_shift;
cr_grain_block[i * chroma_grain_stride + j] =
(gaussian_sequence[get_random_number(gauss_bits)] +
- ((1 << (12 - bit_depth)) >> 1)) >>
- (12 - bit_depth);
+ ((1 << gauss_sec_shift) >> 1)) >>
+ gauss_sec_shift;
}
for (int i = top_pad; i < chroma_block_size_y - bottom_pad; i++)
diff --git a/aom_dsp/grain_synthesis.h b/aom_dsp/grain_synthesis.h
index 6bad640..a856d78 100644
--- a/aom_dsp/grain_synthesis.h
+++ b/aom_dsp/grain_synthesis.h
@@ -76,6 +76,8 @@
int chroma_scaling_from_luma;
+ int grain_scale_shift;
+
uint16_t random_seed;
} aom_film_grain_t;
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 6a168e9..b5fa065 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2269,6 +2269,8 @@
pars->ar_coeff_shift = aom_rb_read_literal(rb, 2) + 6; // 6 + value
+ pars->grain_scale_shift = aom_rb_read_literal(rb, 2);
+
if (pars->num_cb_points) {
pars->cb_mult = aom_rb_read_literal(rb, 8);
pars->cb_luma_mult = aom_rb_read_literal(rb, 8);
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index c12016d..4152165 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -3409,6 +3409,8 @@
aom_wb_write_literal(wb, pars->ar_coeff_shift - 6, 2); // 8 + value
+ aom_wb_write_literal(wb, pars->grain_scale_shift, 2);
+
if (pars->num_cb_points) {
aom_wb_write_literal(wb, pars->cb_mult, 8);
aom_wb_write_literal(wb, pars->cb_luma_mult, 8);
diff --git a/av1/encoder/grain_test_vectors.h b/av1/encoder/grain_test_vectors.h
index 054c3d9..c1ce84b 100644
--- a/av1/encoder/grain_test_vectors.h
+++ b/av1/encoder/grain_test_vectors.h
@@ -71,6 +71,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /* chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 2 */
@@ -108,17 +109,18 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 3 */
{
1 /* apply_grain */,
1 /* update_parameters */,
- { { 0, 96 }, { 255, 96 } },
+ { { 0, 192 }, { 255, 192 } },
2 /* num_points_y */,
- { { 0, 64 }, { 255, 64 } },
+ { { 0, 128 }, { 255, 128 } },
2 /* num_cb_points */,
- { { 0, 64 }, { 255, 64 } },
+ { { 0, 128 }, { 255, 128 } },
2 /* num_cr_points */,
11 /* scaling_shift */,
3 /* ar_coeff_lag */,
@@ -145,6 +147,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 1 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 4 */
@@ -212,6 +215,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 5 */
@@ -269,6 +273,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
1063 /* random_seed */
},
/* Test 6 */
@@ -321,6 +326,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
2754 /* random_seed */
},
/* Test 7 */
@@ -373,6 +379,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 8 */
@@ -410,6 +417,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 9 */
@@ -438,6 +446,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 10 */
@@ -466,6 +475,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 11 */
@@ -523,6 +533,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
1357 /* random_seed */
},
/* Test 12 */
@@ -581,6 +592,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 13 */
@@ -624,6 +636,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 14 */
@@ -667,6 +680,7 @@
1 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 15 */
@@ -695,6 +709,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
1 /*chroma_scaling_from_luma*/,
+ 0 /* grain_scale_shift*/,
45231 /* random_seed */
},
/* Test 16 */
@@ -734,7 +749,7 @@
{ 203, 85 },
},
8 /* num_cr_points */,
- 11 /* scaling_shift */,
+ 10 /* scaling_shift */,
3 /* ar_coeff_lag */,
{
4, 1, 3, 0, 1, -3, 8, -3, 7, -23, 1, -25,
@@ -759,6 +774,7 @@
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
+ 2 /* grain_scale_shift*/,
45231 /* random_seed */
},
};