Removed unused vp8_recon_intra4x4mb function
[libvpx.git] / vp8 / encoder / psnr.c
blobdc2a03b69083e581cc339797eabec7cc2d38b1af
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 #include "vpx_scale/yv12config.h"
13 #include "math.h"
14 #include "systemdependent.h" /* for vp8_clear_system_state() */
16 #define MAX_PSNR 60
18 double vp8_mse2psnr(double Samples, double Peak, double Mse)
20 double psnr;
22 if ((double)Mse > 0.0)
23 psnr = 10.0 * log10(Peak * Peak * Samples / Mse);
24 else
25 psnr = MAX_PSNR; // Limit to prevent / 0
27 if (psnr > MAX_PSNR)
28 psnr = MAX_PSNR;
30 return psnr;
33 double vp8_calc_psnr(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, double *YPsnr, double *UPsnr, double *VPsnr, double *sq_error)
35 int i, j;
36 int Diff;
37 double frame_psnr;
38 double Total;
39 double grand_total;
40 unsigned char *src = source->y_buffer;
41 unsigned char *dst = dest->y_buffer;
43 Total = 0.0;
44 grand_total = 0.0;
46 // Loop throught the Y plane raw and reconstruction data summing (square differences)
47 for (i = 0; i < source->y_height; i++)
50 for (j = 0; j < source->y_width; j++)
52 Diff = (int)(src[j]) - (int)(dst[j]);
53 Total += Diff * Diff;
56 src += source->y_stride;
57 dst += dest->y_stride;
60 // Work out Y PSNR
61 *YPsnr = vp8_mse2psnr(source->y_height * source->y_width, 255.0, Total);
62 grand_total += Total;
63 Total = 0;
66 // Loop through the U plane
67 src = source->u_buffer;
68 dst = dest->u_buffer;
70 for (i = 0; i < source->uv_height; i++)
73 for (j = 0; j < source->uv_width; j++)
75 Diff = (int)(src[j]) - (int)(dst[j]);
76 Total += Diff * Diff;
79 src += source->uv_stride;
80 dst += dest->uv_stride;
83 // Work out U PSNR
84 *UPsnr = vp8_mse2psnr(source->uv_height * source->uv_width, 255.0, Total);
85 grand_total += Total;
86 Total = 0;
89 // V PSNR
90 src = source->v_buffer;
91 dst = dest->v_buffer;
93 for (i = 0; i < source->uv_height; i++)
96 for (j = 0; j < source->uv_width; j++)
98 Diff = (int)(src[j]) - (int)(dst[j]);
99 Total += Diff * Diff;
102 src += source->uv_stride;
103 dst += dest->uv_stride;
106 // Work out UV PSNR
107 *VPsnr = vp8_mse2psnr(source->uv_height * source->uv_width, 255.0, Total);
108 grand_total += Total;
109 Total = 0;
111 // Work out total PSNR
112 frame_psnr = vp8_mse2psnr(source->y_height * source->y_width * 3 / 2 , 255.0, grand_total);
114 *sq_error = 1.0 * grand_total;
116 return frame_psnr;