Skip to content

Commit

Permalink
Added PSNR calculation in diff-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
figgis committed Jan 30, 2013
1 parent 38aa80f commit f7bd99a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions yv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <sys/ipc.h>
#include <sys/msg.h>

Expand Down Expand Up @@ -45,6 +46,7 @@ void cr_only(void);
void draw_420(void);
void draw_422(void);
Uint32 diff_mode(void);
void calc_psnr(Uint8* frame0, Uint8* frame1);
void usage(char* name);
void mb_loop(char* str, Uint32 rows, Uint8* data, Uint32 pitch);
void show_mb(Uint32 mouse_x, Uint32 mouse_y);
Expand Down Expand Up @@ -423,6 +425,8 @@ Uint32 diff_mode(void)
* Calculate diff and place result where it belongs
* Clear croma data */

calc_psnr(y_tmp, P.y_data);

if (FORMAT == YV12 || FORMAT == IYUV) {
for (Uint32 i = 0; i < P.y_size; i++) {
P.y_data[i] = 0x80 - (y_tmp[i] - P.y_data[i]);
Expand All @@ -444,6 +448,30 @@ Uint32 diff_mode(void)
return 1;
}

void calc_psnr(Uint8* frame0, Uint8* frame1)
{
double mse = 0.0;
double mse_tmp = 0.0;
double psnr = 0.0;

for (Uint32 i = 0; i < P.y_size; i++) {
mse_tmp = abs(frame0[i] - frame1[i]);
mse += mse_tmp * mse_tmp;
}

/* division by zero */
if (mse == 0) {
fprintf(stdout, "PSNR: NaN\n");
return;
}

mse /= P.y_size;

psnr = 10.0*log10((256 * 256) / mse);

fprintf(stdout, "PSNR: %f\n", psnr);
}

void setup_param(void)
{
P.zoom = 1;
Expand Down

0 comments on commit f7bd99a

Please sign in to comment.