From 279db4fbc92aab6eb3d1c3e6a31ca23aea7d4ba6 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 1 Feb 2013 08:20:48 +0100 Subject: Put frame_diff and pswap into util --- src/cuttime.c | 32 -------------------------------- src/overlap.c | 32 -------------------------------- src/util.c | 22 ++++++++++++++++++++++ src/util.h | 13 +++++++++++++ 4 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/cuttime.c b/src/cuttime.c index 8fd8a7a..422e4be 100644 --- a/src/cuttime.c +++ b/src/cuttime.c @@ -7,16 +7,6 @@ #include "video_decode.h" #include "util.h" -static inline void -pswap(void **p1, void **p2) -{ - void *tmp; - - tmp = *p1; - *p1 = *p2; - *p2 = tmp; -} - static void start_new_szene(int64_t prev_szene_end, int64_t start) { @@ -28,28 +18,6 @@ start_new_szene(int64_t prev_szene_end, int64_t start) prev_dts_start = start; } -static double -frame_diff(struct video_frame *frame_a, struct video_frame *frame_b) -{ - double average = 0; - uint8_t *row_a = frame_a->data, *col_a = NULL; - uint8_t *row_b = frame_b->data, *col_b = NULL; - - for (int y = 0; y < frame_a->height; ++y) { - col_a = row_a; - col_b = row_b; - for (int x = 0; x < frame_a->width; ++x) { - average += abs(*col_a - *col_b); - col_a++; - col_b++; - } - row_a += frame_a->stride; - row_b += frame_b->stride; - } - - return average / (frame_a->width * frame_a->height); -} - static double frame_average(struct video_frame *frame) { diff --git a/src/overlap.c b/src/overlap.c index a989ccb..207a306 100644 --- a/src/overlap.c +++ b/src/overlap.c @@ -7,38 +7,6 @@ #include "video_decode.h" #include "util.h" -static inline void -pswap(void **p1, void **p2) -{ - void *tmp; - - tmp = *p1; - *p1 = *p2; - *p2 = tmp; -} - -static double -frame_diff(struct video_frame *frame_a, struct video_frame *frame_b) -{ - double average = 0; - uint8_t *row_a = frame_a->data, *col_a = NULL; - uint8_t *row_b = frame_b->data, *col_b = NULL; - - for (int y = 0; y < frame_a->height; ++y) { - col_a = row_a; - col_b = row_b; - for (int x = 0; x < frame_a->width; ++x) { - average += abs(*col_a - *col_b); - col_a++; - col_b++; - } - row_a += frame_a->stride; - row_b += frame_b->stride; - } - - return average / (frame_a->width * frame_a->height); -} - static void usage(void) { diff --git a/src/util.c b/src/util.c index 7b7077d..e642762 100644 --- a/src/util.c +++ b/src/util.c @@ -81,6 +81,28 @@ frame_mix(struct video_frame *frame_a, struct video_frame *frame_b) } } +double +frame_diff(struct video_frame *frame_a, struct video_frame *frame_b) +{ + double average = 0; + uint8_t *row_a = frame_a->data, *col_a = NULL; + uint8_t *row_b = frame_b->data, *col_b = NULL; + + for (int y = 0; y < frame_a->height; ++y) { + col_a = row_a; + col_b = row_b; + for (int x = 0; x < frame_a->width; ++x) { + average += abs(*col_a - *col_b); + col_a++; + col_b++; + } + row_a += frame_a->stride; + row_b += frame_b->stride; + } + + return average / (frame_a->width * frame_a->height); +} + /* print time in format: "hh:mm:ss.xxx" */ void print_time(int64_t msec) { diff --git a/src/util.h b/src/util.h index 5921a86..bc926b6 100644 --- a/src/util.h +++ b/src/util.h @@ -3,6 +3,16 @@ #include +static inline void +pswap(void **p1, void **p2) +{ + void *tmp; + + tmp = *p1; + *p1 = *p2; + *p2 = tmp; +} + int pgm_read(char *filename, unsigned char **buf, int *xsize, int *ysize); @@ -13,6 +23,9 @@ pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename); void frame_mix(struct video_frame *frame_a, struct video_frame *frame_b); +double +frame_diff(struct video_frame *frame_a, struct video_frame *frame_b); + void print_time(int64_t msec); -- cgit