summaryrefslogtreecommitdiff
path: root/tests/tiny_psnr.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-07-30 23:04:28 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-07-30 23:28:31 +0200
commitb5da7d4c1a7f08f89aece651a8f0f8c4963e5ad9 (patch)
treec5ade4afd26c2cbd5fd7d5442e044e688724269a /tests/tiny_psnr.c
parenta85b4a5696787e36df8d7c805de8f86ea6365acb (diff)
parent6774247a9d7d15033c2b80118c03cb0cb10027df (diff)
downloadffmpeg-b5da7d4c1a7f08f89aece651a8f0f8c4963e5ad9.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: avformat: Drop pointless "format" from container long names swscale: bury one more piece of inline asm under HAVE_INLINE_ASM. wv: K&R formatting cosmetics configure: Add missing descriptions to help output h264_ps: declare array of colorspace strings on its own line. fate: amix: specify f32 sample format for comparison tiny_psnr: support 32-bit float samples eamad/eatgq/eatqi: call special EA IDCT directly eamad: remove use of MpegEncContext mpegvideo: remove unnecessary inclusions of faandct.h af_asyncts: avoid overflow in out_size with large delta values af_asyncts: add first_pts option Conflicts: configure libavcodec/eamad.c libavcodec/h264_ps.c libavformat/crcenc.c libavformat/ffmdec.c libavformat/ffmenc.c libavformat/framecrcenc.c libavformat/md5enc.c libavformat/nutdec.c libavformat/rawenc.c libavformat/yuv4mpeg.c tests/tiny_psnr.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'tests/tiny_psnr.c')
-rw-r--r--tests/tiny_psnr.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/tests/tiny_psnr.c b/tests/tiny_psnr.c
index 4f307b02b2..b4d05d300d 100644
--- a/tests/tiny_psnr.c
+++ b/tests/tiny_psnr.c
@@ -24,6 +24,8 @@
#include <inttypes.h>
#include <assert.h>
+#include "libavutil/intfloat.h"
+
#define FFMIN(a, b) ((a) > (b) ? (b) : (a))
#define F 100
#define SIZE 2048
@@ -103,6 +105,23 @@ static uint64_t int_sqrt(uint64_t a)
return ret;
}
+static int16_t get_s16l(uint8_t *p)
+{
+ union {
+ uint16_t u;
+ int16_t s;
+ } v;
+ v.u = p[0] | p[1] << 8;
+ return v.s;
+}
+
+static float get_f32l(uint8_t *p)
+{
+ union av_intfloat32 v;
+ v.i = p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+ return v.f;
+}
+
static int run_psnr(FILE *f[2], int len, int shift, int skip_bytes)
{
int i, j;
@@ -149,13 +168,19 @@ static int run_psnr(FILE *f[2], int len, int shift, int skip_bytes)
int s0 = fread(buf[0], 1, SIZE, f[0]);
int s1 = fread(buf[1], 1, SIZE, f[1]);
- for (j = 0; j < FFMIN(s0, s1); j++) {
+ for (j = 0; j < FFMIN(s0, s1); j += len) {
int64_t a = buf[0][j];
int64_t b = buf[1][j];
int dist;
if (len == 2) {
- a = (int16_t)(a | (buf[0][++j] << 8));
- b = (int16_t)(b | (buf[1][ j] << 8));
+ a = get_s16l(buf[0] + j);
+ b = get_s16l(buf[1] + j);
+ } else if (len == 4) {
+ a = get_f32l(buf[0] + j) * (1 << 24);
+ b = get_f32l(buf[1] + j) * (1 << 24);
+ } else {
+ a = buf[0][j];
+ b = buf[1][j];
}
sse += (a - b) * (a - b);
dist = abs(a - b);
@@ -188,7 +213,7 @@ static int run_psnr(FILE *f[2], int len, int shift, int skip_bytes)
int main(int argc, char *argv[])
{
FILE *f[2];
- int len = argc < 4 ? 1 : atoi(argv[3]);
+ int len = 1;
int shift_first= argc < 5 ? 0 : atoi(argv[4]);
int skip_bytes = argc < 6 ? 0 : atoi(argv[5]);
int shift_last = shift_first + (argc < 7 ? 0 : atoi(argv[6]));
@@ -196,6 +221,23 @@ int main(int argc, char *argv[])
int max_psnr = -1;
int max_psnr_shift = 0;
+ if (argc > 3) {
+ if (!strcmp(argv[3], "u8")) {
+ len = 1;
+ } else if (!strcmp(argv[3], "s16")) {
+ len = 2;
+ } else if (!strcmp(argv[3], "f32")) {
+ len = 4;
+ } else {
+ char *end;
+ len = strtol(argv[3], &end, 0);
+ if (*end || len > 2) {
+ fprintf(stderr, "Unsupported sample format: %s\n", argv[3]);
+ return 1;
+ }
+ }
+ }
+
if (argc < 3) {
printf("tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes> [<shift search range>]]]]\n");
printf("WAV headers are skipped automatically.\n");