[FFmpeg-devel] [PATCH] avfilter: Refactor vf_psnr sse_line
Suraj Shirvankar
surajshirvankar at gmail.com
Fri Apr 14 19:30:04 EEST 2023
Small refactor to psnr
Signed-off-by: Suraj Shirvankar <surajshirvankar at gmail.com>
---
libavfilter/vf_psnr.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c
index 15cde7e8c8..a0c673831d 100644
--- a/libavfilter/vf_psnr.c
+++ b/libavfilter/vf_psnr.c
@@ -59,7 +59,7 @@ typedef struct PSNRContext {
} PSNRContext;
#define OFFSET(x) offsetof(PSNRContext, x)
-#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
static const AVOption psnr_options[] = {
{"stats_file", "Set file where to store per-frame difference
information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL},
0, 0, FLAGS },
@@ -81,31 +81,26 @@ static inline double get_psnr(double mse, uint64_t
nb_frames, int max)
return 10.0 * log10(pow_2(max) / (mse / nb_frames));
}
-static uint64_t sse_line_8bit(const uint8_t *main_line, const
uint8_t *ref_line, int outw)
-{
- int j;
- unsigned m2 = 0;
-
- for (j = 0; j < outw; j++)
- m2 += pow_2(main_line[j] - ref_line[j]);
+#define SSE_LINE(name, type) \
+ static uint64_t sse_line_##name(const uint8_t *_main_line, \
+ const uint8_t *_ref_line, int outw) \
+ { \
+ int j; \
+ uint64_t m2 = 0; \
+ const type *main_line = (const type *)_main_line; \
+ const type *ref_line = (const type *)_ref_line; \
+ \
+ for (j = 0; j < outw; j++) \
+ m2 += pow_2(main_line[j] - ref_line[j]); \
+ \
+ return m2; \
+ }
- return m2;
-}
+SSE_LINE(8bit, uint8_t)
+SSE_LINE(16bit, uint16_t)
-static uint64_t sse_line_16bit(const uint8_t *_main_line, const
uint8_t *_ref_line, int outw)
+typedef struct ThreadData
{
- int j;
- uint64_t m2 = 0;
- const uint16_t *main_line = (const uint16_t *) _main_line;
- const uint16_t *ref_line = (const uint16_t *) _ref_line;
-
- for (j = 0; j < outw; j++)
- m2 += pow_2(main_line[j] - ref_line[j]);
-
- return m2;
-}
-
-typedef struct ThreadData {
const uint8_t *main_data[4];
const uint8_t *ref_data[4];
int main_linesize[4];
--
2.34.1
More information about the ffmpeg-devel
mailing list