Commit eeaf8e6b authored by Yaowu Xu's avatar Yaowu Xu

Extend vpxssim to handle more HBD combinations

Change-Id: I38426d946b74c9090a265d34b89e2db6693927c2
parent 38cfc45e
......@@ -82,7 +82,7 @@ double compute_hbd_vpxssim(const YV12_BUFFER_CONFIG *source,
const YV12_BUFFER_CONFIG *dest,
uint32_t in_bd, uint32_t bd) {
double ssim, weight;
ssim = vpx_highbd_calc_ssim(source, dest, &weight, bd);
ssim = vpx_highbd_calc_ssim(source, dest, &weight, bd, in_bd);
return 100 * pow(ssim / weight, 8.0);
}
......@@ -209,11 +209,11 @@ INSTANTIATE_TEST_CASE_P(
MetricTestTParam(&compute_vpxssim, &compute_hbd_vpxssim, 8, 10,
kSsim_thresh),
MetricTestTParam(&compute_vpxssim, &compute_hbd_vpxssim, 10, 10,
kSsim_thresh),
kPhvs_thresh),
MetricTestTParam(&compute_vpxssim, &compute_hbd_vpxssim, 8, 12,
kSsim_thresh),
MetricTestTParam(&compute_vpxssim, &compute_hbd_vpxssim, 12, 12,
kSsim_thresh)));
kPhvs_thresh)));
INSTANTIATE_TEST_CASE_P(
FASTSSIM, HBDMetricsTest,
::testing::Values(
......
......@@ -3951,7 +3951,8 @@ static void compute_internal_stats(VP10_COMP *cpi) {
// TODO(yaowu): unify these two versions into one.
#if CONFIG_VP9_HIGHBITDEPTH
if (cm->use_highbitdepth)
frame_ssim2 = vpx_highbd_calc_ssim(orig, recon, &weight, bit_depth);
frame_ssim2 = vpx_highbd_calc_ssim(orig, recon, &weight,
bit_depth, in_bit_depth);
else
frame_ssim2 = vpx_calc_ssim(orig, recon, &weight);
#else
......
......@@ -4345,7 +4345,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
PSNR_STATS psnr2;
double frame_ssim2 = 0, weight = 0;
#if CONFIG_VP9_POSTPROC
if (vpx_alloc_frame_buffer(&cm->post_proc_buffer,
if (vpx_alloc_frame_buffer(pp,
recon->y_crop_width, recon->y_crop_height,
cm->subsampling_x, cm->subsampling_y,
#if CONFIG_VP9_HIGHBITDEPTH
......@@ -4357,7 +4357,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
"Failed to allocate post processing buffer");
}
vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer,
vp9_deblock(cm->frame_to_show, pp,
cm->lf.filter_level * 10 / 6);
#endif
vpx_clear_system_state();
......@@ -4377,7 +4377,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
#if CONFIG_VP9_HIGHBITDEPTH
if (cm->use_highbitdepth) {
frame_ssim2 = vpx_highbd_calc_ssim(orig, recon, &weight,
(int)cm->bit_depth);
bit_depth, in_bit_depth);
} else {
frame_ssim2 = vpx_calc_ssim(orig, recon, &weight);
}
......@@ -4392,12 +4392,12 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
#if CONFIG_VP9_HIGHBITDEPTH
if (cm->use_highbitdepth) {
frame_ssim2 = vpx_highbd_calc_ssim(
orig, &cm->post_proc_buffer, &weight, (int)cm->bit_depth);
orig, pp, &weight, bit_depth, in_bit_depth);
} else {
frame_ssim2 = vpx_calc_ssim(orig, &cm->post_proc_buffer, &weight);
frame_ssim2 = vpx_calc_ssim(orig, pp, &weight);
}
#else
frame_ssim2 = vpx_calc_ssim(orig, &cm->post_proc_buffer, &weight);
frame_ssim2 = vpx_calc_ssim(orig, pp, &weight);
#endif // CONFIG_VP9_HIGHBITDEPTH
cpi->summedp_quality += frame_ssim2 * weight;
......
......@@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <assert.h>
#include <math.h>
#include "./vpx_dsp_rtcd.h"
#include "vpx_dsp/ssim.h"
......@@ -66,16 +67,28 @@ void vpx_highbd_ssim_parms_8x8_c(const uint16_t *s, int sp,
static const int64_t cc1 = 26634; // (64^2*(.01*255)^2
static const int64_t cc2 = 239708; // (64^2*(.03*255)^2
static const int64_t cc1_10 = 428658; // (64^2*(.01*1023)^2
static const int64_t cc2_10 = 3857925; // (64^2*(.03*1023)^2
static const int64_t cc1_12 = 6868593; // (64^2*(.01*4095)^2
static const int64_t cc2_12 = 61817334; // (64^2*(.03*4095)^2
static double similarity(uint32_t sum_s, uint32_t sum_r,
uint32_t sum_sq_s, uint32_t sum_sq_r,
uint32_t sum_sxr, int count) {
uint32_t sum_sxr, int count,
uint32_t bd) {
int64_t ssim_n, ssim_d;
int64_t c1, c2;
// scale the constants by number of pixels
c1 = (cc1 * count * count) >> 12;
c2 = (cc2 * count * count) >> 12;
if (bd == 8) {
// scale the constants by number of pixels
c1 = (cc1 * count * count) >> 12;
c2 = (cc2 * count * count) >> 12;
} else if (bd == 10) {
c1 = (cc1_10 * count * count) >> 12;
c2 = (cc2_10 * count * count) >> 12;
} else if (bd == 12) {
c1 = (cc1_12 * count * count) >> 12;
c2 = (cc2_12 * count * count) >> 12;
}
ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr -
(int64_t) 2 * sum_s * sum_r + c2);
......@@ -91,22 +104,21 @@ static double ssim_8x8(const uint8_t *s, int sp, const uint8_t *r, int rp) {
uint32_t sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0;
vpx_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r,
&sum_sxr);
return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64);
return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64, 8);
}
#if CONFIG_VP9_HIGHBITDEPTH
static double highbd_ssim_8x8(const uint16_t *s, int sp, const uint16_t *r,
int rp, unsigned int bd) {
int rp, uint32_t bd, uint32_t shift) {
uint32_t sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0;
const int oshift = bd - 8;
vpx_highbd_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r,
&sum_sxr);
return similarity(sum_s >> oshift,
sum_r >> oshift,
sum_sq_s >> (2 * oshift),
sum_sq_r >> (2 * oshift),
sum_sxr >> (2 * oshift),
64);
return similarity(sum_s >> shift,
sum_r >> shift,
sum_sq_s >> (2 * shift),
sum_sq_r >> (2 * shift),
sum_sxr >> (2 * shift),
64, bd);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
......@@ -136,7 +148,7 @@ static double vpx_ssim2(const uint8_t *img1, const uint8_t *img2,
#if CONFIG_VP9_HIGHBITDEPTH
static double vpx_highbd_ssim2(const uint8_t *img1, const uint8_t *img2,
int stride_img1, int stride_img2, int width,
int height, unsigned int bd) {
int height, uint32_t bd, uint32_t shift) {
int i, j;
int samples = 0;
double ssim_total = 0;
......@@ -147,7 +159,7 @@ static double vpx_highbd_ssim2(const uint8_t *img1, const uint8_t *img2,
for (j = 0; j <= width - 8; j += 4) {
double v = highbd_ssim_8x8(CONVERT_TO_SHORTPTR(img1 + j), stride_img1,
CONVERT_TO_SHORTPTR(img2 + j), stride_img2,
bd);
bd, shift);
ssim_total += v;
samples++;
}
......@@ -430,21 +442,28 @@ double vpx_get_ssim_metrics(uint8_t *img1, int img1_pitch,
#if CONFIG_VP9_HIGHBITDEPTH
double vpx_highbd_calc_ssim(const YV12_BUFFER_CONFIG *source,
const YV12_BUFFER_CONFIG *dest,
double *weight, unsigned int bd) {
double *weight, uint32_t bd, uint32_t in_bd) {
double a, b, c;
double ssimv;
uint32_t shift = 0;
assert(bd >= in_bd);
shift = bd - in_bd;
a = vpx_highbd_ssim2(source->y_buffer, dest->y_buffer,
source->y_stride, dest->y_stride,
source->y_crop_width, source->y_crop_height, bd);
source->y_crop_width, source->y_crop_height,
in_bd, shift);
b = vpx_highbd_ssim2(source->u_buffer, dest->u_buffer,
source->uv_stride, dest->uv_stride,
source->uv_crop_width, source->uv_crop_height, bd);
source->uv_crop_width, source->uv_crop_height,
in_bd, shift);
c = vpx_highbd_ssim2(source->v_buffer, dest->v_buffer,
source->uv_stride, dest->uv_stride,
source->uv_crop_width, source->uv_crop_height, bd);
source->uv_crop_width, source->uv_crop_height,
in_bd, shift);
ssimv = a * .8 + .1 * (b + c);
......
......@@ -79,7 +79,7 @@ double vpx_calc_fastssim(const YV12_BUFFER_CONFIG *source,
double vpx_highbd_calc_ssim(const YV12_BUFFER_CONFIG *source,
const YV12_BUFFER_CONFIG *dest,
double *weight,
uint32_t bd);
uint32_t bd, uint32_t in_bd);
#endif // CONFIG_VP9_HIGHBITDEPTH
#ifdef __cplusplus
......
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