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.
12 #include "vpx_scale/yv12config.h"
14 #include "systemdependent.h" /* for vp8_clear_system_state() */
18 double vp8_mse2psnr(double Samples
, double Peak
, double Mse
)
22 if ((double)Mse
> 0.0)
23 psnr
= 10.0 * log10(Peak
* Peak
* Samples
/ Mse
);
25 psnr
= MAX_PSNR
; // Limit to prevent / 0
33 double vp8_calc_psnr(YV12_BUFFER_CONFIG
*source
, YV12_BUFFER_CONFIG
*dest
, double *YPsnr
, double *UPsnr
, double *VPsnr
, double *sq_error
)
40 unsigned char *src
= source
->y_buffer
;
41 unsigned char *dst
= dest
->y_buffer
;
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
]);
56 src
+= source
->y_stride
;
57 dst
+= dest
->y_stride
;
61 *YPsnr
= vp8_mse2psnr(source
->y_height
* source
->y_width
, 255.0, Total
);
66 // Loop through the U plane
67 src
= source
->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
]);
79 src
+= source
->uv_stride
;
80 dst
+= dest
->uv_stride
;
84 *UPsnr
= vp8_mse2psnr(source
->uv_height
* source
->uv_width
, 255.0, Total
);
90 src
= source
->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
]);
102 src
+= source
->uv_stride
;
103 dst
+= dest
->uv_stride
;
107 *VPsnr
= vp8_mse2psnr(source
->uv_height
* source
->uv_width
, 255.0, Total
);
108 grand_total
+= Total
;
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
;