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
"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();
#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);
}
#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;
* 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"
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);
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
#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;
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++;
}
#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);