Commit a840cde6 authored by Andrey Norkin's avatar Andrey Norkin

[NORMATIVE] Film grain scale parameter

BUG=aomedia:1400

Change-Id: I9cf4f0de4fb15295e4acbd8b511d93abd7897165
parent 99bac01b
......@@ -386,6 +386,7 @@ static void generate_luma_grain_block(
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 @@ static void generate_luma_grain_block(
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 @@ static void generate_chroma_grain_blocks(
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 @@ static void generate_chroma_grain_blocks(
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++)
......
......@@ -76,6 +76,8 @@ typedef struct {
int chroma_scaling_from_luma;
int grain_scale_shift;
uint16_t random_seed;
} aom_film_grain_t;
......
......@@ -2269,6 +2269,8 @@ void av1_read_film_grain_params(AV1_COMMON *cm,
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);
......
......@@ -3409,6 +3409,8 @@ static void write_film_grain_params(AV1_COMMON *const cm,
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);
......
......@@ -71,6 +71,7 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
{ 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 @@ static aom_film_grain_t film_grain_test_vectors[16] = {
0 /* clip_to_restricted_range */,
8 /* bit_depth */,
0 /*chroma_scaling_from_luma*/,
2 /* grain_scale_shift*/,
45231 /* random_seed */
},
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment