diff --git a/libfprint/aeslib.c b/libfprint/aeslib.c index e93e06f..aa8571e 100644 --- a/libfprint/aeslib.c +++ b/libfprint/aeslib.c @@ -93,3 +93,18 @@ int aes_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs, return 0; } +int aes_assemble_image(unsigned char *input, size_t width, size_t height, + unsigned char *output) +{ + size_t frame_size = width * height; + size_t row, column; + + for (column = 0; column < width; column++) { + for (row = 0; row < height; row += 2) { + output[width * row + column] = (*input & 0x07) * 36; + output[width * (row + 1) + column] = ((*input & 0x70) >> 4) * 36; + input++; + } + } +} + diff --git a/libfprint/aeslib.h b/libfprint/aeslib.h index 19b6cc6..c02f507 100644 --- a/libfprint/aeslib.h +++ b/libfprint/aeslib.h @@ -30,5 +30,8 @@ struct aes_regwrite { int aes_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs, unsigned int num); +int aes_assemble_image(unsigned char *input, size_t width, size_t height, + unsigned char *output); + #endif diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 5bc4d80..eb71a4b 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -231,15 +231,8 @@ static unsigned int assemble(unsigned char *input, unsigned char *output, if (reverse) output += (num_strips - 1) * FRAME_SIZE; for (frame = 0; frame < num_strips; frame++) { - int column; - for (column = 0; column < FRAME_WIDTH; column++) { - int row; - for (row = 0; row < (FRAME_HEIGHT / 2); row++) { - output[FRAME_WIDTH * ( 2 * row) + column] = *input & 0x0F; - output[FRAME_WIDTH * ( 2 * row + 1) + column] = *input >> 4; - input++; - } - } + aes_assemble_image(input, FRAME_WIDTH, FRAME_HEIGHT, output); + input += FRAME_WIDTH * (FRAME_HEIGHT / 2); if (reverse) output -= FRAME_SIZE; @@ -410,6 +403,7 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional, unsigned char *cooked; unsigned char *imgptr; unsigned char buf[665]; + int final_size; int sum; unsigned int count_blank = 0; int i; @@ -511,10 +505,9 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional, fp_dbg("reversed scan direction"); } - for (i = 0; i < img->height * FRAME_WIDTH; i++) - img->data[i] = (cooked[i] << 4) | 0xf; - - img = fpi_img_resize(img, img->height * FRAME_WIDTH); + final_size = img->height * FRAME_WIDTH; + memcpy(img->data, cooked, final_size); + img = fpi_img_resize(img, final_size); *ret = img; return 0; err: diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 2abfa4e..ff7cd10 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -394,15 +394,8 @@ static unsigned int assemble(unsigned char *input, unsigned char *output, if (reverse) output += (num_strips - 1) * FRAME_SIZE; for (frame = 0; frame < num_strips; frame++) { - int column; - for (column = 0; column < FRAME_WIDTH; column++) { - int row; - for (row = 0; row < (FRAME_HEIGHT / 2); row++) { - output[FRAME_WIDTH * ( 2 * row) + column] = *input & 0x0F; - output[FRAME_WIDTH * ( 2 * row + 1) + column] = *input >> 4; - input++; - } - } + aes_assemble_image(input, FRAME_WIDTH, FRAME_HEIGHT, output); + input += FRAME_WIDTH * (FRAME_HEIGHT / 2); if (reverse) output -= FRAME_SIZE; @@ -492,8 +485,8 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional, unsigned char *cooked; unsigned char *imgptr; unsigned char buf[1705]; + int final_size; int sum; - int i; /* FIXME can do better here in terms of buffer management? */ fp_dbg(""); @@ -563,10 +556,9 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional, fp_dbg("reversed scan direction"); } - for (i = 0; i < img->height * FRAME_WIDTH; i++) - img->data[i] = (cooked[i] << 4) | 0xf; - - img = fpi_img_resize(img, img->height * FRAME_WIDTH); + final_size = img->height * FRAME_WIDTH; + memcpy(img->data, cooked, final_size); + img = fpi_img_resize(img, final_size); *ret = img; return 0; err: diff --git a/libfprint/drivers/aes4000.c b/libfprint/drivers/aes4000.c index f300477..f2c737f 100644 --- a/libfprint/drivers/aes4000.c +++ b/libfprint/drivers/aes4000.c @@ -34,20 +34,6 @@ #define NR_SUBARRAYS 6 #define SUBARRAY_LEN 768 -static void process_subarray(unsigned char *src, unsigned char *dst) -{ - int col, row; - int offset = -1; - - for (col = 95; col >= 0; col--) { - for (row = 15; row >= 0; row -= 2) { - unsigned char val = src[++offset]; - dst[(row * 96) + col] = (val & 0x7) * 36; - dst[((row - 1) * 96) + col] = ((val & 0x70) >> 4) * 36; - } - } -} - static const struct aes_regwrite init_reqs[] = { /* master reset */ { 0x80, 0x01 }, @@ -156,14 +142,14 @@ retry: goto err; } - for (i = NR_SUBARRAYS - 1; i >= 0; i--) { + for (i = 0; i < NR_SUBARRAYS; i++) { fp_dbg("subarray header byte %02x", *ptr); ptr++; - process_subarray(ptr, img->data + (i * 96 * 16)); + aes_assemble_image(ptr, 96, 16, img->data + (i * 96 * 16)); ptr += SUBARRAY_LEN; } - img->flags = FP_IMG_COLORS_INVERTED; + img->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED; *ret = img; g_free(data); return 0;