ref: c5b32838f4ada4a7590fd7f6de88d6ced95603d1
parent: 5df8d048c67af0e1f5f43eba1eae45fdf16805ff
parent: aec12b097630b9751bcf33306b4f4291c6b98b67
author: Jingning Han <jingning@google.com>
date: Mon Mar 18 00:03:28 EDT 2019
Merge "Setup AQ mode for perceptual quality"
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -3596,7 +3596,7 @@
wiener_variance += cpi->mb_wiener_variance[row * cm->mb_cols + col];
kmeans_data = &cpi->kmeans_data_arr[cpi->kmeans_data_size++];
- kmeans_data->value = log(1 + wiener_variance);
+ kmeans_data->value = log(1.0 + wiener_variance) / log(2.0);
kmeans_data->pos = mi_row * cpi->kmeans_data_stride + mi_col;
if (wiener_variance)
wiener_variance /=
@@ -5876,17 +5876,23 @@
}
// Frame segmentation
- if (cpi->sf.enable_wiener_variance && cm->show_frame) {
- int mi_row, mi_col;
- cpi->kmeans_data_size = 0;
- cpi->kmeans_ctr_num = 5;
+ if (cpi->sf.enable_wiener_variance) {
+ vp9_disable_segmentation(&cm->seg);
+ if (cm->show_frame) {
+ int mi_row, mi_col;
+ cpi->kmeans_data_size = 0;
+ cpi->kmeans_ctr_num = 5;
- for (mi_row = 0; mi_row < cm->mi_rows; mi_row += MI_BLOCK_SIZE)
- for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE)
- wiener_var_rdmult(cpi, BLOCK_64X64, mi_row, mi_col, cpi->rd.RDMULT);
+ for (mi_row = 0; mi_row < cm->mi_rows; mi_row += MI_BLOCK_SIZE)
+ for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE)
+ wiener_var_rdmult(cpi, BLOCK_64X64, mi_row, mi_col, cpi->rd.RDMULT);
- vp9_kmeans(cpi->kmeans_ctr_ls, cpi->kmeans_boundary_ls, cpi->kmeans_ctr_num,
- cpi->kmeans_data_arr, cpi->kmeans_data_size);
+ vp9_kmeans(cpi->kmeans_ctr_ls, cpi->kmeans_boundary_ls,
+ cpi->kmeans_ctr_num, cpi->kmeans_data_arr,
+ cpi->kmeans_data_size);
+
+ vp9_perceptual_aq_mode_setup(cpi, &cm->seg);
+ }
}
{
--- a/vp9/encoder/vp9_segmentation.c
+++ b/vp9/encoder/vp9_segmentation.c
@@ -9,6 +9,7 @@
*/
#include <limits.h>
+#include <math.h>
#include "vpx_mem/vpx_mem.h"
@@ -55,6 +56,46 @@
for (i = 0; i < MAX_SEGMENTS; ++i) {
vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, 2 * (i - (MAX_SEGMENTS / 2)));
+ vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
+ }
+}
+
+void vp9_perceptual_aq_mode_setup(struct VP9_COMP *cpi,
+ struct segmentation *seg) {
+ const VP9_COMMON *cm = &cpi->common;
+ const int seg_counts = cpi->kmeans_ctr_num;
+ const int base_qindex = cm->base_qindex;
+ const double base_qstep = vp9_convert_qindex_to_q(base_qindex, cm->bit_depth);
+ const double mid_ctr = cpi->kmeans_ctr_ls[seg_counts / 2];
+ const double var_diff_scale = 8.0;
+ int i;
+
+ assert(seg_counts <= MAX_SEGMENTS);
+
+ vp9_enable_segmentation(seg);
+ vp9_clearall_segfeatures(seg);
+ seg->abs_delta = SEGMENT_DELTADATA;
+
+ for (i = 0; i < seg_counts / 2; ++i) {
+ double wiener_var_diff = mid_ctr - cpi->kmeans_ctr_ls[i];
+ double target_qstep = base_qstep / (1.0 + wiener_var_diff / var_diff_scale);
+ int target_qindex = vp9_convert_q_to_qindex(target_qstep, cm->bit_depth);
+ assert(wiener_var_diff >= 0.0);
+
+ vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, target_qindex - base_qindex);
+ vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
+ }
+
+ vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, 0);
+ vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
+
+ for (; i < seg_counts; ++i) {
+ double wiener_var_diff = cpi->kmeans_ctr_ls[i] - mid_ctr;
+ double target_qstep = base_qstep * (1.0 + wiener_var_diff / var_diff_scale);
+ int target_qindex = vp9_convert_q_to_qindex(target_qstep, cm->bit_depth);
+ assert(wiener_var_diff >= 0.0);
+
+ vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, target_qindex - base_qindex);
vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
}
}
--- a/vp9/encoder/vp9_segmentation.h
+++ b/vp9/encoder/vp9_segmentation.h
@@ -28,6 +28,9 @@
void vp9_psnr_aq_mode_setup(struct segmentation *seg);
+void vp9_perceptual_aq_mode_setup(struct VP9_COMP *cpi,
+ struct segmentation *seg);
+
// The values given for each segment can be either deltas (from the default
// value chosen for the frame) or absolute values.
//