Compare commits
3 commits
master
...
wip/hadess
Author | SHA1 | Date | |
---|---|---|---|
|
e2f06e8f1e | ||
|
22a252c57e | ||
|
3953436f0a |
7 changed files with 36 additions and 63 deletions
|
@ -611,8 +611,8 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer)
|
||||||
/* send stop capture bits */
|
/* send stop capture bits */
|
||||||
aes_write_regv(dev, capture_stop, G_N_ELEMENTS(capture_stop), stub_capture_stop_cb, NULL);
|
aes_write_regv(dev, capture_stop, G_N_ELEMENTS(capture_stop), stub_capture_stop_cb, NULL);
|
||||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
aesdev->strips = g_slist_reverse(aesdev->strips);
|
||||||
fpi_do_movement_estimation(&assembling_ctx, aesdev->strips, aesdev->strips_len);
|
fpi_do_movement_estimation(&assembling_ctx, 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;
|
img->flags |= FP_IMG_PARTIAL;
|
||||||
g_slist_free_full(aesdev->strips, g_free);
|
g_slist_free_full(aesdev->strips, g_free);
|
||||||
aesdev->strips = NULL;
|
aesdev->strips = NULL;
|
||||||
|
|
|
@ -482,10 +482,8 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer,
|
||||||
struct fp_img *img;
|
struct fp_img *img;
|
||||||
|
|
||||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
aesdev->strips = g_slist_reverse(aesdev->strips);
|
||||||
fpi_do_movement_estimation(&assembling_ctx,
|
fpi_do_movement_estimation(&assembling_ctx, aesdev->strips);
|
||||||
aesdev->strips, aesdev->strips_len);
|
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips);
|
||||||
img = fpi_assemble_frames(&assembling_ctx,
|
|
||||||
aesdev->strips, aesdev->strips_len);
|
|
||||||
img->flags |= FP_IMG_PARTIAL;
|
img->flags |= FP_IMG_PARTIAL;
|
||||||
g_slist_free_full(aesdev->strips, g_free);
|
g_slist_free_full(aesdev->strips, g_free);
|
||||||
aesdev->strips = NULL;
|
aesdev->strips = NULL;
|
||||||
|
|
|
@ -244,8 +244,7 @@ static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer)
|
||||||
struct fp_img *img;
|
struct fp_img *img;
|
||||||
|
|
||||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
aesdev->strips = g_slist_reverse(aesdev->strips);
|
||||||
img = fpi_assemble_frames(&assembling_ctx,
|
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips);
|
||||||
aesdev->strips, aesdev->strips_len);
|
|
||||||
img->flags |= FP_IMG_PARTIAL;
|
img->flags |= FP_IMG_PARTIAL;
|
||||||
g_slist_free_full(aesdev->strips, g_free);
|
g_slist_free_full(aesdev->strips, g_free);
|
||||||
aesdev->strips = NULL;
|
aesdev->strips = NULL;
|
||||||
|
|
|
@ -305,7 +305,7 @@ static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer)
|
||||||
struct fp_img *img;
|
struct fp_img *img;
|
||||||
|
|
||||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
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;
|
img->flags |= aesdev->extra_img_flags;
|
||||||
g_slist_foreach(aesdev->strips, (GFunc) g_free, NULL);
|
g_slist_foreach(aesdev->strips, (GFunc) g_free, NULL);
|
||||||
g_slist_free(aesdev->strips);
|
g_slist_free(aesdev->strips);
|
||||||
|
|
|
@ -307,8 +307,8 @@ static void elan_submit_image(struct fp_img_dev *dev)
|
||||||
assembling_ctx.frame_height = elandev->frame_height;
|
assembling_ctx.frame_height = elandev->frame_height;
|
||||||
assembling_ctx.image_width = elandev->frame_width * 3 / 2;
|
assembling_ctx.image_width = elandev->frame_width * 3 / 2;
|
||||||
g_slist_foreach(raw_frames, (GFunc) elandev->process_frame, &frames);
|
g_slist_foreach(raw_frames, (GFunc) elandev->process_frame, &frames);
|
||||||
fpi_do_movement_estimation(&assembling_ctx, frames, num_frames);
|
fpi_do_movement_estimation(&assembling_ctx, frames);
|
||||||
img = fpi_assemble_frames(&assembling_ctx, frames, num_frames);
|
img = fpi_assemble_frames(&assembling_ctx, frames);
|
||||||
|
|
||||||
img->flags |= FP_IMG_PARTIAL;
|
img->flags |= FP_IMG_PARTIAL;
|
||||||
fpi_imgdev_image_captured(dev, img);
|
fpi_imgdev_image_captured(dev, img);
|
||||||
|
|
|
@ -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,
|
static unsigned int do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx,
|
||||||
GSList *stripes, size_t num_stripes,
|
GSList *stripes, gboolean reverse)
|
||||||
gboolean reverse)
|
|
||||||
{
|
{
|
||||||
GSList *list_entry = stripes;
|
GSList *l;
|
||||||
GTimer *timer;
|
GTimer *timer;
|
||||||
int frame = 1;
|
guint num_frames = 0;
|
||||||
struct fpi_frame *prev_stripe = list_entry->data;
|
struct fpi_frame *prev_stripe;
|
||||||
unsigned int min_error;
|
unsigned int min_error;
|
||||||
/* Max error is width * height * 255, for AES2501 which has the largest
|
/* 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
|
* 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;
|
unsigned long long total_error = 0;
|
||||||
|
|
||||||
list_entry = g_slist_next(list_entry);
|
|
||||||
|
|
||||||
timer = g_timer_new();
|
timer = g_timer_new();
|
||||||
do {
|
prev_stripe = stripes->data;
|
||||||
struct fpi_frame *cur_stripe = list_entry->data;
|
for (l = stripes; l != NULL; l = l->next, num_frames++) {
|
||||||
|
struct fpi_frame *cur_stripe = l->data;
|
||||||
|
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
find_overlap(ctx, prev_stripe, cur_stripe, &min_error);
|
find_overlap(ctx, prev_stripe, cur_stripe, &min_error);
|
||||||
cur_stripe->delta_y = -cur_stripe->delta_y;
|
cur_stripe->delta_y = -cur_stripe->delta_y;
|
||||||
cur_stripe->delta_x = -cur_stripe->delta_x;
|
cur_stripe->delta_x = -cur_stripe->delta_x;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
find_overlap(ctx, cur_stripe, prev_stripe, &min_error);
|
find_overlap(ctx, cur_stripe, prev_stripe, &min_error);
|
||||||
|
}
|
||||||
total_error += min_error;
|
total_error += min_error;
|
||||||
|
|
||||||
frame++;
|
|
||||||
prev_stripe = cur_stripe;
|
prev_stripe = cur_stripe;
|
||||||
list_entry = g_slist_next(list_entry);
|
}
|
||||||
|
|
||||||
} while (frame < num_stripes);
|
|
||||||
|
|
||||||
g_timer_stop(timer);
|
g_timer_stop(timer);
|
||||||
fp_dbg("calc delta completed in %f secs", g_timer_elapsed(timer, NULL));
|
fp_dbg("calc delta completed in %f secs", g_timer_elapsed(timer, NULL));
|
||||||
g_timer_destroy(timer);
|
g_timer_destroy(timer);
|
||||||
|
|
||||||
return total_error / num_stripes;
|
return total_error / num_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fpi_do_movement_estimation:
|
* fpi_do_movement_estimation:
|
||||||
* @ctx: #fpi_frame_asmbl_ctx - frame assembling context
|
* @ctx: #fpi_frame_asmbl_ctx - frame assembling context
|
||||||
* @stripes: a singly-linked list of #fpi_frame
|
* @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
|
* fpi_do_movement_estimation() estimates the movement between adjacent
|
||||||
* frames, populating @delta_x and @delta_y values for each #fpi_frame.
|
* 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
|
* This function is used for devices that don't do movement estimation
|
||||||
* in hardware. If hardware movement estimation is supported, the driver
|
* in hardware. If hardware movement estimation is supported, the driver
|
||||||
* should populate @delta_x and @delta_y instead.
|
* 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,
|
void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx,
|
||||||
GSList *stripes, size_t num_stripes)
|
GSList *stripes)
|
||||||
{
|
{
|
||||||
int err, rev_err;
|
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);
|
fp_dbg("errors: %d rev: %d", err, rev_err);
|
||||||
if (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:
|
* fpi_assemble_frames:
|
||||||
* @ctx: #fpi_frame_asmbl_ctx - frame assembling context
|
* @ctx: #fpi_frame_asmbl_ctx - frame assembling context
|
||||||
* @stripes: linked list of #fpi_frame
|
* @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.
|
* fpi_assemble_frames() assembles individual frames into a single image.
|
||||||
* It expects @delta_x and @delta_y of #fpi_frame to be populated.
|
* 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.
|
* Returns: a newly allocated #fp_img.
|
||||||
*/
|
*/
|
||||||
struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx,
|
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;
|
struct fp_img *img;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
int i, y, x;
|
int y, x;
|
||||||
gboolean reverse = FALSE;
|
gboolean reverse = FALSE;
|
||||||
struct fpi_frame *fpi_frame;
|
struct fpi_frame *fpi_frame;
|
||||||
|
|
||||||
//FIXME g_return_if_fail
|
//FIXME g_return_if_fail
|
||||||
BUG_ON(num_stripes == 0);
|
|
||||||
BUG_ON(ctx->image_width < ctx->frame_width);
|
BUG_ON(ctx->image_width < ctx->frame_width);
|
||||||
|
|
||||||
/* Calculate height */
|
|
||||||
i = 0;
|
|
||||||
stripe = stripes;
|
|
||||||
|
|
||||||
/* No offset for 1st image */
|
/* No offset for 1st image */
|
||||||
fpi_frame = stripe->data;
|
fpi_frame = stripes->data;
|
||||||
fpi_frame->delta_x = 0;
|
fpi_frame->delta_x = 0;
|
||||||
fpi_frame->delta_y = 0;
|
fpi_frame->delta_y = 0;
|
||||||
do {
|
for (l = stripes; l != NULL; l = l->next) {
|
||||||
fpi_frame = stripe->data;
|
fpi_frame = l->data;
|
||||||
|
|
||||||
height += fpi_frame->delta_y;
|
height += fpi_frame->delta_y;
|
||||||
i++;
|
}
|
||||||
stripe = g_slist_next(stripe);
|
|
||||||
} while (i < num_stripes);
|
|
||||||
|
|
||||||
fp_dbg("height is %d", height);
|
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;
|
img->height = height;
|
||||||
|
|
||||||
/* Assemble stripes */
|
/* Assemble stripes */
|
||||||
i = 0;
|
|
||||||
stripe = stripes;
|
|
||||||
y = reverse ? (height - ctx->frame_height) : 0;
|
y = reverse ? (height - ctx->frame_height) : 0;
|
||||||
x = (ctx->image_width - ctx->frame_width) / 2;
|
x = (ctx->image_width - ctx->frame_width) / 2;
|
||||||
|
|
||||||
do {
|
for (l = stripes; l != NULL; l = l->next) {
|
||||||
fpi_frame = stripe->data;
|
fpi_frame = l->data;
|
||||||
|
|
||||||
if(reverse) {
|
if(reverse) {
|
||||||
y += fpi_frame->delta_y;
|
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;
|
y += fpi_frame->delta_y;
|
||||||
x += fpi_frame->delta_x;
|
x += fpi_frame->delta_x;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
stripe = g_slist_next(stripe);
|
|
||||||
i++;
|
|
||||||
} while (i < num_stripes);
|
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,10 +63,10 @@ struct fpi_frame_asmbl_ctx {
|
||||||
};
|
};
|
||||||
|
|
||||||
void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *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,
|
struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx,
|
||||||
GSList *stripes, size_t num_stripes);
|
GSList *stripes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fpi_line_asmbl_ctx:
|
* fpi_line_asmbl_ctx:
|
||||||
|
|
Loading…
Reference in a new issue