Compare commits

...

3 commits

Author SHA1 Message Date
Bastien Nocera e2f06e8f1e lib: Remove num_stripes from fpi_assemble_frames() 2019-08-05 19:04:25 +02:00
Bastien Nocera 22a252c57e lib: Remove num_stripes from fpi_do_movement_estimation() 2019-08-05 18:57:55 +02:00
Bastien Nocera 3953436f0a lib: Remove num_stripes from do_movement_estimation()
We never used a number of stripes that didn't match the length of the
list anyway.

Closes: #132
2019-08-05 18:55:41 +02:00
7 changed files with 36 additions and 63 deletions

View file

@ -611,8 +611,8 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer)
/* send stop capture bits */
aes_write_regv(dev, capture_stop, G_N_ELEMENTS(capture_stop), stub_capture_stop_cb, NULL);
aesdev->strips = g_slist_reverse(aesdev->strips);
fpi_do_movement_estimation(&assembling_ctx, aesdev->strips, aesdev->strips_len);
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips, aesdev->strips_len);
fpi_do_movement_estimation(&assembling_ctx, aesdev->strips);
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips);
img->flags |= FP_IMG_PARTIAL;
g_slist_free_full(aesdev->strips, g_free);
aesdev->strips = NULL;

View file

@ -482,10 +482,8 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer,
struct fp_img *img;
aesdev->strips = g_slist_reverse(aesdev->strips);
fpi_do_movement_estimation(&assembling_ctx,
aesdev->strips, aesdev->strips_len);
img = fpi_assemble_frames(&assembling_ctx,
aesdev->strips, aesdev->strips_len);
fpi_do_movement_estimation(&assembling_ctx, aesdev->strips);
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips);
img->flags |= FP_IMG_PARTIAL;
g_slist_free_full(aesdev->strips, g_free);
aesdev->strips = NULL;

View file

@ -244,8 +244,7 @@ static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer)
struct fp_img *img;
aesdev->strips = g_slist_reverse(aesdev->strips);
img = fpi_assemble_frames(&assembling_ctx,
aesdev->strips, aesdev->strips_len);
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips);
img->flags |= FP_IMG_PARTIAL;
g_slist_free_full(aesdev->strips, g_free);
aesdev->strips = NULL;

View file

@ -305,7 +305,7 @@ static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer)
struct fp_img *img;
aesdev->strips = g_slist_reverse(aesdev->strips);
img = fpi_assemble_frames(aesdev->assembling_ctx, aesdev->strips, aesdev->strips_len);
img = fpi_assemble_frames(aesdev->assembling_ctx, aesdev->strips);
img->flags |= aesdev->extra_img_flags;
g_slist_foreach(aesdev->strips, (GFunc) g_free, NULL);
g_slist_free(aesdev->strips);

View file

@ -307,8 +307,8 @@ static void elan_submit_image(struct fp_img_dev *dev)
assembling_ctx.frame_height = elandev->frame_height;
assembling_ctx.image_width = elandev->frame_width * 3 / 2;
g_slist_foreach(raw_frames, (GFunc) elandev->process_frame, &frames);
fpi_do_movement_estimation(&assembling_ctx, frames, num_frames);
img = fpi_assemble_frames(&assembling_ctx, frames, num_frames);
fpi_do_movement_estimation(&assembling_ctx, frames);
img = fpi_assemble_frames(&assembling_ctx, frames);
img->flags |= FP_IMG_PARTIAL;
fpi_imgdev_image_captured(dev, img);

View file

@ -121,13 +121,12 @@ static void 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
@ -135,39 +134,34 @@ static unsigned int 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 {
struct fpi_frame *cur_stripe = list_entry->data;
prev_stripe = stripes->data;
for (l = stripes; l != NULL; l = l->next, num_frames++) {
struct fpi_frame *cur_stripe = l->data;
if (reverse) {
find_overlap(ctx, prev_stripe, cur_stripe, &min_error);
cur_stripe->delta_y = -cur_stripe->delta_y;
cur_stripe->delta_x = -cur_stripe->delta_x;
}
else
} else {
find_overlap(ctx, cur_stripe, prev_stripe, &min_error);
}
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;
}
/**
* fpi_do_movement_estimation:
* @ctx: #fpi_frame_asmbl_ctx - frame assembling context
* @stripes: a singly-linked list of #fpi_frame
* @num_stripes: number of items in @stripes to process
*
* fpi_do_movement_estimation() estimates the movement between adjacent
* frames, populating @delta_x and @delta_y values for each #fpi_frame.
@ -175,19 +169,17 @@ static unsigned int do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx,
* This function is used for devices that don't do movement estimation
* in hardware. If hardware movement estimation is supported, the driver
* should populate @delta_x and @delta_y instead.
*
* Note that @num_stripes might be shorter than the length of the list,
* if some stripes should be skipped.
*/
void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx,
GSList *stripes, size_t num_stripes)
GSList *stripes)
{
int err, rev_err;
err = do_movement_estimation(ctx, stripes, num_stripes, FALSE);
rev_err = do_movement_estimation(ctx, stripes, num_stripes, TRUE);
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);
}
}
@ -256,45 +248,34 @@ static inline void aes_blit_stripe(struct fpi_frame_asmbl_ctx *ctx,
* fpi_assemble_frames:
* @ctx: #fpi_frame_asmbl_ctx - frame assembling context
* @stripes: linked list of #fpi_frame
* @num_stripes: number of items in @stripes to process
*
* fpi_assemble_frames() assembles individual frames into a single image.
* It expects @delta_x and @delta_y of #fpi_frame to be populated.
*
* Note that @num_stripes might be shorter than the length of the list,
* if some stripes should be skipped.
*
* Returns: a newly allocated #fp_img.
*/
struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx,
GSList *stripes, size_t num_stripes)
GSList *stripes)
{
GSList *stripe;
GSList *l;
struct fp_img *img;
int height = 0;
int i, y, x;
int y, x;
gboolean reverse = FALSE;
struct fpi_frame *fpi_frame;
//FIXME g_return_if_fail
BUG_ON(num_stripes == 0);
BUG_ON(ctx->image_width < ctx->frame_width);
/* Calculate height */
i = 0;
stripe = stripes;
/* No offset for 1st image */
fpi_frame = stripe->data;
fpi_frame = stripes->data;
fpi_frame->delta_x = 0;
fpi_frame->delta_y = 0;
do {
fpi_frame = stripe->data;
for (l = stripes; l != NULL; l = l->next) {
fpi_frame = l->data;
height += fpi_frame->delta_y;
i++;
stripe = g_slist_next(stripe);
} while (i < num_stripes);
}
fp_dbg("height is %d", height);
@ -314,13 +295,11 @@ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx,
img->height = height;
/* Assemble stripes */
i = 0;
stripe = stripes;
y = reverse ? (height - ctx->frame_height) : 0;
x = (ctx->image_width - ctx->frame_width) / 2;
do {
fpi_frame = stripe->data;
for (l = stripes; l != NULL; l = l->next) {
fpi_frame = l->data;
if(reverse) {
y += fpi_frame->delta_y;
@ -333,10 +312,7 @@ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx,
y += fpi_frame->delta_y;
x += fpi_frame->delta_x;
}
stripe = g_slist_next(stripe);
i++;
} while (i < num_stripes);
}
return img;
}

View file

@ -63,10 +63,10 @@ struct fpi_frame_asmbl_ctx {
};
void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx,
GSList *stripes, size_t num_stripes);
GSList *stripes);
struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx,
GSList *stripes, size_t num_stripes);
GSList *stripes);
/**
* fpi_line_asmbl_ctx: