comparison 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
comparison
equal deleted inserted replaced
251:75091bfc577b 252:ddb1a0e94cf4
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */ 18 */
19 #include <stdlib.h> 19 #include <stdlib.h>
20 #include <stdio.h> 20 #include <stdio.h>
21 #include <math.h>
21 #include "avcodec.h" 22 #include "avcodec.h"
22 #include "dsputil.h" 23 #include "dsputil.h"
23 #include "simple_idct.h" 24 #include "simple_idct.h"
24 25
25 void (*ff_idct)(DCTELEM *block); 26 void (*ff_idct)(DCTELEM *block);
574 block_permute(default_non_intra_matrix); 575 block_permute(default_non_intra_matrix);
575 } 576 }
576 577
577 build_zigzag_end(); 578 build_zigzag_end();
578 } 579 }
580
581 void get_psnr(UINT8 *orig_image[3], UINT8 *coded_image[3],
582 int orig_linesize[3], int coded_linesize,
583 AVCodecContext *avctx)
584 {
585 int quad, diff, x, y;
586 UINT8 *orig, *coded;
587 UINT32 *sq = squareTbl + 256;
588
589 quad = 0;
590 diff = 0;
591
592 /* Luminance */
593 orig = orig_image[0];
594 coded = coded_image[0];
595
596 for (y=0;y<avctx->height;y++) {
597 for (x=0;x<avctx->width;x++) {
598 diff = *(orig + x) - *(coded + x);
599 quad += sq[diff];
600 }
601 orig += orig_linesize[0];
602 coded += coded_linesize;
603 }
604
605 avctx->psnr_y = (float) quad / (float) (avctx->width * avctx->height);
606
607 if (avctx->psnr_y) {
608 avctx->psnr_y = (float) (255 * 255) / avctx->psnr_y;
609 avctx->psnr_y = 10 * (float) log10 (avctx->psnr_y);
610 } else
611 avctx->psnr_y = 99.99;
612 }
613