diff dsputil.c @ 252:ddb1a0e94cf4 libavcodec

- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm sure it works ok. Also it's slow, so use it only when you _really_ need to measure quality. - Fix libavcodec Makefile to enable profiling.
author pulento
date Tue, 26 Feb 2002 22:14:27 +0000
parents 0b234715e205
children db20b987c32d
line wrap: on
line diff
--- a/dsputil.c	Fri Feb 22 19:19:01 2002 +0000
+++ b/dsputil.c	Tue Feb 26 22:14:27 2002 +0000
@@ -18,6 +18,7 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
+#include <math.h>
 #include "avcodec.h"
 #include "dsputil.h"
 #include "simple_idct.h"
@@ -576,3 +577,37 @@
     
     build_zigzag_end();
 }
+
+void get_psnr(UINT8 *orig_image[3], UINT8 *coded_image[3],
+              int orig_linesize[3], int coded_linesize,
+              AVCodecContext *avctx)
+{
+    int quad, diff, x, y;
+    UINT8 *orig, *coded;
+    UINT32 *sq = squareTbl + 256;
+    
+    quad = 0;
+    diff = 0;
+    
+    /* Luminance */
+    orig = orig_image[0];
+    coded = coded_image[0];
+    
+    for (y=0;y<avctx->height;y++) {
+        for (x=0;x<avctx->width;x++) {
+            diff = *(orig + x) - *(coded + x);
+            quad += sq[diff];
+        }
+        orig += orig_linesize[0];
+        coded += coded_linesize;
+    }
+   
+    avctx->psnr_y = (float) quad / (float) (avctx->width * avctx->height);
+    
+    if (avctx->psnr_y) {
+        avctx->psnr_y = (float) (255 * 255) / avctx->psnr_y;
+        avctx->psnr_y = 10 * (float) log10 (avctx->psnr_y); 
+    } else
+        avctx->psnr_y = 99.99;
+}
+