Split imagemagick hack from main library

Cleans up the conditional compilation system
This commit is contained in:
Daniel Drake 2008-08-10 14:34:44 -05:00
parent bba1c1085f
commit 6b8b17f575
5 changed files with 88 additions and 73 deletions

View file

@ -91,7 +91,8 @@ DRIVER_SRC += $(AES4000_SRC)
endif endif
if REQUIRE_IMAGEMAGICK if REQUIRE_IMAGEMAGICK
libfprint_la_CFLAGS += $(IMAGEMAGICK_CFLAGS) -DREQUIRE_IMAGEMAGICK OTHER_SRC += imagemagick.c
libfprint_la_CFLAGS += $(IMAGEMAGICK_CFLAGS)
libfprint_la_LIBADD += $(IMAGEMAGICK_LIBS) libfprint_la_LIBADD += $(IMAGEMAGICK_LIBS)
endif endif

View file

@ -34,6 +34,10 @@
#define NR_SUBARRAYS 6 #define NR_SUBARRAYS 6
#define SUBARRAY_LEN 768 #define SUBARRAY_LEN 768
#define IMG_HEIGHT 96
#define IMG_WIDTH 96
#define ENLARGE_FACTOR 3
struct aes4k_dev { struct aes4k_dev {
struct libusb_transfer *img_trf; struct libusb_transfer *img_trf;
}; };
@ -120,6 +124,7 @@ static void img_cb(struct libusb_transfer *transfer)
struct fp_img_dev *dev = transfer->user_data; struct fp_img_dev *dev = transfer->user_data;
struct aes4k_dev *aesdev = dev->priv; struct aes4k_dev *aesdev = dev->priv;
unsigned char *ptr = transfer->buffer; unsigned char *ptr = transfer->buffer;
struct fp_img *tmp;
struct fp_img *img; struct fp_img *img;
int i; int i;
@ -135,15 +140,21 @@ static void img_cb(struct libusb_transfer *transfer)
fpi_imgdev_report_finger_status(dev, TRUE); fpi_imgdev_report_finger_status(dev, TRUE);
img = fpi_img_new_for_imgdev(dev); tmp = fpi_img_new(IMG_WIDTH * IMG_HEIGHT);
img->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED; tmp->width = IMG_WIDTH;
tmp->height = IMG_HEIGHT;
tmp->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED;
for (i = 0; i < NR_SUBARRAYS; i++) { for (i = 0; i < NR_SUBARRAYS; i++) {
fp_dbg("subarray header byte %02x", *ptr); fp_dbg("subarray header byte %02x", *ptr);
ptr++; ptr++;
aes_assemble_image(ptr, 96, 16, img->data + (i * 96 * 16)); aes_assemble_image(ptr, 96, 16, tmp->data + (i * 96 * 16));
ptr += SUBARRAY_LEN; ptr += SUBARRAY_LEN;
} }
/* FIXME: this is an ugly hack to make the image big enough for NBIS
* to process reliably */
img = fpi_im_resize(tmp, ENLARGE_FACTOR);
fp_img_free(tmp);
fpi_imgdev_image_captured(dev, img); fpi_imgdev_image_captured(dev, img);
/* FIXME: rather than assuming finger has gone, we should poll regs until /* FIXME: rather than assuming finger has gone, we should poll regs until
@ -244,9 +255,8 @@ struct fp_img_driver aes4000_driver = {
.id_table = id_table, .id_table = id_table,
}, },
.flags = 0, .flags = 0,
.img_height = 96, .img_height = IMG_HEIGHT * ENLARGE_FACTOR,
.img_width = 96, .img_width = IMG_WIDTH * ENLARGE_FACTOR,
.enlarge_factor = 3,
/* temporarily lowered until image quality improves */ /* temporarily lowered until image quality improves */
.bz3_threshold = 9, .bz3_threshold = 9,

View file

@ -222,7 +222,6 @@ struct fp_img_driver {
uint16_t flags; uint16_t flags;
int img_width; int img_width;
int img_height; int img_height;
unsigned int enlarge_factor;
int bz3_threshold; int bz3_threshold;
/* Device operations */ /* Device operations */
@ -346,6 +345,7 @@ int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
struct fp_print_data *new_print); struct fp_print_data *new_print);
int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print, int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print,
struct fp_print_data **gallery, int match_threshold, size_t *match_offset); struct fp_print_data **gallery, int match_threshold, size_t *match_offset);
struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int factor);
/* polling and timeouts */ /* polling and timeouts */

67
libfprint/imagemagick.c Normal file
View file

