lib: move some functions from vfs5011.c into img.c
This commit is contained in:
parent
49a46668ad
commit
5e29695969
3 changed files with 40 additions and 35 deletions
|
@ -252,39 +252,6 @@ static void usb_exchange_async(struct fpi_ssm *ssm,
|
|||
|
||||
/* ====================== utils ======================= */
|
||||
|
||||
#if VFS5011_LINE_SIZE > INT_MAX/(256*256)
|
||||
#error We might get integer overflow while computing standard deviation!
|
||||
#endif
|
||||
|
||||
/* Calculade squared standand deviation */
|
||||
static int get_deviation(unsigned char *buf, int size)
|
||||
{
|
||||
int res = 0, mean = 0, i;
|
||||
for (i = 0; i < size; i++)
|
||||
mean += buf[i];
|
||||
|
||||
mean /= size;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
int dev = (int)buf[i] - mean;
|
||||
res += dev*dev;
|
||||
}
|
||||
|
||||
return res / size;
|
||||
}
|
||||
|
||||
/* Calculate mean square difference of two lines */
|
||||
static int get_diff_norm(unsigned char *buf1, unsigned char *buf2, int size)
|
||||
{
|
||||
int res = 0, i;
|
||||
for (i = 0; i < size; i++) {
|
||||
int dev = (int)buf1[i] - (int)buf2[i];
|
||||
res += dev*dev;
|
||||
}
|
||||
|
||||
return res / size;
|
||||
}
|
||||
|
||||
/* Calculade squared standand deviation of sum of two lines */
|
||||
static int vfs5011_get_deviation2(struct fpi_line_asmbl_ctx *ctx, GSList *row1, GSList *row2)
|
||||
{
|
||||
|
@ -395,7 +362,7 @@ static int process_chunk(struct vfs5011_data *data, int transferred)
|
|||
unsigned char *linebuf = data->capture_buffer
|
||||
+ i * VFS5011_LINE_SIZE;
|
||||
|
||||
if (get_deviation(linebuf + 8, VFS5011_IMAGE_WIDTH)
|
||||
if (fpi_std_sq_dev(linebuf + 8, VFS5011_IMAGE_WIDTH)
|
||||
< DEVIATION_THRESHOLD) {
|
||||
if (data->lines_captured == 0)
|
||||
continue;
|
||||
|
@ -417,7 +384,7 @@ static int process_chunk(struct vfs5011_data *data, int transferred)
|
|||
}
|
||||
|
||||
if ((data->lastline == NULL)
|
||||
|| (get_diff_norm(
|
||||
|| (fpi_mean_sq_diff_norm(
|
||||
data->lastline + 8,
|
||||
linebuf + 8,
|
||||
VFS5011_IMAGE_WIDTH) >= DIFFERENCE_THRESHOLD)) {
|
||||
|
|
|
@ -489,5 +489,9 @@ void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img);
|
|||
void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result);
|
||||
void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error);
|
||||
|
||||
/* utils */
|
||||
int fpi_std_sq_dev(const unsigned char *buf, int size);
|
||||
int fpi_mean_sq_diff_norm(unsigned char *buf1, unsigned char *buf2, int size);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -511,3 +511,37 @@ API_EXPORTED struct fp_minutia **fp_img_get_minutiae(struct fp_img *img,
|
|||
return img->minutiae->list;
|
||||
}
|
||||
|
||||
/* Calculate squared standand deviation */
|
||||
int fpi_std_sq_dev(const unsigned char *buf, int size)
|
||||
{
|
||||
int res = 0, mean = 0, i;
|
||||
|
||||
if (size > (INT_MAX / 65536)) {
|
||||
fp_err("%s: we might get an overflow!", __func__);
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
mean += buf[i];
|
||||
|
||||
mean /= size;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
int dev = (int)buf[i] - mean;
|
||||
res += dev*dev;
|
||||
}
|
||||
|
||||
return res / size;
|
||||
}
|
||||
|
||||
/* Calculate normalized mean square difference of two lines */
|
||||
int fpi_mean_sq_diff_norm(unsigned char *buf1, unsigned char *buf2, int size)
|
||||
{
|
||||
int res = 0, i;
|
||||
for (i = 0; i < size; i++) {
|
||||
int dev = (int)buf1[i] - (int)buf2[i];
|
||||
res += dev * dev;
|
||||
}
|
||||
|
||||
return res / size;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue