Commit 0c294fab authored by Andrey Norkin's avatar Andrey Norkin

[NORMATIVE] Film grain bug fixes

BUG=aomedia:1348
BUG=aomedia:1347
BUG=aomedia:1345

Change-Id: Ibe94d826b06e44e4ffad5a6ddc24f962b889ae17
parent fa904a09
...@@ -493,6 +493,8 @@ static void generate_chroma_grain_blocks( ...@@ -493,6 +493,8 @@ static void generate_chroma_grain_blocks(
static void init_scaling_function(int scaling_points[][2], int num_points, static void init_scaling_function(int scaling_points[][2], int num_points,
int scaling_lut[]) { int scaling_lut[]) {
if (num_points == 0) return;
for (int i = 0; i < scaling_points[0][0]; i++) for (int i = 0; i < scaling_points[0][0]; i++)
scaling_lut[i] = scaling_points[0][1]; scaling_lut[i] = scaling_points[0][1];
......
...@@ -2209,33 +2209,72 @@ void av1_read_film_grain_params(AV1_COMMON *cm, ...@@ -2209,33 +2209,72 @@ void av1_read_film_grain_params(AV1_COMMON *cm,
aom_film_grain_t *pars = &cm->film_grain_params; aom_film_grain_t *pars = &cm->film_grain_params;
pars->apply_grain = aom_rb_read_bit(rb); pars->apply_grain = aom_rb_read_bit(rb);
if (!pars->apply_grain) return; if (!pars->apply_grain) {
memset(pars, 0, sizeof(*pars));
return;
}
pars->random_seed = aom_rb_read_literal(rb, 16); pars->random_seed = aom_rb_read_literal(rb, 16);
pars->update_parameters = aom_rb_read_bit(rb); pars->update_parameters = aom_rb_read_bit(rb);
if (!pars->update_parameters) return; if (!pars->update_parameters) {
if (cm->frame_type != INTER_FRAME) {
aom_internal_error(
&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"Film grain parameters prediction is only allowed in inter-frames");
}
return;
}
// Scaling functions parameters // Scaling functions parameters
pars->num_y_points = aom_rb_read_literal(rb, 4); // max 14 pars->num_y_points = aom_rb_read_literal(rb, 4); // max 14
if (pars->num_y_points > 14)
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"Number of points for film grain luma scaling function "
"exceeds the maximum value.");
for (int i = 0; i < pars->num_y_points; i++) { for (int i = 0; i < pars->num_y_points; i++) {
pars->scaling_points_y[i][0] = aom_rb_read_literal(rb, 8); pars->scaling_points_y[i][0] = aom_rb_read_literal(rb, 8);
if (i && pars->scaling_points_y[i - 1][0] >= pars->scaling_points_y[i][0])
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"First coordinateg of the scaling function points "
"shall be increasing.");
pars->scaling_points_y[i][1] = aom_rb_read_literal(rb, 8); pars->scaling_points_y[i][1] = aom_rb_read_literal(rb, 8);
} }
pars->chroma_scaling_from_luma = aom_rb_read_bit(rb); pars->chroma_scaling_from_luma = aom_rb_read_bit(rb);
if (!pars->chroma_scaling_from_luma) { if (pars->chroma_scaling_from_luma) {
pars->num_cb_points = 0;
pars->num_cr_points = 0;
} else {
pars->num_cb_points = aom_rb_read_literal(rb, 4); // max 10 pars->num_cb_points = aom_rb_read_literal(rb, 4); // max 10
if (pars->num_cb_points > 10)
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"Number of points for film grain cb scaling function "
"exceeds the maximum value.");
for (int i = 0; i < pars->num_cb_points; i++) { for (int i = 0; i < pars->num_cb_points; i++) {
pars->scaling_points_cb[i][0] = aom_rb_read_literal(rb, 8); pars->scaling_points_cb[i][0] = aom_rb_read_literal(rb, 8);
if (i &&
pars->scaling_points_cb[i - 1][0] >= pars->scaling_points_cb[i][0])
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"First coordinate of the scaling function points "
"shall be increasing.");
pars->scaling_points_cb[i][1] = aom_rb_read_literal(rb, 8); pars->scaling_points_cb[i][1] = aom_rb_read_literal(rb, 8);
} }
pars->num_cr_points = aom_rb_read_literal(rb, 4); // max 10 pars->num_cr_points = aom_rb_read_literal(rb, 4); // max 10
if (pars->num_cr_points > 10)
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"Number of points for film grain cr scaling function "
"exceeds the maximum value.");
for (int i = 0; i < pars->num_cr_points; i++) { for (int i = 0; i < pars->num_cr_points; i++) {
pars->scaling_points_cr[i][0] = aom_rb_read_literal(rb, 8); pars->scaling_points_cr[i][0] = aom_rb_read_literal(rb, 8);
if (i &&
pars->scaling_points_cr[i - 1][0] >= pars->scaling_points_cr[i][0])
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"First coordinate of the scaling function points "
"shall be increasing.");
pars->scaling_points_cr[i][1] = aom_rb_read_literal(rb, 8); pars->scaling_points_cr[i][1] = aom_rb_read_literal(rb, 8);
} }
} }
......
...@@ -3361,7 +3361,10 @@ static void write_film_grain_params(AV1_COMMON *const cm, ...@@ -3361,7 +3361,10 @@ static void write_film_grain_params(AV1_COMMON *const cm,
aom_wb_write_bit(wb, pars->chroma_scaling_from_luma); aom_wb_write_bit(wb, pars->chroma_scaling_from_luma);
if (!pars->chroma_scaling_from_luma) { if (pars->chroma_scaling_from_luma) {
assert(pars->num_cb_points == 0);
assert(pars->num_cr_points == 0);
} else {
aom_wb_write_literal(wb, pars->num_cb_points, 4); // max 10 aom_wb_write_literal(wb, pars->num_cb_points, 4); // max 10
for (int i = 0; i < pars->num_cb_points; i++) { for (int i = 0; i < pars->num_cb_points; i++) {
aom_wb_write_literal(wb, pars->scaling_points_cb[i][0], 8); aom_wb_write_literal(wb, pars->scaling_points_cb[i][0], 8);
......
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