@ -0,0 +1,67 @@
/*
* Imaging utility functions for libfprint
* Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <errno.h>
#include <magick/ImageMagick.h>
#include "fp_internal.h"
struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int factor)
{
Image *mimg;
Image *resized;
ExceptionInfo exception;
MagickBooleanType ret;
int new_width = img->width * factor;
int new_height = img->height * factor;
struct fp_img *newimg;
/* It is possible to implement resizing using a simple algorithm, however
* we use ImageMagick because it applies some kind of smoothing to the
* result, which improves matching performances in my experiments. */
if (!IsMagickInstantiated())
InitializeMagick(NULL);
GetExceptionInfo(&exception);
mimg = ConstituteImage(img->width, img->height, "I", CharPixel, img->data,
&exception);
GetExceptionInfo(&exception);
resized = ResizeImage(mimg, new_width, new_height, 0, 1.0, &exception);
newimg = fpi_img_new(new_width * new_height);
newimg->width = new_width;
newimg->height = new_height;
newimg->flags = img->flags;
GetExceptionInfo(&exception);
ret = ExportImagePixels(resized, 0, 0, new_width, new_height, "I",
CharPixel, newimg->data, &exception);
if (ret != MagickTrue) {
fp_err("export failed");
return NULL;
}
DestroyImage(mimg);
DestroyImage(resized);
return newimg;
}

View file

@ -20,9 +20,6 @@
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#ifdef REQUIRE_IMAGEMAGICK
#include <magick/ImageMagick.h>
#endif
#include "fp_internal.h" #include "fp_internal.h"
@ -89,51 +86,6 @@ static int dev_change_state(struct fp_img_dev *imgdev,
return imgdrv->change_state(imgdev, state); return imgdrv->change_state(imgdev, state);
} }
#ifdef REQUIRE_IMAGEMAGICK
static struct fp_img *im_resize(struct fp_img *img, unsigned int factor)
{
Image *mimg;
Image *resized;
ExceptionInfo exception;
MagickBooleanType ret;
int new_width = img->width * factor;
int new_height = img->height * factor;
struct fp_img *newimg;
/* It is possible to implement resizing using a simple algorithm, however
* we use ImageMagick because it applies some kind of smoothing to the
* result, which improves matching performances in my experiments. */
if (!IsMagickInstantiated())
InitializeMagick(NULL);
GetExceptionInfo(&exception);
mimg = ConstituteImage(img->width, img->height, "I", CharPixel, img->data,
&exception);
GetExceptionInfo(&exception);
resized = ResizeImage(mimg, new_width, new_height, 0, 1.0, &exception);
newimg = fpi_img_new(new_width * new_height);
newimg->width = new_width;
newimg->height = new_height;
newimg->flags = img->flags;
GetExceptionInfo(&exception);
ret = ExportImagePixels(resized, 0, 0, new_width, new_height, "I",
CharPixel, newimg->data, &exception);
if (ret != MagickTrue) {
fp_err("export failed");
return NULL;
}
DestroyImage(mimg);
DestroyImage(resized);
return newimg;
}
#endif
/* check image properties and resize it if necessary. potentially returns a new /* check image properties and resize it if necessary. potentially returns a new
* image after freeing the old one. */ * image after freeing the old one. */
static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img) static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img)
@ -161,17 +113,6 @@ static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img)
return -EINVAL; return -EINVAL;
} }
#ifdef REQUIRE_IMAGEMAGICK
if (imgdrv->enlarge_factor > 1) {
/* FIXME: enlarge_factor should not exist! instead, MINDTCT should
* actually look at the value of the pixels-per-mm parameter and
* figure out itself when the image needs to be treated as if it
* were bigger. */
struct fp_img *tmp = im_resize(img, imgdrv->enlarge_factor);
fp_img_free(img);
*_img = tmp;
}
#endif
return 0; return 0;
} }
@ -392,9 +333,7 @@ int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev)
struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv);
int width = imgdrv->img_width; int width = imgdrv->img_width;
if (width > 0 && imgdrv->enlarge_factor > 1) if (width == -1)
width *= imgdrv->enlarge_factor;
else if (width == -1)
width = 0; width = 0;
return width; return width;
@ -406,9 +345,7 @@ int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev)
struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv);
int height = imgdrv->img_height; int height = imgdrv->img_height;
if (height > 0 && imgdrv->enlarge_factor > 1) if (height == -1)
height *= imgdrv->enlarge_factor;
else if (height == -1)
height = 0; height = 0;
return height; return height;