From dcc04089d129d4f291194a455298cd97bedd9ede Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 5 Aug 2019 18:55:41 +0200 Subject: [PATCH] lib: Remove num_stripes from movement_estimation() fpi_do_movement_estimation is always called with num_stripes set to the length of the list. Rather than using the passed value, assume we should consume all stripes from the list. Closes: #132 --- libfprint/fpi-assembling.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/libfprint/fpi-assembling.c b/libfprint/fpi-assembling.c index b6403cb3..ccd96439 100644 --- a/libfprint/fpi-assembling.c +++ b/libfprint/fpi-assembling.c @@ -128,13 +128,12 @@ find_overlap (struct fpi_frame_asmbl_ctx *ctx, static unsigned int do_movement_estimation (struct fpi_frame_asmbl_ctx *ctx, - GSList *stripes, size_t num_stripes, - gboolean reverse) + GSList *stripes, gboolean reverse) { - GSList *list_entry = stripes; + GSList *l; GTimer *timer; - int frame = 1; - struct fpi_frame *prev_stripe = list_entry->data; + guint num_frames = 0; + struct fpi_frame *prev_stripe; unsigned int min_error; /* Max error is width * height * 255, for AES2501 which has the largest * sensor its 192*16*255 = 783360. So for 32bit value it's ~5482 frame before @@ -142,12 +141,11 @@ do_movement_estimation (struct fpi_frame_asmbl_ctx *ctx, */ unsigned long long total_error = 0; - list_entry = g_slist_next (list_entry); - timer = g_timer_new (); - do + prev_stripe = stripes->data; + for (l = stripes; l != NULL; l = l->next, num_frames++) { - struct fpi_frame *cur_stripe = list_entry->data; + struct fpi_frame *cur_stripe = l->data; if (reverse) { @@ -161,18 +159,14 @@ do_movement_estimation (struct fpi_frame_asmbl_ctx *ctx, } total_error += min_error; - frame++; prev_stripe = cur_stripe; - list_entry = g_slist_next (list_entry); - } - while (frame < num_stripes); g_timer_stop (timer); fp_dbg ("calc delta completed in %f secs", g_timer_elapsed (timer, NULL)); g_timer_destroy (timer); - return total_error / num_stripes; + return total_error / num_frames; } /** @@ -197,11 +191,13 @@ fpi_do_movement_estimation (struct fpi_frame_asmbl_ctx *ctx, { int err, rev_err; - err = do_movement_estimation (ctx, stripes, num_stripes, FALSE); - rev_err = do_movement_estimation (ctx, stripes, num_stripes, TRUE); + g_return_if_fail (g_slist_length(stripes) != num_stripes); + + err = do_movement_estimation (ctx, stripes, FALSE); + rev_err = do_movement_estimation (ctx, stripes, TRUE); fp_dbg ("errors: %d rev: %d", err, rev_err); if (err < rev_err) - do_movement_estimation (ctx, stripes, num_stripes, FALSE); + do_movement_estimation (ctx, stripes, FALSE); } static inline void