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
b9936e59
Commit
b9936e59
authored
Feb 17, 2014
by
Ronald S. Bultje
Committed by
Michael Niedermayer
Feb 19, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tiny_ssim: add per-frame metrics and final ssim db number.
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
d0e23629
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
16 deletions
+53
-16
tiny_ssim.c
tests/tiny_ssim.c
+53
-16
No files found.
tests/tiny_ssim.c
View file @
b9936e59
...
...
@@ -27,10 +27,19 @@
* overlapped 8x8 block sums, rather than the original gaussian weights.
*/
#include "config.h"
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#if HAVE_ISATTY
#if HAVE_IO_H
#include <io.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#endif
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
...
...
@@ -149,11 +158,31 @@ uint64_t ssd_plane( const uint8_t *pix1, const uint8_t *pix2, int size )
return
ssd
;
}
double
ssd_to_psnr
(
uint64_t
ssd
,
uint64_t
denom
)
static
double
ssd_to_psnr
(
uint64_t
ssd
,
uint64_t
denom
)
{
return
-
10
*
log
((
double
)
ssd
/
(
denom
*
255
*
255
))
/
log
(
10
);
}
static
double
ssim_db
(
double
ssim
,
double
weight
)
{
return
10
*
(
log
(
weight
)
/
log
(
10
)
-
log
(
weight
-
ssim
)
/
log
(
10
));
}
static
void
print_results
(
uint64_t
ssd
[
3
],
double
ssim
[
3
],
int
frames
,
int
w
,
int
h
)
{
printf
(
"PSNR Y:%.3f U:%.3f V:%.3f All:%.3f | "
,
ssd_to_psnr
(
ssd
[
0
],
(
uint64_t
)
frames
*
w
*
h
),
ssd_to_psnr
(
ssd
[
1
],
(
uint64_t
)
frames
*
w
*
h
/
4
),
ssd_to_psnr
(
ssd
[
2
],
(
uint64_t
)
frames
*
w
*
h
/
4
),
ssd_to_psnr
(
ssd
[
0
]
+
ssd
[
1
]
+
ssd
[
2
],
(
uint64_t
)
frames
*
w
*
h
*
3
/
2
)
);
printf
(
"SSIM Y:%.5f U:%.5f V:%.5f All:%.5f (%.5f)"
,
ssim
[
0
]
/
frames
,
ssim
[
1
]
/
frames
,
ssim
[
2
]
/
frames
,
(
ssim
[
0
]
*
4
+
ssim
[
1
]
+
ssim
[
2
])
/
(
frames
*
6
),
ssim_db
(
ssim
[
0
]
*
4
+
ssim
[
1
]
+
ssim
[
2
],
frames
*
6
));
}
int
main
(
int
argc
,
char
*
argv
[])
{
FILE
*
f
[
2
];
...
...
@@ -163,7 +192,7 @@ int main(int argc, char* argv[])
double
ssim
[
3
]
=
{
0
,
0
,
0
};
int
frame_size
,
w
,
h
;
int
frames
,
seek
;
int
i
;
int
i
,
istty
=
1
;
if
(
argc
<
4
||
2
!=
sscanf
(
argv
[
3
],
"%dx%d"
,
&
w
,
&
h
)
)
{
...
...
@@ -186,31 +215,39 @@ int main(int argc, char* argv[])
seek
=
argc
<
5
?
0
:
atoi
(
argv
[
4
]);
fseek
(
f
[
seek
<
0
],
seek
<
0
?
-
seek
:
seek
,
SEEK_SET
);
#if HAVE_ISATTY
istty
=
isatty
(
0
)
&&
isatty
(
2
);
#endif
for
(
frames
=
0
;;
frames
++
)
{
uint64_t
ssd_one
[
3
];
double
ssim_one
[
3
];
if
(
fread
(
buf
[
0
],
frame_size
,
1
,
f
[
0
])
!=
1
)
break
;
if
(
fread
(
buf
[
1
],
frame_size
,
1
,
f
[
1
])
!=
1
)
break
;
for
(
i
=
0
;
i
<
3
;
i
++
)
{
ssd
[
i
]
+=
ssd_plane
(
plane
[
0
][
i
],
plane
[
1
][
i
],
w
*
h
>>
2
*!!
i
);
ssim
[
i
]
+=
ssim_plane
(
plane
[
0
][
i
],
w
>>!!
i
,
plane
[
1
][
i
],
w
>>!!
i
,
w
>>!!
i
,
h
>>!!
i
,
temp
,
NULL
);
ssd_one
[
i
]
=
ssd_plane
(
plane
[
0
][
i
],
plane
[
1
][
i
],
w
*
h
>>
2
*!!
i
);
ssim_one
[
i
]
=
ssim_plane
(
plane
[
0
][
i
],
w
>>!!
i
,
plane
[
1
][
i
],
w
>>!!
i
,
w
>>!!
i
,
h
>>!!
i
,
temp
,
NULL
);
ssd
[
i
]
+=
ssd_one
[
i
];
ssim
[
i
]
+=
ssim_one
[
i
];
}
printf
(
"Frame %d | "
,
frames
);
print_results
(
ssd_one
,
ssim_one
,
1
,
w
,
h
);
if
(
istty
)
{
printf
(
"
\r
"
);
fflush
(
stdout
);
}
else
printf
(
"
\n
"
);
}
if
(
!
frames
)
return
0
;
printf
(
"PSNR Y:%.3f U:%.3f V:%.3f All:%.3f
\n
"
,
ssd_to_psnr
(
ssd
[
0
],
(
uint64_t
)
frames
*
w
*
h
),
ssd_to_psnr
(
ssd
[
1
],
(
uint64_t
)
frames
*
w
*
h
/
4
),
ssd_to_psnr
(
ssd
[
2
],
(
uint64_t
)
frames
*
w
*
h
/
4
),
ssd_to_psnr
(
ssd
[
0
]
+
ssd
[
1
]
+
ssd
[
2
],
(
uint64_t
)
frames
*
w
*
h
*
3
/
2
)
);
printf
(
"SSIM Y:%.5f U:%.5f V:%.5f All:%.5f
\n
"
,
ssim
[
0
]
/
frames
,
ssim
[
1
]
/
frames
,
ssim
[
2
]
/
frames
,
(
ssim
[
0
]
*
4
+
ssim
[
1
]
+
ssim
[
2
])
/
(
frames
*
6
)
);
printf
(
"Total %d frames | "
,
frames
);
print_results
(
ssd
,
ssim
,
frames
,
w
,
h
);
printf
(
"
\n
"
);
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