Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
dd33637c
Commit
dd33637c
authored
Oct 14, 2013
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tiny_psnr: switch f32 handling to floating point
Also add support for f64.
parent
29c455ce
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
30 deletions
+84
-30
tiny_psnr.c
tests/tiny_psnr.c
+84
-30
No files found.
tests/tiny_psnr.c
View file @
dd33637c
...
@@ -23,8 +23,11 @@
...
@@ -23,8 +23,11 @@
#include <string.h>
#include <string.h>
#include <inttypes.h>
#include <inttypes.h>
#include <assert.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include "libavutil/intfloat.h"
#include "libavutil/intfloat.h"
#include "libavutil/intreadwrite.h"
#define FFMIN(a, b) ((a) > (b) ? (b) : (a))
#define FFMIN(a, b) ((a) > (b) ? (b) : (a))
#define F 100
#define F 100
...
@@ -107,21 +110,26 @@ static float get_f32l(uint8_t *p)
...
@@ -107,21 +110,26 @@ static float get_f32l(uint8_t *p)
return
v
.
f
;
return
v
.
f
;
}
}
static
double
get_f64l
(
uint8_t
*
p
)
{
return
av_int2double
(
AV_RL64
(
p
));
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
i
,
j
;
int
i
,
j
;
uint64_t
sse
=
0
;
uint64_t
sse
=
0
;
uint64_t
dev
;
double
sse_d
=
0
.
0
;
FILE
*
f
[
2
];
FILE
*
f
[
2
];
uint8_t
buf
[
2
][
SIZE
];
uint8_t
buf
[
2
][
SIZE
];
uint64_t
psnr
;
int
len
=
1
;
int
len
=
1
;
int64_t
max
;
int64_t
max
;
int
shift
=
argc
<
5
?
0
:
atoi
(
argv
[
4
]);
int
shift
=
argc
<
5
?
0
:
atoi
(
argv
[
4
]);
int
skip_bytes
=
argc
<
6
?
0
:
atoi
(
argv
[
5
]);
int
skip_bytes
=
argc
<
6
?
0
:
atoi
(
argv
[
5
]);
int
size0
=
0
;
int
size0
=
0
;
int
size1
=
0
;
int
size1
=
0
;
int
maxdist
=
0
;
uint64_t
maxdist
=
0
;
double
maxdist_d
=
0
.
0
;
if
(
argc
<
3
)
{
if
(
argc
<
3
)
{
printf
(
"tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]
\n
"
);
printf
(
"tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]
\n
"
);
...
@@ -136,6 +144,8 @@ int main(int argc, char *argv[])
...
@@ -136,6 +144,8 @@ int main(int argc, char *argv[])
len
=
2
;
len
=
2
;
}
else
if
(
!
strcmp
(
argv
[
3
],
"f32"
))
{
}
else
if
(
!
strcmp
(
argv
[
3
],
"f32"
))
{
len
=
4
;
len
=
4
;
}
else
if
(
!
strcmp
(
argv
[
3
],
"f64"
))
{
len
=
8
;
}
else
{
}
else
{
char
*
end
;
char
*
end
;
len
=
strtol
(
argv
[
3
],
&
end
,
0
);
len
=
strtol
(
argv
[
3
],
&
end
,
0
);
...
@@ -184,15 +194,15 @@ int main(int argc, char *argv[])
...
@@ -184,15 +194,15 @@ int main(int argc, char *argv[])
int
s1
=
fread
(
buf
[
1
],
1
,
SIZE
,
f
[
1
]);
int
s1
=
fread
(
buf
[
1
],
1
,
SIZE
,
f
[
1
]);
for
(
j
=
0
;
j
<
FFMIN
(
s0
,
s1
);
j
+=
len
)
{
for
(
j
=
0
;
j
<
FFMIN
(
s0
,
s1
);
j
+=
len
)
{
switch
(
len
)
{
case
1
:
case
2
:
{
int64_t
a
=
buf
[
0
][
j
];
int64_t
a
=
buf
[
0
][
j
];
int64_t
b
=
buf
[
1
][
j
];
int64_t
b
=
buf
[
1
][
j
];
int
dist
;
int
dist
;
if
(
len
==
2
)
{
if
(
len
==
2
)
{
a
=
get_s16l
(
buf
[
0
]
+
j
);
a
=
get_s16l
(
buf
[
0
]
+
j
);
b
=
get_s16l
(
buf
[
1
]
+
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
{
}
else
{
a
=
buf
[
0
][
j
];
a
=
buf
[
0
][
j
];
b
=
buf
[
1
][
j
];
b
=
buf
[
1
][
j
];
...
@@ -201,6 +211,25 @@ int main(int argc, char *argv[])
...
@@ -201,6 +211,25 @@ int main(int argc, char *argv[])
dist
=
abs
(
a
-
b
);
dist
=
abs
(
a
-
b
);
if
(
dist
>
maxdist
)
if
(
dist
>
maxdist
)
maxdist
=
dist
;
maxdist
=
dist
;
break
;
}
case
4
:
case
8
:
{
double
dist
,
a
,
b
;
if
(
len
==
8
)
{
a
=
get_f64l
(
buf
[
0
]
+
j
);
b
=
get_f64l
(
buf
[
1
]
+
j
);
}
else
{
a
=
get_f32l
(
buf
[
0
]
+
j
);
b
=
get_f32l
(
buf
[
1
]
+
j
);
}
dist
=
fabs
(
a
-
b
);
sse_d
+=
(
a
-
b
)
*
(
a
-
b
);
if
(
dist
>
maxdist_d
)
maxdist_d
=
dist
;
break
;
}
}
}
}
size0
+=
s0
;
size0
+=
s0
;
size1
+=
s1
;
size1
+=
s1
;
...
@@ -211,16 +240,41 @@ int main(int argc, char *argv[])
...
@@ -211,16 +240,41 @@ int main(int argc, char *argv[])
i
=
FFMIN
(
size0
,
size1
)
/
len
;
i
=
FFMIN
(
size0
,
size1
)
/
len
;
if
(
!
i
)
if
(
!
i
)
i
=
1
;
i
=
1
;
dev
=
int_sqrt
(((
sse
/
i
)
*
F
*
F
)
+
(((
sse
%
i
)
*
F
*
F
)
+
i
/
2
)
/
i
);
switch
(
len
)
{
case
1
:
case
2
:
{
uint64_t
psnr
;
uint64_t
dev
=
int_sqrt
(((
sse
/
i
)
*
F
*
F
)
+
(((
sse
%
i
)
*
F
*
F
)
+
i
/
2
)
/
i
);
if
(
sse
)
if
(
sse
)
psnr
=
((
2
*
log16
(
max
<<
16
)
+
log16
(
i
)
-
log16
(
sse
))
*
psnr
=
((
2
*
log16
(
max
<<
16
)
+
log16
(
i
)
-
log16
(
sse
))
*
284619LL
*
F
+
(
1LL
<<
31
))
/
(
1LL
<<
32
);
284619LL
*
F
+
(
1LL
<<
31
))
/
(
1LL
<<
32
);
else
else
psnr
=
1000
*
F
-
1
;
// floating point free infinity :)
psnr
=
1000
*
F
-
1
;
// floating point free infinity :)
printf
(
"stddev:%5d.%02d PSNR:%3d.%02d MAXDIFF:%5d
bytes:%9d/%9d
\n
"
,
printf
(
"stddev:%5d.%02d PSNR:%3d.%02d MAXDIFF:%5"
PRIu64
"
bytes:%9d/%9d
\n
"
,
(
int
)(
dev
/
F
),
(
int
)(
dev
%
F
),
(
int
)(
dev
/
F
),
(
int
)(
dev
%
F
),
(
int
)(
psnr
/
F
),
(
int
)(
psnr
%
F
),
(
int
)(
psnr
/
F
),
(
int
)(
psnr
%
F
),
maxdist
,
size0
,
size1
);
maxdist
,
size0
,
size1
);
break
;
}
case
4
:
case
8
:
{
char
psnr_str
[
64
];
double
dev
=
sqrt
(
sse_d
/
i
);
uint64_t
scale
=
(
len
==
4
)
?
(
1ULL
<<
24
)
:
(
1ULL
<<
32
);
if
(
sse_d
)
{
double
psnr
=
2
*
log
(
DBL_MAX
)
-
log
(
i
/
sse_d
);
snprintf
(
psnr_str
,
sizeof
(
psnr_str
),
"%5.02f"
,
psnr
);
}
else
snprintf
(
psnr_str
,
sizeof
(
psnr_str
),
"inf"
);
maxdist
=
maxdist_d
*
scale
;
printf
(
"stddev:%10.2f PSNR:%s MAXDIFF:%10"
PRIu64
" bytes:%9d/%9d
\n
"
,
dev
*
scale
,
psnr_str
,
maxdist
,
size0
,
size1
);
break
;
}
}
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment