diff options
author | Mans Rullgard <mans@mansr.com> | 2012-07-29 21:10:36 +0400 |
---|---|---|
committer | Mans Rullgard <mans@mansr.com> | 2012-07-30 01:05:09 +0400 |
commit | 9f1280def4e838802806b0762f64a3874d845fda (patch) | |
tree | 2b26d8b9976845f00274f40e9b7ba87f40d4ce7a /tests | |
parent | f3eb00834362273dcb1fd3320faa5f8f5a00fb22 (diff) |
tiny_psnr: support 32-bit float samples
Signed-off-by: Mans Rullgard <mans@mansr.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tiny_psnr.c | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/tests/tiny_psnr.c b/tests/tiny_psnr.c index 1583f2cf7b..5db2662478 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 @@ -88,6 +90,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; +} + int main(int argc, char *argv[]) { int i, j; @@ -96,8 +115,8 @@ int main(int argc, char *argv[]) FILE *f[2]; uint8_t buf[2][SIZE]; uint64_t psnr; - int len = argc < 4 ? 1 : atoi(argv[3]); - int64_t max = (1 << (8 * len)) - 1; + int len = 1; + int64_t max; int shift = argc < 5 ? 0 : atoi(argv[4]); int skip_bytes = argc < 6 ? 0 : atoi(argv[5]); int size0 = 0; @@ -110,6 +129,25 @@ int main(int argc, char *argv[]) return 1; } + 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; + } + } + } + + max = (1 << (8 * len)) - 1; + f[0] = fopen(argv[1], "rb"); f[1] = fopen(argv[2], "rb"); if (!f[0] || !f[1]) { @@ -145,13 +183,19 @@ int main(int argc, char *argv[]) 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); |