--- libfprint-20081125git.orig/configure.ac +++ libfprint-20081125git/configure.ac @@ -1,5 +1,6 @@ -AC_INIT([libfprint], [0.1.0-pre1]) +AC_INIT([libfprint], [0.1.0-pre2]) AM_INIT_AUTOMAKE +AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([libfprint/core.c]) AM_CONFIG_HEADER([config.h]) --- libfprint-20081125git.orig/Makefile.am +++ libfprint-20081125git/Makefile.am @@ -1,4 +1,5 @@ AUTOMAKE_OPTIONS = dist-bzip2 +ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = THANKS TODO HACKING libfprint.pc.in DISTCLEANFILES = ChangeLog libfprint.pc @@ -18,4 +19,4 @@ dist-hook: ChangeLog dist-up: dist - ncftpput upload.sourceforge.net incoming $(distdir).tar.bz2 + rsync $(distdir).tar.bz2 frs.sourceforge.net:uploads/ --- libfprint-20081125git.orig/examples/.svn/entries +++ libfprint-20081125git/examples/.svn/entries @@ -0,0 +1,232 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/examples +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +img_capture.c +file + + + + +2009-01-13T22:22:22.000000Z +aae2293a26ddad722a646c918c2abccc +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2601 + +verify_live.c +file + + + + +2009-01-13T22:22:22.000000Z +a0607f2fea85b11dcc46018594b737bb +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +4751 + +verify.c +file + + + + +2009-01-13T22:22:22.000000Z +8b4991424d643c04f21fe47837b1f95c +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +3667 + +img_capture_continuous.c +file + + + + +2009-01-13T22:22:22.000000Z +c6f039ae49d4f930ceafc0d1058072bd +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +6258 + +Makefile.am +file + + + + +2009-01-13T22:22:22.000000Z +f9f51f92deaacfd474f0a5c816dd4e36 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +733 + +enroll.c +file + + + + +2009-01-13T22:22:22.000000Z +52d71a7561c2362090385b198661170c +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +4043 + --- libfprint-20081125git.orig/examples/.svn/text-base/img_capture.c.svn-base +++ libfprint-20081125git/examples/.svn/text-base/img_capture.c.svn-base @@ -0,0 +1,105 @@ +/* + * Example libfprint image capture program + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include + +#include + +struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) +{ + struct fp_dscv_dev *ddev = discovered_devs[0]; + struct fp_driver *drv; + if (!ddev) + return NULL; + + drv = fp_dscv_dev_get_driver(ddev); + printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv)); + return ddev; +} + +int main(void) +{ + int r = 1; + struct fp_dscv_dev *ddev; + struct fp_dscv_dev **discovered_devs; + struct fp_dev *dev; + struct fp_img *img = NULL; + + r = fp_init(); + if (r < 0) { + fprintf(stderr, "Failed to initialize libfprint\n"); + exit(1); + } + fp_set_debug(3); + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) { + fprintf(stderr, "Could not discover devices\n"); + goto out; + } + + ddev = discover_device(discovered_devs); + if (!ddev) { + fprintf(stderr, "No devices detected.\n"); + goto out; + } + + dev = fp_dev_open(ddev); + fp_dscv_devs_free(discovered_devs); + if (!dev) { + fprintf(stderr, "Could not open device.\n"); + goto out; + } + + if (!fp_dev_supports_imaging(dev)) { + fprintf(stderr, "this device does not have imaging capabilities.\n"); + goto out_close; + } + + printf("Opened device. It's now time to scan your finger.\n\n"); + + r = fp_dev_img_capture(dev, 0, &img); + if (r) { + fprintf(stderr, "image capture failed, code %d\n", r); + goto out_close; + } + + r = fp_img_save_to_file(img, "finger.pgm"); + if (r) { + fprintf(stderr, "img save failed, code %d\n", r); + goto out_close; + } + + fp_img_standardize(img); + r = fp_img_save_to_file(img, "finger_standardized.pgm"); + fp_img_free(img); + if (r) { + fprintf(stderr, "standardized img save failed, code %d\n", r); + goto out_close; + } + + r = 0; +out_close: + fp_dev_close(dev); +out: + fp_exit(); + return r; +} + --- libfprint-20081125git.orig/examples/.svn/text-base/img_capture_continuous.c.svn-base +++ libfprint-20081125git/examples/.svn/text-base/img_capture_continuous.c.svn-base @@ -0,0 +1,259 @@ +/* + * Example libfprint continuous image capture program + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include +#include + +#include +#include +#include +#include + +#define FORMAT 0x32595559 + +static int adaptor = -1; +static unsigned char *framebuffer = NULL; + +static Display *display = NULL; +static Window window=(Window)NULL; +static XvImage *xv_image = NULL; +static XvAdaptorInfo *info; +static GC gc; +static int connection = -1; + +/* based on macro by Bart Nabbe */ +#define GREY2YUV(grey, y, u, v)\ + y = (9798*grey + 19235*grey + 3736*grey) / 32768;\ + u = (-4784*grey - 9437*grey + 14221*grey) / 32768 + 128;\ + v = (20218*grey - 16941*grey - 3277*grey) / 32768 + 128;\ + y = y < 0 ? 0 : y;\ + u = u < 0 ? 0 : u;\ + v = v < 0 ? 0 : v;\ + y = y > 255 ? 255 : y;\ + u = u > 255 ? 255 : u;\ + v = v > 255 ? 255 : v + +static void grey2yuy2 (unsigned char *grey, unsigned char *YUV, int num) { + int i, j; + int y0, y1, u0, u1, v0, v1; + int gval; + + for (i = 0, j = 0; i < num; i += 2, j += 4) + { + gval = grey[i]; + GREY2YUV (gval, y0, u0 , v0); + gval = grey[i + 1]; + GREY2YUV (gval, y1, u1 , v1); + YUV[j + 0] = y0; + YUV[j + 1] = (u0+u1)/2; + YUV[j + 2] = y1; + YUV[j + 3] = (v0+v1)/2; + } +} + +static void display_frame(struct fp_img *img) +{ + int width = fp_img_get_width(img); + int height = fp_img_get_height(img); + unsigned char *data = fp_img_get_data(img); + + if (adaptor < 0) + return; + + grey2yuy2(data, framebuffer, width * height); + xv_image = XvCreateImage(display, info[adaptor].base_id, FORMAT, + framebuffer, width, height); + XvPutImage(display, info[adaptor].base_id, window, gc, xv_image, + 0, 0, width, height, 0, 0, width, height); +} + +static void QueryXv() +{ + int num_adaptors; + int num_formats; + XvImageFormatValues *formats = NULL; + int i,j; + char xv_name[5]; + + XvQueryAdaptors(display, DefaultRootWindow(display), &num_adaptors, + &info); + + for(i = 0; i < num_adaptors; i++) { + formats = XvListImageFormats(display, info[i].base_id, + &num_formats); + for(j = 0; j < num_formats; j++) { + xv_name[4] = 0; + memcpy(xv_name, &formats[j].id, 4); + if(formats[j].id == FORMAT) { + printf("using Xv format 0x%x %s %s\n", + formats[j].id, xv_name, + (formats[j].format==XvPacked) + ? "packed" : "planar"); + if (adaptor < 0) + adaptor = i; + } + } + } + XFree(formats); + if (adaptor < 0) + printf("No suitable Xv adaptor found\n"); +} + +struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) +{ + struct fp_dscv_dev *ddev = discovered_devs[0]; + struct fp_driver *drv; + if (!ddev) + return NULL; + + drv = fp_dscv_dev_get_driver(ddev); + printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv)); + return ddev; +} + +int main(void) +{ + int r = 1; + XEvent xev; + XGCValues xgcv; + long background=0x010203; + struct fp_dscv_dev *ddev; + struct fp_dscv_dev **discovered_devs; + struct fp_dev *dev; + int img_width; + int img_height; + int standardize = 0; + + r = fp_init(); + if (r < 0) { + fprintf(stderr, "Failed to initialize libfprint\n"); + exit(1); + } + fp_set_debug(3); + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) { + fprintf(stderr, "Could not discover devices\n"); + goto out; + } + + ddev = discover_device(discovered_devs); + if (!ddev) { + fprintf(stderr, "No devices detected.\n"); + goto out; + } + + dev = fp_dev_open(ddev); + fp_dscv_devs_free(discovered_devs); + if (!dev) { + fprintf(stderr, "Could not open device.\n"); + goto out; + } + + if (!fp_dev_supports_imaging(dev)) { + fprintf(stderr, "this device does not have imaging capabilities.\n"); + goto out_close; + } + + img_width = fp_dev_get_img_width(dev); + img_height = fp_dev_get_img_height(dev); + if (img_width <= 0 || img_height <= 0) { + fprintf(stderr, "this device returns images with variable dimensions," + " this example does not support that.\n"); + goto out_close; + } + framebuffer = malloc(img_width * img_height * 2); + if (!framebuffer) + goto out_close; + + /* make the window */ + display = XOpenDisplay(getenv("DISPLAY")); + if(display == NULL) { + fprintf(stderr,"Could not open display \"%s\"\n", + getenv("DISPLAY")); + goto out_close; + } + + QueryXv(); + + if (adaptor < 0) + goto out_close; + + window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, + img_width, img_height, 0, + WhitePixel(display, DefaultScreen(display)), background); + + XSelectInput(display, window, StructureNotifyMask | KeyPressMask); + XMapWindow(display, window); + connection = ConnectionNumber(display); + + gc = XCreateGC(display, window, 0, &xgcv); + + printf("Press S to toggle standardized mode, Q to quit\n"); + + while (1) { /* event loop */ + struct fp_img *img; + + r = fp_dev_img_capture(dev, 1, &img); + if (r) { + fprintf(stderr, "image capture failed, code %d\n", r); + goto out_close; + } + if (standardize) + fp_img_standardize(img); + + display_frame(img); + fp_img_free(img); + XFlush(display); + + while (XPending(display) > 0) { + XNextEvent(display, &xev); + if (xev.type != KeyPress) + continue; + + switch (XKeycodeToKeysym(display, xev.xkey.keycode, 0)) { + case XK_q: + case XK_Q: + r = 0; + goto out_close; + break; + case XK_s: + case XK_S: + standardize = !standardize; + break; + } + } /* XPending */ + } + + r = 0; +out_close: + if (framebuffer) + free(framebuffer); + fp_dev_close(dev); + if ((void *) window != NULL) + XUnmapWindow(display, window); + if (display != NULL) + XFlush(display); +out: + fp_exit(); + return r; +} + + --- libfprint-20081125git.orig/examples/.svn/text-base/Makefile.am.svn-base +++ libfprint-20081125git/examples/.svn/text-base/Makefile.am.svn-base @@ -0,0 +1,23 @@ +INCLUDES = -I$(top_srcdir) +noinst_PROGRAMS = verify_live enroll verify img_capture + +verify_live_SOURCES = verify_live.c +verify_live_LDADD = ../libfprint/libfprint.la -lfprint + +enroll_SOURCES = enroll.c +enroll_LDADD = ../libfprint/libfprint.la -lfprint + +verify_SOURCES = verify.c +verify_LDADD = ../libfprint/libfprint.la -lfprint + +img_capture_SOURCES = img_capture.c +img_capture_LDADD = ../libfprint/libfprint.la -lfprint + +if BUILD_X11_EXAMPLES +noinst_PROGRAMS += img_capture_continuous + +img_capture_continuous_CFLAGS = $(X_CFLAGS) $(XV_CFLAGS) +img_capture_continuous_SOURCES = img_capture_continuous.c +img_capture_continuous_LDADD = ../libfprint/libfprint.la -lfprint $(X_LIBS) $(X_PRE_LIBS) $(XV_LIBS) -lX11 $(X_EXTRA_LIBS); +endif + --- libfprint-20081125git.orig/examples/.svn/text-base/enroll.c.svn-base +++ libfprint-20081125git/examples/.svn/text-base/enroll.c.svn-base @@ -0,0 +1,156 @@ +/* + * Example fingerprint enrollment program + * Enrolls your right index finger and saves the print to disk + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include +#include + +#include + +struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) +{ + struct fp_dscv_dev *ddev = discovered_devs[0]; + struct fp_driver *drv; + if (!ddev) + return NULL; + + drv = fp_dscv_dev_get_driver(ddev); + printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv)); + return ddev; +} + +struct fp_print_data *enroll(struct fp_dev *dev) { + struct fp_print_data *enrolled_print = NULL; + int r; + + printf("You will need to successfully scan your finger %d times to " + "complete the process.\n", fp_dev_get_nr_enroll_stages(dev)); + + do { + struct fp_img *img = NULL; + + sleep(1); + printf("\nScan your finger now.\n"); + + r = fp_enroll_finger_img(dev, &enrolled_print, &img); + if (img) { + fp_img_save_to_file(img, "enrolled.pgm"); + printf("Wrote scanned image to enrolled.pgm\n"); + fp_img_free(img); + } + if (r < 0) { + printf("Enroll failed with error %d\n", r); + return NULL; + } + + switch (r) { + case FP_ENROLL_COMPLETE: + printf("Enroll complete!\n"); + break; + case FP_ENROLL_FAIL: + printf("Enroll failed, something wen't wrong :(\n"); + return NULL; + case FP_ENROLL_PASS: + printf("Enroll stage passed. Yay!\n"); + break; + case FP_ENROLL_RETRY: + printf("Didn't quite catch that. Please try again.\n"); + break; + case FP_ENROLL_RETRY_TOO_SHORT: + printf("Your swipe was too short, please try again.\n"); + break; + case FP_ENROLL_RETRY_CENTER_FINGER: + printf("Didn't catch that, please center your finger on the " + "sensor and try again.\n"); + break; + case FP_ENROLL_RETRY_REMOVE_FINGER: + printf("Scan failed, please remove your finger and then try " + "again.\n"); + break; + } + } while (r != FP_ENROLL_COMPLETE); + + if (!enrolled_print) { + fprintf(stderr, "Enroll complete but no print?\n"); + return NULL; + } + + printf("Enrollment completed!\n\n"); + return enrolled_print; +} + +int main(void) +{ + int r = 1; + struct fp_dscv_dev *ddev; + struct fp_dscv_dev **discovered_devs; + struct fp_dev *dev; + struct fp_print_data *data; + + printf("This program will enroll your right index finger, " + "unconditionally overwriting any right-index print that was enrolled " + "previously. If you want to continue, press enter, otherwise hit " + "Ctrl+C\n"); + getchar(); + + r = fp_init(); + if (r < 0) { + fprintf(stderr, "Failed to initialize libfprint\n"); + exit(1); + } + fp_set_debug(3); + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) { + fprintf(stderr, "Could not discover devices\n"); + goto out; + } + + ddev = discover_device(discovered_devs); + if (!ddev) { + fprintf(stderr, "No devices detected.\n"); + goto out; + } + + dev = fp_dev_open(ddev); + fp_dscv_devs_free(discovered_devs); + if (!dev) { + fprintf(stderr, "Could not open device.\n"); + goto out; + } + + printf("Opened device. It's now time to enroll your finger.\n\n"); + data = enroll(dev); + if (!data) + goto out_close; + + r = fp_print_data_save(data, RIGHT_INDEX); + if (r < 0) + fprintf(stderr, "Data save failed, code %d\n", r); + + fp_print_data_free(data); +out_close: + fp_dev_close(dev); +out: + fp_exit(); + return r; +} + + --- libfprint-20081125git.orig/examples/.svn/text-base/verify.c.svn-base +++ libfprint-20081125git/examples/.svn/text-base/verify.c.svn-base @@ -0,0 +1,145 @@ +/* + * Example fingerprint verification program, which verifies the right index + * finger which has been previously enrolled to disk. + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include +#include + +#include + +struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) +{ + struct fp_dscv_dev *ddev = discovered_devs[0]; + struct fp_driver *drv; + if (!ddev) + return NULL; + + drv = fp_dscv_dev_get_driver(ddev); + printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv)); + return ddev; +} + +int verify(struct fp_dev *dev, struct fp_print_data *data) +{ + int r; + + do { + struct fp_img *img = NULL; + + sleep(1); + printf("\nScan your finger now.\n"); + r = fp_verify_finger_img(dev, data, &img); + if (img) { + fp_img_save_to_file(img, "verify.pgm"); + printf("Wrote scanned image to verify.pgm\n"); + fp_img_free(img); + } + if (r < 0) { + printf("verification failed with error %d :(\n", r); + return r; + } + switch (r) { + case FP_VERIFY_NO_MATCH: + printf("NO MATCH!\n"); + return 0; + case FP_VERIFY_MATCH: + printf("MATCH!\n"); + return 0; + case FP_VERIFY_RETRY: + printf("Scan didn't quite work. Please try again.\n"); + break; + case FP_VERIFY_RETRY_TOO_SHORT: + printf("Swipe was too short, please try again.\n"); + break; + case FP_VERIFY_RETRY_CENTER_FINGER: + printf("Please center your finger on the sensor and try again.\n"); + break; + case FP_VERIFY_RETRY_REMOVE_FINGER: + printf("Please remove finger from the sensor and try again.\n"); + break; + } + } while (1); +} + +int main(void) +{ + int r = 1; + struct fp_dscv_dev *ddev; + struct fp_dscv_dev **discovered_devs; + struct fp_dev *dev; + struct fp_print_data *data; + + r = fp_init(); + if (r < 0) { + fprintf(stderr, "Failed to initialize libfprint\n"); + exit(1); + } + fp_set_debug(3); + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) { + fprintf(stderr, "Could not discover devices\n"); + goto out; + } + + ddev = discover_device(discovered_devs); + if (!ddev) { + fprintf(stderr, "No devices detected.\n"); + goto out; + } + + dev = fp_dev_open(ddev); + fp_dscv_devs_free(discovered_devs); + if (!dev) { + fprintf(stderr, "Could not open device.\n"); + goto out; + } + + printf("Opened device. Loading previously enrolled right index finger " + "data...\n"); + + r = fp_print_data_load(dev, RIGHT_INDEX, &data); + if (r != 0) { + fprintf(stderr, "Failed to load fingerprint, error %d\n", r); + fprintf(stderr, "Did you remember to enroll your right index finger " + "first?\n"); + goto out_close; + } + + printf("Print loaded. Time to verify!\n"); + do { + char buffer[20]; + + verify(dev, data); + printf("Verify again? [Y/n]? "); + fgets(buffer, sizeof(buffer), stdin); + if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y') + break; + } while (1); + + fp_print_data_free(data); +out_close: + fp_dev_close(dev); +out: + fp_exit(); + return r; +} + + --- libfprint-20081125git.orig/examples/.svn/text-base/verify_live.c.svn-base +++ libfprint-20081125git/examples/.svn/text-base/verify_live.c.svn-base @@ -0,0 +1,187 @@ +/* + * Example fingerprint verification program + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include +#include + +#include + +struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) +{ + struct fp_dscv_dev *ddev = discovered_devs[0]; + struct fp_driver *drv; + if (!ddev) + return NULL; + + drv = fp_dscv_dev_get_driver(ddev); + printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv)); + return ddev; +} + +struct fp_print_data *enroll(struct fp_dev *dev) { + struct fp_print_data *enrolled_print = NULL; + int r; + + printf("You will need to successfully scan your finger %d times to " + "complete the process.\n", fp_dev_get_nr_enroll_stages(dev)); + + do { + sleep(1); + printf("\nScan your finger now.\n"); + r = fp_enroll_finger(dev, &enrolled_print); + if (r < 0) { + printf("Enroll failed with error %d\n", r); + return NULL; + } + switch (r) { + case FP_ENROLL_COMPLETE: + printf("Enroll complete!\n"); + break; + case FP_ENROLL_FAIL: + printf("Enroll failed, something wen't wrong :(\n"); + return NULL; + case FP_ENROLL_PASS: + printf("Enroll stage passed. Yay!\n"); + break; + case FP_ENROLL_RETRY: + printf("Didn't quite catch that. Please try again.\n"); + break; + case FP_ENROLL_RETRY_TOO_SHORT: + printf("Your swipe was too short, please try again.\n"); + break; + case FP_ENROLL_RETRY_CENTER_FINGER: + printf("Didn't catch that, please center your finger on the " + "sensor and try again.\n"); + break; + case FP_ENROLL_RETRY_REMOVE_FINGER: + printf("Scan failed, please remove your finger and then try " + "again.\n"); + break; + } + } while (r != FP_ENROLL_COMPLETE); + + if (!enrolled_print) { + fprintf(stderr, "Enroll complete but no print?\n"); + return NULL; + } + + printf("Enrollment completed!\n\n"); + return enrolled_print; +} + +int verify(struct fp_dev *dev, struct fp_print_data *data) +{ + int r; + + do { + sleep(1); + printf("\nScan your finger now.\n"); + r = fp_verify_finger(dev, data); + if (r < 0) { + printf("verification failed with error %d :(\n", r); + return r; + } + switch (r) { + case FP_VERIFY_NO_MATCH: + printf("NO MATCH!\n"); + return 0; + case FP_VERIFY_MATCH: + printf("MATCH!\n"); + return 0; + case FP_VERIFY_RETRY: + printf("Scan didn't quite work. Please try again.\n"); + break; + case FP_VERIFY_RETRY_TOO_SHORT: + printf("Swipe was too short, please try again.\n"); + break; + case FP_VERIFY_RETRY_CENTER_FINGER: + printf("Please center your finger on the sensor and try again.\n"); + break; + case FP_VERIFY_RETRY_REMOVE_FINGER: + printf("Please remove finger from the sensor and try again.\n"); + break; + } + } while (1); +} + +int main(void) +{ + int r = 1; + struct fp_dscv_dev *ddev; + struct fp_dscv_dev **discovered_devs; + struct fp_dev *dev; + struct fp_print_data *data; + + r = fp_init(); + if (r < 0) { + fprintf(stderr, "Failed to initialize libfprint\n"); + exit(1); + } + fp_set_debug(3); + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) { + fprintf(stderr, "Could not discover devices\n"); + goto out; + } + + ddev = discover_device(discovered_devs); + if (!ddev) { + fprintf(stderr, "No devices detected.\n"); + goto out; + } + + dev = fp_dev_open(ddev); + fp_dscv_devs_free(discovered_devs); + if (!dev) { + fprintf(stderr, "Could not open device.\n"); + goto out; + } + + printf("Opened device. It's now time to enroll your finger.\n\n"); + data = enroll(dev); + if (!data) + goto out_close; + + + printf("Normally we'd save that print to disk, and recall it at some " + "point later when we want to authenticate the user who just " + "enrolled. In the interests of demonstration, we'll authenticate " + "that user immediately.\n"); + + do { + char buffer[20]; + + verify(dev, data); + printf("Verify again? [Y/n]? "); + fgets(buffer, sizeof(buffer), stdin); + if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y') + break; + } while (1); + + fp_print_data_free(data); +out_close: + fp_dev_close(dev); +out: + fp_exit(); + return r; +} + + --- libfprint-20081125git.orig/libfprint/.svn/entries +++ libfprint-20081125git/libfprint/.svn/entries @@ -0,0 +1,544 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/libfprint +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +imagemagick.c +file + + + + +2009-01-13T22:22:22.000000Z +27d66dc4f3b6d19ae8b97eb1f9dc9561 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2100 + +aeslib.c +file + + + + +2009-01-13T22:22:22.000000Z +5f59d7d6c9624c5d5d3bdbe93ca6f8dd +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +4992 + +aeslib.h +file + + + + +2009-01-13T22:22:22.000000Z +b2a75f8d6b8066c8332d2bbfc6df388a +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +1342 + +poll.c +file + + + + +2009-01-13T22:22:22.000000Z +f906d76bcc460f4a32689b175555eb70 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9856 + +fprint-list-hal-info.c +file + + + + +2009-01-13T22:22:22.000000Z +06680feaf82b46b13d7ef1cbcc5f1146 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +3362 + +fp_internal.h +file + + + + +2009-01-13T22:22:22.000000Z +0847fd77fbe5a13356a0f608f9ad77f2 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +11842 + +fprint.h +file + + + + +2009-01-13T22:22:22.000000Z +859efbf1da6b7dd0ba80481f5991fc95 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +13281 + +data.c +file + + + + +2009-01-13T22:22:22.000000Z +48e2cafdbf3403f7d1555850dd77baa9 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +20001 + +nbis +dir + +imgdev.c +file + + + + +2009-01-13T22:22:22.000000Z +470c82d2112bb0b132e7e8dca0c21ace +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +11620 + +img.c +file + + + + +2009-01-13T22:22:22.000000Z +1effce35f17a218311e53a80848662a1 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +13411 + +sync.c +file + + + + +2009-01-13T22:22:22.000000Z +d58a01b07ac088a9137abf86cfc5584d +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +14741 + +async.c +file + + + + +2009-01-13T22:22:22.000000Z +d1153857a17cc9294d773390a80242f7 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +10739 + +Makefile.am +file + + + + +2009-01-13T22:22:22.000000Z +f386ef54127eb01e5bc01d9e0672a644 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2940 + +core.c +file + + + + +2009-01-13T22:22:22.000000Z +d7bac1e8332ec0ae6df54f7a9c3d831d +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +31725 + +drv.c +file + + + + +2009-01-13T22:22:22.000000Z +622c971e7ea859db412feb4ff3309633 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +5570 + +drivers +dir + --- libfprint-20081125git.orig/libfprint/.svn/text-base/imgdev.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/imgdev.c.svn-base @@ -0,0 +1,454 @@ +/* + * Core imaging device functions for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + +#include + +#include "fp_internal.h" + +#define MIN_ACCEPTABLE_MINUTIAE 10 +#define BOZORTH3_DEFAULT_THRESHOLD 40 + +static int img_dev_open(struct fp_dev *dev, unsigned long driver_data) +{ + struct fp_img_dev *imgdev = g_malloc0(sizeof(*imgdev)); + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(dev->drv); + int r = 0; + + imgdev->dev = dev; + dev->priv = imgdev; + dev->nr_enroll_stages = 1; + + /* for consistency in driver code, allow udev access through imgdev */ + imgdev->udev = dev->udev; + + if (imgdrv->open) { + r = imgdrv->open(imgdev, driver_data); + if (r) + goto err; + } else { + fpi_drvcb_open_complete(dev, 0); + } + + return 0; +err: + g_free(imgdev); + return r; +} + +void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status) +{ + fpi_drvcb_open_complete(imgdev->dev, status); +} + +static void img_dev_close(struct fp_dev *dev) +{ + struct fp_img_dev *imgdev = dev->priv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(dev->drv); + + if (imgdrv->close) + imgdrv->close(imgdev); + else + fpi_drvcb_close_complete(dev); +} + +void fpi_imgdev_close_complete(struct fp_img_dev *imgdev) +{ + fpi_drvcb_close_complete(imgdev->dev); + g_free(imgdev); +} + +static int dev_change_state(struct fp_img_dev *imgdev, + enum fp_imgdev_state state) +{ + struct fp_driver *drv = imgdev->dev->drv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); + + if (!imgdrv->change_state) + return 0; + return imgdrv->change_state(imgdev, state); +} + +/* check image properties and resize it if necessary. potentially returns a new + * image after freeing the old one. */ +static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img) +{ + struct fp_driver *drv = imgdev->dev->drv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); + struct fp_img *img = *_img; + + if (imgdrv->img_width > 0) { + img->width = imgdrv->img_width; + } else if (img->width <= 0) { + fp_err("no image width assigned"); + return -EINVAL; + } + + if (imgdrv->img_height > 0) { + img->height = imgdrv->img_height; + } else if (img->height <= 0) { + fp_err("no image height assigned"); + return -EINVAL; + } + + if (!fpi_img_is_sane(img)) { + fp_err("image is not sane!"); + return -EINVAL; + } + + return 0; +} + +void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, + gboolean present) +{ + int r = imgdev->action_result; + struct fp_print_data *data = imgdev->acquire_data; + struct fp_img *img = imgdev->acquire_img; + + fp_dbg(present ? "finger on sensor" : "finger removed"); + + if (present && imgdev->action_state == IMG_ACQUIRE_STATE_AWAIT_FINGER_ON) { + dev_change_state(imgdev, IMGDEV_STATE_CAPTURE); + imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_IMAGE; + return; + } else if (present + || imgdev->action_state != IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF) { + fp_dbg("ignoring status report"); + return; + } + + /* clear these before reporting results to avoid complications with + * call cascading in and out of the library */ + imgdev->acquire_img = NULL; + imgdev->acquire_data = NULL; + + /* finger removed, report results */ + switch (imgdev->action) { + case IMG_ACTION_ENROLL: + fp_dbg("reporting enroll result"); + fpi_drvcb_enroll_stage_completed(imgdev->dev, r, data, img); + if (r > 0 && r != FP_ENROLL_COMPLETE && r != FP_ENROLL_FAIL) { + imgdev->action_result = 0; + imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_ON; + dev_change_state(imgdev, IMG_ACQUIRE_STATE_AWAIT_FINGER_ON); + } + break; + case IMG_ACTION_VERIFY: + fpi_drvcb_report_verify_result(imgdev->dev, r, img); + fp_print_data_free(data); + break; + case IMG_ACTION_IDENTIFY: + fpi_drvcb_report_identify_result(imgdev->dev, r, + imgdev->identify_match_offset, img); + fp_print_data_free(data); + break; + default: + fp_err("unhandled action %d", imgdev->action); + break; + } +} + +static void verify_process_img(struct fp_img_dev *imgdev) +{ + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); + int match_score = imgdrv->bz3_threshold; + int r; + + if (match_score == 0) + match_score = BOZORTH3_DEFAULT_THRESHOLD; + + r = fpi_img_compare_print_data(imgdev->dev->verify_data, + imgdev->acquire_data); + + if (r >= match_score) + r = FP_VERIFY_MATCH; + else if (r >= 0) + r = FP_VERIFY_NO_MATCH; + + imgdev->action_result = r; +} + +static void identify_process_img(struct fp_img_dev *imgdev) +{ + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); + int match_score = imgdrv->bz3_threshold; + size_t match_offset; + int r; + + if (match_score == 0) + match_score = BOZORTH3_DEFAULT_THRESHOLD; + + r = fpi_img_compare_print_data_to_gallery(imgdev->acquire_data, + imgdev->dev->identify_gallery, match_score, &match_offset); + + imgdev->action_result = r; + imgdev->identify_match_offset = match_offset; +} + +void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) +{ + struct fp_print_data *print; + int r; + fp_dbg(""); + + if (imgdev->action_state != IMG_ACQUIRE_STATE_AWAIT_IMAGE) { + fp_dbg("ignoring due to current state %d", imgdev->action_state); + return; + } + + if (imgdev->action_result) { + fp_dbg("not overwriting existing action result"); + return; + } + + r = sanitize_image(imgdev, &img); + if (r < 0) { + imgdev->action_result = r; + fp_img_free(img); + goto next_state; + } + + fp_img_standardize(img); + imgdev->acquire_img = img; + fpi_img_to_print_data(imgdev, img, &print); + if (img->minutiae->num < MIN_ACCEPTABLE_MINUTIAE) { + fp_dbg("not enough minutiae, %d/%d", img->minutiae->num, + MIN_ACCEPTABLE_MINUTIAE); + fp_print_data_free(print); + /* depends on FP_ENROLL_RETRY == FP_VERIFY_RETRY */ + imgdev->action_result = FP_ENROLL_RETRY; + goto next_state; + } + + imgdev->acquire_data = print; + switch (imgdev->action) { + case IMG_ACTION_ENROLL: + imgdev->action_result = FP_ENROLL_COMPLETE; + break; + case IMG_ACTION_VERIFY: + verify_process_img(imgdev); + break; + case IMG_ACTION_IDENTIFY: + identify_process_img(imgdev); + break; + default: + BUG(); + break; + } + +next_state: + imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF; + dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_OFF); +} + +void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error) +{ + fp_dbg("error %d", error); + BUG_ON(error == 0); + switch (imgdev->action) { + case IMG_ACTION_ENROLL: + fpi_drvcb_enroll_stage_completed(imgdev->dev, error, NULL, NULL); + break; + case IMG_ACTION_VERIFY: + fpi_drvcb_report_verify_result(imgdev->dev, error, NULL); + break; + case IMG_ACTION_IDENTIFY: + fpi_drvcb_report_identify_result(imgdev->dev, error, 0, NULL); + break; + default: + fp_err("unhandled action %d", imgdev->action); + break; + } +} + +void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status) +{ + fp_dbg("status %d", status); + + switch (imgdev->action) { + case IMG_ACTION_ENROLL: + fpi_drvcb_enroll_started(imgdev->dev, status); + break; + case IMG_ACTION_VERIFY: + fpi_drvcb_verify_started(imgdev->dev, status); + break; + case IMG_ACTION_IDENTIFY: + fpi_drvcb_identify_started(imgdev->dev, status); + break; + default: + fp_err("unhandled action %d", imgdev->action); + return; + } + + if (status == 0) { + imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_ON; + dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_ON); + } +} + +void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev) +{ + fp_dbg(""); + + switch (imgdev->action) { + case IMG_ACTION_ENROLL: + fpi_drvcb_enroll_stopped(imgdev->dev); + break; + case IMG_ACTION_VERIFY: + fpi_drvcb_verify_stopped(imgdev->dev); + break; + case IMG_ACTION_IDENTIFY: + fpi_drvcb_identify_stopped(imgdev->dev); + break; + default: + fp_err("unhandled action %d", imgdev->action); + break; + } + + imgdev->action = IMG_ACTION_NONE; + imgdev->action_state = 0; +} + +int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev) +{ + struct fp_driver *drv = imgdev->dev->drv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); + int width = imgdrv->img_width; + + if (width == -1) + width = 0; + + return width; +} + +int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev) +{ + struct fp_driver *drv = imgdev->dev->drv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); + int height = imgdrv->img_height; + + if (height == -1) + height = 0; + + return height; +} + +static int dev_activate(struct fp_img_dev *imgdev, enum fp_imgdev_state state) +{ + struct fp_driver *drv = imgdev->dev->drv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); + + if (!imgdrv->activate) + return 0; + return imgdrv->activate(imgdev, state); +} + +static void dev_deactivate(struct fp_img_dev *imgdev) +{ + struct fp_driver *drv = imgdev->dev->drv; + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); + + if (!imgdrv->activate) + return; + return imgdrv->deactivate(imgdev); +} + +static int generic_acquire_start(struct fp_dev *dev, int action) +{ + struct fp_img_dev *imgdev = dev->priv; + int r; + fp_dbg("action %d", action); + imgdev->action = action; + imgdev->action_state = IMG_ACQUIRE_STATE_ACTIVATING; + + r = dev_activate(imgdev, IMGDEV_STATE_AWAIT_FINGER_ON); + if (r < 0) + fp_err("activation failed with error %d", r); + + return r; + +} + +static void generic_acquire_stop(struct fp_img_dev *imgdev) +{ + imgdev->action_state = IMG_ACQUIRE_STATE_DEACTIVATING; + dev_deactivate(imgdev); + + fp_print_data_free(imgdev->acquire_data); + fp_img_free(imgdev->acquire_img); + imgdev->acquire_data = NULL; + imgdev->acquire_img = NULL; + imgdev->action_result = 0; +} + +static int img_dev_enroll_start(struct fp_dev *dev) +{ + return generic_acquire_start(dev, IMG_ACTION_ENROLL); +} + +static int img_dev_verify_start(struct fp_dev *dev) +{ + return generic_acquire_start(dev, IMG_ACTION_VERIFY); +} + +static int img_dev_identify_start(struct fp_dev *dev) +{ + return generic_acquire_start(dev, IMG_ACTION_IDENTIFY); +} + +static int img_dev_enroll_stop(struct fp_dev *dev) +{ + struct fp_img_dev *imgdev = dev->priv; + BUG_ON(imgdev->action != IMG_ACTION_ENROLL); + generic_acquire_stop(imgdev); + return 0; +} + +static int img_dev_verify_stop(struct fp_dev *dev, gboolean iterating) +{ + struct fp_img_dev *imgdev = dev->priv; + BUG_ON(imgdev->action != IMG_ACTION_VERIFY); + generic_acquire_stop(imgdev); + return 0; +} + +static int img_dev_identify_stop(struct fp_dev *dev, gboolean iterating) +{ + struct fp_img_dev *imgdev = dev->priv; + BUG_ON(imgdev->action != IMG_ACTION_IDENTIFY); + generic_acquire_stop(imgdev); + imgdev->identify_match_offset = 0; + return 0; +} + +void fpi_img_driver_setup(struct fp_img_driver *idriver) +{ + idriver->driver.type = DRIVER_IMAGING; + idriver->driver.open = img_dev_open; + idriver->driver.close = img_dev_close; + idriver->driver.enroll_start = img_dev_enroll_start; + idriver->driver.enroll_stop = img_dev_enroll_stop; + idriver->driver.verify_start = img_dev_verify_start; + idriver->driver.verify_stop = img_dev_verify_stop; + idriver->driver.identify_start = img_dev_identify_start; + idriver->driver.identify_stop = img_dev_identify_stop; +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/imagemagick.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/imagemagick.c.svn-base @@ -0,0 +1,67 @@ +/* + * Imaging utility functions for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 +#include + +#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; +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/poll.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/poll.c.svn-base @@ -0,0 +1,354 @@ +/* + * Polling/timing management + * Copyright (C) 2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "poll" + +#include +#include +#include +#include + +#include +#include + +#include "fp_internal.h" + +/** + * @defgroup poll Polling and timing operations + * These functions are only applicable to users of libfprint's asynchronous + * API. + * + * libfprint does not create internal library threads and hence can only + * execute when your application is calling a libfprint function. However, + * libfprint often has work to be do, such as handling of completed USB + * transfers, and processing of timeouts required in order for the library + * to function. Therefore it is essential that your own application must + * regularly "phone into" libfprint so that libfprint can handle any pending + * events. + * + * The function you must call is fp_handle_events() or a variant of it. This + * function will handle any pending events, and it is from this context that + * all asynchronous event callbacks from the library will occur. You can view + * this function as a kind of iteration function. + * + * If there are no events pending, fp_handle_events() will block for a few + * seconds (and will handle any new events should anything occur in that time). + * If you wish to customise this timeout, you can use + * fp_handle_events_timeout() instead. If you wish to do a nonblocking + * iteration, call fp_handle_events_timeout() with a zero timeout. + * + * TODO: document how application is supposed to know when to call these + * functions. + */ + +/* this is a singly-linked list of pending timers, sorted with the timer that + * is expiring soonest at the head. */ +static GSList *active_timers = NULL; + +/* notifiers for added or removed poll fds */ +static fp_pollfd_added_cb fd_added_cb = NULL; +static fp_pollfd_removed_cb fd_removed_cb = NULL; + +struct fpi_timeout { + struct timeval expiry; + fpi_timeout_fn callback; + void *data; +}; + +static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) +{ + struct fpi_timeout *a = (struct fpi_timeout *) _a; + struct fpi_timeout *b = (struct fpi_timeout *) _b; + struct timeval *tv_a = &a->expiry; + struct timeval *tv_b = &b->expiry; + + if (timercmp(tv_a, tv_b, <)) + return -1; + else if (timercmp(tv_a, tv_b, >)) + return 1; + else + return 0; +} + +/* A timeout is the asynchronous equivalent of sleeping. You create a timeout + * saying that you'd like to have a function invoked at a certain time in + * the future. */ +struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, + void *data) +{ + struct timespec ts; + struct timeval add_msec; + struct fpi_timeout *timeout; + int r; + + fp_dbg("in %dms", msec); + + r = clock_gettime(CLOCK_MONOTONIC, &ts); + if (r < 0) { + fp_err("failed to read monotonic clock, errno=%d", errno); + return NULL; + } + + timeout = g_malloc(sizeof(*timeout)); + timeout->callback = callback; + timeout->data = data; + TIMESPEC_TO_TIMEVAL(&timeout->expiry, &ts); + + /* calculate timeout expiry by adding delay to current monotonic clock */ + timerclear(&add_msec); + add_msec.tv_sec = msec / 1000; + add_msec.tv_usec = (msec % 1000) * 1000; + timeradd(&timeout->expiry, &add_msec, &timeout->expiry); + + active_timers = g_slist_insert_sorted(active_timers, timeout, + timeout_sort_fn); + + return timeout; +} + +void fpi_timeout_cancel(struct fpi_timeout *timeout) +{ + fp_dbg(""); + active_timers = g_slist_remove(active_timers, timeout); + g_free(timeout); +} + +/* get the expiry time and optionally the timeout structure for the next + * timeout. returns 0 if there are no expired timers, or 1 if the + * timeval/timeout output parameters were populated. if the returned timeval + * is zero then it means the timeout has already expired and should be handled + * ASAP. */ +static int get_next_timeout_expiry(struct timeval *out, + struct fpi_timeout **out_timeout) +{ + struct timespec ts; + struct timeval tv; + struct fpi_timeout *next_timeout; + int r; + + if (active_timers == NULL) + return 0; + + r = clock_gettime(CLOCK_MONOTONIC, &ts); + if (r < 0) { + fp_err("failed to read monotonic clock, errno=%d", errno); + return r; + } + TIMESPEC_TO_TIMEVAL(&tv, &ts); + + next_timeout = active_timers->data; + if (out_timeout) + *out_timeout = next_timeout; + + if (timercmp(&tv, &next_timeout->expiry, >=)) { + fp_dbg("first timeout already expired"); + timerclear(out); + } else { + timersub(&next_timeout->expiry, &tv, out); + fp_dbg("next timeout in %d.%06ds", out->tv_sec, out->tv_usec); + } + + return 1; +} + +/* handle a timeout that has expired */ +static void handle_timeout(struct fpi_timeout *timeout) +{ + fp_dbg(""); + timeout->callback(timeout->data); + active_timers = g_slist_remove(active_timers, timeout); + g_free(timeout); +} + +static int handle_timeouts(void) +{ + struct timeval next_timeout_expiry; + struct fpi_timeout *next_timeout; + int r; + + r = get_next_timeout_expiry(&next_timeout_expiry, &next_timeout); + if (r <= 0) + return r; + + if (!timerisset(&next_timeout_expiry)) + handle_timeout(next_timeout); + + return 0; +} + +/** \ingroup poll + * Handle any pending events. If a non-zero timeout is specified, the function + * will potentially block for the specified amount of time, although it may + * return sooner if events have been handled. The function acts as non-blocking + * for a zero timeout. + * + * \param timeout Maximum timeout for this blocking function + * \returns 0 on success, non-zero on error. + */ +API_EXPORTED int fp_handle_events_timeout(struct timeval *timeout) +{ + struct timeval next_timeout_expiry; + struct timeval select_timeout; + struct fpi_timeout *next_timeout; + int r; + + r = get_next_timeout_expiry(&next_timeout_expiry, &next_timeout); + if (r < 0) + return r; + + if (r) { + /* timer already expired? */ + if (!timerisset(&next_timeout_expiry)) { + handle_timeout(next_timeout); + return 0; + } + + /* choose the smallest of next URB timeout or user specified timeout */ + if (timercmp(&next_timeout_expiry, timeout, <)) + select_timeout = next_timeout_expiry; + else + select_timeout = *timeout; + } else { + select_timeout = *timeout; + } + + r = libusb_handle_events_timeout(fpi_usb_ctx, &select_timeout); + *timeout = select_timeout; + if (r < 0) + return r; + + return handle_timeouts(); +} + +/** \ingroup poll + * Convenience function for calling fp_handle_events_timeout() with a sensible + * default timeout value of two seconds (subject to change if we decide another + * value is more sensible). + * + * \returns 0 on success, non-zero on error. + */ +API_EXPORTED int fp_handle_events(void) +{ + struct timeval tv; + tv.tv_sec = 2; + tv.tv_usec = 0; + return fp_handle_events_timeout(&tv); +} + +/* FIXME: docs + * returns 0 if no timeouts active + * returns 1 if timeout returned + * zero timeout means events are to be handled immediately */ +API_EXPORTED int fp_get_next_timeout(struct timeval *tv) +{ + struct timeval fprint_timeout; + struct timeval libusb_timeout; + int r_fprint; + int r_libusb; + + r_fprint = get_next_timeout_expiry(&fprint_timeout, NULL); + r_libusb = libusb_get_next_timeout(fpi_usb_ctx, &libusb_timeout); + + /* if we have no pending timeouts and the same is true for libusb, + * indicate that we have no pending timouts */ + if (r_fprint == 0 && r_libusb == 0) + return 0; + + /* otherwise return the smaller of the 2 timeouts */ + else if (timercmp(&fprint_timeout, &libusb_timeout, <)) + *tv = fprint_timeout; + else + *tv = libusb_timeout; + return 1; +} + +/** \ingroup poll + * Retrieve a list of file descriptors that should be polled for events + * interesting to libfprint. This function is only for users who wish to + * combine libfprint's file descriptor set with other event sources - more + * simplistic users will be able to call fp_handle_events() or a variant + * directly. + * + * \param pollfds output location for a list of pollfds. If non-NULL, must be + * released with free() when done. + * \returns the number of pollfds in the resultant list, or negative on error. + */ +API_EXPORTED size_t fp_get_pollfds(struct fp_pollfd **pollfds) +{ + const struct libusb_pollfd **usbfds; + const struct libusb_pollfd *usbfd; + struct fp_pollfd *ret; + size_t cnt = 0; + size_t i = 0; + + usbfds = libusb_get_pollfds(fpi_usb_ctx); + if (!usbfds) { + *pollfds = NULL; + return -EIO; + } + + while ((usbfd = usbfds[i++]) != NULL) + cnt++; + + ret = g_malloc(sizeof(struct fp_pollfd) * cnt); + i = 0; + while ((usbfd = usbfds[i]) != NULL) { + ret[i].fd = usbfd->fd; + ret[i].events = usbfd->events; + i++; + } + + *pollfds = ret; + return cnt; +} + +/* FIXME: docs */ +API_EXPORTED void fp_set_pollfd_notifiers(fp_pollfd_added_cb added_cb, + fp_pollfd_removed_cb removed_cb) +{ + fd_added_cb = added_cb; + fd_removed_cb = removed_cb; +} + +static void add_pollfd(int fd, short events, void *user_data) +{ + if (fd_added_cb) + fd_added_cb(fd, events); +} + +static void remove_pollfd(int fd, void *user_data) +{ + if (fd_removed_cb) + fd_removed_cb(fd); +} + +void fpi_poll_init(void) +{ + libusb_set_pollfd_notifiers(fpi_usb_ctx, add_pollfd, remove_pollfd, NULL); +} + +void fpi_poll_exit(void) +{ + g_slist_free(active_timers); + active_timers = NULL; + fd_added_cb = NULL; + fd_removed_cb = NULL; + libusb_set_pollfd_notifiers(fpi_usb_ctx, NULL, NULL, NULL); +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/img.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/img.c.svn-base @@ -0,0 +1,477 @@ +/* + * Image management functions for libfprint + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include +#include +#include + +#include + +#include "fp_internal.h" +#include "nbis/include/bozorth.h" +#include "nbis/include/lfs.h" + +/** @defgroup img Image operations + * libfprint offers several ways of retrieving images from imaging devices, + * one example being the fp_dev_img_capture() function. The functions + * documented below allow you to work with such images. + * + * \section img_fmt Image format + * All images are represented as 8-bit greyscale data. + * + * \section img_std Image standardization + * In some contexts, images you are provided through libfprint are raw images + * from the hardware. The orientation of these varies from device-to-device, + * as does the color scheme (black-on-white or white-on-black?). libfprint + * provides the fp_img_standardize function to convert images into standard + * form, which is defined to be: finger flesh as black on white surroundings, + * natural upright orientation. + */ + +struct fp_img *fpi_img_new(size_t length) +{ + struct fp_img *img = g_malloc(sizeof(*img) + length); + memset(img, 0, sizeof(*img)); + fp_dbg("length=%zd", length); + img->length = length; + return img; +} + +struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev) +{ + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); + int width = imgdrv->img_width; + int height = imgdrv->img_height; + struct fp_img *img = fpi_img_new(width * height); + img->width = width; + img->height = height; + return img; +} + +gboolean fpi_img_is_sane(struct fp_img *img) +{ + /* basic checks */ + if (!img->length || !img->width || !img->height) + return FALSE; + + /* buffer is big enough? */ + if ((img->length * img->height) < img->length) + return FALSE; + + return TRUE; +} + +struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize) +{ + return g_realloc(img, sizeof(*img) + newsize); +} + +/** \ingroup img + * Frees an image. Must be called when you are finished working with an image. + * \param img the image to destroy. If NULL, function simply returns. + */ +API_EXPORTED void fp_img_free(struct fp_img *img) +{ + if (!img) + return; + + if (img->minutiae) + free_minutiae(img->minutiae); + if (img->binarized) + free(img->binarized); + g_free(img); +} + +/** \ingroup img + * Gets the pixel height of an image. + * \param img an image + * \returns the height of the image + */ +API_EXPORTED int fp_img_get_height(struct fp_img *img) +{ + return img->height; +} + +/** \ingroup img + * Gets the pixel width of an image. + * \param img an image + * \returns the width of the image + */ +API_EXPORTED int fp_img_get_width(struct fp_img *img) +{ + return img->width; +} + +/** \ingroup img + * Gets the greyscale data for an image. This data must not be modified or + * freed, and must not be used after fp_img_free() has been called. + * \param img an image + * \returns a pointer to libfprint's internal data for the image + */ +API_EXPORTED unsigned char *fp_img_get_data(struct fp_img *img) +{ + return img->data; +} + +/** \ingroup img + * A quick convenience function to save an image to a file in + * PGM format. + * \param img the image to save + * \param path the path to save the image. Existing files will be overwritten. + * \returns 0 on success, non-zero on error. + */ +API_EXPORTED int fp_img_save_to_file(struct fp_img *img, char *path) +{ + FILE *fd = fopen(path, "w"); + size_t write_size = img->width * img->height; + int r; + + if (!fd) { + fp_dbg("could not open '%s' for writing: %d", path, errno); + return -errno; + } + + r = fprintf(fd, "P5 %d %d 255\n", img->width, img->height); + if (r < 0) { + fp_err("pgm header write failed, error %d", r); + return r; + } + + r = fwrite(img->data, 1, write_size, fd); + if (r < write_size) { + fp_err("short write (%d)", r); + return -EIO; + } + + fclose(fd); + fp_dbg("written to '%s'", path); + return 0; +} + +static void vflip(struct fp_img *img) +{ + int width = img->width; + int data_len = img->width * img->height; + unsigned char rowbuf[width]; + int i; + + for (i = 0; i < img->height / 2; i++) { + int offset = i * width; + int swap_offset = data_len - (width * (i + 1)); + + /* copy top row into buffer */ + memcpy(rowbuf, img->data + offset, width); + + /* copy lower row over upper row */ + memcpy(img->data + offset, img->data + swap_offset, width); + + /* copy buffer over lower row */ + memcpy(img->data + swap_offset, rowbuf, width); + } +} + +static void hflip(struct fp_img *img) +{ + int width = img->width; + unsigned char rowbuf[width]; + int i, j; + + for (i = 0; i < img->height; i++) { + int offset = i * width; + + memcpy(rowbuf, img->data + offset, width); + for (j = 0; j < width; j++) + img->data[offset + j] = rowbuf[width - j - 1]; + } +} + +static void invert_colors(struct fp_img *img) +{ + int data_len = img->width * img->height; + int i; + for (i = 0; i < data_len; i++) + img->data[i] = 0xff - img->data[i]; +} + +/** \ingroup img + * \ref img_std "Standardizes" an image by normalizing its orientation, colors, + * etc. It is safe to call this multiple times on an image, libfprint keeps + * track of the work it needs to do to make an image standard and will not + * perform these operations more than once for a given image. + * \param img the image to standardize + */ +API_EXPORTED void fp_img_standardize(struct fp_img *img) +{ + if (img->flags & FP_IMG_V_FLIPPED) { + vflip(img); + img->flags &= ~FP_IMG_V_FLIPPED; + } + if (img->flags & FP_IMG_H_FLIPPED) { + hflip(img); + img->flags &= ~FP_IMG_H_FLIPPED; + } + if (img->flags & FP_IMG_COLORS_INVERTED) { + invert_colors(img); + img->flags &= ~FP_IMG_COLORS_INVERTED; + } +} + +/* Based on write_minutiae_XYTQ and bz_load */ +static void minutiae_to_xyt(struct fp_minutiae *minutiae, int bwidth, + int bheight, unsigned char *buf) +{ + int i; + struct fp_minutia *minutia; + struct minutiae_struct c[MAX_FILE_MINUTIAE]; + struct xyt_struct *xyt = (struct xyt_struct *) buf; + + /* FIXME: only considers first 150 minutiae (MAX_FILE_MINUTIAE) */ + /* nist does weird stuff with 150 vs 1000 limits */ + int nmin = min(minutiae->num, MAX_FILE_MINUTIAE); + + for (i = 0; i < nmin; i++){ + minutia = minutiae->list[i]; + + lfs2nist_minutia_XYT(&c[i].col[0], &c[i].col[1], &c[i].col[2], + minutia, bwidth, bheight); + c[i].col[3] = sround(minutia->reliability * 100.0); + + if (c[i].col[2] > 180) + c[i].col[2] -= 360; + } + + qsort((void *) &c, (size_t) nmin, sizeof(struct minutiae_struct), + sort_x_y); + + for (i = 0; i < nmin; i++) { + xyt->xcol[i] = c[i].col[0]; + xyt->ycol[i] = c[i].col[1]; + xyt->thetacol[i] = c[i].col[2]; + } + xyt->nrows = nmin; +} + +int fpi_img_detect_minutiae(struct fp_img *img) +{ + struct fp_minutiae *minutiae; + int r; + int *direction_map, *low_contrast_map, *low_flow_map; + int *high_curve_map, *quality_map; + int map_w, map_h; + unsigned char *bdata; + int bw, bh, bd; + GTimer *timer; + + if (img->flags & FP_IMG_STANDARDIZATION_FLAGS) { + fp_err("cant detect minutiae for non-standardized image"); + return -EINVAL; + } + + /* 25.4 mm per inch */ + timer = g_timer_new(); + r = get_minutiae(&minutiae, &quality_map, &direction_map, + &low_contrast_map, &low_flow_map, &high_curve_map, + &map_w, &map_h, &bdata, &bw, &bh, &bd, + img->data, img->width, img->height, 8, + DEFAULT_PPI / (double)25.4, &lfsparms_V2); + g_timer_stop(timer); + fp_dbg("minutiae scan completed in %f secs", g_timer_elapsed(timer, NULL)); + g_timer_destroy(timer); + if (r) { + fp_err("get minutiae failed, code %d", r); + return r; + } + fp_dbg("detected %d minutiae", minutiae->num); + img->minutiae = minutiae; + img->binarized = bdata; + + free(quality_map); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + return minutiae->num; +} + +int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img, + struct fp_print_data **ret) +{ + struct fp_print_data *print; + int r; + + if (!img->minutiae) { + r = fpi_img_detect_minutiae(img); + if (r < 0) + return r; + if (!img->minutiae) { + fp_err("no minutiae after successful detection?"); + return -ENOENT; + } + } + + /* FIXME: space is wasted if we dont hit the max minutiae count. would + * be good to make this dynamic. */ + print = fpi_print_data_new(imgdev->dev, sizeof(struct xyt_struct)); + print->type = PRINT_DATA_NBIS_MINUTIAE; + minutiae_to_xyt(img->minutiae, img->width, img->height, print->data); + + /* FIXME: the print buffer at this point is endian-specific, and will + * only work when loaded onto machines with identical endianness. not good! + * data format should be platform-independent. */ + *ret = print; + + return 0; +} + +int fpi_img_compare_print_data(struct fp_print_data *enrolled_print, + struct fp_print_data *new_print) +{ + struct xyt_struct *gstruct = (struct xyt_struct *) enrolled_print->data; + struct xyt_struct *pstruct = (struct xyt_struct *) new_print->data; + GTimer *timer; + int r; + + if (enrolled_print->type != PRINT_DATA_NBIS_MINUTIAE || + new_print->type != PRINT_DATA_NBIS_MINUTIAE) { + fp_err("invalid print format"); + return -EINVAL; + } + + timer = g_timer_new(); + r = bozorth_main(pstruct, gstruct); + g_timer_stop(timer); + fp_dbg("bozorth processing took %f seconds, score=%d", + g_timer_elapsed(timer, NULL), r); + g_timer_destroy(timer); + + return r; +} + +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 xyt_struct *pstruct = (struct xyt_struct *) print->data; + struct fp_print_data *gallery_print; + int probe_len = bozorth_probe_init(pstruct); + size_t i = 0; + + while ((gallery_print = gallery[i++])) { + struct xyt_struct *gstruct = (struct xyt_struct *) gallery_print->data; + int r = bozorth_to_gallery(probe_len, pstruct, gstruct); + if (r >= match_threshold) { + *match_offset = i - 1; + return FP_VERIFY_MATCH; + } + } + return FP_VERIFY_NO_MATCH; +} + +/** \ingroup img + * Get a binarized form of a standardized scanned image. This is where the + * fingerprint image has been "enhanced" and is a set of pure black ridges + * on a pure white background. Internally, image processing happens on top + * of the binarized image. + * + * The image must have been \ref img_std "standardized" otherwise this function + * will fail. + * + * It is safe to binarize an image and free the original while continuing + * to use the binarized version. + * + * You cannot binarize an image twice. + * + * \param img a standardized image + * \returns a new image representing the binarized form of the original, or + * NULL on error. Must be freed with fp_img_free() after use. + */ +API_EXPORTED struct fp_img *fp_img_binarize(struct fp_img *img) +{ + struct fp_img *ret; + int height = img->height; + int width = img->width; + int imgsize = height * width; + + if (img->flags & FP_IMG_BINARIZED_FORM) { + fp_err("image already binarized"); + return NULL; + } + + if (!img->binarized) { + int r = fpi_img_detect_minutiae(img); + if (r < 0) + return NULL; + if (!img->binarized) { + fp_err("no minutiae after successful detection?"); + return NULL; + } + } + + ret = fpi_img_new(imgsize); + ret->flags |= FP_IMG_BINARIZED_FORM; + ret->width = width; + ret->height = height; + memcpy(ret->data, img->binarized, imgsize); + return ret; +} + +/** \ingroup img + * Get a list of minutiae detected in an image. A minutia point is a feature + * detected on a fingerprint, typically where ridges end or split. + * libfprint's image processing code relies upon comparing sets of minutiae, + * so accurate placement of minutia points is critical for good imaging + * performance. + * + * The image must have been \ref img_std "standardized" otherwise this function + * will fail. + * + * You cannot pass a binarized image to this function. Instead, pass the + * original image. + * + * Returns a list of pointers to minutiae, where the list is of length + * indicated in the nr_minutiae output parameter. The returned list is only + * valid while the parent image has not been freed, and the minutiae data + * must not be modified or freed. + * + * \param img a standardized image + * \param nr_minutiae an output location to store minutiae list length + * \returns a list of minutiae points. Must not be modified or freed. + */ +API_EXPORTED struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, + int *nr_minutiae) +{ + if (img->flags & FP_IMG_BINARIZED_FORM) { + fp_err("image is binarized"); + return NULL; + } + + if (!img->minutiae) { + int r = fpi_img_detect_minutiae(img); + if (r < 0) + return NULL; + if (!img->minutiae) { + fp_err("no minutiae after successful detection?"); + return NULL; + } + } + + *nr_minutiae = img->minutiae->num; + return img->minutiae->list; +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/Makefile.am.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/Makefile.am.svn-base @@ -0,0 +1,130 @@ +lib_LTLIBRARIES = libfprint.la +noinst_PROGRAMS = fprint-list-hal-info +MOSTLYCLEANFILES = $(hal_fdi_DATA) + +UPEKTS_SRC = drivers/upekts.c +UPEKTC_SRC = drivers/upektc.c +UPEKSONLY_SRC = drivers/upeksonly.c +URU4000_SRC = drivers/uru4000.c +AES1610_SRC = drivers/aes1610.c +AES2501_SRC = drivers/aes2501.c drivers/aes2501.h +AES4000_SRC = drivers/aes4000.c +FDU2000_SRC = drivers/fdu2000.c +VCOM5S_SRC = drivers/vcom5s.c + +DRIVER_SRC = +OTHER_SRC = + +NBIS_SRC = \ + nbis/include/bozorth.h \ + nbis/include/bz_array.h \ + nbis/include/defs.h \ + nbis/include/lfs.h \ + nbis/include/log.h \ + nbis/include/morph.h \ + nbis/include/sunrast.h \ + nbis/bozorth3/bozorth3.c \ + nbis/bozorth3/bz_alloc.c \ + nbis/bozorth3/bz_drvrs.c \ + nbis/bozorth3/bz_gbls.c \ + nbis/bozorth3/bz_io.c \ + nbis/bozorth3/bz_sort.c \ + nbis/mindtct/binar.c \ + nbis/mindtct/block.c \ + nbis/mindtct/contour.c \ + nbis/mindtct/detect.c \ + nbis/mindtct/dft.c \ + nbis/mindtct/free.c \ + nbis/mindtct/globals.c \ + nbis/mindtct/imgutil.c \ + nbis/mindtct/init.c \ + nbis/mindtct/line.c \ + nbis/mindtct/log.c \ + nbis/mindtct/loop.c \ + nbis/mindtct/maps.c \ + nbis/mindtct/matchpat.c \ + nbis/mindtct/minutia.c \ + nbis/mindtct/morph.c \ + nbis/mindtct/quality.c \ + nbis/mindtct/remove.c \ + nbis/mindtct/ridges.c \ + nbis/mindtct/shape.c \ + nbis/mindtct/sort.c \ + nbis/mindtct/util.c + +libfprint_la_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS) +libfprint_la_LDFLAGS = -version-info @lt_major@:@lt_revision@:@lt_age@ +libfprint_la_LIBADD = -lm $(LIBUSB_LIBS) $(GLIB_LIBS) $(CRYPTO_LIBS) + +fprint_list_hal_info_SOURCES = fprint-list-hal-info.c +fprint_list_hal_info_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(IMAGEMAGICK_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS) +fprint_list_hal_info_LDADD = $(builddir)/libfprint.la + +hal_fdi_DATA = 10-fingerprint-reader-fprint.fdi +hal_fdidir = $(datadir)/hal/fdi/information/20thirdparty/ + +$(hal_fdi_DATA): fprint-list-hal-info + $(builddir)/fprint-list-hal-info > $@ + + +if ENABLE_UPEKTS +DRIVER_SRC += $(UPEKTS_SRC) +endif + +if ENABLE_UPEKSONLY +DRIVER_SRC += $(UPEKSONLY_SRC) +endif + +#if ENABLE_UPEKTC +#DRIVER_SRC += $(UPEKTC_SRC) +#endif + +if ENABLE_URU4000 +DRIVER_SRC += $(URU4000_SRC) +endif + +if ENABLE_VCOM5S +DRIVER_SRC += $(VCOM5S_SRC) +endif + +#if ENABLE_FDU2000 +#DRIVER_SRC += $(FDU2000_SRC) +#endif + +#if ENABLE_AES1610 +#DRIVER_SRC += $(AES1610_SRC) +#endif + +if ENABLE_AES2501 +DRIVER_SRC += $(AES2501_SRC) +endif + +if ENABLE_AES4000 +DRIVER_SRC += $(AES4000_SRC) +endif + +if REQUIRE_IMAGEMAGICK +OTHER_SRC += imagemagick.c +libfprint_la_CFLAGS += $(IMAGEMAGICK_CFLAGS) +libfprint_la_LIBADD += $(IMAGEMAGICK_LIBS) +endif + +if REQUIRE_AESLIB +OTHER_SRC += aeslib.c aeslib.h +endif + +libfprint_la_SOURCES = \ + fp_internal.h \ + async.c \ + core.c \ + data.c \ + drv.c \ + img.c \ + imgdev.c \ + poll.c \ + sync.c \ + $(DRIVER_SRC) \ + $(OTHER_SRC) \ + $(NBIS_SRC) + +pkginclude_HEADERS = fprint.h --- libfprint-20081125git.orig/libfprint/.svn/text-base/drv.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/drv.c.svn-base @@ -0,0 +1,171 @@ +/* + * Functions to assist with asynchronous driver <---> library communications + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "drv" + +#include +#include + +#include "fp_internal.h" + +/* SSM: sequential state machine + * Asynchronous driver design encourages some kind of state machine behind it. + * In most cases, the state machine is entirely linear - you only go to the + * next state, you never jump or go backwards. The SSM functions help you + * implement such a machine. + * + * e.g. S1 --> S2 --> S3 --> S4 + * S1 is the start state + * There is also an implicit error state and an implicit accepting state + * (both with implicit edges from every state). + * + * You can also jump to any arbitrary state (while marking completion of the + * current state) while the machine is running. In other words there are + * implicit edges linking one state to every other state. OK, we're stretching + * the "state machine" description at this point. + * + * To create a ssm, you pass a state handler function and the total number of + * states (4 in the above example). + * + * To start a ssm, you pass in a completion callback function which gets + * called when the ssm completes (both on error and on failure). + * + * To iterate to the next state, call fpi_ssm_next_state(). It is legal to + * attempt to iterate beyond the final state - this is equivalent to marking + * the ssm as successfully completed. + * + * To mark successful completion of a SSM, either iterate beyond the final + * state or call fpi_ssm_mark_completed() from any state. + * + * To mark failed completion of a SSM, call fpi_ssm_mark_aborted() from any + * state. You must pass a non-zero error code. + * + * Your state handling function looks at ssm->cur_state in order to determine + * the current state and hence which operations to perform (a switch statement + * is appropriate). + * Typically, the state handling function fires off an asynchronous libusb + * transfer, and the callback function iterates the machine to the next state + * upon success (or aborts the machine on transfer failure). + * + * Your completion callback should examine ssm->error in order to determine + * whether the ssm completed or failed. An error code of zero indicates + * successful completion. + */ + +/* Allocate a new ssm */ +struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, + int nr_states) +{ + struct fpi_ssm *machine; + BUG_ON(nr_states < 1); + + machine = g_malloc0(sizeof(*machine)); + machine->handler = handler; + machine->nr_states = nr_states; + machine->dev = dev; + machine->completed = TRUE; + return machine; +} + +/* Free a ssm */ +void fpi_ssm_free(struct fpi_ssm *machine) +{ + if (!machine) + return; + g_free(machine); +} + +/* Invoke the state handler */ +static void __ssm_call_handler(struct fpi_ssm *machine) +{ + fp_dbg("%p entering state %d", machine, machine->cur_state); + machine->handler(machine); +} + +/* Start a ssm. You can also restart a completed or aborted ssm. */ +void fpi_ssm_start(struct fpi_ssm *ssm, ssm_completed_fn callback) +{ + BUG_ON(!ssm->completed); + ssm->callback = callback; + ssm->cur_state = 0; + ssm->completed = FALSE; + ssm->error = 0; + __ssm_call_handler(ssm); +} + +static void __subsm_complete(struct fpi_ssm *ssm) +{ + struct fpi_ssm *parent = ssm->parentsm; + BUG_ON(!parent); + if (ssm->error) + fpi_ssm_mark_aborted(parent, ssm->error); + else + fpi_ssm_next_state(parent); + fpi_ssm_free(ssm); +} + +/* start a SSM as a child of another. if the child completes successfully, the + * parent will be advanced to the next state. if the child aborts, the parent + * will be aborted with the same error code. the child will be automatically + * freed upon completion/abortion. */ +void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child) +{ + child->parentsm = parent; + fpi_ssm_start(child, __subsm_complete); +} + +/* Mark a ssm as completed successfully. */ +void fpi_ssm_mark_completed(struct fpi_ssm *machine) +{ + BUG_ON(machine->completed); + machine->completed = TRUE; + fp_dbg("%p completed with status %d", machine, machine->error); + if (machine->callback) + machine->callback(machine); +} + +/* Mark a ssm as aborted with error. */ +void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error) +{ + fp_dbg("error %d from state %d", error, machine->cur_state); + BUG_ON(error == 0); + machine->error = error; + fpi_ssm_mark_completed(machine); +} + +/* Iterate to next state of a ssm */ +void fpi_ssm_next_state(struct fpi_ssm *machine) +{ + BUG_ON(machine->completed); + machine->cur_state++; + if (machine->cur_state == machine->nr_states) { + fpi_ssm_mark_completed(machine); + } else { + __ssm_call_handler(machine); + } +} + +void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state) +{ + BUG_ON(machine->completed); + BUG_ON(state >= machine->nr_states); + machine->cur_state = state; + __ssm_call_handler(machine); +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/fprint.h.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/fprint.h.svn-base @@ -0,0 +1,340 @@ +/* + * Main definitions for libfprint + * Copyright (C) 2007 Daniel Drake + * + * 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 + */ + +#ifndef __FPRINT_H__ +#define __FPRINT_H__ + +#include +#include + +/* structs that applications are not allowed to peek into */ +struct fp_dscv_dev; +struct fp_dscv_print; +struct fp_dev; +struct fp_driver; +struct fp_print_data; +struct fp_img; + +/* misc/general stuff */ + +/** \ingroup print_data + * Numeric codes used to refer to fingers (and thumbs) of a human. These are + * purposely not available as strings, to avoid getting the library tangled up + * in localization efforts. + */ +enum fp_finger { + LEFT_THUMB = 1, /** thumb (left hand) */ + LEFT_INDEX, /** index finger (left hand) */ + LEFT_MIDDLE, /** middle finger (left hand) */ + LEFT_RING, /** ring finger (left hand) */ + LEFT_LITTLE, /** little finger (left hand) */ + RIGHT_THUMB, /** thumb (right hand) */ + RIGHT_INDEX, /** index finger (right hand) */ + RIGHT_MIDDLE, /** middle finger (right hand) */ + RIGHT_RING, /** ring finger (right hand) */ + RIGHT_LITTLE, /** little finger (right hand) */ +}; + +/** \ingroup dev + * Numeric codes used to refer to the scan type of the device. Devices require + * either swiping or pressing the finger on the device. This is useful for + * front-ends. + */ +enum fp_scan_type { + FP_SCAN_TYPE_PRESS = 0, /** press */ + FP_SCAN_TYPE_SWIPE, /** swipe */ +}; + +/* Drivers */ +const char *fp_driver_get_name(struct fp_driver *drv); +const char *fp_driver_get_full_name(struct fp_driver *drv); +uint16_t fp_driver_get_driver_id(struct fp_driver *drv); +enum fp_scan_type fp_driver_get_scan_type(struct fp_driver *drv); + +/* Device discovery */ +struct fp_dscv_dev **fp_discover_devs(void); +void fp_dscv_devs_free(struct fp_dscv_dev **devs); +struct fp_driver *fp_dscv_dev_get_driver(struct fp_dscv_dev *dev); +uint32_t fp_dscv_dev_get_devtype(struct fp_dscv_dev *dev); +int fp_dscv_dev_supports_print_data(struct fp_dscv_dev *dev, + struct fp_print_data *print); +int fp_dscv_dev_supports_dscv_print(struct fp_dscv_dev *dev, + struct fp_dscv_print *print); +struct fp_dscv_dev *fp_dscv_dev_for_print_data(struct fp_dscv_dev **devs, + struct fp_print_data *print); +struct fp_dscv_dev *fp_dscv_dev_for_dscv_print(struct fp_dscv_dev **devs, + struct fp_dscv_print *print); + +static inline uint16_t fp_dscv_dev_get_driver_id(struct fp_dscv_dev *dev) +{ + return fp_driver_get_driver_id(fp_dscv_dev_get_driver(dev)); +} + +/* Print discovery */ +struct fp_dscv_print **fp_discover_prints(void); +void fp_dscv_prints_free(struct fp_dscv_print **prints); +uint16_t fp_dscv_print_get_driver_id(struct fp_dscv_print *print); +uint32_t fp_dscv_print_get_devtype(struct fp_dscv_print *print); +enum fp_finger fp_dscv_print_get_finger(struct fp_dscv_print *print); +int fp_dscv_print_delete(struct fp_dscv_print *print); + +/* Device handling */ +struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev); +void fp_dev_close(struct fp_dev *dev); +struct fp_driver *fp_dev_get_driver(struct fp_dev *dev); +int fp_dev_get_nr_enroll_stages(struct fp_dev *dev); +uint32_t fp_dev_get_devtype(struct fp_dev *dev); +int fp_dev_supports_print_data(struct fp_dev *dev, struct fp_print_data *data); +int fp_dev_supports_dscv_print(struct fp_dev *dev, struct fp_dscv_print *print); + +int fp_dev_supports_imaging(struct fp_dev *dev); +int fp_dev_img_capture(struct fp_dev *dev, int unconditional, + struct fp_img **image); +int fp_dev_get_img_width(struct fp_dev *dev); +int fp_dev_get_img_height(struct fp_dev *dev); + +/** \ingroup dev + * Enrollment result codes returned from fp_enroll_finger(). + * Result codes with RETRY in the name suggest that the scan failed due to + * user error. Applications will generally want to inform the user of the + * problem and then retry the enrollment stage. For more info on the semantics + * of interpreting these result codes and tracking enrollment process, see + * \ref enrolling. + */ +enum fp_enroll_result { + /** Enrollment completed successfully, the enrollment data has been + * returned to the caller. */ + FP_ENROLL_COMPLETE = 1, + /** Enrollment failed due to incomprehensible data; this may occur when + * the user scans a different finger on each enroll stage. */ + FP_ENROLL_FAIL, + /** Enroll stage passed; more stages are need to complete the process. */ + FP_ENROLL_PASS, + /** The enrollment scan did not succeed due to poor scan quality or + * other general user scanning problem. */ + FP_ENROLL_RETRY = 100, + /** The enrollment scan did not succeed because the finger swipe was + * too short. */ + FP_ENROLL_RETRY_TOO_SHORT, + /** The enrollment scan did not succeed because the finger was not + * centered on the scanner. */ + FP_ENROLL_RETRY_CENTER_FINGER, + /** The verification scan did not succeed due to quality or pressure + * problems; the user should remove their finger from the scanner before + * retrying. */ + FP_ENROLL_RETRY_REMOVE_FINGER, +}; + +int fp_enroll_finger_img(struct fp_dev *dev, struct fp_print_data **print_data, + struct fp_img **img); + +/** \ingroup dev + * Performs an enroll stage. See \ref enrolling for an explanation of enroll + * stages. This function is just a shortcut to calling fp_enroll_finger_img() + * with a NULL image parameter. Be sure to read the description of + * fp_enroll_finger_img() in order to understand its behaviour. + * + * \param dev the device + * \param print_data a location to return the resultant enrollment data from + * the final stage. Must be freed with fp_print_data_free() after use. + * \return negative code on error, otherwise a code from #fp_enroll_result + */ +static inline int fp_enroll_finger(struct fp_dev *dev, + struct fp_print_data **print_data) +{ + return fp_enroll_finger_img(dev, print_data, NULL); +} + +/** \ingroup dev + * Verification result codes returned from fp_verify_finger(). Return codes + * are also shared with fp_identify_finger(). + * Result codes with RETRY in the name suggest that the scan failed due to + * user error. Applications will generally want to inform the user of the + * problem and then retry the verify operation. + */ +enum fp_verify_result { + /** The scan completed successfully, but the newly scanned fingerprint + * does not match the fingerprint being verified against. + * In the case of identification, this return code indicates that the + * scanned finger could not be found in the print gallery. */ + FP_VERIFY_NO_MATCH = 0, + /** The scan completed successfully and the newly scanned fingerprint does + * match the fingerprint being verified, or in the case of identification, + * the scanned fingerprint was found in the print gallery. */ + FP_VERIFY_MATCH = 1, + /** The scan did not succeed due to poor scan quality or other general + * user scanning problem. */ + FP_VERIFY_RETRY = FP_ENROLL_RETRY, + /** The scan did not succeed because the finger swipe was too short. */ + FP_VERIFY_RETRY_TOO_SHORT = FP_ENROLL_RETRY_TOO_SHORT, + /** The scan did not succeed because the finger was not centered on the + * scanner. */ + FP_VERIFY_RETRY_CENTER_FINGER = FP_ENROLL_RETRY_CENTER_FINGER, + /** The scan did not succeed due to quality or pressure problems; the user + * should remove their finger from the scanner before retrying. */ + FP_VERIFY_RETRY_REMOVE_FINGER = FP_ENROLL_RETRY_REMOVE_FINGER, +}; + +int fp_verify_finger_img(struct fp_dev *dev, + struct fp_print_data *enrolled_print, struct fp_img **img); + +/** \ingroup dev + * Performs a new scan and verify it against a previously enrolled print. This + * function is just a shortcut to calling fp_verify_finger_img() with a NULL + * image output parameter. + * \param dev the device to perform the scan. + * \param enrolled_print the print to verify against. Must have been previously + * enrolled with a device compatible to the device selected to perform the scan. + * \return negative code on error, otherwise a code from #fp_verify_result + * \sa fp_verify_finger_img() + */ +static inline int fp_verify_finger(struct fp_dev *dev, + struct fp_print_data *enrolled_print) +{ + return fp_verify_finger_img(dev, enrolled_print, NULL); +} + +int fp_dev_supports_identification(struct fp_dev *dev); +int fp_identify_finger_img(struct fp_dev *dev, + struct fp_print_data **print_gallery, size_t *match_offset, + struct fp_img **img); + +/** \ingroup dev + * Performs a new scan and attempts to identify the scanned finger against a + * collection of previously enrolled fingerprints. This function is just a + * shortcut to calling fp_identify_finger_img() with a NULL image output + * parameter. + * \param dev the device to perform the scan. + * \param print_gallery NULL-terminated array of pointers to the prints to + * identify against. Each one must have been previously enrolled with a device + * compatible to the device selected to perform the scan. + * \param match_offset output location to store the array index of the matched + * gallery print (if any was found). Only valid if FP_VERIFY_MATCH was + * returned. + * \return negative code on error, otherwise a code from #fp_verify_result + * \sa fp_identify_finger_img() + */ +static inline int fp_identify_finger(struct fp_dev *dev, + struct fp_print_data **print_gallery, size_t *match_offset) +{ + return fp_identify_finger_img(dev, print_gallery, match_offset, NULL); +} + +/* Data handling */ +int fp_print_data_load(struct fp_dev *dev, enum fp_finger finger, + struct fp_print_data **data); +int fp_print_data_from_dscv_print(struct fp_dscv_print *print, + struct fp_print_data **data); +int fp_print_data_save(struct fp_print_data *data, enum fp_finger finger); +int fp_print_data_delete(struct fp_dev *dev, enum fp_finger finger); +void fp_print_data_free(struct fp_print_data *data); +size_t fp_print_data_get_data(struct fp_print_data *data, unsigned char **ret); +struct fp_print_data *fp_print_data_from_data(unsigned char *buf, + size_t buflen); +uint16_t fp_print_data_get_driver_id(struct fp_print_data *data); +uint32_t fp_print_data_get_devtype(struct fp_print_data *data); + +/* Image handling */ + +/** \ingroup img */ +struct fp_minutia { + int x; + int y; + int ex; + int ey; + int direction; + double reliability; + int type; + int appearing; + int feature_id; + int *nbrs; + int *ridge_counts; + int num_nbrs; +}; + +int fp_img_get_height(struct fp_img *img); +int fp_img_get_width(struct fp_img *img); +unsigned char *fp_img_get_data(struct fp_img *img); +int fp_img_save_to_file(struct fp_img *img, char *path); +void fp_img_standardize(struct fp_img *img); +struct fp_img *fp_img_binarize(struct fp_img *img); +struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, int *nr_minutiae); +void fp_img_free(struct fp_img *img); + +/* Polling and timing */ + +struct fp_pollfd { + int fd; + short events; +}; + +int fp_handle_events_timeout(struct timeval *timeout); +int fp_handle_events(void); +size_t fp_get_pollfds(struct fp_pollfd **pollfds); +int fp_get_next_timeout(struct timeval *tv); + +typedef void (*fp_pollfd_added_cb)(int fd, short events); +typedef void (*fp_pollfd_removed_cb)(int fd); +void fp_set_pollfd_notifiers(fp_pollfd_added_cb added_cb, + fp_pollfd_removed_cb removed_cb); + +/* Library */ +int fp_init(void); +void fp_exit(void); +void fp_set_debug(int level); + +/* Asynchronous I/O */ + +typedef void (*fp_dev_open_cb)(struct fp_dev *dev, int status, void *user_data); +int fp_async_dev_open(struct fp_dscv_dev *ddev, fp_dev_open_cb callback, + void *user_data); + +typedef void (*fp_dev_close_cb)(struct fp_dev *dev, void *user_data); +void fp_async_dev_close(struct fp_dev *dev, fp_dev_close_cb callback, + void *user_data); + +typedef void (*fp_enroll_stage_cb)(struct fp_dev *dev, int result, + struct fp_print_data *print, struct fp_img *img, void *user_data); +int fp_async_enroll_start(struct fp_dev *dev, fp_enroll_stage_cb callback, + void *user_data); + +typedef void (*fp_enroll_stop_cb)(struct fp_dev *dev, void *user_data); +int fp_async_enroll_stop(struct fp_dev *dev, fp_enroll_stop_cb callback, + void *user_data); + +typedef void (*fp_verify_cb)(struct fp_dev *dev, int result, + struct fp_img *img, void *user_data); +int fp_async_verify_start(struct fp_dev *dev, struct fp_print_data *data, + fp_verify_cb callback, void *user_data); + +typedef void (*fp_verify_stop_cb)(struct fp_dev *dev, void *user_data); +int fp_async_verify_stop(struct fp_dev *dev, fp_verify_stop_cb callback, + void *user_data); + +typedef void (*fp_identify_cb)(struct fp_dev *dev, int result, + size_t match_offset, struct fp_img *img, void *user_data); +int fp_async_identify_start(struct fp_dev *dev, struct fp_print_data **gallery, + fp_identify_cb callback, void *user_data); + +typedef void (*fp_identify_stop_cb)(struct fp_dev *dev, void *user_data); +int fp_async_identify_stop(struct fp_dev *dev, fp_identify_stop_cb callback, + void *user_data); + +#endif + --- libfprint-20081125git.orig/libfprint/.svn/text-base/core.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/core.c.svn-base @@ -0,0 +1,937 @@ +/* + * Core functions for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 +#include +#include +#include + +#include +#include + +#include "fp_internal.h" + +static int log_level = 0; +static int log_level_fixed = 0; + +libusb_context *fpi_usb_ctx = NULL; +GSList *opened_devices = NULL; + +/** + * \mainpage libfprint API Reference + * libfprint is an open source library to provide access to fingerprint + * scanning devices. For more info, see the + * libfprint project + * homepage. + * + * This documentation is aimed at application developers who wish to integrate + * fingerprint-related functionality into their software. libfprint has been + * designed so that you only have to do this once - by integrating your + * software with libfprint, you'll be supporting all the fingerprint readers + * that we have got our hands on. As such, the API is rather general (and + * therefore hopefully easy to comprehend!), and does its best to hide the + * technical details that required to operate the hardware. + * + * This documentation is not aimed at developers wishing to develop and + * contribute fingerprint device drivers to libfprint. + * + * Feedback on this API and its associated documentation is appreciated. Was + * anything unclear? Does anything seem unreasonably complicated? Is anything + * missing? Let us know on the + * mailing list. + * + * \section enrollment Enrollment + * + * Before you dive into the API, it's worth introducing a couple of concepts. + * + * The process of enrolling a finger is where you effectively scan your + * finger for the purposes of teaching the system what your finger looks like. + * This means that you scan your fingerprint, then the system processes it and + * stores some data about your fingerprint to refer to later. + * + * \section verification Verification + * + * Verification is what most people think of when they think about fingerprint + * scanning. The process of verification is effectively performing a fresh + * fingerprint scan, and then comparing that scan to a finger that was + * previously enrolled. + * + * As an example scenario, verification can be used to implement what people + * would picture as fingerprint login (i.e. fingerprint replaces password). + * For example: + * - I enroll my fingerprint through some software that trusts I am who I say + * I am. This is a prerequisite before I can perform fingerprint-based + * login for my account. + * - Some time later, I want to login to my computer. I enter my username, + * but instead of prompting me for a password, it asks me to scan my finger. + * I scan my finger. + * - The system compares the finger I just scanned to the one that was + * enrolled earlier. If the system decides that the fingerprints match, + * I am successfully logged in. Otherwise, the system informs me that I am + * not authorised to login as that user. + * + * \section identification Identification + * + * Identification is the process of comparing a freshly scanned fingerprint + * to a collection of previously enrolled fingerprints. For example, + * imagine there are 100 people in an organisation, and they all have enrolled + * their fingerprints. One user walks up to a fingerprint scanner and scans + * their finger. With no other knowledge of who that user might be, + * the system examines their fingerprint, looks in the database, and determines + * that the user is user number #61. + * + * In other words, verification might be seen as a one-to-one fingerprint + * comparison where you know the identity of the user that you wish to + * authenticate, whereas identification is a one-to-many comparison where you + * do not know the identity of the user that you wish to authenticate. + * + * \section compat_general Device and print compatibility + * Moving off generic conceptual ideas and onto libfprint-specific + * implementation details, here are some introductory notes regarding how + * libfprint copes with compatibility of fingerprints. + * + * libfprint deals with a whole variety of different fingerprint readers and + * the design includes considerations of compatibility and interoperability + * between multiple devices. Your application should also be prepared to + * work with more than one type of fingerprint reader and should consider that + * enrolled fingerprint X may not be compatible with the device the user has + * plugged in today. + * + * libfprint implements the principle that fingerprints from different devices + * are not necessarily compatible. For example, different devices may see + * significantly different areas of fingerprint surface, and comparing images + * between the devices would be unreliable. Also, devices can stretch and + * distort images in different ways. + * + * libfprint also implements the principle that in some cases, fingerprints + * are compatible between different devices. If you go and buy two + * identical fingerprint readers, it seems logical that you should be able + * to enroll on one and verify on another without problems. + * + * libfprint takes a fairly simplistic approach to these issues. Internally, + * fingerprint hardware is driven by individual drivers. libfprint enforces + * that a fingerprint that came from a device backed by driver X is never + * compared to a fingerprint that came from a device backed by driver Y. + * + * Additionally, libfprint is designed for the situation where a single driver + * may support a range of devices which differ in imaging or scanning + * properties. For example, a driver may support two ranges of devices which + * even though are programmed over the same interface, one device sees + * substantially less of the finger flesh, therefore images from the two + * device types should be incompatible despite being from the same driver. To + * implement this, each driver assigns a device type to each device + * that it detects based on its imaging characteristics. libfprint ensures that + * two prints being compared have the same device type. + * + * In summary, libfprint represents fingerprints in several internal structures + * and each representation will offer you a way of determining the + * \ref driver_id "driver ID" and \ref devtype "devtype" of the print in + * question. Prints are only compatible if the driver ID and devtypes + * match. libfprint does offer you some "is this print compatible?" helper + * functions, so you don't have to worry about these details too much. + * + * \section sync Synchronity/asynchronity + * + * Currently, all data acquisition operations are synchronous and can + * potentially block for extended periods of time. For example, the enroll + * function will block for an unpredictable amount of time until the user + * scans their finger. + * + * Alternative asynchronous/non-blocking functionality will be offered in + * future but has not been implemented yet. + * + * \section getting_started Getting started + * + * libfprint includes several simple functional examples under the examples/ + * directory in the libfprint source distribution. Those are good starting + * points. + * + * Usually the first thing you want to do is determine which fingerprint + * devices are present. This is done through \ref dscv_dev "device discovery". + * + * Once you have found a device you would like to operate, you should open it. + * Refer to \ref dev "device operations". This section also details enrollment, + * image capture, and verification. + * + * + * That should be enough to get you started, but do remember there are + * documentation pages on other aspects of libfprint's API (see the modules + * page). + */ + +/** @defgroup core Core library operations */ + +/** + * @defgroup dev Device operations + * In order to interact with fingerprint scanners, your software will + * interface primarily with libfprint's representation of devices, detailed + * on this page. + * + * \section enrolling Enrolling + * Enrolling is represented within libfprint as a multi-stage process. This + * slightly complicates things for application developers, but is required + * for a smooth process. + * + * Some devices require the user to scan their finger multiple times in + * order to complete the enrollment process. libfprint must return control + * to your application inbetween each scan in order for your application to + * instruct the user to swipe their finger again. Each scan is referred to + * as a stage, so a device that requires 3 scans for enrollment corresponds + * to you running 3 enrollment stages using libfprint. + * + * The fp_dev_get_nr_enroll_stages() function can be used to find out how + * many enroll stages are needed. + * + * In order to complete an enroll stage, you call an enroll function such + * as fp_enroll_finger(). The return of this function does not necessarily + * indicate that a stage has completed though, as the user may not have + * produced a good enough scan. Each stage may have to be retried several + * times. + * + * The exact semantics of the enroll functions are described in the + * fp_enroll_finger() documentation. You should pay careful attention to the + * details. + * + * \section imaging Imaging + * libfprint provides you with some ways to retrieve images of scanned + * fingers, such as the fp_dev_img_capture() function, or some enroll/verify + * function variants which provide images. You may wish to do something with + * such images in your application. + * + * However, you must be aware that not all hardware supported by libfprint + * operates like this. Most hardware does operate simply by sending + * fingerprint images to the host computer for further processing, but some + * devices do all fingerprint processing in hardware and do not present images + * to the host computer. + * + * You can use fp_dev_supports_imaging() to see if image capture is possible + * on a particular device. Your application must be able to cope with the + * fact that libfprint does support regular operations (e.g. enrolling and + * verification) on some devices which do not provide images. + * + * \section devtype Devtypes + * Internally, the \ref drv "driver" behind a device assigns a 32-bit + * devtype identifier to the device. This cannot be used as a unique + * ID for a specific device as many devices under the same range may share + * the same devtype. The devtype may even be 0 in all cases. + * + * The only reason you may be interested in retrieving the devtype for a + * device is for the purpose of checking if some print data is compatible + * with a device. libfprint uses the devtype as one way of checking that the + * print you are verifying is compatible with the device in question - the + * devtypes must be equal. This effectively allows drivers to support more + * than one type of device where the data from each one is not compatible with + * the other. Note that libfprint does provide you with helper functions to + * determine whether a print is compatible with a device, so under most + * circumstances, you don't have to worry about devtypes at all. + */ + +/** @defgroup dscv_dev Device discovery + * These functions allow you to scan the system for supported fingerprint + * scanning hardware. This is your starting point when integrating libfprint + * into your software. + * + * When you've identified a discovered device that you would like to control, + * you can open it with fp_dev_open(). Note that discovered devices may no + * longer be available at the time when you want to open them, for example + * the user may have unplugged the device. + */ + +/** @defgroup drv Driver operations + * Internally, libfprint is abstracted into various drivers to communicate + * with the different types of supported fingerprint readers. libfprint works + * hard so that you don't have to care about these internal abstractions, + * however there are some situations where you may be interested in a little + * behind-the-scenes driver info. + * + * You can obtain the driver for a device using fp_dev_get_driver(), which + * you can pass to the functions documented on this page. + * + * \section driver_id Driver IDs + * Each driver is assigned a unique ID by the project maintainer. These + * assignments are + * + * documented on the wiki and will never change. + * + * The only reason you may be interested in retrieving the driver ID for a + * driver is for the purpose of checking if some print data is compatible + * with a device. libfprint uses the driver ID as one way of checking that + * the print you are trying to verify is compatible with the device in + * question - it ensures that enrollment data from one driver is never fed to + * another. Note that libfprint does provide you with helper functions to + * determine whether a print is compatible with a device, so under most + * circumstances, you don't have to worry about driver IDs at all. + */ + +static GSList *registered_drivers = NULL; + +void fpi_log(enum fpi_log_level level, const char *component, + const char *function, const char *format, ...) +{ + va_list args; + FILE *stream = stdout; + const char *prefix; + +#ifndef ENABLE_DEBUG_LOGGING + if (!log_level) + return; + if (level == LOG_LEVEL_WARNING && log_level < 2) + return; + if (level == LOG_LEVEL_INFO && log_level < 3) + return; +#endif + + switch (level) { + case LOG_LEVEL_INFO: + prefix = "info"; + break; + case LOG_LEVEL_WARNING: + stream = stderr; + prefix = "warning"; + break; + case LOG_LEVEL_ERROR: + stream = stderr; + prefix = "error"; + break; + case LOG_LEVEL_DEBUG: + stream = stderr; + prefix = "debug"; + break; + default: + stream = stderr; + prefix = "unknown"; + break; + } + + fprintf(stream, "%s:%s [%s] ", component ? component : "fp", prefix, + function); + + va_start (args, format); + vfprintf(stream, format, args); + va_end (args); + + fprintf(stream, "\n"); +} + +static void register_driver(struct fp_driver *drv) +{ + if (drv->id == 0) { + fp_err("not registering driver %s: driver ID is 0", drv->name); + return; + } + registered_drivers = g_slist_prepend(registered_drivers, (gpointer) drv); + fp_dbg("registered driver %s", drv->name); +} + +static struct fp_driver * const primitive_drivers[] = { +#ifdef ENABLE_UPEKTS + &upekts_driver, +#endif +}; + +static struct fp_img_driver * const img_drivers[] = { +#ifdef ENABLE_AES4000 + &aes4000_driver, +#endif +#ifdef ENABLE_AES2501 + &aes2501_driver, +#endif +#ifdef ENABLE_URU4000 + &uru4000_driver, +#endif +#ifdef ENABLE_VCOM5S + &vcom5s_driver, +#endif +#ifdef ENABLE_UPEKSONLY + &upeksonly_driver, +#endif + /* +#ifdef ENABLE_AES1610 + &aes1610_driver, +#endif +#ifdef ENABLE_UPEKTC + &upektc_driver, +#endif +#ifdef ENABLE_FDU2000 + &fdu2000_driver, +#endif + */ +}; + +static void register_drivers(void) +{ + unsigned int i; + + for (i = 0; i < G_N_ELEMENTS(primitive_drivers); i++) + register_driver(primitive_drivers[i]); + + for (i = 0; i < G_N_ELEMENTS(img_drivers); i++) { + struct fp_img_driver *imgdriver = img_drivers[i]; + fpi_img_driver_setup(imgdriver); + register_driver(&imgdriver->driver); + } +} + +API_EXPORTED struct fp_driver **fprint_get_drivers (void) +{ + GPtrArray *array; + unsigned int i; + + array = g_ptr_array_new (); + for (i = 0; i < G_N_ELEMENTS(primitive_drivers); i++) + g_ptr_array_add (array, primitive_drivers[i]); + + for (i = 0; i < G_N_ELEMENTS(img_drivers); i++) + g_ptr_array_add (array, &(img_drivers[i]->driver)); + + /* Add a null item terminating the array */ + g_ptr_array_add (array, NULL); + + return (struct fp_driver **) g_ptr_array_free (array, FALSE); +} + +static struct fp_driver *find_supporting_driver(libusb_device *udev, + const struct usb_id **usb_id) +{ + int ret; + GSList *elem = registered_drivers; + struct libusb_device_descriptor dsc; + + ret = libusb_get_device_descriptor(udev, &dsc); + if (ret < 0) { + fp_err("Failed to get device descriptor"); + return NULL; + } + + do { + struct fp_driver *drv = elem->data; + const struct usb_id *id; + + for (id = drv->id_table; id->vendor; id++) + if (dsc.idVendor == id->vendor && dsc.idProduct == id->product) { + fp_dbg("driver %s supports USB device %04x:%04x", + drv->name, id->vendor, id->product); + *usb_id = id; + return drv; + } + } while ((elem = g_slist_next(elem))); + return NULL; +} + +static struct fp_dscv_dev *discover_dev(libusb_device *udev) +{ + const struct usb_id *usb_id; + struct fp_driver *drv = find_supporting_driver(udev, &usb_id); + struct fp_dscv_dev *ddev; + uint32_t devtype = 0; + + if (!drv) + return NULL; + + if (drv->discover) { + int r = drv->discover(usb_id, &devtype); + if (r < 0) + fp_err("%s discover failed, code %d", drv->name, r); + if (r <= 0) + return NULL; + } + + ddev = g_malloc0(sizeof(*ddev)); + ddev->drv = drv; + ddev->udev = udev; + ddev->driver_data = usb_id->driver_data; + ddev->devtype = devtype; + return ddev; +} + +/** \ingroup dscv_dev + * Scans the system and returns a list of discovered devices. This is your + * entry point into finding a fingerprint reader to operate. + * \returns a NULL-terminated list of discovered devices. Must be freed with + * fp_dscv_devs_free() after use. + */ +API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void) +{ + GSList *tmplist = NULL; + struct fp_dscv_dev **list; + libusb_device *udev; + libusb_device **devs; + int dscv_count = 0; + int r; + int i = 0; + + if (registered_drivers == NULL) + return NULL; + + r = libusb_get_device_list(fpi_usb_ctx, &devs); + if (r < 0) { + fp_err("couldn't enumerate USB devices, error %d", r); + return NULL; + } + + /* Check each device against each driver, temporarily storing successfully + * discovered devices in a GSList. + * + * Quite inefficient but excusable as we'll only be dealing with small + * sets of drivers against small sets of USB devices */ + while ((udev = devs[i++]) != NULL) { + struct fp_dscv_dev *ddev = discover_dev(udev); + if (!ddev) + continue; + tmplist = g_slist_prepend(tmplist, (gpointer) ddev); + dscv_count++; + } + + /* Convert our temporary GSList into a standard NULL-terminated pointer + * array. */ + list = g_malloc(sizeof(*list) * (dscv_count + 1)); + if (dscv_count > 0) { + GSList *elem = tmplist; + i = 0; + do { + list[i++] = elem->data; + } while ((elem = g_slist_next(elem))); + } + list[dscv_count] = NULL; /* NULL-terminate */ + + g_slist_free(tmplist); + return list; +} + +/** \ingroup dscv_dev + * Free a list of discovered devices. This function destroys the list and all + * discovered devices that it included, so make sure you have opened your + * discovered device before freeing the list. + * \param devs the list of discovered devices. If NULL, function simply + * returns. + */ +API_EXPORTED void fp_dscv_devs_free(struct fp_dscv_dev **devs) +{ + int i; + if (!devs) + return; + + for (i = 0; devs[i]; i++) + g_free(devs[i]); + g_free(devs); +} + +/** \ingroup dscv_dev + * Gets the \ref drv "driver" for a discovered device. + * \param dev the discovered device + * \returns the driver backing the device + */ +API_EXPORTED struct fp_driver *fp_dscv_dev_get_driver(struct fp_dscv_dev *dev) +{ + return dev->drv; +} + +/** \ingroup dscv_dev + * Gets the \ref devtype "devtype" for a discovered device. + * \param dev the discovered device + * \returns the devtype of the device + */ +API_EXPORTED uint32_t fp_dscv_dev_get_devtype(struct fp_dscv_dev *dev) +{ + return dev->devtype; +} + +enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv) +{ + switch (drv->type) { + case DRIVER_PRIMITIVE: + return PRINT_DATA_RAW; + case DRIVER_IMAGING: + return PRINT_DATA_NBIS_MINUTIAE; + default: + fp_err("unrecognised drv type %d", drv->type); + return PRINT_DATA_RAW; + } +} + +/** \ingroup dscv_dev + * Determines if a specific \ref print_data "stored print" appears to be + * compatible with a discovered device. + * \param dev the discovered device + * \param data the print for compatibility checking + * \returns 1 if the print is compatible with the device, 0 otherwise + */ +API_EXPORTED int fp_dscv_dev_supports_print_data(struct fp_dscv_dev *dev, + struct fp_print_data *data) +{ + return fpi_print_data_compatible(dev->drv->id, dev->devtype, + fpi_driver_get_data_type(dev->drv), data->driver_id, data->devtype, + data->type); +} + +/** \ingroup dscv_dev + * Determines if a specific \ref dscv_print "discovered print" appears to be + * compatible with a discovered device. + * \param dev the discovered device + * \param data the discovered print for compatibility checking + * \returns 1 if the print is compatible with the device, 0 otherwise + */ +API_EXPORTED int fp_dscv_dev_supports_dscv_print(struct fp_dscv_dev *dev, + struct fp_dscv_print *data) +{ + return fpi_print_data_compatible(dev->drv->id, dev->devtype, 0, + data->driver_id, data->devtype, 0); +} + +/** \ingroup dscv_dev + * Searches a list of discovered devices for a device that appears to be + * compatible with a \ref print_data "stored print". + * \param devs a list of discovered devices + * \param data the print under inspection + * \returns the first discovered device that appears to support the print, or + * NULL if no apparently compatible devices could be found + */ +API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_print_data(struct fp_dscv_dev **devs, + struct fp_print_data *data) +{ + struct fp_dscv_dev *ddev; + int i; + + for (i = 0; (ddev = devs[i]); i++) + if (fp_dscv_dev_supports_print_data(ddev, data)) + return ddev; + return NULL; +} + +/** \ingroup dscv_dev + * Searches a list of discovered devices for a device that appears to be + * compatible with a \ref dscv_print "discovered print". + * \param devs a list of discovered devices + * \param print the print under inspection + * \returns the first discovered device that appears to support the print, or + * NULL if no apparently compatible devices could be found + */ +API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_dscv_print(struct fp_dscv_dev **devs, + struct fp_dscv_print *print) +{ + struct fp_dscv_dev *ddev; + int i; + + for (i = 0; (ddev = devs[i]); i++) + if (fp_dscv_dev_supports_dscv_print(ddev, print)) + return ddev; + return NULL; +} + +/** \ingroup dev + * Get the \ref drv "driver" for a fingerprint device. + * \param dev the device + * \returns the driver controlling the device + */ +API_EXPORTED struct fp_driver *fp_dev_get_driver(struct fp_dev *dev) +{ + return dev->drv; +} + +/** \ingroup dev + * Gets the number of \ref enrolling "enroll stages" required to enroll a + * fingerprint with the device. + * \param dev the device + * \returns the number of enroll stages + */ +API_EXPORTED int fp_dev_get_nr_enroll_stages(struct fp_dev *dev) +{ + return dev->nr_enroll_stages; +} + +/** \ingroup dev + * Gets the \ref devtype "devtype" for a device. + * \param dev the device + * \returns the devtype + */ +API_EXPORTED uint32_t fp_dev_get_devtype(struct fp_dev *dev) +{ + return dev->devtype; +} + +/** \ingroup dev + * Determines if a stored print is compatible with a certain device. + * \param dev the device + * \param data the stored print + * \returns 1 if the print is compatible with the device, 0 if not + */ +API_EXPORTED int fp_dev_supports_print_data(struct fp_dev *dev, + struct fp_print_data *data) +{ + return fpi_print_data_compatible(dev->drv->id, dev->devtype, + fpi_driver_get_data_type(dev->drv), data->driver_id, data->devtype, + data->type); +} + +/** \ingroup dev + * Determines if a \ref dscv_print "discovered print" appears to be compatible + * with a certain device. + * \param dev the device + * \param data the discovered print + * \returns 1 if the print is compatible with the device, 0 if not + */ +API_EXPORTED int fp_dev_supports_dscv_print(struct fp_dev *dev, + struct fp_dscv_print *data) +{ + return fpi_print_data_compatible(dev->drv->id, dev->devtype, + 0, data->driver_id, data->devtype, 0); +} + +/** \ingroup drv + * Retrieves the name of the driver. For example: "upekts" + * \param drv the driver + * \returns the driver name. Must not be modified or freed. + */ +API_EXPORTED const char *fp_driver_get_name(struct fp_driver *drv) +{ + return drv->name; +} + +/** \ingroup drv + * Retrieves a descriptive name of the driver. For example: "UPEK TouchStrip" + * \param drv the driver + * \returns the descriptive name. Must not be modified or freed. + */ +API_EXPORTED const char *fp_driver_get_full_name(struct fp_driver *drv) +{ + return drv->full_name; +} + +/** \ingroup drv + * Retrieves the driver ID code for a driver. + * \param drv the driver + * \returns the driver ID + */ +API_EXPORTED uint16_t fp_driver_get_driver_id(struct fp_driver *drv) +{ + return drv->id; +} + +/** \ingroup drv + * Retrieves the scan type for the devices associated with the driver. + * \param drv the driver + * \returns the scan type + */ +API_EXPORTED enum fp_scan_type fp_driver_get_scan_type(struct fp_driver *drv) +{ + return drv->scan_type; +} + +static struct fp_img_dev *dev_to_img_dev(struct fp_dev *dev) +{ + if (dev->drv->type != DRIVER_IMAGING) + return NULL; + return dev->priv; +} + +/** \ingroup dev + * Determines if a device has imaging capabilities. If a device has imaging + * capabilities you are able to perform imaging operations such as retrieving + * scan images using fp_dev_img_capture(). However, not all devices are + * imaging devices - some do all processing in hardware. This function will + * indicate which class a device in question falls into. + * \param dev the fingerprint device + * \returns 1 if the device is an imaging device, 0 if the device does not + * provide images to the host computer + */ +API_EXPORTED int fp_dev_supports_imaging(struct fp_dev *dev) +{ + return dev->drv->type == DRIVER_IMAGING; +} + +/** \ingroup dev + * Determines if a device is capable of \ref identification "identification" + * through fp_identify_finger() and similar. Not all devices support this + * functionality. + * \param dev the fingerprint device + * \returns 1 if the device is capable of identification, 0 otherwise. + */ +API_EXPORTED int fp_dev_supports_identification(struct fp_dev *dev) +{ + return dev->drv->identify_start != NULL; +} + +/** \ingroup dev + * Captures an \ref img "image" from a device. The returned image is the raw + * image provided by the device, you may wish to \ref img_std "standardize" it. + * + * If set, the unconditional flag indicates that the device should + * capture an image unconditionally, regardless of whether a finger is there + * or not. If unset, this function will block until a finger is detected on + * the sensor. + * + * \param dev the device + * \param unconditional whether to unconditionally capture an image, or to only capture when a finger is detected + * \param image a location to return the captured image. Must be freed with + * fp_img_free() after use. + * \return 0 on success, non-zero on error. -ENOTSUP indicates that either the + * unconditional flag was set but the device does not support this, or that the + * device does not support imaging. + * \sa fp_dev_supports_imaging() + */ +API_EXPORTED int fp_dev_img_capture(struct fp_dev *dev, int unconditional, + struct fp_img **image) +{ + struct fp_img_dev *imgdev = dev_to_img_dev(dev); + if (!imgdev) { + fp_dbg("image capture on non-imaging device"); + return -ENOTSUP; + } + + //return fpi_imgdev_capture(imgdev, unconditional, image); + /* FIXME reimplement async */ + return -ENOTSUP; +} + +/** \ingroup dev + * Gets the expected width of images that will be captured from the device. + * This function will return -1 for devices that are not + * \ref imaging "imaging devices". If the width of images from this device + * can vary, 0 will be returned. + * \param dev the device + * \returns the expected image width, or 0 for variable, or -1 for non-imaging + * devices. + */ +API_EXPORTED int fp_dev_get_img_width(struct fp_dev *dev) +{ + struct fp_img_dev *imgdev = dev_to_img_dev(dev); + if (!imgdev) { + fp_dbg("get image width for non-imaging device"); + return -1; + } + + return fpi_imgdev_get_img_width(imgdev); +} + +/** \ingroup dev + * Gets the expected height of images that will be captured from the device. + * This function will return -1 for devices that are not + * \ref imaging "imaging devices". If the height of images from this device + * can vary, 0 will be returned. + * \param dev the device + * \returns the expected image height, or 0 for variable, or -1 for non-imaging + * devices. + */ +API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev) +{ + struct fp_img_dev *imgdev = dev_to_img_dev(dev); + if (!imgdev) { + fp_dbg("get image height for non-imaging device"); + return -1; + } + + return fpi_imgdev_get_img_height(imgdev); +} + +/** \ingroup core + * Set message verbosity. + * - Level 0: no messages ever printed by the library (default) + * - Level 1: error messages are printed to stderr + * - Level 2: warning and error messages are printed to stderr + * - Level 3: informational messages are printed to stdout, warning and error + * messages are printed to stderr + * + * The default level is 0, which means no messages are ever printed. If you + * choose to increase the message verbosity level, ensure that your + * application does not close the stdout/stderr file descriptors. + * + * You are advised to set level 3. libfprint is conservative with its message + * logging and most of the time, will only log messages that explain error + * conditions and other oddities. This will help you debug your software. + * + * If the LIBFPRINT_DEBUG environment variable was set when libfprint was + * initialized, this function does nothing: the message verbosity is fixed + * to the value in the environment variable. + * + * If libfprint was compiled without any message logging, this function does + * nothing: you'll never get any messages. + * + * If libfprint was compiled with verbose debug message logging, this function + * does nothing: you'll always get messages from all levels. + * + * \param ctx the context to operate on, or NULL for the default context + * \param level debug level to set + */ +API_EXPORTED void fp_set_debug(int level) +{ + if (log_level_fixed) + return; + + log_level = level; + libusb_set_debug(fpi_usb_ctx, level); +} + +/** \ingroup core + * Initialise libfprint. This function must be called before you attempt to + * use the library in any way. + * \return 0 on success, non-zero on error. + */ +API_EXPORTED int fp_init(void) +{ + char *dbg = getenv("LIBFPRINT_DEBUG"); + int r; + fp_dbg(""); + + r = libusb_init(&fpi_usb_ctx); + if (r < 0) + return r; + + if (dbg) { + log_level = atoi(dbg); + if (log_level) { + log_level_fixed = 1; + libusb_set_debug(fpi_usb_ctx, log_level); + } + } + + register_drivers(); + fpi_poll_init(); + return 0; +} + +/** \ingroup core + * Deinitialise libfprint. This function should be called during your program + * exit sequence. You must not use any libfprint functions after calling this + * function, unless you call fp_init() again. + */ +API_EXPORTED void fp_exit(void) +{ + fp_dbg(""); + + if (opened_devices) { + GSList *copy = g_slist_copy(opened_devices); + GSList *elem = copy; + fp_dbg("naughty app left devices open on exit!"); + + do + fp_dev_close((struct fp_dev *) elem->data); + while ((elem = g_slist_next(elem))); + + g_slist_free(copy); + g_slist_free(opened_devices); + opened_devices = NULL; + } + + fpi_data_exit(); + fpi_poll_exit(); + g_slist_free(registered_drivers); + registered_drivers = NULL; + libusb_exit(fpi_usb_ctx); +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/sync.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/sync.c.svn-base @@ -0,0 +1,516 @@ +/* + * Synchronous I/O functionality + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "sync" + +#include +#include + +#include "fp_internal.h" + +struct sync_open_data { + struct fp_dev *dev; + int status; +}; + +static void sync_open_cb(struct fp_dev *dev, int status, void *user_data) +{ + struct sync_open_data *odata = user_data; + fp_dbg("status %d", status); + odata->dev = dev; + odata->status = status; +} + +/** \ingroup dev + * Opens and initialises a device. This is the function you call in order + * to convert a \ref dscv_dev "discovered device" into an actual device handle + * that you can perform operations with. + * \param ddev the discovered device to open + * \returns the opened device handle, or NULL on error + */ +API_EXPORTED struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev) +{ + struct fp_dev *dev = NULL; + struct sync_open_data *odata = g_malloc0(sizeof(*odata)); + int r; + + fp_dbg(""); + r = fp_async_dev_open(ddev, sync_open_cb, odata); + if (r) + goto out; + + while (!odata->dev) + if (fp_handle_events() < 0) + goto out; + + if (odata->status == 0) + dev = odata->dev; + else + fp_dev_close(odata->dev); + +out: + g_free(odata); + return dev; +} + +static void sync_close_cb(struct fp_dev *dev, void *user_data) +{ + fp_dbg(""); + gboolean *closed = user_data; + *closed = TRUE; +} + +/** \ingroup dev + * Close a device. You must call this function when you are finished using + * a fingerprint device. + * \param dev the device to close. If NULL, function simply returns. + */ +API_EXPORTED void fp_dev_close(struct fp_dev *dev) +{ + gboolean closed = FALSE; + + if (!dev) + return; + + fp_dbg(""); + fp_async_dev_close(dev, sync_close_cb, &closed); + while (!closed) + if (fp_handle_events() < 0) + break; +} + +struct sync_enroll_data { + gboolean populated; + int result; + struct fp_print_data *data; + struct fp_img *img; +}; + +static void sync_enroll_cb(struct fp_dev *dev, int result, + struct fp_print_data *data, struct fp_img *img, void *user_data) +{ + struct sync_enroll_data *edata = user_data; + fp_dbg("result %d", result); + edata->result = result; + edata->data = data; + edata->img = img; + edata->populated = TRUE; +} + +static void enroll_stop_cb(struct fp_dev *dev, void *user_data) +{ + gboolean *stopped = user_data; + fp_dbg(""); + *stopped = TRUE; +} + +/** \ingroup dev + * Performs an enroll stage. See \ref enrolling for an explanation of enroll + * stages. + * + * If no enrollment is in process, this kicks of the process and runs the + * first stage. If an enrollment is already in progress, calling this + * function runs the next stage, which may well be the last. + * + * A negative error code may be returned from any stage. When this occurs, + * further calls to the enroll function will start a new enrollment process, + * i.e. a negative error code indicates that the enrollment process has been + * aborted. These error codes only ever indicate unexpected internal errors + * or I/O problems. + * + * The RETRY codes from #fp_enroll_result may be returned from any enroll + * stage. These codes indicate that the scan was not succesful in that the + * user did not position their finger correctly or similar. When a RETRY code + * is returned, the enrollment stage is not advanced, so the next call + * into this function will retry the current stage again. The current stage may + * need to be retried several times. + * + * The fp_enroll_result#FP_ENROLL_FAIL code may be returned from any enroll + * stage. This code indicates that even though the scans themselves have been + * acceptable, data processing applied to these scans produces incomprehensible + * results. In other words, the user may have been scanning a different finger + * for each stage or something like that. Like negative error codes, this + * return code indicates that the enrollment process has been aborted. + * + * The fp_enroll_result#FP_ENROLL_PASS code will only ever be returned for + * non-final stages. This return code indicates that the scan was acceptable + * and the next call into this function will advance onto the next enroll + * stage. + * + * The fp_enroll_result#FP_ENROLL_COMPLETE code will only ever be returned + * from the final enroll stage. It indicates that enrollment completed + * successfully, and that print_data has been assigned to point to the + * resultant enrollment data. The print_data parameter will not be modified + * during any other enrollment stages, hence it is actually legal to pass NULL + * as this argument for all but the final stage. + * + * If the device is an imaging device, it can also return the image from + * the scan, even when the enroll fails with a RETRY or FAIL code. It is legal + * to call this function even on non-imaging devices, just don't expect them to + * provide images. + * + * \param dev the device + * \param print_data a location to return the resultant enrollment data from + * the final stage. Must be freed with fp_print_data_free() after use. + * \param img location to store the scan image. accepts NULL for no image + * storage. If an image is returned, it must be freed with fp_img_free() after + * use. + * \return negative code on error, otherwise a code from #fp_enroll_result + */ +API_EXPORTED int fp_enroll_finger_img(struct fp_dev *dev, + struct fp_print_data **print_data, struct fp_img **img) +{ + struct fp_driver *drv = dev->drv; + int stage = dev->__enroll_stage; + gboolean final = FALSE; + gboolean stopped = FALSE; + struct sync_enroll_data *edata = NULL; + int r; + fp_dbg(""); + + /* FIXME __enroll_stage is ugly, can we replace it by some function that + * says whether we're enrolling or not, and then put __enroll_stage into + * edata? */ + + if (stage == -1) { + edata = g_malloc0(sizeof(struct sync_enroll_data)); + r = fp_async_enroll_start(dev, sync_enroll_cb, edata); + if (r < 0) { + g_free(edata); + return r; + } + + dev->__enroll_stage = ++stage; + } else if (stage >= dev->nr_enroll_stages) { + fp_err("exceeding number of enroll stages for device claimed by " + "driver %s (%d stages)", drv->name, dev->nr_enroll_stages); + dev->__enroll_stage = -1; + r = -EINVAL; + final = TRUE; + goto out; + } + fp_dbg("%s will handle enroll stage %d/%d", drv->name, stage, + dev->nr_enroll_stages - 1); + + /* FIXME this isn't very clean */ + edata = dev->enroll_stage_cb_data; + + while (!edata->populated) { + r = fp_handle_events(); + if (r < 0) { + g_free(edata); + goto err; + } + } + + edata->populated = FALSE; + + if (img) + *img = edata->img; + else + fp_img_free(edata->img); + + r = edata->result; + switch (r) { + case FP_ENROLL_PASS: + fp_dbg("enroll stage passed"); + dev->__enroll_stage = stage + 1; + break; + case FP_ENROLL_COMPLETE: + fp_dbg("enroll complete"); + dev->__enroll_stage = -1; + *print_data = edata->data; + final = TRUE; + break; + case FP_ENROLL_RETRY: + fp_dbg("enroll should retry"); + break; + case FP_ENROLL_RETRY_TOO_SHORT: + fp_dbg("swipe was too short, enroll should retry"); + break; + case FP_ENROLL_RETRY_CENTER_FINGER: + fp_dbg("finger was not centered, enroll should retry"); + break; + case FP_ENROLL_RETRY_REMOVE_FINGER: + fp_dbg("scan failed, remove finger and retry"); + break; + case FP_ENROLL_FAIL: + fp_err("enroll failed"); + dev->__enroll_stage = -1; + final = TRUE; + break; + default: + fp_err("unrecognised return code %d", r); + dev->__enroll_stage = -1; + r = -EINVAL; + final = TRUE; + break; + } + + if (!final) + return r; + +out: + if (final) { + fp_dbg("ending enrollment"); + g_free(edata); + } + +err: + if (fp_async_enroll_stop(dev, enroll_stop_cb, &stopped) == 0) + while (!stopped) + if (fp_handle_events() < 0) + break; + return r; +} + +struct sync_verify_data { + gboolean populated; + int result; + struct fp_img *img; +}; + +static void sync_verify_cb(struct fp_dev *dev, int result, struct fp_img *img, + void *user_data) +{ + struct sync_verify_data *vdata = user_data; + vdata->result = result; + vdata->img = img; + vdata->populated = TRUE; +} + +static void verify_stop_cb(struct fp_dev *dev, void *user_data) +{ + gboolean *stopped = user_data; + fp_dbg(""); + *stopped = TRUE; +} + +/** \ingroup dev + * Performs a new scan and verify it against a previously enrolled print. + * If the device is an imaging device, it can also return the image from + * the scan, even when the verify fails with a RETRY code. It is legal to + * call this function even on non-imaging devices, just don't expect them to + * provide images. + * + * \param dev the device to perform the scan. + * \param enrolled_print the print to verify against. Must have been previously + * enrolled with a device compatible to the device selected to perform the scan. + * \param img location to store the scan image. accepts NULL for no image + * storage. If an image is returned, it must be freed with fp_img_free() after + * use. + * \return negative code on error, otherwise a code from #fp_verify_result + */ +API_EXPORTED int fp_verify_finger_img(struct fp_dev *dev, + struct fp_print_data *enrolled_print, struct fp_img **img) +{ + struct fp_driver *drv = dev->drv; + struct sync_verify_data *vdata; + gboolean stopped = FALSE; + int r; + + if (!enrolled_print) { + fp_err("no print given"); + return -EINVAL; + } + + if (!fp_dev_supports_print_data(dev, enrolled_print)) { + fp_err("print is not compatible with device"); + return -EINVAL; + } + + fp_dbg("to be handled by %s", drv->name); + vdata = g_malloc0(sizeof(struct sync_verify_data)); + r = fp_async_verify_start(dev, enrolled_print, sync_verify_cb, vdata); + if (r < 0) { + fp_dbg("verify_start error %d", r); + g_free(vdata); + return r; + } + + while (!vdata->populated) { + r = fp_handle_events(); + if (r < 0) { + g_free(vdata); + goto err; + } + } + + if (img) + *img = vdata->img; + else + fp_img_free(vdata->img); + + r = vdata->result; + g_free(vdata); + switch (r) { + case FP_VERIFY_NO_MATCH: + fp_dbg("result: no match"); + break; + case FP_VERIFY_MATCH: + fp_dbg("result: match"); + break; + case FP_VERIFY_RETRY: + fp_dbg("verify should retry"); + break; + case FP_VERIFY_RETRY_TOO_SHORT: + fp_dbg("swipe was too short, verify should retry"); + break; + case FP_VERIFY_RETRY_CENTER_FINGER: + fp_dbg("finger was not centered, verify should retry"); + break; + case FP_VERIFY_RETRY_REMOVE_FINGER: + fp_dbg("scan failed, remove finger and retry"); + break; + default: + fp_err("unrecognised return code %d", r); + r = -EINVAL; + } + +err: + fp_dbg("ending verification"); + if (fp_async_verify_stop(dev, verify_stop_cb, &stopped) == 0) + while (!stopped) + if (fp_handle_events() < 0) + break; + + return r; +} + +struct sync_identify_data { + gboolean populated; + int result; + size_t match_offset; + struct fp_img *img; +}; + +static void sync_identify_cb(struct fp_dev *dev, int result, + size_t match_offset, struct fp_img *img, void *user_data) +{ + struct sync_identify_data *idata = user_data; + idata->result = result; + idata->match_offset = match_offset; + idata->img = img; + idata->populated = TRUE; +} + +static void identify_stop_cb(struct fp_dev *dev, void *user_data) +{ + gboolean *stopped = user_data; + fp_dbg(""); + *stopped = TRUE; +} + +/** \ingroup dev + * Performs a new scan and attempts to identify the scanned finger against + * a collection of previously enrolled fingerprints. + * If the device is an imaging device, it can also return the image from + * the scan, even when identification fails with a RETRY code. It is legal to + * call this function even on non-imaging devices, just don't expect them to + * provide images. + * + * This function returns codes from #fp_verify_result. The return code + * fp_verify_result#FP_VERIFY_MATCH indicates that the scanned fingerprint + * does appear in the print gallery, and the match_offset output parameter + * will indicate the index into the print gallery array of the matched print. + * + * This function will not necessarily examine the whole print gallery, it + * will return as soon as it finds a matching print. + * + * Not all devices support identification. -ENOTSUP will be returned when + * this is the case. + * + * \param dev the device to perform the scan. + * \param print_gallery NULL-terminated array of pointers to the prints to + * identify against. Each one must have been previously enrolled with a device + * compatible to the device selected to perform the scan. + * \param match_offset output location to store the array index of the matched + * gallery print (if any was found). Only valid if FP_VERIFY_MATCH was + * returned. + * \param img location to store the scan image. accepts NULL for no image + * storage. If an image is returned, it must be freed with fp_img_free() after + * use. + * \return negative code on error, otherwise a code from #fp_verify_result + */ +API_EXPORTED int fp_identify_finger_img(struct fp_dev *dev, + struct fp_print_data **print_gallery, size_t *match_offset, + struct fp_img **img) +{ + struct fp_driver *drv = dev->drv; + gboolean stopped = FALSE; + struct sync_identify_data *idata + = g_malloc0(sizeof(struct sync_identify_data)); + int r; + + fp_dbg("to be handled by %s", drv->name); + + r = fp_async_identify_start(dev, print_gallery, sync_identify_cb, idata); + if (r < 0) { + fp_err("identify_start error %d", r); + goto err; + } + + while (!idata->populated) { + r = fp_handle_events(); + if (r < 0) + goto err_stop; + } + + if (img) + *img = idata->img; + else + fp_img_free(idata->img); + + r = idata->result; + switch (idata->result) { + case FP_VERIFY_NO_MATCH: + fp_dbg("result: no match"); + break; + case FP_VERIFY_MATCH: + fp_dbg("result: match at offset %zd", idata->match_offset); + *match_offset = idata->match_offset; + break; + case FP_VERIFY_RETRY: + fp_dbg("verify should retry"); + break; + case FP_VERIFY_RETRY_TOO_SHORT: + fp_dbg("swipe was too short, verify should retry"); + break; + case FP_VERIFY_RETRY_CENTER_FINGER: + fp_dbg("finger was not centered, verify should retry"); + break; + case FP_VERIFY_RETRY_REMOVE_FINGER: + fp_dbg("scan failed, remove finger and retry"); + break; + default: + fp_err("unrecognised return code %d", r); + r = -EINVAL; + } + +err_stop: + if (fp_async_identify_stop(dev, identify_stop_cb, &stopped) == 0) + while (!stopped) + if (fp_handle_events() < 0) + break; + +err: + g_free(idata); + return r; +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/async.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/async.c.svn-base @@ -0,0 +1,414 @@ +/* + * Asynchronous I/O functionality + * Copyright (C) 2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "async" + +#include +#include +#include + +#include "fp_internal.h" + +/* Drivers call this when device initialisation has completed */ +void fpi_drvcb_open_complete(struct fp_dev *dev, int status) +{ + fp_dbg("status %d", status); + BUG_ON(dev->state != DEV_STATE_INITIALIZING); + dev->state = (status) ? DEV_STATE_ERROR : DEV_STATE_INITIALIZED; + opened_devices = g_slist_prepend(opened_devices, dev); + if (dev->open_cb) + dev->open_cb(dev, status, dev->open_cb_data); +} + +API_EXPORTED int fp_async_dev_open(struct fp_dscv_dev *ddev, fp_dev_open_cb cb, + void *user_data) +{ + struct fp_driver *drv = ddev->drv; + struct fp_dev *dev; + libusb_device_handle *udevh; + int r; + + fp_dbg(""); + r = libusb_open(ddev->udev, &udevh); + if (r < 0) { + fp_err("usb_open failed, error %d", r); + return r; + } + + dev = g_malloc0(sizeof(*dev)); + dev->drv = drv; + dev->udev = udevh; + dev->__enroll_stage = -1; + dev->state = DEV_STATE_INITIALIZING; + dev->open_cb = cb; + dev->open_cb_data = user_data; + + if (!drv->open) { + fpi_drvcb_open_complete(dev, 0); + return 0; + } + + dev->state = DEV_STATE_INITIALIZING; + r = drv->open(dev, ddev->driver_data); + if (r) { + fp_err("device initialisation failed, driver=%s", drv->name); + libusb_close(udevh); + g_free(dev); + } + + return r; +} + +/* Drivers call this when device deinitialisation has completed */ +void fpi_drvcb_close_complete(struct fp_dev *dev) +{ + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_DEINITIALIZING); + dev->state = DEV_STATE_DEINITIALIZED; + libusb_close(dev->udev); + if (dev->close_cb) + dev->close_cb(dev, dev->close_cb_data); + g_free(dev); +} + +API_EXPORTED void fp_async_dev_close(struct fp_dev *dev, + fp_dev_close_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + + if (g_slist_index(opened_devices, (gconstpointer) dev) == -1) + fp_err("device %p not in opened list!", dev); + opened_devices = g_slist_remove(opened_devices, (gconstpointer) dev); + + dev->close_cb = callback; + dev->close_cb_data = user_data; + + if (!drv->close) { + fpi_drvcb_close_complete(dev); + return; + } + + dev->state = DEV_STATE_DEINITIALIZING; + drv->close(dev); +} + +/* Drivers call this when enrollment has started */ +void fpi_drvcb_enroll_started(struct fp_dev *dev, int status) +{ + fp_dbg("status %d", status); + BUG_ON(dev->state != DEV_STATE_ENROLL_STARTING); + if (status) { + if (status > 0) { + status = -status; + fp_dbg("adjusted to %d", status); + } + dev->state = DEV_STATE_ERROR; + if (dev->enroll_stage_cb) + dev->enroll_stage_cb(dev, status, NULL, NULL, + dev->enroll_stage_cb_data); + } else { + dev->state = DEV_STATE_ENROLLING; + } +} + +API_EXPORTED int fp_async_enroll_start(struct fp_dev *dev, + fp_enroll_stage_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + int r; + + if (!dev->nr_enroll_stages || !drv->enroll_start) { + fp_err("driver %s has 0 enroll stages or no enroll func", + drv->name); + return -ENOTSUP; + } + + fp_dbg("starting enrollment"); + dev->enroll_stage_cb = callback; + dev->enroll_stage_cb_data = user_data; + + dev->state = DEV_STATE_ENROLL_STARTING; + r = drv->enroll_start(dev); + if (r < 0) { + dev->enroll_stage_cb = NULL; + fp_err("failed to start enrollment"); + dev->state = DEV_STATE_ERROR; + } + + return r; +} + +/* Drivers call this when an enroll stage has completed */ +void fpi_drvcb_enroll_stage_completed(struct fp_dev *dev, int result, + struct fp_print_data *data, struct fp_img *img) +{ + BUG_ON(dev->state != DEV_STATE_ENROLLING); + fp_dbg("result %d", result); + if (!dev->enroll_stage_cb) { + fp_dbg("ignoring enroll result as no callback is subscribed"); + return; + } + if (result == FP_ENROLL_COMPLETE && !data) { + fp_err("BUG: complete but no data?"); + result = FP_ENROLL_FAIL; + } + dev->enroll_stage_cb(dev, result, data, img, dev->enroll_stage_cb_data); +} + +/* Drivers call this when enrollment has stopped */ +void fpi_drvcb_enroll_stopped(struct fp_dev *dev) +{ + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_ENROLL_STOPPING); + dev->state = DEV_STATE_INITIALIZED; + if (dev->enroll_stop_cb) + dev->enroll_stop_cb(dev, dev->enroll_stop_cb_data); +} + +API_EXPORTED int fp_async_enroll_stop(struct fp_dev *dev, + fp_enroll_stop_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + int r; + + fp_dbg(""); + if (!drv->enroll_start) + return -ENOTSUP; + + dev->enroll_stage_cb = NULL; + dev->enroll_stop_cb = callback; + dev->enroll_stop_cb_data = user_data; + dev->state = DEV_STATE_ENROLL_STOPPING; + + if (!drv->enroll_stop) { + fpi_drvcb_enroll_stopped(dev); + return 0; + } + + r = drv->enroll_stop(dev); + if (r < 0) { + fp_err("failed to stop enrollment"); + dev->enroll_stop_cb = NULL; + } + + return r; +} + +API_EXPORTED int fp_async_verify_start(struct fp_dev *dev, + struct fp_print_data *data, fp_verify_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + int r; + + fp_dbg(""); + if (!drv->verify_start) + return -ENOTSUP; + + dev->state = DEV_STATE_VERIFY_STARTING; + dev->verify_cb = callback; + dev->verify_cb_data = user_data; + dev->verify_data = data; + + r = drv->verify_start(dev); + if (r < 0) { + dev->verify_cb = NULL; + dev->state = DEV_STATE_ERROR; + fp_err("failed to start verification, error %d", r); + } + return r; +} + +/* Drivers call this when verification has started */ +void fpi_drvcb_verify_started(struct fp_dev *dev, int status) +{ + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_VERIFY_STARTING); + if (status) { + if (status > 0) { + status = -status; + fp_dbg("adjusted to %d", status); + } + dev->state = DEV_STATE_ERROR; + if (dev->verify_cb) + dev->verify_cb(dev, status, NULL, dev->verify_cb_data); + } else { + dev->state = DEV_STATE_VERIFYING; + } +} + +/* Drivers call this to report a verify result (which might mark completion) */ +void fpi_drvcb_report_verify_result(struct fp_dev *dev, int result, + struct fp_img *img) +{ + fp_dbg("result %d", result); + BUG_ON(dev->state != DEV_STATE_VERIFYING); + if (result < 0 || result == FP_VERIFY_NO_MATCH + || result == FP_VERIFY_MATCH) + dev->state = DEV_STATE_VERIFY_DONE; + + if (dev->verify_cb) + dev->verify_cb(dev, result, img, dev->verify_cb_data); + else + fp_dbg("ignoring verify result as no callback is subscribed"); +} + +/* Drivers call this when verification has stopped */ +void fpi_drvcb_verify_stopped(struct fp_dev *dev) +{ + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_VERIFY_STOPPING); + dev->state = DEV_STATE_INITIALIZED; + if (dev->verify_stop_cb) + dev->verify_stop_cb(dev, dev->verify_stop_cb_data); +} + +API_EXPORTED int fp_async_verify_stop(struct fp_dev *dev, + fp_verify_stop_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + gboolean iterating = (dev->state == DEV_STATE_VERIFYING); + int r; + + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_ERROR + && dev->state != DEV_STATE_VERIFYING + && dev->state != DEV_STATE_VERIFY_DONE); + + dev->verify_cb = NULL; + dev->verify_stop_cb = callback; + dev->verify_stop_cb_data = user_data; + dev->state = DEV_STATE_VERIFY_STOPPING; + + if (!drv->verify_start) + return -ENOTSUP; + if (!drv->verify_stop) { + dev->state = DEV_STATE_INITIALIZED; + fpi_drvcb_verify_stopped(dev); + return 0; + } + + r = drv->verify_stop(dev, iterating); + if (r < 0) { + fp_err("failed to stop verification"); + dev->verify_stop_cb = NULL; + } + return r; +} + +API_EXPORTED int fp_async_identify_start(struct fp_dev *dev, + struct fp_print_data **gallery, fp_identify_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + int r; + + fp_dbg(""); + if (!drv->identify_start) + return -ENOTSUP; + dev->state = DEV_STATE_IDENTIFY_STARTING; + dev->identify_cb = callback; + dev->identify_cb_data = user_data; + dev->identify_gallery = gallery; + + r = drv->identify_start(dev); + if (r < 0) { + fp_err("identify_start failed with error %d", r); + dev->identify_cb = NULL; + dev->state = DEV_STATE_ERROR; + } + return r; +} + +/* Driver-lib: identification has started, expect results soon */ +void fpi_drvcb_identify_started(struct fp_dev *dev, int status) +{ + fp_dbg("status %d", status); + BUG_ON(dev->state != DEV_STATE_IDENTIFY_STARTING); + if (status) { + if (status > 0) { + status = -status; + fp_dbg("adjusted to %d", status); + } + dev->state = DEV_STATE_ERROR; + if (dev->identify_cb) + dev->identify_cb(dev, status, 0, NULL, dev->identify_cb_data); + } else { + dev->state = DEV_STATE_IDENTIFYING; + } +} + +/* Drivers report an identify result (which might mark completion) */ +void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, + size_t match_offset, struct fp_img *img) +{ + fp_dbg("result %d", result); + BUG_ON(dev->state != DEV_STATE_IDENTIFYING + && dev->state != DEV_STATE_ERROR); + if (result < 0 || result == FP_VERIFY_NO_MATCH + || result == FP_VERIFY_MATCH) + dev->state = DEV_STATE_IDENTIFY_DONE; + + if (dev->identify_cb) + dev->identify_cb(dev, result, match_offset, img, dev->identify_cb_data); + else + fp_dbg("ignoring verify result as no callback is subscribed"); +} + +API_EXPORTED int fp_async_identify_stop(struct fp_dev *dev, + fp_identify_stop_cb callback, void *user_data) +{ + struct fp_driver *drv = dev->drv; + gboolean iterating = (dev->state == DEV_STATE_IDENTIFYING); + int r; + + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_IDENTIFYING + && dev->state != DEV_STATE_IDENTIFY_DONE); + + dev->state = DEV_STATE_IDENTIFY_STOPPING; + dev->identify_cb = NULL; + dev->identify_stop_cb = callback; + dev->identify_stop_cb_data = user_data; + + if (!drv->identify_start) + return -ENOTSUP; + if (!drv->identify_stop) { + dev->state = DEV_STATE_INITIALIZED; + fpi_drvcb_identify_stopped(dev); + return 0; + } + + r = drv->identify_stop(dev, iterating); + if (r < 0) { + fp_err("failed to stop identification"); + dev->identify_stop_cb = NULL; + } + + return r; +} + +/* Drivers call this when identification has stopped */ +void fpi_drvcb_identify_stopped(struct fp_dev *dev) +{ + fp_dbg(""); + BUG_ON(dev->state != DEV_STATE_IDENTIFY_STOPPING); + dev->state = DEV_STATE_INITIALIZED; + if (dev->identify_stop_cb) + dev->identify_stop_cb(dev, dev->identify_stop_cb_data); +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/fp_internal.h.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/fp_internal.h.svn-base @@ -0,0 +1,430 @@ +/* + * Internal/private definitions for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + */ + +#ifndef __FPRINT_INTERNAL_H__ +#define __FPRINT_INTERNAL_H__ + +#include +#include + +#include +#include + +#include + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +enum fpi_log_level { + LOG_LEVEL_DEBUG, + LOG_LEVEL_INFO, + LOG_LEVEL_WARNING, + LOG_LEVEL_ERROR, +}; + +void fpi_log(enum fpi_log_level, const char *component, const char *function, + const char *format, ...); + +#ifndef FP_COMPONENT +#define FP_COMPONENT NULL +#endif + +#ifdef ENABLE_LOGGING +#define _fpi_log(level, fmt...) fpi_log(level, FP_COMPONENT, __FUNCTION__, fmt) +#else +#define _fpi_log(level, fmt...) +#endif + +#ifdef ENABLE_DEBUG_LOGGING +#define fp_dbg(fmt...) _fpi_log(LOG_LEVEL_DEBUG, fmt) +#else +#define fp_dbg(fmt...) +#endif + +#define fp_info(fmt...) _fpi_log(LOG_LEVEL_INFO, fmt) +#define fp_warn(fmt...) _fpi_log(LOG_LEVEL_WARNING, fmt) +#define fp_err(fmt...) _fpi_log(LOG_LEVEL_ERROR, fmt) + +#ifndef NDEBUG +#define BUG_ON(condition) \ + if ((condition)) fp_err("BUG at %s:%d", __FILE__, __LINE__) +#else +#define BUG_ON(condition) +#endif + +#define BUG() BUG_ON(1) + +enum fp_dev_state { + DEV_STATE_INITIAL = 0, + DEV_STATE_ERROR, + DEV_STATE_INITIALIZING, + DEV_STATE_INITIALIZED, + DEV_STATE_DEINITIALIZING, + DEV_STATE_DEINITIALIZED, + DEV_STATE_ENROLL_STARTING, + DEV_STATE_ENROLLING, + DEV_STATE_ENROLL_STOPPING, + DEV_STATE_VERIFY_STARTING, + DEV_STATE_VERIFYING, + DEV_STATE_VERIFY_DONE, + DEV_STATE_VERIFY_STOPPING, + DEV_STATE_IDENTIFY_STARTING, + DEV_STATE_IDENTIFYING, + DEV_STATE_IDENTIFY_DONE, + DEV_STATE_IDENTIFY_STOPPING, +}; + +struct fp_driver **fprint_get_drivers (void); + +struct fp_dev { + struct fp_driver *drv; + libusb_device_handle *udev; + uint32_t devtype; + void *priv; + + int nr_enroll_stages; + + /* read-only to drivers */ + struct fp_print_data *verify_data; + + /* drivers should not mess with any of the below */ + enum fp_dev_state state; + + int __enroll_stage; + + /* async I/O callbacks and data */ + /* FIXME: convert this to generic state operational data mechanism? */ + fp_dev_open_cb open_cb; + void *open_cb_data; + fp_dev_close_cb close_cb; + void *close_cb_data; + fp_enroll_stage_cb enroll_stage_cb; + void *enroll_stage_cb_data; + fp_enroll_stop_cb enroll_stop_cb; + void *enroll_stop_cb_data; + fp_verify_cb verify_cb; + void *verify_cb_data; + fp_verify_stop_cb verify_stop_cb; + void *verify_stop_cb_data; + fp_identify_cb identify_cb; + void *identify_cb_data; + fp_identify_stop_cb identify_stop_cb; + void *identify_stop_cb_data; + + /* FIXME: better place to put this? */ + struct fp_print_data **identify_gallery; +}; + +enum fp_imgdev_state { + IMGDEV_STATE_INACTIVE, + IMGDEV_STATE_AWAIT_FINGER_ON, + IMGDEV_STATE_CAPTURE, + IMGDEV_STATE_AWAIT_FINGER_OFF, +}; + +enum fp_imgdev_action { + IMG_ACTION_NONE = 0, + IMG_ACTION_ENROLL, + IMG_ACTION_VERIFY, + IMG_ACTION_IDENTIFY, +}; + +enum fp_imgdev_enroll_state { + IMG_ACQUIRE_STATE_NONE = 0, + IMG_ACQUIRE_STATE_ACTIVATING, + IMG_ACQUIRE_STATE_AWAIT_FINGER_ON, + IMG_ACQUIRE_STATE_AWAIT_IMAGE, + IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF, + IMG_ACQUIRE_STATE_DONE, + IMG_ACQUIRE_STATE_DEACTIVATING, +}; + +enum fp_imgdev_verify_state { + IMG_VERIFY_STATE_NONE = 0, + IMG_VERIFY_STATE_ACTIVATING +}; + +struct fp_img_dev { + struct fp_dev *dev; + libusb_device_handle *udev; + enum fp_imgdev_action action; + int action_state; + + struct fp_print_data *acquire_data; + struct fp_img *acquire_img; + int action_result; + + /* FIXME: better place to put this? */ + size_t identify_match_offset; + + void *priv; +}; + +int fpi_imgdev_capture(struct fp_img_dev *imgdev, int unconditional, + struct fp_img **image); +int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev); +int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev); + +struct usb_id { + uint16_t vendor; + uint16_t product; + unsigned long driver_data; +}; + +enum fp_driver_type { + DRIVER_PRIMITIVE = 0, + DRIVER_IMAGING = 1, +}; + +struct fp_driver { + const uint16_t id; + const char *name; + const char *full_name; + const struct usb_id * const id_table; + enum fp_driver_type type; + enum fp_scan_type scan_type; + + void *priv; + + /* Device operations */ + int (*discover)(const struct usb_id *usb_id, uint32_t *devtype); + int (*open)(struct fp_dev *dev, unsigned long driver_data); + void (*close)(struct fp_dev *dev); + int (*enroll_start)(struct fp_dev *dev); + int (*enroll_stop)(struct fp_dev *dev); + int (*verify_start)(struct fp_dev *dev); + int (*verify_stop)(struct fp_dev *dev, gboolean iterating); + int (*identify_start)(struct fp_dev *dev); + int (*identify_stop)(struct fp_dev *dev, gboolean iterating); +}; + +enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv); + +/* flags for fp_img_driver.flags */ +#define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0) + +struct fp_img_driver { + struct fp_driver driver; + uint16_t flags; + int img_width; + int img_height; + int bz3_threshold; + + /* Device operations */ + int (*open)(struct fp_img_dev *dev, unsigned long driver_data); + void (*close)(struct fp_img_dev *dev); + int (*activate)(struct fp_img_dev *dev, enum fp_imgdev_state state); + int (*change_state)(struct fp_img_dev *dev, enum fp_imgdev_state state); + void (*deactivate)(struct fp_img_dev *dev); +}; + +#ifdef ENABLE_UPEKTS +extern struct fp_driver upekts_driver; +#endif +#ifdef ENABLE_UPEKTC +extern struct fp_img_driver upektc_driver; +#endif +#ifdef ENABLE_UPEKSONLY +extern struct fp_img_driver upeksonly_driver; +#endif +#ifdef ENABLE_URU4000 +extern struct fp_img_driver uru4000_driver; +#endif +#ifdef ENABLE_AES1610 +extern struct fp_img_driver aes1610_driver; +#endif +#ifdef ENABLE_AES2501 +extern struct fp_img_driver aes2501_driver; +#endif +#ifdef ENABLE_AES4000 +extern struct fp_img_driver aes4000_driver; +#endif +#ifdef ENABLE_FDU2000 +extern struct fp_img_driver fdu2000_driver; +#endif +#ifdef ENABLE_VCOM5S +extern struct fp_img_driver vcom5s_driver; +#endif + +extern libusb_context *fpi_usb_ctx; +extern GSList *opened_devices; + +void fpi_img_driver_setup(struct fp_img_driver *idriver); + +#define fpi_driver_to_img_driver(drv) \ + container_of((drv), struct fp_img_driver, driver) + +struct fp_dscv_dev { + struct libusb_device *udev; + struct fp_driver *drv; + unsigned long driver_data; + uint32_t devtype; +}; + +struct fp_dscv_print { + uint16_t driver_id; + uint32_t devtype; + enum fp_finger finger; + char *path; +}; + +enum fp_print_data_type { + PRINT_DATA_RAW = 0, /* memset-imposed default */ + PRINT_DATA_NBIS_MINUTIAE, +}; + +struct fp_print_data { + uint16_t driver_id; + uint32_t devtype; + enum fp_print_data_type type; + size_t length; + unsigned char data[0]; +}; + +struct fpi_print_data_fp1 { + char prefix[3]; + uint16_t driver_id; + uint32_t devtype; + unsigned char data_type; + unsigned char data[0]; +} __attribute__((__packed__)); + +void fpi_data_exit(void); +struct fp_print_data *fpi_print_data_new(struct fp_dev *dev, size_t length); +gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1, + enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2, + enum fp_print_data_type type2); + +struct fp_minutiae { + int alloc; + int num; + struct fp_minutia **list; +}; + +/* bit values for fp_img.flags */ +#define FP_IMG_V_FLIPPED (1<<0) +#define FP_IMG_H_FLIPPED (1<<1) +#define FP_IMG_COLORS_INVERTED (1<<2) +#define FP_IMG_BINARIZED_FORM (1<<3) + +#define FP_IMG_STANDARDIZATION_FLAGS (FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED \ + | FP_IMG_COLORS_INVERTED) + +struct fp_img { + int width; + int height; + size_t length; + uint16_t flags; + struct fp_minutiae *minutiae; + unsigned char *binarized; + unsigned char data[0]; +}; + +struct fp_img *fpi_img_new(size_t length); +struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); +struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); +gboolean fpi_img_is_sane(struct fp_img *img); +int fpi_img_detect_minutiae(struct fp_img *img); +int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img, + struct fp_print_data **ret); +int fpi_img_compare_print_data(struct fp_print_data *enrolled_print, + struct fp_print_data *new_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_img *fpi_im_resize(struct fp_img *img, unsigned int factor); + +/* polling and timeouts */ + +void fpi_poll_init(void); +void fpi_poll_exit(void); + +typedef void (*fpi_timeout_fn)(void *data); + +struct fpi_timeout; +struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, + void *data); +void fpi_timeout_cancel(struct fpi_timeout *timeout); + +/* async drv <--> lib comms */ + +struct fpi_ssm; +typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm); +typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm); + +/* sequential state machine: state machine that iterates sequentially over + * a predefined series of states. can be aborted by either completion or + * abortion error conditions. */ +struct fpi_ssm { + struct fp_dev *dev; + struct fpi_ssm *parentsm; + void *priv; + int nr_states; + int cur_state; + gboolean completed; + int error; + ssm_completed_fn callback; + ssm_handler_fn handler; +}; + + +/* for library and drivers */ +struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, + int nr_states); +void fpi_ssm_free(struct fpi_ssm *machine); +void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback); +void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child); +int fpi_ssm_has_completed(struct fpi_ssm *machine); + +/* for drivers */ +void fpi_ssm_next_state(struct fpi_ssm *machine); +void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state); +void fpi_ssm_mark_completed(struct fpi_ssm *machine); +void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error); + +void fpi_drvcb_open_complete(struct fp_dev *dev, int status); +void fpi_drvcb_close_complete(struct fp_dev *dev); + +void fpi_drvcb_enroll_started(struct fp_dev *dev, int status); +void fpi_drvcb_enroll_stage_completed(struct fp_dev *dev, int result, + struct fp_print_data *data, struct fp_img *img); +void fpi_drvcb_enroll_stopped(struct fp_dev *dev); + +void fpi_drvcb_verify_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_verify_result(struct fp_dev *dev, int result, + struct fp_img *img); +void fpi_drvcb_verify_stopped(struct fp_dev *dev); + +void fpi_drvcb_identify_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, + size_t match_offset, struct fp_img *img); +void fpi_drvcb_identify_stopped(struct fp_dev *dev); + +/* for image drivers */ +void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status); +void fpi_imgdev_close_complete(struct fp_img_dev *imgdev); +void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status); +void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev); +void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, + gboolean present); +void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img); +void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error); + +#endif + --- libfprint-20081125git.orig/libfprint/.svn/text-base/aeslib.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/aeslib.c.svn-base @@ -0,0 +1,173 @@ +/* + * Shared functions between libfprint Authentec drivers + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "aeslib" + +#include + +#include +#include + +#include "fp_internal.h" +#include "aeslib.h" + +#define MAX_REGWRITES_PER_REQUEST 16 + +#define BULK_TIMEOUT 4000 +#define EP_IN (1 | LIBUSB_ENDPOINT_IN) +#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) + +struct write_regv_data { + struct fp_img_dev *imgdev; + unsigned int num_regs; + const struct aes_regwrite *regs; + unsigned int offset; + aes_write_regv_cb callback; + void *user_data; +}; + +static void continue_write_regv(struct write_regv_data *wdata); + +/* libusb bulk callback for regv write completion transfer. continues the + * transaction */ +static void write_regv_trf_complete(struct libusb_transfer *transfer) +{ + struct write_regv_data *wdata = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + wdata->callback(wdata->imgdev, -EIO, wdata->user_data); + else if (transfer->length != transfer->actual_length) + wdata->callback(wdata->imgdev, -EPROTO, wdata->user_data); + else + continue_write_regv(wdata); + + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +/* write from wdata->offset to upper_bound (inclusive) of wdata->regs */ +static int do_write_regv(struct write_regv_data *wdata, int upper_bound) +{ + unsigned int offset = wdata->offset; + unsigned int num = upper_bound - offset + 1; + size_t alloc_size = num * 2; + unsigned char *data = g_malloc(alloc_size); + unsigned int i; + size_t data_offset = 0; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + int r; + + if (!transfer) { + g_free(data); + return -ENOMEM; + } + + for (i = offset; i < offset + num; i++) { + const struct aes_regwrite *regwrite = &wdata->regs[i]; + data[data_offset++] = regwrite->reg; + data[data_offset++] = regwrite->value; + } + + libusb_fill_bulk_transfer(transfer, wdata->imgdev->udev, EP_OUT, data, + alloc_size, write_regv_trf_complete, wdata, BULK_TIMEOUT); + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + } + + return r; +} + +/* write the next batch of registers to be written, or if there are no more, + * indicate completion to the caller */ +static void continue_write_regv(struct write_regv_data *wdata) +{ + unsigned int offset = wdata->offset; + unsigned int regs_remaining; + unsigned int limit; + unsigned int upper_bound; + int i; + int r; + + /* skip all zeros and ensure there is still work to do */ + while (TRUE) { + if (offset >= wdata->num_regs) { + fp_dbg("all registers written"); + wdata->callback(wdata->imgdev, 0, wdata->user_data); + return; + } + if (wdata->regs[offset].reg) + break; + offset++; + } + + wdata->offset = offset; + regs_remaining = wdata->num_regs - offset; + limit = MIN(regs_remaining, MAX_REGWRITES_PER_REQUEST); + upper_bound = offset + limit - 1; + + /* determine if we can write the entire of the regs at once, or if there + * is a zero dividing things up */ + for (i = offset; i <= upper_bound; i++) + if (!wdata->regs[i].reg) { + upper_bound = i - 1; + break; + } + + r = do_write_regv(wdata, upper_bound); + if (r < 0) { + wdata->callback(wdata->imgdev, r, wdata->user_data); + return; + } + + wdata->offset = upper_bound + 1; +} + +/* write a load of registers to the device, combining multiple writes in a + * single URB up to a limit. insert writes to non-existent register 0 to force + * specific groups of writes to be separated by different URBs. */ +void aes_write_regv(struct fp_img_dev *dev, const struct aes_regwrite *regs, + unsigned int num_regs, aes_write_regv_cb callback, void *user_data) +{ + struct write_regv_data *wdata = g_malloc(sizeof(*wdata)); + fp_dbg("write %d regs", num_regs); + wdata->imgdev = dev; + wdata->num_regs = num_regs; + wdata->regs = regs; + wdata->offset = 0; + wdata->callback = callback; + wdata->user_data = user_data; + continue_write_regv(wdata); +} + +void aes_assemble_image(unsigned char *input, size_t width, size_t height, + unsigned char *output) +{ + 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++; + } + } +} + --- libfprint-20081125git.orig/libfprint/.svn/text-base/fprint-list-hal-info.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/fprint-list-hal-info.c.svn-base @@ -0,0 +1,81 @@ +/* + * Helper binary for creating a HAL FDI file for supported devices + * Copyright (C) 2008 Bastien Nocera + * Copyright (C) 2008 Timo Hoenig , + * + * 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 +#include + +#include "fp_internal.h" + +/* FDI entry example: + * + * + * + * + * biometric.fingerprint_reader + * libfprint + * biometric + * biometric.fingerprint_reader + * aes2501 + * true + * + * + * + */ + +static void print_driver (struct fp_driver *driver) +{ + int i; + + for (i = 0; driver->id_table[i].vendor != 0; i++) { + printf (" \n", fp_driver_get_full_name (driver)); + printf (" \n", driver->id_table[i].vendor); + printf (" \n", driver->id_table[i].product); + printf (" biometric.fingerprint_reader\n"); + printf (" libfprint\n"); + printf (" biometric\n"); + printf (" biometric.fingerprint_reader\n"); + printf (" %s\n", driver->name); + printf (" true\n"); + printf (" %s\n", + fp_driver_get_scan_type (driver) == FP_SCAN_TYPE_PRESS ? "press" : "swipe"); + printf (" \n"); + printf (" \n"); + } +} + +int main (int argc, char **argv) +{ + struct fp_driver **list; + guint i; + + list = fprint_get_drivers (); + + printf ("\n"); + printf ("\n", VERSION); + printf ("\n"); + + for (i = 0; list[i] != NULL; i++) { + print_driver (list[i]); + } + + printf ("\n"); + + return 0; +} --- libfprint-20081125git.orig/libfprint/.svn/text-base/aeslib.h.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/aeslib.h.svn-base @@ -0,0 +1,40 @@ +/* + * Shared functions between libfprint Authentec drivers + * Copyright (C) 2007 Daniel Drake + * + * 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 + */ + +#ifndef __AESLIB_H__ +#define __AESLIB_H__ + +#include + +struct aes_regwrite { + unsigned char reg; + unsigned char value; +}; + +typedef void (*aes_write_regv_cb)(struct fp_img_dev *dev, int result, + void *user_data); + +void aes_write_regv(struct fp_img_dev *dev, const struct aes_regwrite *regs, + unsigned int num_regs, aes_write_regv_cb callback, void *user_data); + +void aes_assemble_image(unsigned char *input, size_t width, size_t height, + unsigned char *output); + +#endif + --- libfprint-20081125git.orig/libfprint/.svn/text-base/data.c.svn-base +++ libfprint-20081125git/libfprint/.svn/text-base/data.c.svn-base @@ -0,0 +1,685 @@ +/* + * Fingerprint data handling and storage + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "fp_internal.h" + +#define DIR_PERMS 0700 + +/** @defgroup print_data Stored prints + * Stored prints are represented by a structure named fp_print_data. + * Stored prints are originally obtained from an enrollment function such as + * fp_enroll_finger(). + * + * This page documents the various operations you can do with a stored print. + * Note that by default, "stored prints" are not actually stored anywhere + * except in RAM. For the simple scenarios, libfprint provides a simple API + * for you to save and load the stored prints referring to a single user in + * their home directory. For more advanced users, libfprint provides APIs for + * you to convert print data to a byte string, and to reconstruct stored prints + * from such data at a later point. You are welcome to store these byte strings + * in any fashion that suits you. + */ + +static char *base_store = NULL; + +static void storage_setup(void) +{ + const char *homedir; + + homedir = g_getenv("HOME"); + if (!homedir) + homedir = g_get_home_dir(); + if (!homedir) + return; + + base_store = g_build_filename(homedir, ".fprint/prints", NULL); + g_mkdir_with_parents(base_store, DIR_PERMS); + /* FIXME handle failure */ +} + +void fpi_data_exit(void) +{ + g_free(base_store); +} + +#define FP_FINGER_IS_VALID(finger) \ + ((finger) >= LEFT_THUMB && (finger) <= RIGHT_LITTLE) + +/* for debug messages only */ +#ifdef ENABLE_DEBUG_LOGGING +static const char *finger_num_to_str(enum fp_finger finger) +{ + const char *names[] = { + [LEFT_THUMB] = "left thumb", + [LEFT_INDEX] = "left index", + [LEFT_MIDDLE] = "left middle", + [LEFT_RING] = "left ring", + [LEFT_LITTLE] = "left little", + [RIGHT_THUMB] = "right thumb", + [RIGHT_INDEX] = "right index", + [RIGHT_MIDDLE] = "right middle", + [RIGHT_RING] = "right ring", + [RIGHT_LITTLE] = "right little", + }; + if (!FP_FINGER_IS_VALID(finger)) + return "UNKNOWN"; + return names[finger]; +} +#endif + +static struct fp_print_data *print_data_new(uint16_t driver_id, + uint32_t devtype, enum fp_print_data_type type, size_t length) +{ + struct fp_print_data *data = g_malloc(sizeof(*data) + length); + fp_dbg("length=%zd driver=%02x devtype=%04x", length, driver_id, devtype); + memset(data, 0, sizeof(*data)); + data->driver_id = driver_id; + data->devtype = devtype; + data->type = type; + data->length = length; + return data; +} + +struct fp_print_data *fpi_print_data_new(struct fp_dev *dev, size_t length) +{ + return print_data_new(dev->drv->id, dev->devtype, + fpi_driver_get_data_type(dev->drv), length); +} + +/** \ingroup print_data + * Convert a stored print into a unified representation inside a data buffer. + * You can then store this data buffer in any way that suits you, and load + * it back at some later time using fp_print_data_from_data(). + * \param data the stored print + * \param ret output location for the data buffer. Must be freed with free() + * after use. + * \returns the size of the freshly allocated buffer, or 0 on error. + */ +API_EXPORTED size_t fp_print_data_get_data(struct fp_print_data *data, + unsigned char **ret) +{ + struct fpi_print_data_fp1 *buf; + size_t buflen; + + fp_dbg(""); + + buflen = sizeof(*buf) + data->length; + buf = malloc(buflen); + if (!buf) + return 0; + + *ret = (unsigned char *) buf; + buf->prefix[0] = 'F'; + buf->prefix[1] = 'P'; + buf->prefix[2] = '1'; + buf->driver_id = GUINT16_TO_LE(data->driver_id); + buf->devtype = GUINT32_TO_LE(data->devtype); + buf->data_type = data->type; + memcpy(buf->data, data->data, data->length); + return buflen; +} + +/** \ingroup print_data + * Load a stored print from a data buffer. The contents of said buffer must + * be the untouched contents of a buffer previously supplied to you by the + * fp_print_data_get_data() function. + * \param buf the data buffer + * \param buflen the length of the buffer + * \returns the stored print represented by the data, or NULL on error. Must + * be freed with fp_print_data_free() after use. + */ +API_EXPORTED struct fp_print_data *fp_print_data_from_data(unsigned char *buf, + size_t buflen) +{ + struct fpi_print_data_fp1 *raw = (struct fpi_print_data_fp1 *) buf; + size_t print_data_len; + struct fp_print_data *data; + + fp_dbg("buffer size %zd", buflen); + if (buflen < sizeof(*raw)) + return NULL; + + if (strncmp(raw->prefix, "FP1", 3) != 0) { + fp_dbg("bad header prefix"); + return NULL; + } + + print_data_len = buflen - sizeof(*raw); + data = print_data_new(GUINT16_FROM_LE(raw->driver_id), + GUINT32_FROM_LE(raw->devtype), raw->data_type, print_data_len); + memcpy(data->data, raw->data, print_data_len); + return data; +} + +static char *get_path_to_storedir(uint16_t driver_id, uint32_t devtype) +{ + char idstr[5]; + char devtypestr[9]; + + g_snprintf(idstr, sizeof(idstr), "%04x", driver_id); + g_snprintf(devtypestr, sizeof(devtypestr), "%08x", devtype); + + return g_build_filename(base_store, idstr, devtypestr, NULL); +} + +static char *__get_path_to_print(uint16_t driver_id, uint32_t devtype, + enum fp_finger finger) +{ + char *dirpath; + char *path; + char fingername[2]; + + g_snprintf(fingername, 2, "%x", finger); + + dirpath = get_path_to_storedir(driver_id, devtype); + path = g_build_filename(dirpath, fingername, NULL); + g_free(dirpath); + return path; +} + +static char *get_path_to_print(struct fp_dev *dev, enum fp_finger finger) +{ + return __get_path_to_print(dev->drv->id, dev->devtype, finger); +} + +/** \ingroup print_data + * Saves a stored print to disk, assigned to a specific finger. Even though + * you are limited to storing only the 10 human fingers, this is a + * per-device-type limit. For example, you can store the users right index + * finger from a DigitalPersona scanner, and you can also save the right index + * finger from a UPEK scanner. When you later come to load the print, the right + * one will be automatically selected. + * + * This function will unconditionally overwrite a fingerprint previously + * saved for the same finger and device type. The print is saved in a hidden + * directory beneath the current user's home directory. + * \param data the stored print to save to disk + * \param finger the finger that this print corresponds to + * \returns 0 on success, non-zero on error. + */ +API_EXPORTED int fp_print_data_save(struct fp_print_data *data, + enum fp_finger finger) +{ + GError *err = NULL; + char *path; + char *dirpath; + unsigned char *buf; + size_t len; + int r; + + if (!base_store) + storage_setup(); + + fp_dbg("save %s print from driver %04x", finger_num_to_str(finger), + data->driver_id); + len = fp_print_data_get_data(data, &buf); + if (!len) + return -ENOMEM; + + path = __get_path_to_print(data->driver_id, data->devtype, finger); + dirpath = g_path_get_dirname(path); + r = g_mkdir_with_parents(dirpath, DIR_PERMS); + if (r < 0) { + fp_err("couldn't create storage directory"); + g_free(path); + g_free(dirpath); + return r; + } + + fp_dbg("saving to %s", path); + g_file_set_contents(path, buf, len, &err); + free(buf); + g_free(dirpath); + g_free(path); + if (err) { + r = err->code; + fp_err("save failed: %s", err->message); + g_error_free(err); + /* FIXME interpret error codes */ + return r; + } + + return 0; +} + +gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1, + enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2, + enum fp_print_data_type type2) +{ + if (driver_id1 != driver_id2) { + fp_dbg("driver ID mismatch: %02x vs %02x", driver_id1, driver_id2); + return FALSE; + } + + if (devtype1 != devtype2) { + fp_dbg("devtype mismatch: %04x vs %04x", devtype1, devtype2); + return FALSE; + } + + if (type1 != type2) { + fp_dbg("type mismatch: %d vs %d", type1, type2); + return FALSE; + } + + return TRUE; +} + +static int load_from_file(char *path, struct fp_print_data **data) +{ + gsize length; + gchar *contents; + GError *err = NULL; + struct fp_print_data *fdata; + + fp_dbg("from %s", path); + g_file_get_contents(path, &contents, &length, &err); + if (err) { + int r = err->code; + fp_err("%s load failed: %s", path, err->message); + g_error_free(err); + /* FIXME interpret more error codes */ + if (r == G_FILE_ERROR_NOENT) + return -ENOENT; + else + return r; + } + + fdata = fp_print_data_from_data(contents, length); + g_free(contents); + if (!fdata) + return -EIO; + *data = fdata; + return 0; +} + +/** \ingroup print_data + * Loads a previously stored print from disk. The print must have been saved + * earlier using the fp_print_data_save() function. + * + * A return code of -ENOENT indicates that the fingerprint requested could not + * be found. Other error codes (both positive and negative) are possible for + * obscure error conditions (e.g. corruption). + * + * \param dev the device you are loading the print for + * \param finger the finger of the file you are loading + * \param data output location to put the corresponding stored print. Must be + * freed with fp_print_data_free() after use. + * \returns 0 on success, non-zero on error + */ +API_EXPORTED int fp_print_data_load(struct fp_dev *dev, + enum fp_finger finger, struct fp_print_data **data) +{ + gchar *path; + struct fp_print_data *fdata; + int r; + + if (!base_store) + storage_setup(); + + path = get_path_to_print(dev, finger); + r = load_from_file(path, &fdata); + g_free(path); + if (r) + return r; + + if (!fp_dev_supports_print_data(dev, fdata)) { + fp_err("print data is not compatible!"); + fp_print_data_free(fdata); + return -EINVAL; + } + + *data = fdata; + return 0; +} + +/** \ingroup print_data + * Removes a stored print from disk previously saved with fp_print_data_save(). + * \param dev the device that the print belongs to + * \param finger the finger of the file you are deleting + * \returns 0 on success, negative on error + */ +API_EXPORTED int fp_print_data_delete(struct fp_dev *dev, + enum fp_finger finger) +{ + int r; + gchar *path = get_path_to_print(dev, finger); + + fp_dbg("remove finger %d at %s", finger, path); + r = g_unlink(path); + g_free(path); + if (r < 0) + fp_dbg("unlink failed with error %d", r); + + /* FIXME: cleanup empty directory */ + return r; +} + +/** \ingroup print_data + * Attempts to load a stored print based on a \ref dscv_print + * "discovered print" record. + * + * A return code of -ENOENT indicates that the file referred to by the + * discovered print could not be found. Other error codes (both positive and + * negative) are possible for obscure error conditions (e.g. corruption). + * + * \param print the discovered print + * \param data output location to point to the corresponding stored print. Must + * be freed with fp_print_data_free() after use. + * \returns 0 on success, non-zero on error. + */ +API_EXPORTED int fp_print_data_from_dscv_print(struct fp_dscv_print *print, + struct fp_print_data **data) +{ + return load_from_file(print->path, data); +} + +/** \ingroup print_data + * Frees a stored print. Must be called when you are finished using the print. + * \param data the stored print to destroy. If NULL, function simply returns. + */ +API_EXPORTED void fp_print_data_free(struct fp_print_data *data) +{ + g_free(data); +} + +/** \ingroup print_data + * Gets the \ref driver_id "driver ID" for a stored print. The driver ID + * indicates which driver the print originally came from. The print is + * only usable with a device controlled by that driver. + * \param data the stored print + * \returns the driver ID of the driver compatible with the print + */ +API_EXPORTED uint16_t fp_print_data_get_driver_id(struct fp_print_data *data) +{ + return data->driver_id; +} + +/** \ingroup print_data + * Gets the \ref devtype "devtype" for a stored print. The devtype represents + * which type of device under the parent driver is compatible with the print. + * \param data the stored print + * \returns the devtype of the device range compatible with the print + */ +API_EXPORTED uint32_t fp_print_data_get_devtype(struct fp_print_data *data) +{ + return data->devtype; +} + +/** @defgroup dscv_print Print discovery + * The \ref print_data "stored print" documentation detailed a simple API + * for storing per-device prints for a single user, namely + * fp_print_data_save(). It also detailed a load function, + * fp_print_data_load(), but usage of this function is limited to scenarios + * where you know which device you would like to use, and you know which + * finger you are looking to verify. + * + * In other cases, it would be more useful to be able to enumerate all + * previously saved prints, potentially even before device discovery. These + * functions are designed to offer this functionality to you. + * + * Discovered prints are stored in a dscv_print structure, and you + * can use functions documented below to access some information about these + * prints. You can determine if a discovered print appears to be compatible + * with a device using functions such as fp_dscv_dev_supports_dscv_print() and + * fp_dev_supports_dscv_print(). + * + * When you are ready to use the print, you can load it into memory in the form + * of a stored print by using the fp_print_data_from_dscv_print() function. + * + * You may have noticed the use of the word "appears" in the above paragraphs. + * libfprint performs print discovery simply by examining the file and + * directory structure of libfprint's private data store. It does not examine + * the actual prints themselves. Just because a print has been discovered + * and appears to be compatible with a certain device does not necessarily mean + * that it is usable; when you come to load or use it, under unusual + * circumstances it may turn out that the print is corrupt or not for the + * device that it appeared to be. Also, it is possible that the print may have + * been deleted by the time you come to load it. + */ + +static GSList *scan_dev_store_dir(char *devpath, uint16_t driver_id, + uint32_t devtype, GSList *list) +{ + GError *err = NULL; + const gchar *ent; + struct fp_dscv_print *print; + + GDir *dir = g_dir_open(devpath, 0, &err); + if (!dir) { + fp_err("opendir %s failed: %s", devpath, err->message); + g_error_free(err); + return list; + } + + while ((ent = g_dir_read_name(dir))) { + /* ent is an 1 hex character fp_finger code */ + guint64 val; + enum fp_finger finger; + gchar *endptr; + + if (*ent == 0 || strlen(ent) != 1) + continue; + + val = g_ascii_strtoull(ent, &endptr, 16); + if (endptr == ent || !FP_FINGER_IS_VALID(val)) { + fp_dbg("skipping print file %s", ent); + continue; + } + + finger = (enum fp_finger) val; + print = g_malloc(sizeof(*print)); + print->driver_id = driver_id; + print->devtype = devtype; + print->path = g_build_filename(devpath, ent, NULL); + print->finger = finger; + list = g_slist_prepend(list, print); + } + + g_dir_close(dir); + return list; +} + +static GSList *scan_driver_store_dir(char *drvpath, uint16_t driver_id, + GSList *list) +{ + GError *err = NULL; + const gchar *ent; + + GDir *dir = g_dir_open(drvpath, 0, &err); + if (!dir) { + fp_err("opendir %s failed: %s", drvpath, err->message); + g_error_free(err); + return list; + } + + while ((ent = g_dir_read_name(dir))) { + /* ent is an 8 hex character devtype */ + guint64 val; + uint32_t devtype; + gchar *endptr; + gchar *path; + + if (*ent == 0 || strlen(ent) != 8) + continue; + + val = g_ascii_strtoull(ent, &endptr, 16); + if (endptr == ent) { + fp_dbg("skipping devtype %s", ent); + continue; + } + + devtype = (uint32_t) val; + path = g_build_filename(drvpath, ent, NULL); + list = scan_dev_store_dir(path, driver_id, devtype, list); + g_free(path); + } + + g_dir_close(dir); + return list; +} + +/** \ingroup dscv_print + * Scans the users home directory and returns a list of prints that were + * previously saved using fp_print_data_save(). + * \returns a NULL-terminated list of discovered prints, must be freed with + * fp_dscv_prints_free() after use. + */ +API_EXPORTED struct fp_dscv_print **fp_discover_prints(void) +{ + GDir *dir; + const gchar *ent; + GError *err = NULL; + GSList *tmplist = NULL; + GSList *elem; + unsigned int tmplist_len; + struct fp_dscv_print **list; + unsigned int i; + + if (!base_store) + storage_setup(); + + dir = g_dir_open(base_store, 0, &err); + if (!dir) { + fp_err("opendir %s failed: %s", base_store, err->message); + g_error_free(err); + return NULL; + } + + while ((ent = g_dir_read_name(dir))) { + /* ent is a 4 hex digit driver_id */ + gchar *endptr; + gchar *path; + guint64 val; + uint16_t driver_id; + + if (*ent == 0 || strlen(ent) != 4) + continue; + + val = g_ascii_strtoull(ent, &endptr, 16); + if (endptr == ent) { + fp_dbg("skipping drv id %s", ent); + continue; + } + + driver_id = (uint16_t) val; + path = g_build_filename(base_store, ent, NULL); + tmplist = scan_driver_store_dir(path, driver_id, tmplist); + g_free(path); + } + + g_dir_close(dir); + tmplist_len = g_slist_length(tmplist); + list = g_malloc(sizeof(*list) * (tmplist_len + 1)); + elem = tmplist; + for (i = 0; i < tmplist_len; i++, elem = g_slist_next(elem)) + list[i] = elem->data; + list[tmplist_len] = NULL; /* NULL-terminate */ + + g_slist_free(tmplist); + return list; +} + +/** \ingroup dscv_print + * Frees a list of discovered prints. This function also frees the discovered + * prints themselves, so make sure you do not use any discovered prints + * after calling this function. + * \param prints the list of discovered prints. If NULL, function simply + * returns. + */ +API_EXPORTED void fp_dscv_prints_free(struct fp_dscv_print **prints) +{ + int i; + struct fp_dscv_print *print; + + if (!prints) + return; + + for (i = 0; (print = prints[i]); i++) { + if (print) + g_free(print->path); + g_free(print); + } + g_free(prints); +} + +/** \ingroup dscv_print + * Gets the \ref driver_id "driver ID" for a discovered print. The driver ID + * indicates which driver the print originally came from. The print is only + * usable with a device controlled by that driver. + * \param print the discovered print + * \returns the driver ID of the driver compatible with the print + */ +API_EXPORTED uint16_t fp_dscv_print_get_driver_id(struct fp_dscv_print *print) +{ + return print->driver_id; +} + +/** \ingroup dscv_print + * Gets the \ref devtype "devtype" for a discovered print. The devtype + * represents which type of device under the parent driver is compatible + * with the print. + * \param print the discovered print + * \returns the devtype of the device range compatible with the print + */ +API_EXPORTED uint32_t fp_dscv_print_get_devtype(struct fp_dscv_print *print) +{ + return print->devtype; +} + +/** \ingroup dscv_print + * Gets the finger code for a discovered print. + * \param print discovered print + * \returns a finger code from #fp_finger + */ +API_EXPORTED enum fp_finger fp_dscv_print_get_finger(struct fp_dscv_print *print) +{ + return print->finger; +} + +/** \ingroup dscv_print + * Removes a discovered print from disk. After successful return of this + * function, functions such as fp_dscv_print_get_finger() will continue to + * operate as before, however calling fp_print_data_from_dscv_print() will + * fail for obvious reasons. + * \param print the discovered print to remove from disk + * \returns 0 on success, negative on error + */ +API_EXPORTED int fp_dscv_print_delete(struct fp_dscv_print *print) +{ + int r; + fp_dbg("remove at %s", print->path); + r = g_unlink(print->path); + if (r < 0) + fp_dbg("unlink failed with error %d", r); + + /* FIXME: cleanup empty directory */ + return r; +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/entries +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/entries @@ -0,0 +1,776 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/libfprint/nbis/mindtct +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +maps.c +file + + + + +2009-01-13T22:22:21.000000Z +a566b4353e65d6289c773a2c6a9df4ed +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +93093 + +shape.c +file + + + + +2009-01-13T22:22:21.000000Z +f5baf5479011c295bcc7cbaa78cdceb7 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +10804 + +matchpat.c +file + + + + +2009-01-13T22:22:21.000000Z +8a74bf1c047c9955cd1aa121f58f55ab +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +10115 + +init.c +file + + + + +2009-01-13T22:22:21.000000Z +09ad927ec96f28e25e4e71abe5c4ffa6 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +28149 + +minutia.c +file + + + + +2009-01-13T22:22:21.000000Z +a5ac624504c755854d7be447d21507ce +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +152690 + +detect.c +file + + + + +2009-01-13T22:22:21.000000Z +58ff6a29e24200791eed999c7d970016 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +16597 + +loop.c +file + + + + +2009-01-13T22:22:21.000000Z +ec8c2811d77ce8e7a5958e7ac1b0858b +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +53875 + +imgutil.c +file + + + + +2009-01-13T22:22:21.000000Z +dc12ea25e6ba38500d31a8f3ecbc9c7c +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +18324 + +dft.c +file + + + + +2009-01-13T22:22:21.000000Z +0b4879db080813b4d12cc3882be8ab10 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +15444 + +ridges.c +file + + + + +2009-01-13T22:22:21.000000Z +08330dbff0a5361ad5467b81c79e452b +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +33140 + +util.c +file + + + + +2009-01-13T22:22:21.000000Z +fbb95127a8b04362bca91435a6e5b325 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +22524 + +log.c +file + + + + +2009-01-13T22:22:21.000000Z +584a33efa45a6000afa574d1679eeb13 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +3122 + +free.c +file + + + + +2009-01-13T22:22:21.000000Z +9fbe7242f7a0034f8bfb9ea67be78d49 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +4230 + +globals.c +file + + + + +2009-01-13T22:22:21.000000Z +4f3e8b829bb48fbc17e8ea1d6b39ef58 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9066 + +morph.c +file + + + + +2009-01-13T22:22:21.000000Z +9e914251f951fe540e6e5c035c3c3b83 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9728 + +line.c +file + + + + +2009-01-13T22:22:21.000000Z +f0c1d98cc1ce883c94e2e288b6fbe02c +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +6750 + +sort.c +file + + + + +2009-01-13T22:22:21.000000Z +9f9a9cd7f754b6d9493fe90831031135 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +11944 + +quality.c +file + + + + +2009-01-13T22:22:21.000000Z +010fec445a5a73f99b084740911664ba +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +15621 + +contour.c +file + + + + +2009-01-13T22:22:21.000000Z +c056a9ba237b68ea4cdc60dd3da1b87f +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +55066 + +block.c +file + + + + +2009-01-13T22:22:21.000000Z +4993de1a71415d97faa6f16de4c8e88a +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +14430 + +binar.c +file + + + + +2009-01-13T22:22:21.000000Z +40e62bf5909efae256642efaccf957b1 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +10069 + +remove.c +file + + + + +2009-01-13T22:22:21.000000Z +b89a8dd09e7504c9f845ead89f5eee6a +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +93432 + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/init.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/init.c.svn-base @@ -0,0 +1,693 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: INIT.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for allocation and/or initialization + of memories required by the NIST Latent Fingerprint System. + +*********************************************************************** + ROUTINES: + init_dir2rad() + init_dftwaves() + get_max_padding_V2() + init_rotgrids() + alloc_dir_powers() + alloc_power_stats() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: init_dir2rad - Allocates and initializes a lookup table containing +#cat: cosine and sine values needed to convert integer IMAP +#cat: directions to angles in radians. + + Input: + ndirs - the number of integer directions to be defined in a + semicircle + Output: + optr - points to the allocated/initialized DIR2RAD structure + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int init_dir2rad(DIR2RAD **optr, const int ndirs) +{ + DIR2RAD *dir2rad; + int i; + double theta, pi_factor; + double cs, sn; + + /* Allocate structure */ + dir2rad = (DIR2RAD *)malloc(sizeof(DIR2RAD)); + if(dir2rad == (DIR2RAD *)NULL){ + fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad\n"); + return(-10); + } + + /* Assign number of directions */ + dir2rad->ndirs = ndirs; + + /* Allocate cosine vector */ + dir2rad->cos = (double *)malloc(ndirs * sizeof(double)); + if(dir2rad->cos == (double *)NULL){ + /* Free memory allocated to this point. */ + free(dir2rad); + fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad->cos\n"); + return(-11); + } + + /* Allocate sine vector */ + dir2rad->sin = (double *)malloc(ndirs * sizeof(double)); + if(dir2rad->sin == (double *)NULL){ + /* Free memory allocated to this point. */ + free(dir2rad->cos); + free(dir2rad); + fprintf(stderr, "ERROR : init_dir2rad : malloc : dir2rad->sin\n"); + return(-12); + } + + /* Pi_factor sets the period of the trig functions to NDIRS units in x. */ + /* For example, if NDIRS==16, then pi_factor = 2(PI/16) = .3926... */ + pi_factor = 2.0*M_PI/(double)ndirs; + + /* Now compute cos and sin values for each direction. */ + for (i = 0; i < ndirs; ++i) { + theta = (double)(i * pi_factor); + cs = cos(theta); + sn = sin(theta); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures. */ + cs = trunc_dbl_precision(cs, TRUNC_SCALE); + sn = trunc_dbl_precision(sn, TRUNC_SCALE); + dir2rad->cos[i] = cs; + dir2rad->sin[i] = sn; + } + + *optr = dir2rad; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: init_dftwaves - Allocates and initializes a set of wave forms needed +#cat: to conduct DFT analysis on blocks of the input image + + Input: + dft_coefs - array of multipliers used to define the frequency for + each wave form to be computed + nwaves - number of wave forms to be computed + blocksize - the width and height of each block of image data to + be DFT analyzed + Output: + optr - points to the allocated/initialized DFTWAVES structure + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int init_dftwaves(DFTWAVES **optr, const double *dft_coefs, + const int nwaves, const int blocksize) +{ + DFTWAVES *dftwaves; + int i, j; + double pi_factor, freq, x; + double *cptr, *sptr; + + /* Allocate structure */ + dftwaves = (DFTWAVES *)malloc(sizeof(DFTWAVES)); + if(dftwaves == (DFTWAVES *)NULL){ + fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves\n"); + return(-20); + } + + /* Set number of DFT waves */ + dftwaves->nwaves = nwaves; + /* Set wave length of the DFT waves (they all must be the same length) */ + dftwaves->wavelen = blocksize; + + /* Allocate list of wave pointers */ + dftwaves->waves = (DFTWAVE **)malloc(nwaves * sizeof(DFTWAVE *)); + if(dftwaves == (DFTWAVES *)NULL){ + /* Free memory allocated to this point. */ + free(dftwaves); + fprintf(stderr, "ERROR : init_dftwaves : malloc : dftwaves->waves\n"); + return(-21); + } + + /* Pi_factor sets the period of the trig functions to BLOCKSIZE units */ + /* in x. For example, if BLOCKSIZE==24, then */ + /* pi_factor = 2(PI/24) = .26179... */ + pi_factor = 2.0*M_PI/(double)blocksize; + + /* Foreach of 4 DFT frequency coef ... */ + for (i = 0; i < nwaves; ++i) { + /* Allocate wave structure */ + dftwaves->waves[i] = (DFTWAVE *)malloc(sizeof(DFTWAVE)); + if(dftwaves->waves[i] == (DFTWAVE *)NULL){ + /* Free memory allocated to this point. */ + { int _j; for(_j = 0; _j < i; _j++){ + free(dftwaves->waves[_j]->cos); + free(dftwaves->waves[_j]->sin); + free(dftwaves->waves[_j]); + }} + free(dftwaves->waves); + free(dftwaves); + fprintf(stderr, + "ERROR : init_dftwaves : malloc : dftwaves->waves[i]\n"); + return(-22); + } + /* Allocate cosine vector */ + dftwaves->waves[i]->cos = (double *)malloc(blocksize * sizeof(double)); + if(dftwaves->waves[i]->cos == (double *)NULL){ + /* Free memory allocated to this point. */ + { int _j; for(_j = 0; _j < i; _j++){ + free(dftwaves->waves[_j]->cos); + free(dftwaves->waves[_j]->sin); + free(dftwaves->waves[_j]); + }} + free(dftwaves->waves[i]); + free(dftwaves->waves); + free(dftwaves); + fprintf(stderr, + "ERROR : init_dftwaves : malloc : dftwaves->waves[i]->cos\n"); + return(-23); + } + /* Allocate sine vector */ + dftwaves->waves[i]->sin = (double *)malloc(blocksize * sizeof(double)); + if(dftwaves->waves[i]->sin == (double *)NULL){ + /* Free memory allocated to this point. */ + { int _j; for(_j = 0; _j < i; _j++){ + free(dftwaves->waves[_j]->cos); + free(dftwaves->waves[_j]->sin); + free(dftwaves->waves[_j]); + }} + free(dftwaves->waves[i]->cos); + free(dftwaves->waves[i]); + free(dftwaves->waves); + free(dftwaves); + fprintf(stderr, + "ERROR : init_dftwaves : malloc : dftwaves->waves[i]->sin\n"); + return(-24); + } + + /* Assign pointer nicknames */ + cptr = dftwaves->waves[i]->cos; + sptr = dftwaves->waves[i]->sin; + + /* Compute actual frequency */ + freq = pi_factor * dft_coefs[i]; + + /* Used as a 1D DFT on a 24 long vector of pixel sums */ + for (j = 0; j < blocksize; ++j) { + /* Compute sample points from frequency */ + x = freq * (double)j; + /* Store cos and sin components of sample point */ + *cptr++ = cos(x); + *sptr++ = sin(x); + } + } + + *optr = dftwaves; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: get_max_padding_V2 - Deterines the maximum amount of image pixel padding +#cat: required by all LFS (Version 2) processes. Padding is currently +#cat: required by the rotated grids used in DFT analyses and in +#cat: directional binarization. The NIST generalized code enables +#cat: the parameters governing these processes to be redefined, so a +#cat: check at runtime is required to determine which process +#cat: requires the most padding. By using the maximum as the padding +#cat: factor, all processes will run safely with a single padding of +#cat: the input image avoiding the need to repad for further processes. + + Input: + map_windowsize - the size (in pixels) of each window centered about + each block in the image used in DFT analyses + map_windowoffset - the offset (in pixels) from the orgin of the + surrounding window to the origin of the block + dirbin_grid_w - the width (in pixels) of the rotated grids used in + directional binarization + dirbin_grid_h - the height (in pixels) of the rotated grids used in + directional binarization + Return Code: + Non-negative - the maximum padding required for all processes +**************************************************************************/ +int get_max_padding_V2(const int map_windowsize, const int map_windowoffset, + const int dirbin_grid_w, const int dirbin_grid_h) +{ + int dft_pad, dirbin_pad, max_pad; + double diag; + double pad; + + + /* 1. Compute pad required for rotated windows used in DFT analyses. */ + + /* Explanation of DFT padding: + + B--------------------- + | window | + | | + | | + | A.......______|__________ + | : : | + |<-C-->: block: | + <--|--D-->: : | image + | ........ | + | | | + | | | + | | | + ---------------------- + | + | + | + + Pixel A = Origin of entire fingerprint image + = Also origin of first block in image. Each pixel in + this block gets the same DFT results computed from + the surrounding window. Note that in general + blocks are adjacent and non-overlapping. + + Pixel B = Origin of surrounding window in which DFT + analysis is conducted. Note that this window is not + completely contained in the image but extends to the + top and to the right. + + Distance C = Number of pixels in which the window extends + beyond the image (map_windowoffset). + + Distance D = Amount of padding required to hold the entire + rotated window in memory. + + */ + + /* Compute pad as difference between the MAP windowsize */ + /* and the diagonal distance of the window. */ + /* (DFT grids are computed with pixel offsets RELATIVE2ORIGIN.) */ + diag = sqrt((double)(2.0 * map_windowsize * map_windowsize)); + pad = (diag-map_windowsize)/(double)2.0; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + pad = trunc_dbl_precision(pad, TRUNC_SCALE); + /* Must add the window offset to the rotational padding. */ + dft_pad = sround(pad) + map_windowoffset; + + /* 2. Compute pad required for rotated blocks used in directional */ + /* binarization. Binarization blocks are applied to each pixel */ + /* in the input image. */ + diag = sqrt((double)((dirbin_grid_w*dirbin_grid_w)+ + (dirbin_grid_h*dirbin_grid_h))); + /* Assumption: all grid centers reside in valid/allocated memory. */ + /* (Dirbin grids are computed with pixel offsets RELATIVE2CENTER.) */ + pad = (diag-1)/(double)2.0; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + pad = trunc_dbl_precision(pad, TRUNC_SCALE); + dirbin_pad = sround(pad); + + max_pad = max(dft_pad, dirbin_pad); + + /* Return the maximum of the two required paddings. This padding will */ + /* be sufficiently large for all purposes, so that padding of the */ + /* input image will only be required once. */ + return(max_pad); +} + +/************************************************************************* +************************************************************************** +#cat: init_rotgrids - Allocates and initializes a set of offsets that address +#cat: individual rotated pixels within a grid. +#cat: These rotated grids are used to conduct DFT analyses +#cat: on blocks of input image data, and they are used +#cat: in isotropic binarization. + + Input: + iw - width (in pixels) of the input image + ih - height (in pixels) of the input image + pad - designates the number of pixels to be padded to the perimeter + of the input image. May be passed as UNDEFINED, in which + case the specific padding required by the rotated grids + will be computed and returned in ROTGRIDS. + start_dir_angle - angle from which rotations are to start + ndirs - number of rotations to compute (within a semicircle) + grid_w - width of the grid in pixels to be rotated + grid_h - height of the grid in pixels to be rotated + relative2 - designates whether pixel offsets whould be computed + relative to the ORIGIN or the CENTER of the grid + Output: + optr - points to the allcated/initialized ROTGRIDS structure + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int init_rotgrids(ROTGRIDS **optr, const int iw, const int ih, const int ipad, + const double start_dir_angle, const int ndirs, + const int grid_w, const int grid_h, const int relative2) +{ + ROTGRIDS *rotgrids; + double pi_offset, pi_incr; + int dir, ix, iy, grid_size, pw, grid_pad, min_dim; + int *grid; + double diag, theta, cs, sn, cx, cy; + double fxm, fym, fx, fy; + int ixt, iyt; + double pad; + + /* Allocate structure */ + rotgrids = (ROTGRIDS *)malloc(sizeof(ROTGRIDS)); + if(rotgrids == (ROTGRIDS *)NULL){ + fprintf(stderr, "ERROR : init_rotgrids : malloc : rotgrids\n"); + return(-30); + } + + /* Set rotgrid attributes */ + rotgrids->ngrids = ndirs; + rotgrids->grid_w = grid_w; + rotgrids->grid_h = grid_h; + rotgrids->start_angle = start_dir_angle; + rotgrids->relative2 = relative2; + + /* Compute pad based on diagonal of the grid */ + diag = sqrt((double)((grid_w*grid_w)+(grid_h*grid_h))); + switch(relative2){ + case RELATIVE2CENTER: + /* Assumption: all grid centers reside in valid/allocated memory. */ + pad = (diag-1)/(double)2.0; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + pad = trunc_dbl_precision(pad, TRUNC_SCALE); + grid_pad = sround(pad); + break; + case RELATIVE2ORIGIN: + /* Assumption: all grid origins reside in valid/allocated memory. */ + min_dim = min(grid_w, grid_h); + /* Compute pad as difference between the smallest grid dimension */ + /* and the diagonal distance of the grid. */ + pad = (diag-min_dim)/(double)2.0; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + pad = trunc_dbl_precision(pad, TRUNC_SCALE); + grid_pad = sround(pad); + break; + default: + fprintf(stderr, + "ERROR : init_rotgrids : Illegal relative flag : %d\n", + relative2); + free(rotgrids); + return(-31); + } + + /* If input padding is UNDEFINED ... */ + if(ipad == UNDEFINED) + /* Use the padding specifically required by the rotated grids herein. */ + rotgrids->pad = grid_pad; + else{ + /* Otherwise, input pad was specified, so check to make sure it is */ + /* sufficiently large to handle the rotated grids herein. */ + if(ipad < grid_pad){ + /* If input pad is NOT large enough, then ERROR. */ + fprintf(stderr, "ERROR : init_rotgrids : Pad passed is too small\n"); + free(rotgrids); + return(-32); + } + /* Otherwise, use the specified input pad in computing grid offsets. */ + rotgrids->pad = ipad; + } + + /* Total number of points in grid */ + grid_size = grid_w * grid_h; + + /* Compute width of "padded" image */ + pw = iw + (rotgrids->pad<<1); + + /* Center coord of grid (0-oriented). */ + cx = (grid_w-1)/(double)2.0; + cy = (grid_h-1)/(double)2.0; + + /* Allocate list of rotgrid pointers */ + rotgrids->grids = (int **)malloc(ndirs * sizeof(int *)); + if(rotgrids->grids == (int **)NULL){ + /* Free memory allocated to this point. */ + free(rotgrids); + fprintf(stderr, "ERROR : init_rotgrids : malloc : rotgrids->grids\n"); + return(-33); + } + + /* Pi_offset is the offset in radians from which angles are to begin. */ + pi_offset = start_dir_angle; + pi_incr = M_PI/(double)ndirs; /* if ndirs == 16, incr = 11.25 degrees */ + + /* For each direction to rotate a grid ... */ + for (dir = 0, theta = pi_offset; + dir < ndirs; dir++, theta += pi_incr) { + + /* Allocate a rotgrid */ + rotgrids->grids[dir] = (int *)malloc(grid_size * sizeof(int)); + if(rotgrids->grids[dir] == (int *)NULL){ + /* Free memory allocated to this point. */ + { int _j; for(_j = 0; _j < dir; _j++){ + free(rotgrids->grids[_j]); + }} + free(rotgrids); + fprintf(stderr, + "ERROR : init_rotgrids : malloc : rotgrids->grids[dir]\n"); + return(-34); + } + + /* Set pointer to current grid */ + grid = rotgrids->grids[dir]; + + /* Compute cos and sin of current angle */ + cs = cos(theta); + sn = sin(theta); + + /* This next section of nested FOR loops precomputes a */ + /* rotated grid. The rotation is set up to rotate a GRID_W X */ + /* GRID_H grid on its center point at C=(Cx,Cy). The current */ + /* pixel being rotated is P=(Ix,Iy). Therefore, we have a */ + /* rotation transformation of point P about pivot point C. */ + /* The rotation transformation about a pivot point in matrix */ + /* form is: */ + /* + +- -+ + | cos(T) sin(T) 0 | + [Ix Iy 1] | -sin(T) cos(T) 0 | + | (1-cos(T))*Cx + Cy*sin(T) (1-cos(T))*Cy - Cx*sin(T) 1 | + +- -+ + */ + /* Multiplying the 2 matrices and combining terms yeilds the */ + /* equations for rotated coordinates (Rx, Ry): */ + /* Rx = Cx + (Ix - Cx)*cos(T) - (Iy - Cy)*sin(T) */ + /* Ry = Cy + (Ix - Cx)*sin(T) + (Iy - Cy)*cos(T) */ + /* */ + /* Care has been taken to ensure that (for example) when */ + /* BLOCKSIZE==24 the rotated indices stay within a centered */ + /* 34X34 area. */ + /* This is important for computing an accurate padding of */ + /* the input image. The rotation occurs "in-place" so that */ + /* outer pixels in the grid are mapped at times from */ + /* adjoining blocks. As a result, to keep from accessing */ + /* "unknown" memory or pixels wrapped from the other side of */ + /* the image, the input image should first be padded by */ + /* PAD=round((DIAG - BLOCKSIZE)/2.0) where DIAG is the */ + /* diagonal distance of the grid. */ + /* For example, when BLOCKSIZE==24, Dx=34, so PAD=5. */ + + /* Foreach each y coord in block ... */ + for (iy = 0; iy < grid_h; ++iy) { + /* Compute rotation factors dependent on Iy (include constant) */ + fxm = -1.0 * ((iy - cy) * sn); + fym = ((iy - cy) * cs); + + /* If offsets are to be relative to the grids origin, then */ + /* we need to subtract CX and CY. */ + if(relative2 == RELATIVE2ORIGIN){ + fxm += cx; + fym += cy; + } + + /* foreach each x coord in block ... */ + for (ix = 0; ix < grid_w; ++ix) { + + /* Now combine factors dependent on Iy with those of Ix */ + fx = fxm + ((ix - cx) * cs); + fy = fym + ((ix - cx) * sn); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + fx = trunc_dbl_precision(fx, TRUNC_SCALE); + fy = trunc_dbl_precision(fy, TRUNC_SCALE); + ixt = sround(fx); + iyt = sround(fy); + + /* Store the current pixels relative */ + /* rotated offset. Make sure to */ + /* multiply the y-component of the */ + /* offset by the "padded" image width! */ + *grid++ = ixt + (iyt * pw); + }/* ix */ + }/* iy */ + }/* dir */ + + *optr = rotgrids; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: alloc_dir_powers - Allocates the memory associated with DFT power +#cat: vectors. The DFT analysis is conducted block by block in the +#cat: input image, and within each block, N wave forms are applied +#cat: at M different directions. + + Input: + nwaves - number of DFT wave forms + ndirs - number of orientations (directions) used in DFT analysis + Output: + opowers - pointer to the allcated power vectors + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int alloc_dir_powers(double ***opowers, const int nwaves, const int ndirs) +{ + int w; + double **powers; + + /* Allocate list of double pointers to hold power vectors */ + powers = (double **)malloc(nwaves * sizeof(double*)); + if(powers == (double **)NULL){ + fprintf(stderr, "ERROR : alloc_dir_powers : malloc : powers\n"); + return(-40); + } + /* Foreach DFT wave ... */ + for(w = 0; w < nwaves; w++){ + /* Allocate power vector for all directions */ + powers[w] = (double *)malloc(ndirs * sizeof(double)); + if(powers[w] == (double *)NULL){ + /* Free memory allocated to this point. */ + { int _j; for(_j = 0; _j < w; _j++){ + free(powers[_j]); + }} + free(powers); + fprintf(stderr, "ERROR : alloc_dir_powers : malloc : powers[w]\n"); + return(-41); + } + } + + *opowers = powers; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: alloc_power_stats - Allocates memory associated with set of statistics +#cat: derived from DFT power vectors computed in a block of the +#cat: input image. Statistics are not computed for the lowest DFT +#cat: wave form, so the length of the statistics arrays is 1 less +#cat: than the number of DFT wave forms used. The staistics +#cat: include the Maximum power for each wave form, the direction +#cat: at which the maximum power occured, and a normalized value +#cat: for the maximum power. In addition, the statistics are +#cat: ranked in descending order based on normalized squared +#cat: maximum power. + + Input: + nstats - the number of waves forms from which statistics are to be + derived (N Waves - 1) + Output: + owis - points to an array to hold the ranked wave form indicies + of the corresponding statistics + opowmaxs - points to an array to hold the maximum DFT power for each + wave form + opowmax_dirs - points to an array to hold the direction corresponding to + each maximum power value + opownorms - points to an array to hold the normalized maximum power + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int alloc_power_stats(int **owis, double **opowmaxs, int **opowmax_dirs, + double **opownorms, const int nstats) +{ + int *wis, *powmax_dirs; + double *powmaxs, *pownorms; + + /* Allocate DFT wave index vector */ + wis = (int *)malloc(nstats * sizeof(int)); + if(wis == (int *)NULL){ + fprintf(stderr, "ERROR : alloc_power_stats : malloc : wis\n"); + return(-50); + } + + /* Allocate max power vector */ + powmaxs = (double *)malloc(nstats * sizeof(double)); + if(powmaxs == (double *)NULL){ + /* Free memory allocated to this point. */ + free(wis); + fprintf(stderr, "ERROR : alloc_power_stats : malloc : powmaxs\n"); + return(-51); + } + + /* Allocate max power direction vector */ + powmax_dirs = (int *)malloc(nstats * sizeof(int)); + if(powmax_dirs == (int *)NULL){ + /* Free memory allocated to this point. */ + free(wis); + free(powmaxs); + fprintf(stderr, "ERROR : alloc_power_stats : malloc : powmax_dirs\n"); + return(-52); + } + + /* Allocate normalized power vector */ + pownorms = (double *)malloc(nstats * sizeof(double)); + if(pownorms == (double *)NULL){ + /* Free memory allocated to this point. */ + free(wis); + free(powmaxs); + free(pownorms); + fprintf(stderr, "ERROR : alloc_power_stats : malloc : pownorms\n"); + return(-53); + } + + *owis = wis; + *opowmaxs = powmaxs; + *opowmax_dirs = powmax_dirs; + *opownorms = pownorms; + return(0); +} + + + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/minutia.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/minutia.c.svn-base @@ -0,0 +1,3511 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: MINUTIA.C + AUTHOR: Michael D. Garris + DATE: 05/11/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 09/13/2004 + + Contains routines responsible for detecting initial minutia + points as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + alloc_minutiae() + realloc_minutiae() + detect_minutiae_V2() + update_minutiae() + update_minutiae_V2() + sort_minutiae_y_x() + sort_minutiae_x_y() + rm_dup_minutiae() + dump_minutiae() + dump_minutiae_pts() + dump_reliable_minutiae_pts() + create_minutia() + free_minutiae() + free_minutia() + remove_minutia() + join_minutia() + minutia_type() + is_minutia_appearing() + choose_scan_direction() + scan4minutiae() + scan4minutiae_horizontally() + scan4minutiae_horizontally_V2() + scan4minutiae_vertically() + scan4minutiae_vertically_V2() + rescan4minutiae_horizontally() + rescan4minutiae_vertically() + rescan_partial_horizontally() + rescan_partial_vertically() + get_nbr_block_index() + adjust_horizontal_rescan() + adjust_vertical_rescan() + process_horizontal_scan_minutia() + process_horizontal_scan_minutia_V2() + process_vertical_scan_minutia() + process_vertical_scan_minutia_V2() + adjust_high_curvature_minutia() + adjust_high_curvature_minutia_V2() + get_low_curvature_direction() + lfs2nist_minutia_XYT() + +***********************************************************************/ + +#include +#include +#include + + + +/************************************************************************* +************************************************************************** +#cat: alloc_minutiae - Allocates and initializes a minutia list based on the +#cat: specified maximum number of minutiae to be detected. + + Input: + max_minutiae - number of minutia to be allocated in list + Output: + ominutiae - points to the allocated minutiae list + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int alloc_minutiae(MINUTIAE **ominutiae, const int max_minutiae) +{ + MINUTIAE *minutiae; + + minutiae = (MINUTIAE *)malloc(sizeof(MINUTIAE)); + if(minutiae == (MINUTIAE *)NULL){ + fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae\n"); + exit(-430); + } + minutiae->list = (MINUTIA **)malloc(max_minutiae * sizeof(MINUTIA *)); + if(minutiae->list == (MINUTIA **)NULL){ + fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae->list\n"); + exit(-431); + } + + minutiae->alloc = max_minutiae; + minutiae->num = 0; + + *ominutiae = minutiae; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: realloc_minutiae - Reallocates a previously allocated minutia list +#cat: extending its allocated length based on the specified +#cat: increment. + + Input: + minutiae - previously allocated list of minutiae points + max_minutiae - number of minutia to be allocated in list + Output: + minutiae - extended list of minutiae points + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int realloc_minutiae(MINUTIAE *minutiae, const int incr_minutiae) +{ + minutiae->alloc += incr_minutiae; + minutiae->list = (MINUTIA **)realloc(minutiae->list, + minutiae->alloc * sizeof(MINUTIA *)); + if(minutiae->list == (MINUTIA **)NULL){ + fprintf(stderr, "ERROR : realloc_minutiae : realloc : minutiae->list\n"); + exit(-432); + } + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: detect_minutiae_V2 - Takes a binary image and its associated +#cat: Direction and Low Flow Maps and scans each image block +#cat: with valid direction for minutia points. Minutia points +#cat: detected in LOW FLOW blocks are set with lower reliability. + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + direction_map - map of image blocks containing directional ridge flow + low_flow_map - map of image blocks flagged as LOW RIDGE FLOW + high_curve_map - map of image blocks flagged as HIGH CURVATURE + mw - width (in blocks) of the maps + mh - height (in blocks) of the maps + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int detect_minutiae_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *direction_map, int *low_flow_map, int *high_curve_map, + const int mw, const int mh, + const LFSPARMS *lfsparms) +{ + int ret; + int *pdirection_map, *plow_flow_map, *phigh_curve_map; + + /* Pixelize the maps by assigning block values to individual pixels. */ + if((ret = pixelize_map(&pdirection_map, iw, ih, direction_map, mw, mh, + lfsparms->blocksize))){ + return(ret); + } + + if((ret = pixelize_map(&plow_flow_map, iw, ih, low_flow_map, mw, mh, + lfsparms->blocksize))){ + free(pdirection_map); + return(ret); + } + + if((ret = pixelize_map(&phigh_curve_map, iw, ih, high_curve_map, mw, mh, + lfsparms->blocksize))){ + free(pdirection_map); + free(plow_flow_map); + return(ret); + } + + if((ret = scan4minutiae_horizontally_V2(minutiae, bdata, iw, ih, + pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){ + free(pdirection_map); + free(plow_flow_map); + free(phigh_curve_map); + return(ret); + } + + if((ret = scan4minutiae_vertically_V2(minutiae, bdata, iw, ih, + pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){ + free(pdirection_map); + free(plow_flow_map); + free(phigh_curve_map); + return(ret); + } + + /* Deallocate working memories. */ + free(pdirection_map); + free(plow_flow_map); + free(phigh_curve_map); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: update_minutiae - Takes a detected minutia point and (if it is not +#cat: determined to already be in the minutiae list) adds it to +#cat: the list. + + Input: + minutia - minutia structure for detected point + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - minutia added to successfully added to minutiae list + IGNORE - minutia is to be ignored (already in the minutiae list) + Negative - system error +**************************************************************************/ +int update_minutiae(MINUTIAE *minutiae, MINUTIA *minutia, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int i, ret, dy, dx, delta_dir; + int qtr_ndirs, full_ndirs; + + /* Check to see if minutiae list is full ... if so, then extend */ + /* the length of the allocated list of minutia points. */ + if(minutiae->num >= minutiae->alloc){ + if((ret = realloc_minutiae(minutiae, MAX_MINUTIAE))) + return(ret); + } + + /* Otherwise, there is still room for more minutia. */ + + /* Compute quarter of possible directions in a semi-circle */ + /* (ie. 45 degrees). */ + qtr_ndirs = lfsparms->num_directions>>2; + + /* Compute number of directions in full circle. */ + full_ndirs = lfsparms->num_directions<<1; + + /* Is the minutiae list empty? */ + if(minutiae->num > 0){ + /* Foreach minutia stored in the list... */ + for(i = 0; i < minutiae->num; i++){ + /* If x distance between new minutia and current list minutia */ + /* are sufficiently close... */ + dx = abs(minutiae->list[i]->x - minutia->x); + if(dx < lfsparms->max_minutia_delta){ + /* If y distance between new minutia and current list minutia */ + /* are sufficiently close... */ + dy = abs(minutiae->list[i]->y - minutia->y); + if(dy < lfsparms->max_minutia_delta){ + /* If new minutia and current list minutia are same type... */ + if(minutiae->list[i]->type == minutia->type){ + /* Test to see if minutiae have similar directions. */ + /* Take minimum of computed inner and outer */ + /* direction differences. */ + delta_dir = abs(minutiae->list[i]->direction - + minutia->direction); + delta_dir = min(delta_dir, full_ndirs-delta_dir); + /* If directional difference is <= 45 degrees... */ + if(delta_dir <= qtr_ndirs){ + /* If new minutia and current list minutia share */ + /* the same point... */ + if((dx==0) && (dy==0)){ + /* Then the minutiae match, so don't add the new one */ + /* to the list. */ + return(IGNORE); + } + /* Othewise, check if they share the same contour. */ + /* Start by searching "max_minutia_delta" steps */ + /* clockwise. */ + /* If new minutia point found on contour... */ + if(search_contour(minutia->x, minutia->y, + lfsparms->max_minutia_delta, + minutiae->list[i]->x, minutiae->list[i]->y, + minutiae->list[i]->ex, minutiae->list[i]->ey, + SCAN_CLOCKWISE, bdata, iw, ih)){ + /* Consider the new minutia to be the same as the */ + /* current list minutia, so don't add the new one */ + /* to the list. */ + return(IGNORE); + } + /* Now search "max_minutia_delta" steps counter- */ + /* clockwise along contour. */ + /* If new minutia point found on contour... */ + if(search_contour(minutia->x, minutia->y, + lfsparms->max_minutia_delta, + minutiae->list[i]->x, minutiae->list[i]->y, + minutiae->list[i]->ex, minutiae->list[i]->ey, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih)){ + /* Consider the new minutia to be the same as the */ + /* current list minutia, so don't add the new one */ + /* to the list. */ + return(IGNORE); + } + + /* Otherwise, new minutia and current list minutia do */ + /* not share the same contour, so although they are */ + /* similar in type and location, treat them as 2 */ + /* different minutia. */ + + } /* Otherwise, directions are too different. */ + } /* Otherwise, minutiae are different type. */ + } /* Otherwise, minutiae too far apart in Y. */ + } /* Otherwise, minutiae too far apart in X. */ + } /* End FOR minutia in list. */ + } /* Otherwise, minutiae list is empty. */ + + /* Otherwise, assume new minutia is not in the list, so add it. */ + minutiae->list[minutiae->num] = minutia; + (minutiae->num)++; + + /* New minutia was successfully added to the list. */ + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: update_minutiae_V2 - Takes a detected minutia point and (if it is not +#cat: determined to already be in the minutiae list or the +#cat: new point is determined to be "more compatible") adds +#cat: it to the list. + + Input: + minutia - minutia structure for detected point + scan_dir - orientation of scan when minutia was detected + dmapval - directional ridge flow of block minutia is in + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - minutia added to successfully added to minutiae list + IGNORE - minutia is to be ignored (already in the minutiae list) + Negative - system error +**************************************************************************/ +int update_minutiae_V2(MINUTIAE *minutiae, MINUTIA *minutia, + const int scan_dir, const int dmapval, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int i, ret, dy, dx, delta_dir; + int qtr_ndirs, full_ndirs; + int map_scan_dir; + + /* Check to see if minutiae list is full ... if so, then extend */ + /* the length of the allocated list of minutia points. */ + if(minutiae->num >= minutiae->alloc){ + if((ret = realloc_minutiae(minutiae, MAX_MINUTIAE))) + return(ret); + } + + /* Otherwise, there is still room for more minutia. */ + + /* Compute quarter of possible directions in a semi-circle */ + /* (ie. 45 degrees). */ + qtr_ndirs = lfsparms->num_directions>>2; + + /* Compute number of directions in full circle. */ + full_ndirs = lfsparms->num_directions<<1; + + /* Is the minutiae list empty? */ + if(minutiae->num > 0){ + /* Foreach minutia stored in the list (in reverse order) ... */ + for(i = minutiae->num-1; i >= 0; i--){ + /* If x distance between new minutia and current list minutia */ + /* are sufficiently close... */ + dx = abs(minutiae->list[i]->x - minutia->x); + if(dx < lfsparms->max_minutia_delta){ + /* If y distance between new minutia and current list minutia */ + /* are sufficiently close... */ + dy = abs(minutiae->list[i]->y - minutia->y); + if(dy < lfsparms->max_minutia_delta){ + /* If new minutia and current list minutia are same type... */ + if(minutiae->list[i]->type == minutia->type){ + /* Test to see if minutiae have similar directions. */ + /* Take minimum of computed inner and outer */ + /* direction differences. */ + delta_dir = abs(minutiae->list[i]->direction - + minutia->direction); + delta_dir = min(delta_dir, full_ndirs-delta_dir); + /* If directional difference is <= 45 degrees... */ + if(delta_dir <= qtr_ndirs){ + /* If new minutia and current list minutia share */ + /* the same point... */ + if((dx==0) && (dy==0)){ + /* Then the minutiae match, so don't add the new one */ + /* to the list. */ + return(IGNORE); + } + /* Othewise, check if they share the same contour. */ + /* Start by searching "max_minutia_delta" steps */ + /* clockwise. */ + /* If new minutia point found on contour... */ + if(search_contour(minutia->x, minutia->y, + lfsparms->max_minutia_delta, + minutiae->list[i]->x, minutiae->list[i]->y, + minutiae->list[i]->ex, minutiae->list[i]->ey, + SCAN_CLOCKWISE, bdata, iw, ih) || + search_contour(minutia->x, minutia->y, + lfsparms->max_minutia_delta, + minutiae->list[i]->x, minutiae->list[i]->y, + minutiae->list[i]->ex, minutiae->list[i]->ey, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih)){ + /* If new minutia has VALID block direction ... */ + if(dmapval >= 0){ + /* Derive feature scan direction compatible */ + /* with VALID direction. */ + map_scan_dir = choose_scan_direction(dmapval, + lfsparms->num_directions); + /* If map scan direction compatible with scan */ + /* direction in which new minutia was found ... */ + if(map_scan_dir == scan_dir){ + /* Then choose the new minutia over the one */ + /* currently in the list. */ + if((ret = remove_minutia(i, minutiae))){ + return(ret); + } + /* Continue on ... */ + } + else + /* Othersize, scan directions not compatible...*/ + /* so choose to keep the current minutia in */ + /* the list and ignore the new one. */ + return(IGNORE); + } + else{ + /* Otherwise, no reason to believe new minutia */ + /* is any better than the current one in the list,*/ + /* so consider the new minutia to be the same as */ + /* the current list minutia, and don't add the new*/ + /* one to the list. */ + return(IGNORE); + } + } + + /* Otherwise, new minutia and current list minutia do */ + /* not share the same contour, so although they are */ + /* similar in type and location, treat them as 2 */ + /* different minutia. */ + + } /* Otherwise, directions are too different. */ + } /* Otherwise, minutiae are different type. */ + } /* Otherwise, minutiae too far apart in Y. */ + } /* Otherwise, minutiae too far apart in X. */ + } /* End FOR minutia in list. */ + } /* Otherwise, minutiae list is empty. */ + + /* Otherwise, assume new minutia is not in the list, or those that */ + /* were close neighbors were selectively removed, so add it. */ + minutiae->list[minutiae->num] = minutia; + (minutiae->num)++; + + /* New minutia was successfully added to the list. */ + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: sort_minutiae_y_x - Takes a list of minutia points and sorts them +#cat: top-to-bottom and then left-to-right. + + Input: + minutiae - list of minutiae + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + minutiae - list of sorted minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int sort_minutiae_y_x(MINUTIAE *minutiae, const int iw, const int ih) +{ + int *ranks, *order; + int i, ret; + MINUTIA **newlist; + + /* Allocate a list of integers to hold 1-D image pixel offsets */ + /* for each of the 2-D minutia coordinate points. */ + ranks = (int *)malloc(minutiae->num * sizeof(int)); + if(ranks == (int *)NULL){ + fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : ranks\n"); + return(-310); + } + + /* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */ + for(i = 0; i < minutiae->num; i++) + ranks[i] = (minutiae->list[i]->y * iw) + minutiae->list[i]->x; + + /* Get sorted order of minutiae. */ + if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){ + free(ranks); + return(ret); + } + + /* Allocate new MINUTIA list to hold sorted minutiae. */ + newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *)); + if(newlist == (MINUTIA **)NULL){ + free(ranks); + free(order); + fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : newlist\n"); + return(-311); + } + + /* Put minutia into sorted order in new list. */ + for(i = 0; i < minutiae->num; i++) + newlist[i] = minutiae->list[order[i]]; + + /* Deallocate non-sorted list of minutia pointers. */ + free(minutiae->list); + /* Assign new sorted list of minutia to minutiae list. */ + minutiae->list = newlist; + + /* Free the working memories supporting the sort. */ + free(order); + free(ranks); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: sort_minutiae_x_y - Takes a list of minutia points and sorts them +#cat: left-to-right and then top-to-bottom. + + Input: + minutiae - list of minutiae + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + minutiae - list of sorted minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int sort_minutiae_x_y(MINUTIAE *minutiae, const int iw, const int ih) +{ + int *ranks, *order; + int i, ret; + MINUTIA **newlist; + + /* Allocate a list of integers to hold 1-D image pixel offsets */ + /* for each of the 2-D minutia coordinate points. */ + ranks = (int *)malloc(minutiae->num * sizeof(int)); + if(ranks == (int *)NULL){ + fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : ranks\n"); + return(-440); + } + + /* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */ + for(i = 0; i < minutiae->num; i++) + ranks[i] = (minutiae->list[i]->x * iw) + minutiae->list[i]->y; + + /* Get sorted order of minutiae. */ + if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){ + free(ranks); + return(ret); + } + + /* Allocate new MINUTIA list to hold sorted minutiae. */ + newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *)); + if(newlist == (MINUTIA **)NULL){ + free(ranks); + free(order); + fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : newlist\n"); + return(-441); + } + + /* Put minutia into sorted order in new list. */ + for(i = 0; i < minutiae->num; i++) + newlist[i] = minutiae->list[order[i]]; + + /* Deallocate non-sorted list of minutia pointers. */ + free(minutiae->list); + /* Assign new sorted list of minutia to minutiae list. */ + minutiae->list = newlist; + + /* Free the working memories supporting the sort. */ + free(order); + free(ranks); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: rm_dup_minutiae - Takes a list of minutiae sorted in some adjacent order +#cat: and detects and removes redundant minutia that have the +#cat: same exact pixel coordinate locations (even if other +#cat: attributes may differ). + + Input: + mintuiae - list of sorted minutiae + Output: + mintuiae - list of sorted minutiae with duplicates removed + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int rm_dup_minutiae(MINUTIAE *minutiae) +{ + int i, ret; + MINUTIA *minutia1, *minutia2; + + /* Work backward from the end of the list of minutiae. This way */ + /* we can selectively remove minutia from the list and not cause */ + /* problems with keeping track of current indices. */ + for(i = minutiae->num-1; i > 0; i--){ + minutia1 = minutiae->list[i]; + minutia2 = minutiae->list[i-1]; + /* If minutia pair has identical coordinates ... */ + if((minutia1->x == minutia2->x) && + (minutia1->y == minutia2->y)){ + /* Remove the 2nd minutia from the minutiae list. */ + if((ret = remove_minutia(i-1, minutiae))) + return(ret); + /* The first minutia slides into the position of the 2nd. */ + } + } + + /* Return successfully. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: dump_minutiae - Given a minutiae list, writes a formatted text report of +#cat: the list's contents to the specified open file pointer. + + Input: + minutiae - list of minutia structures + Output: + fpout - open file pointer +**************************************************************************/ +void dump_minutiae(FILE *fpout, const MINUTIAE *minutiae) +{ + int i, j; + + fprintf(fpout, "\n%d Minutiae Detected\n\n", minutiae->num); + + for(i = 0; i < minutiae->num; i++){ + /* Precision of reliablity added one decimal position */ + /* on 09-13-04 */ + fprintf(fpout, "%4d : %4d, %4d : %2d : %6.3f :", i, + minutiae->list[i]->x, minutiae->list[i]->y, + minutiae->list[i]->direction, minutiae->list[i]->reliability); + if(minutiae->list[i]->type == RIDGE_ENDING) + fprintf(fpout, "RIG : "); + else + fprintf(fpout, "BIF : "); + + if(minutiae->list[i]->appearing) + fprintf(fpout, "APP : "); + else + fprintf(fpout, "DIS : "); + + fprintf(fpout, "%2d ", minutiae->list[i]->feature_id); + + for(j = 0; j < minutiae->list[i]->num_nbrs; j++){ + fprintf(fpout, ": %4d,%4d; %2d ", + minutiae->list[minutiae->list[i]->nbrs[j]]->x, + minutiae->list[minutiae->list[i]->nbrs[j]]->y, + minutiae->list[i]->ridge_counts[j]); + } + + fprintf(fpout, "\n"); + } +} + +/************************************************************************* +************************************************************************** +#cat: dump_minutiae_pts - Given a minutiae list, writes the coordinate point +#cat: for each minutia in the list to the specified open +#cat: file pointer. + + Input: + minutiae - list of minutia structures + Output: + fpout - open file pointer +**************************************************************************/ +void dump_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae) +{ + int i; + + /* First line in the output file contians the number of minutia */ + /* points to be written to the file. */ + fprintf(fpout, "%d\n", minutiae->num); + + /* Foreach minutia in list... */ + for(i = 0; i < minutiae->num; i++){ + /* Write the minutia's coordinate point to the file pointer. */ + fprintf(fpout, "%4d %4d\n", minutiae->list[i]->x, minutiae->list[i]->y); + } +} + + +/************************************************************************* +************************************************************************** +#cat: dump_reliable_minutiae_pts - Given a minutiae list, writes the +#cat: coordinate point for each minutia in the list that has +#cat: the specified reliability to the specified open +#cat: file pointer. + + Input: + minutiae - list of minutia structures + reliability - desired reliability level for minutiae to be reported + Output: + fpout - open file pointer +**************************************************************************/ +void dump_reliable_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae, + const double reliability) +{ + int i, count; + + /* First count the number of qualifying minutiae so that the */ + /* MFS header may be written. */ + count = 0; + /* Foreach minutia in list... */ + for(i = 0; i < minutiae->num; i++){ + if(minutiae->list[i]->reliability == reliability) + count++; + } + + /* First line in the output file contians the number of minutia */ + /* points to be written to the file. */ + fprintf(fpout, "%d\n", count); + + /* Foreach minutia in list... */ + for(i = 0; i < minutiae->num; i++){ + if(minutiae->list[i]->reliability == reliability) + /* Write the minutia's coordinate point to the file pointer. */ + fprintf(fpout, "%4d %4d\n", + minutiae->list[i]->x, minutiae->list[i]->y); + } +} + +/************************************************************************* +************************************************************************** +#cat: create_minutia - Takes attributes associated with a detected minutia +#cat: point and allocates and initializes a minutia structure. + + Input: + x_loc - x-pixel coord of minutia (interior to feature) + y_loc - y-pixel coord of minutia (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel (exterior to feature) + idir - integer direction of the minutia + reliability - floating point measure of minutia's reliability + type - type of the minutia (ridge-ending or bifurcation) + appearing - designates the minutia as appearing or disappearing + feature_id - index of minutia's matching feature_patterns[] + Output: + ominutia - ponter to an allocated and initialized minutia structure + Return Code: + Zero - minutia structure successfully allocated and initialized + Negative - system error +*************************************************************************/ +int create_minutia(MINUTIA **ominutia, const int x_loc, const int y_loc, + const int x_edge, const int y_edge, const int idir, + const double reliability, + const int type, const int appearing, const int feature_id) +{ + MINUTIA *minutia; + + /* Allocate a minutia structure. */ + minutia = (MINUTIA *)malloc(sizeof(MINUTIA)); + /* If allocation error... */ + if(minutia == (MINUTIA *)NULL){ + fprintf(stderr, "ERROR : create_minutia : malloc : minutia\n"); + return(-230); + } + + /* Assign minutia structure attributes. */ + minutia->x = x_loc; + minutia->y = y_loc; + minutia->ex = x_edge; + minutia->ey = y_edge; + minutia->direction = idir; + minutia->reliability = reliability; + minutia->type = type; + minutia->appearing = appearing; + minutia->feature_id = feature_id; + minutia->nbrs = (int *)NULL; + minutia->ridge_counts = (int *)NULL; + minutia->num_nbrs = 0; + + /* Set minutia object to output pointer. */ + *ominutia = minutia; + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: free_minutiae - Takes a minutiae list and deallocates all memory +#cat: associated with it. + + Input: + minutiae - pointer to allocated list of minutia structures +*************************************************************************/ +void free_minutiae(MINUTIAE *minutiae) +{ + int i; + + /* Deallocate minutia structures in the list. */ + for(i = 0; i < minutiae->num; i++) + free_minutia(minutiae->list[i]); + /* Deallocate list of minutia pointers. */ + free(minutiae->list); + + /* Deallocate the list structure. */ + free(minutiae); +} + +/************************************************************************* +************************************************************************** +#cat: free_minutia - Takes a minutia pointer and deallocates all memory +#cat: associated with it. + + Input: + minutia - pointer to allocated minutia structure +*************************************************************************/ +void free_minutia(MINUTIA *minutia) +{ + /* Deallocate sublists. */ + if(minutia->nbrs != (int *)NULL) + free(minutia->nbrs); + if(minutia->ridge_counts != (int *)NULL) + free(minutia->ridge_counts); + + /* Deallocate the minutia structure. */ + free(minutia); +} + +/************************************************************************* +************************************************************************** +#cat: remove_minutia - Removes the specified minutia point from the input +#cat: list of minutiae. + + Input: + index - position of minutia to be removed from list + minutiae - input list of minutiae + Output: + minutiae - list with minutia removed + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int remove_minutia(const int index, MINUTIAE *minutiae) +{ + int fr, to; + + /* Make sure the requested index is within range. */ + if((index < 0) && (index >= minutiae->num)){ + fprintf(stderr, "ERROR : remove_minutia : index out of range\n"); + return(-380); + } + + /* Deallocate the minutia structure to be removed. */ + free_minutia(minutiae->list[index]); + + /* Slide the remaining list of minutiae up over top of the */ + /* position of the minutia being removed. */ + for(to = index, fr = index+1; fr < minutiae->num; to++, fr++) + minutiae->list[to] = minutiae->list[fr]; + + /* Decrement the number of minutiae remaining in the list. */ + minutiae->num--; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: join_minutia - Takes 2 minutia points and connectes their features in +#cat: the input binary image. A line is drawn in the image +#cat: between the 2 minutia with a specified line-width radius +#cat: and a conditional border of pixels opposite in color +#cat: from the interior line. + + Input: + minutia1 - first minutia point to be joined + minutia2 - second minutia point to be joined + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + with_boundary - signifies the inclusion of border pixels + line_radius - line-width radius of join line + Output: + bdata - edited image with minutia features joined + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int join_minutia(const MINUTIA *minutia1, const MINUTIA *minutia2, + unsigned char *bdata, const int iw, const int ih, + const int with_boundary, const int line_radius) +{ + int dx_gte_dy, delta_x, delta_y; + int *x_list, *y_list, num; + int minutia_pix, boundary_pix; + int i, j, ret; + int x1, y1, x2, y2; + + /* Compute X and Y deltas between minutia points. */ + delta_x = abs(minutia1->x - minutia2->x); + delta_y = abs(minutia1->y - minutia2->y); + + /* Set flag based on |DX| >= |DY|. */ + /* If flag is true then add additional pixel width to the join line */ + /* by adding pixels neighboring top and bottom. */ + /* If flag is false then add additional pixel width to the join line */ + /* by adding pixels neighboring left and right. */ + if(delta_x >= delta_y) + dx_gte_dy = 1; + else + dx_gte_dy = 0; + + /* Compute points along line segment between the two minutia points. */ + if((ret = line_points(&x_list, &y_list, &num, + minutia1->x, minutia1->y, minutia2->x, minutia2->y))) + /* If error with line routine, return error code. */ + return(ret); + + /* Determine pixel color of minutia and boundary. */ + if(minutia1->type == RIDGE_ENDING){ + /* To connect 2 ridge-endings, draw black. */ + minutia_pix = 1; + boundary_pix = 0; + } + else{ + /* To connect 2 bifurcations, draw white. */ + minutia_pix = 0; + boundary_pix = 1; + } + + /* Foreach point on line connecting the minutiae points ... */ + for(i = 1; i < num-1; i++){ + /* Draw minutia pixel at current point on line. */ + *(bdata+(y_list[i]*iw)+x_list[i]) = minutia_pix; + + /* Initialize starting corrdinates for adding width to the */ + /* join line to the current point on the line. */ + x1 = x_list[i]; + y1 = y_list[i]; + x2 = x1; + y2 = y1; + /* Foreach pixel of added radial width ... */ + for(j = 0; j < line_radius; j++){ + + /* If |DX|>=|DY|, we want to add width to line by writing */ + /* to pixels neighboring above and below. */ + /* x1 -= (0=(1-1)); y1 -= 1 ==> ABOVE */ + /* x2 += (0=(1-1)); y2 += 1 ==> BELOW */ + /* If |DX|<|DY|, we want to add width to line by writing */ + /* to pixels neighboring left and right. */ + /* x1 -= (1=(1-0)); y1 -= 0 ==> LEFT */ + /* x2 += (1=(1-0)); y2 += 0 ==> RIGHT */ + + /* Advance 1st point along width dimension. */ + x1 -= (1 - dx_gte_dy); + y1 -= dx_gte_dy; + /* If pixel 1st point is within image boundaries ... */ + if((x1 >= 0) && (x1 < iw) && + (y1 >= 0) && (y1 < ih)) + /* Write the pixel ABOVE or LEFT. */ + *(bdata+(y1*iw)+x1) = minutia_pix; + + /* Advance 2nd point along width dimension. */ + x2 += (1 - dx_gte_dy); + y2 += dx_gte_dy; + /* If pixel 2nd point is within image boundaries ... */ + if((x2 >= 0) && (x2 < iw) && + /* Write the pixel BELOW or RIGHT. */ + (y2 >= 0) && (y2 < ih)) + *(bdata+(y2*iw)+x2) = minutia_pix; + } + + /* If boundary flag is set ... draw the boundary pixels.*/ + if(with_boundary){ + /* Advance 1st point along width dimension. */ + x1 -= (1 - dx_gte_dy); + y1 -= dx_gte_dy; + /* If pixel 1st point is within image boundaries ... */ + if((x1 >= 0) && (x1 < iw) && + (y1 >= 0) && (y1 < ih)) + /* Write the pixel ABOVE or LEFT of opposite color. */ + *(bdata+(y1*iw)+x1) = boundary_pix; + + /* Advance 2nd point along width dimension. */ + x2 += (1 - dx_gte_dy); + y2 += dx_gte_dy; + /* If pixel 2nd point is within image boundaries ... */ + if((x2 >= 0) && (x2 < iw) && + (y2 >= 0) && (y2 < ih)) + /* Write the pixel BELOW or RIGHT of opposite color. */ + *(bdata+(y2*iw)+x2) = boundary_pix; + } + } + + /* Deallocate points along connecting line. */ + free(x_list); + free(y_list); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: minutia_type - Given the pixel color of the detected feature, returns +#cat: whether the minutia is a ridge-ending (black pixel) or +#cat: bifurcation (white pixel). + + Input: + feature_pix - pixel color of the feature's interior + Return Code: + RIDGE_ENDING - minutia is a ridge-ending + BIFURCATION - minutia is a bifurcation (valley-ending) +**************************************************************************/ +int minutia_type(const int feature_pix) +{ + int type; + + /* If feature pixel is white ... */ + if(feature_pix == 0) + /* Then the feature is a valley-ending, so BIFURCATION. */ + type = BIFURCATION; + /* Otherwise, the feature pixel is black ... */ + else + /* So the feature is a RIDGE-ENDING. */ + type = RIDGE_ENDING; + + /* Return the type. */ + return(type); +} + +/************************************************************************* +************************************************************************** +#cat: is_minutia_appearing - Given the pixel location of a minutia feature +#cat: and its corresponding adjacent edge pixel, returns whether +#cat: the minutia is appearing or disappearing. Remeber, that +#cat: "feature" refers to either a ridge or valley-ending. + + Input: + x_loc - x-pixel coord of feature (interior to feature) + y_loc - y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + Return Code: + APPEARING - minutia is appearing (TRUE==1) + DISAPPEARING - minutia is disappearing (FALSE==0) + Negative - system error +**************************************************************************/ +int is_minutia_appearing(const int x_loc, const int y_loc, + const int x_edge, const int y_edge) +{ + /* Edge pixels will always be N,S,E,W of feature pixel. */ + + /* 1. When scanning for feature's HORIZONTALLY... */ + /* If the edge is above the feature, then appearing. */ + if(x_edge < x_loc) + return(APPEARING); + /* If the edge is below the feature, then disappearing. */ + if(x_edge > x_loc) + return(DISAPPEARING); + + /* 1. When scanning for feature's VERTICALLY... */ + /* If the edge is left of feature, then appearing. */ + if(y_edge < y_loc) + return(APPEARING); + /* If the edge is right of feature, then disappearing. */ + if(y_edge > y_loc) + return(DISAPPEARING); + + /* Should never get here, but just in case. */ + fprintf(stderr, + "ERROR : is_minutia_appearing : bad configuration of pixels\n"); + return(-240); +} + +/************************************************************************* +************************************************************************** +#cat: choose_scan_direction - Determines the orientation (horizontal or +#cat: vertical) in which a block is to be scanned for minutiae. +#cat: The orientation is based on the blocks corresponding IMAP +#cat: direction. + + Input: + imapval - Block's IMAP direction + ndirs - number of possible IMAP directions (within semicircle) + Return Code: + SCAN_HORIZONTAL - horizontal orientation + SCAN_VERTICAL - vertical orientation +**************************************************************************/ +int choose_scan_direction(const int imapval, const int ndirs) +{ + int qtr_ndirs; + + /* Compute quarter of directions in semi-circle. */ + qtr_ndirs = ndirs>>2; + + /* If ridge flow in block is relatively vertical, then we want */ + /* to scan for minutia features in the opposite direction */ + /* (ie. HORIZONTALLY). */ + if((imapval <= qtr_ndirs) || (imapval > (qtr_ndirs*3))) + return(SCAN_HORIZONTAL); + /* Otherwise, ridge flow is realtively horizontal, and we want */ + /* to scan for minutia features in the opposite direction */ + /* (ie. VERTICALLY). */ + else + return(SCAN_VERTICAL); + +} + +/************************************************************************* +************************************************************************** +#cat: scan4minutiae - Scans a block of binary image data detecting potential +#cat: minutiae points. + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imap - matrix of ridge flow directions + nmap - IMAP augmented with blocks of HIGH-CURVATURE and + blocks which have no neighboring valid directions. + blk_x - x-block coord to be scanned + blk_y - y-block coord to be scanned + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + scan_x - x-pixel coord of origin of region to be scanned + scan_y - y-pixel coord of origin of region to be scanned + scan_w - width (in pixels) of region to be scanned + scan_h - height (in pixels) of region to be scanned + scan_dir - the scan orientation (horizontal or vertical) + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int scan4minutiae(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int *imap, const int *nmap, + const int blk_x, const int blk_y, const int mw, const int mh, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, const int scan_dir, + const LFSPARMS *lfsparms) +{ + int blk_i, ret; + + /* Compute block index from block coordinates. */ + blk_i = (blk_y*mw) + blk_x; + + /* Conduct primary scan for minutiae horizontally. */ + if(scan_dir == SCAN_HORIZONTAL){ + + if((ret = scan4minutiae_horizontally(minutiae, bdata, iw, ih, + imap[blk_i], nmap[blk_i], + scan_x, scan_y, scan_w, scan_h, lfsparms))){ + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + } + + /* Rescan block vertically. */ + if((ret = rescan4minutiae_vertically(minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))){ + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + } + } + + /* Otherwise, conduct primary scan for minutiae vertically. */ + else{ + if((ret = scan4minutiae_vertically(minutiae, bdata, iw, ih, + imap[blk_i], nmap[blk_i], + scan_x, scan_y, scan_w, scan_h, lfsparms))){ + /* Return resulting code. */ + return(ret); + } + + /* Rescan block horizontally. */ + if((ret = rescan4minutiae_horizontally(minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))){ + /* Return resulting code. */ + return(ret); + } + } + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: scan4minutiae_horizontally - Scans a specified region of binary image +#cat: data horizontally, detecting potential minutiae points. +#cat: Minutia detected via the horizontal scan process are +#cat: by nature vertically oriented (orthogonal to the scan). +#cat: The region actually scanned is slightly larger than that +#cat: specified. This overlap attempts to minimize the number +#cat: of minutiae missed at the region boundaries. +#cat: HOWEVER, some minutiae will still be missed! + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imapval - IMAP value associated with this image region + nmapval - NMAP value associated with this image region + scan_x - x-pixel coord of origin of region to be scanned + scan_y - y-pixel coord of origin of region to be scanned + scan_w - width (in pixels) of region to be scanned + scan_h - height (in pixels) of region to be scanned + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int scan4minutiae_horizontally(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int imapval, const int nmapval, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, + const LFSPARMS *lfsparms) +{ + int sx, sy, ex, ey, cx, cy, x2; + unsigned char *p1ptr, *p2ptr; + int possible[NFEATURES], nposs; + int ret; + + /* NOTE!!! Minutia that "straddle" region boundaries may be missed! */ + + /* If possible, overlap left and right of current scan region */ + /* by 2 pixel columns to help catch some minutia that straddle the */ + /* the scan region boundaries. */ + sx = max(0, scan_x-2); + ex = min(iw, scan_x+scan_w+2); + + /* If possible, overlap the scan region below by 1 pixel row. */ + sy = scan_y; + ey = min(ih, scan_y+scan_h+1); + + /* For now, we will not adjust for IMAP edge, as the binary image */ + /* was properly padded at its edges so as not to cause anomallies. */ + + /* Start at first row in region. */ + cy = sy; + /* While second scan row not outside the bottom of the scan region... */ + while(cy+1 < ey){ + /* Start at beginning of new scan row in region. */ + cx = sx; + /* While not at end of region's current scan row. */ + while(cx < ex){ + /* Get pixel pair from current x position in current and next */ + /* scan rows. */ + p1ptr = bdata+(cy*iw)+cx; + p2ptr = bdata+((cy+1)*iw)+cx; + /* If scan pixel pair matches first pixel pair of */ + /* 1 or more features... */ + if(match_1st_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Bump forward to next scan pixel pair. */ + cx++; + p1ptr++; + p2ptr++; + /* If not at end of region's current scan row... */ + if(cx < ex){ + /* If scan pixel pair matches second pixel pair of */ + /* 1 or more features... */ + if(match_2nd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Store current x location. */ + x2 = cx; + /* Skip repeated pixel pairs. */ + skip_repeated_horizontal_pair(&cx, ex, &p1ptr, &p2ptr, + iw, ih); + /* If not at end of region's current scan row... */ + if(cx < ex){ + /* If scan pixel pair matches third pixel pair of */ + /* a single feature... */ + if(match_3rd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Process detected minutia point. */ + if((ret = process_horizontal_scan_minutia(minutiae, + cx, cy, x2, possible[0], + bdata, iw, ih, + imapval, nmapval, lfsparms))){ + /* Return code may be: */ + /* 1. ret< 0 (implying system error) */ + /* 2. ret==IGNORE (ignore current feature) */ + if(ret < 0) + return(ret); + /* Otherwise, IGNORE and continue. */ + } + } + + /* Set up to resume scan. */ + /* Test to see if 3rd pair can slide into 2nd pair. */ + /* The values of the 2nd pair MUST be different. */ + /* If 3rd pair values are different ... */ + if(*p1ptr != *p2ptr){ + /* Set next first pair to last of repeated */ + /* 2nd pairs, ie. back up one pair. */ + cx--; + } + + /* Otherwise, 3rd pair can't be a 2nd pair, so */ + /* keep pointing to 3rd pair so that it is used */ + /* in the next first pair test. */ + + } /* Else, at end of current scan row. */ + } + + /* Otherwise, 2nd pair failed, so keep pointing to it */ + /* so that it is used in the next first pair test. */ + + } /* Else, at end of current scan row. */ + } + /* Otherwise, 1st pair failed... */ + else{ + /* Bump forward to next pixel pair. */ + cx++; + } + } /* While not at end of current scan row. */ + /* Bump forward to next scan row. */ + cy++; + } /* While not out of scan rows. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: scan4minutiae_horizontally_V2 - Scans an entire binary image +#cat: horizontally, detecting potential minutiae points. +#cat: Minutia detected via the horizontal scan process are +#cat: by nature vertically oriented (orthogonal to the scan). + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + pdirection_map - pixelized Direction Map + plow_flow_map - pixelized Low Ridge Flow Map + phigh_curve_map - pixelized High Curvature Map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int scan4minutiae_horizontally_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *pdirection_map, int *plow_flow_map, int *phigh_curve_map, + const LFSPARMS *lfsparms) +{ + int sx, sy, ex, ey, cx, cy, x2; + unsigned char *p1ptr, *p2ptr; + int possible[NFEATURES], nposs; + int ret; + + /* Set scan region to entire image. */ + sx = 0; + ex = iw; + sy = 0; + ey = ih; + + /* Start at first row in region. */ + cy = sy; + /* While second scan row not outside the bottom of the scan region... */ + while(cy+1 < ey){ + /* Start at beginning of new scan row in region. */ + cx = sx; + /* While not at end of region's current scan row. */ + while(cx < ex){ + /* Get pixel pair from current x position in current and next */ + /* scan rows. */ + p1ptr = bdata+(cy*iw)+cx; + p2ptr = bdata+((cy+1)*iw)+cx; + /* If scan pixel pair matches first pixel pair of */ + /* 1 or more features... */ + if(match_1st_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Bump forward to next scan pixel pair. */ + cx++; + p1ptr++; + p2ptr++; + /* If not at end of region's current scan row... */ + if(cx < ex){ + /* If scan pixel pair matches second pixel pair of */ + /* 1 or more features... */ + if(match_2nd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Store current x location. */ + x2 = cx; + /* Skip repeated pixel pairs. */ + skip_repeated_horizontal_pair(&cx, ex, &p1ptr, &p2ptr, + iw, ih); + /* If not at end of region's current scan row... */ + if(cx < ex){ + /* If scan pixel pair matches third pixel pair of */ + /* a single feature... */ + if(match_3rd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Process detected minutia point. */ + if((ret = process_horizontal_scan_minutia_V2(minutiae, + cx, cy, x2, possible[0], + bdata, iw, ih, pdirection_map, + plow_flow_map, phigh_curve_map, + lfsparms))){ + /* Return code may be: */ + /* 1. ret< 0 (implying system error) */ + /* 2. ret==IGNORE (ignore current feature) */ + if(ret < 0) + return(ret); + /* Otherwise, IGNORE and continue. */ + } + } + + /* Set up to resume scan. */ + /* Test to see if 3rd pair can slide into 2nd pair. */ + /* The values of the 2nd pair MUST be different. */ + /* If 3rd pair values are different ... */ + if(*p1ptr != *p2ptr){ + /* Set next first pair to last of repeated */ + /* 2nd pairs, ie. back up one pair. */ + cx--; + } + + /* Otherwise, 3rd pair can't be a 2nd pair, so */ + /* keep pointing to 3rd pair so that it is used */ + /* in the next first pair test. */ + + } /* Else, at end of current scan row. */ + } + + /* Otherwise, 2nd pair failed, so keep pointing to it */ + /* so that it is used in the next first pair test. */ + + } /* Else, at end of current scan row. */ + } + /* Otherwise, 1st pair failed... */ + else{ + /* Bump forward to next pixel pair. */ + cx++; + } + } /* While not at end of current scan row. */ + /* Bump forward to next scan row. */ + cy++; + } /* While not out of scan rows. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: scan4minutiae_vertically - Scans a specified region of binary image data +#cat: vertically, detecting potential minutiae points. +#cat: Minutia detected via the vetical scan process are +#cat: by nature horizontally oriented (orthogonal to the scan). +#cat: The region actually scanned is slightly larger than that +#cat: specified. This overlap attempts to minimize the number +#cat: of minutiae missed at the region boundaries. +#cat: HOWEVER, some minutiae will still be missed! + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imapval - IMAP value associated with this image region + nmapval - NMAP value associated with this image region + scan_x - x-pixel coord of origin of region to be scanned + scan_y - y-pixel coord of origin of region to be scanned + scan_w - width (in pixels) of region to be scanned + scan_h - height (in pixels) of region to be scanned + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int scan4minutiae_vertically(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int imapval, const int nmapval, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, + const LFSPARMS *lfsparms) +{ + int sx, sy, ex, ey, cx, cy, y2; + unsigned char *p1ptr, *p2ptr; + int possible[NFEATURES], nposs; + int ret; + + /* NOTE!!! Minutia that "straddle" region boundaries may be missed! */ + + /* If possible, overlap scan region to the right by 1 pixel column. */ + sx = scan_x; + ex = min(iw, scan_x+scan_w+1); + + /* If possible, overlap top and bottom of current scan region */ + /* by 2 pixel rows to help catch some minutia that straddle the */ + /* the scan region boundaries. */ + sy = max(0, scan_y-2); + ey = min(ih, scan_y+scan_h+2); + + /* For now, we will not adjust for IMAP edge, as the binary image */ + /* was properly padded at its edges so as not to cause anomalies. */ + + /* Start at first column in region. */ + cx = sx; + /* While second scan column not outside the right of the region ... */ + while(cx+1 < ex){ + /* Start at beginning of new scan column in region. */ + cy = sy; + /* While not at end of region's current scan column. */ + while(cy < ey){ + /* Get pixel pair from current y position in current and next */ + /* scan columns. */ + p1ptr = bdata+(cy*iw)+cx; + p2ptr = p1ptr+1; + /* If scan pixel pair matches first pixel pair of */ + /* 1 or more features... */ + if(match_1st_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Bump forward to next scan pixel pair. */ + cy++; + p1ptr+=iw; + p2ptr+=iw; + /* If not at end of region's current scan column... */ + if(cy < ey){ + /* If scan pixel pair matches second pixel pair of */ + /* 1 or more features... */ + if(match_2nd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Store current y location. */ + y2 = cy; + /* Skip repeated pixel pairs. */ + skip_repeated_vertical_pair(&cy, ey, &p1ptr, &p2ptr, + iw, ih); + /* If not at end of region's current scan column... */ + if(cy < ey){ + /* If scan pixel pair matches third pixel pair of */ + /* a single feature... */ + if(match_3rd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Process detected minutia point. */ + if((ret = process_vertical_scan_minutia(minutiae, + cx, cy, y2, possible[0], + bdata, iw, ih, + imapval, nmapval, lfsparms))){ + /* Return code may be: */ + /* 1. ret< 0 (implying system error) */ + /* 2. ret==IGNORE (ignore current feature) */ + if(ret < 0) + return(ret); + /* Otherwise, IGNORE and continue. */ + } + } + + /* Set up to resume scan. */ + /* Test to see if 3rd pair can slide into 2nd pair. */ + /* The values of the 2nd pair MUST be different. */ + /* If 3rd pair values are different ... */ + if(*p1ptr != *p2ptr){ + /* Set next first pair to last of repeated */ + /* 2nd pairs, ie. back up one pair. */ + cy--; + } + + /* Otherwise, 3rd pair can't be a 2nd pair, so */ + /* keep pointing to 3rd pair so that it is used */ + /* in the next first pair test. */ + + } /* Else, at end of current scan row. */ + } + + /* Otherwise, 2nd pair failed, so keep pointing to it */ + /* so that it is used in the next first pair test. */ + + } /* Else, at end of current scan column. */ + } + /* Otherwise, 1st pair failed... */ + else{ + /* Bump forward to next pixel pair. */ + cy++; + } + } /* While not at end of current scan column. */ + /* Bump forward to next scan column. */ + cx++; + } /* While not out of scan columns. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: scan4minutiae_vertically_V2 - Scans an entire binary image +#cat: vertically, detecting potential minutiae points. +#cat: Minutia detected via the vetical scan process are +#cat: by nature horizontally oriented (orthogonal to the scan). + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + pdirection_map - pixelized Direction Map + plow_flow_map - pixelized Low Ridge Flow Map + phigh_curve_map - pixelized High Curvature Map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int scan4minutiae_vertically_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *pdirection_map, int *plow_flow_map, int *phigh_curve_map, + const LFSPARMS *lfsparms) +{ + int sx, sy, ex, ey, cx, cy, y2; + unsigned char *p1ptr, *p2ptr; + int possible[NFEATURES], nposs; + int ret; + + /* Set scan region to entire image. */ + sx = 0; + ex = iw; + sy = 0; + ey = ih; + + /* Start at first column in region. */ + cx = sx; + /* While second scan column not outside the right of the region ... */ + while(cx+1 < ex){ + /* Start at beginning of new scan column in region. */ + cy = sy; + /* While not at end of region's current scan column. */ + while(cy < ey){ + /* Get pixel pair from current y position in current and next */ + /* scan columns. */ + p1ptr = bdata+(cy*iw)+cx; + p2ptr = p1ptr+1; + /* If scan pixel pair matches first pixel pair of */ + /* 1 or more features... */ + if(match_1st_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Bump forward to next scan pixel pair. */ + cy++; + p1ptr+=iw; + p2ptr+=iw; + /* If not at end of region's current scan column... */ + if(cy < ey){ + /* If scan pixel pair matches second pixel pair of */ + /* 1 or more features... */ + if(match_2nd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Store current y location. */ + y2 = cy; + /* Skip repeated pixel pairs. */ + skip_repeated_vertical_pair(&cy, ey, &p1ptr, &p2ptr, + iw, ih); + /* If not at end of region's current scan column... */ + if(cy < ey){ + /* If scan pixel pair matches third pixel pair of */ + /* a single feature... */ + if(match_3rd_pair(*p1ptr, *p2ptr, possible, &nposs)){ + /* Process detected minutia point. */ + if((ret = process_vertical_scan_minutia_V2(minutiae, + cx, cy, y2, possible[0], + bdata, iw, ih, pdirection_map, + plow_flow_map, phigh_curve_map, + lfsparms))){ + /* Return code may be: */ + /* 1. ret< 0 (implying system error) */ + /* 2. ret==IGNORE (ignore current feature) */ + if(ret < 0) + return(ret); + /* Otherwise, IGNORE and continue. */ + } + } + + /* Set up to resume scan. */ + /* Test to see if 3rd pair can slide into 2nd pair. */ + /* The values of the 2nd pair MUST be different. */ + /* If 3rd pair values are different ... */ + if(*p1ptr != *p2ptr){ + /* Set next first pair to last of repeated */ + /* 2nd pairs, ie. back up one pair. */ + cy--; + } + + /* Otherwise, 3rd pair can't be a 2nd pair, so */ + /* keep pointing to 3rd pair so that it is used */ + /* in the next first pair test. */ + + } /* Else, at end of current scan row. */ + } + + /* Otherwise, 2nd pair failed, so keep pointing to it */ + /* so that it is used in the next first pair test. */ + + } /* Else, at end of current scan column. */ + } + /* Otherwise, 1st pair failed... */ + else{ + /* Bump forward to next pixel pair. */ + cy++; + } + } /* While not at end of current scan column. */ + /* Bump forward to next scan column. */ + cx++; + } /* While not out of scan columns. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: rescan4minutiae_horizontally - Rescans portions of a block of binary +#cat: image data horizontally for potential minutiae. The areas +#cat: rescanned within the block are based on the current +#cat: block's neighboring blocks' IMAP and NMAP values. + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imap - matrix of ridge flow directions + nmap - IMAP augmented with blocks of HIGH-CURVATURE and + blocks which have no neighboring valid directions. + blk_x - x-block coord to be rescanned + blk_y - y-block coord to be rescanned + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + scan_x - x-pixel coord of origin of region to be rescanned + scan_y - y-pixel coord of origin of region to be rescanned + scan_w - width (in pixels) of region to be rescanned + scan_h - height (in pixels) of region to be rescanned + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int rescan4minutiae_horizontally(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int *imap, const int *nmap, + const int blk_x, const int blk_y, + const int mw, const int mh, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, + const LFSPARMS *lfsparms) +{ + int blk_i, ret; + + /* Compute block index from block coordinates. */ + blk_i = (blk_y*mw)+blk_x; + + /* If high-curve block... */ + if(nmap[blk_i] == HIGH_CURVATURE){ + /* Rescan entire block in orthogonal direction. */ + if((ret = scan4minutiae_horizontally(minutiae, bdata, iw, ih, + imap[blk_i], nmap[blk_i], + scan_x, scan_y, scan_w, scan_h, lfsparms))) + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + } + /* Otherwise, block is low-curvature. */ + else{ + /* 1. Rescan horizontally to the North. */ + if((ret = rescan_partial_horizontally(NORTH, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + + /* 2. Rescan horizontally to the East. */ + if((ret = rescan_partial_horizontally(EAST, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + return(ret); + + /* 3. Rescan horizontally to the South. */ + if((ret = rescan_partial_horizontally(SOUTH, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + return(ret); + + /* 4. Rescan horizontally to the West. */ + if((ret = rescan_partial_horizontally(WEST, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + return(ret); + } /* End low-curvature rescan. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: rescan4minutiae_vertically - Rescans portions of a block of binary +#cat: image data vertically for potential minutiae. The areas +#cat: rescanned within the block are based on the current +#cat: block's neighboring blocks' IMAP and NMAP values. + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imap - matrix of ridge flow directions + nmap - IMAP augmented with blocks of HIGH-CURVATURE and + blocks which have no neighboring valid directions. + blk_x - x-block coord to be rescanned + blk_y - y-block coord to be rescanned + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + scan_x - x-pixel coord of origin of region to be rescanned + scan_y - y-pixel coord of origin of region to be rescanned + scan_w - width (in pixels) of region to be rescanned + scan_h - height (in pixels) of region to be rescanned + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int rescan4minutiae_vertically(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int *imap, const int *nmap, + const int blk_x, const int blk_y, + const int mw, const int mh, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, + const LFSPARMS *lfsparms) +{ + int blk_i, ret; + + /* Compute block index from block coordinates. */ + blk_i = (blk_y*mw)+blk_x; + + /* If high-curve block... */ + if(nmap[blk_i] == HIGH_CURVATURE){ + /* Rescan entire block in orthogonal direction. */ + if((ret = scan4minutiae_vertically(minutiae, bdata, iw, ih, + imap[blk_i], nmap[blk_i], + scan_x, scan_y, scan_w, scan_h, lfsparms))) + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + } + /* Otherwise, block is low-curvature. */ + else{ + /* 1. Rescan vertically to the North. */ + if((ret = rescan_partial_vertically(NORTH, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + + /* 2. Rescan vertically to the East. */ + if((ret = rescan_partial_vertically(EAST, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + return(ret); + + /* 3. Rescan vertically to the South. */ + if((ret = rescan_partial_vertically(SOUTH, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + return(ret); + + /* 4. Rescan vertically to the West. */ + if((ret = rescan_partial_vertically(WEST, minutiae, bdata, iw, ih, + imap, nmap, blk_x, blk_y, mw, mh, + scan_x, scan_y, scan_w, scan_h, lfsparms))) + return(ret); + } /* End low-curvature rescan. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: rescan_partial_horizontally - Rescans a portion of a block of binary +#cat: image data horizontally based on the IMAP and NMAP values +#cat: of a specified neighboring block. + + Input: + nbr_dir - specifies which block neighbor {NORTH, SOUTH, EAST, WEST} + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imap - matrix of ridge flow directions + nmap - IMAP augmented with blocks of HIGH-CURVATURE and + blocks which have no neighboring valid directions. + blk_x - x-block coord to be rescanned + blk_y - y-block coord to be rescanned + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + scan_x - x-pixel coord of origin of image region + scan_y - y-pixel coord of origin of image region + scan_w - width (in pixels) of image region + scan_h - height (in pixels) of image region + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int rescan_partial_horizontally(const int nbr_dir, MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int *imap, const int *nmap, + const int blk_x, const int blk_y, + const int mw, const int mh, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, + const LFSPARMS *lfsparms) +{ + int nblk_i, blk_i; + int rescan_dir; + int rescan_x, rescan_y, rescan_w, rescan_h; + int ret; + + /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ + ret = get_nbr_block_index(&nblk_i, nbr_dir, blk_x, blk_y, mw, mh); + /* Will return: */ + /* 1. Neighbor index found == FOUND */ + /* 2. Neighbor not found == NOT_FOUND */ + /* 3. System error < 0 */ + + /* If system error ... */ + if(ret < 0) + /* Return the error code. */ + return(ret); + + /* If neighbor not found ... */ + if(ret == NOT_FOUND) + /* Nothing to do, so return normally. */ + return(0); + + /* Otherwise, neighboring block found ... */ + + /* If neighbor block is VALID... */ + if(imap[nblk_i] != INVALID_DIR){ + + /* Compute block index from current (not neighbor) block coordinates. */ + blk_i = (blk_y*mw)+blk_x; + + /* Select feature scan direction based on neighbor IMAP. */ + rescan_dir = choose_scan_direction(imap[nblk_i], + lfsparms->num_directions); + /* If new scan direction is HORIZONTAL... */ + if(rescan_dir == SCAN_HORIZONTAL){ + /* Adjust scan_x, scan_y, scan_w, scan_h for rescan. */ + if((ret = adjust_horizontal_rescan(nbr_dir, &rescan_x, &rescan_y, + &rescan_w, &rescan_h, + scan_x, scan_y, scan_w, scan_h, lfsparms->blocksize))) + /* Return system error code. */ + return(ret); + /* Rescan specified region in block vertically. */ + /* Pass IMAP direction for the block, NOT its neighbor. */ + if((ret = scan4minutiae_horizontally(minutiae, bdata, iw, ih, + imap[blk_i], nmap[blk_i], + rescan_x, rescan_y, rescan_w, rescan_h, lfsparms))) + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + } /* Otherwise, block has already been scanned vertically. */ + } /* Otherwise, neighbor has INVALID IMAP, so ignore rescan. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: rescan_partial_vertically - Rescans a portion of a block of binary +#cat: image data vertically based on the IMAP and NMAP values +#cat: of a specified neighboring block. + + Input: + nbr_dir - specifies which block neighbor {NORTH, SOUTH, EAST, WEST} + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imap - matrix of ridge flow directions + nmap - IMAP augmented with blocks of HIGH-CURVATURE and + blocks which have no neighboring valid directions. + blk_x - x-block coord to be rescanned + blk_y - y-block coord to be rescanned + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + scan_x - x-pixel coord of origin of image region + scan_y - y-pixel coord of origin of image region + scan_w - width (in pixels) of image region + scan_h - height (in pixels) of image region + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int rescan_partial_vertically(const int nbr_dir, MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const int *imap, const int *nmap, + const int blk_x, const int blk_y, + const int mw, const int mh, + const int scan_x, const int scan_y, + const int scan_w, const int scan_h, + const LFSPARMS *lfsparms) +{ + int nblk_i, blk_i; + int rescan_dir; + int rescan_x, rescan_y, rescan_w, rescan_h; + int ret; + + /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ + ret = get_nbr_block_index(&nblk_i, nbr_dir, blk_x, blk_y, mw, mh); + /* Will return: */ + /* 1. Neighbor index found == FOUND */ + /* 2. Neighbor not found == NOT_FOUND */ + /* 3. System error < 0 */ + + /* If system error ... */ + if(ret < 0) + /* Return the error code. */ + return(ret); + + /* If neighbor not found ... */ + if(ret == NOT_FOUND) + /* Nothing to do, so return normally. */ + return(0); + + /* Otherwise, neighboring block found ... */ + + /* If neighbor block is VALID... */ + if(imap[nblk_i] != INVALID_DIR){ + + /* Compute block index from current (not neighbor) block coordinates. */ + blk_i = (blk_y*mw)+blk_x; + + /* Select feature scan direction based on neighbor IMAP. */ + rescan_dir = choose_scan_direction(imap[nblk_i], + lfsparms->num_directions); + /* If new scan direction is VERTICAL... */ + if(rescan_dir == SCAN_VERTICAL){ + /* Adjust scan_x, scan_y, scan_w, scan_h for rescan. */ + if((ret = adjust_vertical_rescan(nbr_dir, &rescan_x, &rescan_y, + &rescan_w, &rescan_h, + scan_x, scan_y, scan_w, scan_h, lfsparms->blocksize))) + /* Return system error code. */ + return(ret); + /* Rescan specified region in block vertically. */ + /* Pass IMAP direction for the block, NOT its neighbor. */ + if((ret = scan4minutiae_vertically(minutiae, bdata, iw, ih, + imap[blk_i], nmap[blk_i], + rescan_x, rescan_y, rescan_w, rescan_h, lfsparms))) + /* Return code may be: */ + /* 1. ret<0 (implying system error) */ + return(ret); + } /* Otherwise, block has already been scanned horizontally. */ + } /* Otherwise, neighbor has INVALID IMAP, so ignore rescan. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: get_nbr_block_index - Determines the block index (if one exists) +#cat: for a specified neighbor of a block in the image. + + Input: + nbr_dir - specifies which block neighbor {NORTH, SOUTH, EAST, WEST} + blk_x - x-block coord to find neighbor of + blk_y - y-block coord to find neighbor of + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + Output: + oblk_i - points to neighbor's block index + Return Code: + NOT_FOUND - neighbor index does not exist + FOUND - neighbor index exists and returned + Negative - system error +**************************************************************************/ +int get_nbr_block_index(int *oblk_i, const int nbr_dir, + const int blk_x, const int blk_y, const int mw, const int mh) +{ + int nx, ny, ni; + + switch(nbr_dir){ + case NORTH: + /* If neighbor doesn't exist above... */ + if((ny = blk_y-1) < 0) + /* Done, so return normally. */ + return(NOT_FOUND); + /* Get neighbor's block index. */ + ni = (ny*mw)+blk_x; + break; + case EAST: + /* If neighbor doesn't exist to the right... */ + if((nx = blk_x+1) >= mw) + /* Done, so return normally. */ + return(NOT_FOUND); + /* Get neighbor's block index. */ + ni = (blk_y*mw)+nx; + break; + case SOUTH: + /* If neighbor doesn't exist below... */ + if((ny = blk_y+1) >= mh) + /* Return normally. */ + return(NOT_FOUND); + /* Get neighbor's block index. */ + ni = (ny*mw)+blk_x; + break; + case WEST: + /* If neighbor doesn't exist to the left... */ + if((nx = blk_x-1) < 0) + /* Return normally. */ + return(NOT_FOUND); + /* Get neighbor's block index. */ + ni = (blk_y*mw)+nx; + break; + default: + fprintf(stderr, + "ERROR : get_nbr_block_index : illegal neighbor direction\n"); + return(-200); + } + + /* Assign output pointer. */ + *oblk_i = ni; + + /* Return neighbor FOUND. */ + return(FOUND); +} + +/************************************************************************* +************************************************************************** +#cat: adjust_horizontal_rescan - Determines the portion of an image block to +#cat: be rescanned horizontally based on a specified neighbor. + + Input: + nbr_dir - specifies which block neighbor {NORTH, SOUTH, EAST, WEST} + scan_x - x-pixel coord of origin of image region + scan_y - y-pixel coord of origin of image region + scan_w - width (in pixels) of image region + scan_h - height (in pixels) of image region + blocksize - dimension of image blocks (in pixels) + Output: + rescan_x - x-pixel coord of origin of region to be rescanned + rescan_y - y-pixel coord of origin of region to be rescanned + rescan_w - width (in pixels) of region to be rescanned + rescan_h - height (in pixels) of region to be rescanned + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int adjust_horizontal_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, + int *rescan_w, int *rescan_h, const int scan_x, const int scan_y, + const int scan_w, const int scan_h, const int blocksize) +{ + int half_blocksize, qtr_blocksize; + + /* Compute half of blocksize. */ + half_blocksize = blocksize>>1; + /* Compute quarter of blocksize. */ + qtr_blocksize = blocksize>>2; + + /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ + switch(nbr_dir){ + case NORTH: + /* + ************************* + * RESCAN NORTH * + * AREA * + ************************* + | | + | | + | | + | | + | | + | | + ------------------------- + */ + /* Rescan origin stays the same. */ + *rescan_x = scan_x; + *rescan_y = scan_y; + /* Rescan width stays the same. */ + *rescan_w = scan_w; + /* Rescan height is reduced to "qtr_blocksize" */ + /* if scan_h is larger. */ + *rescan_h = min(qtr_blocksize, scan_h); + break; + case EAST: + /* + ------------************* + | * * + | * * + | * E R * + | * A E * + | * S S * + | * T C * + | * A * + | * N * + | * * + | * * + ------------************* + */ + /* Rescan x-orign is set to half_blocksize from right edge of */ + /* block if scan width is larger. */ + *rescan_x = max(scan_x+scan_w-half_blocksize, scan_x); + /* Rescan y-origin stays the same. */ + *rescan_y = scan_y; + /* Rescan width is reduced to "half_blocksize" */ + /* if scan width is larger. */ + *rescan_w = min(half_blocksize, scan_w); + /* Rescan height stays the same. */ + *rescan_h = scan_h; + break; + case SOUTH: + /* + ------------------------- + | | + | | + | | + | | + | | + | | + ************************* + * RESCAN SOUTH * + * AREA * + ************************* + */ + /* Rescan x-origin stays the same. */ + *rescan_x = scan_x; + /* Rescan y-orign is set to qtr_blocksize from bottom edge of */ + /* block if scan height is larger. */ + *rescan_y = max(scan_y+scan_h-qtr_blocksize, scan_y); + /* Rescan width stays the same. */ + *rescan_w = scan_w; + /* Rescan height is reduced to "qtr_blocksize" */ + /* if scan height is larger. */ + *rescan_h = min(qtr_blocksize, scan_h); + break; + case WEST: + /* + *************------------ + * * | + * * | + * W R * | + * E E * | + * S S * | + * T C * | + * A * | + * N * | + * * | + * * | + *************------------ + */ + /* Rescan origin stays the same. */ + *rescan_x = scan_x; + *rescan_y = scan_y; + /* Rescan width is reduced to "half_blocksize" */ + /* if scan width is larger. */ + *rescan_w = min(half_blocksize, scan_w); + /* Rescan height stays the same. */ + *rescan_h = scan_h; + break; + default: + fprintf(stderr, + "ERROR : adjust_horizontal_rescan : illegal neighbor direction\n"); + return(-210); + } + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: adjust_vertical_rescan - Determines the portion of an image block to +#cat: be rescanned vertically based on a specified neighbor. + + Input: + nbr_dir - specifies which block neighbor {NORTH, SOUTH, EAST, WEST} + scan_x - x-pixel coord of origin of image region + scan_y - y-pixel coord of origin of image region + scan_w - width (in pixels) of image region + scan_h - height (in pixels) of image region + blocksize - dimension of image blocks (in pixels) + Output: + rescan_x - x-pixel coord of origin of region to be rescanned + rescan_y - y-pixel coord of origin of region to be rescanned + rescan_w - width (in pixels) of region to be rescanned + rescan_h - height (in pixels) of region to be rescanned + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int adjust_vertical_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, + int *rescan_w, int *rescan_h, const int scan_x, const int scan_y, + const int scan_w, const int scan_h, const int blocksize) +{ + int half_blocksize, qtr_blocksize; + + /* Compute half of blocksize. */ + half_blocksize = blocksize>>1; + /* Compute quarter of blocksize. */ + qtr_blocksize = blocksize>>2; + + /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ + switch(nbr_dir){ + case NORTH: + /* + ************************* + * * + * RESCAN NORTH * + * AREA * + * * + ************************* + | | + | | + | | + | | + | | + ------------------------- + */ + /* Rescan origin stays the same. */ + *rescan_x = scan_x; + *rescan_y = scan_y; + /* Rescan width stays the same. */ + *rescan_w = scan_w; + /* Rescan height is reduced to "half_blocksize" */ + /* if scan_h is larger. */ + *rescan_h = min(half_blocksize, scan_h); + break; + case EAST: + /* + ------------------******* + | * * + | * * + | * E R * + | * A E * + | * S S * + | * T C * + | * A * + | * N * + | * * + | * * + ------------------******* + */ + /* Rescan x-orign is set to qtr_blocksize from right edge of */ + /* block if scan width is larger. */ + *rescan_x = max(scan_x+scan_w-qtr_blocksize, scan_x); + /* Rescan y-origin stays the same. */ + *rescan_y = scan_y; + /* Rescan width is reduced to "qtr_blocksize" */ + /* if scan width is larger. */ + *rescan_w = min(qtr_blocksize, scan_w); + /* Rescan height stays the same. */ + *rescan_h = scan_h; + break; + case SOUTH: + /* + ------------------------- + | | + | | + | | + | | + | | + ************************* + * * + * RESCAN SOUTH * + * AREA * + * * + ************************* + */ + /* Rescan x-origin stays the same. */ + *rescan_x = scan_x; + /* Rescan y-orign is set to half_blocksize from bottom edge of */ + /* block if scan height is larger. */ + *rescan_y = max(scan_y+scan_h-half_blocksize, scan_y); + /* Rescan width stays the same. */ + *rescan_w = scan_w; + /* Rescan height is reduced to "half_blocksize" */ + /* if scan height is larger. */ + *rescan_h = min(half_blocksize, scan_h); + break; + case WEST: + /* + *******------------------ + * * | + * * | + * W R * | + * E E * | + * S S * | + * T C * | + * A * | + * N * | + * * | + * * | + *******------------------ + */ + /* Rescan origin stays the same. */ + *rescan_x = scan_x; + *rescan_y = scan_y; + /* Rescan width is reduced to "qtr_blocksize" */ + /* if scan width is larger. */ + *rescan_w = min(qtr_blocksize, scan_w); + /* Rescan height stays the same. */ + *rescan_h = scan_h; + break; + default: + fprintf(stderr, + "ERROR : adjust_vertical_rescan : illegal neighbor direction\n"); + return(-220); + } + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: process_horizontal_scan_minutia - Takes a minutia point that was +#cat: detected via the horizontal scan process and +#cat: adjusts its location (if necessary), determines its +#cat: direction, and (if it is not already in the minutiae +#cat: list) adds it to the list. These minutia are by nature +#cat: vertical in orientation (orthogonal to the scan). + + Input: + cx - x-pixel coord where 3rd pattern pair of mintuia was detected + cy - y-pixel coord where 3rd pattern pair of mintuia was detected + y2 - y-pixel coord where 2nd pattern pair of mintuia was detected + feature_id - type of minutia (ex. index into feature_patterns[] list) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imapval - IMAP value associated with this image region + nmapval - NMAP value associated with this image region + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + IGNORE - minutia is to be ignored + Negative - system error +**************************************************************************/ +int process_horizontal_scan_minutia(MINUTIAE *minutiae, + const int cx, const int cy, + const int x2, const int feature_id, + unsigned char *bdata, const int iw, const int ih, + const int imapval, const int nmapval, + const LFSPARMS *lfsparms) +{ + MINUTIA *minutia; + int x_loc, y_loc; + int x_edge, y_edge; + int idir, ret; + + /* Set x location of minutia point to be half way between */ + /* first position of second feature pair and position of */ + /* third feature pair. */ + x_loc = (cx + x2)>>1; + + /* Set same x location to neighboring edge pixel. */ + x_edge = x_loc; + + /* Feature location should always point to either ending */ + /* of ridge or (for bifurcations) ending of valley. */ + /* So, if detected feature is APPEARING... */ + if(feature_patterns[feature_id].appearing){ + /* Set y location to second scan row. */ + y_loc = cy+1; + /* Set y location of neighboring edge pixel to the first scan row. */ + y_edge = cy; + } + /* Otherwise, feature is DISAPPEARING... */ + else{ + /* Set y location to first scan row. */ + y_loc = cy; + /* Set y location of neighboring edge pixel to the second scan row. */ + y_edge = cy+1; + } + + /* If current minutia is in a high-curvature block... */ + if(nmapval == HIGH_CURVATURE){ + /* Adjust location and direction locally. */ + if((ret = adjust_high_curvature_minutia(&idir, &x_loc, &y_loc, + &x_edge, &y_edge, x_loc, y_loc, x_edge, y_edge, + bdata, iw, ih, minutiae, lfsparms))){ + /* Could be a system error or IGNORE minutia. */ + return(ret); + } + /* Otherwise, we have our high-curvature minutia attributes. */ + } + /* Otherwise, minutia is in fairly low-curvature block... */ + else{ + /* Get minutia direction based on current IMAP value. */ + idir = get_low_curvature_direction(SCAN_HORIZONTAL, + feature_patterns[feature_id].appearing, + imapval, lfsparms->num_directions); + } + + /* Create a minutia object based on derived attributes. */ + if((ret = create_minutia(&minutia, x_loc, y_loc, x_edge, y_edge, idir, + DEFAULT_RELIABILITY, + feature_patterns[feature_id].type, + feature_patterns[feature_id].appearing, feature_id))) + /* Return system error. */ + return(ret); + + /* Update the minutiae list with potential new minutia. */ + ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* Otherwise, return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: process_horizontal_scan_minutia_V2 - Takes a minutia point that was +#cat: detected via the horizontal scan process and +#cat: adjusts its location (if necessary), determines its +#cat: direction, and (if it is not already in the minutiae +#cat: list) adds it to the list. These minutia are by nature +#cat: vertical in orientation (orthogonal to the scan). + + Input: + cx - x-pixel coord where 3rd pattern pair of mintuia was detected + cy - y-pixel coord where 3rd pattern pair of mintuia was detected + y2 - y-pixel coord where 2nd pattern pair of mintuia was detected + feature_id - type of minutia (ex. index into feature_patterns[] list) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + pdirection_map - pixelized Direction Map + plow_flow_map - pixelized Low Ridge Flow Map + phigh_curve_map - pixelized High Curvature Map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + IGNORE - minutia is to be ignored + Negative - system error +**************************************************************************/ +int process_horizontal_scan_minutia_V2(MINUTIAE *minutiae, + const int cx, const int cy, + const int x2, const int feature_id, + unsigned char *bdata, const int iw, const int ih, + int *pdirection_map, int *plow_flow_map, int *phigh_curve_map, + const LFSPARMS *lfsparms) +{ + MINUTIA *minutia; + int x_loc, y_loc; + int x_edge, y_edge; + int idir, ret; + int dmapval, fmapval, cmapval; + double reliability; + + /* Set x location of minutia point to be half way between */ + /* first position of second feature pair and position of */ + /* third feature pair. */ + x_loc = (cx + x2)>>1; + + /* Set same x location to neighboring edge pixel. */ + x_edge = x_loc; + + /* Feature location should always point to either ending */ + /* of ridge or (for bifurcations) ending of valley. */ + /* So, if detected feature is APPEARING... */ + if(feature_patterns[feature_id].appearing){ + /* Set y location to second scan row. */ + y_loc = cy+1; + /* Set y location of neighboring edge pixel to the first scan row. */ + y_edge = cy; + } + /* Otherwise, feature is DISAPPEARING... */ + else{ + /* Set y location to first scan row. */ + y_loc = cy; + /* Set y location of neighboring edge pixel to the second scan row. */ + y_edge = cy+1; + } + + dmapval = *(pdirection_map+(y_loc*iw)+x_loc); + fmapval = *(plow_flow_map+(y_loc*iw)+x_loc); + cmapval = *(phigh_curve_map+(y_loc*iw)+x_loc); + + /* If the minutia point is in a block with INVALID direction ... */ + if(dmapval == INVALID_DIR) + /* Then, IGNORE the point. */ + return(IGNORE); + + /* If current minutia is in a HIGH CURVATURE block ... */ + if(cmapval){ + /* Adjust location and direction locally. */ + if((ret = adjust_high_curvature_minutia_V2(&idir, &x_loc, &y_loc, + &x_edge, &y_edge, x_loc, y_loc, x_edge, y_edge, + bdata, iw, ih, plow_flow_map, minutiae, lfsparms))){ + /* Could be a system error or IGNORE minutia. */ + return(ret); + } + /* Otherwise, we have our high-curvature minutia attributes. */ + } + /* Otherwise, minutia is in fairly low-curvature block... */ + else{ + /* Get minutia direction based on current block's direction. */ + idir = get_low_curvature_direction(SCAN_HORIZONTAL, + feature_patterns[feature_id].appearing, dmapval, + lfsparms->num_directions); + } + + /* If current minutia is in a LOW RIDGE FLOW block ... */ + if(fmapval) + reliability = MEDIUM_RELIABILITY; + else + /* Otherwise, minutia is in a block with reliable direction and */ + /* binarization. */ + reliability = HIGH_RELIABILITY; + + /* Create a minutia object based on derived attributes. */ + if((ret = create_minutia(&minutia, x_loc, y_loc, x_edge, y_edge, idir, + reliability, + feature_patterns[feature_id].type, + feature_patterns[feature_id].appearing, feature_id))) + /* Return system error. */ + return(ret); + + /* Update the minutiae list with potential new minutia. */ + ret = update_minutiae_V2(minutiae, minutia, SCAN_HORIZONTAL, + dmapval, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* Otherwise, return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: process_vertical_scan_minutia - Takes a minutia point that was +#cat: detected in via the vertical scan process and +#cat: adjusts its location (if necessary), determines its +#cat: direction, and (if it is not already in the minutiae +#cat: list) adds it to the list. These minutia are by nature +#cat: horizontal in orientation (orthogonal to the scan). + + Input: + cx - x-pixel coord where 3rd pattern pair of mintuia was detected + cy - y-pixel coord where 3rd pattern pair of mintuia was detected + x2 - x-pixel coord where 2nd pattern pair of mintuia was detected + feature_id - type of minutia (ex. index into feature_patterns[] list) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imapval - IMAP value associated with this image region + nmapval - NMAP value associated with this image region + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + IGNORE - minutia is to be ignored + Negative - system error +**************************************************************************/ +int process_vertical_scan_minutia(MINUTIAE *minutiae, + const int cx, const int cy, + const int y2, const int feature_id, + unsigned char *bdata, const int iw, const int ih, + const int imapval, const int nmapval, + const LFSPARMS *lfsparms) +{ + MINUTIA *minutia; + int x_loc, y_loc; + int x_edge, y_edge; + int idir, ret; + + /* Feature location should always point to either ending */ + /* of ridge or (for bifurcations) ending of valley. */ + /* So, if detected feature is APPEARING... */ + if(feature_patterns[feature_id].appearing){ + /* Set x location to second scan column. */ + x_loc = cx+1; + /* Set x location of neighboring edge pixel to the first scan column. */ + x_edge = cx; + } + /* Otherwise, feature is DISAPPEARING... */ + else{ + /* Set x location to first scan column. */ + x_loc = cx; + /* Set x location of neighboring edge pixel to the second scan column. */ + x_edge = cx+1; + } + + /* Set y location of minutia point to be half way between */ + /* first position of second feature pair and position of */ + /* third feature pair. */ + y_loc = (cy + y2)>>1; + /* Set same y location to neighboring edge pixel. */ + y_edge = y_loc; + + /* If current minutia is in a high-curvature block... */ + if(nmapval == HIGH_CURVATURE){ + /* Adjust location and direction locally. */ + if((ret = adjust_high_curvature_minutia(&idir, &x_loc, &y_loc, + &x_edge, &y_edge, x_loc, y_loc, x_edge, y_edge, + bdata, iw, ih, minutiae, lfsparms))){ + /* Could be a system error or IGNORE minutia. */ + return(ret); + } + /* Otherwise, we have our high-curvature minutia attributes. */ + } + /* Otherwise, minutia is in fairly low-curvature block... */ + else{ + /* Get minutia direction based on current IMAP value. */ + idir = get_low_curvature_direction(SCAN_VERTICAL, + feature_patterns[feature_id].appearing, + imapval, lfsparms->num_directions); + } + + /* Create a minutia object based on derived attributes. */ + if((ret = create_minutia(&minutia, x_loc, y_loc, x_edge, y_edge, idir, + DEFAULT_RELIABILITY, + feature_patterns[feature_id].type, + feature_patterns[feature_id].appearing, feature_id))) + /* Return system error. */ + return(ret); + + /* Update the minutiae list with potential new minutia. */ + ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* Otherwise, return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: process_vertical_scan_minutia_V2 - Takes a minutia point that was +#cat: detected in via the vertical scan process and +#cat: adjusts its location (if necessary), determines its +#cat: direction, and (if it is not already in the minutiae +#cat: list) adds it to the list. These minutia are by nature +#cat: horizontal in orientation (orthogonal to the scan). + + Input: + cx - x-pixel coord where 3rd pattern pair of mintuia was detected + cy - y-pixel coord where 3rd pattern pair of mintuia was detected + x2 - x-pixel coord where 2nd pattern pair of mintuia was detected + feature_id - type of minutia (ex. index into feature_patterns[] list) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + pdirection_map - pixelized Direction Map + plow_flow_map - pixelized Low Ridge Flow Map + phigh_curve_map - pixelized High Curvature Map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + IGNORE - minutia is to be ignored + Negative - system error +**************************************************************************/ +int process_vertical_scan_minutia_V2(MINUTIAE *minutiae, + const int cx, const int cy, + const int y2, const int feature_id, + unsigned char *bdata, const int iw, const int ih, + int *pdirection_map, int *plow_flow_map, int *phigh_curve_map, + const LFSPARMS *lfsparms) +{ + MINUTIA *minutia; + int x_loc, y_loc; + int x_edge, y_edge; + int idir, ret; + int dmapval, fmapval, cmapval; + double reliability; + + /* Feature location should always point to either ending */ + /* of ridge or (for bifurcations) ending of valley. */ + /* So, if detected feature is APPEARING... */ + if(feature_patterns[feature_id].appearing){ + /* Set x location to second scan column. */ + x_loc = cx+1; + /* Set x location of neighboring edge pixel to the first scan column. */ + x_edge = cx; + } + /* Otherwise, feature is DISAPPEARING... */ + else{ + /* Set x location to first scan column. */ + x_loc = cx; + /* Set x location of neighboring edge pixel to the second scan column. */ + x_edge = cx+1; + } + + /* Set y location of minutia point to be half way between */ + /* first position of second feature pair and position of */ + /* third feature pair. */ + y_loc = (cy + y2)>>1; + /* Set same y location to neighboring edge pixel. */ + y_edge = y_loc; + + dmapval = *(pdirection_map+(y_loc*iw)+x_loc); + fmapval = *(plow_flow_map+(y_loc*iw)+x_loc); + cmapval = *(phigh_curve_map+(y_loc*iw)+x_loc); + + /* If the minutia point is in a block with INVALID direction ... */ + if(dmapval == INVALID_DIR) + /* Then, IGNORE the point. */ + return(IGNORE); + + /* If current minutia is in a HIGH CURVATURE block... */ + if(cmapval){ + /* Adjust location and direction locally. */ + if((ret = adjust_high_curvature_minutia_V2(&idir, &x_loc, &y_loc, + &x_edge, &y_edge, x_loc, y_loc, x_edge, y_edge, + bdata, iw, ih, plow_flow_map, minutiae, lfsparms))){ + /* Could be a system error or IGNORE minutia. */ + return(ret); + } + /* Otherwise, we have our high-curvature minutia attributes. */ + } + /* Otherwise, minutia is in fairly low-curvature block... */ + else{ + /* Get minutia direction based on current block's direction. */ + idir = get_low_curvature_direction(SCAN_VERTICAL, + feature_patterns[feature_id].appearing, dmapval, + lfsparms->num_directions); + } + + /* If current minutia is in a LOW RIDGE FLOW block ... */ + if(fmapval) + reliability = MEDIUM_RELIABILITY; + else + /* Otherwise, minutia is in a block with reliable direction and */ + /* binarization. */ + reliability = HIGH_RELIABILITY; + + /* Create a minutia object based on derived attributes. */ + if((ret = create_minutia(&minutia, x_loc, y_loc, x_edge, y_edge, idir, + reliability, + feature_patterns[feature_id].type, + feature_patterns[feature_id].appearing, feature_id))) + /* Return system error. */ + return(ret); + + /* Update the minutiae list with potential new minutia. */ + ret = update_minutiae_V2(minutiae, minutia, SCAN_VERTICAL, + dmapval, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* Otherwise, return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: adjust_high_curvature_minutia - Takes an initial minutia point detected +#cat: in a high-curvature area and adjusts its location and +#cat: direction. First, it walks and extracts the contour +#cat: of the detected feature looking for and processing any loop +#cat: discovered along the way. Once the contour is extracted, +#cat: the point of highest-curvature is determined and used to +#cat: adjust the location of the minutia point. The angle of +#cat: the line perpendicular to the tangent on the high-curvature +#cat: contour at the minutia point is used as the mintutia's +#cat: direction. + + Input: + x_loc - starting x-pixel coord of feature (interior to feature) + y_loc - starting y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + oidir - direction of adjusted minutia point + ox_loc - adjusted x-pixel coord of feature + oy_loc - adjusted y-pixel coord of feature + ox_edge - adjusted x-pixel coord of corresponding edge pixel + oy_edge - adjusted y-pixel coord of corresponding edge pixel + minutiae - points to a list of detected minutia structures + Return Code: + Zero - minutia point processed successfully + IGNORE - minutia point is to be ignored + Negative - system error +**************************************************************************/ +int adjust_high_curvature_minutia(int *oidir, int *ox_loc, int *oy_loc, + int *ox_edge, int *oy_edge, + const int x_loc, const int y_loc, + const int x_edge, const int y_edge, + unsigned char *bdata, const int iw, const int ih, + MINUTIAE *minutiae, const LFSPARMS *lfsparms) +{ + int ret; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int min_i; + double min_theta; + int feature_pix; + int mid_x, mid_y, mid_pix; + int idir; + int half_contour, angle_edge; + + /* Set variable from parameter structure. */ + half_contour = lfsparms->high_curve_half_contour; + + /* Set edge length for computing contour's angle of curvature */ + /* to one quarter of desired pixel length of entire contour. */ + /* Ex. If half_contour==14, then contour length==29=(2X14)+1 */ + /* and angle_edge==7=(14/2). */ + angle_edge = half_contour>>1; + + /* Get the pixel value of current feature. */ + feature_pix = *(bdata + (y_loc * iw) + x_loc); + + /* Extract feature's contour. */ + if((ret = get_high_curvature_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, half_contour, + x_loc, y_loc, x_edge, y_edge, bdata, iw, ih))){ + /* Returns with: */ + /* 1. Successful or empty contour == 0 */ + /* If contour is empty, then contour lists are not allocated. */ + /* 2. Contour forms loop == LOOP_FOUND */ + /* 3. Sysetm error < 0 */ + + /* If the contour forms a loop... */ + if(ret == LOOP_FOUND){ + + /* If the order of the contour is clockwise, then the loops's */ + /* contour pixels are outside the corresponding edge pixels. We */ + /* definitely do NOT want to fill based on the feature pixel in */ + /* this case, because it is OUTSIDE the loop. For now we will */ + /* ignore the loop and the minutia that triggered its tracing. */ + /* It is likely that other minutia on the loop will be */ + /* detected that create a contour on the "inside" of the loop. */ + /* There is another issue here that could be addressed ... */ + /* It seems that many/multiple minutia are often detected within */ + /* the same loop, which currently requires retracing the loop, */ + /* locating minutia on opposite ends of the major axis of the */ + /* loop, and then determining that the minutia have already been */ + /* entered into the minutiae list upon processing the very first */ + /* minutia detected in the loop. There is a lot of redundant */ + /* work being done here! */ + /* Is_loop_clockwise takes a default value to be returned if the */ + /* routine is unable to determine the direction of the contour. */ + /* In this case, we want to IGNORE the loop if we can't tell its */ + /* direction so that we do not inappropriately fill the loop, so */ + /* we are passing the default value TRUE. */ + if((ret = is_loop_clockwise(contour_x, contour_y, ncontour, TRUE))){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* If we had a system error... */ + if(ret < 0) + /* Return the error code. */ + return(ret); + /* Otherwise, loop is clockwise, so return IGNORE. */ + return(IGNORE); + } + + /* Otherwise, process the clockwise-ordered contour of the loop */ + /* as it may contain minutia. If no minutia found, then it is */ + /* filled in. */ + ret = process_loop(minutiae, contour_x, contour_y, + contour_ex, contour_ey, ncontour, + bdata, iw, ih, lfsparms); + /* Returns with: */ + /* 1. Successful processing of loop == 0 */ + /* 2. System error < 0 */ + + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /* If loop processed successfully ... */ + if(ret == 0) + /* Then either a minutia pair was extracted or the loop was */ + /* filled. Either way we want to IGNORE the minutia that */ + /* started the whole loop processing in the beginning. */ + return(IGNORE); + + /* Otherwise, there was a system error. */ + /* Return the resulting code. */ + return(ret); + } + + /* Otherwise not a loop, so get_high_curvature_contour incurred */ + /* a system error. Return the error code. */ + return(ret); + } + + /* If contour is empty ... then contour lists were not allocated, so */ + /* simply return IGNORE. The contour comes back empty when there */ + /* were not a sufficient number of points found on the contour. */ + if(ncontour == 0) + return(IGNORE); + + /* Otherwise, there are contour points to process. */ + + /* Given the contour, determine the point of highest curvature */ + /* (ie. forming the minimum angle between contour walls). */ + if((ret = min_contour_theta(&min_i, &min_theta, angle_edge, + contour_x, contour_y, ncontour))){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Returns IGNORE or system error. Either way */ + /* free the contour and return the code. */ + return(ret); + } + + /* If the minimum theta found along the contour is too large... */ + if(min_theta >= lfsparms->max_high_curve_theta){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Reject the high-curvature minutia, and return IGNORE. */ + return(IGNORE); + } + + /* Test to see if interior of curvature is OK. Compute midpoint */ + /* between left and right points symmetrically distant (angle_edge */ + /* pixels) from the contour's point of minimum theta. */ + mid_x = (contour_x[min_i-angle_edge] + contour_x[min_i+angle_edge])>>1; + mid_y = (contour_y[min_i-angle_edge] + contour_y[min_i+angle_edge])>>1; + mid_pix = *(bdata + (mid_y * iw) + mid_x); + /* If the interior pixel value is not the same as the feature's... */ + if(mid_pix != feature_pix){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Reject the high-curvature minutia and return IGNORE. */ + return(IGNORE); + } + + /* Compute new direction based on line connecting adjusted feature */ + /* location and the midpoint in the feature's interior. */ + idir = line2direction(contour_x[min_i], contour_y[min_i], + mid_x, mid_y, lfsparms->num_directions); + + /* Set minutia location to minimum theta position on the contour. */ + *oidir = idir; + *ox_loc = contour_x[min_i]; + *oy_loc = contour_y[min_i]; + *ox_edge = contour_ex[min_i]; + *oy_edge = contour_ey[min_i]; + + /* Deallocate contour buffers. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /*Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: adjust_high_curvature_minutia_V2 - Takes an initial minutia point +#cat: in a high-curvature area and adjusts its location and +#cat: direction. First, it walks and extracts the contour +#cat: of the detected feature looking for and processing any loop +#cat: discovered along the way. Once the contour is extracted, +#cat: the point of highest-curvature is determined and used to +#cat: adjust the location of the minutia point. The angle of +#cat: the line perpendicular to the tangent on the high-curvature +#cat: contour at the minutia point is used as the mintutia's +#cat: direction. + + Input: + x_loc - starting x-pixel coord of feature (interior to feature) + y_loc - starting y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + plow_flow_map - pixelized Low Ridge Flow Map + lfsparms - parameters and thresholds for controlling LFS + Output: + oidir - direction of adjusted minutia point + ox_loc - adjusted x-pixel coord of feature + oy_loc - adjusted y-pixel coord of feature + ox_edge - adjusted x-pixel coord of corresponding edge pixel + oy_edge - adjusted y-pixel coord of corresponding edge pixel + minutiae - points to a list of detected minutia structures + Return Code: + Zero - minutia point processed successfully + IGNORE - minutia point is to be ignored + Negative - system error +**************************************************************************/ +int adjust_high_curvature_minutia_V2(int *oidir, int *ox_loc, int *oy_loc, + int *ox_edge, int *oy_edge, + const int x_loc, const int y_loc, + const int x_edge, const int y_edge, + unsigned char *bdata, const int iw, const int ih, + int *plow_flow_map, MINUTIAE *minutiae, const LFSPARMS *lfsparms) +{ + int ret; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int min_i; + double min_theta; + int feature_pix; + int mid_x, mid_y, mid_pix; + int idir; + int half_contour, angle_edge; + + /* Set variable from parameter structure. */ + half_contour = lfsparms->high_curve_half_contour; + + /* Set edge length for computing contour's angle of curvature */ + /* to one quarter of desired pixel length of entire contour. */ + /* Ex. If half_contour==14, then contour length==29=(2X14)+1 */ + /* and angle_edge==7=(14/2). */ + angle_edge = half_contour>>1; + + /* Get the pixel value of current feature. */ + feature_pix = *(bdata + (y_loc * iw) + x_loc); + + /* Extract feature's contour. */ + if((ret = get_high_curvature_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, half_contour, + x_loc, y_loc, x_edge, y_edge, bdata, iw, ih))){ + /* Returns with: */ + /* 1. Successful or empty contour == 0 */ + /* If contour is empty, then contour lists are not allocated. */ + /* 2. Contour forms loop == LOOP_FOUND */ + /* 3. Sysetm error < 0 */ + + /* If the contour forms a loop... */ + if(ret == LOOP_FOUND){ + + /* If the order of the contour is clockwise, then the loops's */ + /* contour pixels are outside the corresponding edge pixels. We */ + /* definitely do NOT want to fill based on the feature pixel in */ + /* this case, because it is OUTSIDE the loop. For now we will */ + /* ignore the loop and the minutia that triggered its tracing. */ + /* It is likely that other minutia on the loop will be */ + /* detected that create a contour on the "inside" of the loop. */ + /* There is another issue here that could be addressed ... */ + /* It seems that many/multiple minutia are often detected within */ + /* the same loop, which currently requires retracing the loop, */ + /* locating minutia on opposite ends of the major axis of the */ + /* loop, and then determining that the minutia have already been */ + /* entered into the minutiae list upon processing the very first */ + /* minutia detected in the loop. There is a lot of redundant */ + /* work being done here! */ + /* Is_loop_clockwise takes a default value to be returned if the */ + /* routine is unable to determine the direction of the contour. */ + /* In this case, we want to IGNORE the loop if we can't tell its */ + /* direction so that we do not inappropriately fill the loop, so */ + /* we are passing the default value TRUE. */ + if((ret = is_loop_clockwise(contour_x, contour_y, ncontour, TRUE))){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* If we had a system error... */ + if(ret < 0) + /* Return the error code. */ + return(ret); + /* Otherwise, loop is clockwise, so return IGNORE. */ + return(IGNORE); + } + + /* Otherwise, process the clockwise-ordered contour of the loop */ + /* as it may contain minutia. If no minutia found, then it is */ + /* filled in. */ + ret = process_loop_V2(minutiae, contour_x, contour_y, + contour_ex, contour_ey, ncontour, + bdata, iw, ih, plow_flow_map, lfsparms); + /* Returns with: */ + /* 1. Successful processing of loop == 0 */ + /* 2. System error < 0 */ + + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /* If loop processed successfully ... */ + if(ret == 0) + /* Then either a minutia pair was extracted or the loop was */ + /* filled. Either way we want to IGNORE the minutia that */ + /* started the whole loop processing in the beginning. */ + return(IGNORE); + + /* Otherwise, there was a system error. */ + /* Return the resulting code. */ + return(ret); + } + + /* Otherwise not a loop, so get_high_curvature_contour incurred */ + /* a system error. Return the error code. */ + return(ret); + } + + /* If contour is empty ... then contour lists were not allocated, so */ + /* simply return IGNORE. The contour comes back empty when there */ + /* were not a sufficient number of points found on the contour. */ + if(ncontour == 0) + return(IGNORE); + + /* Otherwise, there are contour points to process. */ + + /* Given the contour, determine the point of highest curvature */ + /* (ie. forming the minimum angle between contour walls). */ + if((ret = min_contour_theta(&min_i, &min_theta, angle_edge, + contour_x, contour_y, ncontour))){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Returns IGNORE or system error. Either way */ + /* free the contour and return the code. */ + return(ret); + } + + /* If the minimum theta found along the contour is too large... */ + if(min_theta >= lfsparms->max_high_curve_theta){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Reject the high-curvature minutia, and return IGNORE. */ + return(IGNORE); + } + + /* Test to see if interior of curvature is OK. Compute midpoint */ + /* between left and right points symmetrically distant (angle_edge */ + /* pixels) from the contour's point of minimum theta. */ + mid_x = (contour_x[min_i-angle_edge] + contour_x[min_i+angle_edge])>>1; + mid_y = (contour_y[min_i-angle_edge] + contour_y[min_i+angle_edge])>>1; + mid_pix = *(bdata + (mid_y * iw) + mid_x); + /* If the interior pixel value is not the same as the feature's... */ + if(mid_pix != feature_pix){ + /* Deallocate contour lists. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Reject the high-curvature minutia and return IGNORE. */ + return(IGNORE); + } + + /* Compute new direction based on line connecting adjusted feature */ + /* location and the midpoint in the feature's interior. */ + idir = line2direction(contour_x[min_i], contour_y[min_i], + mid_x, mid_y, lfsparms->num_directions); + + /* Set minutia location to minimum theta position on the contour. */ + *oidir = idir; + *ox_loc = contour_x[min_i]; + *oy_loc = contour_y[min_i]; + *ox_edge = contour_ex[min_i]; + *oy_edge = contour_ey[min_i]; + + /* Deallocate contour buffers. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /*Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: get_low_curvature_direction - Converts a bi-direcitonal IMAP direction +#cat: (based on a semi-circle) to a uni-directional value covering +#cat: a full circle based on the scan orientation used to detect +#cat: a minutia feature (horizontal or vertical) and whether the +#cat: detected minutia is appearing or disappearing. + + Input: + scan_dir - designates the feature scan orientation + appearing - designates the minutia as appearing or disappearing + imapval - IMAP block direction + ndirs - number of IMAP directions (in semicircle) + Return Code: + New direction - bi-directonal integer direction on full circle +*************************************************************************/ +int get_low_curvature_direction(const int scan_dir, const int appearing, + const int imapval, const int ndirs) +{ + int idir; + + /* Start direction out with IMAP value. */ + idir = imapval; + + /* NOTE! */ + /* The logic in this routine should hold whether for ridge endings */ + /* or for bifurcations. The examples in the comments show ridge */ + /* ending conditions only. */ + + /* CASE I : Ridge flow in Quadrant I; directions [0..8] */ + if(imapval <= (ndirs>>1)){ + /* I.A: HORIZONTAL scan */ + if(scan_dir == SCAN_HORIZONTAL){ + /* I.A.1: Appearing Minutia */ + if(appearing){ + /* Ex. 0 0 0 */ + /* 0 1 0 */ + /* ? ? */ + /* Ridge flow is up and to the right, whereas */ + /* actual ridge is running down and to the */ + /* left. */ + /* Thus: HORIZONTAL : appearing : should be */ + /* OPPOSITE the ridge flow direction. */ + idir += ndirs; + } + /* Otherwise: */ + /* I.A.2: Disappearing Minutia */ + /* Ex. ? ? */ + /* 0 1 0 */ + /* 0 0 0 */ + /* Ridge flow is up and to the right, which */ + /* should be SAME direction from which ridge */ + /* is projecting. */ + /* Thus: HORIZONTAL : disappearing : should */ + /* be the same as ridge flow direction. */ + } /* End if HORIZONTAL scan */ + /* Otherwise: */ + /* I.B: VERTICAL scan */ + else{ + /* I.B.1: Disappearing Minutia */ + if(!appearing){ + /* Ex. 0 0 */ + /* ? 1 0 */ + /* ? 0 0 */ + /* Ridge flow is up and to the right, whereas */ + /* actual ridge is projecting down and to the */ + /* left. */ + /* Thus: VERTICAL : disappearing : should be */ + /* OPPOSITE the ridge flow direction. */ + idir += ndirs; + } + /* Otherwise: */ + /* I.B.2: Appearing Minutia */ + /* Ex. 0 0 ? */ + /* 0 1 ? */ + /* 0 0 */ + /* Ridge flow is up and to the right, which */ + /* should be SAME direction the ridge is */ + /* running. */ + /* Thus: VERTICAL : appearing : should be */ + /* be the same as ridge flow direction. */ + } /* End else VERTICAL scan */ + } /* End if Quadrant I */ + + /* Otherwise: */ + /* CASE II : Ridge flow in Quadrant II; directions [9..15] */ + else{ + /* II.A: HORIZONTAL scan */ + if(scan_dir == SCAN_HORIZONTAL){ + /* II.A.1: Disappearing Minutia */ + if(!appearing){ + /* Ex. ? ? */ + /* 0 1 0 */ + /* 0 0 0 */ + /* Ridge flow is down and to the right, */ + /* whereas actual ridge is running up and to */ + /* the left. */ + /* Thus: HORIZONTAL : disappearing : should */ + /* be OPPOSITE the ridge flow direction.*/ + idir += ndirs; + } + /* Otherwise: */ + /* II.A.2: Appearing Minutia */ + /* Ex. 0 0 0 */ + /* 0 1 0 */ + /* ? ? */ + /* Ridge flow is down and to the right, which */ + /* should be same direction from which ridge */ + /* is projecting. */ + /* Thus: HORIZONTAL : appearing : should be */ + /* the SAME as ridge flow direction. */ + } /* End if HORIZONTAL scan */ + /* Otherwise: */ + /* II.B: VERTICAL scan */ + else{ + /* II.B.1: Disappearing Minutia */ + if(!appearing){ + /* Ex. ? 0 0 */ + /* ? 1 0 */ + /* 0 0 */ + /* Ridge flow is down and to the right, */ + /* whereas actual ridge is running up and to */ + /* the left. */ + /* Thus: VERTICAL : disappearing : should be */ + /* OPPOSITE the ridge flow direction. */ + idir += ndirs; + } + /* Otherwise: */ + /* II.B.2: Appearing Minutia */ + /* Ex. 0 0 */ + /* 0 1 ? */ + /* 0 0 ? */ + /* Ridge flow is down and to the right, which */ + /* should be same direction the ridge is */ + /* projecting. */ + /* Thus: VERTICAL : appearing : should be */ + /* be the SAME as ridge flow direction. */ + } /* End else VERTICAL scan */ + } /* End else Quadrant II */ + + /* Return resulting direction on range [0..31]. */ + return(idir); +} + +/************************************************************************* +************************************************************************** +#cat: lfs2nist_minutia_XYT - Converts XYT minutiae attributes in LFS native +#cat: representation to NIST internal representation + + Input: + minutia - LFS minutia structure containing attributes to be converted + Output: + ox - NIST internal based x-pixel coordinate + oy - NIST internal based y-pixel coordinate + ot - NIST internal based minutia direction/orientation + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +void lfs2nist_minutia_XYT(int *ox, int *oy, int *ot, + const MINUTIA *minutia, const int iw, const int ih) +{ + int x, y, t; + float degrees_per_unit; + + /* XYT's according to NIST internal rep: */ + /* 1. pixel coordinates with origin bottom-left */ + /* 2. orientation in degrees on range [0..360] */ + /* with 0 pointing east and increasing counter */ + /* clockwise (same as M1) */ + /* 3. direction pointing out and away from the */ + /* ridge ending or bifurcation valley */ + /* (opposite direction from M1) */ + + x = minutia->x; + y = ih - minutia->y; + + degrees_per_unit = 180 / (float)NUM_DIRECTIONS; + + t = (270 - sround(minutia->direction * degrees_per_unit)) % 360; + if(t < 0){ + t += 360; + } + + *ox = x; + *oy = y; + *ot = t; +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/line.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/line.c.svn-base @@ -0,0 +1,203 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: LINE.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + + Contains routines that compute contiguous linear trajectories + between two coordinate points required by the NIST Latent + Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + line_points() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: line_points - Returns the contiguous coordinates of a line connecting +#cat: 2 specified points. + + Input: + x1 - x-coord of first point + y1 - y-coord of first point + x2 - x-coord of second point + y2 - y-coord of second point + Output: + ox_list - x-coords along line trajectory + oy_list - y-coords along line trajectory + onum - number of points along line trajectory + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int line_points(int **ox_list, int **oy_list, int *onum, + const int x1, const int y1, const int x2, const int y2) +{ + int asize; + int dx, dy, adx, ady; + int x_incr, y_incr; + int i, inx, iny, intx, inty; + double x_factor, y_factor; + double rx, ry; + int ix, iy; + int *x_list, *y_list; + + /* Compute maximum number of points needed to hold line segment. */ + asize = max(abs(x2-x1)+2, abs(y2-y1)+2); + + /* Allocate x and y-pixel coordinate lists to length 'asize'. */ + x_list = (int *)malloc(asize*sizeof(int)); + if(x_list == (int *)NULL){ + fprintf(stderr, "ERROR : line_points : malloc : x_list\n"); + return(-410); + } + y_list = (int *)malloc(asize*sizeof(int)); + if(y_list == (int *)NULL){ + free(x_list); + fprintf(stderr, "ERROR : line_points : malloc : y_list\n"); + return(-411); + } + + /* Compute delta x and y. */ + dx = x2 - x1; + dy = y2 - y1; + + /* Set x and y increments. */ + if(dx >= 0) + x_incr = 1; + else + x_incr = -1; + + if(dy >= 0) + y_incr = 1; + else + y_incr = -1; + + /* Compute |DX| and |DY|. */ + adx = abs(dx); + ady = abs(dy); + + /* Set x-orientation. */ + if(adx > ady) + inx = 1; + else + inx = 0; + + /* Set y-orientation. */ + if(ady > adx) + iny = 1; + else + iny = 0; + + /* CASE 1: |DX| > |DY| */ + /* Increment in X by +-1 */ + /* in Y by +-|DY|/|DX| */ + /* inx = 1 */ + /* iny = 0 */ + /* intx = 1 (inx) */ + /* inty = 0 (iny) */ + /* CASE 2: |DX| < |DY| */ + /* Increment in Y by +-1 */ + /* in X by +-|DX|/|DY| */ + /* inx = 0 */ + /* iny = 1 */ + /* intx = 0 (inx) */ + /* inty = 1 (iny) */ + /* CASE 3: |DX| == |DY| */ + /* inx = 0 */ + /* iny = 0 */ + /* intx = 1 */ + /* inty = 1 */ + intx = 1 - iny; + inty = 1 - inx; + + /* DX */ + /* x_factor = (inx * +-1) + ( iny * ------------ ) */ + /* max(1, |DY|) */ + /* */ + x_factor = (inx * x_incr) + (iny * ((double)dx/max(1, ady))); + + /* DY */ + /* y_factor = (iny * +-1) + ( inx * ------------ ) */ + /* max(1, |DX|) */ + /* */ + y_factor = (iny * y_incr) + (inx * ((double)dy/max(1, adx))); + + /* Initialize integer coordinates. */ + ix = x1; + iy = y1; + /* Set floating point coordinates. */ + rx = (double)x1; + ry = (double)y1; + + /* Initialize to first point in line segment. */ + i = 0; + + /* Assign first point into coordinate list. */ + x_list[i] = x1; + y_list[i++] = y1; + + while((ix != x2) || (iy != y2)){ + + if(i >= asize){ + fprintf(stderr, "ERROR : line_points : coord list overflow\n"); + free(x_list); + free(y_list); + return(-412); + } + + rx += x_factor; + ry += y_factor; + + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when truncating doubles. */ + rx = trunc_dbl_precision(rx, TRUNC_SCALE); + ry = trunc_dbl_precision(ry, TRUNC_SCALE); + + /* Compute new x and y-pixel coords in floating point and */ + /* then round to the nearest integer. */ + ix = (intx * (ix + x_incr)) + (iny * (int)(rx + 0.5)); + iy = (inty * (iy + y_incr)) + (inx * (int)(ry + 0.5)); + + /* Assign first point into coordinate list. */ + x_list[i] = ix; + y_list[i++] = iy; + } + + /* Set output pointers. */ + *ox_list = x_list; + *oy_list = y_list; + *onum = i; + + /* Return normally. */ + return(0); +} --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/detect.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/detect.c.svn-base @@ -0,0 +1,455 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: DETECT.C + AUTHOR: Michael D. Garris + DATE: 08/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Takes an 8-bit grayscale fingerpinrt image and detects minutiae + as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + lfs_detect_minutiae_V2() + get_minutiae() + +***********************************************************************/ + +#include +#include +#include +#include + +/************************************************************************* +#cat: lfs_detect_minutiae_V2 - Takes a grayscale fingerprint image (of +#cat: arbitrary size), and returns a set of image block maps, +#cat: a binarized image designating ridges from valleys, +#cat: and a list of minutiae (including position, reliability, +#cat: type, direction, neighbors, and ridge counts to neighbors). +#cat: The image maps include a ridge flow directional map, +#cat: a map of low contrast blocks, a map of low ridge flow blocks. +#cat: and a map of high-curvature blocks. + + Input: + idata - input 8-bit grayscale fingerprint image data + iw - width (in pixels) of the image + ih - height (in pixels) of the image + lfsparms - parameters and thresholds for controlling LFS + + Output: + ominutiae - resulting list of minutiae + odmap - resulting Direction Map + {invalid (-1) or valid ridge directions} + olcmap - resulting Low Contrast Map + {low contrast (TRUE), high contrast (FALSE)} + olfmap - resulting Low Ridge Flow Map + {low ridge flow (TRUE), high ridge flow (FALSE)} + ohcmap - resulting High Curvature Map + {high curvature (TRUE), low curvature (FALSE)} + omw - width (in blocks) of image maps + omh - height (in blocks) of image maps + obdata - resulting binarized image + {0 = black pixel (ridge) and 255 = white pixel (valley)} + obw - width (in pixels) of the binary image + obh - height (in pixels) of the binary image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, + int **odmap, int **olcmap, int **olfmap, int **ohcmap, + int *omw, int *omh, + unsigned char **obdata, int *obw, int *obh, + unsigned char *idata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + unsigned char *pdata, *bdata; + int pw, ph, bw, bh; + DIR2RAD *dir2rad; + DFTWAVES *dftwaves; + ROTGRIDS *dftgrids; + ROTGRIDS *dirbingrids; + int *direction_map, *low_contrast_map, *low_flow_map, *high_curve_map; + int mw, mh; + int ret, maxpad; + MINUTIAE *minutiae; + + /******************/ + /* INITIALIZATION */ + /******************/ + + /* If LOG_REPORT defined, open log report file. */ + if((ret = open_logfile())) + /* If system error, exit with error code. */ + return(ret); + + /* Determine the maximum amount of image padding required to support */ + /* LFS processes. */ + maxpad = get_max_padding_V2(lfsparms->windowsize, lfsparms->windowoffset, + lfsparms->dirbin_grid_w, lfsparms->dirbin_grid_h); + + /* Initialize lookup table for converting integer directions */ + /* to angles in radians. */ + if((ret = init_dir2rad(&dir2rad, lfsparms->num_directions))){ + /* Free memory allocated to this point. */ + return(ret); + } + + /* Initialize wave form lookup tables for DFT analyses. */ + /* used for direction binarization. */ + if((ret = init_dftwaves(&dftwaves, dft_coefs, lfsparms->num_dft_waves, + lfsparms->windowsize))){ + /* Free memory allocated to this point. */ + free_dir2rad(dir2rad); + return(ret); + } + + /* Initialize lookup table for pixel offsets to rotated grids */ + /* used for DFT analyses. */ + if((ret = init_rotgrids(&dftgrids, iw, ih, maxpad, + lfsparms->start_dir_angle, lfsparms->num_directions, + lfsparms->windowsize, lfsparms->windowsize, + RELATIVE2ORIGIN))){ + /* Free memory allocated to this point. */ + free_dir2rad(dir2rad); + free_dftwaves(dftwaves); + return(ret); + } + + /* Pad input image based on max padding. */ + if(maxpad > 0){ /* May not need to pad at all */ + if((ret = pad_uchar_image(&pdata, &pw, &ph, idata, iw, ih, + maxpad, lfsparms->pad_value))){ + /* Free memory allocated to this point. */ + free_dir2rad(dir2rad); + free_dftwaves(dftwaves); + free_rotgrids(dftgrids); + return(ret); + } + } + else{ + /* If padding is unnecessary, then copy the input image. */ + pdata = (unsigned char *)malloc(iw*ih); + if(pdata == (unsigned char *)NULL){ + /* Free memory allocated to this point. */ + free_dir2rad(dir2rad); + free_dftwaves(dftwaves); + free_rotgrids(dftgrids); + fprintf(stderr, "ERROR : lfs_detect_minutiae_V2 : malloc : pdata\n"); + return(-580); + } + memcpy(pdata, idata, iw*ih); + pw = iw; + ph = ih; + } + + /* Scale input image to 6 bits [0..63] */ + /* !!! Would like to remove this dependency eventualy !!! */ + /* But, the DFT computations will need to be changed, and */ + /* could not get this work upon first attempt. Also, if not */ + /* careful, I think accumulated power magnitudes may overflow */ + /* doubles. */ + bits_8to6(pdata, pw, ph); + + print2log("\nINITIALIZATION AND PADDING DONE\n"); + + /******************/ + /* MAPS */ + /******************/ + + /* Generate block maps from the input image. */ + if((ret = gen_image_maps(&direction_map, &low_contrast_map, + &low_flow_map, &high_curve_map, &mw, &mh, + pdata, pw, ph, dir2rad, dftwaves, dftgrids, lfsparms))){ + /* Free memory allocated to this point. */ + free_dir2rad(dir2rad); + free_dftwaves(dftwaves); + free_rotgrids(dftgrids); + free(pdata); + return(ret); + } + /* Deallocate working memories. */ + free_dir2rad(dir2rad); + free_dftwaves(dftwaves); + free_rotgrids(dftgrids); + + print2log("\nMAPS DONE\n"); + + /******************/ + /* BINARIZARION */ + /******************/ + + /* Initialize lookup table for pixel offsets to rotated grids */ + /* used for directional binarization. */ + if((ret = init_rotgrids(&dirbingrids, iw, ih, maxpad, + lfsparms->start_dir_angle, lfsparms->num_directions, + lfsparms->dirbin_grid_w, lfsparms->dirbin_grid_h, + RELATIVE2CENTER))){ + /* Free memory allocated to this point. */ + free(pdata); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + return(ret); + } + + /* Binarize input image based on NMAP information. */ + if((ret = binarize_V2(&bdata, &bw, &bh, + pdata, pw, ph, direction_map, mw, mh, + dirbingrids, lfsparms))){ + /* Free memory allocated to this point. */ + free(pdata); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free_rotgrids(dirbingrids); + return(ret); + } + + /* Deallocate working memory. */ + free_rotgrids(dirbingrids); + + /* Check dimension of binary image. If they are different from */ + /* the input image, then ERROR. */ + if((iw != bw) || (ih != bh)){ + /* Free memory allocated to this point. */ + free(pdata); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(bdata); + fprintf(stderr, "ERROR : lfs_detect_minutiae_V2 :"); + fprintf(stderr,"binary image has bad dimensions : %d, %d\n", + bw, bh); + return(-581); + } + + print2log("\nBINARIZATION DONE\n"); + + /******************/ + /* DETECTION */ + /******************/ + + /* Convert 8-bit grayscale binary image [0,255] to */ + /* 8-bit binary image [0,1]. */ + gray2bin(1, 1, 0, bdata, iw, ih); + + /* Allocate initial list of minutia pointers. */ + if((ret = alloc_minutiae(&minutiae, MAX_MINUTIAE))){ + return(ret); + } + + /* Detect the minutiae in the binarized image. */ + if((ret = detect_minutiae_V2(minutiae, bdata, iw, ih, + direction_map, low_flow_map, high_curve_map, + mw, mh, lfsparms))){ + /* Free memory allocated to this point. */ + free(pdata); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(bdata); + return(ret); + } + + if((ret = remove_false_minutia_V2(minutiae, bdata, iw, ih, + direction_map, low_flow_map, high_curve_map, mw, mh, + lfsparms))){ + /* Free memory allocated to this point. */ + free(pdata); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(bdata); + free_minutiae(minutiae); + return(ret); + } + + print2log("\nMINUTIA DETECTION DONE\n"); + + /******************/ + /* RIDGE COUNTS */ + /******************/ + if((ret = count_minutiae_ridges(minutiae, bdata, iw, ih, lfsparms))){ + /* Free memory allocated to this point. */ + free(pdata); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free_minutiae(minutiae); + return(ret); + } + + + print2log("\nNEIGHBOR RIDGE COUNT DONE\n"); + + /******************/ + /* WRAP-UP */ + /******************/ + + /* Convert 8-bit binary image [0,1] to 8-bit */ + /* grayscale binary image [0,255]. */ + gray2bin(1, 255, 0, bdata, iw, ih); + + /* Deallocate working memory. */ + free(pdata); + + /* Assign results to output pointers. */ + *odmap = direction_map; + *olcmap = low_contrast_map; + *olfmap = low_flow_map; + *ohcmap = high_curve_map; + *omw = mw; + *omh = mh; + *obdata = bdata; + *obw = bw; + *obh = bh; + *ominutiae = minutiae; + + /* If LOG_REPORT defined, close log report file. */ + if((ret = close_logfile())) + return(ret); + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: get_minutiae - Takes a grayscale fingerprint image, binarizes the input +#cat: image, and detects minutiae points using LFS Version 2. +#cat: The routine passes back the detected minutiae, the +#cat: binarized image, and a set of image quality maps. + + Input: + idata - grayscale fingerprint image data + iw - width (in pixels) of the grayscale image + ih - height (in pixels) of the grayscale image + id - pixel depth (in bits) of the grayscale image + ppmm - the scan resolution (in pixels/mm) of the grayscale image + lfsparms - parameters and thresholds for controlling LFS + Output: + ominutiae - points to a structure containing the + detected minutiae + oquality_map - resulting integrated image quality map + odirection_map - resulting direction map + olow_contrast_map - resulting low contrast map + olow_flow_map - resulting low ridge flow map + ohigh_curve_map - resulting high curvature map + omap_w - width (in blocks) of image maps + omap_h - height (in blocks) of image maps + obdata - points to binarized image data + obw - width (in pixels) of binarized image + obh - height (in pixels) of binarized image + obd - pixel depth (in bits) of binarized image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int get_minutiae(MINUTIAE **ominutiae, int **oquality_map, + int **odirection_map, int **olow_contrast_map, + int **olow_flow_map, int **ohigh_curve_map, + int *omap_w, int *omap_h, + unsigned char **obdata, int *obw, int *obh, int *obd, + unsigned char *idata, const int iw, const int ih, + const int id, const double ppmm, const LFSPARMS *lfsparms) +{ + int ret; + MINUTIAE *minutiae; + int *direction_map, *low_contrast_map, *low_flow_map; + int *high_curve_map, *quality_map; + int map_w, map_h; + unsigned char *bdata; + int bw, bh; + + /* If input image is not 8-bit grayscale ... */ + if(id != 8){ + fprintf(stderr, "ERROR : get_minutiae : input image pixel "); + fprintf(stderr, "depth = %d != 8.\n", id); + return(-2); + } + + /* Detect minutiae in grayscale fingerpeint image. */ + if((ret = lfs_detect_minutiae_V2(&minutiae, + &direction_map, &low_contrast_map, + &low_flow_map, &high_curve_map, + &map_w, &map_h, + &bdata, &bw, &bh, + idata, iw, ih, lfsparms))){ + return(ret); + } + + /* Build integrated quality map. */ + if((ret = gen_quality_map(&quality_map, + direction_map, low_contrast_map, + low_flow_map, high_curve_map, map_w, map_h))){ + free_minutiae(minutiae); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(bdata); + return(ret); + } + + /* Assign reliability from quality map. */ + if((ret = combined_minutia_quality(minutiae, quality_map, map_w, map_h, + lfsparms->blocksize, + idata, iw, ih, id, ppmm))){ + free_minutiae(minutiae); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(quality_map); + free(bdata); + return(ret); + } + + /* Set output pointers. */ + *ominutiae = minutiae; + *oquality_map = quality_map; + *odirection_map = direction_map; + *olow_contrast_map = low_contrast_map; + *olow_flow_map = low_flow_map; + *ohigh_curve_map = high_curve_map; + *omap_w = map_w; + *omap_h = map_h; + *obdata = bdata; + *obw = bw; + *obh = bh; + *obd = id; + + /* Return normally. */ + return(0); +} --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/imgutil.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/imgutil.c.svn-base @@ -0,0 +1,469 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: IMGUTIL.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 03/16/2005 by MDG + + Contains general support image routines required by the NIST + Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + bits_6to8() + bits_8to6() + gray2bin() + pad_uchar_image() + fill_holes() + free_path() + search_in_direction() + +***********************************************************************/ + +#include +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: bits_6to8 - Takes an array of unsigned characters and bitwise shifts +#cat: each value 2 postitions to the left. This is equivalent +#cat: to multiplying each value by 4. This puts original values +#cat: on the range [0..64) now on the range [0..256). Another +#cat: way to say this, is the original 6-bit values now fit in +#cat: 8 bits. This is to be used to undo the effects of bits_8to6. + + Input: + idata - input array of unsigned characters + iw - width (in characters) of the input array + ih - height (in characters) of the input array + Output: + idata - contains the bit-shifted results +**************************************************************************/ +void bits_6to8(unsigned char *idata, const int iw, const int ih) +{ + int i, isize; + unsigned char *iptr; + + isize = iw * ih; + iptr = idata; + for(i = 0; i < isize; i++){ + /* Multiply every pixel value by 4 so that [0..64) -> [0..255) */ + *iptr++ <<= 2; + } +} + +/************************************************************************* +************************************************************************** +#cat: bits_8to6 - Takes an array of unsigned characters and bitwise shifts +#cat: each value 2 postitions to the right. This is equivalent +#cat: to dividing each value by 4. This puts original values +#cat: on the range [0..256) now on the range [0..64). Another +#cat: way to say this, is the original 8-bit values now fit in +#cat: 6 bits. I would really like to make this dependency +#cat: go away. + + Input: + idata - input array of unsigned characters + iw - width (in characters) of the input array + ih - height (in characters) of the input array + Output: + idata - contains the bit-shifted results +**************************************************************************/ +void bits_8to6(unsigned char *idata, const int iw, const int ih) +{ + int i, isize; + unsigned char *iptr; + + isize = iw * ih; + iptr = idata; + for(i = 0; i < isize; i++){ + /* Divide every pixel value by 4 so that [0..256) -> [0..64) */ + *iptr++ >>= 2; + } +} + +/************************************************************************* +************************************************************************** +#cat: gray2bin - Takes an 8-bit threshold value and two 8-bit pixel values. +#cat: Those pixels in the image less than the threhsold are set +#cat: to the first specified pixel value, whereas those pixels +#cat: greater than or equal to the threshold are set to the second +#cat: specified pixel value. On application for this routine is +#cat: to convert binary images from 8-bit pixels valued {0,255} to +#cat: {1,0} and vice versa. + + Input: + thresh - 8-bit pixel threshold + less_pix - pixel value used when image pixel is < threshold + greater_pix - pixel value used when image pixel is >= threshold + bdata - 8-bit image data + iw - width (in pixels) of the image + ih - height (in pixels) of the image + Output: + bdata - altered 8-bit image data +**************************************************************************/ +void gray2bin(const int thresh, const int less_pix, const int greater_pix, + unsigned char *bdata, const int iw, const int ih) +{ + int i; + + for(i = 0; i < iw*ih; i++){ + if(bdata[i] >= thresh) + bdata[i] = (unsigned char)greater_pix; + else + bdata[i] = (unsigned char)less_pix; + } +} + +/************************************************************************* +************************************************************************** +#cat: pad_uchar_image - Copies an 8-bit grayscale images into a larger +#cat: output image centering the input image so as to +#cat: add a specified amount of pixel padding along the +#cat: entire perimeter of the input image. The amount of +#cat: pixel padding and the intensity of the pixel padding +#cat: are specified. An alternative to padding with a +#cat: constant intensity would be to copy the edge pixels +#cat: of the centered image into the adjacent pad area. + + Input: + idata - input 8-bit grayscale image + iw - width (in pixels) of the input image + ih - height (in pixels) of the input image + pad - size of padding (in pixels) to be added + pad_value - intensity of the padded area + Output: + optr - points to the newly padded image + ow - width (in pixels) of the padded image + oh - height (in pixels) of the padded image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int pad_uchar_image(unsigned char **optr, int *ow, int *oh, + unsigned char *idata, const int iw, const int ih, + const int pad, const int pad_value) +{ + unsigned char *pdata, *pptr, *iptr; + int i, pw, ph; + int pad2, psize; + + /* Account for pad on both sides of image */ + pad2 = pad<<1; + + /* Compute new pad sizes */ + pw = iw + pad2; + ph = ih + pad2; + psize = pw * ph; + + /* Allocate padded image */ + pdata = (unsigned char *)malloc(psize * sizeof(unsigned char)); + if(pdata == (unsigned char *)NULL){ + fprintf(stderr, "ERROR : pad_uchar_image : malloc : pdata\n"); + return(-160); + } + + /* Initialize values to a constant PAD value */ + memset(pdata, pad_value, psize); + + /* Copy input image into padded image one scanline at a time */ + iptr = idata; + pptr = pdata + (pad * pw) + pad; + for(i = 0; i < ih; i++){ + memcpy(pptr, iptr, iw); + iptr += iw; + pptr += pw; + } + + *optr = pdata; + *ow = pw; + *oh = ph; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: fill_holes - Takes an input image and analyzes triplets of horizontal +#cat: pixels first and then triplets of vertical pixels, filling +#cat: in holes of width 1. A hole is defined as the case where +#cat: the neighboring 2 pixels are equal, AND the center pixel +#cat: is different. Each hole is filled with the value of its +#cat: immediate neighbors. This routine modifies the input image. + + Input: + bdata - binary image data to be processed + iw - width (in pixels) of the binary input image + ih - height (in pixels) of the binary input image + Output: + bdata - points to the results +**************************************************************************/ +void fill_holes(unsigned char *bdata, const int iw, const int ih) +{ + int ix, iy, iw2; + unsigned char *lptr, *mptr, *rptr, *tptr, *bptr, *sptr; + + /* 1. Fill 1-pixel wide holes in horizontal runs first ... */ + sptr = bdata + 1; + /* Foreach row in image ... */ + for(iy = 0; iy < ih; iy++){ + /* Initialize pointers to start of next line ... */ + lptr = sptr-1; /* Left pixel */ + mptr = sptr; /* Middle pixel */ + rptr = sptr+1; /* Right pixel */ + /* Foreach column in image (less far left and right pixels) ... */ + for(ix = 1; ix < iw-1; ix++){ + /* Do we have a horizontal hole of length 1? */ + if((*lptr != *mptr) && (*lptr == *rptr)){ + /* If so, then fill it. */ + *mptr = *lptr; + /* Bump passed right pixel because we know it will not */ + /* be a hole. */ + lptr+=2; + mptr+=2; + rptr+=2; + /* We bump ix once here and then the FOR bumps it again. */ + ix++; + } + else{ + /* Otherwise, bump to the next pixel to the right. */ + lptr++; + mptr++; + rptr++; + } + } + /* Bump to start of next row. */ + sptr += iw; + } + + /* 2. Now, fill 1-pixel wide holes in vertical runs ... */ + iw2 = iw<<1; + /* Start processing column one row down from the top of the image. */ + sptr = bdata + iw; + /* Foreach column in image ... */ + for(ix = 0; ix < iw; ix++){ + /* Initialize pointers to start of next column ... */ + tptr = sptr-iw; /* Top pixel */ + mptr = sptr; /* Middle pixel */ + bptr = sptr+iw; /* Bottom pixel */ + /* Foreach row in image (less top and bottom row) ... */ + for(iy = 1; iy < ih-1; iy++){ + /* Do we have a vertical hole of length 1? */ + if((*tptr != *mptr) && (*tptr == *bptr)){ + /* If so, then fill it. */ + *mptr = *tptr; + /* Bump passed bottom pixel because we know it will not */ + /* be a hole. */ + tptr+=iw2; + mptr+=iw2; + bptr+=iw2; + /* We bump iy once here and then the FOR bumps it again. */ + iy++; + } + else{ + /* Otherwise, bump to the next pixel below. */ + tptr+=iw; + mptr+=iw; + bptr+=iw; + } + } + /* Bump to start of next column. */ + sptr++; + } +} + +/************************************************************************* +************************************************************************** +#cat: free_path - Traverses a straight line between 2 pixel points in an +#cat: image and determines if a "free path" exists between the +#cat: 2 points by counting the number of pixel value transitions +#cat: between adjacent pixels along the trajectory. + + Input: + x1 - x-pixel coord of first point + y1 - y-pixel coord of first point + x2 - x-pixel coord of second point + y2 - y-pixel coord of second point + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and threshold for controlling LFS + Return Code: + TRUE - free path determined to exist + FALSE - free path determined not to exist + Negative - system error +**************************************************************************/ +int free_path(const int x1, const int y1, const int x2, const int y2, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int *x_list, *y_list, num; + int ret; + int i, trans, preval, nextval; + + /* Compute points along line segment between the two points. */ + if((ret = line_points(&x_list, &y_list, &num, x1, y1, x2, y2))) + return(ret); + + /* Intialize the number of transitions to 0. */ + trans = 0; + /* Get the pixel value of first point along line segment. */ + preval = *(bdata+(y1*iw)+x1); + + /* Foreach remaining point along line segment ... */ + for(i = 1; i < num; i++){ + /* Get pixel value of next point along line segment. */ + nextval = *(bdata+(y_list[i]*iw)+x_list[i]); + + /* If next pixel value different from previous pixel value ... */ + if(nextval != preval){ + /* Then we have detected a transition, so bump counter. */ + trans++; + /* If number of transitions seen > than threshold (ex. 2) ... */ + if(trans > lfsparms->maxtrans){ + /* Deallocate the line segment's coordinate lists. */ + free(x_list); + free(y_list); + /* Return free path to be FALSE. */ + return(FALSE); + } + /* Otherwise, maximum number of transitions not yet exceeded. */ + /* Assign the next pixel value to the previous pixel value. */ + preval = nextval; + } + /* Otherwise, no transition detected this interation. */ + + } + + /* If we get here we did not exceed the maximum allowable number */ + /* of transitions. So, deallocate the line segment's coordinate lists. */ + free(x_list); + free(y_list); + + /* Return free path to be TRUE. */ + return(TRUE); +} + +/************************************************************************* +************************************************************************** +#cat: search_in_direction - Takes a specified maximum number of steps in a +#cat: specified direction looking for the first occurence of +#cat: a pixel with specified value. (Once found, adjustments +#cat: are potentially made to make sure the resulting pixel +#cat: and its associated edge pixel are 4-connected.) + + Input: + pix - value of pixel to be searched for + strt_x - x-pixel coord to start search + strt_y - y-pixel coord to start search + delta_x - increment in x for each step + delta_y - increment in y for each step + maxsteps - maximum number of steps to conduct search + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + ox - x coord of located pixel + oy - y coord of located pixel + oex - x coord of associated edge pixel + oey - y coord of associated edge pixel + Return Code: + TRUE - pixel of specified value found + FALSE - pixel of specified value NOT found +**************************************************************************/ +int search_in_direction(int *ox, int *oy, int *oex, int *oey, const int pix, + const int strt_x, const int strt_y, + const double delta_x, const double delta_y, const int maxsteps, + unsigned char *bdata, const int iw, const int ih) +{ + + int i, x, y, px, py; + double fx, fy; + + /* Set previous point to starting point. */ + px = strt_x; + py = strt_y; + /* Set floating point accumulators to starting point. */ + fx = (double)strt_x; + fy = (double)strt_y; + + /* Foreach step up to the specified maximum ... */ + for(i = 0; i < maxsteps; i++){ + + /* Increment accumulators. */ + fx += delta_x; + fy += delta_y; + /* Round to get next step. */ + x = sround(fx); + y = sround(fy); + + /* If we stepped outside the image boundaries ... */ + if((x < 0) || (x >= iw) || + (y < 0) || (y >= ih)){ + /* Return FALSE (we did not find what we were looking for). */ + *ox = -1; + *oy = -1; + *oex = -1; + *oey = -1; + return(FALSE); + } + + /* Otherwise, test to see if we found our pixel with value 'pix'. */ + if(*(bdata+(y*iw)+x) == pix){ + /* The previous and current pixels form a feature, edge pixel */ + /* pair, which we would like to use for edge following. The */ + /* previous pixel may be a diagonal neighbor however to the */ + /* current pixel, in which case the pair could not be used by */ + /* the contour tracing (which requires the edge pixel in the */ + /* pair neighbor to the N,S,E or W. */ + /* This routine adjusts the pair so that the results may be */ + /* used by the contour tracing. */ + fix_edge_pixel_pair(&x, &y, &px, &py, bdata, iw, ih); + + /* Return TRUE (we found what we were looking for). */ + *ox = x; + *oy = y; + *oex = px; + *oey = py; + return(TRUE); + } + + /* Otherwise, still haven't found pixel with desired value, */ + /* so set current point to previous and take another step. */ + px = x; + py = y; + } + + /* Return FALSE (we did not find what we were looking for). */ + *ox = -1; + *oy = -1; + *oex = -1; + *oey = -1; + return(FALSE); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/globals.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/globals.c.svn-base @@ -0,0 +1,293 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: GLOBALS.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + + Contains general global variable definitions required by the + NIST Latent Fingerprint System (LFS). +***********************************************************************/ + +#include + +/*************************************************************************/ +/* GOBAL DECLARATIONS */ +/*************************************************************************/ + +#ifdef LOG_REPORT +FILE *logfp; +#endif + +/* Constants (C) for defining 4 DFT frequencies, where */ +/* frequency is defined as C*(PI_FACTOR). PI_FACTOR */ +/* regulates the period of the function in x, so: */ +/* 1 = one period in range X. */ +/* 2 = twice the frequency in range X. */ +/* 3 = three times the frequency in reange X. */ +/* 4 = four times the frequency in ranage X. */ +double dft_coefs[NUM_DFT_WAVES] = { 1,2,3,4 }; + +/* Allocate and initialize a global LFS parameters structure. */ +LFSPARMS lfsparms = { + /* Image Controls */ + PAD_VALUE, + JOIN_LINE_RADIUS, + + /* Map Controls */ + IMAP_BLOCKSIZE, + UNUSED_INT, /* windowsize */ + UNUSED_INT, /* windowoffset */ + NUM_DIRECTIONS, + START_DIR_ANGLE, + RMV_VALID_NBR_MIN, + DIR_STRENGTH_MIN, + DIR_DISTANCE_MAX, + SMTH_VALID_NBR_MIN, + VORT_VALID_NBR_MIN, + HIGHCURV_VORTICITY_MIN, + HIGHCURV_CURVATURE_MIN, + UNUSED_INT, /* min_interpolate_nbrs */ + UNUSED_INT, /* percentile_min_max */ + UNUSED_INT, /* min_contrast_delta */ + + /* DFT Controls */ + NUM_DFT_WAVES, + POWMAX_MIN, + POWNORM_MIN, + POWMAX_MAX, + FORK_INTERVAL, + FORK_PCT_POWMAX, + FORK_PCT_POWNORM, + + /* Binarization Controls */ + DIRBIN_GRID_W, + DIRBIN_GRID_H, + ISOBIN_GRID_DIM, + NUM_FILL_HOLES, + + /* Minutiae Detection Controls */ + MAX_MINUTIA_DELTA, + MAX_HIGH_CURVE_THETA, + HIGH_CURVE_HALF_CONTOUR, + MIN_LOOP_LEN, + MIN_LOOP_ASPECT_DIST, + MIN_LOOP_ASPECT_RATIO, + + /* Minutiae Link Controls */ + LINK_TABLE_DIM, + MAX_LINK_DIST, + MIN_THETA_DIST, + MAXTRANS, + SCORE_THETA_NORM, + SCORE_DIST_NORM, + SCORE_DIST_WEIGHT, + SCORE_NUMERATOR, + + /* False Minutiae Removal Controls */ + MAX_RMTEST_DIST, + MAX_HOOK_LEN, + MAX_HALF_LOOP, + TRANS_DIR_PIX, + SMALL_LOOP_LEN, + SIDE_HALF_CONTOUR, + INV_BLOCK_MARGIN, + RM_VALID_NBR_MIN, + UNUSED_INT, /* max_overlap_dist */ + UNUSED_INT, /* max_overlap_join_dist */ + UNUSED_INT, /* malformation_steps_1 */ + UNUSED_INT, /* malformation_steps_2 */ + UNUSED_DBL, /* min_malformation_ratio */ + UNUSED_INT, /* max_malformation_dist */ + PORES_TRANS_R, + PORES_PERP_STEPS, + PORES_STEPS_FWD, + PORES_STEPS_BWD, + PORES_MIN_DIST2, + PORES_MAX_RATIO, + + /* Ridge Counting Controls */ + MAX_NBRS, + MAX_RIDGE_STEPS +}; + + +/* Allocate and initialize VERSION 2 global LFS parameters structure. */ +LFSPARMS lfsparms_V2 = { + /* Image Controls */ + PAD_VALUE, + JOIN_LINE_RADIUS, + + /* Map Controls */ + MAP_BLOCKSIZE_V2, + MAP_WINDOWSIZE_V2, + MAP_WINDOWOFFSET_V2, + NUM_DIRECTIONS, + START_DIR_ANGLE, + RMV_VALID_NBR_MIN, + DIR_STRENGTH_MIN, + DIR_DISTANCE_MAX, + SMTH_VALID_NBR_MIN, + VORT_VALID_NBR_MIN, + HIGHCURV_VORTICITY_MIN, + HIGHCURV_CURVATURE_MIN, + MIN_INTERPOLATE_NBRS, + PERCENTILE_MIN_MAX, + MIN_CONTRAST_DELTA, + + /* DFT Controls */ + NUM_DFT_WAVES, + POWMAX_MIN, + POWNORM_MIN, + POWMAX_MAX, + FORK_INTERVAL, + FORK_PCT_POWMAX, + FORK_PCT_POWNORM, + + /* Binarization Controls */ + DIRBIN_GRID_W, + DIRBIN_GRID_H, + UNUSED_INT, /* isobin_grid_dim */ + NUM_FILL_HOLES, + + /* Minutiae Detection Controls */ + MAX_MINUTIA_DELTA, + MAX_HIGH_CURVE_THETA, + HIGH_CURVE_HALF_CONTOUR, + MIN_LOOP_LEN, + MIN_LOOP_ASPECT_DIST, + MIN_LOOP_ASPECT_RATIO, + + /* Minutiae Link Controls */ + UNUSED_INT, /* link_table_dim */ + UNUSED_INT, /* max_link_dist */ + UNUSED_INT, /* min_theta_dist */ + MAXTRANS, /* used for removing overlaps as well */ + UNUSED_DBL, /* score_theta_norm */ + UNUSED_DBL, /* score_dist_norm */ + UNUSED_DBL, /* score_dist_weight */ + UNUSED_DBL, /* score_numerator */ + + /* False Minutiae Removal Controls */ + MAX_RMTEST_DIST_V2, + MAX_HOOK_LEN_V2, + MAX_HALF_LOOP_V2, + TRANS_DIR_PIX_V2, + SMALL_LOOP_LEN, + SIDE_HALF_CONTOUR, + INV_BLOCK_MARGIN_V2, + RM_VALID_NBR_MIN, + MAX_OVERLAP_DIST, + MAX_OVERLAP_JOIN_DIST, + MALFORMATION_STEPS_1, + MALFORMATION_STEPS_2, + MIN_MALFORMATION_RATIO, + MAX_MALFORMATION_DIST, + PORES_TRANS_R, + PORES_PERP_STEPS, + PORES_STEPS_FWD, + PORES_STEPS_BWD, + PORES_MIN_DIST2, + PORES_MAX_RATIO, + + /* Ridge Counting Controls */ + MAX_NBRS, + MAX_RIDGE_STEPS +}; + +/* Variables for conducting 8-connected neighbor analyses. */ +/* Pixel neighbor offsets: 0 1 2 3 4 5 6 7 */ /* 7 0 1 */ +int nbr8_dx[] = { 0, 1, 1, 1, 0,-1,-1,-1 }; /* 6 C 2 */ +int nbr8_dy[] = { -1,-1, 0, 1, 1, 1, 0,-1 }; /* 5 4 3 */ + +/* The chain code lookup matrix for 8-connected neighbors. */ +/* Should put this in globals. */ +int chaincodes_nbr8[]={ 3, 2, 1, + 4,-1, 0, + 5, 6, 7}; + +/* Global array of feature pixel pairs. */ +FEATURE_PATTERN feature_patterns[]= + {{RIDGE_ENDING, /* a. Ridge Ending (appearing) */ + APPEARING, + {0,0}, + {0,1}, + {0,0}}, + + {RIDGE_ENDING, /* b. Ridge Ending (disappearing) */ + DISAPPEARING, + {0,0}, + {1,0}, + {0,0}}, + + {BIFURCATION, /* c. Bifurcation (disappearing) */ + DISAPPEARING, + {1,1}, + {0,1}, + {1,1}}, + + {BIFURCATION, /* d. Bifurcation (appearing) */ + APPEARING, + {1,1}, + {1,0}, + {1,1}}, + + {BIFURCATION, /* e. Bifurcation (disappearing) */ + DISAPPEARING, + {1,0}, + {0,1}, + {1,1}}, + + {BIFURCATION, /* f. Bifurcation (disappearing) */ + DISAPPEARING, + {1,1}, + {0,1}, + {1,0}}, + + {BIFURCATION, /* g. Bifurcation (appearing) */ + APPEARING, + {1,1}, + {1,0}, + {0,1}}, + + {BIFURCATION, /* h. Bifurcation (appearing) */ + APPEARING, + {0,1}, + {1,0}, + {1,1}}, + + {BIFURCATION, /* i. Bifurcation (disappearing) */ + DISAPPEARING, + {1,0}, + {0,1}, + {1,0}}, + + {BIFURCATION, /* j. Bifurcation (appearing) */ + APPEARING, + {0,1}, + {1,0}, + {0,1}}}; --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/binar.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/binar.c.svn-base @@ -0,0 +1,249 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: BINAR.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for binarizing a grayscale image based + on an arbitrarily-sized image and its precomputed direcitonal ridge + flow (IMAP) as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + binarize_V2() + binarize_image_V2() + dirbinarize() + +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: binarize_V2 - Takes a padded grayscale input image and its associated +#cat: Direction Map and produces a binarized version of the +#cat: image. It then fills horizontal and vertical "holes" in +#cat: the binary image results. Note that the input image must +#cat: be padded sufficiently to contain in memory rotated +#cat: directional binarization grids applied to pixels along the +#cat: perimeter of the input image. + + Input: + pdata - padded input grayscale image + pw - padded width (in pixels) of input image + ph - padded height (in pixels) of input image + direction_map - 2-D vector of discrete ridge flow directions + mw - width (in blocks) of the map + mh - height (in blocks) of the map + dirbingrids - set of rotated grid offsets used for directional + binarization + lfsparms - parameters and thresholds for controlling LFS + Output: + odata - points to created (unpadded) binary image + ow - width of binary image + oh - height of binary image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int binarize_V2(unsigned char **odata, int *ow, int *oh, + unsigned char *pdata, const int pw, const int ph, + int *direction_map, const int mw, const int mh, + const ROTGRIDS *dirbingrids, const LFSPARMS *lfsparms) +{ + unsigned char *bdata; + int i, bw, bh, ret; /* return code */ + + /* 1. Binarize the padded input image using directional block info. */ + if((ret = binarize_image_V2(&bdata, &bw, &bh, pdata, pw, ph, + direction_map, mw, mh, + lfsparms->blocksize, dirbingrids))){ + return(ret); + } + + /* 2. Fill black and white holes in binary image. */ + /* LFS scans the binary image, filling holes, 3 times. */ + for(i = 0; i < lfsparms->num_fill_holes; i++) + fill_holes(bdata, bw, bh); + + /* Return binarized input image. */ + *odata = bdata; + *ow = bw; + *oh = bh; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: binarize_image_V2 - Takes a grayscale input image and its associated +#cat: Direction Map and generates a binarized version of the +#cat: image. Note that there is no "Isotropic" binarization +#cat: used in this version. + + Input: + pdata - padded input grayscale image + pw - padded width (in pixels) of input image + ph - padded height (in pixels) of input image + direction_map - 2-D vector of discrete ridge flow directions + mw - width (in blocks) of the map + mh - height (in blocks) of the map + blocksize - dimension (in pixels) of each NMAP block + dirbingrids - set of rotated grid offsets used for directional + binarization + Output: + odata - points to binary image results + ow - points to binary image width + oh - points to binary image height + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int binarize_image_V2(unsigned char **odata, int *ow, int *oh, + unsigned char *pdata, const int pw, const int ph, + const int *direction_map, const int mw, const int mh, + const int blocksize, const ROTGRIDS *dirbingrids) +{ + int ix, iy, bw, bh, bx, by, mapval; + unsigned char *bdata, *bptr; + unsigned char *pptr, *spptr; + + /* Compute dimensions of "unpadded" binary image results. */ + bw = pw - (dirbingrids->pad<<1); + bh = ph - (dirbingrids->pad<<1); + + bdata = (unsigned char *)malloc(bw*bh*sizeof(unsigned char)); + if(bdata == (unsigned char *)NULL){ + fprintf(stderr, "ERROR : binarize_image_V2 : malloc : bdata\n"); + return(-600); + } + + bptr = bdata; + spptr = pdata + (dirbingrids->pad * pw) + dirbingrids->pad; + for(iy = 0; iy < bh; iy++){ + /* Set pixel pointer to start of next row in grid. */ + pptr = spptr; + for(ix = 0; ix < bw; ix++){ + + /* Compute which block the current pixel is in. */ + bx = (int)(ix/blocksize); + by = (int)(iy/blocksize); + /* Get corresponding value in Direction Map. */ + mapval = *(direction_map + (by*mw) + bx); + /* If current block has has INVALID direction ... */ + if(mapval == INVALID_DIR) + /* Set binary pixel to white (255). */ + *bptr = WHITE_PIXEL; + /* Otherwise, if block has a valid direction ... */ + else /*if(mapval >= 0)*/ + /* Use directional binarization based on block's direction. */ + *bptr = dirbinarize(pptr, mapval, dirbingrids); + + /* Bump input and output pixel pointers. */ + pptr++; + bptr++; + } + /* Bump pointer to the next row in padded input image. */ + spptr += pw; + } + + *odata = bdata; + *ow = bw; + *oh = bh; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: dirbinarize - Determines the binary value of a grayscale pixel based +#cat: on a VALID IMAP ridge flow direction. + + CAUTION: The image to which the input pixel points must be appropriately + padded to account for the radius of the rotated grid. Otherwise, + this routine may access "unkown" memory. + + Input: + pptr - pointer to current grayscale pixel + idir - IMAP integer direction associated with the block the + current is in + dirbingrids - set of precomputed rotated grid offsets + Return Code: + BLACK_PIXEL - pixel intensity for BLACK + WHITE_PIXEL - pixel intensity of WHITE +**************************************************************************/ +int dirbinarize(const unsigned char *pptr, const int idir, + const ROTGRIDS *dirbingrids) +{ + int gx, gy, gi, cy; + int rsum, gsum, csum = 0; + int *grid; + double dcy; + + /* Assign nickname pointer. */ + grid = dirbingrids->grids[idir]; + /* Calculate center (0-oriented) row in grid. */ + dcy = (dirbingrids->grid_h-1)/(double)2.0; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + dcy = trunc_dbl_precision(dcy, TRUNC_SCALE); + cy = sround(dcy); + /* Initialize grid's pixel offset index to zero. */ + gi = 0; + /* Initialize grid's pixel accumulator to zero */ + gsum = 0; + + /* Foreach row in grid ... */ + for(gy = 0; gy < dirbingrids->grid_h; gy++){ + /* Initialize row pixel sum to zero. */ + rsum = 0; + /* Foreach column in grid ... */ + for(gx = 0; gx < dirbingrids->grid_w; gx++){ + /* Accumulate next pixel along rotated row in grid. */ + rsum += *(pptr+grid[gi]); + /* Bump grid's pixel offset index. */ + gi++; + } + /* Accumulate row sum into grid pixel sum. */ + gsum += rsum; + /* If current row is center row, then save row sum separately. */ + if(gy == cy) + csum = rsum; + } + + /* If the center row sum treated as an average is less than the */ + /* total pixel sum in the rotated grid ... */ + if((csum * dirbingrids->grid_h) < gsum) + /* Set the binary pixel to BLACK. */ + return(BLACK_PIXEL); + else + /* Otherwise set the binary pixel to WHITE. */ + return(WHITE_PIXEL); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/log.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/log.c.svn-base @@ -0,0 +1,90 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: LOG.C + AUTHOR: Michael D. Garris + DATE: 08/02/1999 + + Contains routines responsible for dynamically updating a log file + during the execution of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + open_logfile() + print2log() + close_logfile() +***********************************************************************/ + +#include + +/* If logging is on, declare global file pointer and supporting */ +/* global variable for logging intermediate results. */ +FILE *logfp; +int avrdir; +float dir_strength; +int nvalid; + +/***************************************************************************/ +/***************************************************************************/ +int open_logfile() +{ +#ifdef LOG_REPORT + if((logfp = fopen(LOG_FILE, "wb")) == NULL){ + fprintf(stderr, "ERROR : open_logfile : fopen : %s\n", LOG_FILE); + return(-1); + } +#endif + + return(0); +} + +/***************************************************************************/ +/***************************************************************************/ +void print2log(char *fmt, ...) +{ +#ifdef LOG_REPORT + va_list ap; + + va_start(ap, fmt); + vfprintf(logfp, fmt, ap); + va_end(ap); +#endif +} + +/***************************************************************************/ +/***************************************************************************/ +int close_logfile() +{ +#ifdef LOG_REPORT + if(fclose(logfp)){ + fprintf(stderr, "ERROR : close_logfile : fclose : %s\n", LOG_FILE); + return(-1); + } +#endif + + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/util.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/util.c.svn-base @@ -0,0 +1,605 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: UTIL.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + + Contains general support routines required by the NIST + Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + maxv() + minv() + minmaxs() + distance() + squared_distance() + in_int_list() + remove_from_int_list() + find_incr_position_dbl() + angle2line() + line2direction() + closest_dir_dist() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: maxv - Determines the maximum value in the given list of integers. +#cat: NOTE, the list is assumed to be NOT empty! + + Input: + list - non-empty list of integers to be searched + num - number of integers in the list + Return Code: + Maximum - maximum value in the list +**************************************************************************/ +int maxv(const int *list, const int num) +{ + int i; + int maxval; + + /* NOTE: The list is assumed to be NOT empty. */ + /* Initialize running maximum to first item in list. */ + maxval = list[0]; + + /* Foreach subsequent item in the list... */ + for(i = 1; i < num; i++){ + /* If current item is larger than running maximum... */ + if(list[i] > maxval) + /* Set running maximum to the larger item. */ + maxval = list[i]; + /* Otherwise, skip to next item. */ + } + + /* Return the resulting maximum. */ + return(maxval); +} + +/************************************************************************* +************************************************************************** +#cat: minv - Determines the minimum value in the given list of integers. +#cat: NOTE, the list is assumed to be NOT empty! + + Input: + list - non-empty list of integers to be searched + num - number of integers in the list + Return Code: + Minimum - minimum value in the list +**************************************************************************/ +int minv(const int *list, const int num) +{ + int i; + int minval; + + /* NOTE: The list is assumed to be NOT empty. */ + /* Initialize running minimum to first item in list. */ + minval = list[0]; + + /* Foreach subsequent item in the list... */ + for(i = 1; i < num; i++){ + /* If current item is smaller than running minimum... */ + if(list[i] < minval) + /* Set running minimum to the smaller item. */ + minval = list[i]; + /* Otherwise, skip to next item. */ + } + + /* Return the resulting minimum. */ + return(minval); +} + +/************************************************************************* +************************************************************************** +#cat: minmaxs - Takes a list of integers and identifies points of relative +#cat: minima and maxima. The midpoint of flat plateaus and valleys +#cat: are selected when they are detected. + + Input: + items - list of integers to be analyzed + num - number of items in the list + Output: + ominmax_val - value of the item at each minima or maxima + ominmax_type - identifies a minima as '-1' and maxima as '1' + ominmax_i - index of item's position in list + ominmax_alloc - number of allocated minima and/or maxima + ominmax_num - number of detected minima and/or maxima + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int minmaxs(int **ominmax_val, int **ominmax_type, int **ominmax_i, + int *ominmax_alloc, int *ominmax_num, + const int *items, const int num) +{ + int i, diff, state, start, loc; + int *minmax_val, *minmax_type, *minmax_i, minmax_alloc, minmax_num; + + + /* Determine maximum length for allocation of buffers. */ + /* If there are fewer than 3 items ... */ + if(num < 3){ + /* Then no min/max is possible, so set allocated length */ + /* to 0 and return. */ + *ominmax_alloc = 0; + *ominmax_num = 0; + return(0); + } + /* Otherwise, set allocation length to number of items - 2 */ + /* (one for the first item in the list, and on for the last). */ + /* Every other intermediate point can potentially represent a */ + /* min or max. */ + minmax_alloc = num - 2; + /* Allocate the buffers. */ + minmax_val = (int *)malloc(minmax_alloc * sizeof(int)); + if(minmax_val == (int *)NULL){ + fprintf(stderr, "ERROR : minmaxs : malloc : minmax_val\n"); + return(-290); + } + minmax_type = (int *)malloc(minmax_alloc * sizeof(int)); + if(minmax_type == (int *)NULL){ + free(minmax_val); + fprintf(stderr, "ERROR : minmaxs : malloc : minmax_type\n"); + return(-291); + } + minmax_i = (int *)malloc(minmax_alloc * sizeof(int)); + if(minmax_i == (int *)NULL){ + free(minmax_val); + free(minmax_type); + fprintf(stderr, "ERROR : minmaxs : malloc : minmax_i\n"); + return(-292); + } + + /* Initialize number of min/max to 0. */ + minmax_num = 0; + + /* Start witht the first item in the list. */ + i = 0; + + /* Get starting state between first pair of items. */ + diff = items[1] - items[0]; + if(diff > 0) + state = 1; + else if (diff < 0) + state = -1; + else + state = 0; + + /* Set start location to first item in list. */ + start = 0; + + /* Bump to next item in list. */ + i++; + + /* While not at the last item in list. */ + while(i < num-1){ + + /* Compute difference between next pair of items. */ + diff = items[i+1] - items[i]; + /* If items are increasing ... */ + if(diff > 0){ + /* If previously increasing ... */ + if(state == 1){ + /* Reset start to current location. */ + start = i; + } + /* If previously decreasing ... */ + else if (state == -1){ + /* Then we have incurred a minima ... */ + /* Compute midpoint of minima. */ + loc = (start + i)/2; + /* Store value at minima midpoint. */ + minmax_val[minmax_num] = items[loc]; + /* Store type code for minima. */ + minmax_type[minmax_num] = -1; + /* Store location of minima midpoint. */ + minmax_i[minmax_num++] = loc; + /* Change state to increasing. */ + state = 1; + /* Reset start location. */ + start = i; + } + /* If previously level (this state only can occur at the */ + /* beginning of the list of items) ... */ + else { + /* If more than one level state in a row ... */ + if(i-start > 1){ + /* Then consider a minima ... */ + /* Compute midpoint of minima. */ + loc = (start + i)/2; + /* Store value at minima midpoint. */ + minmax_val[minmax_num] = items[loc]; + /* Store type code for minima. */ + minmax_type[minmax_num] = -1; + /* Store location of minima midpoint. */ + minmax_i[minmax_num++] = loc; + /* Change state to increasing. */ + state = 1; + /* Reset start location. */ + start = i; + } + /* Otherwise, ignore single level state. */ + else{ + /* Change state to increasing. */ + state = 1; + /* Reset start location. */ + start = i; + } + } + } + /* If items are decreasing ... */ + else if(diff < 0){ + /* If previously decreasing ... */ + if(state == -1){ + /* Reset start to current location. */ + start = i; + } + /* If previously increasing ... */ + else if (state == 1){ + /* Then we have incurred a maxima ... */ + /* Compute midpoint of maxima. */ + loc = (start + i)/2; + /* Store value at maxima midpoint. */ + minmax_val[minmax_num] = items[loc]; + /* Store type code for maxima. */ + minmax_type[minmax_num] = 1; + /* Store location of maxima midpoint. */ + minmax_i[minmax_num++] = loc; + /* Change state to decreasing. */ + state = -1; + /* Reset start location. */ + start = i; + } + /* If previously level (this state only can occur at the */ + /* beginning of the list of items) ... */ + else { + /* If more than one level state in a row ... */ + if(i-start > 1){ + /* Then consider a maxima ... */ + /* Compute midpoint of maxima. */ + loc = (start + i)/2; + /* Store value at maxima midpoint. */ + minmax_val[minmax_num] = items[loc]; + /* Store type code for maxima. */ + minmax_type[minmax_num] = 1; + /* Store location of maxima midpoint. */ + minmax_i[minmax_num++] = loc; + /* Change state to decreasing. */ + state = -1; + /* Reset start location. */ + start = i; + } + /* Otherwise, ignore single level state. */ + else{ + /* Change state to decreasing. */ + state = -1; + /* Reset start location. */ + start = i; + } + } + } + /* Otherwise, items are level, so continue to next item pair. */ + + /* Advance to next item pair in list. */ + i++; + } + + /* Set results to output pointers. */ + *ominmax_val = minmax_val; + *ominmax_type = minmax_type; + *ominmax_i = minmax_i; + *ominmax_alloc = minmax_alloc; + *ominmax_num = minmax_num; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: distance - Takes two coordinate points and computes the +#cat: Euclidean distance between the two points. + + Input: + x1 - x-coord of first point + y1 - y-coord of first point + x2 - x-coord of second point + y2 - y-coord of second point + Return Code: + Distance - computed Euclidean distance +**************************************************************************/ +double distance(const int x1, const int y1, const int x2, const int y2) +{ + double dx, dy, dist; + + /* Compute delta x between points. */ + dx = (double)(x1 - x2); + /* Compute delta y between points. */ + dy = (double)(y1 - y2); + /* Compute the squared distance between points. */ + dist = (dx*dx) + (dy*dy); + /* Take square root of squared distance. */ + dist = sqrt(dist); + + /* Return the squared distance. */ + return(dist); +} + +/************************************************************************* +************************************************************************** +#cat: squared_distance - Takes two coordinate points and computes the +#cat: squared distance between the two points. + + Input: + x1 - x-coord of first point + y1 - y-coord of first point + x2 - x-coord of second point + y2 - y-coord of second point + Return Code: + Distance - computed squared distance +**************************************************************************/ +double squared_distance(const int x1, const int y1, const int x2, const int y2) +{ + double dx, dy, dist; + + /* Compute delta x between points. */ + dx = (double)(x1 - x2); + /* Compute delta y between points. */ + dy = (double)(y1 - y2); + /* Compute the squared distance between points. */ + dist = (dx*dx) + (dy*dy); + + /* Return the squared distance. */ + return(dist); +} + +/************************************************************************* +************************************************************************** +#cat: in_int_list - Determines if a specified value is store in a list of +#cat: integers and returns its location if found. + + Input: + item - value to search for in list + list - list of integers to be searched + len - number of integers in search list + Return Code: + Zero or greater - first location found equal to search value + Negative - search value not found in the list of integers +**************************************************************************/ +int in_int_list(const int item, const int *list, const int len) +{ + int i; + + /* Foreach item in list ... */ + for(i = 0; i < len; i++){ + /* If search item found in list ... */ + if(list[i] == item) + /* Return the location in list where found. */ + return(i); + } + + /* If we get here, then search item not found in list, */ + /* so return -1 ==> NOT FOUND. */ + return(-1); +} + +/************************************************************************* +************************************************************************** +#cat: remove_from_int_list - Takes a position index into an integer list and +#cat: removes the value from the list, collapsing the resulting +#cat: list. + + Input: + index - position of value to be removed from list + list - input list of integers + num - number of integers in the list + Output: + list - list with specified integer removed + num - decremented number of integers in list + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int remove_from_int_list(const int index, int *list, const int num) +{ + int fr, to; + + /* Make sure the requested index is within range. */ + if((index < 0) && (index >= num)){ + fprintf(stderr, "ERROR : remove_from_int_list : index out of range\n"); + return(-370); + } + + /* Slide the remaining list of integers up over top of the */ + /* position of the integer being removed. */ + for(to = index, fr = index+1; fr < num; to++, fr++) + list[to] = list[fr]; + + /* NOTE: Decrementing the number of integers remaining in the list is */ + /* the responsibility of the caller! */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: ind_incr_position_dbl - Takes a double value and a list of doubles and +#cat: determines where in the list the double may be inserted, +#cat: preserving the increasing sorted order of the list. + + Input: + val - value to be inserted into the list + list - list of double in increasing sorted order + num - number of values in the list + Return Code: + Zero or Positive - insertion position in the list +**************************************************************************/ +int find_incr_position_dbl(const double val, double *list, const int num) +{ + int i; + + /* Foreach item in double list ... */ + for(i = 0; i < num; i++){ + /* If the value is smaller than the current item in list ... */ + if(val < list[i]) + /* Then we found were to insert the value in the list maintaining */ + /* an increasing sorted order. */ + return(i); + + /* Otherwise, the value is still larger than current item, so */ + /* continue to next item in the list. */ + } + + /* Otherwise, we never found a slot within the list to insert the */ + /* the value, so place at the end of the sorted list. */ + return(i); +} + +/************************************************************************* +************************************************************************** +#cat: angle2line - Takes two coordinate points and computes the angle +#cat: to the line formed by the two points. + + Input: + fx - x-coord of first point + fy - y-coord of first point + tx - x-coord of second point + ty - y-coord of second point + Return Code: + Angle - angle to the specified line +**************************************************************************/ +double angle2line(const int fx, const int fy, const int tx, const int ty) +{ + double dx, dy, theta; + + /* Compute slope of line connecting the 2 specified points. */ + dy = (double)(fy - ty); + dx = (double)(tx - fx); + /* If delta's are sufficiently small ... */ + if((fabs(dx) < MIN_SLOPE_DELTA) && (fabs(dy) < MIN_SLOPE_DELTA)) + theta = 0.0; + /* Otherwise, compute angle to the line. */ + else + theta = atan2(dy, dx); + + /* Return the compute angle in radians. */ + return(theta); +} + +/************************************************************************* +************************************************************************** +#cat: line2direction - Takes two coordinate points and computes the +#cat: directon (on a full circle) in which the first points +#cat: to the second. + + Input: + fx - x-coord of first point (pointing from) + fy - y-coord of first point (pointing from) + tx - x-coord of second point (pointing to) + ty - y-coord of second point (pointing to) + ndirs - number of IMAP directions (in semicircle) + Return Code: + Direction - determined direction on a "full" circle +**************************************************************************/ +int line2direction(const int fx, const int fy, + const int tx, const int ty, const int ndirs) +{ + double theta, pi_factor; + int idir, full_ndirs; + static double pi2 = M_PI*2.0; + + /* Compute angle to line connecting the 2 points. */ + /* Coordinates are swapped and order of points reversed to */ + /* account for 0 direction is vertical and positive direction */ + /* is clockwise. */ + theta = angle2line(ty, tx, fy, fx); + + /* Make sure the angle is positive. */ + theta += pi2; + theta = fmod(theta, pi2); + /* Convert from radians to integer direction on range [0..(ndirsX2)]. */ + /* Multiply radians by units/radian ((ndirsX2)/(2PI)), and you get */ + /* angle in integer units. */ + /* Compute number of directions on full circle. */ + full_ndirs = ndirs<<1; + /* Compute the radians to integer direction conversion factor. */ + pi_factor = (double)full_ndirs/pi2; + /* Convert radian angle to integer direction on full circle. */ + theta *= pi_factor; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + theta = trunc_dbl_precision(theta, TRUNC_SCALE); + idir = sround(theta); + /* Make sure on range [0..(ndirsX2)]. */ + idir %= full_ndirs; + + /* Return the integer direction. */ + return(idir); +} + +/************************************************************************* +************************************************************************** +#cat: closest_dir_dist - Takes to integer IMAP directions and determines the +#cat: closest distance between them accounting for +#cat: wrap-around either at the beginning or ending of +#cat: the range of directions. + + Input: + dir1 - integer value of the first direction + dir2 - integer value of the second direction + ndirs - the number of possible directions + Return Code: + Non-negative - distance between the 2 directions +**************************************************************************/ +int closest_dir_dist(const int dir1, const int dir2, const int ndirs) +{ + int d1, d2, dist; + + /* Initialize distance to -1 = INVALID. */ + dist = INVALID_DIR; + + /* Measure shortest distance between to directions. */ + /* If both neighbors are VALID ... */ + if((dir1 >= 0)&&(dir2 >= 0)){ + /* Compute inner and outer distances to account for distances */ + /* that wrap around the end of the range of directions, which */ + /* may in fact be closer. */ + d1 = abs(dir2 - dir1); + d2 = ndirs - d1; + dist = min(d1, d2); + } + /* Otherwise one or both directions are INVALID, so ignore */ + /* and return INVALID. */ + + /* Return determined closest distance. */ + return(dist); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/free.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/free.c.svn-base @@ -0,0 +1,116 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: FREE.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + + Contains routines responsible for deallocating + memories required by the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + free_dir2rad() + free_dftwaves() + free_rotgrids() + free_dir_powers() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: free_dir2rad - Deallocates memory associated with a DIR2RAD structure + + Input: + dir2rad - pointer to memory to be freed +*************************************************************************/ +void free_dir2rad(DIR2RAD *dir2rad) +{ + free(dir2rad->cos); + free(dir2rad->sin); + free(dir2rad); +} + +/************************************************************************* +************************************************************************** +#cat: free_dftwaves - Deallocates the memory associated with a DFTWAVES +#cat: structure + + Input: + dftwaves - pointer to memory to be freed +**************************************************************************/ +void free_dftwaves(DFTWAVES *dftwaves) +{ + int i; + + for(i = 0; i < dftwaves->nwaves; i++){ + free(dftwaves->waves[i]->cos); + free(dftwaves->waves[i]->sin); + free(dftwaves->waves[i]); + } + free(dftwaves->waves); + free(dftwaves); +} + +/************************************************************************* +************************************************************************** +#cat: free_rotgrids - Deallocates the memory associated with a ROTGRIDS +#cat: structure + + Input: + rotgrids - pointer to memory to be freed +**************************************************************************/ +void free_rotgrids(ROTGRIDS *rotgrids) +{ + int i; + + for(i = 0; i < rotgrids->ngrids; i++) + free(rotgrids->grids[i]); + free(rotgrids->grids); + free(rotgrids); +} + +/************************************************************************* +************************************************************************** +#cat: free_dir_powers - Deallocate memory associated with DFT power vectors + + Input: + powers - vectors of DFT power values (N Waves X M Directions) + nwaves - number of DFT wave forms used +**************************************************************************/ +void free_dir_powers(double **powers, const int nwaves) +{ + int w; + + for(w = 0; w < nwaves; w++) + free(powers[w]); + + free(powers); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/contour.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/contour.c.svn-base @@ -0,0 +1,1274 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: CONTOUR.C + AUTHOR: Michael D. Garris + DATE: 05/11/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for extracting and analyzing + minutia feature contour lists as part of the NIST Latent + Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + allocate_contour() + free_contour() + get_high_curvature_contour() + get_centered_contour() + trace_contour() + search_contour() + next_contour_pixel() + start_scan_nbr() + next_scan_nbr() + min_contour_theta() + contour_limits() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: allocate_contour - Allocates the lists needed to represent the +#cat: contour of a minutia feature (a ridge or valley-ending). +#cat: This includes two lists of coordinate pairs. The first is +#cat: the 8-connected chain of points interior to the feature +#cat: and are called the feature's "contour points". +#cat: The second is a list or corresponding points each +#cat: adjacent to its respective feature contour point in the first +#cat: list and on the exterior of the feature. These second points +#cat: are called the feature's "edge points". Don't be confused, +#cat: both lists of points are on the "edge". The first set is +#cat: guaranteed 8-connected and the color of the feature. The +#cat: second set is NOT guaranteed to be 8-connected and its points +#cat: are opposite the color of the feature. Remeber that "feature" +#cat: means either ridge-ending (black pixels) or valley-ending +#cat: (white pixels). + + Input: + ncontour - number of items in each coordinate list to be allocated + Output: + ocontour_x - allocated x-coord list for feature's contour points + ocontour_y - allocated y-coord list for feature's contour points + ocontour_ex - allocated x-coord list for feature's edge points + ocontour_ey - allocated y-coord list for feature's edge points + Return Code: + Zero - lists were successfully allocated + Negative - system (allocation) error +**************************************************************************/ +int allocate_contour(int **ocontour_x, int **ocontour_y, + int **ocontour_ex, int **ocontour_ey, const int ncontour) +{ + int *contour_x, *contour_y, *contour_ex, *contour_ey; + + /* Allocate contour's x-coord list. */ + contour_x = (int *)malloc(ncontour*sizeof(int)); + /* If allocation error... */ + if(contour_x == (int *)NULL){ + fprintf(stderr, "ERROR : allocate_contour : malloc : contour_x\n"); + return(-180); + } + + /* Allocate contour's y-coord list. */ + contour_y = (int *)malloc(ncontour*sizeof(int)); + /* If allocation error... */ + if(contour_y == (int *)NULL){ + /* Deallocate memory allocated to this point in this routine. */ + free(contour_x); + fprintf(stderr, "ERROR : allocate_contour : malloc : contour_y\n"); + return(-181); + } + + /* Allocate contour's edge x-coord list. */ + contour_ex = (int *)malloc(ncontour*sizeof(int)); + /* If allocation error... */ + if(contour_ex == (int *)NULL){ + /* Deallocate memory allocated to this point in this routine. */ + free(contour_x); + free(contour_y); + fprintf(stderr, "ERROR : allocate_contour : malloc : contour_ex\n"); + return(-182); + } + + /* Allocate contour's edge y-coord list. */ + contour_ey = (int *)malloc(ncontour*sizeof(int)); + /* If allocation error... */ + if(contour_ey == (int *)NULL){ + /* Deallocate memory allocated to this point in this routine. */ + free(contour_x); + free(contour_y); + free(contour_ex); + fprintf(stderr, "ERROR : allocate_contour : malloc : contour_ey\n"); + return(-183); + } + + /* Otherwise, allocations successful, so assign output pointers. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: free_contour - Deallocates the lists used to represent the +#cat: contour of a minutia feature (a ridge or valley-ending). +#cat: This includes two lists of coordinate pairs. The first is +#cat: the 8-connected chain of points interior to the feature +#cat: and are called the feature's "contour points". +#cat: The second is a list or corresponding points each +#cat: adjacent to its respective feature contour point in the first +#cat: list and on the exterior of the feature. These second points +#cat: are called the feature's "edge points". + + Input: + contour_x - x-coord list for feature's contour points + contour_y - y-coord list for feature's contour points + contour_ex - x-coord list for feature's edge points + contour_ey - y-coord list for feature's edge points +**************************************************************************/ +void free_contour(int *contour_x, int *contour_y, + int *contour_ex, int *contour_ey) +{ + free(contour_x); + free(contour_y); + free(contour_ex); + free(contour_ey); +} + +/************************************************************************* +************************************************************************** +#cat: get_high_curvature_contour - Takes the pixel coordinate of a detected +#cat: minutia feature point and its corresponding/adjacent edge +#cat: pixel and attempts to extract a contour of specified length +#cat: of the feature's edge. The contour is extracted by walking +#cat: the feature's edge a specified number of steps clockwise and +#cat: then counter-clockwise. If a loop is detected while +#cat: extracting the contour, the contour of the loop is returned +#cat: with a return code of (LOOP_FOUND). If the process fails +#cat: to extract a contour of total specified length, then +#cat: the returned contour length is set to Zero, NO allocated +#cat: memory is returned in this case, and the return code is set +#cat: to Zero. An alternative implementation would be to return +#cat: the incomplete contour with a return code of (INCOMPLETE). +#cat: For now, NO allocated contour is returned in this case. + + Input: + half_contour - half the length of the extracted contour + (full-length non-loop contour = (half_contourX2)+1) + x_loc - starting x-pixel coord of feature (interior to feature) + y_loc - starting y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + ocontour_x - x-pixel coords of contour (interior to feature) + ocontour_y - y-pixel coords of contour (interior to feature) + ocontour_ex - x-pixel coords of corresponding edge (exterior to feature) + ocontour_ey - y-pixel coords of corresponding edge (exterior to feature) + oncontour - number of contour points returned + Return Code: + Zero - resulting contour was successfully extracted or is empty + LOOP_FOUND - resulting contour forms a complete loop + Negative - system error +**************************************************************************/ +int get_high_curvature_contour(int **ocontour_x, int **ocontour_y, + int **ocontour_ex, int **ocontour_ey, int *oncontour, + const int half_contour, + const int x_loc, const int y_loc, + const int x_edge, const int y_edge, + unsigned char *bdata, const int iw, const int ih) +{ + int max_contour; + int *half1_x, *half1_y, *half1_ex, *half1_ey, nhalf1; + int *half2_x, *half2_y, *half2_ex, *half2_ey, nhalf2; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int i, j, ret; + + /* Compute maximum length of complete contour */ + /* (2 half contours + feature point). */ + max_contour = (half_contour<<1) + 1; + + /* Initialize output contour length to 0. */ + *oncontour = 0; + + /* Get 1st half contour with clockwise neighbor trace. */ + if((ret = trace_contour(&half1_x, &half1_y, &half1_ex, &half1_ey, &nhalf1, + half_contour, x_loc, y_loc, x_loc, y_loc, x_edge, y_edge, + SCAN_CLOCKWISE, bdata, iw, ih))){ + + /* If trace was not possible ... */ + if(ret == IGNORE) + /* Return, with nothing allocated and contour length equal to 0. */ + return(0); + + /* If 1st half contour forms a loop ... */ + if(ret == LOOP_FOUND){ + /* Need to reverse the 1st half contour so that the points are */ + /* in consistent order. */ + /* We need to add the original feature point to the list, so */ + /* set new contour length to one plus length of 1st half contour. */ + ncontour = nhalf1+1; + /* Allocate new contour list. */ + if((ret = allocate_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, ncontour))){ + /* If allcation error, then deallocate memory allocated to */ + /* this point in this routine. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return error code. */ + return(ret); + } + + /* Otherwise, we have the new contour allocated, so store the */ + /* original feature point. */ + contour_x[0] = x_loc; + contour_y[0] = y_loc; + contour_ex[0] = x_edge; + contour_ey[0] = y_edge; + + /* Now store the first half contour in reverse order. */ + for(i = 1, j = nhalf1-1; i < ncontour; i++, j--){ + contour_x[i] = half1_x[j]; + contour_y[i] = half1_y[j]; + contour_ex[i] = half1_ex[j]; + contour_ey[i] = half1_ey[j]; + } + + /* Deallocate the first half contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + + /* Assign the output pointers. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + *oncontour = ncontour; + + /* Return LOOP_FOUND for further processing. */ + return(LOOP_FOUND); + } + + /* Otherwise, return the system error code from the first */ + /* call to trace_contour. */ + return(ret); + } + + /* If 1st half contour not complete ... */ + if(nhalf1 < half_contour){ + /* Deallocate the partial contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return, with nothing allocated and contour length equal to 0. */ + return(0); + } + + /* Otherwise, we have a complete 1st half contour... */ + /* Get 2nd half contour with counter-clockwise neighbor trace. */ + /* Use the last point from the first contour trace as the */ + /* point to test for a loop when tracing the second contour. */ + if((ret = trace_contour(&half2_x, &half2_y, &half2_ex, &half2_ey, &nhalf2, + half_contour, half1_x[nhalf1-1], half1_y[nhalf1-1], + x_loc, y_loc, x_edge, y_edge, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih))){ + + /* If 2nd trace was not possible ... */ + if(ret == IGNORE){ + /* Deallocate the 1st half contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return, with nothing allocated and contour length equal to 0. */ + return(0); + } + + /* If non-zero return code is NOT LOOP_FOUND, then system error ... */ + if(ret != LOOP_FOUND){ + /* Deallocate the 1st half contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return system error. */ + return(ret); + } + } + + /* If 2nd half NOT a loop AND not complete ... */ + if((ret != LOOP_FOUND) && (nhalf2 < half_contour)){ + /* Deallocate both half contours. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + free_contour(half2_x, half2_y, half2_ex, half2_ey); + /* Return, with nothing allocated and contour length equal to 0. */ + return(0); + } + + /* Otherwise we have a full 1st half contour and a 2nd half contour */ + /* that is either a loop or complete. In either case we need to */ + /* concatenate the two half contours into one longer contour. */ + + /* Allocate output contour list. Go ahead and allocate the */ + /* "max_contour" amount even though the resulting contour will */ + /* likely be shorter if it forms a loop. */ + if((ret = allocate_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, max_contour))){ + /* If allcation error, then deallocate memory allocated to */ + /* this point in this routine. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + free_contour(half2_x, half2_y, half2_ex, half2_ey); + /* Return error code. */ + return(ret); + } + + /* Set the current contour point counter to 0 */ + ncontour = 0; + + /* Copy 1st half contour into output contour buffers. */ + /* This contour was collected clockwise, so it's points */ + /* are entered in reverse order of the trace. The result */ + /* is the first point in the output contour if farthest */ + /* from the starting feature point. */ + for(i = 0, j = nhalf1-1; i < nhalf1; i++, j--){ + contour_x[i] = half1_x[j]; + contour_y[i] = half1_y[j]; + contour_ex[i] = half1_ex[j]; + contour_ey[i] = half1_ey[j]; + ncontour++; + } + + /* Deallocate 1st half contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + + /* Next, store starting feature point into output contour buffers. */ + contour_x[nhalf1] = x_loc; + contour_y[nhalf1] = y_loc; + contour_ex[nhalf1] = x_edge; + contour_ey[nhalf1] = y_edge; + ncontour++; + + /* Now, append 2nd half contour to permanent contour buffers. */ + for(i = 0, j = nhalf1+1; i < nhalf2; i++, j++){ + contour_x[j] = half2_x[i]; + contour_y[j] = half2_y[i]; + contour_ex[j] = half2_ex[i]; + contour_ey[j] = half2_ey[i]; + ncontour++; + } + + /* Deallocate 2nd half contour. */ + free_contour(half2_x, half2_y, half2_ex, half2_ey); + + /* Assign outputs contour to output ponters. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + *oncontour = ncontour; + + /* Return the resulting return code form the 2nd call to trace_contour */ + /* (the value will either be 0 or LOOP_FOUND). */ + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: get_centered_contour - Takes the pixel coordinate of a detected +#cat: minutia feature point and its corresponding/adjacent edge +#cat: pixel and attempts to extract a contour of specified length +#cat: of the feature's edge. The contour is extracted by walking +#cat: the feature's edge a specified number of steps clockwise and +#cat: then counter-clockwise. If a loop is detected while +#cat: extracting the contour, no contour is returned with a return +#cat: code of (LOOP_FOUND). If the process fails to extract a +#cat: a complete contour, a code of INCOMPLETE is returned. + + Input: + half_contour - half the length of the extracted contour + (full-length non-loop contour = (half_contourX2)+1) + x_loc - starting x-pixel coord of feature (interior to feature) + y_loc - starting y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + ocontour_x - x-pixel coords of contour (interior to feature) + ocontour_y - y-pixel coords of contour (interior to feature) + ocontour_ex - x-pixel coords of corresponding edge (exterior to feature) + ocontour_ey - y-pixel coords of corresponding edge (exterior to feature) + oncontour - number of contour points returned + Return Code: + Zero - resulting contour was successfully extracted or is empty + LOOP_FOUND - resulting contour forms a complete loop + IGNORE - contour could not be traced due to problem starting + conditions + INCOMPLETE - resulting contour was not long enough + Negative - system error +**************************************************************************/ +int get_centered_contour(int **ocontour_x, int **ocontour_y, + int **ocontour_ex, int **ocontour_ey, int *oncontour, + const int half_contour, + const int x_loc, const int y_loc, + const int x_edge, const int y_edge, + unsigned char *bdata, const int iw, const int ih) +{ + int max_contour; + int *half1_x, *half1_y, *half1_ex, *half1_ey, nhalf1; + int *half2_x, *half2_y, *half2_ex, *half2_ey, nhalf2; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int i, j, ret; + + /* Compute maximum length of complete contour */ + /* (2 half contours + feature point). */ + max_contour = (half_contour<<1) + 1; + + /* Initialize output contour length to 0. */ + *oncontour = 0; + + /* Get 1st half contour with clockwise neighbor trace. */ + ret = trace_contour(&half1_x, &half1_y, &half1_ex, &half1_ey, &nhalf1, + half_contour, x_loc, y_loc, x_loc, y_loc, x_edge, y_edge, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible ... */ + if(ret == IGNORE) + /* Return IGNORE, with nothing allocated. */ + return(IGNORE); + + /* If 1st half contour forms a loop ... */ + if(ret == LOOP_FOUND){ + /* Deallocate loop's contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return LOOP_FOUND, with nothing allocated. */ + return(LOOP_FOUND); + } + + /* If 1st half contour not complete ... */ + if(nhalf1 < half_contour){ + /* Deallocate the partial contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return, with nothing allocated and contour length equal to 0. */ + return(INCOMPLETE); + } + + /* Otherwise, we have a complete 1st half contour... */ + /* Get 2nd half contour with counter-clockwise neighbor trace. */ + /* Use the last point from the first contour trace as the */ + /* point to test for a loop when tracing the second contour. */ + ret = trace_contour(&half2_x, &half2_y, &half2_ex, &half2_ey, &nhalf2, + half_contour, half1_x[nhalf1-1], half1_y[nhalf1-1], + x_loc, y_loc, x_edge, y_edge, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred on 2nd trace ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If 2nd trace was not possible ... */ + if(ret == IGNORE){ + /* Deallocate the 1st half contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + /* Return, with nothing allocated and contour length equal to 0. */ + return(IGNORE); + } + + /* If 2nd trace forms a loop ... */ + if(ret == LOOP_FOUND){ + /* Deallocate 1st and 2nd half contours. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + free_contour(half2_x, half2_y, half2_ex, half2_ey); + /* Return LOOP_FOUND, with nothing allocated. */ + return(LOOP_FOUND); + } + + /* If 2nd half contour not complete ... */ + if(nhalf2 < half_contour){ + /* Deallocate 1st and 2nd half contours. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + free_contour(half2_x, half2_y, half2_ex, half2_ey); + /* Return, with nothing allocated and contour length equal to 0. */ + return(INCOMPLETE); + } + + /* Otherwise we have a full 1st half contour and a 2nd half contour */ + /* that do not form a loop and are complete. We now need to */ + /* concatenate the two half contours into one longer contour. */ + + /* Allocate output contour list. */ + if((ret = allocate_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, max_contour))){ + /* If allcation error, then deallocate memory allocated to */ + /* this point in this routine. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + free_contour(half2_x, half2_y, half2_ex, half2_ey); + /* Return error code. */ + return(ret); + } + + /* Set the current contour point counter to 0 */ + ncontour = 0; + + /* Copy 1st half contour into output contour buffers. */ + /* This contour was collected clockwise, so it's points */ + /* are entered in reverse order of the trace. The result */ + /* is the first point in the output contour if farthest */ + /* from the starting feature point. */ + for(i = 0, j = nhalf1-1; i < nhalf1; i++, j--){ + contour_x[i] = half1_x[j]; + contour_y[i] = half1_y[j]; + contour_ex[i] = half1_ex[j]; + contour_ey[i] = half1_ey[j]; + ncontour++; + } + + /* Deallocate 1st half contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); + + /* Next, store starting feature point into output contour buffers. */ + contour_x[nhalf1] = x_loc; + contour_y[nhalf1] = y_loc; + contour_ex[nhalf1] = x_edge; + contour_ey[nhalf1] = y_edge; + ncontour++; + + /* Now, append 2nd half contour to permanent contour buffers. */ + for(i = 0, j = nhalf1+1; i < nhalf2; i++, j++){ + contour_x[j] = half2_x[i]; + contour_y[j] = half2_y[i]; + contour_ex[j] = half2_ex[i]; + contour_ey[j] = half2_ey[i]; + ncontour++; + } + + /* Deallocate 2nd half contour. */ + free_contour(half2_x, half2_y, half2_ex, half2_ey); + + /* Assign outputs contour to output ponters. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + *oncontour = ncontour; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: start_scan_nbr - Takes a two pixel coordinates that are either +#cat: aligned north-to-south or east-to-west, and returns the +#cat: position the second pixel is in realtionship to the first. +#cat: The positions returned are based on 8-connectedness. +#cat: NOTE, this routine does NOT account for diagonal positions. + + Input: + x_prev - x-coord of first point + y_prev - y-coord of first point + x_next - x-coord of second point + y_next - y-coord of second point + Return Code: + NORTH - second pixel above first + SOUTH - second pixel below first + EAST - second pixel right of first + WEST - second pixel left of first +**************************************************************************/ +static int start_scan_nbr(const int x_prev, const int y_prev, + const int x_next, const int y_next) +{ + if((x_prev==x_next) && (y_next > y_prev)) + return(SOUTH); + else if ((x_prev==x_next) && (y_next < y_prev)) + return(NORTH); + else if ((x_next > x_prev) && (y_prev==y_next)) + return(EAST); + else if ((x_next < x_prev) && (y_prev==y_next)) + return(WEST); + + /* Added by MDG on 03-16-05 */ + /* Should never reach here. Added to remove compiler warning. */ + return(INVALID_DIR); /* -1 */ +} + +/************************************************************************* +************************************************************************** +#cat: next_scan_nbr - Advances the given 8-connected neighbor index +#cat: on location in the specifiec direction (clockwise or +#cat: counter-clockwise). + + Input: + nbr_i - current 8-connected neighbor index + scan_clock - direction in which the neighbor index is to be advanced + Return Code: + Next neighbor - 8-connected index of next neighbor +**************************************************************************/ +static int next_scan_nbr(const int nbr_i, const int scan_clock) +{ + int new_i; + + /* If scanning neighbors clockwise ... */ + if(scan_clock == SCAN_CLOCKWISE) + /* Advance one neighbor clockwise. */ + new_i = (nbr_i+1)%8; + /* Otherwise, scanning neighbors counter-clockwise ... */ + else + /* Advance one neighbor counter-clockwise. */ + /* There are 8 pixels in the neighborhood, so to */ + /* decrement with wrapping from 0 around to 7, add */ + /* the nieghbor index by 7 and mod with 8. */ + new_i = (nbr_i+7)%8; + + /* Return the new neighbor index. */ + return(new_i); +} + +/************************************************************************* +************************************************************************** +#cat: next_contour_pixel - Takes a pixel coordinate of a point determined +#cat: to be on the interior edge of a feature (ridge or valley- +#cat: ending), and attempts to locate a neighboring pixel on the +#cat: feature's contour. Neighbors of the current feature pixel +#cat: are searched in a specified direction (clockwise or counter- +#cat: clockwise) and the first pair of adjacent/neigboring pixels +#cat: found with the first pixel having the color of the feature +#cat: and the second the opposite color are returned as the next +#cat: point on the contour. One exception happens when the new +#cat: point is on an "exposed" corner. + + Input: + cur_x_loc - x-pixel coord of current point on feature's + interior contour + cur_y_loc - y-pixel coord of current point on feature's + interior contour + cur_x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + cur_y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + scan_clock - direction in which neighboring pixels are to be scanned + for the next contour pixel + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + next_x_loc - x-pixel coord of next point on feature's interior contour + next_y_loc - y-pixel coord of next point on feature's interior contour + next_x_edge - x-pixel coord of corresponding edge (exterior to feature) + next_y_edge - y-pixel coord of corresponding edge (exterior to feature) + Return Code: + TRUE - next contour point found and returned + FALSE - next contour point NOT found +**************************************************************************/ +/*************************************************************************/ +static int next_contour_pixel(int *next_x_loc, int *next_y_loc, + int *next_x_edge, int *next_y_edge, + const int cur_x_loc, const int cur_y_loc, + const int cur_x_edge, const int cur_y_edge, + const int scan_clock, + unsigned char *bdata, const int iw, const int ih) +{ + int feature_pix, edge_pix; + int prev_nbr_pix, prev_nbr_x, prev_nbr_y; + int cur_nbr_pix, cur_nbr_x, cur_nbr_y; + int ni, nx, ny, npix; + int nbr_i, i; + + /* Get the feature's pixel value. */ + feature_pix = *(bdata + (cur_y_loc * iw) + cur_x_loc); + /* Get the feature's edge pixel value. */ + edge_pix = *(bdata + (cur_y_edge * iw) + cur_x_edge); + + /* Get the nieghbor position of the feature's edge pixel in relationship */ + /* to the feature's actual position. */ + /* REMEBER: The feature's position is always interior and on a ridge */ + /* ending (black pixel) or (for bifurcations) on a valley ending (white */ + /* pixel). The feature's edge pixel is an adjacent pixel to the feature */ + /* pixel that is exterior to the ridge or valley ending and opposite in */ + /* pixel value. */ + nbr_i = start_scan_nbr(cur_x_loc, cur_y_loc, cur_x_edge, cur_y_edge); + + /* Set current neighbor scan pixel to the feature's edge pixel. */ + cur_nbr_x = cur_x_edge; + cur_nbr_y = cur_y_edge; + cur_nbr_pix = edge_pix; + + /* Foreach pixel neighboring the feature pixel ... */ + for(i = 0; i < 8; i++){ + + /* Set current neighbor scan pixel to previous scan pixel. */ + prev_nbr_x = cur_nbr_x; + prev_nbr_y = cur_nbr_y; + prev_nbr_pix = cur_nbr_pix; + + /* Bump pixel neighbor index clockwise or counter-clockwise. */ + nbr_i = next_scan_nbr(nbr_i, scan_clock); + + /* Set current scan pixel to the new neighbor. */ + /* REMEMBER: the neighbors are being scanned around the original */ + /* feature point. */ + cur_nbr_x = cur_x_loc + nbr8_dx[nbr_i]; + cur_nbr_y = cur_y_loc + nbr8_dy[nbr_i]; + + /* If new neighbor is not within image boundaries... */ + if((cur_nbr_x < 0) || (cur_nbr_x >= iw) || + (cur_nbr_y < 0) || (cur_nbr_y >= ih)) + /* Return (FALSE==>Failure) if neighbor out of bounds. */ + return(FALSE); + + /* Get the new neighbor's pixel value. */ + cur_nbr_pix = *(bdata + (cur_nbr_y * iw) + cur_nbr_x); + + /* If the new neighbor's pixel value is the same as the feature's */ + /* pixel value AND the previous neighbor's pixel value is the same */ + /* as the features's edge, then we have "likely" found our next */ + /* contour pixel. */ + if((cur_nbr_pix == feature_pix) && (prev_nbr_pix == edge_pix)){ + + /* Check to see if current neighbor is on the corner of the */ + /* neighborhood, and if so, test to see if it is "exposed". */ + /* The neighborhood corners have odd neighbor indicies. */ + if(nbr_i % 2){ + /* To do this, look ahead one more neighbor pixel. */ + ni = next_scan_nbr(nbr_i, scan_clock); + nx = cur_x_loc + nbr8_dx[ni]; + ny = cur_y_loc + nbr8_dy[ni]; + /* If new neighbor is not within image boundaries... */ + if((nx < 0) || (nx >= iw) || + (ny < 0) || (ny >= ih)) + /* Return (FALSE==>Failure) if neighbor out of bounds. */ + return(FALSE); + npix = *(bdata + (ny * iw) + nx); + + /* If the next neighbor's value is also the same as the */ + /* feature's pixel, then corner is NOT exposed... */ + if(npix == feature_pix){ + /* Assign the current neighbor pair to the output pointers. */ + *next_x_loc = cur_nbr_x; + *next_y_loc = cur_nbr_y; + *next_x_edge = prev_nbr_x; + *next_y_edge = prev_nbr_y; + /* Return TRUE==>Success. */ + return(TRUE); + } + /* Otherwise, corner pixel is "exposed" so skip it. */ + else{ + /* Skip current corner neighbor by resetting it to the */ + /* next neighbor, which upon the iteration will immediately */ + /* become the previous neighbor. */ + cur_nbr_x = nx; + cur_nbr_y = ny; + cur_nbr_pix = npix; + /* Advance neighbor index. */ + nbr_i = ni; + /* Advance neighbor count. */ + i++; + } + } + /* Otherwise, current neighbor is not a corner ... */ + else{ + /* Assign the current neighbor pair to the output pointers. */ + *next_x_loc = cur_nbr_x; + *next_y_loc = cur_nbr_y; + *next_x_edge = prev_nbr_x; + *next_y_edge = prev_nbr_y; + /* Return TRUE==>Success. */ + return(TRUE); + } + } + } + + /* If we get here, then we did not find the next contour pixel */ + /* within the 8 neighbors of the current feature pixel so */ + /* return (FALSE==>Failure). */ + /* NOTE: This must mean we found a single isolated pixel. */ + /* Perhaps this should be filled? */ + return(FALSE); +} + +/************************************************************************* +************************************************************************** +#cat: trace_contour - Takes the pixel coordinate of a detected minutia +#cat: feature point and its corresponding/adjacent edge pixel +#cat: and extracts a contour (up to a specified maximum length) +#cat: of the feature's edge in either a clockwise or counter- +#cat: clockwise direction. A second point is specified, such that +#cat: if this point is encounted while extracting the contour, +#cat: it is to be assumed that a loop has been found and a code +#cat: of (LOOP_FOUND) is returned with the contour. By independently +#cat: specifying this point, successive calls can be made to +#cat: this routine from the same starting point, and loops across +#cat: successive calls can be detected. + + Input: + max_len - maximum length of contour to be extracted + x_loop - x-pixel coord of point, if encountered, triggers LOOP_FOUND + y_loop - y-pixel coord of point, if encountered, triggers LOOP_FOUND + x_loc - starting x-pixel coord of feature (interior to feature) + y_loc - starting y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel (exterior to feature) + scan_clock - direction in which neighboring pixels are to be scanned + for the next contour pixel + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + ocontour_x - x-pixel coords of contour (interior to feature) + ocontour_y - y-pixel coords of contour (interior to feature) + ocontour_ex - x-pixel coords of corresponding edge (exterior to feature) + ocontour_ey - y-pixel coords of corresponding edge (exterior to feature) + oncontour - number of contour points returned + Return Code: + Zero - resulting contour was successfully allocated and extracted + LOOP_FOUND - resulting contour forms a complete loop + IGNORE - trace is not possible due to state of inputs + Negative - system error +**************************************************************************/ +int trace_contour(int **ocontour_x, int **ocontour_y, + int **ocontour_ex, int **ocontour_ey, int *oncontour, + const int max_len, const int x_loop, const int y_loop, + const int x_loc, const int y_loc, + const int x_edge, const int y_edge, + const int scan_clock, + unsigned char *bdata, const int iw, const int ih) +{ + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int cur_x_loc, cur_y_loc; + int cur_x_edge, cur_y_edge; + int next_x_loc, next_y_loc; + int next_x_edge, next_y_edge; + int i, ret; + + /* Check to make sure that the feature and edge values are opposite. */ + if(*(bdata+(y_loc*iw)+x_loc) == + *(bdata+(y_edge*iw)+x_edge)) + /* If not opposite, then the trace will not work, so return IGNORE. */ + return(IGNORE); + + /* Allocate contour buffers. */ + if((ret = allocate_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, max_len))){ + /* If allocation error, return code. */ + return(ret); + } + + /* Set pixel counter to 0. */ + ncontour = 0; + + /* Set up for finding first contour pixel. */ + cur_x_loc = x_loc; + cur_y_loc = y_loc; + cur_x_edge = x_edge; + cur_y_edge = y_edge; + + /* Foreach pixel to be collected on the feature's contour... */ + for(i = 0; i < max_len; i++){ + /* Find the next contour pixel. */ + if(next_contour_pixel(&next_x_loc, &next_y_loc, + &next_x_edge, &next_y_edge, + cur_x_loc, cur_y_loc, + cur_x_edge, cur_y_edge, + scan_clock, bdata, iw, ih)){ + + /* If we trace back around to the specified starting */ + /* feature location... */ + if((next_x_loc == x_loop) && (next_y_loc == y_loop)){ + /* Then we have found a loop, so return what we */ + /* have traced to this point. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + *oncontour = ncontour; + return(LOOP_FOUND); + } + + /* Otherwise, we found another point on our feature's contour, */ + /* so store the new contour point. */ + contour_x[i] = next_x_loc; + contour_y[i] = next_y_loc; + contour_ex[i] = next_x_edge; + contour_ey[i] = next_y_edge; + /* Bump the number of points stored. */ + ncontour++; + + /* Set up for finding next contour pixel. */ + cur_x_loc = next_x_loc; + cur_y_loc = next_y_loc; + cur_x_edge = next_x_edge; + cur_y_edge = next_y_edge; + } + /* Otherwise, no new contour point found ... */ + else{ + /* So, stop short and return the number of pixels found */ + /* on the contour to this point. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + *oncontour = ncontour; + + /* Return normally. */ + return(0); + } + } + + /* If we get here, we successfully found the maximum points we */ + /* were looking for on the feature contour, so assign the contour */ + /* buffers to the output pointers and return. */ + *ocontour_x = contour_x; + *ocontour_y = contour_y; + *ocontour_ex = contour_ex; + *ocontour_ey = contour_ey; + *oncontour = ncontour; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: search_contour - Walk the contour of a minutia feature starting at a +#cat: specified point on the feature and walking N steps in the +#cat: specified direction (clockwise or counter-clockwise), looking +#cat: for a second specified point. In this code, "feature" is +#cat: consistently referring to either the black interior edge of +#cat: a ridge-ending or the white interior edge of a valley-ending +#cat: (bifurcation). The term "edge of the feature" refers to +#cat: neighboring pixels on the "exterior" edge of the feature. +#cat: So "edge" pixels are opposite in color from the interior +#cat: feature pixels. + + Input: + x_search - x-pixel coord of point being searched for + y_search - y-pixel coord of point being searched for + search_len - number of step to walk contour in search + x_loc - starting x-pixel coord of feature (interior to feature) + y_loc - starting y-pixel coord of feature (interior to feature) + x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + scan_clock - direction in which neighbor pixels are to be scanned + (clockwise or counter-clockwise) + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Return Code: + NOT_FOUND - desired pixel not found along N steps of feature's contour + FOUND - desired pixel WAS found along N steps of feature's contour +**************************************************************************/ +int search_contour(const int x_search, const int y_search, + const int search_len, + const int x_loc, const int y_loc, + const int x_edge, const int y_edge, + const int scan_clock, + unsigned char *bdata, const int iw, const int ih) +{ + int cur_x_loc, cur_y_loc; + int cur_x_edge, cur_y_edge; + int next_x_loc, next_y_loc; + int next_x_edge, next_y_edge; + int i; + + /* Set up for finding first contour pixel. */ + cur_x_loc = x_loc; + cur_y_loc = y_loc; + cur_x_edge = x_edge; + cur_y_edge = y_edge; + + /* Foreach point to be collected on the feature's contour... */ + for(i = 0; i < search_len; i++){ + /* Find the next contour pixel. */ + if(next_contour_pixel(&next_x_loc, &next_y_loc, + &next_x_edge, &next_y_edge, + cur_x_loc, cur_y_loc, + cur_x_edge, cur_y_edge, + scan_clock, bdata, iw, ih)){ + + /* If we find the point we are looking for on the contour... */ + if((next_x_loc == x_search) && (next_y_loc == y_search)){ + /* Then return FOUND. */ + return(FOUND); + } + + /* Otherwise, set up for finding next contour pixel. */ + cur_x_loc = next_x_loc; + cur_y_loc = next_y_loc; + cur_x_edge = next_x_edge; + cur_y_edge = next_y_edge; + } + /* Otherwise, no new contour point found ... */ + else{ + /* So, stop searching, and return NOT_FOUND. */ + return(NOT_FOUND); + } + } + + /* If we get here, we successfully searched the maximum points */ + /* without finding our desired point, so return NOT_FOUND. */ + return(NOT_FOUND); +} + +/************************************************************************* +************************************************************************** +#cat: min_contour_theta - Takes a contour list and analyzes it locating the +#cat: point at which the contour has highest curvature +#cat: (or minimum interior angle). The angle of curvature is +#cat: computed by searching a majority of points on the contour. +#cat: At each of these points, a left and right segment (or edge) +#cat: are extended out N number of pixels from the center point +#cat: on the contour. The angle is formed between the straight line +#cat: connecting the center point to the end point on the left edge +#cat: and the line connecting the center point to the end of the +#cat: right edge. The point of highest curvature is determined +#cat: by locating the where the minimum of these angles occurs. + + Input: + angle_edge - length of the left and right edges extending from a + common/centered pixel on the contour + contour_x - x-coord list for contour points + contour_y - y-coord list for contour points + ncontour - number of points in contour + Output: + omin_i - index of contour point where minimum occurred + omin_theta - minimum angle found along the contour + Return Code: + Zero - minimum angle successfully located + IGNORE - ignore the contour + Negative - system error +**************************************************************************/ +int min_contour_theta(int *omin_i, double *omin_theta, + const int angle_edge, const int *contour_x, + const int *contour_y, const int ncontour) +{ + int pleft, pcenter, pright; + double theta1, theta2, dtheta; + int min_i; + double min_theta; + + /* If the contour length is too short for processing... */ + if(ncontour < (angle_edge<<1)+1) + /* Return IGNORE. */ + return(IGNORE); + + /* Intialize running minimum values. */ + min_theta = M_PI; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when comparing doubles. */ + min_theta = trunc_dbl_precision(min_theta, TRUNC_SCALE); + min_i = -1; + + /* Set left angle point to first contour point. */ + pleft = 0; + /* Set center angle point to "angle_edge" points into contour. */ + pcenter = angle_edge; + /* Set right angle point to "angle_edge" points from pcenter. */ + pright = pcenter + angle_edge; + + /* Loop until the right angle point exceeds the contour list. */ + while(pright < ncontour){ + /* Compute angle to first edge line (connecting pcenter to pleft). */ + theta1 = angle2line(contour_x[pcenter],contour_y[pcenter], + contour_x[pleft],contour_y[pleft]); + /* Compute angle to second edge line (connecting pcenter to pright). */ + theta2 = angle2line(contour_x[pcenter],contour_y[pcenter], + contour_x[pright],contour_y[pright]); + + /* Compute delta between angles accounting for an inner */ + /* and outer distance between the angles. */ + dtheta = fabs(theta2 - theta1); + dtheta = min(dtheta, (M_PI*2.0)-dtheta); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when comparing doubles. */ + dtheta = trunc_dbl_precision(dtheta, TRUNC_SCALE); + + /* Keep track of running minimum theta. */ + if(dtheta < min_theta){ + min_i = pcenter; + min_theta = dtheta; + } + + /* Bump to next points on contour. */ + pleft++; + pcenter++; + pright++; + } + + /* If no minimum found (then contour is perfectly flat) so minimum */ + /* to center point on contour. */ + if(min_i == -1){ + *omin_i = ncontour>>1; + *omin_theta = min_theta; + } + else{ + /* Assign minimum theta information to output pointers. */ + *omin_i = min_i; + *omin_theta = min_theta; + } + + /* Return successfully. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: contour_limits - Determines the X and Y coordinate limits of the +#cat: given contour list. + + Input: + contour_x - x-coord list for contour points + contour_y - y-coord list for contour points + ncontour - number of points in contour + Output: + xmin - left-most x-coord in contour + ymin - top-most y-coord in contour + xmax - right-most x-coord in contour + ymax - bottom-most y-coord in contour +**************************************************************************/ +void contour_limits(int *xmin, int *ymin, int *xmax, int *ymax, + const int *contour_x, const int *contour_y, const int ncontour) +{ + /* Find the minimum x-coord from the list of contour points. */ + *xmin = minv(contour_x, ncontour); + /* Find the minimum y-coord from the list of contour points. */ + *ymin = minv(contour_y, ncontour); + /* Find the maximum x-coord from the list of contour points. */ + *xmax = maxv(contour_x, ncontour); + /* Find the maximum y-coord from the list of contour points. */ + *ymax = maxv(contour_y, ncontour); +} + +/************************************************************************* +************************************************************************** +#cat: fix_edge_pixel_pair - Takes a pair of pixel points with the first +#cat: pixel on a feature and the second adjacent and off the feature, +#cat: determines if the pair neighbor diagonally. If they do, their +#cat: locations are adjusted so that the resulting pair retains the +#cat: same pixel values, but are neighboring either to the N,S,E or W. +#cat: This routine is needed in order to prepare the pixel pair for +#cat: contour tracing. + + Input: + feat_x - pointer to x-pixel coord on feature + feat_y - pointer to y-pixel coord on feature + edge_x - pointer to x-pixel coord on edge of feature + edge_y - pointer to y-pixel coord on edge of feature + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + feat_x - pointer to resulting x-pixel coord on feature + feat_y - pointer to resulting y-pixel coord on feature + edge_x - pointer to resulting x-pixel coord on edge of feature + edge_y - pointer to resulting y-pixel coord on edge of feature +**************************************************************************/ +void fix_edge_pixel_pair(int *feat_x, int *feat_y, int *edge_x, int *edge_y, + unsigned char *bdata, const int iw, const int ih) +{ + int dx, dy; + int px, py, cx, cy; + int feature_pix; + + /* Get the pixel value of the feature. */ + feature_pix = *(bdata + ((*feat_y) * iw) + (*feat_x)); + + /* Store the input points to current and previous points. */ + cx = *feat_x; + cy = *feat_y; + px = *edge_x; + py = *edge_y; + + /* Compute detlas between current and previous point. */ + dx = px - cx; + dy = py - cy; + + /* If previous point (P) is diagonal neighbor of */ + /* current point (C)... This is a problem because */ + /* the contour tracing routine requires that the */ + /* "edge" pixel be north, south, east, or west of */ + /* of the feature point. If the previous pixel is */ + /* diagonal neighbor, then we need to adjust either */ + /* the positon of te previous or current pixel. */ + if((abs(dx)==1) && (abs(dy)==1)){ + /* Then we have one of the 4 following conditions: */ + /* */ + /* *C C* */ + /* 1. P* 2. P* 3. *P 4. *P */ + /* *C C* */ + /* */ + /* dx = -1 -1 1 1 */ + /* dy = 1 -1 -1 1 */ + /* */ + /* Want to test values in positions of '*': */ + /* Let point P == (px, py) */ + /* p1 == '*' positon where x changes */ + /* p2 == '*' positon where y changes */ + /* */ + /* p1 = px+1,py px+1,py px-1,py px-1,py */ + /* p2 = px,py-1 px,py+1 px,py+1 px,py-1 */ + /* */ + /* These can all be rewritten: */ + /* p1 = px-dx,py */ + /* p2 = px,py-dy */ + + /* Check if 'p1' is NOT the value we are searching for... */ + if(*(bdata+(py*iw)+(px-dx)) != feature_pix) + /* Then set x-coord of edge pixel to p1. */ + px -= dx; + /* Check if 'p2' is NOT the value we are searching for... */ + else if(*(bdata+((py-dy)*iw)+px) != feature_pix) + /* Then set y-coord of edge pixel to p2. */ + py -= dy; + /* Otherwise, the current pixel 'C' is exposed on a corner ... */ + else{ + /* Set pixel 'C' to 'p1', which also has the pixel */ + /* value we are searching for. */ + cy += dy; + } + + /* Set the pointers to the resulting values. */ + *feat_x = cx; + *feat_y = cy; + *edge_x = px; + *edge_y = py; + } + + /* Otherwise, nothing has changed. */ +} --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/sort.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/sort.c.svn-base @@ -0,0 +1,320 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: SORT.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 03/16/2005 by MDG + + Contains sorting routines required by the NIST Latent Fingerprint + System (LFS). + +*********************************************************************** + ROUTINES: + sort_indices_int_inc() + sort_indices_double_inc() + bubble_sort_int_inc_2() + bubble_sort_double_inc_2() + bubble_sort_double_dec_2() + bubble_sort_int_inc() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: sort_indices_int_inc - Takes a list of integers and returns a list of +#cat: indices referencing the integer list in increasing order. +#cat: The original list of integers is also returned in sorted +#cat: order. + + Input: + ranks - list of integers to be sorted + num - number of integers in the list + Output: + optr - list of indices referencing the integer list in sorted order + ranks - list of integers in increasing order + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int sort_indices_int_inc(int **optr, int *ranks, const int num) +{ + int *order; + int i; + + /* Allocate list of sequential indices. */ + order = (int *)malloc(num * sizeof(int)); + if(order == (int *)NULL){ + fprintf(stderr, "ERROR : sort_indices_int_inc : malloc : order\n"); + return(-390); + } + /* Initialize list of sequential indices. */ + for(i = 0; i < num; i++) + order[i] = i; + + /* Sort the indecies into rank order. */ + bubble_sort_int_inc_2(ranks, order, num); + + /* Set output pointer to the resulting order of sorted indices. */ + *optr = order; + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: sort_indices_double_inc - Takes a list of doubles and returns a list of +#cat: indices referencing the double list in increasing order. +#cat: The original list of doubles is also returned in sorted +#cat: order. + + Input: + ranks - list of doubles to be sorted + num - number of doubles in the list + Output: + optr - list of indices referencing the double list in sorted order + ranks - list of doubles in increasing order + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int sort_indices_double_inc(int **optr, double *ranks, const int num) +{ + int *order; + int i; + + /* Allocate list of sequential indices. */ + order = (int *)malloc(num * sizeof(int)); + if(order == (int *)NULL){ + fprintf(stderr, "ERROR : sort_indices_double_inc : malloc : order\n"); + return(-400); + } + /* Initialize list of sequential indices. */ + for(i = 0; i < num; i++) + order[i] = i; + + /* Sort the indicies into rank order. */ + bubble_sort_double_inc_2(ranks, order, num); + + /* Set output pointer to the resulting order of sorted indices. */ + *optr = order; + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: bubble_sort_int_inc_2 - Takes a list of integer ranks and a corresponding +#cat: list of integer attributes, and sorts the ranks +#cat: into increasing order moving the attributes +#cat: correspondingly. + + Input: + ranks - list of integers to be sort on + items - list of corresponding integer attributes + len - number of items in list + Output: + ranks - list of integers sorted in increasing order + items - list of attributes in corresponding sorted order +**************************************************************************/ +void bubble_sort_int_inc_2(int *ranks, int *items, const int len) +{ + int done = 0; + int i, p, n, trank, titem; + + /* Set counter to the length of the list being sorted. */ + n = len; + + /* While swaps in order continue to occur from the */ + /* previous iteration... */ + while(!done){ + /* Reset the done flag to TRUE. */ + done = TRUE; + /* Foreach rank in list up to current end index... */ + /* ("p" points to current rank and "i" points to the next rank.) */ + for (i=1, p = 0; i ranks[i]){ + /* Swap ranks. */ + trank = ranks[i]; + ranks[i] = ranks[p]; + ranks[p] = trank; + /* Swap items. */ + titem = items[i]; + items[i] = items[p]; + items[p] = titem; + /* Changes were made, so set done flag to FALSE. */ + done = FALSE; + } + /* Otherwise, rank pair is in order, so continue. */ + } + /* Decrement the ending index. */ + n--; + } +} + +/************************************************************************* +************************************************************************** +#cat: bubble_sort_double_inc_2 - Takes a list of double ranks and a +#cat: corresponding list of integer attributes, and sorts the +#cat: ranks into increasing order moving the attributes +#cat: correspondingly. + + Input: + ranks - list of double to be sort on + items - list of corresponding integer attributes + len - number of items in list + Output: + ranks - list of doubles sorted in increasing order + items - list of attributes in corresponding sorted order +**************************************************************************/ +void bubble_sort_double_inc_2(double *ranks, int *items, const int len) +{ + int done = 0; + int i, p, n, titem; + double trank; + + /* Set counter to the length of the list being sorted. */ + n = len; + + /* While swaps in order continue to occur from the */ + /* previous iteration... */ + while(!done){ + /* Reset the done flag to TRUE. */ + done = TRUE; + /* Foreach rank in list up to current end index... */ + /* ("p" points to current rank and "i" points to the next rank.) */ + for (i=1, p = 0; i ranks[i]){ + /* Swap ranks. */ + trank = ranks[i]; + ranks[i] = ranks[p]; + ranks[p] = trank; + /* Swap items. */ + titem = items[i]; + items[i] = items[p]; + items[p] = titem; + /* Changes were made, so set done flag to FALSE. */ + done = FALSE; + } + /* Otherwise, rank pair is in order, so continue. */ + } + /* Decrement the ending index. */ + n--; + } +} + +/*************************************************************************** +************************************************************************** +#cat: bubble_sort_double_dec_2 - Conducts a simple bubble sort returning a list +#cat: of ranks in decreasing order and their associated items in sorted +#cat: order as well. + + Input: + ranks - list of values to be sorted + items - list of items, each corresponding to a particular rank value + len - length of the lists to be sorted + Output: + ranks - list of values sorted in descending order + items - list of items in the corresponding sorted order of the ranks. + If these items are indices, upon return, they may be used as + indirect addresses reflecting the sorted order of the ranks. +****************************************************************************/ +void bubble_sort_double_dec_2(double *ranks, int *items, const int len) +{ + int done = 0; + int i, p, n, titem; + double trank; + + n = len; + while(!done){ + done = 1; + for (i=1, p = 0;i ranks[i]){ + /* Swap ranks. */ + trank = ranks[i]; + ranks[i] = ranks[p]; + ranks[p] = trank; + /* Changes were made, so set done flag to FALSE. */ + done = FALSE; + } + /* Otherwise, rank pair is in order, so continue. */ + } + /* Decrement the ending index. */ + n--; + } +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/loop.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/loop.c.svn-base @@ -0,0 +1,1263 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: LOOP.C + AUTHOR: Michael D. Garris + DATE: 05/11/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for analyzing and filling + lakes and islands within a binary image as part of the + NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + chain_code_loop() + is_chain_clockwise() + get_loop_list() + on_loop() + on_island_lake() + on_hook() + is_loop_clockwise() + process_loop() + process_loop_V2() + get_loop_aspect() + fill_loop() + fill_partial_row() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: chain_code_loop - Converts a feature's contour points into an +#cat: 8-connected chain code vector. This encoding represents +#cat: the direction taken between each adjacent point in the +#cat: contour. Chain codes may be used for many purposes, such +#cat: as computing the perimeter or area of an object, and they +#cat: may be used in object detection and recognition. + + Input: + contour_x - x-coord list for feature's contour points + contour_y - y-coord list for feature's contour points + ncontour - number of points in contour + Output: + ochain - resulting vector of chain codes + onchain - number of codes in chain + (same as number of points in contour) + Return Code: + Zero - chain code successful derived + Negative - system error +**************************************************************************/ +static int chain_code_loop(int **ochain, int *onchain, + const int *contour_x, const int *contour_y, const int ncontour) +{ + int *chain; + int i, j, dx, dy; + + /* If we don't have at least 3 points in the contour ... */ + if(ncontour <= 3){ + /* Then we don't have a loop, so set chain length to 0 */ + /* and return without any allocations. */ + *onchain = 0; + return(0); + } + + /* Allocate chain code vector. It will be the same length as the */ + /* number of points in the contour. There will be one chain code */ + /* between each point on the contour including a code between the */ + /* last to the first point on the contour (completing the loop). */ + chain = (int *)malloc(ncontour * sizeof(int)); + /* If the allocation fails ... */ + if(chain == (int *)NULL){ + fprintf(stderr, "ERROR : chain_code_loop : malloc : chain\n"); + return(-170); + } + + /* For each neighboring point in the list (with "i" pointing to the */ + /* previous neighbor and "j" pointing to the next neighbor... */ + for(i = 0, j=1; i < ncontour-1; i++, j++){ + /* Compute delta in X between neighbors. */ + dx = contour_x[j] - contour_x[i]; + /* Compute delta in Y between neighbors. */ + dy = contour_y[j] - contour_y[i]; + /* Derive chain code index from neighbor deltas. */ + /* The deltas are on the range [-1..1], so to use them as indices */ + /* into the code list, they must first be incremented by one. */ + chain[i] = *(chaincodes_nbr8+((dy+1)*NBR8_DIM)+dx+1); + } + + /* Now derive chain code between last and first points in the */ + /* contour list. */ + dx = contour_x[0] - contour_x[i]; + dy = contour_y[0] - contour_y[i]; + chain[i] = *(chaincodes_nbr8+((dy+1)*NBR8_DIM)+dx+1); + + /* Store results to the output pointers. */ + *ochain = chain; + *onchain = ncontour; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: is_chain_clockwise - Takes an 8-connected chain code vector and +#cat: determines if the codes are ordered clockwise or +#cat: counter-clockwise. +#cat: The routine also requires a default return value be +#cat: specified in the case the the routine is not able to +#cat: definitively determine the chains direction. This allows +#cat: the default response to be application-specific. + + Input: + chain - chain code vector + nchain - number of codes in chain + default_ret - default return code (used when we can't tell the order) + Return Code: + TRUE - chain determined to be ordered clockwise + FALSE - chain determined to be ordered counter-clockwise + Default - could not determine the order of the chain +**************************************************************************/ +static int is_chain_clockwise(const int *chain, const int nchain, + const int default_ret) +{ + int i, j, d, sum; + + /* Initialize turn-accumulator to 0. */ + sum = 0; + + /* Foreach neighboring code in chain, compute the difference in */ + /* direction and accumulate. Left-hand turns increment, whereas */ + /* right-hand decrement. */ + for(i = 0, j =1; i < nchain-1; i++, j++){ + /* Compute delta in neighbor direction. */ + d = chain[j] - chain[i]; + /* Make the delta the "inner" distance. */ + /* If delta >= 4, for example if chain_i==2 and chain_j==7 (which */ + /* means the contour went from a step up to step down-to-the-right) */ + /* then 5=(7-2) which is >=4, so -3=(5-8) which means that the */ + /* change in direction is a righ-hand turn of 3 units). */ + if(d >= 4) + d -= 8; + /* If delta <= -4, for example if chain_i==7 and chain_j==2 (which */ + /* means the contour went from a step down-to-the-right to step up) */ + /* then -5=(2-7) which is <=-4, so 3=(-5+8) which means that the */ + /* change in direction is a left-hand turn of 3 units). */ + else if (d <= -4) + d += 8; + + /* The delta direction is then accumulated. */ + sum += d; + } + + /* Now we need to add in the final delta direction between the last */ + /* and first codes in the chain. */ + d = chain[0] - chain[i]; + if(d >= 4) + d -= 8; + else if (d <= -4) + d += 8; + sum += d; + + /* If the final turn_accumulator == 0, then we CAN'T TELL the */ + /* direction of the chain code, so return the default return value. */ + if(sum == 0) + return(default_ret); + /* Otherwise, if the final turn-accumulator is positive ... */ + else if(sum > 0) + /* Then we had a greater amount of left-hand turns than right-hand */ + /* turns, so the chain is in COUNTER-CLOCKWISE order, so return FALSE. */ + return(FALSE); + /* Otherwise, the final turn-accumulator is negative ... */ + else + /* So we had a greater amount of right-hand turns than left-hand */ + /* turns, so the chain is in CLOCKWISE order, so return TRUE. */ + return(TRUE); +} + +/************************************************************************* +************************************************************************** +#cat: get_loop_list - Takes a list of minutia points and determines which +#cat: ones lie on loops around valleys (lakes) of a specified +#cat: maximum circumference. The routine returns a list of +#cat: flags, one for each minutia in the input list, and if +#cat: the minutia is on a qualifying loop, the corresponding +#cat: flag is set to TRUE, otherwise it is set to FALSE. +#cat: If for some reason it was not possible to trace the +#cat: minutia's contour, then it is removed from the list. +#cat: This can occur due to edits dynamically taking place +#cat: in the image by other routines. + + Input: + minutiae - list of true and false minutiae + loop_len - maximum size of loop searched for + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + oonloop - loop flags: TRUE == loop, FALSE == no loop + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int get_loop_list(int **oonloop, MINUTIAE *minutiae, const int loop_len, + unsigned char *bdata, const int iw, const int ih) +{ + int i, ret; + int *onloop; + MINUTIA *minutia; + + /* Allocate a list of onloop flags (one for each minutia in list). */ + onloop = (int *)malloc(minutiae->num * sizeof(int)); + if(onloop == (int *)NULL){ + fprintf(stderr, "ERROR : get_loop_list : malloc : onloop\n"); + return(-320); + } + + i = 0; + /* Foreach minutia remaining in list ... */ + while(i < minutiae->num){ + /* Assign a temporary pointer. */ + minutia = minutiae->list[i]; + /* If current minutia is a bifurcation ... */ + if(minutia->type == BIFURCATION){ + /* Check to see if it is on a loop of specified length. */ + ret = on_loop(minutia, loop_len, bdata, iw, ih); + /* If minutia is on a loop... */ + if(ret == LOOP_FOUND){ + /* Then set the onloop flag to TRUE. */ + onloop[i] = TRUE; + /* Advance to next minutia in the list. */ + i++; + } + /* If on loop test IGNORED ... */ + else if (ret == IGNORE){ + /* Remove the current minutia from the list. */ + if((ret = remove_minutia(i, minutiae))){ + /* Deallocate working memory. */ + free(onloop); + /* Return error code. */ + return(ret); + } + /* No need to advance because next minutia has "slid" */ + /* into position pointed to by 'i'. */ + } + /* If the minutia is NOT on a loop... */ + else if (ret == FALSE){ + /* Then set the onloop flag to FALSE. */ + onloop[i] = FALSE; + /* Advance to next minutia in the list. */ + i++; + } + /* Otherwise, an ERROR occurred while looking for loop. */ + else{ + /* Deallocate working memory. */ + free(onloop); + /* Return error code. */ + return(ret); + } + } + /* Otherwise, the current minutia is a ridge-ending... */ + else{ + /* Ridge-endings will never be on a loop, so set flag to FALSE. */ + onloop[i] = FALSE; + /* Advance to next minutia in the list. */ + i++; + } + } + + /* Store flag list to output pointer. */ + *oonloop = onloop; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: on_loop - Determines if a minutia point lies on a loop (island or lake) +#cat: of specified maximum circumference. + + Input: + minutiae - list of true and false minutiae + max_loop_len - maximum size of loop searched for + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Return Code: + IGNORE - minutia contour could not be traced + LOOP_FOUND - minutia determined to lie on qualifying loop + FALSE - minutia determined not to lie on qualifying loop + Negative - system error +**************************************************************************/ +int on_loop(const MINUTIA *minutia, const int max_loop_len, + unsigned char *bdata, const int iw, const int ih) +{ + int ret; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + + /* Trace the contour of the feature starting at the minutia point */ + /* and stepping along up to the specified maximum number of steps. */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, max_loop_len, + minutia->x, minutia->y, minutia->x, minutia->y, + minutia->ex, minutia->ey, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If trace was not possible ... */ + if(ret == IGNORE) + return(ret); + + /* If the trace completed a loop ... */ + if(ret == LOOP_FOUND){ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + return(LOOP_FOUND); + } + + /* If the trace successfully followed the minutia's contour, but did */ + /* not complete a loop within the specified number of steps ... */ + if(ret == 0){ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + return(FALSE); + } + + /* Otherwise, the trace had an error in following the contour ... */ + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: on_island_lake - Determines if two minutia points lie on the same loop +#cat: (island or lake). If a loop is detected, the contour +#cat: points of the loop are returned. + + Input: + minutia1 - first minutia point + minutia2 - second minutia point + max_half_loop - maximum size of half the loop circumference searched for + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + ocontour_x - x-pixel coords of loop contour + ocontour_y - y-pixel coords of loop contour + ocontour_x - x coord of each contour point's edge pixel + ocontour_y - y coord of each contour point's edge pixel + oncontour - number of points in the contour. + Return Code: + IGNORE - contour could not be traced + LOOP_FOUND - minutiae determined to lie on same qualifying loop + FALSE - minutiae determined not to lie on same qualifying loop + Negative - system error +**************************************************************************/ +int on_island_lake(int **ocontour_x, int **ocontour_y, + int **ocontour_ex, int **ocontour_ey, int *oncontour, + const MINUTIA *minutia1, const MINUTIA *minutia2, + const int max_half_loop, + unsigned char *bdata, const int iw, const int ih) +{ + int i, l, ret; + int *contour1_x, *contour1_y, *contour1_ex, *contour1_ey, ncontour1; + int *contour2_x, *contour2_y, *contour2_ex, *contour2_ey, ncontour2; + int *loop_x, *loop_y, *loop_ex, *loop_ey, nloop; + + /* Trace the contour of the feature starting at the 1st minutia point */ + /* and stepping along up to the specified maximum number of steps or */ + /* until 2nd mintuia point is encountered. */ + ret = trace_contour(&contour1_x, &contour1_y, + &contour1_ex, &contour1_ey, &ncontour1, max_half_loop, + minutia2->x, minutia2->y, minutia1->x, minutia1->y, + minutia1->ex, minutia1->ey, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If trace was not possible, return IGNORE. */ + if(ret == IGNORE) + return(ret); + + /* If the trace encounters 2nd minutia point ... */ + if(ret == LOOP_FOUND){ + + /* Now, trace the contour of the feature starting at the 2nd minutia, */ + /* continuing to search for edge neighbors clockwise, and stepping */ + /* along up to the specified maximum number of steps or until 1st */ + /* mintuia point is encountered. */ + ret = trace_contour(&contour2_x, &contour2_y, + &contour2_ex, &contour2_ey, &ncontour2, max_half_loop, + minutia1->x, minutia1->y, minutia2->x, minutia2->y, + minutia2->ex, minutia2->ey, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If trace was not possible, return IGNORE. */ + if(ret == IGNORE){ + free_contour(contour1_x, contour1_y, contour1_ex, contour1_ey); + return(ret); + } + + /* If the 2nd trace encounters 1st minutia point ... */ + if(ret == LOOP_FOUND){ + /* Combine the 2 half loop contours into one full loop. */ + + /* Compute loop length (including the minutia pair). */ + nloop = ncontour1 + ncontour2 + 2; + + /* Allocate loop contour. */ + if((ret = allocate_contour(&loop_x, &loop_y, &loop_ex, &loop_ey, + nloop))){ + free_contour(contour1_x, contour1_y, contour1_ex, contour1_ey); + free_contour(contour2_x, contour2_y, contour2_ex, contour2_ey); + return(ret); + } + + /* Store 1st minutia. */ + l = 0; + loop_x[l] = minutia1->x; + loop_y[l] = minutia1->y; + loop_ex[l] = minutia1->ex; + loop_ey[l++] = minutia1->ey; + /* Store first contour. */ + for(i = 0; i < ncontour1; i++){ + loop_x[l] = contour1_x[i]; + loop_y[l] = contour1_y[i]; + loop_ex[l] = contour1_ex[i]; + loop_ey[l++] = contour1_ey[i]; + } + /* Store 2nd minutia. */ + loop_x[l] = minutia2->x; + loop_y[l] = minutia2->y; + loop_ex[l] = minutia2->ex; + loop_ey[l++] = minutia2->ey; + /* Store 2nd contour. */ + for(i = 0; i < ncontour2; i++){ + loop_x[l] = contour2_x[i]; + loop_y[l] = contour2_y[i]; + loop_ex[l] = contour2_ex[i]; + loop_ey[l++] = contour2_ey[i]; + } + + /* Deallocate the half loop contours. */ + free_contour(contour1_x, contour1_y, contour1_ex, contour1_ey); + free_contour(contour2_x, contour2_y, contour2_ex, contour2_ey); + + /* Assign loop contour to return pointers. */ + *ocontour_x = loop_x; + *ocontour_y = loop_y; + *ocontour_ex = loop_ex; + *ocontour_ey = loop_ey; + *oncontour = nloop; + + /* Then return that an island/lake WAS found (LOOP_FOUND). */ + return(LOOP_FOUND); + } + + /* If the trace successfully followed 2nd minutia's contour, but */ + /* did not encounter 1st minutia point within the specified number */ + /* of steps ... */ + if(ret == 0){ + /* Deallocate the two contours. */ + free_contour(contour1_x, contour1_y, contour1_ex, contour1_ey); + free_contour(contour2_x, contour2_y, contour2_ex, contour2_ey); + /* Then return that an island/lake was NOT found (FALSE). */ + return(FALSE); + } + + /* Otherwise, the 2nd trace had an error in following the contour ... */ + free_contour(contour1_x, contour1_y, contour1_ex, contour1_ey); + return(ret); + } + + /* If the 1st trace successfully followed 1st minutia's contour, but */ + /* did not encounter the 2nd minutia point within the specified number */ + /* of steps ... */ + if(ret == 0){ + free_contour(contour1_x, contour1_y, contour1_ex, contour1_ey); + /* Then return that an island/lake was NOT found (FALSE). */ + return(FALSE); + } + + /* Otherwise, the 1st trace had an error in following the contour ... */ + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: on_hook - Determines if two minutia points lie on a hook on the side +#cat: of a ridge or valley. + + Input: + minutia1 - first minutia point + minutia2 - second minutia point + max_hook_len - maximum length of contour searched along for a hook + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Return Code: + IGNORE - contour could not be traced + HOOK_FOUND - minutiae determined to lie on same qualifying hook + FALSE - minutiae determined not to lie on same qualifying hook + Negative - system error +**************************************************************************/ +int on_hook(const MINUTIA *minutia1, const MINUTIA *minutia2, + const int max_hook_len, + unsigned char *bdata, const int iw, const int ih) +{ + int ret; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + + /* NOTE: This routine should only be called when the 2 minutia points */ + /* are of "opposite" type. */ + + /* Trace the contour of the feature starting at the 1st minutia's */ + /* "edge" point and stepping along up to the specified maximum number */ + /* of steps or until the 2nd minutia point is encountered. */ + /* First search for edge neighbors clockwise. */ + + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, max_hook_len, + minutia2->x, minutia2->y, minutia1->ex, minutia1->ey, + minutia1->x, minutia1->y, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If trace was not possible, return IGNORE. */ + if(ret == IGNORE) + return(ret); + + /* If the trace encountered the second minutia point ... */ + if(ret == LOOP_FOUND){ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + return(HOOK_FOUND); + } + + /* If trace had an error in following the contour ... */ + if(ret != 0) + return(ret); + + + /* Otherwise, the trace successfully followed the contour, but did */ + /* not encounter the 2nd minutia point within the specified number */ + /* of steps. */ + + /* Deallocate previously extracted contour. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /* Try searching contour from 1st minutia "edge" searching for */ + /* edge neighbors counter-clockwise. */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, max_hook_len, + minutia2->x, minutia2->y, minutia1->ex, minutia1->ey, + minutia1->x, minutia1->y, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); + + /* If trace was not possible, return IGNORE. */ + if(ret == IGNORE) + return(ret); + + /* If the trace encountered the second minutia point ... */ + if(ret == LOOP_FOUND){ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + return(HOOK_FOUND); + } + + /* If the trace successfully followed the 1st minutia's contour, but */ + /* did not encounter the 2nd minutia point within the specified number */ + /* of steps ... */ + if(ret == 0){ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Then return hook NOT found (FALSE). */ + return(FALSE); + } + + /* Otherwise, the 2nd trace had an error in following the contour ... */ + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: is_loop_clockwise - Takes a feature's contour points and determines if +#cat: the points are ordered clockwise or counter-clockwise about +#cat: the feature. The routine also requires a default return +#cat: value be specified in the case the the routine is not able +#cat: to definitively determine the contour's order. This allows +#cat: the default response to be application-specific. + + Input: + contour_x - x-coord list for feature's contour points + contour_y - y-coord list for feature's contour points + ncontour - number of points in contour + default_ret - default return code (used when we can't tell the order) + Return Code: + TRUE - contour determined to be ordered clockwise + FALSE - contour determined to be ordered counter-clockwise + Default - could not determine the order of the contour + Negative - system error +**************************************************************************/ +int is_loop_clockwise(const int *contour_x, const int *contour_y, + const int ncontour, const int default_ret) +{ + int ret; + int *chain, nchain; + + /* Derive chain code from contour points. */ + if((ret = chain_code_loop(&chain, &nchain, + contour_x, contour_y, ncontour))) + /* If there is a system error, return the error code. */ + return(ret); + + /* If chain is empty... */ + if(nchain == 0){ + /* There wasn't enough contour points to tell, so return the */ + /* the default return value. No chain needs to be deallocated */ + /* in this case. */ + return(default_ret); + } + + /* If the chain code for contour is clockwise ... pass default return */ + /* value on to this routine to correctly handle the case where we can't */ + /* tell the direction of the chain code. */ + ret = is_chain_clockwise(chain, nchain, default_ret); + + /* Free the chain code and return result. */ + free(chain); + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: get_loop_aspect - Takes a contour list (determined to form a complete +#cat: loop) and measures the loop's aspect (the largest and smallest +#cat: distances across the loop) and returns the points on the +#cat: loop where these distances occur. + + Input: + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + ncontour - number of points in contour + Output: + omin_fr - contour point index where minimum aspect occurs + omin_to - opposite contour point index where minimum aspect occurs + omin_dist - the minimum distance across the loop + omax_fr - contour point index where maximum aspect occurs + omax_to - contour point index where maximum aspect occurs + omax_dist - the maximum distance across the loop +**************************************************************************/ +static void get_loop_aspect(int *omin_fr, int *omin_to, double *omin_dist, + int *omax_fr, int *omax_to, double *omax_dist, + const int *contour_x, const int *contour_y, const int ncontour) +{ + int halfway, limit; + int i, j; + double dist; + double min_dist, max_dist; + int min_i, max_i, min_j, max_j; + + /* Compute half the perimeter of the loop. */ + halfway = ncontour>>1; + + /* Take opposite points on the contour and walk half way */ + /* around the loop. */ + i = 0; + j = halfway; + /* Compute squared distance between opposite points on loop. */ + dist = squared_distance(contour_x[i], contour_y[i], + contour_x[j], contour_y[j]); + + /* Initialize running minimum and maximum distances along loop. */ + min_dist = dist; + min_i = i; + min_j = j; + max_dist = dist; + max_i = i; + max_j = j; + /* Bump to next pair of opposite points. */ + i++; + /* Make sure j wraps around end of list. */ + j++; + j %= ncontour; + + /* If the loop is of even length, then we only need to walk half */ + /* way around as the other half will be exactly redundant. If */ + /* the loop is of odd length, then the second half will not be */ + /* be exactly redundant and the difference "may" be meaningful. */ + /* If execution speed is an issue, then probably get away with */ + /* walking only the fist half of the loop under ALL conditions. */ + + /* If loop has odd length ... */ + if(ncontour % 2) + /* Walk the loop's entire perimeter. */ + limit = ncontour; + /* Otherwise the loop has even length ... */ + else + /* Only walk half the perimeter. */ + limit = halfway; + + /* While we have not reached our perimeter limit ... */ + while(i < limit){ + /* Compute squared distance between opposite points on loop. */ + dist = squared_distance(contour_x[i], contour_y[i], + contour_x[j], contour_y[j]); + /* Check the running minimum and maximum distances. */ + if(dist < min_dist){ + min_dist = dist; + min_i = i; + min_j = j; + } + if(dist > max_dist){ + max_dist = dist; + max_i = i; + max_j = j; + } + /* Bump to next pair of opposite points. */ + i++; + /* Make sure j wraps around end of list. */ + j++; + j %= ncontour; + } + + /* Assign minimum and maximum distances to output pointers. */ + *omin_fr = min_i; + *omin_to = min_j; + *omin_dist = min_dist; + *omax_fr = max_i; + *omax_to = max_j; + *omax_dist = max_dist; +} + +/************************************************************************* +************************************************************************** +#cat: process_loop - Takes a contour list that has been determined to form +#cat: a complete loop, and processes it. If the loop is sufficiently +#cat: large and elongated, then two minutia points are calculated +#cat: along the loop's longest aspect axis. If it is determined +#cat: that the loop does not contain minutiae, it is filled in the +#cat: binary image. + + Input: + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + contour_ex - x-coord list for loop's edge points + contour_ey - y-coord list for loop's edge points + ncontour - number of points in contour + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + OR + bdata - binary image data with loop filled + Return Code: + Zero - loop processed successfully + Negative - system error +**************************************************************************/ +int process_loop(MINUTIAE *minutiae, + const int *contour_x, const int *contour_y, + const int *contour_ex, const int *contour_ey, const int ncontour, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int halfway; + int idir, type, appearing; + double min_dist, max_dist; + int min_fr, max_fr, min_to, max_to; + int mid_x, mid_y, mid_pix; + int feature_pix; + int ret; + MINUTIA *minutia; + + /* If contour is empty, then just return. */ + if(ncontour <= 0) + return(0); + + /* If loop is large enough ... */ + if(ncontour > lfsparms->min_loop_len){ + /* Get pixel value of feature's interior. */ + feature_pix = *(bdata + (contour_y[0] * iw) + contour_x[0]); + + /* Compute half the perimeter of the loop. */ + halfway = ncontour>>1; + + /* Get the aspect dimensions of the loop in units of */ + /* squared distance. */ + get_loop_aspect(&min_fr, &min_to, &min_dist, + &max_fr, &max_to, &max_dist, + contour_x, contour_y, ncontour); + + /* If loop passes aspect ratio tests ... loop is sufficiently */ + /* narrow or elongated ... */ + if((min_dist < lfsparms->min_loop_aspect_dist) || + ((max_dist/min_dist) >= lfsparms->min_loop_aspect_ratio)){ + + /* Update minutiae list with opposite points of max distance */ + /* on the loop. */ + + /* First, check if interior point has proper pixel value. */ + mid_x = (contour_x[max_fr]+contour_x[max_to])>>1; + mid_y = (contour_y[max_fr]+contour_y[max_to])>>1; + mid_pix = *(bdata + (mid_y * iw) + mid_x); + /* If interior point is the same as the feature... */ + if(mid_pix == feature_pix){ + + /* 1. Treat maximum distance point as a potential minutia. */ + + /* Compute direction from maximum loop point to its */ + /* opposite point. */ + idir = line2direction(contour_x[max_fr], contour_y[max_fr], + contour_x[max_to], contour_y[max_to], + lfsparms->num_directions); + /* Get type of minutia: BIFURCATION or RIDGE_ENDING. */ + type = minutia_type(feature_pix); + /* Determine if minutia is appearing or disappearing. */ + if((appearing = is_minutia_appearing( + contour_x[max_fr], contour_y[max_fr], + contour_ex[max_fr], contour_ey[max_fr])) < 0){ + /* Return system error code. */ + return(appearing); + } + /* Create new minutia object. */ + if((ret = create_minutia(&minutia, + contour_x[max_fr], contour_y[max_fr], + contour_ex[max_fr], contour_ey[max_fr], + idir, DEFAULT_RELIABILITY, + type, appearing, LOOP_ID))){ + /* Return system error code. */ + return(ret); + } + /* Update the minutiae list with potential new minutia. */ + ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* 2. Treat point opposite of maximum distance point as */ + /* a potential minutia. */ + + /* Flip the direction 180 degrees. Make sure new direction */ + /* is on the range [0..(ndirsX2)]. */ + idir += lfsparms->num_directions; + idir %= (lfsparms->num_directions<<1); + + /* The type of minutia will stay the same. */ + + /* Determine if minutia is appearing or disappearing. */ + if((appearing = is_minutia_appearing( + contour_x[max_to], contour_y[max_to], + contour_ex[max_to], contour_ey[max_to])) < 0){ + /* Return system error code. */ + return(appearing); + } + /* Create new minutia object. */ + if((ret = create_minutia(&minutia, + contour_x[max_to], contour_y[max_to], + contour_ex[max_to], contour_ey[max_to], + idir, DEFAULT_RELIABILITY, + type, appearing, LOOP_ID))){ + /* Return system error code. */ + return(ret); + } + /* Update the minutiae list with potential new minutia. */ + ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* Done successfully processing this loop, so return normally. */ + return(0); + + } /* Otherwise, loop interior has problems. */ + } /* Otherwise, loop is not the right shape for minutiae. */ + } /* Otherwise, loop's perimeter is too small for minutiae. */ + + /* If we get here, we have a loop that is assumed to not contain */ + /* minutiae, so remove the loop from the image. */ + ret = fill_loop(contour_x, contour_y, ncontour, bdata, iw, ih); + + /* Return either an error code from fill_loop or return normally. */ + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: process_loop_V2 - Takes a contour list that has been determined to form +#cat: a complete loop, and processes it. If the loop is sufficiently +#cat: large and elongated, then two minutia points are calculated +#cat: along the loop's longest aspect axis. If it is determined +#cat: that the loop does not contain minutiae, it is filled in the +#cat: binary image. + + Input: + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + contour_ex - x-coord list for loop's edge points + contour_ey - y-coord list for loop's edge points + ncontour - number of points in contour + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + plow_flow_map - pixelized Low Ridge Flow Map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + OR + bdata - binary image data with loop filled + Return Code: + Zero - loop processed successfully + Negative - system error +**************************************************************************/ +int process_loop_V2(MINUTIAE *minutiae, + const int *contour_x, const int *contour_y, + const int *contour_ex, const int *contour_ey, const int ncontour, + unsigned char *bdata, const int iw, const int ih, + int *plow_flow_map, const LFSPARMS *lfsparms) +{ + int halfway; + int idir, type, appearing; + double min_dist, max_dist; + int min_fr, max_fr, min_to, max_to; + int mid_x, mid_y, mid_pix; + int feature_pix; + int ret; + MINUTIA *minutia; + int fmapval; + double reliability; + + /* If contour is empty, then just return. */ + if(ncontour <= 0) + return(0); + + /* If loop is large enough ... */ + if(ncontour > lfsparms->min_loop_len){ + /* Get pixel value of feature's interior. */ + feature_pix = *(bdata + (contour_y[0] * iw) + contour_x[0]); + + /* Compute half the perimeter of the loop. */ + halfway = ncontour>>1; + + /* Get the aspect dimensions of the loop in units of */ + /* squared distance. */ + get_loop_aspect(&min_fr, &min_to, &min_dist, + &max_fr, &max_to, &max_dist, + contour_x, contour_y, ncontour); + + /* If loop passes aspect ratio tests ... loop is sufficiently */ + /* narrow or elongated ... */ + if((min_dist < lfsparms->min_loop_aspect_dist) || + ((max_dist/min_dist) >= lfsparms->min_loop_aspect_ratio)){ + + /* Update minutiae list with opposite points of max distance */ + /* on the loop. */ + + /* First, check if interior point has proper pixel value. */ + mid_x = (contour_x[max_fr]+contour_x[max_to])>>1; + mid_y = (contour_y[max_fr]+contour_y[max_to])>>1; + mid_pix = *(bdata + (mid_y * iw) + mid_x); + /* If interior point is the same as the feature... */ + if(mid_pix == feature_pix){ + + /* 1. Treat maximum distance point as a potential minutia. */ + + /* Compute direction from maximum loop point to its */ + /* opposite point. */ + idir = line2direction(contour_x[max_fr], contour_y[max_fr], + contour_x[max_to], contour_y[max_to], + lfsparms->num_directions); + /* Get type of minutia: BIFURCATION or RIDGE_ENDING. */ + type = minutia_type(feature_pix); + /* Determine if minutia is appearing or disappearing. */ + if((appearing = is_minutia_appearing( + contour_x[max_fr], contour_y[max_fr], + contour_ex[max_fr], contour_ey[max_fr])) < 0){ + /* Return system error code. */ + return(appearing); + } + + /* Is the new point in a LOW RIDGE FLOW block? */ + fmapval = *(plow_flow_map+(contour_y[max_fr]*iw)+ + contour_x[max_fr]); + + /* If current minutia is in a LOW RIDGE FLOW block ... */ + if(fmapval) + reliability = MEDIUM_RELIABILITY; + else + /* Otherwise, minutia is in a reliable block. */ + reliability = HIGH_RELIABILITY; + + /* Create new minutia object. */ + if((ret = create_minutia(&minutia, + contour_x[max_fr], contour_y[max_fr], + contour_ex[max_fr], contour_ey[max_fr], + idir, reliability, + type, appearing, LOOP_ID))){ + /* Return system error code. */ + return(ret); + } + /* Update the minutiae list with potential new minutia. */ + /* NOTE: Deliberately using version one of this routine. */ + ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* 2. Treat point opposite of maximum distance point as */ + /* a potential minutia. */ + + /* Flip the direction 180 degrees. Make sure new direction */ + /* is on the range [0..(ndirsX2)]. */ + idir += lfsparms->num_directions; + idir %= (lfsparms->num_directions<<1); + + /* The type of minutia will stay the same. */ + + /* Determine if minutia is appearing or disappearing. */ + if((appearing = is_minutia_appearing( + contour_x[max_to], contour_y[max_to], + contour_ex[max_to], contour_ey[max_to])) < 0){ + /* Return system error code. */ + return(appearing); + } + + /* Is the new point in a LOW RIDGE FLOW block? */ + fmapval = *(plow_flow_map+(contour_y[max_to]*iw)+ + contour_x[max_to]); + + /* If current minutia is in a LOW RIDGE FLOW block ... */ + if(fmapval) + reliability = MEDIUM_RELIABILITY; + else + /* Otherwise, minutia is in a reliable block. */ + reliability = HIGH_RELIABILITY; + + /* Create new minutia object. */ + if((ret = create_minutia(&minutia, + contour_x[max_to], contour_y[max_to], + contour_ex[max_to], contour_ey[max_to], + idir, reliability, + type, appearing, LOOP_ID))){ + /* Return system error code. */ + return(ret); + } + + /* Update the minutiae list with potential new minutia. */ + /* NOTE: Deliberately using version one of this routine. */ + ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); + + /* If minuitia IGNORED and not added to the minutia list ... */ + if(ret == IGNORE) + /* Deallocate the minutia. */ + free_minutia(minutia); + + /* Done successfully processing this loop, so return normally. */ + return(0); + + } /* Otherwise, loop interior has problems. */ + } /* Otherwise, loop is not the right shape for minutiae. */ + } /* Otherwise, loop's perimeter is too small for minutiae. */ + + /* If we get here, we have a loop that is assumed to not contain */ + /* minutiae, so remove the loop from the image. */ + ret = fill_loop(contour_x, contour_y, ncontour, bdata, iw, ih); + + /* Return either an error code from fill_loop or return normally. */ + return(ret); +} + +/************************************************************************* +************************************************************************** +#cat: fill_partial_row - Fills a specified range of contiguous pixels on +#cat: a specified row of an 8-bit pixel image with a specified +#cat: pixel value. NOTE, the pixel coordinates are assumed to +#cat: be within the image boundaries. + + Input: + fill_pix - pixel value to fill with (should be on range [0..255] + frx - x-pixel coord where fill should begin + tox - x-pixel coord where fill should end (inclusive) + y - y-pixel coord of current row being filled + bdata - 8-bit image data + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + bdata - 8-bit image data with partial row filled. +**************************************************************************/ +static void fill_partial_row(const int fill_pix, const int frx, const int tox, + const int y, unsigned char *bdata, const int iw, const int ih) +{ + int x; + unsigned char *bptr; + + /* Set pixel pointer to starting x-coord on current row. */ + bptr = bdata+(y*iw)+frx; + + /* Foreach pixel between starting and ending x-coord on row */ + /* (including the end points) ... */ + for(x = frx; x <= tox; x++){ + /* Set current pixel with fill pixel value. */ + *bptr = fill_pix; + /* Bump to next pixel in the row. */ + bptr++; + } +} + +/************************************************************************* +************************************************************************** +#cat: fill_loop - Takes a contour list that has been determined to form +#cat: a complete loop, and fills the loop accounting for +#cat: complex/concaved shapes. +#cat: NOTE, I tried using a flood-fill in place of this routine, +#cat: but the contour (although 8-connected) is NOT guaranteed to +#cat: be "complete" surrounded (in an 8-connected sense) by pixels +#cat: of opposite color. Therefore, the flood would occasionally +#cat: escape the loop and corrupt the binary image! + + Input: + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + ncontour - number of points in contour + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + bdata - binary image data with loop filled + Return Code: + Zero - loop filled successfully + Negative - system error +**************************************************************************/ +int fill_loop(const int *contour_x, const int *contour_y, + const int ncontour, unsigned char *bdata, + const int iw, const int ih) +{ + SHAPE *shape; + int ret, i, j, x, nx, y; + int lastj; + int next_pix, feature_pix, edge_pix; + + /* Create a shape structure from loop's contour. */ + if((ret = shape_from_contour(&shape, contour_x, contour_y, ncontour))) + /* If system error, then return error code. */ + return(ret); + + /* Get feature pixel value (the value on the interior of the loop */ + /* to be filled). */ + feature_pix = *(bdata+(contour_y[0]*iw)+contour_x[0]); + /* Now get edge pixel value (the value on the exterior of the loop */ + /* to be used to filled the loop). We can get this value by flipping */ + /* the feature pixel value. */ + if(feature_pix) + edge_pix = 0; + else + edge_pix = 1; + + /* Foreach row in shape... */ + for(i = 0; i < shape->nrows; i++){ + /* Get y-coord of current row in shape. */ + y = shape->rows[i]->y; + + /* There should always be at least 1 contour points in the row. */ + /* If there isn't, then something is wrong, so post a warning and */ + /* just return. This is mostly for debug purposes. */ + if(shape->rows[i]->npts < 1){ + /* Deallocate the shape. */ + free_shape(shape); + fprintf(stderr, + "WARNING : fill_loop : unexpected shape, preempting loop fill\n"); + /* This is unexpected, but not fatal, so return normally. */ + return(0); + } + + /* Reset x index on row to the left-most contour point in the row. */ + j = 0; + /* Get first x-coord corresponding to the first contour point on row. */ + x = shape->rows[i]->xs[j]; + /* Fill the first contour point on the row. */ + *(bdata+(y*iw)+x) = edge_pix; + /* Set the index of last contour point on row. */ + lastj = shape->rows[i]->npts - 1; + /* While last contour point on row has not been processed... */ + while(j < lastj){ + + /* On each interation, we have filled up to the current */ + /* contour point on the row pointed to by "j", and now we */ + /* need to determine if we need to skip some edge pixels */ + /* caused by a concavity in the shape or not. */ + + /* Get the next pixel value on the row just right of the */ + /* last contour point filled. We know there are more points */ + /* on the row because we haven't processed the last contour */ + /* point on the row yet. */ + x++; + next_pix = *(bdata+(y*iw)+x); + + /* If the next pixel is the same value as loop's edge pixels ... */ + if(next_pix == edge_pix){ + /* Then assume we have found a concavity and skip to next */ + /* contour point on row. */ + j++; + /* Fill the new contour point because we know it is on the */ + /* feature's contour. */ + x = shape->rows[i]->xs[j]; + *(bdata+(y*iw)+x) = edge_pix; + + /* Now we are ready to loop again. */ + } + + /* Otherwise, fill from current pixel up through the next contour */ + /* point to the right on the row. */ + else{ + /* Bump to the next contour point to the right on row. */ + j++; + /* Set the destination x-coord to the next contour point */ + /* to the right on row. Realize that this could be the */ + /* same pixel as the current x-coord if contour points are */ + /* adjacent. */ + nx = shape->rows[i]->xs[j]; + + /* Fill between current x-coord and next contour point to the */ + /* right on the row (including the new contour point).*/ + fill_partial_row(edge_pix, x, nx, y, bdata, iw, ih); + } + + /* Once we are here we have filled the row up to (and including) */ + /* the contour point currently pointed to by "j". */ + /* We are now ready to loop again. */ + + } /* End WHILE */ + } /* End FOR */ + + free_shape(shape); + + /* Return normally. */ + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/morph.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/morph.c.svn-base @@ -0,0 +1,226 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: MORPH.C + AUTHOR: Michael D. Garris + DATE: 10/04/1999 + UPDATED: 10/26/1999 by MDG + To avoid indisciminate erosion of pixels along + the edge of the binary image. + UPDATED: 03/16/2005 by MDG + + Contains general support image morphology routines required by + the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + erode_charimage_2() + dilate_charimage_2() + get_south8_2() + get_north8_2() + get_east8_2() + get_west8_2() + +***********************************************************************/ + +#include +#include + +/************************************************************************* +************************************************************************** +#cat: erode_charimage_2 - Erodes an 8-bit image by setting true pixels to zero +#cat: if any of their 4 neighbors is zero. Allocation of the +#cat: output image is the responsibility of the caller. The +#cat: input image remains unchanged. This routine will NOT +#cat: erode pixels indiscriminately along the image border. + + Input: + inp - input 8-bit image to be eroded + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + out - contains to the resulting eroded image +**************************************************************************/ +void erode_charimage_2(unsigned char *inp, unsigned char *out, + const int iw, const int ih) +{ + int row, col; + unsigned char *itr = inp, *otr = out; + + memcpy(out, inp, iw*ih); + + /* for true pixels. kill pixel if there is at least one false neighbor */ + for ( row = 0 ; row < ih ; row++ ) + for ( col = 0 ; col < iw ; col++ ) + { + if (*itr) /* erode only operates on true pixels */ + { + /* more efficient with C's left to right evaluation of */ + /* conjuctions. E N S functions not executed if W is false */ + if (!(get_west8_2 ((char *)itr, col , 1 ) && + get_east8_2 ((char *)itr, col, iw , 1 ) && + get_north8_2((char *)itr, row, iw , 1 ) && + get_south8_2((char *)itr, row, iw, ih, 1))) + *otr = 0; + } + itr++ ; otr++; + } +} + +/************************************************************************* +************************************************************************** +#cat: dilate_charimage_2 - Dilates an 8-bit image by setting false pixels to +#cat: one if any of their 4 neighbors is non-zero. Allocation +#cat: of the output image is the responsibility of the caller. +#cat: The input image remains unchanged. + + Input: + inp - input 8-bit image to be dilated + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + out - contains to the resulting dilated image +**************************************************************************/ +void dilate_charimage_2(unsigned char *inp, unsigned char *out, + const int iw, const int ih) +{ + int row, col; + unsigned char *itr = inp, *otr = out; + + memcpy(out, inp, iw*ih); + + /* for all pixels. set pixel if there is at least one true neighbor */ + for ( row = 0 ; row < ih ; row++ ) + for ( col = 0 ; col < iw ; col++ ) + { + if (!*itr) /* pixel is already true, neighbors irrelevant */ + { + /* more efficient with C's left to right evaluation of */ + /* conjuctions. E N S functions not executed if W is false */ + if (get_west8_2 ((char *)itr, col , 0) || + get_east8_2 ((char *)itr, col, iw , 0) || + get_north8_2((char *)itr, row, iw , 0) || + get_south8_2((char *)itr, row, iw, ih, 0)) + *otr = 1; + } + itr++ ; otr++; + } +} + +/************************************************************************* +************************************************************************** +#cat: get_south8_2 - Returns the value of the 8-bit image pixel 1 below the +#cat: current pixel if defined else it returns (char)0. + + Input: + ptr - points to current pixel in image + row - y-coord of current pixel + iw - width (in pixels) of image + ih - height (in pixels) of image + failcode - return value if desired pixel does not exist + Return Code: + Zero - if neighboring pixel is undefined + (outside of image boundaries) + Pixel - otherwise, value of neighboring pixel +**************************************************************************/ +char get_south8_2(char *ptr, const int row, const int iw, const int ih, + const int failcode) +{ + if (row >= ih-1) /* catch case where image is undefined southwards */ + return failcode; /* use plane geometry and return code. */ + + return *(ptr+iw); +} + +/************************************************************************* +************************************************************************** +#cat: get_north8_2 - Returns the value of the 8-bit image pixel 1 above the +#cat: current pixel if defined else it returns (char)0. + + Input: + ptr - points to current pixel in image + row - y-coord of current pixel + iw - width (in pixels) of image + failcode - return value if desired pixel does not exist + Return Code: + Zero - if neighboring pixel is undefined + (outside of image boundaries) + Pixel - otherwise, value of neighboring pixel +**************************************************************************/ +char get_north8_2(char *ptr, const int row, const int iw, + const int failcode) +{ + if (row < 1) /* catch case where image is undefined northwards */ + return failcode; /* use plane geometry and return code. */ + + return *(ptr-iw); +} + +/************************************************************************* +************************************************************************** +#cat: get_east8_2 - Returns the value of the 8-bit image pixel 1 right of the +#cat: current pixel if defined else it returns (char)0. + + Input: + ptr - points to current pixel in image + col - x-coord of current pixel + iw - width (in pixels) of image + failcode - return value if desired pixel does not exist + Return Code: + Zero - if neighboring pixel is undefined + (outside of image boundaries) + Pixel - otherwise, value of neighboring pixel +**************************************************************************/ +char get_east8_2(char *ptr, const int col, const int iw, + const int failcode) +{ + if (col >= iw-1) /* catch case where image is undefined eastwards */ + return failcode; /* use plane geometry and return code. */ + + return *(ptr+ 1); +} + +/************************************************************************* +************************************************************************** +#cat: get_west8_2 - Returns the value of the 8-bit image pixel 1 left of the +#cat: current pixel if defined else it returns (char)0. + + Input: + ptr - points to current pixel in image + col - x-coord of current pixel + failcode - return value if desired pixel does not exist + Return Code: + Zero - if neighboring pixel is undefined + (outside of image boundaries) + Pixel - otherwise, value of neighboring pixel +**************************************************************************/ +char get_west8_2(char *ptr, const int col, const int failcode) +{ + if (col < 1) /* catch case where image is undefined westwards */ + return failcode; /* use plane geometry and return code. */ + + return *(ptr- 1); +} --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/shape.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/shape.c.svn-base @@ -0,0 +1,272 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: SHAPE.C + AUTHOR: Michael D. Garris + DATE: 05/11/1999 + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for creating and manipulating + shape stuctures as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + alloc_shape() + free_shape() + shape_from_contour() + sort_row_on_x() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: alloc_shape - Allocates and initializes a shape structure given the +#cat: the X and Y limits of the shape. + + Input: + xmin - left-most x-coord in shape + ymin - top-most y-coord in shape + xmax - right-most x-coord in shape + ymax - bottom-most y-coord in shape + Output: + oshape - pointer to the allocated & initialized shape structure + Return Code: + Zero - Shape successfully allocated and initialized + Negative - System error +**************************************************************************/ +static int alloc_shape(SHAPE **oshape, const int xmin, const int ymin, + const int xmax, const int ymax) +{ + SHAPE *shape; + int alloc_rows, alloc_pts; + int i, j, y; + + /* Compute allocation parameters. */ + /* First, compute the number of scanlines spanned by the shape. */ + alloc_rows = ymax - ymin + 1; + /* Second, compute the "maximum" number of contour points possible */ + /* on a row. Here we are allocating the maximum number of contiguous */ + /* pixels on each row which will be sufficiently larger than the */ + /* number of actual contour points. */ + alloc_pts = xmax - xmin + 1; + + /* Allocate the shape structure. */ + shape = (SHAPE *)malloc(sizeof(SHAPE)); + /* If there is an allocation error... */ + if(shape == (SHAPE *)NULL){ + fprintf(stderr, "ERROR : alloc_shape : malloc : shape\n"); + return(-250); + } + + /* Allocate the list of row pointers. We now this number will fit */ + /* the shape exactly. */ + shape->rows = (ROW **)malloc(alloc_rows * sizeof(ROW *)); + /* If there is an allocation error... */ + if(shape->rows == (ROW **)NULL){ + /* Deallocate memory alloated by this routine to this point. */ + free(shape); + fprintf(stderr, "ERROR : alloc_shape : malloc : shape->rows\n"); + return(-251); + } + + /* Initialize the shape structure's attributes. */ + shape->ymin = ymin; + shape->ymax = ymax; + /* The number of allocated rows will be exactly the number of */ + /* assigned rows for the shape. */ + shape->alloc = alloc_rows; + shape->nrows = alloc_rows; + + /* Foreach row in the shape... */ + for(i = 0, y = ymin; i < alloc_rows; i++, y++){ + /* Allocate a row structure and store it in its respective position */ + /* in the shape structure's list of row pointers. */ + shape->rows[i] = (ROW *)malloc(sizeof(ROW)); + /* If there is an allocation error... */ + if(shape->rows[i] == (ROW *)NULL){ + /* Deallocate memory alloated by this routine to this point. */ + for(j = 0; j < i; j++){ + free(shape->rows[j]->xs); + free(shape->rows[j]); + } + free(shape->rows); + free(shape); + fprintf(stderr, "ERROR : alloc_shape : malloc : shape->rows[i]\n"); + return(-252); + } + + /* Allocate the current rows list of x-coords. */ + shape->rows[i]->xs = (int *)malloc(alloc_pts * sizeof(int)); + /* If there is an allocation error... */ + if(shape->rows[i]->xs == (int *)NULL){ + /* Deallocate memory alloated by this routine to this point. */ + for(j = 0; j < i; j++){ + free(shape->rows[j]->xs); + free(shape->rows[j]); + } + free(shape->rows[i]); + free(shape->rows); + free(shape); + fprintf(stderr, + "ERROR : alloc_shape : malloc : shape->rows[i]->xs\n"); + return(-253); + } + + /* Initialize the current row structure's attributes. */ + shape->rows[i]->y = y; + shape->rows[i]->alloc = alloc_pts; + /* There are initially ZERO points assigned to the row. */ + shape->rows[i]->npts = 0; + } + + /* Assign structure to output pointer. */ + *oshape = shape; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: free_shape - Deallocates a shape structure and all its allocated +#cat: attributes. + + Input: + shape - pointer to the shape structure to be deallocated +**************************************************************************/ +void free_shape(SHAPE *shape) +{ + int i; + + /* Foreach allocated row in the shape ... */ + for(i = 0; i < shape->alloc; i++){ + /* Deallocate the current row's list of x-coords. */ + free(shape->rows[i]->xs); + /* Deallocate the current row structure. */ + free(shape->rows[i]); + } + + /* Deallocate the list of row pointers. */ + free(shape->rows); + /* Deallocate the shape structure. */ + free(shape); +} + +/************************************************************************* +************************************************************************** +#cat: sort_row_on_x - Takes a row structure and sorts its points left-to- +#cat: right on X. + + Input: + row - row structure to be sorted + Output: + row - row structure with points in sorted order +**************************************************************************/ +static void sort_row_on_x(ROW *row) +{ + /* Conduct a simple increasing bubble sort on the x-coords */ + /* in the given row. A bubble sort is satisfactory as the */ + /* number of points will be relatively small. */ + bubble_sort_int_inc(row->xs, row->npts); +} + +/************************************************************************* +************************************************************************** +#cat: shape_from_contour - Converts a contour list that has been determined +#cat: to form a complete loop into a shape representation where +#cat: the contour points on each contiguous scanline of the shape +#cat: are stored in left-to-right order. + + Input: + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + ncontour - number of points in contour + Output: + oshape - points to the resulting shape structure + Return Code: + Zero - shape successfully derived + Negative - system error +**************************************************************************/ +int shape_from_contour(SHAPE **oshape, const int *contour_x, + const int *contour_y, const int ncontour) +{ + SHAPE *shape; + ROW *row; + int ret, i, xmin, ymin, xmax, ymax; + + /* Find xmin, ymin, xmax, ymax on contour. */ + contour_limits(&xmin, &ymin, &xmax, &ymax, + contour_x, contour_y, ncontour); + + /* Allocate and initialize a shape structure. */ + if((ret = alloc_shape(&shape, xmin, ymin, xmax, ymax))) + /* If system error, then return error code. */ + return(ret); + + /* Foreach point on contour ... */ + for(i = 0; i < ncontour; i++){ + /* Add point to corresponding row. */ + /* First set a pointer to the current row. We need to subtract */ + /* ymin because the rows are indexed relative to the top-most */ + /* scanline in the shape. */ + row = shape->rows[contour_y[i]-ymin]; + + /* It is possible with complex shapes to reencounter points */ + /* already visited on a contour, especially at "pinching" points */ + /* along the contour. So we need to test to see if a point has */ + /* already been stored in the row. If not in row list already ... */ + if(in_int_list(contour_x[i], row->xs, row->npts) < 0){ + /* If row is full ... */ + if(row->npts >= row->alloc){ + /* This should never happen becuase we have allocated */ + /* based on shape bounding limits. */ + fprintf(stderr, + "ERROR : shape_from_contour : row overflow\n"); + return(-260); + } + /* Assign the x-coord of the current contour point to the row */ + /* and bump the row's point counter. All the contour points */ + /* on the same row share the same y-coord. */ + row->xs[row->npts++] = contour_x[i]; + } + /* Otherwise, point is already stored in row, so ignore. */ + } + + /* Foreach row in the shape. */ + for(i = 0; i < shape->nrows; i++) + /* Sort row points increasing on their x-coord. */ + sort_row_on_x(shape->rows[i]); + + /* Assign shape structure to output pointer. */ + *oshape = shape; + + /* Return normally. */ + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/ridges.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/ridges.c.svn-base @@ -0,0 +1,832 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: RIDGES.C + AUTHOR: Michael D. Garris + DATE: 08/09/1999 + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for locating nearest minutia + neighbors and counting intervening ridges as part of the + NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + count_minutiae_ridges() + count_minutia_ridges() + find_neighbors() + update_nbr_dists() + insert_neighbor() + sort_neighbors() + ridge_count() + find_transition() + validate_ridge_crossing() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: insert_neighbor - Takes a minutia index and its squared distance to a +#cat: primary minutia point, and inserts them in the specified +#cat: position of their respective lists, shifting previously +#cat: stored values down and off the lists as necessary. + + Input: + pos - postions where values are to be inserted in lists + nbr_index - index of minutia being inserted + nbr_dist2 - squared distance of minutia to its primary point + nbr_list - current list of nearest neighbor minutia indices + nbr_sqr_dists - corresponding squared euclidean distance of each + neighbor to the primary minutia point + nnbrs - number of neighbors currently in the list + max_nbrs - maximum number of closest neighbors to be returned + Output: + nbr_list - updated list of nearest neighbor indices + nbr_sqr_dists - updated list of nearest neighbor distances + nnbrs - number of neighbors in the update lists + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int insert_neighbor(const int pos, const int nbr_index, const double nbr_dist2, + int *nbr_list, double *nbr_sqr_dists, + int *nnbrs, const int max_nbrs) +{ + int i; + + /* If the desired insertion position is beyond one passed the last */ + /* neighbor in the lists OR greater than equal to the maximum ... */ + /* NOTE: pos is zero-oriented while nnbrs and max_nbrs are 1-oriented. */ + if((pos > *nnbrs) || + (pos >= max_nbrs)){ + fprintf(stderr, + "ERROR : insert_neighbor : insertion point exceeds lists\n"); + return(-480); + } + + /* If the neighbor lists are NOT full ... */ + if(*nnbrs < max_nbrs){ + /* Then we have room to shift everything down to make room for new */ + /* neighbor and increase the number of neighbors stored by 1. */ + i = *nnbrs-1; + (*nnbrs)++; + } + /* Otherwise, the neighbors lists are full ... */ + else if(*nnbrs == max_nbrs) + /* So, we must bump the last neighbor in the lists off to make */ + /* room for the new neighbor (ignore last neighbor in lists). */ + i = *nnbrs-2; + /* Otherwise, there is a list overflow error condition */ + /* (shouldn't ever happen, but just in case) ... */ + else{ + fprintf(stderr, + "ERROR : insert_neighbor : overflow in neighbor lists\n"); + return(-481); + } + + /* While we havn't reached the desired insertion point ... */ + while(i >= pos){ + /* Shift the current neighbor down the list 1 positon. */ + nbr_list[i+1] = nbr_list[i]; + nbr_sqr_dists[i+1] = nbr_sqr_dists[i]; + i--; + } + + /* We are now ready to put our new neighbor in the position where */ + /* we shifted everything down from to make room. */ + nbr_list[pos] = nbr_index; + nbr_sqr_dists[pos] = nbr_dist2; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: update_nbr_dists - Takes the current list of neighbors along with a +#cat: primary minutia and a potential new neighbor, and +#cat: determines if the new neighbor is sufficiently close +#cat: to be added to the list of nearest neighbors. If added, +#cat: it is placed in the list in its proper order based on +#cat: squared distance to the primary point. + + Input: + nbr_list - current list of nearest neighbor minutia indices + nbr_sqr_dists - corresponding squared euclidean distance of each + neighbor to the primary minutia point + nnbrs - number of neighbors currently in the list + max_nbrs - maximum number of closest neighbors to be returned + first - index of the primary minutia point + second - index of the secondary (new neighbor) point + minutiae - list of minutiae + Output: + nbr_list - updated list of nearest neighbor indices + nbr_sqr_dists - updated list of nearest neighbor distances + nnbrs - number of neighbors in the update lists + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int update_nbr_dists(int *nbr_list, double *nbr_sqr_dists, + int *nnbrs, const int max_nbrs, + const int first, const int second, MINUTIAE *minutiae) +{ + double dist2; + MINUTIA *minutia1, *minutia2; + int pos, last_nbr; + + /* Compute position of maximum last neighbor stored. */ + last_nbr = max_nbrs - 1; + + /* Assigne temporary minutia pointers. */ + minutia1 = minutiae->list[first]; + minutia2 = minutiae->list[second]; + + /* Compute squared euclidean distance between minutia pair. */ + dist2 = squared_distance(minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + + /* If maximum number of neighbors not yet stored in lists OR */ + /* if the squared distance to current secondary is less */ + /* than the largest stored neighbor distance ... */ + if((*nnbrs < max_nbrs) || + (dist2 < nbr_sqr_dists[last_nbr])){ + + /* Find insertion point in neighbor lists. */ + pos = find_incr_position_dbl(dist2, nbr_sqr_dists, *nnbrs); + /* If the position returned is >= maximum list length (this should */ + /* never happen, but just in case) ... */ + if(pos >= max_nbrs){ + fprintf(stderr, + "ERROR : update_nbr_dists : illegal position for new neighbor\n"); + return(-470); + } + /* Insert the new neighbor into the neighbor lists at the */ + /* specified location. */ + if(insert_neighbor(pos, second, dist2, + nbr_list, nbr_sqr_dists, nnbrs, max_nbrs)) + return(-471); + + /* Otherwise, neighbor inserted successfully, so return normally. */ + return(0); + } + /* Otherwise, the new neighbor is not sufficiently close to be */ + /* added or inserted into the neighbor lists, so ignore the neighbor */ + /* and return normally. */ + else + return(0); + +} + +/************************************************************************* +************************************************************************** +#cat: find_neighbors - Takes a primary minutia and a list of all minutiae +#cat: and locates a specified maximum number of closest neighbors +#cat: to the primary point. Neighbors are searched, starting +#cat: in the same pixel column, below, the primary point and then +#cat: along consecutive and complete pixel columns in the image +#cat: to the right of the primary point. + + Input: + max_nbrs - maximum number of closest neighbors to be returned + first - index of the primary minutia point + minutiae - list of minutiae + Output: + onbr_list - points to list of detected closest neighbors + onnbrs - points to number of neighbors returned + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, + const int first, MINUTIAE *minutiae) +{ + int ret, second, last_nbr; + MINUTIA *minutia1, *minutia2; + int *nbr_list, nnbrs; + double *nbr_sqr_dists, xdist, xdist2; + + /* Allocate list of neighbor minutiae indices. */ + nbr_list = (int *)malloc(max_nbrs * sizeof(int)); + if(nbr_list == (int *)NULL){ + fprintf(stderr, "ERROR : find_neighbors : malloc : nbr_list\n"); + return(-460); + } + + /* Allocate list of squared euclidean distances between neighbors */ + /* and current primary minutia point. */ + nbr_sqr_dists = (double *)malloc(max_nbrs * sizeof(double)); + if(nbr_sqr_dists == (double *)NULL){ + free(nbr_list); + fprintf(stderr, + "ERROR : find_neighbors : malloc : nbr_sqr_dists\n"); + return(-461); + } + + /* Initialize number of stored neighbors to 0. */ + nnbrs = 0; + /* Assign secondary to one passed current primary minutia. */ + second = first + 1; + /* Compute location of maximum last stored neighbor. */ + last_nbr = max_nbrs - 1; + + /* While minutia (in sorted order) still remian for processing ... */ + /* NOTE: The minutia in the input list have been sorted on X and */ + /* then on Y. So, the neighbors are selected according to those */ + /* that lie below the primary minutia in the same pixel column and */ + /* then subsequently those that lie in complete pixel columns to */ + /* the right of the primary minutia. */ + while(second < minutiae->num){ + /* Assign temporary minutia pointers. */ + minutia1 = minutiae->list[first]; + minutia2 = minutiae->list[second]; + + /* Compute squared distance between minutiae along x-axis. */ + xdist = minutia2->x - minutia1->x; + xdist2 = xdist * xdist; + + /* If the neighbor lists are not full OR the x-distance to current */ + /* secondary is smaller than maximum neighbor distance stored ... */ + if((nnbrs < max_nbrs) || + (xdist2 < nbr_sqr_dists[last_nbr])){ + /* Append or insert the new neighbor into the neighbor lists. */ + if((ret = update_nbr_dists(nbr_list, nbr_sqr_dists, &nnbrs, max_nbrs, + first, second, minutiae))){ + free(nbr_sqr_dists); + return(ret); + } + } + /* Otherwise, if the neighbor lists is full AND the x-distance */ + /* to current secondary is larger than maximum neighbor distance */ + /* stored ... */ + else + /* So, stop searching for more neighbors. */ + break; + + /* Bump to next secondary minutia. */ + second++; + } + + /* Deallocate working memory. */ + free(nbr_sqr_dists); + + /* If no neighbors found ... */ + if(nnbrs == 0){ + /* Deallocate the neighbor list. */ + free(nbr_list); + *onnbrs = 0; + } + /* Otherwise, assign neighbors to output pointer. */ + else{ + *onbr_list = nbr_list; + *onnbrs = nnbrs; + } + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: sort_neighbors - Takes a list of primary minutia and its neighboring +#cat: minutia indices and sorts the neighbors based on their +#cat: position relative to the primary minutia point. Neighbors +#cat: are sorted starting vertical to the primary point and +#cat: proceeding clockwise. + + Input: + nbr_list - list of neighboring minutia indices + nnbrs - number of neighbors in the list + first - the index of the primary minutia point + minutiae - list of minutiae + Output: + nbr_list - neighboring minutia indices in sorted order + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int sort_neighbors(int *nbr_list, const int nnbrs, const int first, + MINUTIAE *minutiae) +{ + double *join_thetas, theta; + int i; + static double pi2 = M_PI*2.0; + + /* List of angles of lines joining the current primary to each */ + /* of the secondary neighbors. */ + join_thetas = (double *)malloc(nnbrs * sizeof(double)); + if(join_thetas == (double *)NULL){ + fprintf(stderr, "ERROR : sort_neighbors : malloc : join_thetas\n"); + return(-490); + } + + for(i = 0; i < nnbrs; i++){ + /* Compute angle to line connecting the 2 points. */ + /* Coordinates are swapped and order of points reversed to */ + /* account for 0 direction is vertical and positive direction */ + /* is clockwise. */ + theta = angle2line(minutiae->list[nbr_list[i]]->y, + minutiae->list[nbr_list[i]]->x, + minutiae->list[first]->y, + minutiae->list[first]->x); + + /* Make sure the angle is positive. */ + theta += pi2; + theta = fmod(theta, pi2); + join_thetas[i] = theta; + } + + /* Sort the neighbor indicies into rank order. */ + bubble_sort_double_inc_2(join_thetas, nbr_list, nnbrs); + + /* Deallocate the list of angles. */ + free(join_thetas); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: find_transition - Takes a pixel trajectory and a starting index, and +#cat: searches forward along the trajectory until the specified +#cat: adjacent pixel pair is found, returning the index where +#cat: the pair was found (the index of the second pixel). + + Input: + iptr - pointer to starting pixel index into trajectory + pix1 - first pixel value in transition pair + pix2 - second pixel value in transition pair + xlist - x-pixel coords of line trajectory + ylist - y-pixel coords of line trajectory + num - number of coords in line trajectory + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + iptr - points to location where 2nd pixel in pair is found + Return Code: + TRUE - pixel pair transition found + FALSE - pixel pair transition not found +**************************************************************************/ +static int find_transition(int *iptr, const int pix1, const int pix2, + const int *xlist, const int *ylist, const int num, + unsigned char *bdata, const int iw, const int ih) +{ + int i, j; + + /* Set previous index to starting position. */ + i = *iptr; + /* Bump previous index by 1 to get next index. */ + j = i+1; + + /* While not one point from the end of the trajectory .. */ + while(i < num-1){ + /* If we have found the desired transition ... */ + if((*(bdata+(ylist[i]*iw)+xlist[i]) == pix1) && + (*(bdata+(ylist[j]*iw)+xlist[j]) == pix2)){ + /* Adjust the position pointer to the location of the */ + /* second pixel in the transition. */ + *iptr = j; + + /* Return TRUE. */ + return(TRUE); + } + /* Otherwise, the desired transition was not found in current */ + /* pixel pair, so bump to the next pair along the trajector. */ + i++; + j++; + } + + /* If we get here, then we exhausted the trajector without finding */ + /* the desired transition, so set the position pointer to the end */ + /* of the trajector, and return FALSE. */ + *iptr = num; + return(FALSE); +} + +/************************************************************************* +************************************************************************** +#cat: validate_ridge_crossing - Takes a pair of points, a ridge start +#cat: transition and a ridge end transition, and walks the +#cat: ridge contour from thre ridge end points a specified +#cat: number of steps, looking for the ridge start point. +#cat: If found, then transitions determined not to be a valid +#cat: ridge crossing. + + Input: + ridge_start - index into line trajectory of ridge start transition + ridge_end - index into line trajectory of ridge end transition + xlist - x-pixel coords of line trajectory + ylist - y-pixel coords of line trajectory + num - number of coords in line trajectory + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + max_ridge_steps - number of steps taken in search in both + scan directions + Return Code: + TRUE - ridge crossing VALID + FALSE - ridge corssing INVALID + Negative - system error +**************************************************************************/ +static int validate_ridge_crossing(const int ridge_start, const int ridge_end, + const int *xlist, const int *ylist, const int num, + unsigned char *bdata, const int iw, const int ih, + const int max_ridge_steps) +{ + int ret; + int feat_x, feat_y, edge_x, edge_y; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + + /* Assign edge pixel pair for contour trace. */ + feat_x = xlist[ridge_end]; + feat_y = ylist[ridge_end]; + edge_x = xlist[ridge_end-1]; + edge_y = ylist[ridge_end-1]; + + /* Adjust pixel pair if they neighbor each other diagonally. */ + fix_edge_pixel_pair(&feat_x, &feat_y, &edge_x, &edge_y, + bdata, iw, ih); + + /* Trace ridge contour, starting at the ridge end transition, and */ + /* taking a specified number of step scanning for edge neighbors */ + /* clockwise. As we trace the ridge, we want to detect if we */ + /* encounter the ridge start transition. NOTE: The ridge end */ + /* position is on the white (of a black to white transition) and */ + /* the ridge start is on the black (of a black to white trans), */ + /* so the edge trace needs to look for the what pixel (not the */ + /* black one) of the ridge start transition. */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + max_ridge_steps, + xlist[ridge_start-1], ylist[ridge_start-1], + feat_x, feat_y, edge_x, edge_y, + SCAN_CLOCKWISE, bdata, iw, ih); + /* If a system error occurred ... */ + if(ret < 0) + /* Return error code. */ + return(ret); + + /* Otherwise, if the trace was not IGNORED, then a contour was */ + /* was generated and returned. We aren't interested in the */ + /* actual contour, so deallocate it. */ + if(ret != IGNORE) + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /* If the trace was IGNORED, then we had some sort of initialization */ + /* problem, so treat this the same as if was actually located the */ + /* ridge start point (in which case LOOP_FOUND is returned). */ + /* So, If not IGNORED and ridge start not encounted in trace ... */ + if((ret != IGNORE) && + (ret != LOOP_FOUND)){ + + /* Now conduct contour trace scanning for edge neighbors counter- */ + /* clockwise. */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + max_ridge_steps, + xlist[ridge_start-1], ylist[ridge_start-1], + feat_x, feat_y, edge_x, edge_y, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); + /* If a system error occurred ... */ + if(ret < 0) + /* Return error code. */ + return(ret); + + /* Otherwise, if the trace was not IGNORED, then a contour was */ + /* was generated and returned. We aren't interested in the */ + /* actual contour, so deallocate it. */ + if(ret != IGNORE) + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /* If trace not IGNORED and ridge start not encounted in 2nd trace ... */ + if((ret != IGNORE) && + (ret != LOOP_FOUND)){ + /* If we get here, assume we have a ridge crossing. */ + return(TRUE); + } + /* Otherwise, second trace returned IGNORE or ridge start found. */ + } + /* Otherwise, first trace returned IGNORE or ridge start found. */ + + /* If we get here, then we failed to validate a ridge crossing. */ + return(FALSE); +} + +/************************************************************************* +************************************************************************** +#cat: ridge_count - Takes a pair of minutiae, and counts the number of +#cat: ridges crossed along the linear trajectory connecting +#cat: the 2 points in the image. + + Input: + first - index of primary minutia + second - index of secondary (neighbor) minutia + minutiae - list of minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Zero or Positive - number of ridges counted + Negative - system error +**************************************************************************/ +static int ridge_count(const int first, const int second, MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + MINUTIA *minutia1, *minutia2; + int i, ret, found; + int *xlist, *ylist, num; + int ridge_count, ridge_start, ridge_end; + int prevpix, curpix; + + minutia1 = minutiae->list[first]; + minutia2 = minutiae->list[second]; + + /* If the 2 mintuia have identical pixel coords ... */ + if((minutia1->x == minutia2->x) && + (minutia1->y == minutia2->y)) + /* Then zero ridges between points. */ + return(0); + + /* Compute linear trajectory of contiguous pixels between first */ + /* and second minutia points. */ + if((ret = line_points(&xlist, &ylist, &num, + minutia1->x, minutia1->y, minutia2->x, minutia2->y))){ + return(ret); + } + + /* It there are no points on the line trajectory, then no ridges */ + /* to count (this should not happen, but just in case) ... */ + if(num == 0){ + free(xlist); + free(ylist); + return(0); + } + + /* Find first pixel opposite type along linear trajectory from */ + /* first minutia. */ + prevpix = *(bdata+(ylist[0]*iw)+xlist[0]); + i = 1; + found = FALSE; + while(i < num){ + curpix = *(bdata+(ylist[i]*iw)+xlist[i]); + if(curpix != prevpix){ + found = TRUE; + break; + } + i++; + } + + /* If opposite pixel not found ... then no ridges to count */ + if(!found){ + free(xlist); + free(ylist); + return(0); + } + + /* Ready to count ridges, so initialize counter to 0. */ + ridge_count = 0; + + print2log("RIDGE COUNT: %d,%d to %d,%d ", minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + + /* While not at the end of the trajectory ... */ + while(i < num){ + /* If 0-to-1 transition not found ... */ + if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){ + /* Then we are done looking for ridges. */ + free(xlist); + free(ylist); + + print2log("\n"); + + /* Return number of ridges counted to this point. */ + return(ridge_count); + } + /* Otherwise, we found a new ridge start transition, so store */ + /* its location (the location of the 1 in 0-to-1 transition). */ + ridge_start = i; + + print2log(": RS %d,%d ", xlist[i], ylist[i]); + + /* If 1-to-0 transition not found ... */ + if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){ + /* Then we are done looking for ridges. */ + free(xlist); + free(ylist); + + print2log("\n"); + + /* Return number of ridges counted to this point. */ + return(ridge_count); + } + /* Otherwise, we found a new ridge end transition, so store */ + /* its location (the location of the 0 in 1-to-0 transition). */ + ridge_end = i; + + print2log("; RE %d,%d ", xlist[i], ylist[i]); + + /* Conduct the validation, tracing the contour of the ridge */ + /* from the ridge ending point a specified number of steps */ + /* scanning for neighbors clockwise and counter-clockwise. */ + /* If the ridge starting point is encounted during the trace */ + /* then we can assume we do not have a valid ridge crossing */ + /* and instead we are walking on and off the edge of the */ + /* side of a ridge. */ + ret = validate_ridge_crossing(ridge_start, ridge_end, + xlist, ylist, num, bdata, iw, ih, + lfsparms->max_ridge_steps); + + /* If system error ... */ + if(ret < 0){ + free(xlist); + free(ylist); + /* Return the error code. */ + return(ret); + } + + print2log("; V%d ", ret); + + /* If validation result is TRUE ... */ + if(ret){ + /* Then assume we have found a valid ridge crossing and bump */ + /* the ridge counter. */ + ridge_count++; + } + + /* Otherwise, ignore the current ridge start and end transitions */ + /* and go back and search for new ridge start. */ + } + + /* Deallocate working memories. */ + free(xlist); + free(ylist); + + print2log("\n"); + + /* Return the number of ridges counted. */ + return(ridge_count); +} + +/************************************************************************* +************************************************************************** +#cat: count_minutia_ridges - Takes a minutia, and determines its closest +#cat: neighbors and counts the number of interveining ridges +#cat: between the minutia point and each of its neighbors. + + Input: + minutia - input minutia + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - minutia augmented with neighbors and ridge counts + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int count_minutia_ridges(const int first, MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int i, ret, *nbr_list, *nbr_nridges, nnbrs; + + /* Find up to the maximum number of qualifying neighbors. */ + if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, + first, minutiae))){ + free(nbr_list); + return(ret); + } + + print2log("NBRS FOUND: %d,%d = %d\n", minutiae->list[first]->x, + minutiae->list[first]->y, nnbrs); + + /* If no neighors found ... */ + if(nnbrs == 0){ + /* Then no list returned and no ridges to count. */ + return(0); + } + + /* Sort neighbors on delta dirs. */ + if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){ + free(nbr_list); + return(ret); + } + + /* Count ridges between first and neighbors. */ + /* List of ridge counts, one for each neighbor stored. */ + nbr_nridges = (int *)malloc(nnbrs * sizeof(int)); + if(nbr_nridges == (int *)NULL){ + free(nbr_list); + fprintf(stderr, "ERROR : count_minutia_ridges : malloc : nbr_nridges\n"); + return(-450); + } + + /* Foreach neighbor found and sorted in list ... */ + for(i = 0; i < nnbrs; i++){ + /* Count the ridges between the primary minutia and the neighbor. */ + ret = ridge_count(first, nbr_list[i], minutiae, bdata, iw, ih, lfsparms); + /* If system error ... */ + if(ret < 0){ + /* Deallocate working memories. */ + free(nbr_list); + free(nbr_nridges); + /* Return error code. */ + return(ret); + } + + /* Otherwise, ridge count successful, so store ridge count to list. */ + nbr_nridges[i] = ret; + } + + /* Assign neighbor indices and ridge counts to primary minutia. */ + minutiae->list[first]->nbrs = nbr_list; + minutiae->list[first]->ridge_counts = nbr_nridges; + minutiae->list[first]->num_nbrs = nnbrs; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: count_minutiae_ridges - Takes a list of minutiae, and for each one, +#cat: determines its closest neighbors and counts the number +#cat: of interveining ridges between the minutia point and +#cat: each of its neighbors. + + Input: + minutiae - list of minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of minutiae augmented with neighbors and ridge counts + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int count_minutiae_ridges(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int ret; + int i; + + print2log("\nFINDING NBRS AND COUNTING RIDGES:\n"); + + /* Sort minutia points on x then y (column-oriented). */ + if((ret = sort_minutiae_x_y(minutiae, iw, ih))){ + return(ret); + } + + /* Remove any duplicate minutia points from the list. */ + if((ret = rm_dup_minutiae(minutiae))){ + return(ret); + } + + /* Foreach remaining sorted minutia in list ... */ + for(i = 0; i < minutiae->num-1; i++){ + /* Located neighbors and count number of ridges in between. */ + /* NOTE: neighbor and ridge count results are stored in */ + /* minutiae->list[i]. */ + if((ret = count_minutia_ridges(i, minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + } + + /* Return normally. */ + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/matchpat.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/matchpat.c.svn-base @@ -0,0 +1,271 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: MATCHPAT.C + AUTHOR: Michael D. Garris + DATE: 05/11/1999 + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for matching minutia feature + patterns as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + match_1st_pair() + match_2nd_pair() + match_3rd_pair() + skip_repeated_horizontal_pair() + skip_repeated_vertical_pair() +***********************************************************************/ + +#include +#include + +/************************************************************************* +************************************************************************** +#cat: match_1st_pair - Determines which of the feature_patterns[] have their +#cat: first pixel pair match the specified pixel pair. + + Input: + p1 - first pixel value of pair + p2 - second pixel value of pair + Output: + possible - list of matching feature_patterns[] indices + nposs - number of matches + Return Code: + nposs - number of matches +*************************************************************************/ +int match_1st_pair(unsigned char p1, unsigned char p2, + int *possible, int *nposs) +{ + int i; + + /* Set possibilities to 0 */ + *nposs = 0; + + /* Foreach set of feature pairs ... */ + for(i = 0; i < NFEATURES; i++){ + /* If current scan pair matches first pair for feature ... */ + if((p1==feature_patterns[i].first[0]) && + (p2==feature_patterns[i].first[1])){ + /* Store feature as a possible match. */ + possible[*nposs] = i; + /* Bump number of stored possibilities. */ + (*nposs)++; + } + } + + /* Return number of stored possibilities. */ + return(*nposs); +} + +/************************************************************************* +************************************************************************** +#cat: match_2nd_pair - Determines which of the passed feature_patterns[] have +#cat: their second pixel pair match the specified pixel pair. + + Input: + p1 - first pixel value of pair + p2 - second pixel value of pair + possible - list of potentially-matching feature_patterns[] indices + nposs - number of potential matches + Output: + possible - list of matching feature_patterns[] indices + nposs - number of matches + Return Code: + nposs - number of matches +*************************************************************************/ +int match_2nd_pair(unsigned char p1, unsigned char p2, + int *possible, int *nposs) +{ + int i; + int tnposs; + + /* Store input possibilities. */ + tnposs = *nposs; + /* Reset output possibilities to 0. */ + *nposs = 0; + + /* If current scan pair values are the same ... */ + if(p1 == p2) + /* Simply return because pair can't be a second feature pair. */ + return(*nposs); + + /* Foreach possible match based on first pair ... */ + for(i = 0; i < tnposs; i++){ + /* If current scan pair matches second pair for feature ... */ + if((p1==feature_patterns[possible[i]].second[0]) && + (p2==feature_patterns[possible[i]].second[1])){ + /* Store feature as a possible match. */ + possible[*nposs] = possible[i]; + /* Bump number of stored possibilities. */ + (*nposs)++; + } + } + + /* Return number of stored possibilities. */ + return(*nposs); +} + +/************************************************************************* +************************************************************************** +#cat: match_3rd_pair - Determines which of the passed feature_patterns[] have +#cat: their third pixel pair match the specified pixel pair. + + Input: + p1 - first pixel value of pair + p2 - second pixel value of pair + possible - list of potentially-matching feature_patterns[] indices + nposs - number of potential matches + Output: + possible - list of matching feature_patterns[] indices + nposs - number of matches + Return Code: + nposs - number of matches +*************************************************************************/ +int match_3rd_pair(unsigned char p1, unsigned char p2, + int *possible, int *nposs) +{ + int i; + int tnposs; + + /* Store input possibilities. */ + tnposs = *nposs; + /* Reset output possibilities to 0. */ + *nposs = 0; + + /* Foreach possible match based on first and second pairs ... */ + for(i = 0; i < tnposs; i++){ + /* If current scan pair matches third pair for feature ... */ + if((p1==feature_patterns[possible[i]].third[0]) && + (p2==feature_patterns[possible[i]].third[1])){ + /* Store feature as a possible match. */ + possible[*nposs] = possible[i]; + /* Bump number of stored possibilities. */ + (*nposs)++; + } + } + + /* Return number of stored possibilities. */ + return(*nposs); +} + +/************************************************************************* +************************************************************************** +#cat: skip_repeated_horizontal_pair - Takes the location of two pixel in +#cat: adjacent pixel rows within an image region and skips +#cat: rightward until the either the pixel pair no longer repeats +#cat: itself or the image region is exhausted. + + Input: + cx - current x-coord of starting pixel pair + ex - right edge of the image region + p1ptr - pointer to current top pixel in pair + p2ptr - pointer to current bottom pixel in pair + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + cx - x-coord of where rightward skip terminated + p1ptr - points to top pixel where rightward skip terminated + p2ptr - points to bottom pixel where rightward skip terminated +*************************************************************************/ +void skip_repeated_horizontal_pair(int *cx, const int ex, + unsigned char **p1ptr, unsigned char **p2ptr, + const int iw, const int ih) +{ + int old1, old2; + + /* Store starting pixel pair. */ + old1 = **p1ptr; + old2 = **p2ptr; + + /* Bump horizontally to next pixel pair. */ + (*cx)++; + (*p1ptr)++; + (*p2ptr)++; + + /* While not at right of scan region... */ + while(*cx < ex){ + /* If one or the other pixels in the new pair are different */ + /* from the starting pixel pair... */ + if((**p1ptr != old1) || (**p2ptr != old2)) + /* Done skipping repreated pixel pairs. */ + return; + /* Otherwise, bump horizontally to next pixel pair. */ + (*cx)++; + (*p1ptr)++; + (*p2ptr)++; + } +} + +/************************************************************************* +************************************************************************** +#cat: skip_repeated_vertical_pair - Takes the location of two pixel in +#cat: adjacent pixel columns within an image region and skips +#cat: downward until the either the pixel pair no longer repeats +#cat: itself or the image region is exhausted. + + Input: + cy - current y-coord of starting pixel pair + ey - bottom of the image region + p1ptr - pointer to current left pixel in pair + p2ptr - pointer to current right pixel in pair + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + cy - y-coord of where downward skip terminated + p1ptr - points to left pixel where downward skip terminated + p2ptr - points to right pixel where donward skip terminated +*************************************************************************/ +void skip_repeated_vertical_pair(int *cy, const int ey, + unsigned char **p1ptr, unsigned char **p2ptr, + const int iw, const int ih) +{ + int old1, old2; + + /* Store starting pixel pair. */ + old1 = **p1ptr; + old2 = **p2ptr; + + /* Bump vertically to next pixel pair. */ + (*cy)++; + (*p1ptr)+=iw; + (*p2ptr)+=iw; + + /* While not at bottom of scan region... */ + while(*cy < ey){ + /* If one or the other pixels in the new pair are different */ + /* from the starting pixel pair... */ + if((**p1ptr != old1) || (**p2ptr != old2)) + /* Done skipping repreated pixel pairs. */ + return; + /* Otherwise, bump vertically to next pixel pair. */ + (*cy)++; + (*p1ptr)+=iw; + (*p2ptr)+=iw; + } +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/remove.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/remove.c.svn-base @@ -0,0 +1,2109 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: REMOVE.C + AUTHOR: Michael D. Garris + DATE: 08/02/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for detecting and removing false + minutiae as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + remove_false_minutia_V2() + remove_holes() + remove_hooks() + remove_islands_and_lakes() + remove_malformations() + remove_near_invblock_V2() + remove_pointing_invblock_V2() + remove_overlaps() + remove_pores_V2() + remove_or_adjust_side_minutiae_V2() + +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: remove_holes - Removes minutia points on small loops around valleys. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_holes(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int i, ret; + MINUTIA *minutia; + + print2log("\nREMOVING HOLES:\n"); + + i = 0; + /* Foreach minutia remaining in list ... */ + while(i < minutiae->num){ + /* Assign a temporary pointer. */ + minutia = minutiae->list[i]; + /* If current minutia is a bifurcation ... */ + if(minutia->type == BIFURCATION){ + /* Check to see if it is on a loop of specified length (ex. 15). */ + ret = on_loop(minutia, lfsparms->small_loop_len, bdata, iw, ih); + /* If minutia is on a loop ... or loop test IGNORED */ + if((ret == LOOP_FOUND) || (ret == IGNORE)){ + + print2log("%d,%d RM\n", minutia->x, minutia->y); + + /* Then remove the minutia from list. */ + if((ret = remove_minutia(i, minutiae))){ + /* Return error code. */ + return(ret); + } + /* No need to advance because next minutia has "slid" */ + /* into position pointed to by 'i'. */ + } + /* If the minutia is NOT on a loop... */ + else if (ret == FALSE){ + /* Simply advance to next minutia in the list. */ + i++; + } + /* Otherwise, an ERROR occurred while looking for loop. */ + else{ + /* Return error code. */ + return(ret); + } + } + /* Otherwise, the current minutia is a ridge-ending... */ + else{ + /* Advance to next minutia in the list. */ + i++; + } + } + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_hooks - Takes a list of true and false minutiae and +#cat: attempts to detect and remove those false minutiae that +#cat: are on a hook (white or black). + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_hooks(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int *to_remove; + int i, f, s, ret; + int delta_y, full_ndirs, qtr_ndirs, deltadir, min_deltadir; + MINUTIA *minutia1, *minutia2; + double dist; + + print2log("\nREMOVING HOOKS:\n"); + + /* Allocate list of minutia indices that upon completion of testing */ + /* should be removed from the minutiae lists. Note: That using */ + /* "calloc" initializes the list to FALSE. */ + to_remove = (int *)calloc(minutiae->num, sizeof(int)); + if(to_remove == (int *)NULL){ + fprintf(stderr, "ERROR : remove_hooks : calloc : to_remove\n"); + return(-640); + } + + /* Compute number directions in full circle. */ + full_ndirs = lfsparms->num_directions<<1; + /* Compute number of directions in 45=(180/4) degrees. */ + qtr_ndirs = lfsparms->num_directions>>2; + + /* Minimum allowable deltadir to consider joining minutia. */ + /* (The closer the deltadir is to 180 degrees, the more likely the join. */ + /* When ndirs==16, then this value is 11=(3*4)-1 == 123.75 degrees. */ + /* I chose to parameterize this threshold based on a fixed fraction of */ + /* 'ndirs' rather than on passing in a parameter in degrees and doing */ + /* the conversion. I doubt the difference matters. */ + min_deltadir = (3 * qtr_ndirs) - 1; + + f = 0; + /* Foreach primary (first) minutia (except for last one in list) ... */ + while(f < minutiae->num-1){ + + /* If current first minutia not previously set to be removed. */ + if(!to_remove[f]){ + + print2log("\n"); + + /* Set first minutia to temporary pointer. */ + minutia1 = minutiae->list[f]; + /* Foreach secondary (second) minutia to right of first minutia ... */ + s = f+1; + while(s < minutiae->num){ + /* Set second minutia to temporary pointer. */ + minutia2 = minutiae->list[s]; + + print2log("1:%d(%d,%d)%d 2:%d(%d,%d)%d ", + f, minutia1->x, minutia1->y, minutia1->type, + s, minutia2->x, minutia2->y, minutia2->type); + + /* The binary image is potentially being edited during each */ + /* iteration of the secondary minutia loop, therefore */ + /* minutia pixel values may be changed. We need to catch */ + /* these events by using the next 2 tests. */ + + /* If the first minutia's pixel has been previously changed... */ + if(*(bdata+(minutia1->y*iw)+minutia1->x) != minutia1->type){ + print2log("\n"); + /* Then break out of secondary loop and skip to next first. */ + break; + } + + /* If the second minutia's pixel has been previously changed... */ + if(*(bdata+(minutia2->y*iw)+minutia2->x) != minutia2->type) + /* Set to remove second minutia. */ + to_remove[s] = TRUE; + + /* If the second minutia not previously set to be removed. */ + if(!to_remove[s]){ + + /* Compute delta y between 1st & 2nd minutiae and test. */ + delta_y = minutia2->y - minutia1->y; + /* If delta y small enough (ex. < 8 pixels) ... */ + if(delta_y <= lfsparms->max_rmtest_dist){ + + print2log("1DY "); + + /* Compute Euclidean distance between 1st & 2nd mintuae. */ + dist = distance(minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + /* If distance is NOT too large (ex. < 8 pixels) ... */ + if(dist <= lfsparms->max_rmtest_dist){ + + print2log("2DS "); + + /* Compute "inner" difference between directions on */ + /* a full circle and test. */ + if((deltadir = closest_dir_dist(minutia1->direction, + minutia2->direction, full_ndirs)) == + INVALID_DIR){ + free(to_remove); + fprintf(stderr, + "ERROR : remove_hooks : INVALID direction\n"); + return(-641); + } + /* If the difference between dirs is large enough ... */ + /* (the more 1st & 2nd point away from each other the */ + /* more likely they should be joined) */ + if(deltadir > min_deltadir){ + + print2log("3DD "); + + /* If 1st & 2nd minutiae are NOT same type ... */ + if(minutia1->type != minutia2->type){ + /* Check to see if pair on a hook with contour */ + /* of specified length (ex. 15 pixels) ... */ + + ret = on_hook(minutia1, minutia2, + lfsparms->max_hook_len, + bdata, iw, ih); + + /* If hook detected between pair ... */ + if(ret == HOOK_FOUND){ + + print2log("4HK RM\n"); + + /* Set to remove first minutia. */ + to_remove[f] = TRUE; + /* Set to remove second minutia. */ + to_remove[s] = TRUE; + } + /* If hook test IGNORED ... */ + else if (ret == IGNORE){ + + print2log("RM\n"); + + /* Set to remove first minutia. */ + to_remove[f] = TRUE; + /* Skip to next 1st minutia by breaking out of */ + /* inner secondary loop. */ + break; + } + /* If system error occurred during hook test ... */ + else if (ret < 0){ + free(to_remove); + return(ret); + } + /* Otherwise, no hook found, so skip to next */ + /* second minutia. */ + else + print2log("\n"); + } + else + print2log("\n"); + /* End different type test. */ + }/* End deltadir test. */ + else + print2log("\n"); + }/* End distance test. */ + else + print2log("\n"); + } + /* Otherwise, current 2nd too far below 1st, so skip to next */ + /* 1st minutia. */ + else{ + + print2log("\n"); + + /* Break out of inner secondary loop. */ + break; + }/* End delta-y test. */ + + }/* End if !to_remove[s] */ + else + print2log("\n"); + + /* Bump to next second minutia in minutiae list. */ + s++; + }/* End secondary minutiae loop. */ + + }/* Otherwise, first minutia already flagged to be removed. */ + + /* Bump to next first minutia in minutiae list. */ + f++; + }/* End primary minutiae loop. */ + + /* Now remove all minutiae in list that have been flagged for removal. */ + /* NOTE: Need to remove the minutia from their lists in reverse */ + /* order, otherwise, indices will be off. */ + for(i = minutiae->num-1; i >= 0; i--){ + /* If the current minutia index is flagged for removal ... */ + if(to_remove[i]){ + /* Remove the minutia from the minutiae list. */ + if((ret = remove_minutia(i, minutiae))){ + free(to_remove); + return(ret); + } + } + } + + /* Deallocate flag list. */ + free(to_remove); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_islands_and_lakes - Takes a list of true and false minutiae and +#cat: attempts to detect and remove those false minutiae that +#cat: are either on a common island (filled with black pixels) +#cat: or a lake (filled with white pixels). +#cat: Note that this routine edits the binary image by filling +#cat: detected lakes or islands. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_islands_and_lakes(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int *to_remove; + int i, f, s, ret; + int delta_y, full_ndirs, qtr_ndirs, deltadir, min_deltadir; + int *loop_x, *loop_y, *loop_ex, *loop_ey, nloop; + MINUTIA *minutia1, *minutia2; + double dist; + int dist_thresh, half_loop; + + print2log("\nREMOVING ISLANDS AND LAKES:\n"); + + dist_thresh = lfsparms->max_rmtest_dist; + half_loop = lfsparms->max_half_loop; + + /* Allocate list of minutia indices that upon completion of testing */ + /* should be removed from the minutiae lists. Note: That using */ + /* "calloc" initializes the list to FALSE. */ + to_remove = (int *)calloc(minutiae->num, sizeof(int)); + if(to_remove == (int *)NULL){ + fprintf(stderr, + "ERROR : remove_islands_and_lakes : calloc : to_remove\n"); + return(-610); + } + + /* Compute number directions in full circle. */ + full_ndirs = lfsparms->num_directions<<1; + /* Compute number of directions in 45=(180/4) degrees. */ + qtr_ndirs = lfsparms->num_directions>>2; + + /* Minimum allowable deltadir to consider joining minutia. */ + /* (The closer the deltadir is to 180 degrees, the more likely the join. */ + /* When ndirs==16, then this value is 11=(3*4)-1 == 123.75 degrees. */ + /* I chose to parameterize this threshold based on a fixed fraction of */ + /* 'ndirs' rather than on passing in a parameter in degrees and doing */ + /* the conversion. I doubt the difference matters. */ + min_deltadir = (3 * qtr_ndirs) - 1; + + /* Foreach primary (first) minutia (except for last one in list) ... */ + f = 0; + while(f < minutiae->num-1){ + + /* If current first minutia not previously set to be removed. */ + if(!to_remove[f]){ + + print2log("\n"); + + /* Set first minutia to temporary pointer. */ + minutia1 = minutiae->list[f]; + + /* Foreach secondary minutia to right of first minutia ... */ + s = f+1; + while(s < minutiae->num){ + /* Set second minutia to temporary pointer. */ + minutia2 = minutiae->list[s]; + + /* If the secondary minutia is desired type ... */ + if(minutia2->type == minutia1->type){ + + print2log("1:%d(%d,%d)%d 2:%d(%d,%d)%d ", + f, minutia1->x, minutia1->y, minutia1->type, + s, minutia2->x, minutia2->y, minutia2->type); + + /* The binary image is potentially being edited during */ + /* each iteration of the secondary minutia loop, */ + /* therefore minutia pixel values may be changed. We */ + /* need to catch these events by using the next 2 tests. */ + + /* If the first minutia's pixel has been previously */ + /* changed... */ + if(*(bdata+(minutia1->y*iw)+minutia1->x) != minutia1->type){ + print2log("\n"); + /* Then break out of secondary loop and skip to next */ + /* first. */ + break; + } + + /* If the second minutia's pixel has been previously */ + /* changed... */ + if(*(bdata+(minutia2->y*iw)+minutia2->x) != minutia2->type) + /* Set to remove second minutia. */ + to_remove[s] = TRUE; + + /* If the second minutia not previously set to be removed. */ + if(!to_remove[s]){ + + /* Compute delta y between 1st & 2nd minutiae and test. */ + delta_y = minutia2->y - minutia1->y; + /* If delta y small enough (ex. <16 pixels)... */ + if(delta_y <= dist_thresh){ + + print2log("1DY "); + + /* Compute Euclidean distance between 1st & 2nd */ + /* mintuae. */ + dist = distance(minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + + /* If distance is NOT too large (ex. <16 pixels)... */ + if(dist <= dist_thresh){ + + print2log("2DS "); + + /* Compute "inner" difference between directions */ + /* on a full circle and test. */ + if((deltadir = closest_dir_dist(minutia1->direction, + minutia2->direction, full_ndirs)) == + INVALID_DIR){ + free(to_remove); + fprintf(stderr, + "ERROR : remove_islands_and_lakes : INVALID direction\n"); + return(-611); + } + /* If the difference between dirs is large */ + /* enough ... */ + /* (the more 1st & 2nd point away from each */ + /* other the more likely they should be joined) */ + if(deltadir > min_deltadir){ + + print2log("3DD "); + + /* Pair is the same type, so test to see */ + /* if both are on an island or lake. */ + + /* Check to see if pair on a loop of specified */ + /* half length (ex. 30 pixels) ... */ + ret = on_island_lake(&loop_x, &loop_y, + &loop_ex, &loop_ey, &nloop, + minutia1, minutia2, + half_loop, bdata, iw, ih); + /* If pair is on island/lake ... */ + if(ret == LOOP_FOUND){ + + print2log("4IL RM\n"); + + /* Fill the loop. */ + if((ret = fill_loop(loop_x, loop_y, nloop, + bdata, iw, ih))){ + free_contour(loop_x, loop_y, + loop_ex, loop_ey); + free(to_remove); + return(ret); + } + /* Set to remove first minutia. */ + to_remove[f] = TRUE; + /* Set to remove second minutia. */ + to_remove[s] = TRUE; + /* Deallocate loop contour. */ + free_contour(loop_x,loop_y,loop_ex,loop_ey); + } + /* If island/lake test IGNORED ... */ + else if (ret == IGNORE){ + + print2log("RM\n"); + + /* Set to remove first minutia. */ + to_remove[f] = TRUE; + /* Skip to next 1st minutia by breaking out */ + /* of inner secondary loop. */ + break; + } + /* If ERROR while looking for island/lake ... */ + else if (ret < 0){ + free(to_remove); + return(ret); + } + else + print2log("\n"); + }/* End deltadir test. */ + else + print2log("\n"); + }/* End distance test. */ + else + print2log("\n"); + } + /* Otherwise, current 2nd too far below 1st, so skip to */ + /* next 1st minutia. */ + else{ + + print2log("\n"); + + /* Break out of inner secondary loop. */ + break; + }/* End delta-y test. */ + }/* End if !to_remove[s] */ + else + print2log("\n"); + + }/* End if 2nd not desired type */ + + /* Bump to next second minutia in minutiae list. */ + s++; + }/* End secondary minutiae loop. */ + + }/* Otherwise, first minutia already flagged to be removed. */ + + /* Bump to next first minutia in minutiae list. */ + f++; + }/* End primary minutiae loop. */ + + /* Now remove all minutiae in list that have been flagged for removal. */ + /* NOTE: Need to remove the minutia from their lists in reverse */ + /* order, otherwise, indices will be off. */ + for(i = minutiae->num-1; i >= 0; i--){ + /* If the current minutia index is flagged for removal ... */ + if(to_remove[i]){ + /* Remove the minutia from the minutiae list. */ + if((ret = remove_minutia(i, minutiae))){ + free(to_remove); + return(ret); + } + } + } + + /* Deallocate flag list. */ + free(to_remove); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_malformations - Attempts to detect and remove minutia points +#cat: that are "irregularly" shaped. Irregularity is measured +#cat: by measuring across the interior of the feature at +#cat: two progressive points down the feature's contour. The +#cat: test is triggered if a pixel of opposite color from the +#cat: feture's type is found. The ratio of the distances across +#cat: the feature at the two points is computed and if the ratio +#cat: is too large then the minutia is determined to be malformed. +#cat: A cursory test is conducted prior to the general tests in +#cat: the event that the minutia lies in a block with LOW RIDGE +#cat: FLOW. In this case, the distance across the feature at +#cat: the second progressive contour point is measured and if +#cat: too large, the point is determined to be malformed. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + low_flow_map - map of image blocks flagged as LOW RIDGE FLOW + mw - width in blocks of the map + mh - height in blocks of the map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_malformations(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *low_flow_map, const int mw, const int mh, + const LFSPARMS *lfsparms) +{ + int i, j, ret; + MINUTIA *minutia; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int ax1, ay1, bx1, by1; + int ax2, ay2, bx2, by2; + int *x_list, *y_list, num; + double a_dist, b_dist, ratio; + int fmapval, removed; + int blk_x, blk_y; + + print2log("\nREMOVING MALFORMATIONS:\n"); + + for(i = minutiae->num-1; i >= 0; i--){ + minutia = minutiae->list[i]; + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->malformation_steps_2, + minutia->x, minutia->y, + minutia->x, minutia->y, minutia->ex, minutia->ey, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred during trace ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible OR loop found OR */ + /* contour is incomplete ... */ + if((ret == IGNORE) || + (ret == LOOP_FOUND) || + (ncontour < lfsparms->malformation_steps_2)){ + /* If contour allocated and returned ... */ + if((ret == LOOP_FOUND) || + (ncontour < lfsparms->malformation_steps_2)) + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + print2log("%d,%d RMA\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + } + /* Otherwise, traced contour is complete. */ + else{ + /* Store 'A1' contour point. */ + ax1 = contour_x[lfsparms->malformation_steps_1-1]; + ay1 = contour_y[lfsparms->malformation_steps_1-1]; + + /* Store 'B1' contour point. */ + bx1 = contour_x[lfsparms->malformation_steps_2-1]; + by1 = contour_y[lfsparms->malformation_steps_2-1]; + + /* Deallocate the contours. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->malformation_steps_2, + minutia->x, minutia->y, + minutia->x, minutia->y, minutia->ex, minutia->ey, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred during trace ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible OR loop found OR */ + /* contour is incomplete ... */ + if((ret == IGNORE) || + (ret == LOOP_FOUND) || + (ncontour < lfsparms->malformation_steps_2)){ + /* If contour allocated and returned ... */ + if((ret == LOOP_FOUND) || + (ncontour < lfsparms->malformation_steps_2)) + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + print2log("%d,%d RMB\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + } + /* Otherwise, traced contour is complete. */ + else{ + /* Store 'A2' contour point. */ + ax2 = contour_x[lfsparms->malformation_steps_1-1]; + ay2 = contour_y[lfsparms->malformation_steps_1-1]; + + /* Store 'B2' contour point. */ + bx2 = contour_x[lfsparms->malformation_steps_2-1]; + by2 = contour_y[lfsparms->malformation_steps_2-1]; + + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + + /* Compute distances along A & B paths. */ + a_dist = distance(ax1, ay1, ax2, ay2); + b_dist = distance(bx1, by1, bx2, by2); + + /* Compute block coords from minutia's pixel location. */ + blk_x = minutia->x/lfsparms->blocksize; + blk_y = minutia->y/lfsparms->blocksize; + + removed = FALSE; + + /* Check to see if distances are not zero. */ + if((a_dist == 0.0) || (b_dist == 0.0)){ + /* Remove the malformation minutia. */ + print2log("%d,%d RMMAL1\n", minutia->x, minutia->y); + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + removed = TRUE; + } + + if(!removed){ + /* Determine if minutia is in LOW RIDGE FLOW block. */ + fmapval = *(low_flow_map+(blk_y*mw)+blk_x); + if(fmapval){ + /* If in LOW RIDGE LFOW, conduct a cursory distance test. */ + /* Need to test this out! */ + if(b_dist > lfsparms->max_malformation_dist){ + /* Remove the malformation minutia. */ + print2log("%d,%d RMMAL2\n", minutia->x, minutia->y); + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + removed = TRUE; + } + } + } + + if(!removed){ + /* Compute points on line between the points A & B. */ + if((ret = line_points(&x_list, &y_list, &num, + bx1, by1, bx2, by2))) + return(ret); + /* Foreach remaining point along line segment ... */ + for(j = 0; j < num; j++){ + /* If B path contains pixel opposite minutia type ... */ + if(*(bdata+(y_list[j]*iw)+x_list[j]) != minutia->type){ + /* Compute ratio of A & B path lengths. */ + ratio = b_dist / a_dist; + /* Need to truncate precision so that answers are */ + /* consistent on different computer architectures. */ + ratio = trunc_dbl_precision(ratio, TRUNC_SCALE); + /* If the B path is sufficiently longer than A path ... */ + if(ratio > lfsparms->min_malformation_ratio){ + /* Remove the malformation minutia. */ + /* Then remove the minutia. */ + print2log("%d,%d RMMAL3 (%f)\n", + minutia->x, minutia->y, ratio); + if((ret = remove_minutia(i, minutiae))){ + free(x_list); + free(y_list); + /* If system error, return error code. */ + return(ret); + } + /* Break out of FOR loop. */ + break; + } + } + } + + free(x_list); + free(y_list); + + } + } + } + } + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_near_invblocks_V2 - Removes minutia points from the given list +#cat: that are sufficiently close to a block with invalid +#cat: ridge flow or to the edge of the image. + + Input: + minutiae - list of true and false minutiae + direction_map - map of image blocks containing direction ridge flow + mw - width in blocks of the map + mh - height in blocks of the map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_near_invblock_V2(MINUTIAE *minutiae, int *direction_map, + const int mw, const int mh, const LFSPARMS *lfsparms) +{ + int i, ret; + int ni, nbx, nby, nvalid; + int ix, iy, sbi, ebi; + int bx, by, px, py; + int removed; + MINUTIA *minutia; + int lo_margin, hi_margin; + + /* The next 2 lookup tables are indexed by 'ix' and 'iy'. */ + /* When a feature pixel lies within a 6-pixel margin of a */ + /* block, this routine examines neighboring blocks to */ + /* determine appropriate actions. */ + /* 'ix' may take on values: */ + /* 0 == x-pixel coord in leftmost margin */ + /* 1 == x-pixel coord in middle of block */ + /* 2 == x-pixel coord in rightmost margin */ + /* 'iy' may take on values: */ + /* 0 == y-pixel coord in topmost margin */ + /* 1 == y-pixel coord in middle of block */ + /* 2 == y-pixel coord in bottommost margin */ + /* Given (ix, iy): */ + /* 'startblk[ix][iy]' == starting neighbor index (sbi) */ + /* 'endblk[ix][iy]' == ending neighbor index (ebi) */ + /* so that neighbors begin to be analized from index */ + /* 'sbi' to 'ebi'. */ + /* Ex. (ix, iy) = (2, 0) */ + /* ix==2 ==> x-pixel coord in rightmost margin */ + /* iy==0 ==> y-pixel coord in topmost margin */ + /* X - marks the region in the current block */ + /* corresponding to (ix=2, iy=0). */ + /* sbi = 0 = startblk[2][0] */ + /* ebi = 2 = endblk[2][0] */ + /* so neighbors are analized on index range [0..2] */ + /* | */ + /* nbr block 0 | nbr block 1 */ + /* --------------------------+------------ */ + /* top margin | X | */ + /* _._._._._._._._._._._._._.| */ + /* | | */ + /* current block .r m| nbr block 2 */ + /* |i a| */ + /* .g g| */ + /* |h i| */ + /* .t n| */ + /* | | */ + + /* LUT for starting neighbor index given (ix, iy). */ + static int startblk[9] = { 6, 0, 0, + 6,-1, 2, + 4, 4, 2 }; + /* LUT for ending neighbor index given (ix, iy). */ + static int endblk[9] = { 8, 0, 2, + 6,-1, 2, + 6, 4, 4 }; + + /* Pixel coord offsets specifying the order in which neighboring */ + /* blocks are searched. The current block is in the middle of */ + /* 8 surrounding neighbors. The following illustrates the order */ + /* of neighbor indices. (Note that 9 overlaps 1.) */ + /* 8 */ + /* 7 0 1 */ + /* 6 C 2 */ + /* 5 4 3 */ + /* */ + /* 0 1 2 3 4 5 6 7 8 */ + static int blkdx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 }; /* Delta-X */ + static int blkdy[9] = { -1,-1, 0, 1, 1, 1, 0,-1,-1 }; /* Delta-Y */ + + print2log("\nREMOVING MINUTIA NEAR INVALID BLOCKS:\n"); + + /* If the margin covers more than the entire block ... */ + if(lfsparms->inv_block_margin > (lfsparms->blocksize>>1)){ + /* Then treat this as an error. */ + fprintf(stderr, + "ERROR : remove_near_invblock_V2 : margin too large for blocksize\n"); + return(-620); + } + + /* Compute the low and high pixel margin boundaries (ex. 6 pixels wide) */ + /* in the block. */ + lo_margin = lfsparms->inv_block_margin; + hi_margin = lfsparms->blocksize - lfsparms->inv_block_margin - 1; + + i = 0; + /* Foreach minutia remaining in the list ... */ + while(i < minutiae->num){ + /* Assign temporary minutia pointer. */ + minutia = minutiae->list[i]; + + /* Compute block coords from minutia's pixel location. */ + bx = minutia->x/lfsparms->blocksize; + by = minutia->y/lfsparms->blocksize; + + /* Compute pixel offset into the image block corresponding to the */ + /* minutia's pixel location. */ + /* NOTE: The margins used here will not necessarily correspond to */ + /* the actual block boundaries used to compute the map values. */ + /* This will be true when the image width and/or height is not an */ + /* even multiple of 'blocksize' and we are processing minutia */ + /* located in the right-most column (or bottom-most row) of */ + /* blocks. I don't think this will pose a problem in practice. */ + px = minutia->x % lfsparms->blocksize; + py = minutia->y % lfsparms->blocksize; + + /* Determine if x pixel offset into the block is in the margins. */ + /* If x pixel offset is in left margin ... */ + if(px < lo_margin) + ix = 0; + /* If x pixel offset is in right margin ... */ + else if(px > hi_margin) + ix = 2; + /* Otherwise, x pixel offset is in middle of block. */ + else + ix = 1; + + /* Determine if y pixel offset into the block is in the margins. */ + /* If y pixel offset is in top margin ... */ + if(py < lo_margin) + iy = 0; + /* If y pixel offset is in bottom margin ... */ + else if(py > hi_margin) + iy = 2; + /* Otherwise, y pixel offset is in middle of block. */ + else + iy = 1; + + /* Set remove flag to FALSE. */ + removed = FALSE; + + /* If one of the minutia's pixel offsets is in a margin ... */ + if((ix != 1) || (iy != 1)){ + + /* Compute the starting neighbor block index for processing. */ + sbi = *(startblk+(iy*3)+ix); + /* Compute the ending neighbor block index for processing. */ + ebi = *(endblk+(iy*3)+ix); + + /* Foreach neighbor in the range to be processed ... */ + for(ni = sbi; ni <= ebi; ni++){ + /* Compute the neighbor's block coords relative to */ + /* the block the current minutia is in. */ + nbx = bx + blkdx[ni]; + nby = by + blkdy[ni]; + + /* If neighbor's block coords are outside of map boundaries... */ + if((nbx < 0) || (nbx >= mw) || + (nby < 0) || (nby >= mh)){ + + print2log("%d,%d RM1\n", minutia->x, minutia->y); + + /* Then the minutia is in a margin adjacent to the edge of */ + /* the image. */ + /* NOTE: This is true when the image width and/or height */ + /* is an even multiple of blocksize. When the image is not*/ + /* an even multiple, then some minutia may not be detected */ + /* as being in the margin of "the image" (not the block). */ + /* In practice, I don't think this will impact performance.*/ + if((ret = remove_minutia(i, minutiae))) + /* If system error occurred while removing minutia, */ + /* then return error code. */ + return(ret); + /* Set remove flag to TURE. */ + removed = TRUE; + /* Break out of neighboring block loop. */ + break; + } + /* If the neighboring block has INVALID direction ... */ + else if (*(direction_map+(nby*mw)+nbx) == INVALID_DIR){ + /* Count the number of valid blocks neighboring */ + /* the current neighbor. */ + nvalid = num_valid_8nbrs(direction_map, nbx, nby, mw, mh); + /* If the number of valid neighbors is < threshold */ + /* (ex. 7)... */ + if(nvalid < lfsparms->rm_valid_nbr_min){ + + print2log("%d,%d RM2\n", minutia->x, minutia->y); + + /* Then remove the current minutia from the list. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error occurred while removing minutia, */ + /* then return error code. */ + return(ret); + /* Set remove flag to TURE. */ + removed = TRUE; + /* Break out of neighboring block loop. */ + break; + } + /* Otherwise enough valid neighbors, so don't remove minutia */ + /* based on this neighboring block. */ + } + /* Otherwise neighboring block has valid direction, */ + /* so don't remove minutia based on this neighboring block. */ + } + + } /* Otherwise not in margin, so skip to next minutia in list. */ + + /* If current minutia not removed ... */ + if(!removed) + /* Advance to the next minutia in the list. */ + i++; + /* Otherwise the next minutia has slid into the spot where current */ + /* minutia was removed, so don't bump minutia index. */ + } /* End minutia loop */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_pointing_invblock_V2 - Removes minutia points that are relatively +#cat: close in the direction opposite the minutia to a +#cat: block with INVALID ridge flow. + + Input: + minutiae - list of true and false minutiae + direction_map - map of image blocks containing directional ridge flow + mw - width in blocks of the map + mh - height in blocks of the map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_pointing_invblock_V2(MINUTIAE *minutiae, + int *direction_map, const int mw, const int mh, + const LFSPARMS *lfsparms) +{ + int i, ret; + int delta_x, delta_y, dmapval; + int nx, ny, bx, by; + MINUTIA *minutia; + double pi_factor, theta; + double dx, dy; + + print2log("\nREMOVING MINUTIA POINTING TO INVALID BLOCKS:\n"); + + /* Compute factor for converting integer directions to radians. */ + pi_factor = M_PI / (double)lfsparms->num_directions; + + i = 0; + /* Foreach minutia remaining in list ... */ + while(i < minutiae->num){ + /* Set temporary minutia pointer. */ + minutia = minutiae->list[i]; + /* Convert minutia's direction to radians. */ + theta = minutia->direction * pi_factor; + /* Compute translation offsets (ex. 6 pixels). */ + dx = sin(theta) * (double)(lfsparms->trans_dir_pix); + dy = cos(theta) * (double)(lfsparms->trans_dir_pix); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + dx = trunc_dbl_precision(dx, TRUNC_SCALE); + dy = trunc_dbl_precision(dy, TRUNC_SCALE); + delta_x = sround(dx); + delta_y = sround(dy); + /* Translate the minutia's coords. */ + nx = minutia->x - delta_x; + ny = minutia->y + delta_y; + /* Convert pixel coords to block coords. */ + bx = (int)(nx / lfsparms->blocksize); + by = (int)(ny / lfsparms->blocksize); + /* The translation could move the point out of image boundaries, */ + /* and therefore the corresponding block coords can be out of */ + /* map boundaries, so limit the block coords to within boundaries. */ + bx = max(0, bx); + bx = min(mw-1, bx); + by = max(0, by); + by = min(mh-1, by); + + /* Get corresponding block's ridge flow direction. */ + dmapval = *(direction_map+(by*mw)+bx); + + /* If the block's direction is INVALID ... */ + if(dmapval == INVALID_DIR){ + + print2log("%d,%d RM\n", minutia->x, minutia->y); + + /* Remove the minutia from the minutiae list. */ + if((ret = remove_minutia(i, minutiae))){ + return(ret); + } + /* No need to advance because next minutia has slid into slot. */ + } + else{ + /* Advance to next minutia in list. */ + i++; + } + } + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_overlaps - Takes a list of true and false minutiae and +#cat: attempts to detect and remove those false minutiae that +#cat: are on opposite sides of an overlap. Note that this +#cat: routine does NOT edit the binary image when overlaps +#cat: are removed. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_overlaps(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + int *to_remove; + int i, f, s, ret; + int delta_y, full_ndirs, qtr_ndirs, deltadir, min_deltadir; + MINUTIA *minutia1, *minutia2; + double dist; + int joindir, opp1dir, half_ndirs; + + print2log("\nREMOVING OVERLAPS:\n"); + + /* Allocate list of minutia indices that upon completion of testing */ + /* should be removed from the minutiae lists. Note: That using */ + /* "calloc" initializes the list to FALSE. */ + to_remove = (int *)calloc(minutiae->num, sizeof(int)); + if(to_remove == (int *)NULL){ + fprintf(stderr, "ERROR : remove_overlaps : calloc : to_remove\n"); + return(-650); + } + + /* Compute number directions in full circle. */ + full_ndirs = lfsparms->num_directions<<1; + /* Compute number of directions in 45=(180/4) degrees. */ + qtr_ndirs = lfsparms->num_directions>>2; + /* Compute number of directions in 90=(180/2) degrees. */ + half_ndirs = lfsparms->num_directions>>1; + + /* Minimum allowable deltadir to consider joining minutia. */ + /* (The closer the deltadir is to 180 degrees, the more likely the join. */ + /* When ndirs==16, then this value is 11=(3*4)-1 == 123.75 degrees. */ + /* I chose to parameterize this threshold based on a fixed fraction of */ + /* 'ndirs' rather than on passing in a parameter in degrees and doing */ + /* the conversion. I doubt the difference matters. */ + min_deltadir = (3 * qtr_ndirs) - 1; + + f = 0; + /* Foreach primary (first) minutia (except for last one in list) ... */ + while(f < minutiae->num-1){ + + /* If current first minutia not previously set to be removed. */ + if(!to_remove[f]){ + + print2log("\n"); + + /* Set first minutia to temporary pointer. */ + minutia1 = minutiae->list[f]; + /* Foreach secondary (second) minutia to right of first minutia ... */ + s = f+1; + while(s < minutiae->num){ + /* Set second minutia to temporary pointer. */ + minutia2 = minutiae->list[s]; + + print2log("1:%d(%d,%d)%d 2:%d(%d,%d)%d ", + f, minutia1->x, minutia1->y, minutia1->type, + s, minutia2->x, minutia2->y, minutia2->type); + + /* The binary image is potentially being edited during each */ + /* iteration of the secondary minutia loop, therefore */ + /* minutia pixel values may be changed. We need to catch */ + /* these events by using the next 2 tests. */ + + /* If the first minutia's pixel has been previously changed... */ + if(*(bdata+(minutia1->y*iw)+minutia1->x) != minutia1->type){ + print2log("\n"); + /* Then break out of secondary loop and skip to next first. */ + break; + } + + /* If the second minutia's pixel has been previously changed... */ + if(*(bdata+(minutia2->y*iw)+minutia2->x) != minutia2->type) + /* Set to remove second minutia. */ + to_remove[s] = TRUE; + + /* If the second minutia not previously set to be removed. */ + if(!to_remove[s]){ + + /* Compute delta y between 1st & 2nd minutiae and test. */ + delta_y = minutia2->y - minutia1->y; + /* If delta y small enough (ex. < 8 pixels) ... */ + if(delta_y <= lfsparms->max_overlap_dist){ + + print2log("1DY "); + + /* Compute Euclidean distance between 1st & 2nd mintuae. */ + dist = distance(minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + /* If distance is NOT too large (ex. < 8 pixels) ... */ + if(dist <= lfsparms->max_overlap_dist){ + + print2log("2DS "); + + /* Compute "inner" difference between directions on */ + /* a full circle and test. */ + if((deltadir = closest_dir_dist(minutia1->direction, + minutia2->direction, full_ndirs)) == + INVALID_DIR){ + free(to_remove); + fprintf(stderr, + "ERROR : remove_overlaps : INVALID direction\n"); + return(-651); + } + /* If the difference between dirs is large enough ... */ + /* (the more 1st & 2nd point away from each other the */ + /* more likely they should be joined) */ + if(deltadir > min_deltadir){ + + print2log("3DD "); + + /* If 1st & 2nd minutiae are same type ... */ + if(minutia1->type == minutia2->type){ + /* Test to see if both are on opposite sides */ + /* of an overlap. */ + + /* Compute direction of "joining" vector. */ + /* First, compute direction of line from first */ + /* to second minutia points. */ + joindir = line2direction(minutia1->x, minutia1->y, + minutia2->x, minutia2->y, + lfsparms->num_directions); + + /* Comptue opposite direction of first minutia. */ + opp1dir = (minutia1->direction+ + lfsparms->num_directions)%full_ndirs; + /* Take "inner" distance on full circle between */ + /* the first minutia's opposite direction and */ + /* the joining direction. */ + joindir = abs(opp1dir - joindir); + joindir = min(joindir, full_ndirs - joindir); + + print2log("joindir=%d dist=%f ", joindir,dist); + + /* If the joining angle is <= 90 degrees OR */ + /* the 2 points are sufficiently close AND */ + /* a free path exists between pair ... */ + if(((joindir <= half_ndirs) || + (dist <= lfsparms->max_overlap_join_dist)) && + free_path(minutia1->x, minutia1->y, + minutia2->x, minutia2->y, + bdata, iw, ih, lfsparms)){ + + print2log("4OV RM\n"); + + /* Then assume overlap, so ... */ + /* Set to remove first minutia. */ + to_remove[f] = TRUE; + /* Set to remove second minutia. */ + to_remove[s] = TRUE; + } + /* Otherwise, pair not on an overlap, so skip */ + /* to next second minutia. */ + else + print2log("\n"); + } + else + print2log("\n"); + /* End same type test. */ + }/* End deltadir test. */ + else + print2log("\n"); + }/* End distance test. */ + else + print2log("\n"); + } + /* Otherwise, current 2nd too far below 1st, so skip to next */ + /* 1st minutia. */ + else{ + + print2log("\n"); + + /* Break out of inner secondary loop. */ + break; + }/* End delta-y test. */ + + }/* End if !to_remove[s] */ + else + print2log("\n"); + + /* Bump to next second minutia in minutiae list. */ + s++; + }/* End secondary minutiae loop. */ + + }/* Otherwise, first minutia already flagged to be removed. */ + + /* Bump to next first minutia in minutiae list. */ + f++; + }/* End primary minutiae loop. */ + + /* Now remove all minutiae in list that have been flagged for removal. */ + /* NOTE: Need to remove the minutia from their lists in reverse */ + /* order, otherwise, indices will be off. */ + for(i = minutiae->num-1; i >= 0; i--){ + /* If the current minutia index is flagged for removal ... */ + if(to_remove[i]){ + /* Remove the minutia from the minutiae list. */ + if((ret = remove_minutia(i, minutiae))){ + free(to_remove); + return(ret); + } + } + } + + /* Deallocate flag list. */ + free(to_remove); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_pores_V2 - Attempts to detect and remove minutia points located on +#cat: pore-shaped valleys and/or ridges. Detection for +#cat: these features are only performed in blocks with +#cat: LOW RIDGE FLOW or HIGH CURVATURE. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + direction_map - map of image blocks containing directional ridge flow + low_flow_map - map of image blocks flagged as LOW RIDGE FLOW + high_curve_map - map of image blocks flagged as HIGH CURVATURE + mw - width in blocks of the maps + mh - height in blocks of the maps + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_pores_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *direction_map, int *low_flow_map, + int *high_curve_map, const int mw, const int mh, + const LFSPARMS *lfsparms) +{ + int i, ret; + int removed, blk_x, blk_y; + int rx, ry; + int px, py, pex, pey, bx, by, dx, dy; + int qx, qy, qex, qey, ax, ay, cx, cy; + MINUTIA *minutia; + double pi_factor, theta, sin_theta, cos_theta; + double ab2, cd2, ratio; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + double drx, dry; + + /* This routine attempts to locate the following points on all */ + /* minutia within the feature list. */ + /* 1. Compute R 3 pixels opposite the feature direction from */ + /* feature point F. */ + /* 2. Find white pixel transitions P & Q within 12 steps from */ + /* from R perpendicular to the feature's direction. */ + /* 3. Find points B & D by walking white edge from P. */ + /* 4. Find points A & C by walking white edge from Q. */ + /* 5. Measure squared distances between A-B and C-D. */ + /* 6. Compute ratio of squared distances and compare against */ + /* threshold (2.25). If A-B sufficiently larger than C-D, */ + /* then assume NOT pore, otherwise flag the feature point F.*/ + /* If along the way, finding any of these points fails, then */ + /* assume the feature is a pore and flag it. */ + /* */ + /* A */ + /* _____._ */ + /* ----___ Q C */ + /* ------____ ---_.________.___ */ + /* ---_ */ + /* (valley) F.\ .R (ridge) */ + /* ____/ */ + /* ______---- ___-.--------.--- */ + /* ____--- P D */ + /* -----.- */ + /* B */ + /* */ + /* AB^2/CD^2 <= 2.25 then flag feature */ + /* */ + + + print2log("\nREMOVING PORES:\n"); + + /* Factor for converting integer directions into radians. */ + pi_factor = M_PI/(double)lfsparms->num_directions; + + /* Initialize to the beginning of the minutia list. */ + i = 0; + /* Foreach minutia remaining in the list ... */ + while(i < minutiae->num){ + /* Set temporary minutia pointer. */ + minutia = minutiae->list[i]; + + /* Initialize remove flag to FALSE. */ + removed = FALSE; + + /* Compute block coords from minutia point. */ + blk_x = minutia->x / lfsparms->blocksize; + blk_y = minutia->y / lfsparms->blocksize; + + /* If minutia in LOW RIDGE FLOW or HIGH CURVATURE block */ + /* with a valid direction ... */ + if((*(low_flow_map+(blk_y*mw)+blk_x) || + *(high_curve_map+(blk_y*mw)+blk_x)) && + (*(direction_map+(blk_y*mw)+blk_x) >= 0)){ + /* Compute radian angle from minutia direction. */ + theta = (double)minutia->direction * pi_factor; + /* Compute sine and cosine factors of this angle. */ + sin_theta = sin(theta); + cos_theta = cos(theta); + /* Translate the minutia point (ex. 3 pixels) in opposite */ + /* direction minutia is pointing. Call this point 'R'. */ + drx = (double)minutia->x - + (sin_theta * (double)lfsparms->pores_trans_r); + dry = (double)minutia->y + + (cos_theta * (double)lfsparms->pores_trans_r); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + drx = trunc_dbl_precision(drx, TRUNC_SCALE); + dry = trunc_dbl_precision(dry, TRUNC_SCALE); + rx = sround(drx); + ry = sround(dry); + + /* If 'R' is opposite color from minutia type ... */ + if(*(bdata+(ry*iw)+rx) != minutia->type){ + + /* Search a specified number of steps (ex. 12) from 'R' in a */ + /* perpendicular direction from the minutia direction until */ + /* the first white pixel is found. If a white pixel is */ + /* found within the specified number of steps, then call */ + /* this point 'P' (storing the point's edge pixel as well). */ + if(search_in_direction(&px, &py, &pex, &pey, + minutia->type, + rx, ry, -cos_theta, -sin_theta, + lfsparms->pores_perp_steps, + bdata, iw, ih)){ + /* Trace contour from P's edge pixel in counter-clockwise */ + /* scan and step along specified number of steps (ex. 10). */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->pores_steps_fwd, + px, py, px, py, pex, pey, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred during trace ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible OR loop found OR */ + /* contour is incomplete ... */ + if((ret == IGNORE) || + (ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_fwd)){ + /* If contour allocated and returned ... */ + if((ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_fwd)) + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + print2log("%d,%d RMB\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } + /* Otherwise, traced contour is complete. */ + else{ + /* Store last point in contour as point 'B'. */ + bx = contour_x[ncontour-1]; + by = contour_y[ncontour-1]; + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + /* Trace contour from P's edge pixel in clockwise scan */ + /* and step along specified number of steps (ex. 8). */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->pores_steps_bwd, + px, py, px, py, pex, pey, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred during trace ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible OR loop found OR */ + /* contour is incomplete ... */ + if((ret == IGNORE) || + (ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_bwd)){ + /* If contour allocated and returned ... */ + if((ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_bwd)) + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + print2log("%d,%d RMD\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } + /* Otherwise, traced contour is complete. */ + else{ + /* Store last point in contour as point 'D'. */ + dx = contour_x[ncontour-1]; + dy = contour_y[ncontour-1]; + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + /* Search a specified number of steps (ex. 12) from */ + /* 'R' in opposite direction of that used to find */ + /* 'P' until the first white pixel is found. If a */ + /* white pixel is found within the specified number */ + /* of steps, then call this point 'Q' (storing the */ + /* point's edge pixel as well). */ + if(search_in_direction(&qx, &qy, &qex, &qey, + minutia->type, + rx, ry, cos_theta, sin_theta, + lfsparms->pores_perp_steps, + bdata, iw, ih)){ + /* Trace contour from Q's edge pixel in clockwise */ + /* scan and step along specified number of steps */ + /* (ex. 10). */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->pores_steps_fwd, + qx, qy, qx, qy, qex, qey, + SCAN_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred during trace ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible OR loop found OR */ + /* contour is incomplete ... */ + if((ret == IGNORE) || + (ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_fwd)){ + /* If contour allocated and returned ... */ + if((ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_fwd)) + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + print2log("%d,%d RMA\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } + /* Otherwise, traced contour is complete. */ + else{ + /* Store last point in contour as point 'A'. */ + ax = contour_x[ncontour-1]; + ay = contour_y[ncontour-1]; + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + /* Trace contour from Q's edge pixel in */ + /* counter-clockwise scan and step along a */ + /* specified number of steps (ex. 8). */ + ret = trace_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->pores_steps_bwd, + qx, qy, qx, qy, qex, qey, + SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); + + /* If system error occurred during scan ... */ + if(ret < 0){ + /* Return error code. */ + return(ret); + } + + /* If trace was not possible OR loop found OR */ + /* contour is incomplete ... */ + if((ret == IGNORE) || + (ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_bwd)){ + /* If contour allocated and returned ... */ + if((ret == LOOP_FOUND) || + (ncontour < lfsparms->pores_steps_bwd)) + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + print2log("%d,%d RMC\n", + minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } + /* Otherwise, traced contour is complete. */ + else{ + /* Store last point in contour as 'C'. */ + cx = contour_x[ncontour-1]; + cy = contour_y[ncontour-1]; + /* Deallocate the contour. */ + free_contour(contour_x, contour_y, + contour_ex, contour_ey); + + /* Compute squared distance between points */ + /* 'A' and 'B'. */ + ab2 = squared_distance(ax, ay, bx, by); + /* Compute squared distance between points */ + /* 'C' and 'D'. */ + cd2 = squared_distance(cx, cy, dx, dy); + /* If CD distance is not near zero */ + /* (ex. 0.5) ... */ + if(cd2 > lfsparms->pores_min_dist2){ + /* Compute ratio of squared distances. */ + ratio = ab2 / cd2; + + /* If ratio is small enough (ex. 2.25)...*/ + if(ratio <= lfsparms->pores_max_ratio){ + + print2log("%d,%d ", + minutia->x, minutia->y); + print2log("R=%d,%d P=%d,%d B=%d,%d D=%d,%d Q=%d,%d A=%d,%d C=%d,%d ", + rx, ry, px, py, bx, by, dx, dy, qx, qy, ax, ay, cx, cy); + print2log("RMRATIO %f\n", ratio); + + /* Then assume pore & remove minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } + /* Otherwise, ratio to big, so assume */ + /* legitimate minutia. */ + } /* Else, cd2 too small. */ + } /* Done with C. */ + } /* Done with A. */ + } + /* Otherwise, Q not found ... */ + else{ + + print2log("%d,%d RMQ\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } /* Done with Q. */ + } /* Done with D. */ + } /* Done with B. */ + } + /* Otherwise, P not found ... */ + else{ + + print2log("%d,%d RMP\n", minutia->x, minutia->y); + + /* Then remove the minutia. */ + if((ret = remove_minutia(i, minutiae))) + /* If system error, return error code. */ + return(ret); + /* Set remove flag to TRUE. */ + removed = TRUE; + } + } /* Else, R is on pixel the same color as type, so do not */ + /* remove minutia point and skip to next one. */ + } /* Else block is unreliable or has INVALID direction. */ + + /* If current minutia not removed ... */ + if(!removed) + /* Bump to next minutia in list. */ + i++; + /* Otherwise, next minutia has slid into slot of current removed one. */ + + } /* End While minutia remaining in list. */ + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_or_adjust_side_minutiae_V2 - Removes loops or minutia points that +#cat: are not on complete contours of specified length. If the +#cat: contour is complete, then the minutia is adjusted based +#cat: on a minmax analysis of the rotated y-coords of the contour. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + direction_map - map of image blocks containing directional ridge flow + mw - width (in blocks) of the map + mh - height (in blocks) of the map + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *direction_map, const int mw, const int mh, + const LFSPARMS *lfsparms) +{ + int i, j, ret; + MINUTIA *minutia; + double pi_factor, theta, sin_theta, cos_theta; + int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; + int *rot_y, minloc; + int *minmax_val, *minmax_i, *minmax_type, minmax_alloc, minmax_num; + double drot_y; + int bx, by; + + print2log("\nADJUSTING SIDE MINUTIA:\n"); + + /* Allocate working memory for holding rotated y-coord of a */ + /* minutia's contour. */ + rot_y = (int *)malloc(((lfsparms->side_half_contour<<1)+1) * sizeof(int)); + if(rot_y == (int *)NULL){ + fprintf(stderr, + "ERROR : remove_or_adjust_side_minutiae_V2 : malloc : rot_y\n"); + return(-630); + } + + /* Compute factor for converting integer directions to radians. */ + pi_factor = M_PI / (double)lfsparms->num_directions; + + i = 0; + /* Foreach minutia remaining in list ... */ + while(i < minutiae->num){ + /* Assign a temporary pointer. */ + minutia = minutiae->list[i]; + + /* Extract a contour centered on the minutia point (ex. 7 pixels */ + /* in both directions). */ + ret = get_centered_contour(&contour_x, &contour_y, + &contour_ex, &contour_ey, &ncontour, + lfsparms->side_half_contour, + minutia->x, minutia->y, minutia->ex, minutia->ey, + bdata, iw, ih); + + /* If system error occurred ... */ + if(ret < 0){ + /* Deallocate working memory. */ + free(rot_y); + /* Return error code. */ + return(ret); + } + + /* If we didn't succeed in extracting a complete contour for any */ + /* other reason ... */ + if((ret == LOOP_FOUND) || + (ret == IGNORE) || + (ret == INCOMPLETE)){ + + print2log("%d,%d RM1\n", minutia->x, minutia->y); + + /* Remove minutia from list. */ + if((ret = remove_minutia(i, minutiae))){ + /* Deallocate working memory. */ + free(rot_y); + /* Return error code. */ + return(ret); + } + /* No need to advance because next minutia has "slid" */ + /* into position pointed to by 'i'. */ + } + /* Otherwise, a complete contour was found and extracted ... */ + else{ + /* Rotate contour points by negative angle of feature's direction. */ + /* The contour of a well-formed minutia point will form a bowl */ + /* shape concaved in the direction of the minutia. By rotating */ + /* the contour points by the negative angle of feature's direction */ + /* the bowl will be transformed to be concaved upwards and minima */ + /* and maxima of the transformed y-coords can be analyzed to */ + /* determine if the minutia is "well-formed" or not. If well- */ + /* formed then the position of the minutia point is adjusted. If */ + /* not well-formed, then the minutia point is removed altogether. */ + + /* Normal rotation of T degrees around the origin of */ + /* the point (x,y): */ + /* rx = x*cos(T) - y*sin(T) */ + /* ry = x*cos(T) + y*sin(T) */ + /* The rotation here is for -T degrees: */ + /* rx = x*cos(-T) - y*sin(-T) */ + /* ry = x*cos(-T) + y*sin(-T) */ + /* which can be written: */ + /* rx = x*cos(T) + y*sin(T) */ + /* ry = x*sin(T) - y*cos(T) */ + + /* Convert minutia's direction to radians. */ + theta = (double)minutia->direction * pi_factor; + /* Compute sine and cosine values at theta for rotation. */ + sin_theta = sin(theta); + cos_theta = cos(theta); + + for(j = 0; j < ncontour; j++){ + /* We only need to rotate the y-coord (don't worry */ + /* about rotating the x-coord or contour edge pixels). */ + drot_y = ((double)contour_x[j] * sin_theta) - + ((double)contour_y[j] * cos_theta); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + drot_y = trunc_dbl_precision(drot_y, TRUNC_SCALE); + rot_y[j] = sround(drot_y); + } + + /* Locate relative minima and maxima in vector of rotated */ + /* y-coords of current minutia's contour. */ + if((ret = minmaxs(&minmax_val, &minmax_type, &minmax_i, + &minmax_alloc, &minmax_num, + rot_y, ncontour))){ + /* If system error, then deallocate working memories. */ + free(rot_y); + free_contour(contour_x, contour_y, contour_ex, contour_ey); + /* Return error code. */ + return(ret); + } + + /* If one and only one minima was found in rotated y-coord */ + /* of contour ... */ + if((minmax_num == 1) && + (minmax_type[0] == -1)){ + + print2log("%d,%d ", minutia->x, minutia->y); + + /* Reset loation of minutia point to contour point at minima. */ + minutia->x = contour_x[minmax_i[0]]; + minutia->y = contour_y[minmax_i[0]]; + minutia->ex = contour_ex[minmax_i[0]]; + minutia->ey = contour_ey[minmax_i[0]]; + + /* Must check if adjusted minutia is now in INVALID block ... */ + bx = minutia->x/lfsparms->blocksize; + by = minutia->y/lfsparms->blocksize; + if(*(direction_map+(by*mw)+bx) == INVALID_DIR){ + /* Remove minutia from list. */ + if((ret = remove_minutia(i, minutiae))){ + /* Deallocate working memory. */ + free(rot_y); + free_contour(contour_x, contour_y, contour_ex, contour_ey); + if(minmax_alloc > 0){ + free(minmax_val); + free(minmax_type); + free(minmax_i); + } + /* Return error code. */ + return(ret); + } + /* No need to advance because next minutia has "slid" */ + /* into position pointed to by 'i'. */ + + print2log("RM2\n"); + } + else{ + /* Advance to the next minutia in the list. */ + i++; + print2log("AD1 %d,%d\n", minutia->x, minutia->y); + } + + } + /* If exactly 3 min/max found and they are min-max-min ... */ + else if((minmax_num == 3) && + (minmax_type[0] == -1)){ + /* Choose minima location with smallest rotated y-coord. */ + if(minmax_val[0] < minmax_val[2]) + minloc = minmax_i[0]; + else + minloc = minmax_i[2]; + + print2log("%d,%d ", minutia->x, minutia->y); + + /* Reset loation of minutia point to contour point at minima. */ + minutia->x = contour_x[minloc]; + minutia->y = contour_y[minloc]; + minutia->ex = contour_ex[minloc]; + minutia->ey = contour_ey[minloc]; + + /* Must check if adjusted minutia is now in INVALID block ... */ + bx = minutia->x/lfsparms->blocksize; + by = minutia->y/lfsparms->blocksize; + if(*(direction_map+(by*mw)+bx) == INVALID_DIR){ + /* Remove minutia from list. */ + if((ret = remove_minutia(i, minutiae))){ + /* Deallocate working memory. */ + free(rot_y); + free_contour(contour_x, contour_y, contour_ex, contour_ey); + if(minmax_alloc > 0){ + free(minmax_val); + free(minmax_type); + free(minmax_i); + } + /* Return error code. */ + return(ret); + } + /* No need to advance because next minutia has "slid" */ + /* into position pointed to by 'i'. */ + + print2log("RM3\n"); + } + else{ + /* Advance to the next minutia in the list. */ + i++; + print2log("AD2 %d,%d\n", minutia->x, minutia->y); + } + } + /* Otherwise, ... */ + else{ + + print2log("%d,%d RM4\n", minutia->x, minutia->y); + + /* Remove minutia from list. */ + if((ret = remove_minutia(i, minutiae))){ + /* If system error, then deallocate working memories. */ + free(rot_y); + free_contour(contour_x, contour_y, contour_ex, contour_ey); + if(minmax_alloc > 0){ + free(minmax_val); + free(minmax_type); + free(minmax_i); + } + /* Return error code. */ + return(ret); + } + /* No need to advance because next minutia has "slid" */ + /* into position pointed to by 'i'. */ + } + + /* Deallocate contour and min/max buffers. */ + free_contour(contour_x, contour_y, contour_ex, contour_ey); + if(minmax_alloc > 0){ + free(minmax_val); + free(minmax_type); + free(minmax_i); + } + } /* End else contour extracted. */ + } /* End while not end of minutiae list. */ + + /* Deallocate working memory. */ + free(rot_y); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: remove_false_minutia_V2 - Takes a list of true and false minutiae and +#cat: attempts to detect and remove the false minutiae based +#cat: on a series of tests. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + direction_map - map of image blocks containing directional ridge flow + low_flow_map - map of image blocks flagged as LOW RIDGE FLOW + high_curve_map - map of image blocks flagged as HIGH CURVATURE + mw - width in blocks of the maps + mh - height in blocks of the maps + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int remove_false_minutia_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *direction_map, int *low_flow_map, int *high_curve_map, + const int mw, const int mh, const LFSPARMS *lfsparms) +{ + int ret; + + /* 1. Sort minutiae points top-to-bottom and left-to-right. */ + if((ret = sort_minutiae_y_x(minutiae, iw, ih))){ + return(ret); + } + + /* 2. Remove minutiae on lakes (filled with white pixels) and */ + /* islands (filled with black pixels), both defined by a pair of */ + /* minutia points. */ + if((ret = remove_islands_and_lakes(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 3. Remove minutiae on holes in the binary image defined by a */ + /* single point. */ + if((ret = remove_holes(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 4. Remove minutiae that point sufficiently close to a block with */ + /* INVALID direction. */ + if((ret = remove_pointing_invblock_V2(minutiae, direction_map, mw, mh, + lfsparms))){ + return(ret); + } + + /* 5. Remove minutiae that are sufficiently close to a block with */ + /* INVALID direction. */ + if((ret = remove_near_invblock_V2(minutiae, direction_map, mw, mh, + lfsparms))){ + return(ret); + } + + /* 6. Remove or adjust minutiae that reside on the side of a ridge */ + /* or valley. */ + if((ret = remove_or_adjust_side_minutiae_V2(minutiae, bdata, iw, ih, + direction_map, mw, mh, lfsparms))){ + return(ret); + } + + /* 7. Remove minutiae that form a hook on the side of a ridge or valley. */ + if((ret = remove_hooks(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 8. Remove minutiae that are on opposite sides of an overlap. */ + if((ret = remove_overlaps(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 9. Remove minutiae that are "irregularly" shaped. */ + if((ret = remove_malformations(minutiae, bdata, iw, ih, + low_flow_map, mw, mh, lfsparms))){ + return(ret); + } + + /* 10. Remove minutiae that form long, narrow, loops in the */ + /* "unreliable" regions in the binary image. */ + if((ret = remove_pores_V2(minutiae, bdata, iw, ih, + direction_map, low_flow_map, high_curve_map, + mw, mh, lfsparms))){ + return(ret); + } + + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/quality.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/quality.c.svn-base @@ -0,0 +1,393 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: QUALITY.C + AUTHOR: Michael D. Garris + DATE: 09/25/2000 + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for assessing minutia quality + and assigning different reliability measures. These routines + are primarily to support the rejection of bad minutiae. + +*********************************************************************** + ROUTINES: + gen_quality_map() + combined_minutia_quality() + grayscale_reliability() + get_neighborhood_stats() + +***********************************************************************/ + +#include +#include +#include +#include +#include + +/*********************************************************************** +************************************************************************ +#cat: gen_quality_map - Takes a direction map, low contrast map, low ridge +#cat: flow map, and high curvature map, and combines them +#cat: into a single map containing 5 levels of decreasing +#cat: quality. This is done through a set of heuristics. + + Code originally written by Austin Hicklin for FBI ATU + Modified by Michael D. Garris (NIST) Sept. 1, 2000 + + Set quality of 0(unusable)..4(good) (I call these grades A..F) + 0/F: low contrast OR no direction + 1/D: low flow OR high curve + (with low contrast OR no direction neighbor) + (or within NEIGHBOR_DELTA of edge) + 2/C: low flow OR high curve + (or good quality with low contrast/no direction neighbor) + 3/B: good quality with low flow / high curve neighbor + 4/A: good quality (none of the above) + + Generally, the features in A/B quality are useful, the C/D quality + ones are not. + + Input: + direction_map - map with blocks assigned dominant ridge flow direction + low_contrast_map - map with blocks flagged as low contrast + low_flow_map - map with blocks flagged as low ridge flow + high_curve_map - map with blocks flagged as high curvature + map_w - width (in blocks) of the maps + map_h - height (in blocks) of the maps + Output: + oqmap - points to new quality map + Return Code: + Zero - successful completion + Negative - system error +************************************************************************/ +int gen_quality_map(int **oqmap, int *direction_map, int *low_contrast_map, + int *low_flow_map, int *high_curve_map, + const int map_w, const int map_h) +{ + + int *QualMap; + int thisX, thisY; + int compX, compY; + int arrayPos, arrayPos2; + int QualOffset; + + QualMap = (int *)malloc(map_w * map_h * sizeof(int)); + if(QualMap == (int *)NULL){ + fprintf(stderr, "ERROR : gen_quality_map : malloc : QualMap\n"); + return(-2); + } + + /* Foreach row of blocks in maps ... */ + for(thisY=0; thisY map_h - 1 - NEIGHBOR_DELTA || + thisX < NEIGHBOR_DELTA || thisX > map_w - 1 - NEIGHBOR_DELTA) + /* Set block's quality to 1/E. */ + QualMap[arrayPos]=1; + /* Otherwise, test neighboring blocks ... */ + else{ + /* Initialize quality adjustment to 0. */ + QualOffset=0; + /* Foreach row in neighborhood ... */ + for(compY=thisY-NEIGHBOR_DELTA; + compY<=thisY+NEIGHBOR_DELTA;compY++){ + /* Foreach block in neighborhood */ + /* (including current block)... */ + for(compX=thisX-NEIGHBOR_DELTA; + compX<=thisX+NEIGHBOR_DELTA;compX++) { + /* Compute neighboring block's index. */ + arrayPos2 = (compY*map_w)+compX; + /* If neighbor block (which might be itself) has */ + /* low contrast or INVALID direction .. */ + if(low_contrast_map[arrayPos2] || + direction_map[arrayPos2]<0) { + /* Set quality adjustment to -2. */ + QualOffset=-2; + /* Done with neighborhood row. */ + break; + } + /* Otherwise, if neighbor block (which might be */ + /* itself) has low flow or high curvature ... */ + else if(low_flow_map[arrayPos2] || + high_curve_map[arrayPos2]) { + /* Set quality to -1 if not already -2. */ + QualOffset=min(QualOffset,-1); + } + } + } + /* Decrement minutia quality by neighborhood adjustment. */ + QualMap[arrayPos]+=QualOffset; + } + } + } + } + + /* Set output pointer. */ + *oqmap = QualMap; + /* Return normally. */ + return(0); +} + +/*********************************************************************** +************************************************************************ +#cat: get_neighborhood_stats - Given a minutia point, computes the mean +#cat: and stdev of the 8-bit grayscale pixels values in a +#cat: surrounding neighborhood with specified radius. + + Code originally written by Austin Hicklin for FBI ATU + Modified by Michael D. Garris (NIST) Sept. 25, 2000 + + Input: + minutia - structure containing detected minutia + idata - 8-bit grayscale fingerprint image + iw - width (in pixels) of the image + ih - height (in pixels) of the image + radius_pix - pixel radius of surrounding neighborhood + Output: + mean - mean of neighboring pixels + stdev - standard deviation of neighboring pixels +************************************************************************/ +static void get_neighborhood_stats(double *mean, double *stdev, MINUTIA *minutia, + unsigned char *idata, const int iw, const int ih, + const int radius_pix) +{ + int i, x, y, rows, cols; + int n = 0, sumX = 0, sumXX = 0; + int histogram[256]; + + /* Zero out histogram. */ + memset(histogram, 0, 256 * sizeof(int)); + + /* Set minutia's coordinate variables. */ + x = minutia->x; + y = minutia->y; + + + /* If minutiae point is within sampleboxsize distance of image border, */ + /* a value of 0 reliability is returned. */ + if ((x < radius_pix) || (x > iw-radius_pix-1) || + (y < radius_pix) || (y > ih-radius_pix-1)) { + *mean = 0.0; + *stdev = 0.0; + return; + + } + + /* Foreach row in neighborhood ... */ + for(rows = y - radius_pix; + rows <= y + radius_pix; + rows++){ + /* Foreach column in neighborhood ... */ + for(cols = x - radius_pix; + cols <= x + radius_pix; + cols++){ + /* Bump neighbor's pixel value bin in histogram. */ + histogram[*(idata+(rows * iw)+cols)]++; + } + } + + /* Foreach grayscale pixel bin ... */ + for(i = 0; i < 256; i++){ + if(histogram[i]){ + /* Accumulate Sum(X[i]) */ + sumX += (i * histogram[i]); + /* Accumulate Sum(X[i]^2) */ + sumXX += (i * i * histogram[i]); + /* Accumulate N samples */ + n += histogram[i]; + } + } + + /* Mean = Sum(X[i])/N */ + *mean = sumX/(double)n; + /* Stdev = sqrt((Sum(X[i]^2)/N) - Mean^2) */ + *stdev = sqrt((sumXX/(double)n) - ((*mean)*(*mean))); +} + +/*********************************************************************** +************************************************************************ +#cat: grayscale_reliability - Given a minutia point, computes a reliability +#cat: measure from the stdev and mean of its pixel neighborhood. + + Code originally written by Austin Hicklin for FBI ATU + Modified by Michael D. Garris (NIST) Sept. 25, 2000 + + GrayScaleReliability - reasonable reliability heuristic, returns + 0.0 .. 1.0 based on stdev and Mean of a localized histogram where + "ideal" stdev is >=64; "ideal" Mean is 127. In a 1 ridge radius + (11 pixels), if the bytevalue (shade of gray) in the image has a + stdev of >= 64 & a mean of 127, returns 1.0 (well defined + light & dark areas in equal proportions). + + Input: + minutia - structure containing detected minutia + idata - 8-bit grayscale fingerprint image + iw - width (in pixels) of the image + ih - height (in pixels) of the image + radius_pix - pixel radius of surrounding neighborhood + Return Value: + reliability - computed reliability measure +************************************************************************/ +static double grayscale_reliability(MINUTIA *minutia, unsigned char *idata, + const int iw, const int ih, const int radius_pix) +{ + double mean, stdev; + double reliability; + + get_neighborhood_stats(&mean, &stdev, minutia, idata, iw, ih, radius_pix); + + reliability = min((stdev>IDEALSTDEV ? 1.0 : stdev/(double)IDEALSTDEV), + (1.0-(fabs(mean-IDEALMEAN)/(double)IDEALMEAN))); + + return(reliability); +} + +/*********************************************************************** +************************************************************************ +#cat: combined_minutia_quality - Combines quality measures derived from +#cat: the quality map and neighboring pixel statistics to +#cat: infer a reliability measure on the scale [0...1]. + + Input: + minutiae - structure contining the detected minutia + quality_map - map with blocks assigned 1 of 5 quality levels + map_w - width (in blocks) of the map + map_h - height (in blocks) of the map + blocksize - size (in pixels) of each block in the map + idata - 8-bit grayscale fingerprint image + iw - width (in pixels) of the image + ih - height (in pixels) of the image + id - depth (in pixels) of the image + ppmm - scan resolution of the image in pixels/mm + Output: + minutiae - updated reliability members + Return Code: + Zero - successful completion + Negative - system error +************************************************************************/ +int combined_minutia_quality(MINUTIAE *minutiae, + int *quality_map, const int mw, const int mh, const int blocksize, + unsigned char *idata, const int iw, const int ih, const int id, + const double ppmm) +{ + int ret, i, index, radius_pix; + int *pquality_map, qmap_value; + MINUTIA *minutia; + double gs_reliability, reliability; + + /* If image is not 8-bit grayscale ... */ + if(id != 8){ + fprintf(stderr, "ERROR : combined_miutia_quality : "); + fprintf(stderr, "image must pixel depth = %d must be 8 ", id); + fprintf(stderr, "to compute reliability\n"); + return(-2); + } + + /* Compute pixel radius of neighborhood based on image's scan resolution. */ + radius_pix = sround(RADIUS_MM * ppmm); + + /* Expand block map values to pixel map. */ + if((ret = pixelize_map(&pquality_map, iw, ih, + quality_map, mw, mh, blocksize))){ + return(ret); + } + + /* Foreach minutiae detected ... */ + for(i = 0; i < minutiae->num; i++){ + /* Assign minutia pointer. */ + minutia = minutiae->list[i]; + + /* Compute reliability from stdev and mean of pixel neighborhood. */ + gs_reliability = grayscale_reliability(minutia, + idata, iw, ih, radius_pix); + + /* Lookup quality map value. */ + /* Compute minutia pixel index. */ + index = (minutia->y * iw) + minutia->x; + /* Switch on pixel's quality value ... */ + qmap_value = pquality_map[index]; + + /* Combine grayscale reliability and quality map value. */ + switch(qmap_value){ + /* Quality A : [50..99]% */ + case 4 : + reliability = 0.50 + (0.49 * gs_reliability); + break; + /* Quality B : [25..49]% */ + case 3 : + reliability = 0.25 + (0.24 * gs_reliability); + break; + /* Quality C : [10..24]% */ + case 2 : + reliability = 0.10 + (0.14 * gs_reliability); + break; + /* Quality D : [5..9]% */ + case 1 : + reliability = 0.05 + (0.04 * gs_reliability); + break; + /* Quality E : 1% */ + case 0 : + reliability = 0.01; + break; + /* Error if quality value not in range [0..4]. */ + default: + fprintf(stderr, "ERROR : combined_miutia_quality : "); + fprintf(stderr, "unexpected quality map value %d ", qmap_value); + fprintf(stderr, "not in range [0..4]\n"); + free(pquality_map); + return(-3); + } + minutia->reliability = reliability; + } + + /* NEW 05-08-2002 */ + free(pquality_map); + + /* Return normally. */ + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/block.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/block.c.svn-base @@ -0,0 +1,377 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: BLOCK.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for partitioning arbitrarily- + sized images into equally-sized blocks as part of the NIST + Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + block_offsets() + low_contrast_block() + find_valid_block() + set_margin_blocks() + +***********************************************************************/ + +#include +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: block_offsets - Divides an image into mw X mh equally sized blocks, +#cat: returning a list of offsets to the top left corner of each block. +#cat: For images that are even multiples of BLOCKSIZE, blocks do not +#cat: not overlap and are immediately adjacent to each other. For image +#cat: that are NOT even multiples of BLOCKSIZE, blocks continue to be +#cat: non-overlapping up to the last column and/or last row of blocks. +#cat: In these cases the blocks are adjacent to the edge of the image and +#cat: extend inwards BLOCKSIZE units, overlapping the neighboring column +#cat: or row of blocks. This routine also accounts for image padding +#cat: which makes things a little more "messy". This routine is primarily +#cat: responsible providing the ability to processs arbitrarily-sized +#cat: images. The strategy used here is simple, but others are possible. + + Input: + iw - width (in pixels) of the orginal input image + ih - height (in pixels) of the orginal input image + pad - the padding (in pixels) required to support the desired + range of block orientations for DFT analysis. This padding + is required along the entire perimeter of the input image. + For certain applications, the pad may be zero. + blocksize - the width and height (in pixels) of each image block + Output: + optr - points to the list of pixel offsets to the origin of + each block in the "padded" input image + ow - the number of horizontal blocks in the input image + oh - the number of vertical blocks in the input image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int block_offsets(int **optr, int *ow, int *oh, + const int iw, const int ih, const int pad, const int blocksize) +{ + int *blkoffs, bx, by, bw, bh, bi, bsize; + int blkrow_start, blkrow_size, offset; + int lastbw, lastbh; + int pad2, pw, ph; + + /* Test if unpadded image is smaller than a single block */ + if((iw < blocksize) || (ih < blocksize)){ + fprintf(stderr, + "ERROR : block_offsets : image must be at least %d by %d in size\n", + blocksize, blocksize); + return(-80); + } + + /* Compute padded width and height of image */ + pad2 = pad<<1; + pw = iw + pad2; + ph = ih + pad2; + + /* Compute the number of columns and rows of blocks in the image. */ + /* Take the ceiling to account for "leftovers" at the right and */ + /* bottom of the unpadded image */ + bw = (int)ceil(iw / (double)blocksize); + bh = (int)ceil(ih / (double)blocksize); + + /* Total number of blocks in the image */ + bsize = bw*bh; + + /* The index of the last column */ + lastbw = bw - 1; + /* The index of the last row */ + lastbh = bh - 1; + + /* Allocate list of block offsets */ + blkoffs = (int *)malloc(bsize * sizeof(int)); + if(blkoffs == (int *)NULL){ + fprintf(stderr, "ERROR : block_offsets : malloc : blkoffs\n"); + return(-81); + } + + /* Current block index */ + bi = 0; + + /* Current offset from top of padded image to start of new row of */ + /* unpadded image blocks. It is initialize to account for the */ + /* padding and will always be indented the size of the padding */ + /* from the left edge of the padded image. */ + blkrow_start = (pad * pw) + pad; + + /* Number of pixels in a row of blocks in the padded image */ + blkrow_size = pw * blocksize; /* row width X block height */ + + /* Foreach non-overlapping row of blocks in the image */ + for(by = 0; by < lastbh; by++){ + /* Current offset from top of padded image to beginning of */ + /* the next block */ + offset = blkrow_start; + /* Foreach non-overlapping column of blocks in the image */ + for(bx = 0; bx < lastbw; bx++){ + /* Store current block offset */ + blkoffs[bi++] = offset; + /* Bump to the beginning of the next block */ + offset += blocksize; + } + + /* Compute and store "left-over" block in row. */ + /* This is the block in the last column of row. */ + /* Start at far right edge of unpadded image data */ + /* and come in BLOCKSIZE pixels. */ + blkoffs[bi++] = blkrow_start + iw - blocksize; + /* Bump to beginning of next row of blocks */ + blkrow_start += blkrow_size; + } + + /* Compute and store "left-over" row of blocks at bottom of image */ + /* Start at bottom edge of unpadded image data and come up */ + /* BLOCKSIZE pixels. This too must account for padding. */ + blkrow_start = ((pad + ih - blocksize) * pw) + pad; + /* Start the block offset for the last row at this point */ + offset = blkrow_start; + /* Foreach non-overlapping column of blocks in last row of the image */ + for(bx = 0; bx < lastbw; bx++){ + /* Store current block offset */ + blkoffs[bi++] = offset; + /* Bump to the beginning of the next block */ + offset += blocksize; + } + + /* Compute and store last "left-over" block in last row. */ + /* Start at right edge of unpadded image data and come in */ + /* BLOCKSIZE pixels. */ + blkoffs[bi++] = blkrow_start + iw - blocksize; + + *optr = blkoffs; + *ow = bw; + *oh = bh; + return(0); +} + +/************************************************************************* +#cat: low_contrast_block - Takes the offset to an image block of specified +#cat: dimension, and analyzes the pixel intensities in the block +#cat: to determine if there is sufficient contrast for further +#cat: processing. + + Input: + blkoffset - byte offset into the padded input image to the origin of + the block to be analyzed + blocksize - dimension (in pixels) of the width and height of the block + (passing separate blocksize from LFSPARMS on purpose) + pdata - padded input image data (8 bits [0..256) grayscale) + pw - width (in pixels) of the padded input image + ph - height (in pixels) of the padded input image + lfsparms - parameters and thresholds for controlling LFS + Return Code: + TRUE - block has sufficiently low contrast + FALSE - block has sufficiently hight contrast + Negative - system error +************************************************************************** +**************************************************************************/ +int low_contrast_block(const int blkoffset, const int blocksize, + unsigned char *pdata, const int pw, const int ph, + const LFSPARMS *lfsparms) +{ + int pixtable[IMG_6BIT_PIX_LIMIT], numpix; + int px, py, pi; + unsigned char *sptr, *pptr; + int delta; + double tdbl; + int prctmin = 0, prctmax = 0, prctthresh; + int pixsum, found; + + numpix = blocksize*blocksize; + memset(pixtable, 0, IMG_6BIT_PIX_LIMIT*sizeof(int)); + + tdbl = (lfsparms->percentile_min_max/100.0) * (double)(numpix-1); + tdbl = trunc_dbl_precision(tdbl, TRUNC_SCALE); + prctthresh = sround(tdbl); + + sptr = pdata+blkoffset; + for(py = 0; py < blocksize; py++){ + pptr = sptr; + for(px = 0; px < blocksize; px++){ + pixtable[*pptr]++; + pptr++; + } + sptr += pw; + } + + pi = 0; + pixsum = 0; + found = FALSE; + while(pi < IMG_6BIT_PIX_LIMIT){ + pixsum += pixtable[pi]; + if(pixsum >= prctthresh){ + prctmin = pi; + found = TRUE; + break; + } + pi++; + } + if(!found){ + fprintf(stderr, + "ERROR : low_contrast_block : min percentile pixel not found\n"); + return(-510); + } + + pi = IMG_6BIT_PIX_LIMIT-1; + pixsum = 0; + found = FALSE; + while(pi >= 0){ + pixsum += pixtable[pi]; + if(pixsum >= prctthresh){ + prctmax = pi; + found = TRUE; + break; + } + pi--; + } + if(!found){ + fprintf(stderr, + "ERROR : low_contrast_block : max percentile pixel not found\n"); + return(-511); + } + + delta = prctmax - prctmin; + + if(delta < lfsparms->min_contrast_delta) + return(TRUE); + else + return(FALSE); +} + +/************************************************************************* +************************************************************************** +#cat: find_valid_block - Take a Direction Map, Low Contrast Map, +#cat: Starting block address, a direction and searches the +#cat: maps in the specified direction until either a block valid +#cat: direction is encountered or a block flagged as LOW CONTRAST +#cat: is encountered. If a valid direction is located, it and the +#cat: address of the corresponding block are returned with a +#cat: code of FOUND. Otherwise, a code of NOT_FOUND is returned. + + Input: + direction_map - map of blocks containing directional ridge flows + low_contrast_map - map of blocks flagged as LOW CONTRAST + sx - X-block coord where search starts in maps + sy - Y-block coord where search starts in maps + mw - number of blocks horizontally in the maps + mh - number of blocks vertically in the maps + x_incr - X-block increment to direct search + y_incr - Y-block increment to direct search + Output: + nbr_dir - valid direction found + nbr_x - X-block coord where valid direction found + nbr_y - Y-block coord where valid direction found + Return Code: + FOUND - neighboring block with valid direction found + NOT_FOUND - neighboring block with valid direction NOT found +**************************************************************************/ +int find_valid_block(int *nbr_dir, int *nbr_x, int *nbr_y, + int *direction_map, int *low_contrast_map, + const int sx, const int sy, + const int mw, const int mh, + const int x_incr, const int y_incr) +{ + int x, y, dir; + + /* Initialize starting block coords. */ + x = sx + x_incr; + y = sy + y_incr; + + /* While we are not outside the boundaries of the map ... */ + while((x >= 0) && (x < mw) && (y >= 0) && (y < mh)){ + /* Stop unsuccessfully if we encounter a LOW CONTRAST block. */ + if(*(low_contrast_map+(y*mw)+x)) + return(NOT_FOUND); + + /* Stop successfully if we encounter a block with valid direction. */ + if((dir = *(direction_map+(y*mw)+x)) >= 0){ + *nbr_dir = dir; + *nbr_x = x; + *nbr_y = y; + return(FOUND); + } + + /* Otherwise, advance to the next block in the map. */ + x += x_incr; + y += y_incr; + } + + /* If we get here, then we did not find a valid block in the given */ + /* direction in the map. */ + return(NOT_FOUND); +} + +/************************************************************************* +************************************************************************** +#cat: set_margin_blocks - Take an image map and sets its perimeter values to +#cat: the specified value. + + Input: + map - map of blocks to be modified + mw - number of blocks horizontally in the map + mh - number of blocks vertically in the map + margin_value - value to be assigned to the perimeter blocks + Output: + map - resulting map +**************************************************************************/ +void set_margin_blocks(int *map, const int mw, const int mh, + const int margin_value) +{ + int x, y; + int *ptr1, *ptr2; + + ptr1 = map; + ptr2 = map+((mh-1)*mw); + for(x = 0; x < mw; x++){ + *ptr1++ = margin_value; + *ptr2++ = margin_value; + } + + ptr1 = map + mw; + ptr2 = map + mw + mw - 1; + for(y = 1; y < mh-1; y++){ + *ptr1 = margin_value; + *ptr2 = margin_value; + ptr1 += mw; + ptr2 += mw; + } + +} + --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/maps.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/maps.c.svn-base @@ -0,0 +1,2387 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: MAPS.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 10/26/1999 by MDG + To permit margin blocks to be flagged in + low contrast and low flow maps. + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for computing various block-based + maps (including directional ridge flow maps) from an arbitrarily- + sized image as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + gen_image_maps() + gen_initial_maps() + interpolate_direction_map() + morph_TF_map() + pixelize_map() + smooth_direction_map() + gen_high_curve_map() + gen_initial_imap() + primary_dir_test() + secondary_fork_test() + remove_incon_dirs() + test_top_edge() + test_right_edge() + test_bottom_edge() + test_left_edge() + remove_dir() + average_8nbr_dir() + num_valid_8nbrs() + smooth_imap() + vorticity() + accum_nbr_vorticity() + curvature() + +***********************************************************************/ + +#include +#include +#include +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: gen_image_maps - Computes a set of image maps based on Version 2 +#cat: of the NIST LFS System. The first map is a Direction Map +#cat: which is a 2D vector of integer directions, where each +#cat: direction represents the dominant ridge flow in a block of +#cat: the input grayscale image. The Low Contrast Map flags +#cat: blocks with insufficient contrast. The Low Flow Map flags +#cat: blocks with insufficient ridge flow. The High Curve Map +#cat: flags blocks containing high curvature. This routine will +#cat: generate maps for an arbitrarily sized, non-square, image. + + Input: + pdata - padded input image data (8 bits [0..256) grayscale) + pw - padded width (in pixels) of the input image + ph - padded height (in pixels) of the input image + dir2rad - lookup table for converting integer directions + dftwaves - structure containing the DFT wave forms + dftgrids - structure containing the rotated pixel grid offsets + lfsparms - parameters and thresholds for controlling LFS + Output: + odmap - points to the created Direction Map + olcmap - points to the created Low Contrast Map + olfmap - points to the Low Ridge Flow Map + ohcmap - points to the High Curvature Map + omw - width (in blocks) of the maps + omh - height (in blocks) of the maps + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, + int *omw, int *omh, + unsigned char *pdata, const int pw, const int ph, + const DIR2RAD *dir2rad, const DFTWAVES *dftwaves, + const ROTGRIDS *dftgrids, const LFSPARMS *lfsparms) +{ + int *direction_map, *low_contrast_map, *low_flow_map, *high_curve_map; + int mw, mh, iw, ih; + int *blkoffs; + int ret; /* return code */ + + /* 1. Compute block offsets for the entire image, accounting for pad */ + /* Block_offsets() assumes square block (grid), so ERROR otherwise. */ + if(dftgrids->grid_w != dftgrids->grid_h){ + fprintf(stderr, + "ERROR : gen_image_maps : DFT grids must be square\n"); + return(-540); + } + /* Compute unpadded image dimensions. */ + iw = pw - (dftgrids->pad<<1); + ih = ph - (dftgrids->pad<<1); + if((ret = block_offsets(&blkoffs, &mw, &mh, iw, ih, + dftgrids->pad, lfsparms->blocksize))){ + return(ret); + } + + /* 2. Generate initial Direction Map and Low Contrast Map*/ + if((ret = gen_initial_maps(&direction_map, &low_contrast_map, + &low_flow_map, blkoffs, mw, mh, + pdata, pw, ph, dftwaves, dftgrids, lfsparms))){ + /* Free memory allocated to this point. */ + free(blkoffs); + return(ret); + } + + if((ret = morph_TF_map(low_flow_map, mw, mh, lfsparms))){ + return(ret); + } + + /* 3. Remove directions that are inconsistent with neighbors */ + remove_incon_dirs(direction_map, mw, mh, dir2rad, lfsparms); + + + /* 4. Smooth Direction Map values with their neighbors */ + smooth_direction_map(direction_map, low_contrast_map, mw, mh, + dir2rad, lfsparms); + + /* 5. Interpolate INVALID direction blocks with their valid neighbors. */ + if((ret = interpolate_direction_map(direction_map, low_contrast_map, + mw, mh, lfsparms))){ + return(ret); + } + + /* May be able to skip steps 6 and/or 7 if computation time */ + /* is a critical factor. */ + + /* 6. Remove directions that are inconsistent with neighbors */ + remove_incon_dirs(direction_map, mw, mh, dir2rad, lfsparms); + + /* 7. Smooth Direction Map values with their neighbors. */ + smooth_direction_map(direction_map, low_contrast_map, mw, mh, + dir2rad, lfsparms); + + /* 8. Set the Direction Map values in the image margin to INVALID. */ + set_margin_blocks(direction_map, mw, mh, INVALID_DIR); + + /* 9. Generate High Curvature Map from interpolated Direction Map. */ + if((ret = gen_high_curve_map(&high_curve_map, direction_map, mw, mh, + lfsparms))){ + return(ret); + } + + /* Deallocate working memory. */ + free(blkoffs); + + *odmap = direction_map; + *olcmap = low_contrast_map; + *olfmap = low_flow_map; + *ohcmap = high_curve_map; + *omw = mw; + *omh = mh; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: gen_initial_maps - Creates an initial Direction Map from the given +#cat: input image. It very important that the image be properly +#cat: padded so that rotated grids along the boundary of the image +#cat: do not access unkown memory. The rotated grids are used by a +#cat: DFT-based analysis to determine the integer directions +#cat: in the map. Typically this initial vector of directions will +#cat: subsequently have weak or inconsistent directions removed +#cat: followed by a smoothing process. The resulting Direction +#cat: Map contains valid directions >= 0 and INVALID values = -1. +#cat: This routine also computes and returns 2 other image maps. +#cat: The Low Contrast Map flags blocks in the image with +#cat: insufficient contrast. Blocks with low contrast have a +#cat: corresponding direction of INVALID in the Direction Map. +#cat: The Low Flow Map flags blocks in which the DFT analyses +#cat: could not determine a significant ridge flow. Blocks with +#cat: low ridge flow also have a corresponding direction of +#cat: INVALID in the Direction Map. + + Input: + blkoffs - offsets to the pixel origin of each block in the padded image + mw - number of blocks horizontally in the padded input image + mh - number of blocks vertically in the padded input image + pdata - padded input image data (8 bits [0..256) grayscale) + pw - width (in pixels) of the padded input image + ph - height (in pixels) of the padded input image + dftwaves - structure containing the DFT wave forms + dftgrids - structure containing the rotated pixel grid offsets + lfsparms - parameters and thresholds for controlling LFS + Output: + odmap - points to the newly created Direction Map + olcmap - points to the newly created Low Contrast Map + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, + int *blkoffs, const int mw, const int mh, + unsigned char *pdata, const int pw, const int ph, + const DFTWAVES *dftwaves, const ROTGRIDS *dftgrids, + const LFSPARMS *lfsparms) +{ + int *direction_map, *low_contrast_map, *low_flow_map; + int bi, bsize, blkdir; + int *wis, *powmax_dirs; + double **powers, *powmaxs, *pownorms; + int nstats; + int ret; /* return code */ + int dft_offset; + int xminlimit, xmaxlimit, yminlimit, ymaxlimit; + int win_x, win_y, low_contrast_offset; + + print2log("INITIAL MAP\n"); + + /* Compute total number of blocks in map */ + bsize = mw * mh; + + /* Allocate Direction Map memory */ + direction_map = (int *)malloc(bsize * sizeof(int)); + if(direction_map == (int *)NULL){ + fprintf(stderr, + "ERROR : gen_initial_maps : malloc : direction_map\n"); + return(-550); + } + /* Initialize the Direction Map to INVALID (-1). */ + memset(direction_map, INVALID_DIR, bsize * sizeof(int)); + + /* Allocate Low Contrast Map memory */ + low_contrast_map = (int *)malloc(bsize * sizeof(int)); + if(low_contrast_map == (int *)NULL){ + free(direction_map); + fprintf(stderr, + "ERROR : gen_initial_maps : malloc : low_contrast_map\n"); + return(-551); + } + /* Initialize the Low Contrast Map to FALSE (0). */ + memset(low_contrast_map, 0, bsize * sizeof(int)); + + /* Allocate Low Ridge Flow Map memory */ + low_flow_map = (int *)malloc(bsize * sizeof(int)); + if(low_flow_map == (int *)NULL){ + free(direction_map); + free(low_contrast_map); + fprintf(stderr, + "ERROR : gen_initial_maps : malloc : low_flow_map\n"); + return(-552); + } + /* Initialize the Low Flow Map to FALSE (0). */ + memset(low_flow_map, 0, bsize * sizeof(int)); + + /* Allocate DFT directional power vectors */ + if((ret = alloc_dir_powers(&powers, dftwaves->nwaves, dftgrids->ngrids))){ + /* Free memory allocated to this point. */ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + return(ret); + } + + /* Allocate DFT power statistic arrays */ + /* Compute length of statistics arrays. Statistics not needed */ + /* for the first DFT wave, so the length is number of waves - 1. */ + nstats = dftwaves->nwaves - 1; + if((ret = alloc_power_stats(&wis, &powmaxs, &powmax_dirs, + &pownorms, nstats))){ + /* Free memory allocated to this point. */ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free_dir_powers(powers, dftwaves->nwaves); + return(ret); + } + + /* Compute special window origin limits for determining low contrast. */ + /* These pixel limits avoid analyzing the padded borders of the image. */ + xminlimit = dftgrids->pad; + yminlimit = dftgrids->pad; + xmaxlimit = pw - dftgrids->pad - lfsparms->windowsize - 1; + ymaxlimit = ph - dftgrids->pad - lfsparms->windowsize - 1; + + /* Foreach block in image ... */ + for(bi = 0; bi < bsize; bi++){ + /* Adjust block offset from pointing to block origin to pointing */ + /* to surrounding window origin. */ + dft_offset = blkoffs[bi] - (lfsparms->windowoffset * pw) - + lfsparms->windowoffset; + + /* Compute pixel coords of window origin. */ + win_x = dft_offset % pw; + win_y = (int)(dft_offset / pw); + + /* Make sure the current window does not access padded image pixels */ + /* for analyzing low contrast. */ + win_x = max(xminlimit, win_x); + win_x = min(xmaxlimit, win_x); + win_y = max(yminlimit, win_y); + win_y = min(ymaxlimit, win_y); + low_contrast_offset = (win_y * pw) + win_x; + + print2log(" BLOCK %2d (%2d, %2d) ", bi, bi%mw, bi/mw); + + /* If block is low contrast ... */ + if((ret = low_contrast_block(low_contrast_offset, lfsparms->windowsize, + pdata, pw, ph, lfsparms))){ + /* If system error ... */ + if(ret < 0){ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + return(ret); + } + + /* Otherwise, block is low contrast ... */ + print2log("LOW CONTRAST\n"); + low_contrast_map[bi] = TRUE; + /* Direction Map's block is already set to INVALID. */ + } + /* Otherwise, sufficient contrast for DFT processing ... */ + else { + print2log("\n"); + + /* Compute DFT powers */ + if((ret = dft_dir_powers(powers, pdata, low_contrast_offset, pw, ph, + dftwaves, dftgrids))){ + /* Free memory allocated to this point. */ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + return(ret); + } + + /* Compute DFT power statistics, skipping first applied DFT */ + /* wave. This is dependent on how the primary and secondary */ + /* direction tests work below. */ + if((ret = dft_power_stats(wis, powmaxs, powmax_dirs, pownorms, powers, + 1, dftwaves->nwaves, dftgrids->ngrids))){ + /* Free memory allocated to this point. */ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + return(ret); + } + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + { int _w; + fprintf(logfp, " Power\n"); + for(_w = 0; _w < nstats; _w++){ + /* Add 1 to wis[w] to create index to original dft_coefs[] */ + fprintf(logfp, " wis[%d] %d %12.3f %2d %9.3f %12.3f\n", + _w, wis[_w]+1, + powmaxs[wis[_w]], powmax_dirs[wis[_w]], pownorms[wis[_w]], + powers[0][powmax_dirs[wis[_w]]]); + } + } +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Conduct primary direction test */ + blkdir = primary_dir_test(powers, wis, powmaxs, powmax_dirs, + pownorms, nstats, lfsparms); + + if(blkdir != INVALID_DIR) + direction_map[bi] = blkdir; + else{ + /* Conduct secondary (fork) direction test */ + blkdir = secondary_fork_test(powers, wis, powmaxs, powmax_dirs, + pownorms, nstats, lfsparms); + if(blkdir != INVALID_DIR) + direction_map[bi] = blkdir; + /* Otherwise current direction in Direction Map remains INVALID */ + else + /* Flag the block as having LOW RIDGE FLOW. */ + low_flow_map[bi] = TRUE; + } + + } /* End DFT */ + } /* bi */ + + /* Deallocate working memory */ + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + + *odmap = direction_map; + *olcmap = low_contrast_map; + *olfmap = low_flow_map; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: interpolate_direction_map - Take a Direction Map and Low Contrast +#cat: Map and attempts to fill in INVALID directions in the +#cat: Direction Map based on a blocks valid neighbors. The +#cat: valid neighboring directions are combined in a weighted +#cat: average inversely proportional to their distance from +#cat: the block being interpolated. Low Contrast blocks are +#cat: used to prempt the search for a valid neighbor in a +#cat: specific direction, which keeps the process from +#cat: interpolating directions for blocks in the background and +#cat: and perimeter of the fingerprint in the image. + + Input: + direction_map - map of blocks containing directional ridge flow + low_contrast_map - map of blocks flagged as LOW CONTRAST + mw - number of blocks horizontally in the maps + mh - number of blocks vertically in the maps + lfsparms - parameters and thresholds for controlling LFS + Output: + direction_map - contains the newly interpolated results + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int interpolate_direction_map(int *direction_map, int *low_contrast_map, + const int mw, const int mh, const LFSPARMS *lfsparms) +{ + int x, y, new_dir; + int n_dir, e_dir, s_dir, w_dir; + int n_dist = 0, e_dist = 0, s_dist = 0, w_dist = 0, total_dist; + int n_found, e_found, s_found, w_found, total_found; + int n_delta = 0, e_delta = 0, s_delta = 0, w_delta = 0, total_delta; + int nbr_x, nbr_y; + int *omap, *dptr, *cptr, *optr; + double avr_dir; + + print2log("INTERPOLATE DIRECTION MAP\n"); + + /* Allocate output (interpolated) Direction Map. */ + omap = (int *)malloc(mw*mh*sizeof(int)); + if(omap == (int *)NULL){ + fprintf(stderr, + "ERROR : interpolate_direction_map : malloc : omap\n"); + return(-520); + } + + /* Set pointers to the first block in the maps. */ + dptr = direction_map; + cptr = low_contrast_map; + optr = omap; + + /* Foreach block in the maps ... */ + for(y = 0; y < mh; y++){ + for(x = 0; x < mw; x++){ + + /* If image block is NOT LOW CONTRAST and has INVALID direction ... */ + if((!*cptr) && (*dptr == INVALID_DIR)){ + + /* Set neighbor accumulators to 0. */ + total_found = 0; + total_dist = 0; + + /* Find north neighbor. */ + if((n_found = find_valid_block(&n_dir, &nbr_x, &nbr_y, + direction_map, low_contrast_map, + x, y, mw, mh, 0, -1)) == FOUND){ + /* Compute north distance. */ + n_dist = y - nbr_y; + /* Accumulate neighbor distance. */ + total_dist += n_dist; + /* Bump number of neighbors found. */ + total_found++; + } + + /* Find east neighbor. */ + if((e_found = find_valid_block(&e_dir, &nbr_x, &nbr_y, + direction_map, low_contrast_map, + x, y, mw, mh, 1, 0)) == FOUND){ + /* Compute east distance. */ + e_dist = nbr_x - x; + /* Accumulate neighbor distance. */ + total_dist += e_dist; + /* Bump number of neighbors found. */ + total_found++; + } + + /* Find south neighbor. */ + if((s_found = find_valid_block(&s_dir, &nbr_x, &nbr_y, + direction_map, low_contrast_map, + x, y, mw, mh, 0, 1)) == FOUND){ + /* Compute south distance. */ + s_dist = nbr_y - y; + /* Accumulate neighbor distance. */ + total_dist += s_dist; + /* Bump number of neighbors found. */ + total_found++; + } + + /* Find west neighbor. */ + if((w_found = find_valid_block(&w_dir, &nbr_x, &nbr_y, + direction_map, low_contrast_map, + x, y, mw, mh, -1, 0)) == FOUND){ + /* Compute west distance. */ + w_dist = x - nbr_x; + /* Accumulate neighbor distance. */ + total_dist += w_dist; + /* Bump number of neighbors found. */ + total_found++; + } + + /* If a sufficient number of neighbors found (Ex. 2) ... */ + if(total_found >= lfsparms->min_interpolate_nbrs){ + + /* Accumulate weighted sum of neighboring directions */ + /* inversely related to the distance from current block. */ + total_delta = 0.0; + /* If neighbor found to the north ... */ + if(n_found){ + n_delta = total_dist - n_dist; + total_delta += n_delta; + } + /* If neighbor found to the east ... */ + if(e_found){ + e_delta = total_dist - e_dist; + total_delta += e_delta; + } + /* If neighbor found to the south ... */ + if(s_found){ + s_delta = total_dist - s_dist; + total_delta += s_delta; + } + /* If neighbor found to the west ... */ + if(w_found){ + w_delta = total_dist - w_dist; + total_delta += w_delta; + } + + avr_dir = 0.0; + + if(n_found){ + avr_dir += (n_dir*(n_delta/(double)total_delta)); + } + if(e_found){ + avr_dir += (e_dir*(e_delta/(double)total_delta)); + } + if(s_found){ + avr_dir += (s_dir*(s_delta/(double)total_delta)); + } + if(w_found){ + avr_dir += (w_dir*(w_delta/(double)total_delta)); + } + + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + avr_dir = trunc_dbl_precision(avr_dir, TRUNC_SCALE); + + /* Assign interpolated direction to output Direction Map. */ + new_dir = sround(avr_dir); + + print2log(" Block %d,%d INTERP numnbs=%d newdir=%d\n", + x, y, total_found, new_dir); + + *optr = new_dir; + } + else{ + /* Otherwise, the direction remains INVALID. */ + *optr = *dptr; + } + } + else{ + /* Otherwise, assign the current direction to the output block. */ + *optr = *dptr; + } + + /* Bump to the next block in the maps ... */ + dptr++; + cptr++; + optr++; + } + } + + /* Copy the interpolated directions into the input map. */ + memcpy(direction_map, omap, mw*mh*sizeof(int)); + /* Deallocate the working memory. */ + free(omap); + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: morph_tf_map - Takes a 2D vector of TRUE and FALSE values integers +#cat: and dialates and erodes the map in an attempt to fill +#cat: in voids in the map. + + Input: + tfmap - vector of integer block values + mw - width (in blocks) of the map + mh - height (in blocks) of the map + lfsparms - parameters and thresholds for controlling LFS + Output: + tfmap - resulting morphed map +**************************************************************************/ +int morph_TF_map(int *tfmap, const int mw, const int mh, + const LFSPARMS *lfsparms) +{ + unsigned char *cimage, *mimage, *cptr; + int *mptr; + int i; + + + /* Convert TRUE/FALSE map into a binary byte image. */ + cimage = (unsigned char *)malloc(mw*mh); + if(cimage == (unsigned char *)NULL){ + fprintf(stderr, "ERROR : morph_TF_map : malloc : cimage\n"); + return(-660); + } + + mimage = (unsigned char *)malloc(mw*mh); + if(mimage == (unsigned char *)NULL){ + fprintf(stderr, "ERROR : morph_TF_map : malloc : mimage\n"); + return(-661); + } + + cptr = cimage; + mptr = tfmap; + for(i = 0; i < mw*mh; i++){ + *cptr++ = *mptr++; + } + + dilate_charimage_2(cimage, mimage, mw, mh); + dilate_charimage_2(mimage, cimage, mw, mh); + erode_charimage_2(cimage, mimage, mw, mh); + erode_charimage_2(mimage, cimage, mw, mh); + + cptr = cimage; + mptr = tfmap; + for(i = 0; i < mw*mh; i++){ + *mptr++ = *cptr++; + } + + free(cimage); + free(mimage); + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: pixelize_map - Takes a block image map and assigns each pixel in the +#cat: image its corresponding block value. This allows block +#cat: values in maps to be directly accessed via pixel addresses. + + Input: + iw - the width (in pixels) of the corresponding image + ih - the height (in pixels) of the corresponding image + imap - input block image map + mw - the width (in blocks) of the map + mh - the height (in blocks) of the map + blocksize - the dimension (in pixels) of each block + Output: + omap - points to the resulting pixelized map + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int pixelize_map(int **omap, const int iw, const int ih, + int *imap, const int mw, const int mh, const int blocksize) +{ + int *pmap; + int ret, x, y; + int *blkoffs, bw, bh, bi; + int *spptr, *pptr; + + pmap = (int *)malloc(iw*ih*sizeof(int)); + if(pmap == (int *)NULL){ + fprintf(stderr, "ERROR : pixelize_map : malloc : pmap\n"); + return(-590); + } + + if((ret = block_offsets(&blkoffs, &bw, &bh, iw, ih, 0, blocksize))){ + return(ret); + } + + if((bw != mw) || (bh != mh)){ + free(blkoffs); + fprintf(stderr, + "ERROR : pixelize_map : block dimensions do not match\n"); + return(-591); + } + + for(bi = 0; bi < mw*mh; bi++){ + spptr = pmap + blkoffs[bi]; + for(y = 0; y < blocksize; y++){ + pptr = spptr; + for(x = 0; x < blocksize; x++){ + *pptr++ = imap[bi]; + } + spptr += iw; + } + } + + /* Deallocate working memory. */ + free(blkoffs); + /* Assign pixelized map to output pointer. */ + *omap = pmap; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: smooth_direction_map - Takes a vector of integer directions and smooths +#cat: them by analyzing the direction of adjacent neighbors. + + Input: + direction_map - vector of integer block values + mw - width (in blocks) of the map + mh - height (in blocks) of the map + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Output: + imap - vector of smoothed input values +**************************************************************************/ +void smooth_direction_map(int *direction_map, int *low_contrast_map, + const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int mx, my; + int *dptr, *cptr; + int avrdir, nvalid; + double dir_strength; + + print2log("SMOOTH DIRECTION MAP\n"); + + /* Assign pointers to beginning of both maps. */ + dptr = direction_map; + cptr = low_contrast_map; + + /* Foreach block in maps ... */ + for(my = 0; my < mh; my++){ + for(mx = 0; mx < mw; mx++){ + /* If the current block does NOT have LOW CONTRAST ... */ + if(!*cptr){ + + /* Compute average direction from neighbors, returning the */ + /* number of valid neighbors used in the computation, and */ + /* the "strength" of the average direction. */ + average_8nbr_dir(&avrdir, &dir_strength, &nvalid, + direction_map, mx, my, mw, mh, dir2rad); + + /* If average direction strength is strong enough */ + /* (Ex. thresh==0.2)... */ + if(dir_strength >= lfsparms->dir_strength_min){ + /* If Direction Map direction is valid ... */ + if(*dptr != INVALID_DIR){ + /* Conduct valid neighbor test (Ex. thresh==3)... */ + if(nvalid >= lfsparms->rmv_valid_nbr_min){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", + mx+(my*mw), mx, my); + fprintf(logfp, " Average NBR : %2d %6.3f %d\n", + avrdir, dir_strength, nvalid); + fprintf(logfp, " 1. Valid NBR (%d >= %d)\n", + nvalid, lfsparms->rmv_valid_nbr_min); + fprintf(logfp, " Valid Direction = %d\n", *dptr); + fprintf(logfp, " Smoothed Direction = %d\n", avrdir); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Reassign valid direction with average direction. */ + *dptr = avrdir; + } + } + /* Otherwise direction is invalid ... */ + else{ + /* Even if DIRECTION_MAP value is invalid, if number of */ + /* valid neighbors is big enough (Ex. thresh==7)... */ + if(nvalid >= lfsparms->smth_valid_nbr_min){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", + mx+(my*mw), mx, my); + fprintf(logfp, " Average NBR : %2d %6.3f %d\n", + avrdir, dir_strength, nvalid); + fprintf(logfp, " 2. Invalid NBR (%d >= %d)\n", + nvalid, lfsparms->smth_valid_nbr_min); + fprintf(logfp, " Invalid Direction = %d\n", *dptr); + fprintf(logfp, " Smoothed Direction = %d\n", avrdir); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Assign invalid direction with average direction. */ + *dptr = avrdir; + } + } + } + } + /* Otherwise, block has LOW CONTRAST, so keep INVALID direction. */ + + /* Bump to next block in maps. */ + dptr++; + cptr++; + } + } +} + +/************************************************************************* +************************************************************************** +#cat: gen_high_curve_map - Takes a Direction Map and generates a new map +#cat: that flags blocks with HIGH CURVATURE. + + Input: + direction_map - map of blocks containing directional ridge flow + mw - the width (in blocks) of the map + mh - the height (in blocks) of the map + lfsparms - parameters and thresholds for controlling LFS + Output: + ohcmap - points to the created High Curvature Map + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int gen_high_curve_map(int **ohcmap, int *direction_map, + const int mw, const int mh, const LFSPARMS *lfsparms) +{ + int *high_curve_map, mapsize; + int *hptr, *dptr; + int bx, by; + int nvalid, cmeasure, vmeasure; + + mapsize = mw*mh; + + /* Allocate High Curvature Map. */ + high_curve_map = (int *)malloc(mapsize * sizeof(int)); + if(high_curve_map == (int *)NULL){ + fprintf(stderr, + "ERROR: gen_high_curve_map : malloc : high_curve_map\n"); + return(-530); + } + /* Initialize High Curvature Map to FALSE (0). */ + memset(high_curve_map, 0, mapsize*sizeof(int)); + + hptr = high_curve_map; + dptr = direction_map; + + /* Foreach row in maps ... */ + for(by = 0; by < mh; by++){ + /* Foreach column in maps ... */ + for(bx = 0; bx < mw; bx++){ + + /* Count number of valid neighbors around current block ... */ + nvalid = num_valid_8nbrs(direction_map, bx, by, mw, mh); + + /* If valid neighbors exist ... */ + if(nvalid > 0){ + /* If current block's direction is INVALID ... */ + if(*dptr == INVALID_DIR){ + /* If a sufficient number of VALID neighbors exists ... */ + if(nvalid >= lfsparms->vort_valid_nbr_min){ + /* Measure vorticity of neighbors. */ + vmeasure = vorticity(direction_map, bx, by, mw, mh, + lfsparms->num_directions); + /* If vorticity is sufficiently high ... */ + if(vmeasure >= lfsparms->highcurv_vorticity_min) + /* Flag block as HIGH CURVATURE. */ + *hptr = TRUE; + } + } + /* Otherwise block has valid direction ... */ + else{ + /* Measure curvature around the valid block. */ + cmeasure = curvature(direction_map, bx, by, mw, mh, + lfsparms->num_directions); + /* If curvature is sufficiently high ... */ + if(cmeasure >= lfsparms->highcurv_curvature_min) + *hptr = TRUE; + } + } /* Else (nvalid <= 0) */ + + /* Bump pointers to next block in maps. */ + dptr++; + hptr++; + + } /* bx */ + } /* by */ + + /* Assign High Curvature Map to output pointer. */ + *ohcmap = high_curve_map; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: gen_initial_imap - Creates an initial IMAP from the given input image. +#cat: It very important that the image be properly padded so +#cat: that rotated grids along the boudary of the image do not +#cat: access unkown memory. The rotated grids are used by a +#cat: DFT-based analysis to determine the integer directions +#cat: in the IMAP. Typically this initial vector of directions will +#cat: subsequently have weak or inconsistent directions removed +#cat: followed by a smoothing process. + + Input: + blkoffs - offsets to the pixel origin of each block in the padded image + mw - number of blocks horizontally in the padded input image + mh - number of blocks vertically in the padded input image + pdata - padded input image data (8 bits [0..256) grayscale) + pw - width (in pixels) of the padded input image + ph - height (in pixels) of the padded input image + dftwaves - structure containing the DFT wave forms + dftgrids - structure containing the rotated pixel grid offsets + lfsparms - parameters and thresholds for controlling LFS + Output: + optr - points to the newly created IMAP + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int gen_initial_imap(int **optr, int *blkoffs, const int mw, const int mh, + unsigned char *pdata, const int pw, const int ph, + const DFTWAVES *dftwaves, const ROTGRIDS *dftgrids, + const LFSPARMS *lfsparms) +{ + int *imap; + int bi, bsize, blkdir; + int *wis, *powmax_dirs; + double **powers, *powmaxs, *pownorms; + int nstats; + int ret; /* return code */ + + print2log("INITIAL MAP\n"); + + /* Compute total number of blocks in IMAP */ + bsize = mw * mh; + + /* Allocate IMAP memory */ + imap = (int *)malloc(bsize * sizeof(int)); + if(imap == (int *)NULL){ + fprintf(stderr, "ERROR : gen_initial_imap : malloc : imap\n"); + return(-70); + } + + /* Allocate DFT directional power vectors */ + if((ret = alloc_dir_powers(&powers, dftwaves->nwaves, dftgrids->ngrids))){ + /* Free memory allocated to this point. */ + free(imap); + return(ret); + } + + /* Allocate DFT power statistic arrays */ + /* Compute length of statistics arrays. Statistics not needed */ + /* for the first DFT wave, so the length is number of waves - 1. */ + nstats = dftwaves->nwaves - 1; + if((ret = alloc_power_stats(&wis, &powmaxs, &powmax_dirs, + &pownorms, nstats))){ + /* Free memory allocated to this point. */ + free(imap); + free_dir_powers(powers, dftwaves->nwaves); + return(ret); + } + + /* Initialize the imap to -1 */ + memset(imap, INVALID_DIR, bsize * sizeof(int)); + + /* Foreach block in imap ... */ + for(bi = 0; bi < bsize; bi++){ + + print2log(" BLOCK %2d (%2d, %2d)\n", bi, bi%mw, bi/mw); + + /* Compute DFT powers */ + if((ret = dft_dir_powers(powers, pdata, blkoffs[bi], pw, ph, + dftwaves, dftgrids))){ + /* Free memory allocated to this point. */ + free(imap); + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + return(ret); + } + + /* Compute DFT power statistics, skipping first applied DFT */ + /* wave. This is dependent on how the primary and secondary */ + /* direction tests work below. */ + if((ret = dft_power_stats(wis, powmaxs, powmax_dirs, pownorms, powers, + 1, dftwaves->nwaves, dftgrids->ngrids))){ + /* Free memory allocated to this point. */ + free(imap); + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + return(ret); + } + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + { int _w; + fprintf(logfp, " Power\n"); + for(_w = 0; _w < nstats; _w++){ + /* Add 1 to wis[w] to create index to original dft_coefs[] */ + fprintf(logfp, " wis[%d] %d %12.3f %2d %9.3f %12.3f\n", + _w, wis[_w]+1, + powmaxs[wis[_w]], powmax_dirs[wis[_w]], pownorms[wis[_w]], + powers[0][powmax_dirs[wis[_w]]]); + } + } +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Conduct primary direction test */ + blkdir = primary_dir_test(powers, wis, powmaxs, powmax_dirs, + pownorms, nstats, lfsparms); + + if(blkdir != INVALID_DIR) + imap[bi] = blkdir; + else{ + /* Conduct secondary (fork) direction test */ + blkdir = secondary_fork_test(powers, wis, powmaxs, powmax_dirs, + pownorms, nstats, lfsparms); + if(blkdir != INVALID_DIR) + imap[bi] = blkdir; + } + + /* Otherwise current block direction in IMAP remains INVALID */ + + } /* bi */ + + /* Deallocate working memory */ + free_dir_powers(powers, dftwaves->nwaves); + free(wis); + free(powmaxs); + free(powmax_dirs); + free(pownorms); + + *optr = imap; + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: primary_dir_test - Applies the primary set of criteria for selecting +#cat: an IMAP integer direction from a set of DFT results +#cat: computed from a block of image data + + Input: + powers - DFT power computed from each (N) wave frequencies at each + rotation direction in the current image block + wis - sorted order of the highest N-1 frequency power statistics + powmaxs - maximum power for each of the highest N-1 frequencies + powmax_dirs - directions associated with each of the N-1 maximum powers + pownorms - normalized power for each of the highest N-1 frequencies + nstats - N-1 wave frequencies (where N is the length of dft_coefs) + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Zero or Positive - The selected IMAP integer direction + INVALID_DIR - IMAP Integer direction could not be determined +**************************************************************************/ +int primary_dir_test(double **powers, const int *wis, + const double *powmaxs, const int *powmax_dirs, + const double *pownorms, const int nstats, + const LFSPARMS *lfsparms) +{ + int w; + + print2log(" Primary\n"); + + /* Look at max power statistics in decreasing order ... */ + for(w = 0; w < nstats; w++){ + /* 1. Test magnitude of current max power (Ex. Thresh==100000) */ + if((powmaxs[wis[w]] > lfsparms->powmax_min) && + /* 2. Test magnitude of normalized max power (Ex. Thresh==3.8) */ + (pownorms[wis[w]] > lfsparms->pownorm_min) && + /* 3. Test magnitude of power of lowest DFT frequency at current */ + /* max power direction and make sure it is not too big. */ + /* (Ex. Thresh==50000000) */ + (powers[0][powmax_dirs[wis[w]]] <= lfsparms->powmax_max)){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + /* Add 1 to wis[w] to create index to original dft_coefs[] */ + fprintf(logfp, + " Selected Wave = %d\n", wis[w]+1); + fprintf(logfp, + " 1. Power Magnitude (%12.3f > %12.3f)\n", + powmaxs[wis[w]], lfsparms->powmax_min); + fprintf(logfp, + " 2. Norm Power Magnitude (%9.3f > %9.3f)\n", + pownorms[wis[w]], lfsparms->pownorm_min); + fprintf(logfp, + " 3. Low Freq Wave Magnitude (%12.3f <= %12.3f)\n", + powers[0][powmax_dirs[wis[w]]], lfsparms->powmax_max); + fprintf(logfp, + " PASSED\n"); + fprintf(logfp, + " Selected Direction = %d\n", + powmax_dirs[wis[w]]); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* If ALL 3 criteria met, return current max power direction. */ + return(powmax_dirs[wis[w]]); + + } + } + + /* Otherwise test failed. */ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " 1. Power Magnitude ( > %12.3f)\n", + lfsparms->powmax_min); + fprintf(logfp, " 2. Norm Power Magnitude ( > %9.3f)\n", + lfsparms->pownorm_min); + fprintf(logfp, " 3. Low Freq Wave Magnitude ( <= %12.3f)\n", + lfsparms->powmax_max); + fprintf(logfp, " FAILED\n"); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + return(INVALID_DIR); +} + +/************************************************************************* +************************************************************************** +#cat: secondary_fork_test - Applies a secondary set of criteria for selecting +#cat: an IMAP integer direction from a set of DFT results +#cat: computed from a block of image data. This test +#cat: analyzes the strongest power statistics associated +#cat: with a given frequency and direction and analyses +#cat: small changes in direction to the left and right to +#cat: determine if the block contains a "fork". + + Input: + powers - DFT power computed from each (N) wave frequencies at each + rotation direction in the current image block + wis - sorted order of the highest N-1 frequency power statistics + powmaxs - maximum power for each of the highest N-1 frequencies + powmax_dirs - directions associated with each of the N-1 maximum powers + pownorms - normalized power for each of the highest N-1 frequencies + nstats - N-1 wave frequencies (where N is the length of dft_coefs) + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Zero or Positive - The selected IMAP integer direction + INVALID_DIR - IMAP Integer direction could not be determined +**************************************************************************/ +int secondary_fork_test(double **powers, const int *wis, + const double *powmaxs, const int *powmax_dirs, + const double *pownorms, const int nstats, + const LFSPARMS *lfsparms) +{ + int ldir, rdir; + double fork_pownorm_min, fork_pow_thresh; + +#ifdef LOG_REPORT +{ int firstpart = 0; /* Flag to determine if passed 1st part ... */ + fprintf(logfp, " Secondary\n"); +#endif + + /* Relax the normalized power threshold under fork conditions. */ + fork_pownorm_min = lfsparms->fork_pct_pownorm * lfsparms->pownorm_min; + + /* 1. Test magnitude of largest max power (Ex. Thresh==100000) */ + if((powmaxs[wis[0]] > lfsparms->powmax_min) && + /* 2. Test magnitude of corresponding normalized power */ + /* (Ex. Thresh==2.85) */ + (pownorms[wis[0]] >= fork_pownorm_min) && + /* 3. Test magnitude of power of lowest DFT frequency at largest */ + /* max power direction and make sure it is not too big. */ + /* (Ex. Thresh==50000000) */ + (powers[0][powmax_dirs[wis[0]]] <= lfsparms->powmax_max)){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + /* First part passed ... */ + firstpart = 1; + fprintf(logfp, + " Selected Wave = %d\n", wis[0]+1); + fprintf(logfp, + " 1. Power Magnitude (%12.3f > %12.3f)\n", + powmaxs[wis[0]], lfsparms->powmax_min); + fprintf(logfp, + " 2. Norm Power Magnitude (%9.3f >= %9.3f)\n", + pownorms[wis[0]], fork_pownorm_min); + fprintf(logfp, + " 3. Low Freq Wave Magnitude (%12.3f <= %12.3f)\n", + powers[0][powmax_dirs[wis[0]]], lfsparms->powmax_max); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Add FORK_INTERVALs to current direction modulo NDIRS */ + rdir = (powmax_dirs[wis[0]] + lfsparms->fork_interval) % + lfsparms->num_directions; + + /* Subtract FORK_INTERVALs from direction modulo NDIRS */ + /* For example, FORK_INTERVAL==2 & NDIRS==16, then */ + /* ldir = (dir - (16-2)) % 16 */ + /* which keeps result in proper modulo range. */ + ldir = (powmax_dirs[wis[0]] + lfsparms->num_directions - + lfsparms->fork_interval) % lfsparms->num_directions; + + print2log(" Left = %d, Current = %d, Right = %d\n", + ldir, powmax_dirs[wis[0]], rdir); + + /* Set forked angle threshold to be a % of the max directional */ + /* power. (Ex. thresh==0.7*powmax) */ + fork_pow_thresh = powmaxs[wis[0]] * lfsparms->fork_pct_powmax; + + /* Look up and test the computed power for the left and right */ + /* fork directions.s */ + /* The power stats (and thus wis) are on the range [0..nwaves-1) */ + /* as the statistics for the first DFT wave are not included. */ + /* The original power vectors exist for ALL DFT waves, therefore */ + /* wis indices must be added by 1 before addressing the original */ + /* powers vector. */ + /* LFS permits one and only one of the fork angles to exceed */ + /* the relative power threshold. */ + if(((powers[wis[0]+1][ldir] <= fork_pow_thresh) || + (powers[wis[0]+1][rdir] <= fork_pow_thresh)) && + ((powers[wis[0]+1][ldir] > fork_pow_thresh) || + (powers[wis[0]+1][rdir] > fork_pow_thresh))){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, + " 4. Left Power Magnitude (%12.3f > %12.3f)\n", + powers[wis[0]+1][ldir], fork_pow_thresh); + fprintf(logfp, + " 5. Right Power Magnitude (%12.3f > %12.3f)\n", + powers[wis[0]+1][rdir], fork_pow_thresh); + fprintf(logfp, " PASSED\n"); + fprintf(logfp, + " Selected Direction = %d\n", powmax_dirs[wis[0]]); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* If ALL the above criteria hold, then return the direction */ + /* of the largest max power. */ + return(powmax_dirs[wis[0]]); + } + } + + /* Otherwise test failed. */ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + if(!firstpart){ + fprintf(logfp, + " 1. Power Magnitude ( > %12.3f)\n", + lfsparms->powmax_min); + fprintf(logfp, + " 2. Norm Power Magnitude ( > %9.3f)\n", + fork_pownorm_min); + fprintf(logfp, + " 3. Low Freq Wave Magnitude ( <= %12.3f)\n", + lfsparms->powmax_max); + } + else{ + fprintf(logfp, " 4. Left Power Magnitude (%12.3f > %12.3f)\n", + powers[wis[0]+1][ldir], fork_pow_thresh); + fprintf(logfp, " 5. Right Power Magnitude (%12.3f > %12.3f)\n", + powers[wis[0]+1][rdir], fork_pow_thresh); + } + fprintf(logfp, " FAILED\n"); +} /* Close scope of firstpart */ +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + return(INVALID_DIR); +} + +/************************************************************************* +************************************************************************** +#cat: remove_incon_dirs - Takes a vector of integer directions and removes +#cat: individual directions that are too weak or inconsistent. +#cat: Directions are tested from the center of the IMAP working +#cat: outward in concentric squares, and the process resets to +#cat: the center and continues until no changes take place during +#cat: a complete pass. + + Input: + imap - vector of IMAP integer directions + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Output: + imap - vector of pruned input values +**************************************************************************/ +void remove_incon_dirs(int *imap, const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int cx, cy; + int *iptr; + int nremoved; + int lbox, rbox, tbox, bbox; + +#ifdef LOG_REPORT +{ int numpass = 0; + fprintf(logfp, "REMOVE MAP\n"); +#endif + + /* Compute center coords of IMAP */ + cx = mw>>1; + cy = mh>>1; + + /* Do pass, while directions have been removed in a pass ... */ + do{ + +#ifdef LOG_REPORT + /* Count number of complete passes through IMAP */ + ++numpass; + fprintf(logfp, " PASS = %d\n", numpass); +#endif + + /* Reinitialize number of removed directions to 0 */ + nremoved = 0; + + /* Start at center */ + iptr = imap + (cy * mw) + cx; + /* If valid IMAP direction and test for removal is true ... */ + if((*iptr != INVALID_DIR)&& + (remove_dir(imap, cx, cy, mw, mh, dir2rad, lfsparms))){ + + /* Set to INVALID */ + *iptr = INVALID_DIR; + /* Bump number of removed IMAP directions */ + nremoved++; + } + + /* Initialize side indices of concentric boxes */ + lbox = cx-1; + tbox = cy-1; + rbox = cx+1; + bbox = cy+1; + + /* Grow concentric boxes, until ALL edges of imap are exceeded */ + while((lbox >= 0) || (rbox < mw) || (tbox >= 0) || (bbox < mh)){ + + /* test top edge of box */ + if(tbox >= 0) + nremoved += test_top_edge(lbox, tbox, rbox, bbox, imap, mw, mh, + dir2rad, lfsparms); + + /* test right edge of box */ + if(rbox < mw) + nremoved += test_right_edge(lbox, tbox, rbox, bbox, imap, mw, mh, + dir2rad, lfsparms); + + /* test bottom edge of box */ + if(bbox < mh) + nremoved += test_bottom_edge(lbox, tbox, rbox, bbox, imap, mw, mh, + dir2rad, lfsparms); + + /* test left edge of box */ + if(lbox >=0) + nremoved += test_left_edge(lbox, tbox, rbox, bbox, imap, mw, mh, + dir2rad, lfsparms); + + /* Resize current box */ + lbox--; + tbox--; + rbox++; + bbox++; + } + }while(nremoved); + +#ifdef LOG_REPORT +} /* Close scope of numpass */ +#endif + +} + +/************************************************************************* +************************************************************************** +#cat: test_top_edge - Walks the top edge of a concentric square in the IMAP, +#cat: testing directions along the way to see if they should +#cat: be removed due to being too weak or inconsistent with +#cat: respect to their adjacent neighbors. + + Input: + lbox - left edge of current concentric square + tbox - top edge of current concentric square + rbox - right edge of current concentric square + bbox - bottom edge of current concentric square + imap - vector of IMAP integer directions + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Positive - direction should be removed from IMAP + Zero - direction should NOT be remove from IMAP +**************************************************************************/ +int test_top_edge(const int lbox, const int tbox, const int rbox, + const int bbox, int *imap, const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int bx, by, sx, ex; + int *iptr, *sptr, *eptr; + int nremoved; + + /* Initialize number of directions removed on edge to 0 */ + nremoved = 0; + + /* Set start pointer to top-leftmost point of box, or set it to */ + /* the leftmost point in the IMAP row (0), whichever is larger. */ + sx = max(lbox, 0); + sptr = imap + (tbox*mw) + sx; + + /* Set end pointer to either 1 point short of the top-rightmost */ + /* point of box, or set it to the rightmost point in the IMAP */ + /* row (lastx=mw-1), whichever is smaller. */ + ex = min(rbox-1, mw-1); + eptr = imap + (tbox*mw) + ex; + + /* For each point on box's edge ... */ + for(iptr = sptr, bx = sx, by = tbox; + iptr <= eptr; + iptr++, bx++){ + /* If valid IMAP direction and test for removal is true ... */ + if((*iptr != INVALID_DIR)&& + (remove_dir(imap, bx, by, mw, mh, dir2rad, lfsparms))){ + /* Set to INVALID */ + *iptr = INVALID_DIR; + /* Bump number of removed IMAP directions */ + nremoved++; + } + } + + /* Return the number of directions removed on edge */ + return(nremoved); +} + +/************************************************************************* +************************************************************************** +#cat: test_right_edge - Walks the right edge of a concentric square in the +#cat: IMAP, testing directions along the way to see if they +#cat: should be removed due to being too weak or inconsistent +#cat: with respect to their adjacent neighbors. + + Input: + lbox - left edge of current concentric square + tbox - top edge of current concentric square + rbox - right edge of current concentric square + bbox - bottom edge of current concentric square + imap - vector of IMAP integer directions + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Positive - direction should be removed from IMAP + Zero - direction should NOT be remove from IMAP +**************************************************************************/ +int test_right_edge(const int lbox, const int tbox, const int rbox, + const int bbox, int *imap, const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int bx, by, sy, ey; + int *iptr, *sptr, *eptr; + int nremoved; + + /* Initialize number of directions removed on edge to 0 */ + nremoved = 0; + + /* Set start pointer to top-rightmost point of box, or set it to */ + /* the topmost point in IMAP column (0), whichever is larger. */ + sy = max(tbox, 0); + sptr = imap + (sy*mw) + rbox; + + /* Set end pointer to either 1 point short of the bottom- */ + /* rightmost point of box, or set it to the bottommost point */ + /* in the IMAP column (lasty=mh-1), whichever is smaller. */ + ey = min(bbox-1,mh-1); + eptr = imap + (ey*mw) + rbox; + + /* For each point on box's edge ... */ + for(iptr = sptr, bx = rbox, by = sy; + iptr <= eptr; + iptr+=mw, by++){ + /* If valid IMAP direction and test for removal is true ... */ + if((*iptr != INVALID_DIR)&& + (remove_dir(imap, bx, by, mw, mh, dir2rad, lfsparms))){ + /* Set to INVALID */ + *iptr = INVALID_DIR; + /* Bump number of removed IMAP directions */ + nremoved++; + } + } + + /* Return the number of directions removed on edge */ + return(nremoved); +} + +/************************************************************************* +************************************************************************** +#cat: test_bottom_edge - Walks the bottom edge of a concentric square in the +#cat: IMAP, testing directions along the way to see if they +#cat: should be removed due to being too weak or inconsistent +#cat: with respect to their adjacent neighbors. + Input: + lbox - left edge of current concentric square + tbox - top edge of current concentric square + rbox - right edge of current concentric square + bbox - bottom edge of current concentric square + imap - vector of IMAP integer directions + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Positive - direction should be removed from IMAP + Zero - direction should NOT be remove from IMAP +**************************************************************************/ +int test_bottom_edge(const int lbox, const int tbox, const int rbox, + const int bbox, int *imap, const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int bx, by, sx, ex; + int *iptr, *sptr, *eptr; + int nremoved; + + /* Initialize number of directions removed on edge to 0 */ + nremoved = 0; + + /* Set start pointer to bottom-rightmost point of box, or set it to the */ + /* rightmost point in the IMAP ROW (lastx=mw-1), whichever is smaller. */ + sx = min(rbox, mw-1); + sptr = imap + (bbox*mw) + sx; + + /* Set end pointer to either 1 point short of the bottom- */ + /* lefttmost point of box, or set it to the leftmost point */ + /* in the IMAP row (x=0), whichever is larger. */ + ex = max(lbox-1, 0); + eptr = imap + (bbox*mw) + ex; + + /* For each point on box's edge ... */ + for(iptr = sptr, bx = sx, by = bbox; + iptr >= eptr; + iptr--, bx--){ + /* If valid IMAP direction and test for removal is true ... */ + if((*iptr != INVALID_DIR)&& + (remove_dir(imap, bx, by, mw, mh, dir2rad, lfsparms))){ + /* Set to INVALID */ + *iptr = INVALID_DIR; + /* Bump number of removed IMAP directions */ + nremoved++; + } + } + + /* Return the number of directions removed on edge */ + return(nremoved); +} + +/************************************************************************* +************************************************************************** +#cat: test_left_edge - Walks the left edge of a concentric square in the IMAP, +#cat: testing directions along the way to see if they should +#cat: be removed due to being too weak or inconsistent with +#cat: respect to their adjacent neighbors. + + Input: + lbox - left edge of current concentric square + tbox - top edge of current concentric square + rbox - right edge of current concentric square + bbox - bottom edge of current concentric square + imap - vector of IMAP integer directions + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Positive - direction should be removed from IMAP + Zero - direction should NOT be remove from IMAP +**************************************************************************/ +int test_left_edge(const int lbox, const int tbox, const int rbox, + const int bbox, int *imap, const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int bx, by, sy, ey; + int *iptr, *sptr, *eptr; + int nremoved; + + /* Initialize number of directions removed on edge to 0 */ + nremoved = 0; + + /* Set start pointer to bottom-leftmost point of box, or set it to */ + /* the bottommost point in IMAP column (lasty=mh-1), whichever */ + /* is smaller. */ + sy = min(bbox, mh-1); + sptr = imap + (sy*mw) + lbox; + + /* Set end pointer to either 1 point short of the top-leftmost */ + /* point of box, or set it to the topmost point in the IMAP */ + /* column (y=0), whichever is larger. */ + ey = max(tbox-1, 0); + eptr = imap + (ey*mw) + lbox; + + /* For each point on box's edge ... */ + for(iptr = sptr, bx = lbox, by = sy; + iptr >= eptr; + iptr-=mw, by--){ + /* If valid IMAP direction and test for removal is true ... */ + if((*iptr != INVALID_DIR)&& + (remove_dir(imap, bx, by, mw, mh, dir2rad, lfsparms))){ + /* Set to INVALID */ + *iptr = INVALID_DIR; + /* Bump number of removed IMAP directions */ + nremoved++; + } + } + + /* Return the number of directions removed on edge */ + return(nremoved); +} + +/************************************************************************* +************************************************************************** +#cat: remove_dir - Determines if an IMAP direction should be removed based +#cat: on analyzing its adjacent neighbors + + Input: + imap - vector of IMAP integer directions + mx - IMAP X-coord of the current direction being tested + my - IMPA Y-coord of the current direction being tested + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Positive - direction should be removed from IMAP + Zero - direction should NOT be remove from IMAP +**************************************************************************/ +int remove_dir(int *imap, const int mx, const int my, + const int mw, const int mh, const DIR2RAD *dir2rad, + const LFSPARMS *lfsparms) +{ + int avrdir, nvalid, dist; + double dir_strength; + + /* Compute average direction from neighbors, returning the */ + /* number of valid neighbors used in the computation, and */ + /* the "strength" of the average direction. */ + average_8nbr_dir(&avrdir, &dir_strength, &nvalid, imap, mx, my, mw, mh, + dir2rad); + + /* Conduct valid neighbor test (Ex. thresh==3) */ + if(nvalid < lfsparms->rmv_valid_nbr_min){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", + mx+(my*mw), mx, my); + fprintf(logfp, " Average NBR : %2d %6.3f %d\n", + avrdir, dir_strength, nvalid); + fprintf(logfp, " 1. Valid NBR (%d < %d)\n", + nvalid, lfsparms->rmv_valid_nbr_min); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + return(1); + } + + /* If stregnth of average neighbor direction is large enough to */ + /* put credence in ... (Ex. thresh==0.2) */ + if(dir_strength >= lfsparms->dir_strength_min){ + + /* Conduct direction distance test (Ex. thresh==3) */ + /* Compute minimum absolute distance between current and */ + /* average directions accounting for wrapping from 0 to NDIRS. */ + dist = abs(avrdir - *(imap+(my*mw)+mx)); + dist = min(dist, dir2rad->ndirs-dist); + if(dist > lfsparms->dir_distance_max){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", + mx+(my*mw), mx, my); + fprintf(logfp, " Average NBR : %2d %6.3f %d\n", + avrdir, dir_strength, nvalid); + fprintf(logfp, " 1. Valid NBR (%d < %d)\n", + nvalid, lfsparms->rmv_valid_nbr_min); + fprintf(logfp, " 2. Direction Strength (%6.3f >= %6.3f)\n", + dir_strength, lfsparms->dir_strength_min); + fprintf(logfp, " Current Dir = %d, Average Dir = %d\n", + *(imap+(my*mw)+mx), avrdir); + fprintf(logfp, " 3. Direction Distance (%d > %d)\n", + dist, lfsparms->dir_distance_max); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + return(2); + } + } + + /* Otherwise, the strength of the average direciton is not strong enough */ + /* to put credence in, so leave the current block's directon alone. */ + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: average_8nbr_dir - Given an IMAP direction, computes an average +#cat: direction from its adjacent 8 neighbors returning +#cat: the average direction, its strength, and the +#cat: number of valid direction in the neighborhood. + + Input: + imap - vector of IMAP integer directions + mx - IMAP X-coord of the current direction + my - IMPA Y-coord of the current direction + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + Output: + avrdir - the average direction computed from neighbors + dir_strenght - the strength of the average direction + nvalid - the number of valid directions used to compute the + average +**************************************************************************/ +void average_8nbr_dir(int *avrdir, double *dir_strength, int *nvalid, + int *imap, const int mx, const int my, + const int mw, const int mh, + const DIR2RAD *dir2rad) +{ + int *iptr; + int e,w,n,s; + double cospart, sinpart; + double pi2, pi_factor, theta; + double avr; + + /* Compute neighbor coordinates to current IMAP direction */ + e = mx+1; /* East */ + w = mx-1; /* West */ + n = my-1; /* North */ + s = my+1; /* South */ + + /* Intialize accumulators */ + *nvalid = 0; + cospart = 0.0; + sinpart = 0.0; + + /* 1. Test NW */ + /* If NW point within IMAP boudaries ... */ + if((w >= 0) && (n >= 0)){ + iptr = imap + (n*mw) + w; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 2. Test N */ + /* If N point within IMAP boudaries ... */ + if(n >= 0){ + iptr = imap + (n*mw) + mx; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 3. Test NE */ + /* If NE point within IMAP boudaries ... */ + if((e < mw) && (n >= 0)){ + iptr = imap + (n*mw) + e; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 4. Test E */ + /* If E point within IMAP boudaries ... */ + if(e < mw){ + iptr = imap + (my*mw) + e; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 5. Test SE */ + /* If SE point within IMAP boudaries ... */ + if((e < mw) && (s < mh)){ + iptr = imap + (s*mw) + e; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 6. Test S */ + /* If S point within IMAP boudaries ... */ + if(s < mh){ + iptr = imap + (s*mw) + mx; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 7. Test SW */ + /* If SW point within IMAP boudaries ... */ + if((w >= 0) && (s < mh)){ + iptr = imap + (s*mw) + w; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* 8. Test W */ + /* If W point within IMAP boudaries ... */ + if(w >= 0){ + iptr = imap + (my*mw) + w; + /* If valid direction ... */ + if(*iptr != INVALID_DIR){ + /* Accumulate cosine and sine components of the direction */ + cospart += dir2rad->cos[*iptr]; + sinpart += dir2rad->sin[*iptr]; + /* Bump number of accumulated directions */ + (*nvalid)++; + } + } + + /* If there were no neighbors found with valid direction ... */ + if(*nvalid == 0){ + /* Return INVALID direction. */ + *dir_strength = 0; + *avrdir = INVALID_DIR; + return; + } + + /* Compute averages of accumulated cosine and sine direction components */ + cospart /= (double)(*nvalid); + sinpart /= (double)(*nvalid); + + /* Compute directional strength as hypotenuse (without sqrt) of average */ + /* cosine and sine direction components. Believe this value will be on */ + /* the range of [0 .. 1]. */ + *dir_strength = (cospart * cospart) + (sinpart * sinpart); + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when comparing doubles. */ + *dir_strength = trunc_dbl_precision(*dir_strength, TRUNC_SCALE); + + /* If the direction strength is not sufficiently high ... */ + if(*dir_strength < DIR_STRENGTH_MIN){ + /* Return INVALID direction. */ + *dir_strength = 0; + *avrdir = INVALID_DIR; + return; + } + + /* Compute angle (in radians) from Arctan of avarage */ + /* cosine and sine direction components. I think this order */ + /* is necessary because 0 direction is vertical and positive */ + /* direction is clockwise. */ + theta = atan2(sinpart, cospart); + + /* Atan2 returns theta on range [-PI..PI]. Adjust theta so that */ + /* it is on the range [0..2PI]. */ + pi2 = 2*M_PI; + theta += pi2; + theta = fmod(theta, pi2); + + /* Pi_factor sets the period of the trig functions to NDIRS units in x. */ + /* For example, if NDIRS==16, then pi_factor = 2(PI/16) = .3926... */ + /* Dividing theta (in radians) by this factor ((1/pi_factor)==2.546...) */ + /* will produce directions on the range [0..NDIRS]. */ + pi_factor = pi2/(double)dir2rad->ndirs; /* 2(M_PI/ndirs) */ + + /* Round off the direction and return it as an average direction */ + /* for the neighborhood. */ + avr = theta / pi_factor; + /* Need to truncate precision so that answers are consistent */ + /* on different computer architectures when rounding doubles. */ + avr = trunc_dbl_precision(avr, TRUNC_SCALE); + *avrdir = sround(avr); + + /* Really do need to map values > NDIRS back onto [0..NDIRS) range. */ + *avrdir %= dir2rad->ndirs; +} + +/************************************************************************* +************************************************************************** +#cat: num_valid_8nbrs - Given a block in an IMAP, counts the number of +#cat: immediate neighbors that have a valid IMAP direction. + + Input: + imap - 2-D vector of directional ridge flows + mx - horizontal coord of current block in IMAP + my - vertical coord of current block in IMAP + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + Return Code: + Non-negative - the number of valid IMAP neighbors +**************************************************************************/ +int num_valid_8nbrs(int *imap, const int mx, const int my, + const int mw, const int mh) +{ + int e_ind, w_ind, n_ind, s_ind; + int nvalid; + + /* Initialize VALID IMAP counter to zero. */ + nvalid = 0; + + /* Compute neighbor coordinates to current IMAP direction */ + e_ind = mx+1; /* East index */ + w_ind = mx-1; /* West index */ + n_ind = my-1; /* North index */ + s_ind = my+1; /* South index */ + + /* 1. Test NW IMAP value. */ + /* If neighbor indices are within IMAP boundaries and it is VALID ... */ + if((w_ind >= 0) && (n_ind >= 0) && (*(imap + (n_ind*mw) + w_ind) >= 0)) + /* Bump VALID counter. */ + nvalid++; + + /* 2. Test N IMAP value. */ + if((n_ind >= 0) && (*(imap + (n_ind*mw) + mx) >= 0)) + nvalid++; + + /* 3. Test NE IMAP value. */ + if((n_ind >= 0) && (e_ind < mw) && (*(imap + (n_ind*mw) + e_ind) >= 0)) + nvalid++; + + /* 4. Test E IMAP value. */ + if((e_ind < mw) && (*(imap + (my*mw) + e_ind) >= 0)) + nvalid++; + + /* 5. Test SE IMAP value. */ + if((e_ind < mw) && (s_ind < mh) && (*(imap + (s_ind*mw) + e_ind) >= 0)) + nvalid++; + + /* 6. Test S IMAP value. */ + if((s_ind < mh) && (*(imap + (s_ind*mw) + mx) >= 0)) + nvalid++; + + /* 7. Test SW IMAP value. */ + if((w_ind >= 0) && (s_ind < mh) && (*(imap + (s_ind*mw) + w_ind) >= 0)) + nvalid++; + + /* 8. Test W IMAP value. */ + if((w_ind >= 0) && (*(imap + (my*mw) + w_ind) >= 0)) + nvalid++; + + /* Return number of neighbors with VALID IMAP values. */ + return(nvalid); +} + +/************************************************************************* +************************************************************************** +#cat: smooth_imap - Takes a vector of integer directions and smooths them +#cat: by analyzing the direction of adjacent neighbors. + + Input: + imap - vector of IMAP integer directions + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + dir2rad - lookup table for converting integer directions + lfsparms - parameters and thresholds for controlling LFS + Output: + imap - vector of smoothed input values +**************************************************************************/ +void smooth_imap(int *imap, const int mw, const int mh, + const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) +{ + int mx, my; + int *iptr; + int avrdir, nvalid; + double dir_strength; + + print2log("SMOOTH MAP\n"); + + iptr = imap; + for(my = 0; my < mh; my++){ + for(mx = 0; mx < mw; mx++){ + /* Compute average direction from neighbors, returning the */ + /* number of valid neighbors used in the computation, and */ + /* the "strength" of the average direction. */ + average_8nbr_dir(&avrdir, &dir_strength, &nvalid, + imap, mx, my, mw, mh, dir2rad); + + /* If average direction strength is strong enough */ + /* (Ex. thresh==0.2)... */ + if(dir_strength >= lfsparms->dir_strength_min){ + /* If IMAP direction is valid ... */ + if(*iptr != INVALID_DIR){ + /* Conduct valid neighbor test (Ex. thresh==3)... */ + if(nvalid >= lfsparms->rmv_valid_nbr_min){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", + mx+(my*mw), mx, my); + fprintf(logfp, " Average NBR : %2d %6.3f %d\n", + avrdir, dir_strength, nvalid); + fprintf(logfp, " 1. Valid NBR (%d >= %d)\n", + nvalid, lfsparms->rmv_valid_nbr_min); + fprintf(logfp, " Valid Direction = %d\n", *iptr); + fprintf(logfp, " Smoothed Direction = %d\n", avrdir); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Reassign valid IMAP direction with average direction. */ + *iptr = avrdir; + } + } + /* Otherwise IMAP direction is invalid ... */ + else{ + /* Even if IMAP value is invalid, if number of valid */ + /* neighbors is big enough (Ex. thresh==7)... */ + if(nvalid >= lfsparms->smth_valid_nbr_min){ + +#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", + mx+(my*mw), mx, my); + fprintf(logfp, " Average NBR : %2d %6.3f %d\n", + avrdir, dir_strength, nvalid); + fprintf(logfp, " 2. Invalid NBR (%d >= %d)\n", + nvalid, lfsparms->smth_valid_nbr_min); + fprintf(logfp, " Invalid Direction = %d\n", *iptr); + fprintf(logfp, " Smoothed Direction = %d\n", avrdir); +#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + + /* Assign invalid IMAP direction with average direction. */ + *iptr = avrdir; + } + } + } + + /* Bump to next IMAP direction. */ + iptr++; + } + } +} + +/************************************************************************* +************************************************************************** +#cat: vorticity - Measures the amount of cummulative curvature incurred +#cat: among the IMAP neighbors of the given block. + + Input: + imap - 2D vector of ridge flow directions + mx - horizontal coord of current IMAP block + my - vertical coord of current IMAP block + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + ndirs - number of possible directions in the IMAP + Return Code: + Non-negative - the measured vorticity among the neighbors +**************************************************************************/ +int vorticity(int *imap, const int mx, const int my, + const int mw, const int mh, const int ndirs) +{ + int e_ind, w_ind, n_ind, s_ind; + int nw_val, n_val, ne_val, e_val, se_val, s_val, sw_val, w_val; + int vmeasure; + + /* Compute neighbor coordinates to current IMAP direction */ + e_ind = mx+1; /* East index */ + w_ind = mx-1; /* West index */ + n_ind = my-1; /* North index */ + s_ind = my+1; /* South index */ + + /* 1. Get NW IMAP value. */ + /* If neighbor indices are within IMAP boundaries ... */ + if((w_ind >= 0) && (n_ind >= 0)) + /* Set neighbor value to IMAP value. */ + nw_val = *(imap + (n_ind*mw) + w_ind); + else + /* Otherwise, set the neighbor value to INVALID. */ + nw_val = INVALID_DIR; + + /* 2. Get N IMAP value. */ + if(n_ind >= 0) + n_val = *(imap + (n_ind*mw) + mx); + else + n_val = INVALID_DIR; + + /* 3. Get NE IMAP value. */ + if((n_ind >= 0) && (e_ind < mw)) + ne_val = *(imap + (n_ind*mw) + e_ind); + else + ne_val = INVALID_DIR; + + /* 4. Get E IMAP value. */ + if(e_ind < mw) + e_val = *(imap + (my*mw) + e_ind); + else + e_val = INVALID_DIR; + + /* 5. Get SE IMAP value. */ + if((e_ind < mw) && (s_ind < mh)) + se_val = *(imap + (s_ind*mw) + e_ind); + else + se_val = INVALID_DIR; + + /* 6. Get S IMAP value. */ + if(s_ind < mh) + s_val = *(imap + (s_ind*mw) + mx); + else + s_val = INVALID_DIR; + + /* 7. Get SW IMAP value. */ + if((w_ind >= 0) && (s_ind < mh)) + sw_val = *(imap + (s_ind*mw) + w_ind); + else + sw_val = INVALID_DIR; + + /* 8. Get W IMAP value. */ + if(w_ind >= 0) + w_val = *(imap + (my*mw) + w_ind); + else + w_val = INVALID_DIR; + + /* Now that we have all IMAP neighbors, accumulate vorticity between */ + /* the neighboring directions. */ + + /* Initialize vorticity accumulator to zero. */ + vmeasure = 0; + + /* 1. NW & N */ + accum_nbr_vorticity(&vmeasure, nw_val, n_val, ndirs); + + /* 2. N & NE */ + accum_nbr_vorticity(&vmeasure, n_val, ne_val, ndirs); + + /* 3. NE & E */ + accum_nbr_vorticity(&vmeasure, ne_val, e_val, ndirs); + + /* 4. E & SE */ + accum_nbr_vorticity(&vmeasure, e_val, se_val, ndirs); + + /* 5. SE & S */ + accum_nbr_vorticity(&vmeasure, se_val, s_val, ndirs); + + /* 6. S & SW */ + accum_nbr_vorticity(&vmeasure, s_val, sw_val, ndirs); + + /* 7. SW & W */ + accum_nbr_vorticity(&vmeasure, sw_val, w_val, ndirs); + + /* 8. W & NW */ + accum_nbr_vorticity(&vmeasure, w_val, nw_val, ndirs); + + /* Return the accumulated vorticity measure. */ + return(vmeasure); +} + +/************************************************************************* +************************************************************************** +#cat: accum_nbor_vorticity - Accumlates the amount of curvature measures +#cat: between neighboring IMAP blocks. + + Input: + dir1 - first neighbor's integer IMAP direction + dir2 - second neighbor's integer IMAP direction + ndirs - number of possible IMAP directions + Output: + vmeasure - accumulated vorticity among neighbors measured so far +**************************************************************************/ +void accum_nbr_vorticity(int *vmeasure, const int dir1, const int dir2, + const int ndirs) +{ + int dist; + + /* Measure difference in direction between a pair of neighboring */ + /* directions. */ + /* If both neighbors are not equal and both are VALID ... */ + if((dir1 != dir2) && (dir1 >= 0)&&(dir2 >= 0)){ + /* Measure the clockwise distance from the first to the second */ + /* directions. */ + dist = dir2 - dir1; + /* If dist is negative, then clockwise distance must wrap around */ + /* the high end of the direction range. For example: */ + /* dir1 = 8 */ + /* dir2 = 3 */ + /* and ndirs = 16 */ + /* 3 - 8 = -5 */ + /* so 16 - 5 = 11 (the clockwise distance from 8 to 3) */ + if(dist < 0) + dist += ndirs; + /* If the change in clockwise direction is larger than 90 degrees as */ + /* in total the total number of directions covers 180 degrees. */ + if(dist > (ndirs>>1)) + /* Decrement the vorticity measure. */ + (*vmeasure)--; + else + /* Otherwise, bump the vorticity measure. */ + (*vmeasure)++; + } + /* Otherwise both directions are either equal or */ + /* one or both directions are INVALID, so ignore. */ +} + +/************************************************************************* +************************************************************************** +#cat: curvature - Measures the largest change in direction between the +#cat: current IMAP direction and its immediate neighbors. + + Input: + imap - 2D vector of ridge flow directions + mx - horizontal coord of current IMAP block + my - vertical coord of current IMAP block + mw - width (in blocks) of the IMAP + mh - height (in blocks) of the IMAP + ndirs - number of possible directions in the IMAP + Return Code: + Non-negative - maximum change in direction found (curvature) + Negative - No valid neighbor found to measure change in direction +**************************************************************************/ +int curvature(int *imap, const int mx, const int my, + const int mw, const int mh, const int ndirs) +{ + int *iptr; + int e_ind, w_ind, n_ind, s_ind; + int nw_val, n_val, ne_val, e_val, se_val, s_val, sw_val, w_val; + int cmeasure, dist; + + /* Compute neighbor coordinates to current IMAP direction */ + e_ind = mx+1; /* East index */ + w_ind = mx-1; /* West index */ + n_ind = my-1; /* North index */ + s_ind = my+1; /* South index */ + + /* 1. Get NW IMAP value. */ + /* If neighbor indices are within IMAP boundaries ... */ + if((w_ind >= 0) && (n_ind >= 0)) + /* Set neighbor value to IMAP value. */ + nw_val = *(imap + (n_ind*mw) + w_ind); + else + /* Otherwise, set the neighbor value to INVALID. */ + nw_val = INVALID_DIR; + + /* 2. Get N IMAP value. */ + if(n_ind >= 0) + n_val = *(imap + (n_ind*mw) + mx); + else + n_val = INVALID_DIR; + + /* 3. Get NE IMAP value. */ + if((n_ind >= 0) && (e_ind < mw)) + ne_val = *(imap + (n_ind*mw) + e_ind); + else + ne_val = INVALID_DIR; + + /* 4. Get E IMAP value. */ + if(e_ind < mw) + e_val = *(imap + (my*mw) + e_ind); + else + e_val = INVALID_DIR; + + /* 5. Get SE IMAP value. */ + if((e_ind < mw) && (s_ind < mh)) + se_val = *(imap + (s_ind*mw) + e_ind); + else + se_val = INVALID_DIR; + + /* 6. Get S IMAP value. */ + if(s_ind < mh) + s_val = *(imap + (s_ind*mw) + mx); + else + s_val = INVALID_DIR; + + /* 7. Get SW IMAP value. */ + if((w_ind >= 0) && (s_ind < mh)) + sw_val = *(imap + (s_ind*mw) + w_ind); + else + sw_val = INVALID_DIR; + + /* 8. Get W IMAP value. */ + if(w_ind >= 0) + w_val = *(imap + (my*mw) + w_ind); + else + w_val = INVALID_DIR; + + /* Now that we have all IMAP neighbors, determine largest change in */ + /* direction from current block to each of its 8 VALID neighbors. */ + + /* Initialize pointer to current IMAP value. */ + iptr = imap + (my*mw) + mx; + + /* Initialize curvature measure to negative as closest_dir_dist() */ + /* always returns -1=INVALID or a positive value. */ + cmeasure = -1; + + /* 1. With NW */ + /* Compute closest distance between neighboring directions. */ + dist = closest_dir_dist(*iptr, nw_val, ndirs); + /* Keep track of maximum. */ + if(dist > cmeasure) + cmeasure = dist; + + /* 2. With N */ + dist = closest_dir_dist(*iptr, n_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* 3. With NE */ + dist = closest_dir_dist(*iptr, ne_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* 4. With E */ + dist = closest_dir_dist(*iptr, e_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* 5. With SE */ + dist = closest_dir_dist(*iptr, se_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* 6. With S */ + dist = closest_dir_dist(*iptr, s_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* 7. With SW */ + dist = closest_dir_dist(*iptr, sw_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* 8. With W */ + dist = closest_dir_dist(*iptr, w_val, ndirs); + if(dist > cmeasure) + cmeasure = dist; + + /* Return maximum difference between current block's IMAP direction */ + /* and the rest of its VALID neighbors. */ + return(cmeasure); +} --- libfprint-20081125git.orig/libfprint/nbis/mindtct/.svn/text-base/dft.c.svn-base +++ libfprint-20081125git/libfprint/nbis/mindtct/.svn/text-base/dft.c.svn-base @@ -0,0 +1,358 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: DFT.C + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for conducting Discrete Fourier + Transforms (DFT) analysis on a block of image data as part of + the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + dft_dir_powers() + sum_rot_block_rows() + dft_power() + dft_power_stats() + get_max_norm() + sort_dft_waves() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: sum_rot_block_rows - Computes a vector or pixel row sums by sampling +#cat: the current image block at a given orientation. The +#cat: sampling is conducted using a precomputed set of rotated +#cat: pixel offsets (called a grid) relative to the orgin of +#cat: the image block. + + Input: + blkptr - the pixel address of the origin of the current image block + grid_offsets - the rotated pixel offsets for a block-sized grid + rotated according to a specific orientation + blocksize - the width and height of the image block and thus the size + of the rotated grid + Output: + rowsums - the resulting vector of pixel row sums +**************************************************************************/ +static void sum_rot_block_rows(int *rowsums, const unsigned char *blkptr, + const int *grid_offsets, const int blocksize) +{ + int ix, iy, gi; + + /* Initialize rotation offset index. */ + gi = 0; + + /* For each row in block ... */ + for(iy = 0; iy < blocksize; iy++){ + /* The sums are accumlated along the rotated rows of the grid, */ + /* so initialize row sum to 0. */ + rowsums[iy] = 0; + /* Foreach column in block ... */ + for(ix = 0; ix < blocksize; ix++){ + /* Accumulate pixel value at rotated grid position in image */ + rowsums[iy] += *(blkptr + grid_offsets[gi]); + gi++; + } + } +} + +/************************************************************************* +************************************************************************** +#cat: dft_power - Computes the DFT power by applying a specific wave form +#cat: frequency to a vector of pixel row sums computed from a +#cat: specific orientation of the block image + + Input: + rowsums - accumulated rows of pixels from within a rotated grid + overlaying an input image block + wave - the wave form (cosine and sine components) at a specific + frequency + wavelen - the length of the wave form (must match the height of the + image block which is the length of the rowsum vector) + Output: + power - the computed DFT power for the given wave form at the + given orientation within the image block +**************************************************************************/ +static void dft_power(double *power, const int *rowsums, + const DFTWAVE *wave, const int wavelen) +{ + int i; + double cospart, sinpart; + + /* Initialize accumulators */ + cospart = 0.0; + sinpart = 0.0; + + /* Accumulate cos and sin components of DFT. */ + for(i = 0; i < wavelen; i++){ + /* Multiply each rotated row sum by its */ + /* corresponding cos or sin point in DFT wave. */ + cospart += (rowsums[i] * wave->cos[i]); + sinpart += (rowsums[i] * wave->sin[i]); + } + + /* Power is the sum of the squared cos and sin components */ + *power = (cospart * cospart) + (sinpart * sinpart); +} + +/************************************************************************* +************************************************************************** +#cat: dft_dir_powers - Conducts the DFT analysis on a block of image data. +#cat: The image block is sampled across a range of orientations +#cat: (directions) and multiple wave forms of varying frequency are +#cat: applied at each orientation. At each orentation, pixels are +#cat: accumulated along each rotated pixel row, creating a vector +#cat: of pixel row sums. Each DFT wave form is then applied +#cat: individually to this vector of pixel row sums. A DFT power +#cat: value is computed for each wave form (frequency0 at each +#cat: orientaion within the image block. Therefore, the resulting DFT +#cat: power vectors are of dimension (N Waves X M Directions). +#cat: The power signatures derived form this process are used to +#cat: determine dominant direction flow within the image block. + + Input: + pdata - the padded input image. It is important that the image + be properly padded, or else the sampling at various block + orientations may result in accessing unkown memory. + blkoffset - the pixel offset form the origin of the padded image to + the origin of the current block in the image + pw - the width (in pixels) of the padded input image + ph - the height (in pixels) of the padded input image + dftwaves - structure containing the DFT wave forms + dftgrids - structure containing the rotated pixel grid offsets + Output: + powers - DFT power computed from each wave form frequencies at each + orientation (direction) in the current image block + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int dft_dir_powers(double **powers, unsigned char *pdata, + const int blkoffset, const int pw, const int ph, + const DFTWAVES *dftwaves, const ROTGRIDS *dftgrids) +{ + int w, dir; + int *rowsums; + unsigned char *blkptr; + + /* Allocate line sum vector, and initialize to zeros */ + /* This routine requires square block (grid), so ERROR otherwise. */ + if(dftgrids->grid_w != dftgrids->grid_h){ + fprintf(stderr, "ERROR : dft_dir_powers : DFT grids must be square\n"); + return(-90); + } + rowsums = (int *)malloc(dftgrids->grid_w * sizeof(int)); + if(rowsums == (int *)NULL){ + fprintf(stderr, "ERROR : dft_dir_powers : malloc : rowsums\n"); + return(-91); + } + + /* Foreach direction ... */ + for(dir = 0; dir < dftgrids->ngrids; dir++){ + /* Compute vector of line sums from rotated grid */ + blkptr = pdata + blkoffset; + sum_rot_block_rows(rowsums, blkptr, + dftgrids->grids[dir], dftgrids->grid_w); + + /* Foreach DFT wave ... */ + for(w = 0; w < dftwaves->nwaves; w++){ + dft_power(&(powers[w][dir]), rowsums, + dftwaves->waves[w], dftwaves->wavelen); + } + } + + /* Deallocate working memory. */ + free(rowsums); + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: get_max_norm - Analyses a DFT power vector for a specific wave form +#cat: applied at different orientations (directions) to the +#cat: current image block. The routine retuns the maximum +#cat: power value in the vector, the direction at which the +#cat: maximum occurs, and a normalized power value. The +#cat: normalized power is computed as the maximum power divided +#cat: by the average power across all the directions. These +#cat: simple statistics are fundamental to the selection of +#cat: a dominant direction flow for the image block. + + Input: + power_vector - the DFT power values derived form a specific wave form + applied at different directions + ndirs - the number of directions to which the wave form was applied + Output: + powmax - the maximum power value in the DFT power vector + powmax_dir - the direciton at which the maximum power value occured + pownorm - the normalized power corresponding to the maximum power +**************************************************************************/ +static void get_max_norm(double *powmax, int *powmax_dir, + double *pownorm, const double *power_vector, const int ndirs) +{ + int dir; + double max_v, powsum; + int max_i; + double powmean; + + /* Find max power value and store corresponding direction */ + max_v = power_vector[0]; + max_i = 0; + + /* Sum the total power in a block at a given direction */ + powsum = power_vector[0]; + + /* For each direction ... */ + for(dir = 1; dir < ndirs; dir++){ + powsum += power_vector[dir]; + if(power_vector[dir] > max_v){ + max_v = power_vector[dir]; + max_i = dir; + } + } + + *powmax = max_v; + *powmax_dir = max_i; + + /* Powmean is used as denominator for pownorm, so setting */ + /* a non-zero minimum avoids possible division by zero. */ + powmean = max(powsum, MIN_POWER_SUM)/(double)ndirs; + + *pownorm = *powmax / powmean; +} + +/************************************************************************* +************************************************************************** +#cat: sort_dft_waves - Creates a ranked list of DFT wave form statistics +#cat: by sorting on the normalized squared maximum power. + + Input: + powmaxs - maximum DFT power for each wave form used to derive + statistics + pownorms - normalized maximum power corresponding to values in powmaxs + nstats - number of wave forms used to derive statistics (N Wave - 1) + Output: + wis - sorted list of indices corresponding to the ranked set of + wave form statistics. These indices will be used as + indirect addresses when processing the power statistics + in descending order of "dominance" + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +static int sort_dft_waves(int *wis, const double *powmaxs, const double *pownorms, + const int nstats) +{ + int i; + double *pownorms2; + + /* Allocate normalized power^2 array */ + pownorms2 = (double *)malloc(nstats * sizeof(double)); + if(pownorms2 == (double *)NULL){ + fprintf(stderr, "ERROR : sort_dft_waves : malloc : pownorms2\n"); + return(-100); + } + + for(i = 0; i < nstats; i++){ + /* Wis will hold the sorted statistic indices when all is done. */ + wis[i] = i; + /* This is normalized squared max power. */ + pownorms2[i] = powmaxs[i] * pownorms[i]; + } + + /* Sort the statistic indices on the normalized squared power. */ + bubble_sort_double_dec_2(pownorms2, wis, nstats); + + /* Deallocate the working memory. */ + free(pownorms2); + + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: dft_power_stats - Derives statistics from a set of DFT power vectors. +#cat: Statistics are computed for all but the lowest frequency +#cat: wave form, including the Maximum power for each wave form, +#cat: the direction at which the maximum power occured, and a +#cat: normalized value for the maximum power. In addition, the +#cat: statistics are ranked in descending order based on normalized +#cat: squared maximum power. These statistics are fundamental +#cat: to selecting a dominant direction flow for the current +#cat: input image block. + + Input: + powers - DFT power vectors (N Waves X M Directions) computed for + the current image block from which the values in the + statistics arrays are derived + fw - the beginning of the range of wave form indices from which + the statistcs are to derived + tw - the ending of the range of wave form indices from which + the statistcs are to derived (last index is tw-1) + ndirs - number of orientations (directions) at which the DFT + analysis was conducted + Output: + wis - list of ranked wave form indicies of the corresponding + statistics based on normalized squared maximum power. These + indices will be used as indirect addresses when processing + the power statistics in descending order of "dominance" + powmaxs - array holding the maximum DFT power for each wave form + (other than the lowest frequecy) + powmax_dirs - array to holding the direction corresponding to + each maximum power value in powmaxs + pownorms - array to holding the normalized maximum powers corresponding + to each value in powmaxs + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int dft_power_stats(int *wis, double *powmaxs, int *powmax_dirs, + double *pownorms, double **powers, + const int fw, const int tw, const int ndirs) +{ + int w, i; + int ret; /* return code */ + + for(w = fw, i = 0; w < tw; w++, i++){ + get_max_norm(&(powmaxs[i]), &(powmax_dirs[i]), + &(pownorms[i]), powers[w], ndirs); + } + + /* Get sorted order of applied DFT waves based on normalized power */ + if((ret = sort_dft_waves(wis, powmaxs, pownorms, tw-fw))) + return(ret); + + return(0); +} + --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/entries +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/entries @@ -0,0 +1,232 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/libfprint/nbis/bozorth3 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +bz_gbls.c +file + + + + +2009-01-13T22:22:21.000000Z +aa90802491d2bef900a27df15035c6f2 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +5014 + +bz_io.c +file + + + + +2009-01-13T22:22:21.000000Z +1faa417e8a3e1383eb74688e5c22bbdc +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +16940 + +bz_sort.c +file + + + + +2009-01-13T22:22:21.000000Z +9d3af356595fe2c893e5af90b1323bd3 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9584 + +bz_alloc.c +file + + + + +2009-01-13T22:22:21.000000Z +7d80979be280b0346c323409fed77c8b +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +4364 + +bozorth3.c +file + + + + +2009-01-13T22:22:21.000000Z +db74a7bd7b429f6e423755ff9ff5fe81 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +35689 + +bz_drvrs.c +file + + + + +2009-01-13T22:22:21.000000Z +1cae4575831bfe7c550d8281ef800c7b +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +6823 + --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/text-base/bz_drvrs.c.svn-base +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/text-base/bz_drvrs.c.svn-base @@ -0,0 +1,223 @@ +/****************************************************************************** + +This file is part of the Export Control subset of the United States NIST +Biometric Image Software (NBIS) distribution: + http://fingerprint.nist.gov/NBIS/index.html + +It is our understanding that this falls within ECCN 3D980, which covers +software associated with the development, production or use of certain +equipment controlled in accordance with U.S. concerns about crime control +practices in specific countries. + +Therefore, this file should not be exported, or made available on fileservers, +except as allowed by U.S. export control laws. + +Do not remove this notice. + +******************************************************************************/ + +/* NOTE: Despite the above notice (which I have not removed), this file is + * being legally distributed within libfprint; the U.S. Export Administration + * Regulations do not place export restrictions upon distribution of + * "publicly available technology and software", as stated in EAR section + * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per + * the definition in section 734.7(a)(1). + * + * For further information, see http://reactivated.net/fprint/US_export_control + */ + +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: FING - NIST Fingerprint Systems Utilities + + FILE: BZ_DRVRS.C + ALGORITHM: Allan S. Bozorth (FBI) + MODIFICATIONS: Michael D. Garris (NIST) + Stan Janet (NIST) + DATE: 09/21/2004 + + Contains driver routines responsible for kicking off matches + using the Bozorth3 fingerprint matching algorithm. + +*********************************************************************** + + ROUTINES: +#cat: bozorth_probe_init - creates the pairwise minutia comparison +#cat: table for the probe fingerprint +#cat: bozorth_gallery_init - creates the pairwise minutia comparison +#cat: table for the gallery fingerprint +#cat: bozorth_to_gallery - supports the matching scenario where the +#cat: same probe fingerprint is matches repeatedly +#cat: to multiple gallery fingerprints as in +#cat: identification mode +#cat: bozorth_main - supports the matching scenario where a +#cat: single probe fingerprint is to be matched +#cat: to a single gallery fingerprint as in +#cat: verificaiton mode + +***********************************************************************/ + +#include +#include +#include +#include + +/**************************************************************************/ + +int bozorth_probe_init( struct xyt_struct * pstruct ) +{ +int sim; /* number of pointwise comparisons for Subject's record*/ +int msim; /* Pruned length of Subject's comparison pointer list */ + + + +/* Take Subject's points and compute pointwise comparison statistics table and sorted row-pointer list. */ +/* This builds a "Web" of relative edge statistics between points. */ +bz_comp( + pstruct->nrows, + pstruct->xcol, + pstruct->ycol, + pstruct->thetacol, + &sim, + scols, + scolpt ); + +msim = sim; /* Init search to end of Subject's pointwise comparison table (last edge in Web) */ + + + +bz_find( &msim, scolpt ); + + + +if ( msim < FDD ) /* Makes sure there are a reasonable number of edges (at least 500, if possible) to analyze in the Web */ + msim = ( sim > FDD ) ? FDD : sim; + + + + + +return msim; +} + +/**************************************************************************/ + +int bozorth_gallery_init( struct xyt_struct * gstruct ) +{ +int fim; /* number of pointwise comparisons for On-File record*/ +int mfim; /* Pruned length of On-File Record's pointer list */ + + +/* Take On-File Record's points and compute pointwise comparison statistics table and sorted row-pointer list. */ +/* This builds a "Web" of relative edge statistics between points. */ +bz_comp( + gstruct->nrows, + gstruct->xcol, + gstruct->ycol, + gstruct->thetacol, + &fim, + fcols, + fcolpt ); + +mfim = fim; /* Init search to end of On-File Record's pointwise comparison table (last edge in Web) */ + + + +bz_find( &mfim, fcolpt ); + + + +if ( mfim < FDD ) /* Makes sure there are a reasonable number of edges (at least 500, if possible) to analyze in the Web */ + mfim = ( fim > FDD ) ? FDD : fim; + + + + + +return mfim; +} + +/**************************************************************************/ + +int bozorth_to_gallery( + int probe_len, + struct xyt_struct * pstruct, + struct xyt_struct * gstruct + ) +{ +int np; +int gallery_len; + +gallery_len = bozorth_gallery_init( gstruct ); +np = bz_match( probe_len, gallery_len ); +return bz_match_score( np, pstruct, gstruct ); +} + +/**************************************************************************/ + +int bozorth_main( + struct xyt_struct * pstruct, + struct xyt_struct * gstruct + ) +{ +int ms; +int np; +int probe_len; +int gallery_len; + + + +#ifdef DEBUG + printf( "PROBE_INIT() called\n" ); +#endif +probe_len = bozorth_probe_init( pstruct ); + + +#ifdef DEBUG + printf( "GALLERY_INIT() called\n" ); +#endif +gallery_len = bozorth_gallery_init( gstruct ); + + +#ifdef DEBUG + printf( "BZ_MATCH() called\n" ); +#endif +np = bz_match( probe_len, gallery_len ); + + +#ifdef DEBUG + printf( "BZ_MATCH() returned %d edge pairs\n", np ); + printf( "COMPUTE() called\n" ); +#endif +ms = bz_match_score( np, pstruct, gstruct ); + + +#ifdef DEBUG + printf( "COMPUTE() returned %d\n", ms ); +#endif + + +return ms; +} --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/text-base/bz_sort.c.svn-base +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/text-base/bz_sort.c.svn-base @@ -0,0 +1,315 @@ +/****************************************************************************** + +This file is part of the Export Control subset of the United States NIST +Biometric Image Software (NBIS) distribution: + http://fingerprint.nist.gov/NBIS/index.html + +It is our understanding that this falls within ECCN 3D980, which covers +software associated with the development, production or use of certain +equipment controlled in accordance with U.S. concerns about crime control +practices in specific countries. + +Therefore, this file should not be exported, or made available on fileservers, +except as allowed by U.S. export control laws. + +Do not remove this notice. + +******************************************************************************/ + +/* NOTE: Despite the above notice (which I have not removed), this file is + * being legally distributed within libfprint; the U.S. Export Administration + * Regulations do not place export restrictions upon distribution of + * "publicly available technology and software", as stated in EAR section + * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per + * the definition in section 734.7(a)(1). + * + * For further information, see http://reactivated.net/fprint/US_export_control + */ + +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: FING - NIST Fingerprint Systems Utilities + + FILE: BZ_SORT.C + ALGORITHM: Allan S. Bozorth (FBI) + MODIFICATIONS: Michael D. Garris (NIST) + Stan Janet (NIST) + DATE: 09/21/2004 + + Contains sorting routines responsible for supporting the + Bozorth3 fingerprint matching algorithm. + +*********************************************************************** + + ROUTINES: +#cat: sort_quality_decreasing - comparison function passed to stdlib +#cat: qsort() used to sort minutia qualities +#cat: sort_x_y - comparison function passed to stdlib qsort() used +#cat: to sort minutia coordinates increasing first on x +#cat: then on y +#cat: sort_order_decreasing - calls a custom quicksort that sorts +#cat: a list of integers in decreasing order + +***********************************************************************/ + +#include +#include + +/* These are now externally defined in bozorth.h */ +/* extern char * get_progname( void ); */ + +/***********************************************************************/ +int sort_quality_decreasing( const void * a, const void * b ) +{ +struct minutiae_struct * af; +struct minutiae_struct * bf; + +af = (struct minutiae_struct *) a; +bf = (struct minutiae_struct *) b; + +if ( af->col[3] > bf->col[3] ) + return -1; +if ( af->col[3] < bf->col[3] ) + return 1; +return 0; +} + +/***********************************************************************/ +int sort_x_y( const void * a, const void * b ) +{ +struct minutiae_struct * af; +struct minutiae_struct * bf; + +af = (struct minutiae_struct *) a; +bf = (struct minutiae_struct *) b; + +if ( af->col[0] < bf->col[0] ) + return -1; +if ( af->col[0] > bf->col[0] ) + return 1; + +if ( af->col[1] < bf->col[1] ) + return -1; +if ( af->col[1] > bf->col[1] ) + return 1; + +return 0; +} + +/******************************************************** +qsort_decreasing() - quicksort an array of integers in decreasing + order [based on multisort.c, by Michael Garris + and Ted Zwiesler, 1986] +********************************************************/ +/* Used by custom quicksort code below */ +static int stack[BZ_STACKSIZE]; +static int * stack_pointer = stack; + +/***********************************************************************/ +/* return values: 0 == successful, 1 == error */ +static int popstack( int *popval ) +{ +if ( --stack_pointer < stack ) { + fprintf( stderr, "%s: ERROR: popstack(): stack underflow\n", get_progname() ); + return 1; +} + +*popval = *stack_pointer; +return 0; +} + +/***********************************************************************/ +/* return values: 0 == successful, 1 == error */ +static int pushstack( int position ) +{ +*stack_pointer++ = position; +if ( stack_pointer > ( stack + BZ_STACKSIZE ) ) { + fprintf( stderr, "%s: ERROR: pushstack(): stack overflow\n", get_progname() ); + return 1; +} +return 0; +} + +/***********************************************************************/ +/******************************************************************* +select_pivot() +selects a pivot from a list being sorted using the Singleton Method. +*******************************************************************/ +static int select_pivot( struct cell v[], int left, int right ) +{ +int midpoint; + + +midpoint = ( left + right ) / 2; +if ( v[left].index <= v[midpoint].index ) { + if ( v[midpoint].index <= v[right].index ) { + return midpoint; + } else { + if ( v[right].index > v[left].index ) { + return right; + } else { + return left; + } + } +} else { + if ( v[left].index < v[right].index ) { + return left; + } else { + if ( v[right].index < v[midpoint].index ) { + return midpoint; + } else { + return right; + } + } +} +} + +/***********************************************************************/ +/******************************************************** +partition_dec() +Inputs a pivot element making comparisons and swaps with other elements in a list, +until pivot resides at its correct position in the list. +********************************************************/ +static void partition_dec( struct cell v[], int *llen, int *rlen, int *ll, int *lr, int *rl, int *rr, int p, int l, int r ) +{ +#define iswap(a,b) { int itmp = (a); a = (b); b = itmp; } + +*ll = l; +*rr = r; +while ( 1 ) { + if ( l < p ) { + if ( v[l].index < v[p].index ) { + iswap( v[l].index, v[p].index ) + iswap( v[l].item, v[p].item ) + p = l; + } else { + l++; + } + } else { + if ( r > p ) { + if ( v[r].index > v[p].index ) { + iswap( v[r].index, v[p].index ) + iswap( v[r].item, v[p].item ) + p = r; + l++; + } else { + r--; + } + } else { + *lr = p - 1; + *rl = p + 1; + *llen = *lr - *ll + 1; + *rlen = *rr - *rl + 1; + break; + } + } +} +} + +/***********************************************************************/ +/******************************************************** +qsort_decreasing() +This procedure inputs a pointer to an index_struct, the subscript of an index array to be +sorted, a left subscript pointing to where the sort is to begin in the index array, and a right +subscript where to end. This module invokes a decreasing quick-sort sorting the index array from l to r. +********************************************************/ +/* return values: 0 == successful, 1 == error */ +static int qsort_decreasing( struct cell v[], int left, int right ) +{ +int pivot; +int llen, rlen; +int lleft, lright, rleft, rright; + + +if ( pushstack( left )) + return 1; +if ( pushstack( right )) + return 2; +while ( stack_pointer != stack ) { + if (popstack(&right)) + return 3; + if (popstack(&left )) + return 4; + if ( right - left > 0 ) { + pivot = select_pivot( v, left, right ); + partition_dec( v, &llen, &rlen, &lleft, &lright, &rleft, &rright, pivot, left, right ); + if ( llen > rlen ) { + if ( pushstack( lleft )) + return 5; + if ( pushstack( lright )) + return 6; + if ( pushstack( rleft )) + return 7; + if ( pushstack( rright )) + return 8; + } else{ + if ( pushstack( rleft )) + return 9; + if ( pushstack( rright )) + return 10; + if ( pushstack( lleft )) + return 11; + if ( pushstack( lright )) + return 12; + } + } +} +return 0; +} + +/***********************************************************************/ +/* return values: 0 == successful, 1 == error */ +int sort_order_decreasing( + int values[], /* INPUT: the unsorted values themselves */ + int num, /* INPUT: the number of values */ + int order[] /* OUTPUT: the order for each of the values if sorted */ + ) +{ +int i; +struct cell * cells; + + +cells = (struct cell *) malloc( num * sizeof(struct cell) ); +if ( cells == (struct cell *) NULL ){ + fprintf( stderr, "%s: ERROR: malloc(): struct cell\n", get_progname() ); + return 1; +} + +for( i = 0; i < num; i++ ) { + cells[i].index = values[i]; + cells[i].item = i; +} + +if ( qsort_decreasing( cells, 0, num-1 ) < 0) + return 2; + +for( i = 0; i < num; i++ ) { + order[i] = cells[i].item; +} + +free( (void *) cells ); + +return 0; +} --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/text-base/bz_gbls.c.svn-base +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/text-base/bz_gbls.c.svn-base @@ -0,0 +1,113 @@ +/****************************************************************************** + +This file is part of the Export Control subset of the United States NIST +Biometric Image Software (NBIS) distribution: + http://fingerprint.nist.gov/NBIS/index.html + +It is our understanding that this falls within ECCN 3D980, which covers +software associated with the development, production or use of certain +equipment controlled in accordance with U.S. concerns about crime control +practices in specific countries. + +Therefore, this file should not be exported, or made available on fileservers, +except as allowed by U.S. export control laws. + +Do not remove this notice. + +******************************************************************************/ + +/* NOTE: Despite the above notice (which I have not removed), this file is + * being legally distributed within libfprint; the U.S. Export Administration + * Regulations do not place export restrictions upon distribution of + * "publicly available technology and software", as stated in EAR section + * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per + * the definition in section 734.7(a)(1). + * + * For further information, see http://reactivated.net/fprint/US_export_control + */ + +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: FING - NIST Fingerprint Systems Utilities + + FILE: BZ_GBLS.C + ALGORITHM: Allan S. Bozorth (FBI) + MODIFICATIONS: Michael D. Garris (NIST) + Stan Janet (NIST) + DATE: 09/21/2004 + + Contains global variables responsible for supporting the + Bozorth3 fingerprint matching "core" algorithm. + +*********************************************************************** +***********************************************************************/ + +#include + +/**************************************************************************/ +/* General supporting global variables */ +/**************************************************************************/ + +int colp[ COLP_SIZE_1 ][ COLP_SIZE_2 ]; /* Output from match(), this is a sorted table of compatible edge pairs containing: */ + /* DeltaThetaKJs, Subject's K, J, then On-File's {K,J} or {J,K} depending */ + /* Sorted first on Subject's point index K, */ + /* then On-File's K or J point index (depending), */ + /* lastly on Subject's J point index */ +int scols[ SCOLS_SIZE_1 ][ COLS_SIZE_2 ]; /* Subject's pointwise comparison table containing: */ + /* Distance,min(BetaK,BetaJ),max(BetaK,BbetaJ), K,J,ThetaKJ */ +int fcols[ FCOLS_SIZE_1 ][ COLS_SIZE_2 ]; /* On-File Record's pointwise comparison table with: */ + /* Distance,min(BetaK,BetaJ),max(BetaK,BbetaJ),K,J, ThetaKJ */ +int * scolpt[ SCOLPT_SIZE ]; /* Subject's list of pointers to pointwise comparison rows, sorted on: */ + /* Distance, min(BetaK,BetaJ), then max(BetaK,BetaJ) */ +int * fcolpt[ FCOLPT_SIZE ]; /* On-File Record's list of pointers to pointwise comparison rows sorted on: */ + /* Distance, min(BetaK,BetaJ), then max(BetaK,BetaJ) */ +int sc[ SC_SIZE ]; /* Flags all compatible edges in the Subject's Web */ + +int yl[ YL_SIZE_1 ][ YL_SIZE_2 ]; + + +/**************************************************************************/ +/* Globals used significantly by sift() */ +/**************************************************************************/ +int rq[ RQ_SIZE ] = {}; +int tq[ TQ_SIZE ] = {}; +int zz[ ZZ_SIZE ] = {}; + +int rx[ RX_SIZE ] = {}; +int mm[ MM_SIZE ] = {}; +int nn[ NN_SIZE ] = {}; + +int qq[ QQ_SIZE ] = {}; + +int rk[ RK_SIZE ] = {}; + +int cp[ CP_SIZE ] = {}; +int rp[ RP_SIZE ] = {}; + +int rf[RF_SIZE_1][RF_SIZE_2] = {}; +int cf[CF_SIZE_1][CF_SIZE_2] = {}; + +int y[20000] = {}; + --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/text-base/bz_alloc.c.svn-base +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/text-base/bz_alloc.c.svn-base @@ -0,0 +1,119 @@ +/****************************************************************************** + +This file is part of the Export Control subset of the United States NIST +Biometric Image Software (NBIS) distribution: + http://fingerprint.nist.gov/NBIS/index.html + +It is our understanding that this falls within ECCN 3D980, which covers +software associated with the development, production or use of certain +equipment controlled in accordance with U.S. concerns about crime control +practices in specific countries. + +Therefore, this file should not be exported, or made available on fileservers, +except as allowed by U.S. export control laws. + +Do not remove this notice. + +******************************************************************************/ + +/* NOTE: Despite the above notice (which I have not removed), this file is + * being legally distributed within libfprint; the U.S. Export Administration + * Regulations do not place export restrictions upon distribution of + * "publicly available technology and software", as stated in EAR section + * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per + * the definition in section 734.7(a)(1). + * + * For further information, see http://reactivated.net/fprint/US_export_control + */ + +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: FING - NIST Fingerprint Systems Utilities + + FILE: BZ_ALLOC.C + ALGORITHM: Allan S. Bozorth (FBI) + MODIFICATIONS: Michael D. Garris (NIST) + Stan Janet (NIST) + DATE: 09/21/2004 + + Contains routines responsible for supporting the + Bozorth3 fingerprint matching algorithm. + +*********************************************************************** + + ROUTINES: +#cat: malloc_or_exit - allocates a buffer of bytes from the heap of +#cat: specified length exiting directly upon system error +#cat: malloc_or_return_error - allocates a buffer of bytes from the heap +#cat: of specified length returning an error code upon system error + +***********************************************************************/ + +#include +#include +#include + + +/***********************************************************************/ +char * malloc_or_exit( int nbytes, const char * what ) +{ +char * p; + +/* These are now externally defined in bozorth.h */ +/* extern FILE * stderr; */ +/* extern char * get_progname( void ); */ + + +p = malloc( (size_t) nbytes ); +if ( p == CNULL ) { + fprintf( stderr, "%s: ERROR: malloc() of %d bytes for %s failed: %s\n", + get_progname(), + nbytes, + what, + strerror( errno ) + ); + exit(1); +} +return p; +} + +/***********************************************************************/ +/* returns CNULL on error */ +char * malloc_or_return_error( int nbytes, const char * what ) +{ +char * p; + +p = malloc( (size_t) nbytes ); +if ( p == CNULL ) { + fprintf( stderr, "%s: ERROR: malloc() of %d bytes for %s failed: %s\n", + get_progname(), + nbytes, + what, + strerror( errno ) + ); + return(CNULL); +} +return p; +} --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/text-base/bozorth3.c.svn-base +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/text-base/bozorth3.c.svn-base @@ -0,0 +1,1785 @@ +/****************************************************************************** + +This file is part of the Export Control subset of the United States NIST +Biometric Image Software (NBIS) distribution: + http://fingerprint.nist.gov/NBIS/index.html + +It is our understanding that this falls within ECCN 3D980, which covers +software associated with the development, production or use of certain +equipment controlled in accordance with U.S. concerns about crime control +practices in specific countries. + +Therefore, this file should not be exported, or made available on fileservers, +except as allowed by U.S. export control laws. + +Do not remove this notice. + +******************************************************************************/ + +/* NOTE: Despite the above notice (which I have not removed), this file is + * being legally distributed within libfprint; the U.S. Export Administration + * Regulations do not place export restrictions upon distribution of + * "publicly available technology and software", as stated in EAR section + * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per + * the definition in section 734.7(a)(1). + * + * For further information, see http://reactivated.net/fprint/US_export_control + */ + +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: FING - NIST Fingerprint Systems Utilities + + FILE: BOZORTH3.C + ALGORITHM: Allan S. Bozorth (FBI) + MODIFICATIONS: Michael D. Garris (NIST) + Stan Janet (NIST) + DATE: 09/21/2004 + + Contains the "core" routines responsible for supporting the + Bozorth3 fingerprint matching algorithm. + +*********************************************************************** + + ROUTINES: +#cat: bz_comp - takes a set of minutiae (probe or gallery) and +#cat: compares/measures each minutia's {x,y,t} with every +#cat: other minutia's {x,y,t} in the set creating a table +#cat: of pairwise comparison entries +#cat: bz_find - trims sorted table of pairwise minutia comparisons to +#cat: a max distance of 75^2 +#cat: bz_match - takes the two pairwise minutia comparison tables (a probe +#cat: table and a gallery table) and compiles a list of +#cat: all relatively "compatible" entries between the two +#cat: tables generating a match table +#cat: bz_match_score - takes a match table and traverses it looking for +#cat: a sufficiently long path (or a cluster of compatible paths) +#cat: of "linked" match table entries +#cat: the accumulation of which results in a match "score" +#cat: bz_sift - main routine handling the path linking and match table +#cat: traversal +#cat: bz_final_loop - (declared static) a final postprocess after +#cat: the main match table traversal which looks to combine +#cat: clusters of compatible paths + +***********************************************************************/ + +#include +#include + +static const int verbose_bozorth = 0; +static const int m1_xyt = 0; + +/***********************************************************************/ +void bz_comp( + int npoints, /* INPUT: # of points */ + int xcol[ MAX_BOZORTH_MINUTIAE ], /* INPUT: x cordinates */ + int ycol[ MAX_BOZORTH_MINUTIAE ], /* INPUT: y cordinates */ + int thetacol[ MAX_BOZORTH_MINUTIAE ], /* INPUT: theta values */ + + int * ncomparisons, /* OUTPUT: number of pointwise comparisons */ + int cols[][ COLS_SIZE_2 ], /* OUTPUT: pointwise comparison table */ + int * colptrs[] /* INPUT and OUTPUT: sorted list of pointers to rows in cols[] */ + ) +{ +int i, j, k; + +int b; +int t; +int n; +int l; + +int table_index; + +int dx; +int dy; +int distance; + +int theta_kj; +int beta_j; +int beta_k; + +int * c; + + + +c = &cols[0][0]; + +table_index = 0; +for ( k = 0; k < npoints - 1; k++ ) { + for ( j = k + 1; j < npoints; j++ ) { + + + if ( thetacol[j] > 0 ) { + + if ( thetacol[k] == thetacol[j] - 180 ) + continue; + } else { + + if ( thetacol[k] == thetacol[j] + 180 ) + continue; + } + + + dx = xcol[j] - xcol[k]; + dy = ycol[j] - ycol[k]; + distance = SQUARED(dx) + SQUARED(dy); + if ( distance > SQUARED(DM) ) { + if ( dx > DM ) + break; + else + continue; + + } + + /* The distance is in the range [ 0, 125^2 ] */ + if ( dx == 0 ) + theta_kj = 90; + else { + double dz; + + if ( m1_xyt ) + dz = ( 180.0F / PI_SINGLE ) * atanf( (float) -dy / (float) dx ); + else + dz = ( 180.0F / PI_SINGLE ) * atanf( (float) dy / (float) dx ); + if ( dz < 0.0F ) + dz -= 0.5F; + else + dz += 0.5F; + theta_kj = (int) dz; + } + + + beta_k = theta_kj - thetacol[k]; + beta_k = IANGLE180(beta_k); + + beta_j = theta_kj - thetacol[j] + 180; + beta_j = IANGLE180(beta_j); + + + if ( beta_k < beta_j ) { + *c++ = distance; + *c++ = beta_k; + *c++ = beta_j; + *c++ = k+1; + *c++ = j+1; + *c++ = theta_kj; + } else { + *c++ = distance; + *c++ = beta_j; + *c++ = beta_k; + *c++ = k+1; + *c++ = j+1; + *c++ = theta_kj + 400; + + } + + + + + + + b = 0; + t = table_index + 1; + l = 1; + n = -1; /* Init binary search state ... */ + + + + + while ( t - b > 1 ) { + int * midpoint; + + l = ( b + t ) / 2; + midpoint = colptrs[l-1]; + + + + + for ( i=0; i < 3; i++ ) { + int dd, ff; + + dd = cols[table_index][i]; + + ff = midpoint[i]; + + + n = SENSE(dd,ff); + + + if ( n < 0 ) { + t = l; + break; + } + if ( n > 0 ) { + b = l; + break; + } + } + + if ( n == 0 ) { + n = 1; + b = l; + } + } /* END while */ + + if ( n == 1 ) + ++l; + + + + + for ( i = table_index; i >= l; --i ) + colptrs[i] = colptrs[i-1]; + + + colptrs[l-1] = &cols[table_index][0]; + ++table_index; + + + if ( table_index == 19999 ) { +#ifndef NOVERBOSE + if ( verbose_bozorth ) + printf( "bz_comp(): breaking loop to avoid table overflow\n" ); +#endif + goto COMP_END; + } + + } /* END for j */ + +} /* END for k */ + +COMP_END: + *ncomparisons = table_index; + +} + +/***********************************************************************/ +void bz_find( + int * xlim, /* INPUT: number of pointwise comparisons in table */ + /* OUTPUT: determined insertion location (NOT ALWAYS SET) */ + int * colpt[] /* INOUT: sorted list of pointers to rows in the pointwise comparison table */ + ) +{ +int midpoint; +int top; +int bottom; +int state; +int distance; + + + +/* binary search to locate the insertion location of a predefined distance in list of sorted distances */ + + +bottom = 0; +top = *xlim + 1; +midpoint = 1; +state = -1; + +while ( top - bottom > 1 ) { + midpoint = ( bottom + top ) / 2; + distance = *colpt[ midpoint-1 ]; + state = SENSE_NEG_POS(FD,distance); + if ( state < 0 ) + top = midpoint; + else { + bottom = midpoint; + } +} + +if ( state > -1 ) + ++midpoint; + +if ( midpoint < *xlim ) + *xlim = midpoint; + + + +} + +/***********************************************************************/ +/* Make room in RTP list at insertion point by shifting contents down the + list. Then insert the address of the current ROT row into desired + location */ +/***********************************************************************/ +static + +void rtp_insert( int * rtp[], int l, int idx, int * ptr ) +{ +int shiftcount; +int ** r1; +int ** r2; + + +r1 = &rtp[idx]; +r2 = r1 - 1; + +shiftcount = ( idx - l ) + 1; +while ( shiftcount-- > 0 ) { + *r1-- = *r2--; +} +*r1 = ptr; +} + +/***********************************************************************/ +/* Builds list of compatible edge pairs between the 2 Webs. */ +/* The Edge pair DeltaThetaKJs and endpoints are sorted */ +/* first on Subject's K, */ +/* then On-File's J or K (depending), */ +/* and lastly on Subject's J point index. */ +/* Return value is the # of compatible edge pairs */ +/***********************************************************************/ +int bz_match( + int probe_ptrlist_len, /* INPUT: pruned length of Subject's pointer list */ + int gallery_ptrlist_len /* INPUT: pruned length of On-File Record's pointer list */ + ) +{ +int i; /* Temp index */ +int ii; /* Temp index */ +int edge_pair_index; /* Compatible edge pair index */ +float dz; /* Delta difference and delta angle stats */ +float fi; /* Distance limit based on factor TK */ +int * ss; /* Subject's comparison stats row */ +int * ff; /* On-File Record's comparison stats row */ +int j; /* On-File Record's row index */ +int k; /* Subject's row index */ +int st; /* Starting On-File Record's row index */ +int p1; /* Adjusted Subject's ThetaKJ, DeltaThetaKJs, K or J point index */ +int p2; /* Adjusted On-File's ThetaKJ, RTP point index */ +int n; /* ThetaKJ and binary search state variable */ +int l; /* Midpoint of binary search */ +int b; /* ThetaKJ state variable, and bottom of search range */ +int t; /* Top of search range */ + +register int * rotptr; + + +#define ROT_SIZE_1 20000 +#define ROT_SIZE_2 5 + +static int rot[ ROT_SIZE_1 ][ ROT_SIZE_2 ]; + + +static int * rtp[ ROT_SIZE_1 ]; + + + + +/* These now externally defined in bozorth.h */ +/* extern int * scolpt[ SCOLPT_SIZE ]; INPUT */ +/* extern int * fcolpt[ FCOLPT_SIZE ]; INPUT */ +/* extern int colp[ COLP_SIZE_1 ][ COLP_SIZE_2 ]; OUTPUT */ +/* extern int verbose_bozorth; */ +/* extern FILE * stderr; */ +/* extern char * get_progname( void ); */ +/* extern char * get_probe_filename( void ); */ +/* extern char * get_gallery_filename( void ); */ + + + + +st = 1; +edge_pair_index = 0; +rotptr = &rot[0][0]; + +/* Foreach sorted edge in Subject's Web ... */ + +for ( k = 1; k < probe_ptrlist_len; k++ ) { + ss = scolpt[k-1]; + + /* Foreach sorted edge in On-File Record's Web ... */ + + for ( j = st; j <= gallery_ptrlist_len; j++ ) { + ff = fcolpt[j-1]; + dz = *ff - *ss; + + fi = ( 2.0F * TK ) * ( *ff + *ss ); + + + + + + + + + if ( SQUARED(dz) > SQUARED(fi) ) { + if ( dz < 0 ) { + + st = j + 1; + + continue; + } else + break; + + + } + + + + for ( i = 1; i < 3; i++ ) { + float dz_squared; + + dz = *(ss+i) - *(ff+i); + dz_squared = SQUARED(dz); + + + + + if ( dz_squared > TXS && dz_squared < CTXS ) + break; + } + + if ( i < 3 ) + continue; + + + + + + + if ( *(ss+5) >= 220 ) { + p1 = *(ss+5) - 580; + n = 1; + } else { + p1 = *(ss+5); + n = 0; + } + + + if ( *(ff+5) >= 220 ) { + p2 = *(ff+5) - 580; + b = 1; + } else { + p2 = *(ff+5); + b = 0; + } + + p1 -= p2; + p1 = IANGLE180(p1); + + + + + + + + + + + + + + + + + + + + + + + + + if ( n != b ) { + + *rotptr++ = p1; + *rotptr++ = *(ss+3); + *rotptr++ = *(ss+4); + + *rotptr++ = *(ff+4); + *rotptr++ = *(ff+3); + } else { + *rotptr++ = p1; + *rotptr++ = *(ss+3); + *rotptr++ = *(ss+4); + + *rotptr++ = *(ff+3); + *rotptr++ = *(ff+4); + } + + + + + + + n = -1; + l = 1; + b = 0; + t = edge_pair_index + 1; + while ( t - b > 1 ) { + l = ( b + t ) / 2; + + for ( i = 0; i < 3; i++ ) { + static int ii_table[] = { 1, 3, 2 }; + + /* 1 = Subject's Kth, */ + /* 3 = On-File's Jth or Kth (depending), */ + /* 2 = Subject's Jth */ + + ii = ii_table[i]; + p1 = rot[edge_pair_index][ii]; + p2 = *( rtp[l-1] + ii ); + + n = SENSE(p1,p2); + + if ( n < 0 ) { + t = l; + break; + } + if ( n > 0 ) { + b = l; + break; + } + } + + if ( n == 0 ) { + n = 1; + b = l; + } + } /* END while() for binary search */ + + + if ( n == 1 ) + ++l; + + rtp_insert( rtp, l, edge_pair_index, &rot[edge_pair_index][0] ); + ++edge_pair_index; + + if ( edge_pair_index == 19999 ) { +#ifndef NOVERBOSE + if ( verbose_bozorth ) + fprintf( stderr, "%s: bz_match(): WARNING: list is full, breaking loop early [p=%s; g=%s]\n", + get_progname(), get_probe_filename(), get_gallery_filename() ); +#endif + goto END; /* break out if list exceeded */ + } + + } /* END FOR On-File (edge) distance */ + +} /* END FOR Subject (edge) distance */ + + + +END: +{ + int * colp_ptr = &colp[0][0]; + + for ( i = 0; i < edge_pair_index; i++ ) { + INT_COPY( colp_ptr, rtp[i], COLP_SIZE_2 ); + + + } +} + + + +return edge_pair_index; /* Return the number of compatible edge pairs stored into colp[][] */ +} + +/**************************************************************************/ +/* These global arrays are declared "static" as they are only used */ +/* between bz_match_score() & bz_final_loop() */ +/**************************************************************************/ +static int ct[ CT_SIZE ]; +static int gct[ GCT_SIZE ]; +static int ctt[ CTT_SIZE ]; +static int ctp[ CTP_SIZE_1 ][ CTP_SIZE_2 ]; +static int yy[ YY_SIZE_1 ][ YY_SIZE_2 ][ YY_SIZE_3 ]; + +static int bz_final_loop( int ); + +/**************************************************************************/ +int bz_match_score( + int np, + struct xyt_struct * pstruct, + struct xyt_struct * gstruct + ) +{ +int kx, kq; +int ftt; +int tot; +int qh; +int tp; +int ll, jj, kk, n, t, b; +int k, i, j, ii, z; +int kz, l; +int p1, p2; +int dw, ww; +int match_score; +int qq_overflow = 0; +float fi; + +/* These next 3 arrays originally declared global, but moved here */ +/* locally because they are only used herein */ +int rr[ RR_SIZE ]; +int avn[ AVN_SIZE ]; +int avv[ AVV_SIZE_1 ][ AVV_SIZE_2 ]; + +/* These now externally defined in bozorth.h */ +/* extern FILE * stderr; */ +/* extern char * get_progname( void ); */ +/* extern char * get_probe_filename( void ); */ +/* extern char * get_gallery_filename( void ); */ + + + + + + +if ( pstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { +#ifndef NOVERBOSE + if ( gstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { + if ( verbose_bozorth ) + fprintf( stderr, "%s: bz_match_score(): both probe and gallery file have too few minutiae (%d,%d) to compute a real Bozorth match score; min. is %d [p=%s; g=%s]\n", + get_progname(), + pstruct->nrows, gstruct->nrows, MIN_COMPUTABLE_BOZORTH_MINUTIAE, + get_probe_filename(), get_gallery_filename() ); + } else { + if ( verbose_bozorth ) + fprintf( stderr, "%s: bz_match_score(): probe file has too few minutiae (%d) to compute a real Bozorth match score; min. is %d [p=%s; g=%s]\n", + get_progname(), + pstruct->nrows, MIN_COMPUTABLE_BOZORTH_MINUTIAE, + get_probe_filename(), get_gallery_filename() ); + } +#endif + return ZERO_MATCH_SCORE; +} + + + +if ( gstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { +#ifndef NOVERBOSE + if ( verbose_bozorth ) + fprintf( stderr, "%s: bz_match_score(): gallery file has too few minutiae (%d) to compute a real Bozorth match score; min. is %d [p=%s; g=%s]\n", + get_progname(), + gstruct->nrows, MIN_COMPUTABLE_BOZORTH_MINUTIAE, + get_probe_filename(), get_gallery_filename() ); +#endif + return ZERO_MATCH_SCORE; +} + + + + + + + + + + /* initialize tables to 0's */ +INT_SET( (int *) &yl, YL_SIZE_1 * YL_SIZE_2, 0 ); + + + +INT_SET( (int *) &sc, SC_SIZE, 0 ); +INT_SET( (int *) &cp, CP_SIZE, 0 ); +INT_SET( (int *) &rp, RP_SIZE, 0 ); +INT_SET( (int *) &tq, TQ_SIZE, 0 ); +INT_SET( (int *) &rq, RQ_SIZE, 0 ); +INT_SET( (int *) &zz, ZZ_SIZE, 1000 ); /* zz[] initialized to 1000's */ + +INT_SET( (int *) &avn, AVN_SIZE, 0 ); /* avn[0...4] <== 0; */ + + + + + +tp = 0; +p1 = 0; +tot = 0; +ftt = 0; +kx = 0; +match_score = 0; + +for ( k = 0; k < np - 1; k++ ) { + /* printf( "compute(): looping with k=%d\n", k ); */ + + if ( sc[k] ) /* If SC counter for current pair already incremented ... */ + continue; /* Skip to next pair */ + + + i = colp[k][1]; + t = colp[k][3]; + + + + + qq[0] = i; + rq[t-1] = i; + tq[i-1] = t; + + + ww = 0; + dw = 0; + + do { + ftt++; + tot = 0; + qh = 1; + kx = k; + + + + + do { + + + + + + + + + + kz = colp[kx][2]; + l = colp[kx][4]; + kx++; + bz_sift( &ww, kz, &qh, l, kx, ftt, &tot, &qq_overflow ); + if ( qq_overflow ) { + fprintf( stderr, "%s: WARNING: bz_match_score(): qq[] overflow from bz_sift() #1 [p=%s; g=%s]\n", + get_progname(), get_probe_filename(), get_gallery_filename() ); + return QQ_OVERFLOW_SCORE; + } + +#ifndef NOVERBOSE + if ( verbose_bozorth ) + printf( "x1 %d %d %d %d %d %d\n", kx, colp[kx][0], colp[kx][1], colp[kx][2], colp[kx][3], colp[kx][4] ); +#endif + + } while ( colp[kx][3] == colp[k][3] && colp[kx][1] == colp[k][1] ); + /* While the startpoints of lookahead edge pairs are the same as the starting points of the */ + /* current pair, set KQ to lookahead edge pair index where above bz_sift() loop left off */ + + kq = kx; + + for ( j = 1; j < qh; j++ ) { + for ( i = kq; i < np; i++ ) { + + for ( z = 1; z < 3; z++ ) { + if ( z == 1 ) { + if ( (j+1) > QQ_SIZE ) { + fprintf( stderr, "%s: WARNING: bz_match_score(): qq[] overflow #1 in bozorth3(); j-1 is %d [p=%s; g=%s]\n", + get_progname(), j-1, get_probe_filename(), get_gallery_filename() ); + return QQ_OVERFLOW_SCORE; + } + p1 = qq[j]; + } else { + p1 = tq[p1-1]; + + } + + + + + + + if ( colp[i][2*z] != p1 ) + break; + } + + + if ( z == 3 ) { + z = colp[i][1]; + l = colp[i][3]; + + + + if ( z != colp[k][1] && l != colp[k][3] ) { + kx = i + 1; + bz_sift( &ww, z, &qh, l, kx, ftt, &tot, &qq_overflow ); + if ( qq_overflow ) { + fprintf( stderr, "%s: WARNING: bz_match_score(): qq[] overflow from bz_sift() #2 [p=%s; g=%s]\n", + get_progname(), get_probe_filename(), get_gallery_filename() ); + return QQ_OVERFLOW_SCORE; + } + } + } + } /* END for i */ + + + + /* Done looking ahead for current j */ + + + + + + l = 1; + t = np + 1; + b = kq; + + while ( t - b > 1 ) { + l = ( b + t ) / 2; + + for ( i = 1; i < 3; i++ ) { + + if ( i == 1 ) { + if ( (j+1) > QQ_SIZE ) { + fprintf( stderr, "%s: WARNING: bz_match_score(): qq[] overflow #2 in bozorth3(); j-1 is %d [p=%s; g=%s]\n", + get_progname(), j-1, get_probe_filename(), get_gallery_filename() ); + return QQ_OVERFLOW_SCORE; + } + p1 = qq[j]; + } else { + p1 = tq[p1-1]; + } + + + + p2 = colp[l-1][i*2-1]; + + n = SENSE(p1,p2); + + if ( n < 0 ) { + t = l; + break; + } + if ( n > 0 ) { + b = l; + break; + } + } + + if ( n == 0 ) { + + + + + + + /* Locates the head of consecutive sequence of edge pairs all having the same starting Subject and On-File edgepoints */ + while ( colp[l-2][3] == p2 && colp[l-2][1] == colp[l-1][1] ) + l--; + + kx = l - 1; + + + do { + kz = colp[kx][2]; + l = colp[kx][4]; + kx++; + bz_sift( &ww, kz, &qh, l, kx, ftt, &tot, &qq_overflow ); + if ( qq_overflow ) { + fprintf( stderr, "%s: WARNING: bz_match_score(): qq[] overflow from bz_sift() #3 [p=%s; g=%s]\n", + get_progname(), get_probe_filename(), get_gallery_filename() ); + return QQ_OVERFLOW_SCORE; + } + } while ( colp[kx][3] == p2 && colp[kx][1] == colp[kx-1][1] ); + + break; + } /* END if ( n == 0 ) */ + + } /* END while */ + + } /* END for j */ + + + + + if ( tot >= MSTR ) { + jj = 0; + kk = 0; + n = 0; + l = 0; + + for ( i = 0; i < tot; i++ ) { + + + int colp_value = colp[ y[i]-1 ][0]; + if ( colp_value < 0 ) { + kk += colp_value; + n++; + } else { + jj += colp_value; + l++; + } + } + + + if ( n == 0 ) { + n = 1; + } else if ( l == 0 ) { + l = 1; + } + + + + fi = (float) jj / (float) l - (float) kk / (float) n; + + if ( fi > 180.0F ) { + fi = ( jj + kk + n * 360 ) / (float) tot; + if ( fi > 180.0F ) + fi -= 360.0F; + } else { + fi = ( jj + kk ) / (float) tot; + } + + jj = ROUND(fi); + if ( jj <= -180 ) + jj += 360; + + + + kk = 0; + for ( i = 0; i < tot; i++ ) { + int diff = colp[ y[i]-1 ][0] - jj; + j = SQUARED( diff ); + + + + + if ( j > TXS && j < CTXS ) + kk++; + else + y[i-kk] = y[i]; + } /* END FOR i */ + + tot -= kk; /* Adjust the total edge pairs TOT based on # of edge pairs skipped */ + + } /* END if ( tot >= MSTR ) */ + + + + + if ( tot < MSTR ) { + + + + + for ( i = tot-1 ; i >= 0; i-- ) { + int idx = y[i] - 1; + if ( rk[idx] == 0 ) { + sc[idx] = -1; + } else { + sc[idx] = rk[idx]; + } + } + ftt--; + + } else { /* tot >= MSTR */ + /* Otherwise size of TOT group (seq. of TOT indices stored in Y) is large enough to analyze */ + + int pa = 0; + int pb = 0; + int pc = 0; + int pd = 0; + + for ( i = 0; i < tot; i++ ) { + int idx = y[i] - 1; + for ( ii = 1; ii < 4; ii++ ) { + + + + + kk = ( SQUARED(ii) - ii + 2 ) / 2 - 1; + + + + + jj = colp[idx][kk]; + + switch ( ii ) { + case 1: + if ( colp[idx][0] < 0 ) { + pd += colp[idx][0]; + pb++; + } else { + pa += colp[idx][0]; + pc++; + } + break; + case 2: + avn[ii-1] += pstruct->xcol[jj-1]; + avn[ii] += pstruct->ycol[jj-1]; + break; + default: + avn[ii] += gstruct->xcol[jj-1]; + avn[ii+1] += gstruct->ycol[jj-1]; + break; + } /* switch */ + } /* END for ii = [1..3] */ + + for ( ii = 0; ii < 2; ii++ ) { + n = -1; + l = 1; + + for ( jj = 1; jj < 3; jj++ ) { + + + + + + + + + + + p1 = colp[idx][ 2 * ii + jj ]; + + + b = 0; + t = yl[ii][tp] + 1; + + while ( t - b > 1 ) { + l = ( b + t ) / 2; + p2 = yy[l-1][ii][tp]; + n = SENSE(p1,p2); + + if ( n < 0 ) { + t = l; + } else { + if ( n > 0 ) { + b = l; + } else { + break; + } + } + } /* END WHILE */ + + if ( n != 0 ) { + if ( n == 1 ) + ++l; + + for ( kk = yl[ii][tp]; kk >= l; --kk ) { + yy[kk][ii][tp] = yy[kk-1][ii][tp]; + } + + ++yl[ii][tp]; + yy[l-1][ii][tp] = p1; + + + } /* END if ( n != 0 ) */ + + /* Otherwise, edgepoint already stored in YY */ + + } /* END FOR jj in [1,2] */ + } /* END FOR ii in [0,1] */ + } /* END FOR i */ + + if ( pb == 0 ) { + pb = 1; + } else if ( pc == 0 ) { + pc = 1; + } + + + + fi = (float) pa / (float) pc - (float) pd / (float) pb; + if ( fi > 180.0F ) { + + fi = ( pa + pd + pb * 360 ) / (float) tot; + if ( fi > 180.0F ) + fi -= 360.0F; + } else { + fi = ( pa + pd ) / (float) tot; + } + + pa = ROUND(fi); + if ( pa <= -180 ) + pa += 360; + + + + avv[tp][0] = pa; + + for ( ii = 1; ii < 5; ii++ ) { + avv[tp][ii] = avn[ii] / tot; + avn[ii] = 0; + } + + ct[tp] = tot; + gct[tp] = tot; + + if ( tot > match_score ) /* If current TOT > match_score ... */ + match_score = tot; /* Keep track of max TOT in match_score */ + + ctt[tp] = 0; /* Init CTT[TP] to 0 */ + ctp[tp][0] = tp; /* Store TP into CTP */ + + for ( ii = 0; ii < tp; ii++ ) { + int found; + int diff; + + int * avv_tp_ptr = &avv[tp][0]; + int * avv_ii_ptr = &avv[ii][0]; + diff = *avv_tp_ptr++ - *avv_ii_ptr++; + j = SQUARED( diff ); + + + + + + + if ( j > TXS && j < CTXS ) + continue; + + + + + + + + + + ll = *avv_tp_ptr++ - *avv_ii_ptr++; + jj = *avv_tp_ptr++ - *avv_ii_ptr++; + kk = *avv_tp_ptr++ - *avv_ii_ptr++; + j = *avv_tp_ptr++ - *avv_ii_ptr++; + + { + float tt, ai, dz; + + tt = (float) (SQUARED(ll) + SQUARED(jj)); + ai = (float) (SQUARED(j) + SQUARED(kk)); + + fi = ( 2.0F * TK ) * ( tt + ai ); + dz = tt - ai; + + + if ( SQUARED(dz) > SQUARED(fi) ) + continue; + } + + + + if ( ll ) { + + if ( m1_xyt ) + fi = ( 180.0F / PI_SINGLE ) * atanf( (float) -jj / (float) ll ); + else + fi = ( 180.0F / PI_SINGLE ) * atanf( (float) jj / (float) ll ); + if ( fi < 0.0F ) { + if ( ll < 0 ) + fi += 180.5F; + else + fi -= 0.5F; + } else { + if ( ll < 0 ) + fi -= 180.5F; + else + fi += 0.5F; + } + jj = (int) fi; + if ( jj <= -180 ) + jj += 360; + } else { + + if ( m1_xyt ) { + if ( jj > 0 ) + jj = -90; + else + jj = 90; + } else { + if ( jj > 0 ) + jj = 90; + else + jj = -90; + } + } + + + + if ( kk ) { + + if ( m1_xyt ) + fi = ( 180.0F / PI_SINGLE ) * atanf( (float) -j / (float) kk ); + else + fi = ( 180.0F / PI_SINGLE ) * atanf( (float) j / (float) kk ); + if ( fi < 0.0F ) { + if ( kk < 0 ) + fi += 180.5F; + else + fi -= 0.5F; + } else { + if ( kk < 0 ) + fi -= 180.5F; + else + fi += 0.5F; + } + j = (int) fi; + if ( j <= -180 ) + j += 360; + } else { + + if ( m1_xyt ) { + if ( j > 0 ) + j = -90; + else + j = 90; + } else { + if ( j > 0 ) + j = 90; + else + j = -90; + } + } + + + + + + pa = 0; + pb = 0; + pc = 0; + pd = 0; + + if ( avv[tp][0] < 0 ) { + pd += avv[tp][0]; + pb++; + } else { + pa += avv[tp][0]; + pc++; + } + + if ( avv[ii][0] < 0 ) { + pd += avv[ii][0]; + pb++; + } else { + pa += avv[ii][0]; + pc++; + } + + if ( pb == 0 ) { + pb = 1; + } else if ( pc == 0 ) { + pc = 1; + } + + + + fi = (float) pa / (float) pc - (float) pd / (float) pb; + + if ( fi > 180.0F ) { + fi = ( pa + pd + pb * 360 ) / 2.0F; + if ( fi > 180.0F ) + fi -= 360.0F; + } else { + fi = ( pa + pd ) / 2.0F; + } + + pb = ROUND(fi); + if ( pb <= -180 ) + pb += 360; + + + + + + pa = jj - j; + pa = IANGLE180(pa); + kk = SQUARED(pb-pa); + + + + + /* Was: if ( SQUARED(kk) > TXS && kk < CTXS ) : assume typo */ + if ( kk > TXS && kk < CTXS ) + continue; + + + found = 0; + for ( kk = 0; kk < 2; kk++ ) { + jj = 0; + ll = 0; + + do { + while ( yy[jj][kk][ii] < yy[ll][kk][tp] && jj < yl[kk][ii] ) { + + jj++; + } + + + + + while ( yy[jj][kk][ii] > yy[ll][kk][tp] && ll < yl[kk][tp] ) { + + ll++; + } + + + + + if ( yy[jj][kk][ii] == yy[ll][kk][tp] && jj < yl[kk][ii] && ll < yl[kk][tp] ) { + found = 1; + break; + } + + + } while ( jj < yl[kk][ii] && ll < yl[kk][tp] ); + if ( found ) + break; + } /* END for kk */ + + if ( ! found ) { /* If we didn't find what we were searching for ... */ + gct[ii] += ct[tp]; + if ( gct[ii] > match_score ) + match_score = gct[ii]; + ++ctt[ii]; + ctp[ii][ctt[ii]] = tp; + } + + } /* END for ii in [0,TP-1] prior TP group */ + + tp++; /* Bump TP counter */ + + + } /* END ELSE if ( tot == MSTR ) */ + + + + if ( qh > QQ_SIZE ) { + fprintf( stderr, "%s: WARNING: bz_match_score(): qq[] overflow #3 in bozorth3(); qh-1 is %d [p=%s; g=%s]\n", + get_progname(), qh-1, get_probe_filename(), get_gallery_filename() ); + return QQ_OVERFLOW_SCORE; + } + for ( i = qh - 1; i > 0; i-- ) { + n = qq[i] - 1; + if ( ( tq[n] - 1 ) >= 0 ) { + rq[tq[n]-1] = 0; + tq[n] = 0; + zz[n] = 1000; + } + } + + for ( i = dw - 1; i >= 0; i-- ) { + n = rr[i] - 1; + if ( tq[n] ) { + rq[tq[n]-1] = 0; + tq[n] = 0; + } + } + + i = 0; + j = ww - 1; + while ( i >= 0 && j >= 0 ) { + if ( nn[j] < mm[j] ) { + ++nn[j]; + + for ( i = ww - 1; i >= 0; i-- ) { + int rt = rx[i]; + if ( rt < 0 ) { + rt = - rt; + rt--; + z = rf[i][nn[i]-1]-1; + + + + if (( tq[z] != (rt+1) && tq[z] ) || ( rq[rt] != (z+1) && rq[rt] )) + break; + + + tq[z] = rt+1; + rq[rt] = z+1; + rr[i] = z+1; + } else { + rt--; + z = cf[i][nn[i]-1]-1; + + + if (( tq[rt] != (z+1) && tq[rt] ) || ( rq[z] != (rt+1) && rq[z] )) + break; + + + tq[rt] = z+1; + rq[z] = rt+1; + rr[i] = rt+1; + } + } /* END for i */ + + if ( i >= 0 ) { + for ( z = i + 1; z < ww; z++) { + n = rr[z] - 1; + if ( tq[n] - 1 >= 0 ) { + rq[tq[n]-1] = 0; + tq[n] = 0; + } + } + j = ww - 1; + } + + } else { + nn[j] = 1; + j--; + } + + } + + if ( tp > 1999 ) + break; + + dw = ww; + + + } while ( j >= 0 ); /* END while endpoint group remain ... */ + + + if ( tp > 1999 ) + break; + + + + + n = qq[0] - 1; + if ( tq[n] - 1 >= 0 ) { + rq[tq[n]-1] = 0; + tq[n] = 0; + } + + for ( i = ww-1; i >= 0; i-- ) { + n = rx[i]; + if ( n < 0 ) { + n = - n; + rp[n-1] = 0; + } else { + cp[n-1] = 0; + } + + } + +} /* END FOR each edge pair */ + + + +if ( match_score < MMSTR ) { + return match_score; +} + +match_score = bz_final_loop( tp ); +return match_score; +} + + +/***********************************************************************/ +/* These globals signficantly used by bz_sift () */ +/* Now externally defined in bozorth.h */ +/* extern int sc[ SC_SIZE ]; */ +/* extern int rq[ RQ_SIZE ]; */ +/* extern int tq[ TQ_SIZE ]; */ +/* extern int rf[ RF_SIZE_1 ][ RF_SIZE_2 ]; */ +/* extern int cf[ CF_SIZE_1 ][ CF_SIZE_2 ]; */ +/* extern int zz[ ZZ_SIZE ]; */ +/* extern int rx[ RX_SIZE ]; */ +/* extern int mm[ MM_SIZE ]; */ +/* extern int nn[ NN_SIZE ]; */ +/* extern int qq[ QQ_SIZE ]; */ +/* extern int rk[ RK_SIZE ]; */ +/* extern int cp[ CP_SIZE ]; */ +/* extern int rp[ RP_SIZE ]; */ +/* extern int y[ Y_SIZE ]; */ + +void bz_sift( + int * ww, /* INPUT and OUTPUT; endpoint groups index; *ww may be bumped by one or by two */ + int kz, /* INPUT only; endpoint of lookahead Subject edge */ + int * qh, /* INPUT and OUTPUT; the value is an index into qq[] and is stored in zz[]; *qh may be bumped by one */ + int l, /* INPUT only; endpoint of lookahead On-File edge */ + int kx, /* INPUT only -- index */ + int ftt, /* INPUT only */ + int * tot, /* OUTPUT -- counter is incremented by one, sometimes */ + int * qq_overflow /* OUTPUT -- flag is set only if qq[] overflows */ + ) +{ +int n; +int t; + +/* These now externally defined in bozorth.h */ +/* extern FILE * stderr; */ +/* extern char * get_progname( void ); */ +/* extern char * get_probe_filename( void ); */ +/* extern char * get_gallery_filename( void ); */ + + + +n = tq[ kz - 1]; /* Lookup On-File edgepoint stored in TQ at index of endpoint of lookahead Subject edge */ +t = rq[ l - 1]; /* Lookup Subject edgepoint stored in RQ at index of endpoint of lookahead On-File edge */ + +if ( n == 0 && t == 0 ) { + + + if ( sc[kx-1] != ftt ) { + y[ (*tot)++ ] = kx; + rk[kx-1] = sc[kx-1]; + sc[kx-1] = ftt; + } + + if ( *qh >= QQ_SIZE ) { + fprintf( stderr, "%s: ERROR: bz_sift(): qq[] overflow #1; the index [*qh] is %d [p=%s; g=%s]\n", + get_progname(), + *qh, get_probe_filename(), get_gallery_filename() ); + *qq_overflow = 1; + return; + } + qq[ *qh ] = kz; + zz[ kz-1 ] = (*qh)++; + + + /* The TQ and RQ locations are set, so set them ... */ + tq[ kz-1 ] = l; + rq[ l-1 ] = kz; + + return; +} /* END if ( n == 0 && t == 0 ) */ + + + + + + + + + +if ( n == l ) { + + if ( sc[kx-1] != ftt ) { + if ( zz[kx-1] == 1000 ) { + if ( *qh >= QQ_SIZE ) { + fprintf( stderr, "%s: ERROR: bz_sift(): qq[] overflow #2; the index [*qh] is %d [p=%s; g=%s]\n", + get_progname(), + *qh, + get_probe_filename(), get_gallery_filename() ); + *qq_overflow = 1; + return; + } + qq[*qh] = kz; + zz[kz-1] = (*qh)++; + } + y[(*tot)++] = kx; + rk[kx-1] = sc[kx-1]; + sc[kx-1] = ftt; + } + + return; +} /* END if ( n == l ) */ + + + + + +if ( *ww >= WWIM ) /* This limits the number of endpoint groups that can be constructed */ + return; + + +{ +int b; +int b_index; +register int i; +int notfound; +int lim; +register int * lptr; + +/* If lookahead Subject endpoint previously assigned to TQ but not paired with lookahead On-File endpoint ... */ + +if ( n ) { + b = cp[ kz - 1 ]; + if ( b == 0 ) { + b = ++*ww; + b_index = b - 1; + cp[kz-1] = b; + cf[b_index][0] = n; + mm[b_index] = 1; + nn[b_index] = 1; + rx[b_index] = kz; + + } else { + b_index = b - 1; + } + + lim = mm[b_index]; + lptr = &cf[b_index][0]; + notfound = 1; + +#ifndef NOVERBOSE + if ( verbose_bozorth ) { + int * llptr = lptr; + printf( "bz_sift(): n: looking for l=%d in [", l ); + for ( i = 0; i < lim; i++ ) { + printf( " %d", *llptr++ ); + } + printf( " ]\n" ); + } +#endif + + for ( i = 0; i < lim; i++ ) { + if ( *lptr++ == l ) { + notfound = 0; + break; + } + } + if ( notfound ) { /* If lookahead On-File endpoint not in list ... */ + cf[b_index][i] = l; + ++mm[b_index]; + } +} /* END if ( n ) */ + + +/* If lookahead On-File endpoint previously assigned to RQ but not paired with lookahead Subject endpoint... */ + +if ( t ) { + b = rp[ l - 1 ]; + if ( b == 0 ) { + b = ++*ww; + b_index = b - 1; + rp[l-1] = b; + rf[b_index][0] = t; + mm[b_index] = 1; + nn[b_index] = 1; + rx[b_index] = -l; + + + } else { + b_index = b - 1; + } + + lim = mm[b_index]; + lptr = &rf[b_index][0]; + notfound = 1; + +#ifndef NOVERBOSE + if ( verbose_bozorth ) { + int * llptr = lptr; + printf( "bz_sift(): t: looking for kz=%d in [", kz ); + for ( i = 0; i < lim; i++ ) { + printf( " %d", *llptr++ ); + } + printf( " ]\n" ); + } +#endif + + for ( i = 0; i < lim; i++ ) { + if ( *lptr++ == kz ) { + notfound = 0; + break; + } + } + if ( notfound ) { /* If lookahead Subject endpoint not in list ... */ + rf[b_index][i] = kz; + ++mm[b_index]; + } +} /* END if ( t ) */ + +} + +} + +/**************************************************************************/ + +static int bz_final_loop( int tp ) +{ +int ii, i, t, b, n, k, j, kk, jj; +int lim; +int match_score; + +/* This array originally declared global, but moved here */ +/* locally because it is only used herein. The use of */ +/* "static" is required as the array will exceed the */ +/* stack allocation on our local systems otherwise. */ +static int sct[ SCT_SIZE_1 ][ SCT_SIZE_2 ]; + +match_score = 0; +for ( ii = 0; ii < tp; ii++ ) { /* For each index up to the current value of TP ... */ + + if ( match_score >= gct[ii] ) /* if next group total not bigger than current match_score.. */ + continue; /* skip to next TP index */ + + lim = ctt[ii] + 1; + for ( i = 0; i < lim; i++ ) { + sct[i][0] = ctp[ii][i]; + } + + t = 0; + y[0] = lim; + cp[0] = 1; + b = 0; + n = 1; + do { /* looping until T < 0 ... */ + if ( y[t] - cp[t] > 1 ) { + k = sct[cp[t]][t]; + j = ctt[k] + 1; + for ( i = 0; i < j; i++ ) { + rp[i] = ctp[k][i]; + } + k = 0; + kk = cp[t]; + jj = 0; + + do { + while ( rp[jj] < sct[kk][t] && jj < j ) + jj++; + while ( rp[jj] > sct[kk][t] && kk < y[t] ) + kk++; + while ( rp[jj] == sct[kk][t] && kk < y[t] && jj < j ) { + sct[k][t+1] = sct[kk][t]; + k++; + kk++; + jj++; + } + } while ( kk < y[t] && jj < j ); + + t++; + cp[t] = 1; + y[t] = k; + b = t; + n = 1; + } else { + int tot = 0; + + lim = y[t]; + for ( i = n-1; i < lim; i++ ) { + tot += ct[ sct[i][t] ]; + } + + for ( i = 0; i < b; i++ ) { + tot += ct[ sct[0][i] ]; + } + + if ( tot > match_score ) { /* If the current total is larger than the running total ... */ + match_score = tot; /* then set match_score to the new total */ + for ( i = 0; i < b; i++ ) { + rk[i] = sct[0][i]; + } + + { + int rk_index = b; + lim = y[t]; + for ( i = n-1; i < lim; ) { + rk[ rk_index++ ] = sct[ i++ ][ t ]; + } + } + } + b = t; + t--; + if ( t >= 0 ) { + ++cp[t]; + n = y[t]; + } + } /* END IF */ + + } while ( t >= 0 ); + +} /* END FOR ii */ + +return match_score; + +} /* END bz_final_loop() */ --- libfprint-20081125git.orig/libfprint/nbis/bozorth3/.svn/text-base/bz_io.c.svn-base +++ libfprint-20081125git/libfprint/nbis/bozorth3/.svn/text-base/bz_io.c.svn-base @@ -0,0 +1,632 @@ +/****************************************************************************** + +This file is part of the Export Control subset of the United States NIST +Biometric Image Software (NBIS) distribution: + http://fingerprint.nist.gov/NBIS/index.html + +It is our understanding that this falls within ECCN 3D980, which covers +software associated with the development, production or use of certain +equipment controlled in accordance with U.S. concerns about crime control +practices in specific countries. + +Therefore, this file should not be exported, or made available on fileservers, +except as allowed by U.S. export control laws. + +Do not remove this notice. + +******************************************************************************/ + +/* NOTE: Despite the above notice (which I have not removed), this file is + * being legally distributed within libfprint; the U.S. Export Administration + * Regulations do not place export restrictions upon distribution of + * "publicly available technology and software", as stated in EAR section + * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per + * the definition in section 734.7(a)(1). + * + * For further information, see http://reactivated.net/fprint/US_export_control + */ + +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +/*********************************************************************** + LIBRARY: FING - NIST Fingerprint Systems Utilities + + FILE: BZ_IO.C + ALGORITHM: Allan S. Bozorth (FBI) + MODIFICATIONS: Michael D. Garris (NIST) + Stan Janet (NIST) + DATE: 09/21/2004 + + Contains routines responsible for supporting command line + processing, file and data input to, and output from the + Bozorth3 fingerprint matching algorithm. + +*********************************************************************** + + ROUTINES: +#cat: parse_line_range - parses strings of the form #-# into the upper +#cat: and lower bounds of a range corresponding to lines in +#cat: an input file list +#cat: set_progname - stores the program name for the current invocation +#cat: set_probe_filename - stores the name of the current probe file +#cat: being processed +#cat: set_gallery_filename - stores the name of the current gallery file +#cat: being processed +#cat: get_progname - retrieves the program name for the current invocation +#cat: get_probe_filename - retrieves the name of the current probe file +#cat: being processed +#cat: get_gallery_filename - retrieves the name of the current gallery +#cat: file being processed +#cat: get_next_file - gets the next probe (or gallery) filename to be +#cat: processed, either from the command line or from a +#cat: file list +#cat: get_score_filename - returns the filename to which the output line +#cat: should be written +#cat: get_score_line - formats output lines based on command line options +#cat: specified +#cat: bz_load - loads the contents of the specified XYT file into +#cat: structured memory +#cat: fd_readable - when multiple bozorth processes are being run +#cat: concurrently and one of the processes determines a +#cat: has been found, the other processes poll a file +#cat: descriptor using this function to see if they +#cat: should exit as well + +***********************************************************************/ + +#include +#include +#include +#include + +static const int verbose_load = 0; +static const int verbose_main = 0; + +/***********************************************************************/ +int parse_line_range( const char * sb, int * begin, int * end ) +{ +int ib, ie; +char * se; + + +if ( ! isdigit(*sb) ) + return -1; +ib = atoi( sb ); + +se = strchr( sb, '-' ); +if ( se != (char *) NULL ) { + se++; + if ( ! isdigit(*se) ) + return -2; + ie = atoi( se ); +} else { + ie = ib; +} + +if ( ib <= 0 ) { + if ( ie <= 0 ) { + return -3; + } else { + return -4; + } +} + +if ( ie <= 0 ) { + return -5; +} + +if ( ib > ie ) + return -6; + +*begin = ib; +*end = ie; + +return 0; +} + +/***********************************************************************/ + +/* Used by the following set* and get* routines */ +static char program_buffer[ 1024 ]; +static char * pfile; +static char * gfile; + +/***********************************************************************/ +void set_progname( int use_pid, char * basename, pid_t pid ) +{ +if ( use_pid ) + sprintf( program_buffer, "%s pid %ld", basename, (long) pid ); +else + sprintf( program_buffer, "%s", basename ); +} + +/***********************************************************************/ +void set_probe_filename( char * filename ) +{ +pfile = filename; +} + +/***********************************************************************/ +void set_gallery_filename( char * filename ) +{ +gfile = filename; +} + +/***********************************************************************/ +char * get_progname( void ) +{ +return program_buffer; +} + +/***********************************************************************/ +char * get_probe_filename( void ) +{ +return pfile; +} + +/***********************************************************************/ +char * get_gallery_filename( void ) +{ +return gfile; +} + +/***********************************************************************/ +char * get_next_file( + char * fixed_file, + FILE * list_fp, + FILE * mates_fp, + int * done_now, + int * done_afterwards, + char * line, + int argc, + char ** argv, + int * optind, + + int * lineno, + int begin, + int end + ) +{ +char * p; +FILE * fp; + + + +if ( fixed_file != (char *) NULL ) { + if ( verbose_main ) + fprintf( stderr, "returning fixed filename: %s\n", fixed_file ); + return fixed_file; +} + + +fp = list_fp; +if ( fp == (FILE *) NULL ) + fp = mates_fp; +if ( fp != (FILE *) NULL ) { + while (1) { + if ( fgets( line, MAX_LINE_LENGTH, fp ) == (char *) NULL ) { + *done_now = 1; + if ( verbose_main ) + fprintf( stderr, "returning NULL -- reached EOF\n" ); + return (char *) NULL; + } + ++*lineno; + + if ( begin <= 0 ) /* no line number range was specified */ + break; + if ( *lineno > end ) { + *done_now = 1; + if ( verbose_main ) + fprintf( stderr, "returning NULL -- current line (%d) > end line (%d)\n", + *lineno, end ); + return (char *) NULL; + } + if ( *lineno >= begin ) { + break; + } + /* Otherwise ( *lineno < begin ) so read another line */ + } + + p = strchr( line, '\n' ); + if ( p == (char *) NULL ) { + *done_now = 1; + if ( verbose_main ) + fprintf( stderr, "returning NULL -- missing newline character\n" ); + return (char *) NULL; + } + *p = '\0'; + + p = line; + if ( verbose_main ) + fprintf( stderr, "returning filename from next line: %s\n", p ); + return p; +} + + +p = argv[*optind]; +++*optind; +if ( *optind >= argc ) + *done_afterwards = 1; +if ( verbose_main ) + fprintf( stderr, "returning next argv: %s [done_afterwards=%d]\n", p, *done_afterwards ); +return p; +} + +/***********************************************************************/ +/* returns CNULL on error */ +char * get_score_filename( const char * outdir, const char * listfile ) +{ +const char * basename; +int baselen; +int dirlen; +int extlen; +char * outfile; + +/* These are now exteranlly defined in bozorth.h */ +/* extern FILE * stderr; */ +/* extern char * get_progname( void ); */ + + + +basename = strrchr( listfile, '/' ); +if ( basename == CNULL ) { + basename = listfile; +} else { + ++basename; +} +baselen = strlen( basename ); +if ( baselen == 0 ) { + fprintf( stderr, "%s: ERROR: couldn't find basename of %s\n", get_progname(), listfile ); + return(CNULL); +} +dirlen = strlen( outdir ); +if ( dirlen == 0 ) { + fprintf( stderr, "%s: ERROR: illegal output directory %s\n", get_progname(), outdir ); + return(CNULL); +} + +extlen = strlen( SCOREFILE_EXTENSION ); +outfile = malloc_or_return_error( dirlen + baselen + extlen + 2, "output filename" ); +if ( outfile == CNULL) + return(CNULL); + +sprintf( outfile, "%s/%s%s", outdir, basename, SCOREFILE_EXTENSION ); + +return outfile; +} + +/***********************************************************************/ +char * get_score_line( + const char * probe_file, + const char * gallery_file, + int n, + int static_flag, + const char * fmt + ) +{ +int nchars; +char * bufptr; +static char linebuf[1024]; + +nchars = 0; +bufptr = &linebuf[0]; +while ( *fmt ) { + if ( nchars++ > 0 ) + *bufptr++ = ' '; + switch ( *fmt++ ) { + case 's': + sprintf( bufptr, "%d", n ); + break; + case 'p': + sprintf( bufptr, "%s", probe_file ); + break; + case 'g': + sprintf( bufptr, "%s", gallery_file ); + break; + default: + return (char *) NULL; + } + bufptr = strchr( bufptr, '\0' ); +} +*bufptr++ = '\n'; +*bufptr = '\0'; + +return static_flag ? &linebuf[0] : strdup( linebuf ); +} + +/************************************************************************ +Load a 3-4 column (X,Y,T[,Q]) set of minutiae from the specified file. +Row 3's value is an angle which is normalized to the interval (-180,180]. +A maximum of MAX_BOZORTH_MINUTIAE minutiae can be returned -- fewer if +"DEFAULT_BOZORTH_MINUTIAE" is smaller. If the file contains more minutiae than are +to be returned, the highest-quality minutiae are returned. +*************************************************************************/ + +/***********************************************************************/ +struct xyt_struct * bz_load( const char * xyt_file ) +{ +int nminutiae; +int j; +int m; +int nargs_expected; +FILE * fp; +struct xyt_struct * s; +int * xptr; +int * yptr; +int * tptr; +int * qptr; +struct minutiae_struct c[MAX_FILE_MINUTIAE]; +int xvals_lng[MAX_FILE_MINUTIAE], /* Temporary lists to store all the minutaie from a file */ + yvals_lng[MAX_FILE_MINUTIAE], + tvals_lng[MAX_FILE_MINUTIAE], + qvals_lng[MAX_FILE_MINUTIAE]; +int order[MAX_FILE_MINUTIAE]; /* The ranked order, after sort, for each index */ +int xvals[MAX_BOZORTH_MINUTIAE], /* Temporary lists to hold input coordinates */ + yvals[MAX_BOZORTH_MINUTIAE], + tvals[MAX_BOZORTH_MINUTIAE], + qvals[MAX_BOZORTH_MINUTIAE]; +char xyt_line[ MAX_LINE_LENGTH ]; + +/* This is now externally defined in bozorth.h */ +/* extern FILE * stderr; */ + + + +#define C1 0 +#define C2 1 + + + +fp = fopen( xyt_file, "r" ); +if ( fp == (FILE *) NULL ) { + fprintf( stderr, "%s: ERROR: fopen() of minutiae file \"%s\" failed: %s\n", + get_progname(), xyt_file, strerror(errno) ); + return XYT_NULL; +} + +nminutiae = 0; +nargs_expected = 0; +while ( fgets( xyt_line, sizeof xyt_line, fp ) != CNULL ) { + + m = sscanf( xyt_line, "%d %d %d %d", + &xvals_lng[nminutiae], + &yvals_lng[nminutiae], + &tvals_lng[nminutiae], + &qvals_lng[nminutiae] ); + if ( nminutiae == 0 ) { + if ( m != 3 && m != 4 ) { + fprintf( stderr, "%s: ERROR: sscanf() failed on line %u in minutiae file \"%s\"\n", + get_progname(), nminutiae+1, xyt_file ); + return XYT_NULL; + } + nargs_expected = m; + } else { + if ( m != nargs_expected ) { + fprintf( stderr, "%s: ERROR: inconsistent argument count on line %u of minutiae file \"%s\"\n", + get_progname(), nminutiae+1, xyt_file ); + return XYT_NULL; + } + } + if ( m == 3 ) + qvals_lng[nminutiae] = 1; + + + + if ( tvals_lng[nminutiae] > 180 ) + tvals_lng[nminutiae] -= 360; + + /* + if ( C1 ) { + c[nminutiae].col[0] = xvals_lng[nminutiae]; + c[nminutiae].col[1] = yvals_lng[nminutiae]; + c[nminutiae].col[2] = tvals_lng[nminutiae]; + c[nminutiae].col[3] = qvals_lng[nminutiae]; + } + */ + + ++nminutiae; + if ( nminutiae == MAX_FILE_MINUTIAE ) + break; +} + +if ( fclose(fp) != 0 ) { + fprintf( stderr, "%s: ERROR: fclose() of minutiae file \"%s\" failed: %s\n", + get_progname(), xyt_file, strerror(errno) ); + return XYT_NULL; +} + + + + +if ( nminutiae > DEFAULT_BOZORTH_MINUTIAE ) { + if ( verbose_load ) + fprintf( stderr, "%s: WARNING: bz_load(): trimming minutiae to the %d of highest quality\n", + get_progname(), DEFAULT_BOZORTH_MINUTIAE ); + + if ( verbose_load ) + fprintf( stderr, "Before quality sort:\n" ); + if ( sort_order_decreasing( qvals_lng, nminutiae, order )) { + fprintf( stderr, "%s: ERROR: sort failed and returned on error\n", get_progname()); + return XYT_NULL; + } + + for ( j = 0; j < nminutiae; j++ ) { + + if ( verbose_load ) + fprintf( stderr, " %3d: %3d %3d %3d ---> order = %3d\n", + j, xvals_lng[j], yvals_lng[j], qvals_lng[j], order[j] ); + + if ( j == 0 ) + continue; + if ( qvals_lng[order[j]] > qvals_lng[order[j-1]] ) { + fprintf( stderr, "%s: ERROR: sort failed: j=%d; qvals_lng[%d] > qvals_lng[%d]\n", + get_progname(), j, order[j], order[j-1] ); + return XYT_NULL; + } + } + + + if ( verbose_load ) + fprintf( stderr, "\nAfter quality sort:\n" ); + for ( j = 0; j < DEFAULT_BOZORTH_MINUTIAE; j++ ) { + xvals[j] = xvals_lng[order[j]]; + yvals[j] = yvals_lng[order[j]]; + tvals[j] = tvals_lng[order[j]]; + qvals[j] = qvals_lng[order[j]]; + if ( verbose_load ) + fprintf( stderr, " %3d: %3d %3d %3d\n", j, xvals[j], yvals[j], qvals[j] ); + } + + + if ( C1 ) { + if ( verbose_load ) + fprintf( stderr, "\nAfter qsort():\n" ); + qsort( (void *) &c, (size_t) nminutiae, sizeof(struct minutiae_struct), sort_quality_decreasing ); + for ( j = 0; j < nminutiae; j++ ) { + + if ( verbose_load ) + fprintf( stderr, "Q %3d: %3d %3d %3d\n", + j, c[j].col[0], c[j].col[1], c[j].col[3] ); + + if ( j > 0 && c[j].col[3] > c[j-1].col[3] ) { + fprintf( stderr, "%s: ERROR: sort failed: c[%d].col[3] > c[%d].col[3]\n", + get_progname(), j, j-1 ); + return XYT_NULL; + } + } + } + + if ( verbose_load ) + fprintf( stderr, "\n" ); + + xptr = xvals; + yptr = yvals; + tptr = tvals; + qptr = qvals; + + nminutiae = DEFAULT_BOZORTH_MINUTIAE; +} else{ + xptr = xvals_lng; + yptr = yvals_lng; + tptr = tvals_lng; + qptr = qvals_lng; +} + + + +for ( j=0; j < nminutiae; j++ ) { + c[j].col[0] = xptr[j]; + c[j].col[1] = yptr[j]; + c[j].col[2] = tptr[j]; + c[j].col[3] = qptr[j]; +} +qsort( (void *) &c, (size_t) nminutiae, sizeof(struct minutiae_struct), sort_x_y ); + + + + +if ( verbose_load ) { + fprintf( stderr, "\nSorted on increasing x, then increasing y\n" ); + for ( j = 0; j < nminutiae; j++ ) { + fprintf( stderr, "%d : %3d, %3d, %3d, %3d\n", j, c[j].col[0], c[j].col[1], c[j].col[2], c[j].col[3] ); + if ( j > 0 ) { + if ( c[j].col[0] < c[j-1].col[0] ) { + fprintf( stderr, "%s: ERROR: sort failed: c[%d].col[0]=%d > c[%d].col[0]=%d\n", + get_progname(), + j, c[j].col[0], j-1, c[j-1].col[0] + ); + return XYT_NULL; + } + if ( c[j].col[0] == c[j-1].col[0] && c[j].col[1] < c[j-1].col[1] ) { + fprintf( stderr, "%s: ERROR: sort failed: c[%d].col[0]=%d == c[%d].col[0]=%d; c[%d].col[0]=%d == c[%d].col[0]=%d\n", + get_progname(), + j, c[j].col[0], j-1, c[j-1].col[0], + j, c[j].col[1], j-1, c[j-1].col[1] + ); + return XYT_NULL; + } + } + } +} + + + +s = (struct xyt_struct *) malloc( sizeof( struct xyt_struct ) ); +if ( s == XYT_NULL ) { + fprintf( stderr, "%s: ERROR: malloc() failure while loading minutiae file \"%s\" failed: %s\n", + get_progname(), + xyt_file, + strerror(errno) + ); + return XYT_NULL; +} + + + +for ( j = 0; j < nminutiae; j++ ) { + s->xcol[j] = c[j].col[0]; + s->ycol[j] = c[j].col[1]; + s->thetacol[j] = c[j].col[2]; +} +s->nrows = nminutiae; + + + + +if ( verbose_load ) + fprintf( stderr, "Loaded %s\n", xyt_file ); + +return s; +} + +/***********************************************************************/ +#ifdef PARALLEL_SEARCH +int fd_readable( int fd ) +{ +int retval; +fd_set rfds; +struct timeval tv; + + +FD_ZERO( &rfds ); +FD_SET( fd, &rfds ); +tv.tv_sec = 0; +tv.tv_usec = 0; + +retval = select( fd+1, &rfds, NULL, NULL, &tv ); + +if ( retval < 0 ) { + perror( "select() failed" ); + return 0; +} + +if ( FD_ISSET( fd, &rfds ) ) { + /*fprintf( stderr, "data is available now.\n" );*/ + return 1; +} + +/* fprintf( stderr, "no data is available\n" ); */ +return 0; +} +#endif --- libfprint-20081125git.orig/libfprint/nbis/.svn/entries +++ libfprint-20081125git/libfprint/nbis/.svn/entries @@ -0,0 +1,37 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/libfprint/nbis +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +mindtct +dir + +include +dir + +bozorth3 +dir + --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/entries +++ libfprint-20081125git/libfprint/nbis/include/.svn/entries @@ -0,0 +1,266 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/libfprint/nbis/include +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +bz_array.h +file + + + + +2009-01-13T22:22:21.000000Z +c64a795b20953eaf26ade893661d5ae3 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2504 + +sunrast.h +file + + + + +2009-01-13T22:22:21.000000Z +0c3b451f07ed5bd6c7f5dc932fc7bd63 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +3324 + +defs.h +file + + + + +2009-01-13T22:22:21.000000Z +afe43cf603c060e83711c8a0ac2e06ec +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2301 + +log.h +file + + + + +2009-01-13T22:22:21.000000Z +2b1f96646f5879f9f1902c99d8ecb681 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +1763 + +lfs.h +file + + + + +2009-01-13T22:22:21.000000Z +2dded25c6428a5f83ca591d992af2fd3 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +44529 + +morph.h +file + + + + +2009-01-13T22:22:21.000000Z +fc4287eaa193ab25450c0d8b34135572 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +1972 + +bozorth.h +file + + + + +2009-01-13T22:22:21.000000Z +39e9940e544b5e1cb51cb11792e70b8b +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9351 + --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/log.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/log.h.svn-base @@ -0,0 +1,48 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef _LOG_H +#define _LOG_H + +/* Definitions and references to support log report files. */ +/* UPDATED: 03/16/2005 by MDG */ + +#include +#include +#include + +#ifdef LOG_REPORT +/* Uncomment the following line to enable logging. */ +#define LOG_FILE "log.txt" +#endif + +extern FILE *logfp; +extern int avrdir; +extern float dir_strength; +extern int nvalid; + +extern int open_logfile(void); +extern int close_logfile(void); +extern void print2log(char *, ...); + +#endif --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/bozorth.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/bozorth.h.svn-base @@ -0,0 +1,256 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef _BOZORTH_H +#define _BOZORTH_H + +/* The max number of points in any Probe or Gallery XYT is set to 200; */ +/* a pointwise comparison table therefore has a maximum number of: */ +/* (200^2)/2 = 20000 comparisons. */ + + +#include +#include +#include +#include /* Needed for type pid_t */ +#include + +/* If not defined in sys/param.h */ +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +/**************************************************************************/ +/* Math-Related Macros, Definitions & Prototypes */ +/**************************************************************************/ +#include + /* This macro adjusts angles to the range (-180,180] */ +#define IANGLE180(deg) ( ( (deg) > 180 ) ? ( (deg) - 360 ) : ( (deg) <= -180 ? ( (deg) + 360 ) : (deg) ) ) + +#define SENSE(a,b) ( (a) < (b) ? (-1) : ( ( (a) == (b) ) ? 0 : 1 ) ) +#define SENSE_NEG_POS(a,b) ( (a) < (b) ? (-1) : 1 ) + +#define SQUARED(n) ( (n) * (n) ) + +#ifdef ROUND_USING_LIBRARY +/* These functions should be declared in math.h: + extern float roundf( float ); + extern double round( double ); +*/ +#define ROUND(f) (roundf(f)) +#else +#define ROUND(f) ( ( (f) < 0.0F ) ? ( (int) ( (f) - 0.5F ) ) : ( (int) ( (f) + 0.5F ) ) ) +#endif + +/* PI is used in: bozorth3.c, comp.c */ +#ifdef M_PI +#define PI M_PI +#define PI_SINGLE ( (float) PI ) +#else +#define PI 3.14159 +#define PI_SINGLE 3.14159F +#endif + +/* Provide prototype for atanf() */ +extern float atanf( float ); + +/**************************************************************************/ +/* Array Length Definitions */ +/**************************************************************************/ +#include + + +/**************************************************************************/ +/**************************************************************************/ + /* GENERAL DEFINITIONS */ +/**************************************************************************/ + +#define FPNULL ((FILE *) NULL) +#define CNULL ((char *) NULL) + +#define PROGRAM "bozorth3" + +#define MAX_LINE_LENGTH 1024 + +#define SCOREFILE_EXTENSION ".scr" + +#define MAX_FILELIST_LENGTH 10000 + +#define DEFAULT_BOZORTH_MINUTIAE 150 +#define MAX_BOZORTH_MINUTIAE 200 +#define MIN_BOZORTH_MINUTIAE 0 +#define MIN_COMPUTABLE_BOZORTH_MINUTIAE 10 + +#define DEFAULT_MAX_MATCH_SCORE 400 +#define ZERO_MATCH_SCORE 0 + +#define DEFAULT_SCORE_LINE_FORMAT "s" + +#define DM 125 +#define FD 5625 +#define FDD 500 +#define TK 0.05F +#define TXS 121 +#define CTXS 121801 +#define MSTR 3 +#define MMSTR 8 +#define WWIM 10 + +#define QQ_SIZE 4000 + +#define QQ_OVERFLOW_SCORE QQ_SIZE + +/**************************************************************************/ +/**************************************************************************/ + /* MACROS DEFINITIONS */ +/**************************************************************************/ +#define INT_SET(dst,count,value) { \ + int * int_set_dst = (dst); \ + int int_set_count = (count); \ + int int_set_value = (value); \ + while ( int_set_count-- > 0 ) \ + *int_set_dst++ = int_set_value; \ + } + +/* The code that calls it assumed dst gets bumped, so don't assign to a local variable */ +#define INT_COPY(dst,src,count) { \ + int * int_copy_src = (src); \ + int int_copy_count = (count); \ + while ( int_copy_count-- > 0 ) \ + *dst++ = *int_copy_src++; \ + } + + +/**************************************************************************/ +/**************************************************************************/ + /* STRUCTURES & TYPEDEFS */ +/**************************************************************************/ + +/**************************************************************************/ +/* In BZ_SORT.C - supports stdlib qsort() and customized quicksort */ +/**************************************************************************/ + +/* Used by call to stdlib qsort() */ +struct minutiae_struct { + int col[4]; +}; + +/* Used by custom quicksort */ +#define BZ_STACKSIZE 1000 +struct cell { + int index; /* pointer to an array of pointers to index arrays */ + int item; /* pointer to an item array */ +}; + +/**************************************************************************/ +/* In BZ_IO : Supports the loading and manipulation of XYT data */ +/**************************************************************************/ +#define MAX_FILE_MINUTIAE 1000 /* bz_load() */ + +struct xyt_struct { + int nrows; + int xcol[ MAX_BOZORTH_MINUTIAE ]; + int ycol[ MAX_BOZORTH_MINUTIAE ]; + int thetacol[ MAX_BOZORTH_MINUTIAE ]; +}; + +#define XYT_NULL ( (struct xyt_struct *) NULL ) /* bz_load() */ + + +/**************************************************************************/ +/**************************************************************************/ + /* GLOBAL VARIABLES */ +/**************************************************************************/ + +/**************************************************************************/ +/* In: SRC/BIN/BOZORTH3/BOZORTH3.C */ +/**************************************************************************/ +/* Globals supporting command line options */ +extern int verbose_threshold; + +/**************************************************************************/ +/* In: BZ_GBLS.C */ +/**************************************************************************/ +/* Global arrays supporting "core" bozorth algorithm */ +extern int colp[ COLP_SIZE_1 ][ COLP_SIZE_2 ]; +extern int scols[ SCOLS_SIZE_1 ][ COLS_SIZE_2 ]; +extern int fcols[ FCOLS_SIZE_1 ][ COLS_SIZE_2 ]; +extern int * scolpt[ SCOLPT_SIZE ]; +extern int * fcolpt[ FCOLPT_SIZE ]; +extern int sc[ SC_SIZE ]; +extern int yl[ YL_SIZE_1 ][ YL_SIZE_2 ]; +/* Global arrays supporting "core" bozorth algorithm continued: */ +/* Globals used significantly by sift() */ +extern int rq[ RQ_SIZE ]; +extern int tq[ TQ_SIZE ]; +extern int zz[ ZZ_SIZE ]; +extern int rx[ RX_SIZE ]; +extern int mm[ MM_SIZE ]; +extern int nn[ NN_SIZE ]; +extern int qq[ QQ_SIZE ]; +extern int rk[ RK_SIZE ]; +extern int cp[ CP_SIZE ]; +extern int rp[ RP_SIZE ]; +extern int rf[RF_SIZE_1][RF_SIZE_2]; +extern int cf[CF_SIZE_1][CF_SIZE_2]; +extern int y[20000]; + +/**************************************************************************/ +/**************************************************************************/ +/* ROUTINE PROTOTYPES */ +/**************************************************************************/ +/* In: BZ_DRVRS.C */ +extern int bozorth_probe_init( struct xyt_struct *); +extern int bozorth_gallery_init( struct xyt_struct *); +extern int bozorth_to_gallery(int, struct xyt_struct *, struct xyt_struct *); +extern int bozorth_main(struct xyt_struct *, struct xyt_struct *); +/* In: BOZORTH3.C */ +extern void bz_comp(int, int [], int [], int [], int *, int [][COLS_SIZE_2], + int *[]); +extern void bz_find(int *, int *[]); +extern int bz_match(int, int); +extern int bz_match_score(int, struct xyt_struct *, struct xyt_struct *); +extern void bz_sift(int *, int, int *, int, int, int, int *, int *); +/* In: BZ_ALLOC.C */ +extern char *malloc_or_exit(int, const char *); +extern char *malloc_or_return_error(int, const char *); +/* In: BZ_IO.C */ +extern int parse_line_range(const char *, int *, int *); +extern void set_progname(int, char *, pid_t); +extern void set_probe_filename(char *); +extern void set_gallery_filename(char *); +extern char *get_progname(void); +extern char *get_probe_filename(void); +extern char *get_gallery_filename(void); +extern char *get_next_file(char *, FILE *, FILE *, int *, int *, char *, + int, char **, int *, int *, int, int); +extern char *get_score_filename(const char *, const char *); +extern char *get_score_line(const char *, const char *, int, int, const char *); +extern struct xyt_struct *bz_load(const char *); +extern int fd_readable(int); +/* In: BZ_SORT.C */ +extern int sort_quality_decreasing(const void *, const void *); +extern int sort_x_y(const void *, const void *); +extern int sort_order_decreasing(int [], int, int []); + +#endif /* !_BOZORTH_H */ --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/morph.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/morph.h.svn-base @@ -0,0 +1,39 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef __MORPH_H__ +#define __MORPH_H__ + +/* Modified 10/26/1999 by MDG to avoid indisciminate erosion of pixels */ +/* along the edge of the binary image. */ + +extern void erode_charimage_2(unsigned char *, unsigned char *, + const int, const int); +extern void dilate_charimage_2(unsigned char *, unsigned char *, + const int, const int); +extern char get_south8_2(char *, const int, const int, const int, const int); +extern char get_north8_2(char *, const int, const int, const int); +extern char get_east8_2(char *, const int, const int, const int); +extern char get_west8_2(char *, const int, const int); + +#endif /* !__MORPH_H__ */ --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/defs.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/defs.h.svn-base @@ -0,0 +1,63 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef _DEFS_H +#define _DEFS_H + +/*********************************************************************/ +/* General Purpose Defines */ +/*********************************************************************/ +#ifndef True +#define True 1 +#define False 0 +#endif +#ifndef TRUE +#define TRUE True +#define FALSE False +#endif +#define Yes True +#define No False +#define Empty NULL +#ifndef None +#define None -1 +#endif +#ifndef FOUND +#define FOUND 1 +#endif +#define NOT_FOUND_NEG -1 +#define EOL EOF +#ifndef DEG2RAD +#define DEG2RAD (double)(57.29578) +#endif +#define max(a, b) ((a) > (b) ? (a) : (b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define sround(x) ((int) (((x)<0) ? (x)-0.5 : (x)+0.5)) +#define sround_uint(x) ((unsigned int) (((x)<0) ? (x)-0.5 : (x)+0.5)) +#define xor(a, b) (!(a && b) && (a || b)) +#define align_to_16(_v_) ((((_v_)+15)>>4)<<4) +#define align_to_32(_v_) ((((_v_)+31)>>5)<<5) +#ifndef CHUNKS +#define CHUNKS 100 +#endif + +#endif /* !_DEFS_H */ --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/lfs.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/lfs.h.svn-base @@ -0,0 +1,1032 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef _LFS_H +#define _LFS_H + +/*********************************************************************** + PACKAGE: NIST Latent Fingerprint System + AUTHOR: Michael D. Garris + DATE: 03/16/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 10/26/1999 by MDG + Comments added to guide changes to blocksize + or number of detected directions. + UPDATED: 03/11/2005 by MDG + + FILE: LFS.H + + Contains all custom structure definitions, constant definitions, + external function definitions, and external global variable + definitions required by the NIST Latent Fingerprint System (LFS). +***********************************************************************/ + +#include +#include +#include + +/*************************************************************************/ +/* OUTPUT FILE EXTENSIONS */ +/*************************************************************************/ +#define MIN_TXT_EXT "min" +#define LOW_CONTRAST_MAP_EXT "lcm" +#define HIGH_CURVE_MAP_EXT "hcm" +#define DIRECTION_MAP_EXT "dm" +#define LOW_FLOW_MAP_EXT "lfm" +#define QUALITY_MAP_EXT "qm" +#define AN2K_OUT_EXT "mdt" +#define BINARY_IMG_EXT "brw" +#define XYT_EXT "xyt" + +/*************************************************************************/ +/* MINUTIAE XYT REPRESENTATION SCHEMES */ +/*************************************************************************/ +#define NIST_INTERNAL_XYT_REP 0 +#define M1_XYT_REP 1 + +/*************************************************************************/ +/* MACRO DEFINITIONS */ +/*************************************************************************/ + +#define max(a, b) ((a) > (b) ? (a) : (b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define sround(x) ((int) (((x)<0) ? (x)-0.5 : (x)+0.5)) +#define trunc_dbl_precision(x, scale) ((double) (((x)<0.0) \ + ? ((int)(((x)*(scale))-0.5))/(scale) \ + : ((int)(((x)*(scale))+0.5))/(scale))) + +#ifndef M_PI +#define M_PI 3.14159265358979323846 /* pi */ +#endif + +/*************************************************************************/ +/* STRUCTURE DEFINITIONS */ +/*************************************************************************/ + +/* Lookup tables for converting from integer directions */ +/* to angles in radians. */ +typedef struct dir2rad{ + int ndirs; + double *cos; + double *sin; +} DIR2RAD; + +/* DFT wave form structure containing both cosine and */ +/* sine components for a specific frequency. */ +typedef struct dftwave{ + double *cos; + double *sin; +} DFTWAVE; + +/* DFT wave forms structure containing all wave forms */ +/* to be used in DFT analysis. */ +typedef struct dftwaves{ + int nwaves; + int wavelen; + DFTWAVE **waves; +}DFTWAVES; + +/* Rotated pixel offsets for a grid of specified dimensions */ +/* rotated at a specified number of different orientations */ +/* (directions). This structure used by the DFT analysis */ +/* when generating a Direction Map and also for conducting */ +/* isotropic binarization. */ +typedef struct rotgrids{ + int pad; + int relative2; + double start_angle; + int ngrids; + int grid_w; + int grid_h; + int **grids; +} ROTGRIDS; + +/*************************************************************************/ +/* 10, 2X3 pixel pair feature patterns used to define ridge endings */ +/* and bifurcations. */ +/* 2nd pixel pair is permitted to repeat multiple times in match. */ +#define NFEATURES 10 +#define BIFURCATION 0 +#define RIDGE_ENDING 1 +#define DISAPPEARING 0 +#define APPEARING 1 + +typedef struct fp_minutia MINUTIA; +typedef struct fp_minutiae MINUTIAE; + +typedef struct feature_pattern{ + int type; + int appearing; + int first[2]; + int second[2]; + int third[2]; +} FEATURE_PATTERN; + +/* SHAPE structure definitions. */ +typedef struct rows{ + int y; /* Y-coord of current row in shape. */ + int *xs; /* X-coords for shape contour points on current row. */ + int alloc; /* Number of points allocate for x-coords on row. */ + int npts; /* Number of points assigned for x-coords on row. */ +} ROW; + +typedef struct shape{ + int ymin; /* Y-coord of top-most scanline in shape. */ + int ymax; /* Y-coord of bottom-most scanline in shape. */ + ROW **rows; /* List of row pointers comprising the shape. */ + int alloc; /* Number of rows allocated for shape. */ + int nrows; /* Number of rows assigned to shape. */ +} SHAPE; + +/* Parameters used by LFS for setting thresholds and */ +/* defining testing criterion. */ +typedef struct lfsparms{ + /* Image Controls */ + int pad_value; + int join_line_radius; + + /* Map Controls */ + int blocksize; /* Pixel dimension image block. */ + int windowsize; /* Pixel dimension window surrounding block. */ + int windowoffset; /* Offset in X & Y from block to window origin. */ + int num_directions; + double start_dir_angle; + int rmv_valid_nbr_min; + double dir_strength_min; + int dir_distance_max; + int smth_valid_nbr_min; + int vort_valid_nbr_min; + int highcurv_vorticity_min; + int highcurv_curvature_min; + int min_interpolate_nbrs; + int percentile_min_max; + int min_contrast_delta; + + /* DFT Controls */ + int num_dft_waves; + double powmax_min; + double pownorm_min; + double powmax_max; + int fork_interval; + double fork_pct_powmax; + double fork_pct_pownorm; + + /* Binarization Controls */ + int dirbin_grid_w; + int dirbin_grid_h; + int isobin_grid_dim; + int num_fill_holes; + + /* Minutiae Detection Controls */ + int max_minutia_delta; + double max_high_curve_theta; + int high_curve_half_contour; + int min_loop_len; + double min_loop_aspect_dist; + double min_loop_aspect_ratio; + + /* Minutiae Link Controls */ + int link_table_dim; + int max_link_dist; + int min_theta_dist; + int maxtrans; + double score_theta_norm; + double score_dist_norm; + double score_dist_weight; + double score_numerator; + + /* False Minutiae Removal Controls */ + int max_rmtest_dist; + int max_hook_len; + int max_half_loop; + int trans_dir_pix; + int small_loop_len; + int side_half_contour; + int inv_block_margin; + int rm_valid_nbr_min; + int max_overlap_dist; + int max_overlap_join_dist; + int malformation_steps_1; + int malformation_steps_2; + double min_malformation_ratio; + int max_malformation_dist; + int pores_trans_r; + int pores_perp_steps; + int pores_steps_fwd; + int pores_steps_bwd; + double pores_min_dist2; + double pores_max_ratio; + + /* Ridge Counting Controls */ + int max_nbrs; + int max_ridge_steps; +} LFSPARMS; + +/*************************************************************************/ +/* LFS CONSTANT DEFINITIONS */ +/*************************************************************************/ + +/***** IMAGE CONSTANTS *****/ + +#ifndef DEFAULT_PPI +#define DEFAULT_PPI 500 +#endif + +/* Intensity used to fill padded image area */ +#define PAD_VALUE 128 /* medium gray @ 8 bits */ + +/* Intensity used to draw on grayscale images */ +#define DRAW_PIXEL 255 /* white in 8 bits */ + +/* Definitions for 8-bit binary pixel intensities. */ +#define WHITE_PIXEL 255 +#define BLACK_PIXEL 0 + +/* Definitions for controlling join_miutia(). */ +/* Draw without opposite perimeter pixels. */ +#define NO_BOUNDARY 0 + +/* Draw with opposite perimeter pixels. */ +#define WITH_BOUNDARY 1 + +/* Radial width added to join line (not including the boundary pixels). */ +#define JOIN_LINE_RADIUS 1 + + +/***** MAP CONSTANTS *****/ + +/* Map value for not well-defined directions */ +#define INVALID_DIR -1 + +/* Map value assigned when the current block has no neighbors */ +/* with valid direction. */ +#define NO_VALID_NBRS -3 + +/* Map value designating a block is near a high-curvature */ +/* area such as a core or delta. */ +#define HIGH_CURVATURE -2 + +/* This specifies the pixel dimensions of each block in the IMAP */ +#define IMAP_BLOCKSIZE 24 + +/* Pixel dimension of image blocks. The following three constants work */ +/* together to define a system of 8X8 adjacent and non-overlapping */ +/* blocks that are assigned results from analyzing a larger 24X24 */ +/* window centered about each of the 8X8 blocks. */ +/* CAUTION: If MAP_BLOCKSIZE_V2 is changed, then the following will */ +/* likely need to be changed: MAP_WINDOWOFFSET_V2, */ +/* TRANS_DIR_PIX_V2, */ +/* INV_BLOCK_MARGIN_V2 */ +#define MAP_BLOCKSIZE_V2 8 + +/* Pixel dimension of window that surrounds the block. The result from */ +/* analyzing the content of the window is stored in the interior block. */ +#define MAP_WINDOWSIZE_V2 24 + +/* Pixel offset in X & Y from the origin of the block to the origin of */ +/* the surrounding window. */ +#define MAP_WINDOWOFFSET_V2 8 + +/* This is the number of integer directions to be used in semicircle. */ +/* CAUTION: If NUM_DIRECTIONS is changed, then the following will */ +/* likely need to be changed: HIGHCURV_VORTICITY_MIN, */ +/* HIGHCURV_CURVATURE_MIN, */ +/* FORK_INTERVAL */ +#define NUM_DIRECTIONS 16 + +/* This is the theta from which integer directions */ +/* are to begin. */ +#define START_DIR_ANGLE (double)(M_PI/2.0) /* 90 degrees */ + +/* Minimum number of valid neighbors required for a */ +/* valid block value to keep from being removed. */ +#define RMV_VALID_NBR_MIN 3 + +/* Minimum strength for a direction to be considered significant. */ +#define DIR_STRENGTH_MIN 0.2 + +/* Maximum distance allowable between valid block direction */ +/* and the average direction of its neighbors before the */ +/* direction is removed. */ +#define DIR_DISTANCE_MAX 3 + +/* Minimum number of valid neighbors required for an */ +/* INVALID block direction to receive its direction from */ +/* the average of its neighbors. */ +#define SMTH_VALID_NBR_MIN 7 + +/* Minimum number of valid neighbors required for a block */ +/* with an INVALID block direction to be measured for */ +/* vorticity. */ +#define VORT_VALID_NBR_MIN 7 + +/* The minimum vorticity value whereby an INVALID block */ +/* is determined to be high-curvature based on the directions */ +/* of it neighbors. */ +#define HIGHCURV_VORTICITY_MIN 5 + +/* The minimum curvature value whereby a VALID direction block is */ +/* determined to be high-curvature based on it value compared with */ +/* its neighbors' directions. */ +#define HIGHCURV_CURVATURE_MIN 5 + +/* Minimum number of neighbors with VALID direction for an INVALID */ +/* directon block to have its direction interpolated from those neighbors. */ +#define MIN_INTERPOLATE_NBRS 2 + +/* Definitions for creating a low contrast map. */ +/* Percentile cut off for choosing min and max pixel intensities */ +/* in a block. */ +#define PERCENTILE_MIN_MAX 10 + +/* The minimum delta between min and max percentile pixel intensities */ +/* in block for block NOT to be considered low contrast. (Note that */ +/* this value is in terms of 6-bit pixels.) */ +#define MIN_CONTRAST_DELTA 5 + + +/***** DFT CONSTANTS *****/ + +/* This specifies the number of DFT wave forms to be applied */ +#define NUM_DFT_WAVES 4 + +/* Minimum total DFT power for any given block */ +/* which is used to compute an average power. */ +/* By setting a non-zero minimum total,possible */ +/* division by zero is avoided. This value was */ +/* taken from HO39. */ +#define MIN_POWER_SUM 10.0 + +/* Thresholds and factors used by HO39. Renamed */ +/* here to give more meaning. */ + /* HO39 Name=Value */ +/* Minimum DFT power allowable in any one direction. */ +#define POWMAX_MIN 100000.0 /* thrhf=1e5f */ + +/* Minimum normalized power allowable in any one */ +/* direction. */ +#define POWNORM_MIN 3.8 /* disc=3.8f */ + +/* Maximum power allowable at the lowest frequency */ +/* DFT wave. */ +#define POWMAX_MAX 50000000.0 /* thrlf=5e7f */ + +/* Check for a fork at +- this number of units from */ +/* current integer direction. For example, */ +/* 2 dir ==> 11.25 X 2 degrees. */ +#define FORK_INTERVAL 2 + +/* Minimum DFT power allowable at fork angles is */ +/* FORK_PCT_POWMAX X block's max directional power. */ +#define FORK_PCT_POWMAX 0.7 + +/* Minimum normalized power allowable at fork angles */ +/* is FORK_PCT_POWNORM X POWNORM_MIN */ +#define FORK_PCT_POWNORM 0.75 + + +/***** BINRAIZATION CONSTANTS *****/ + +/* Directional binarization grid dimensions. */ +#define DIRBIN_GRID_W 7 +#define DIRBIN_GRID_H 9 + +/* The pixel dimension (square) of the grid used in isotropic */ +/* binarization. */ +#define ISOBIN_GRID_DIM 11 + +/* Number of passes through the resulting binary image where holes */ +/* of pixel length 1 in horizontal and vertical runs are filled. */ +#define NUM_FILL_HOLES 3 + + +/***** MINUTIAE DETECTION CONSTANTS *****/ + +/* The maximum pixel translation distance in X or Y within which */ +/* two potential minutia points are to be considered similar. */ +#define MAX_MINUTIA_DELTA 10 + +/* If the angle of a contour exceeds this angle, then it is NOT */ +/* to be considered to contain minutiae. */ +#define MAX_HIGH_CURVE_THETA (double)(M_PI/3.0) + +/* Half the length in pixels to be extracted for a high-curvature contour. */ +#define HIGH_CURVE_HALF_CONTOUR 14 + +/* Loop must be larger than this threshold (in pixels) to be considered */ +/* to contain minutiae. */ +#define MIN_LOOP_LEN 20 + +/* If loop's minimum distance half way across its contour is less than */ +/* this threshold, then loop is tested for minutiae. */ +#define MIN_LOOP_ASPECT_DIST 1.0 + +/* If ratio of loop's maximum/minimum distances half way across its */ +/* contour is >= to this threshold, then loop is tested for minutiae. */ +#define MIN_LOOP_ASPECT_RATIO 2.25 + +/* There are 10 unique feature patterns with ID = [0..9] , */ +/* so set LOOP ID to 10 (one more than max pattern ID). */ +#define LOOP_ID 10 + +/* Definitions for controlling the scanning of minutiae. */ +#define SCAN_HORIZONTAL 0 +#define SCAN_VERTICAL 1 +#define SCAN_CLOCKWISE 0 +#define SCAN_COUNTER_CLOCKWISE 1 + +/* The dimension of the chaincode loopkup matrix. */ +#define NBR8_DIM 3 + +/* Default minutiae reliability. */ +#define DEFAULT_RELIABILITY 0.99 + +/* Medium minutia reliability. */ +#define MEDIUM_RELIABILITY 0.50 + +/* High minutia reliability. */ +#define HIGH_RELIABILITY 0.99 + + +/***** MINUTIAE LINKING CONSTANTS *****/ + +/* Definitions for controlling the linking of minutiae. */ +/* Square dimensions of 2D table of potentially linked minutiae. */ +#define LINK_TABLE_DIM 20 + +/* Distance (in pixels) used to determine if the orthogonal distance */ +/* between the coordinates of 2 minutia points are sufficiently close */ +/* to be considered for linking. */ +#define MAX_LINK_DIST 20 + +/* Minimum distance (in pixels) between 2 minutia points that an angle */ +/* computed between the points may be considered reliable. */ +#define MIN_THETA_DIST 5 + +/* Maximum number of transitions along a contiguous pixel trajectory */ +/* between 2 minutia points for that trajectory to be considered "free" */ +/* of obstacles. */ +#define MAXTRANS 2 + +/* Parameters used to compute a link score between 2 minutiae. */ +#define SCORE_THETA_NORM 15.0 +#define SCORE_DIST_NORM 10.0 +#define SCORE_DIST_WEIGHT 4.0 +#define SCORE_NUMERATOR 32000.0 + + +/***** FALSE MINUTIAE REMOVAL CONSTANTS *****/ + +/* Definitions for removing hooks, islands, lakes, and overlaps. */ +/* Distance (in pixels) used to determine if the orthogonal distance */ +/* between the coordinates of 2 minutia points are sufficiently close */ +/* to be considered for removal. */ +#define MAX_RMTEST_DIST 8 + +#define MAX_RMTEST_DIST_V2 16 + +/* Length of pixel contours to be traced and analyzed for possible hooks. */ +#define MAX_HOOK_LEN 15 + +#define MAX_HOOK_LEN_V2 30 + +/* Half the maximum length of pixel contours to be traced and analyzed */ +/* for possible loops (islands/lakes). */ +#define MAX_HALF_LOOP 15 + +#define MAX_HALF_LOOP_V2 30 + +/* Definitions for removing minutiae that are sufficiently close and */ +/* point to a block with invalid ridge flow. */ +/* Distance (in pixels) in direction opposite the minutia to be */ +/* considered sufficiently close to an invalid block. */ +#define TRANS_DIR_PIX 6 + +#define TRANS_DIR_PIX_V2 4 + +/* Definitions for removing small holes (islands/lakes). */ +/* Maximum circumference (in pixels) of qualifying loops. */ +#define SMALL_LOOP_LEN 15 + +/* Definitions for removing or adusting side minutiae. */ +/* Half the number of pixels to be traced to form a complete contour. */ +#define SIDE_HALF_CONTOUR 7 + +/* Definitions for removing minutiae near invalid blocks. */ +/* Maximum orthogonal distance a minutia can be neighboring a block with */ +/* invalid ridge flow in order to be removed. */ +#define INV_BLOCK_MARGIN 6 + +#define INV_BLOCK_MARGIN_V2 4 + +/* Given a sufficiently close, neighboring invalid block, if that invalid */ +/* block has a total number of neighboring blocks with valid ridge flow */ +/* less than this threshold, then the minutia point is removed. */ +#define RM_VALID_NBR_MIN 7 + +/* Definitions for removing overlaps. */ +/* Maximum pixel distance between 2 points to be tested for overlapping */ +/* conditions. */ +#define MAX_OVERLAP_DIST 8 + +/* Maximum pixel distance between 2 points on opposite sides of an overlap */ +/* will be joined. */ +#define MAX_OVERLAP_JOIN_DIST 6 + +/* Definitions for removing "irregularly-shaped" minutiae. */ +/* Contour steps to be traced to 1st measuring point. */ +#define MALFORMATION_STEPS_1 10 +/* Contour steps to be traced to 2nd measuring point. */ +#define MALFORMATION_STEPS_2 20 +/* Minimum ratio of distances across feature at the two point to be */ +/* considered normal. */ +#define MIN_MALFORMATION_RATIO 2.0 +/* Maximum distance permitted across feature to be considered normal. */ +#define MAX_MALFORMATION_DIST 20 + +/* Definitions for removing minutiae on pores. */ +/* Translation distance (in pixels) from minutia point in opposite direction */ +/* in order to get off a valley edge and into the neighboring ridge. */ +#define PORES_TRANS_R 3 + +/* Number of steps (in pixels) to search for edge of current ridge. */ +#define PORES_PERP_STEPS 12 + +/* Number of pixels to be traced to find forward contour points. */ +#define PORES_STEPS_FWD 10 + +/* Number of pixels to be traced to find backward contour points. */ +#define PORES_STEPS_BWD 8 + +/* Minimum squared distance between points before being considered zero. */ +#define PORES_MIN_DIST2 0.5 + +/* Max ratio of computed distances between pairs of forward and backward */ +/* contour points to be considered a pore. */ +#define PORES_MAX_RATIO 2.25 + + +/***** RIDGE COUNTING CONSTANTS *****/ + +/* Definitions for detecting nearest neighbors and counting ridges. */ +/* Maximum number of nearest neighbors per minutia. */ +#define MAX_NBRS 5 + +/* Maximum number of contour steps taken to validate a ridge crossing. */ +#define MAX_RIDGE_STEPS 10 + +/*************************************************************************/ +/* QUALITY/RELIABILITY DEFINITIONS */ +/*************************************************************************/ +/* Quality map levels */ +#define QMAP_LEVELS 5 + +/* Neighborhood radius in millimeters computed from 11 pixles */ +/* scanned at 19.69 pixels/mm. */ +#define RADIUS_MM ((double)(11.0 / 19.69)) + +/* Ideal Standard Deviation of pixel values in a neighborhood. */ +#define IDEALSTDEV 64 +/* Ideal Mean of pixel values in a neighborhood. */ +#define IDEALMEAN 127 + +/* Look for neighbors this many blocks away. */ +#define NEIGHBOR_DELTA 2 + +/*************************************************************************/ +/* GENERAL DEFINITIONS */ +/*************************************************************************/ +#define LFS_VERSION_STR "NIST_LFS_VER2" + +/* This factor converts degrees to radians. */ +#ifndef DEG2RAD +#define DEG2RAD (double)(M_PI/180.0) +#endif + +#define NORTH 0 +#define SOUTH 4 +#define EAST 2 +#define WEST 6 + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef FOUND +#define FOUND TRUE +#endif +#ifndef NOT_FOUND +#define NOT_FOUND FALSE +#endif + +#define HOOK_FOUND 1 +#define LOOP_FOUND 1 +#define IGNORE 2 +#define LIST_FULL 3 +#define INCOMPLETE 3 + +/* Pixel value limit in 6-bit image. */ +#define IMG_6BIT_PIX_LIMIT 64 + +/* Maximum number (or reallocated chunks) of minutia to be detected */ +/* in an image. */ +#define MAX_MINUTIAE 1000 + +/* If both deltas in X and Y for a line of specified slope is less than */ +/* this threshold, then the angle for the line is set to 0 radians. */ +#define MIN_SLOPE_DELTA 0.5 + +/* Designates that rotated grid offsets should be relative */ +/* to the grid's center. */ +#define RELATIVE2CENTER 0 + +/* Designates that rotated grid offsets should be relative */ +/* to the grid's origin. */ +#define RELATIVE2ORIGIN 1 + +/* Truncate floating point precision by multiply, rounding, and then */ +/* dividing by this value. This enables consistant results across */ +/* different computer architectures. */ +#define TRUNC_SCALE 16384.0 + +/* Designates passed argument as undefined. */ +#define UNDEFINED -1 + +/* Dummy values for unused LFS control parameters. */ +#define UNUSED_INT 0 +#define UNUSED_DBL 0.0 + +/*************************************************************************/ +/* EXTERNAL FUNCTION DEFINITIONS */ +/*************************************************************************/ + +/* binar.c */ +extern int binarize_V2(unsigned char **, int *, int *, + unsigned char *, const int, const int, + int *, const int, const int, + const ROTGRIDS *, const LFSPARMS *); +extern int binarize_image_V2(unsigned char **, int *, int *, + unsigned char *, const int, const int, + const int *, const int, const int, + const int, const ROTGRIDS *); +extern int dirbinarize(const unsigned char *, const int, const ROTGRIDS *); + +/* block.c */ +extern int block_offsets(int **, int *, int *, const int, const int, + const int, const int); +extern int low_contrast_block(const int, const int, + unsigned char *, const int, const int, const LFSPARMS *); +extern int find_valid_block(int *, int *, int *, int *, int *, + const int, const int, const int, const int, + const int, const int); +extern void set_margin_blocks(int *, const int, const int, const int); + +/* contour.c */ +int allocate_contour(int **ocontour_x, int **ocontour_y, + int **ocontour_ex, int **ocontour_ey, const int ncontour); +extern void free_contour(int *, int *, int *, int *); +extern int get_high_curvature_contour(int **, int **, int **, int **, int *, + const int, const int, const int, const int, const int, + unsigned char *, const int, const int); +extern int get_centered_contour(int **, int **, int **, int **, int *, + const int, const int, const int, const int, const int, + unsigned char *, const int, const int); +extern int trace_contour(int **, int **, int **, int **, int *, + const int, const int, const int, const int, const int, + const int, const int, const int, + unsigned char *, const int, const int); +extern int search_contour(const int, const int, const int, + const int, const int, const int, const int, const int, + unsigned char *, const int, const int); +extern int min_contour_theta(int *, double *, const int, const int *, + const int *, const int); +extern void contour_limits(int *, int *, int *, int *, const int *, + const int *, const int); +extern void fix_edge_pixel_pair(int *, int *, int *, int *, + unsigned char *, const int, const int); + +/* detect.c */ +extern int get_minutiae(MINUTIAE **, int **, int **, int **, + int **, int **, int *, int *, + unsigned char **, int *, int *, int *, + unsigned char *, const int, const int, + const int, const double, const LFSPARMS *); + +/* dft.c */ +extern int dft_dir_powers(double **, unsigned char *, const int, + const int, const int, const DFTWAVES *, + const ROTGRIDS *); +extern int dft_power_stats(int *, double *, int *, double *, double **, + const int, const int, const int); + +/* free.c */ +extern void free_dir2rad(DIR2RAD *); +extern void free_dftwaves(DFTWAVES *); +extern void free_rotgrids(ROTGRIDS *); +extern void free_dir_powers(double **, const int); + +/* imgutil.c */ +extern void bits_6to8(unsigned char *, const int, const int); +extern void bits_8to6(unsigned char *, const int, const int); +extern void gray2bin(const int, const int, const int, + unsigned char *, const int, const int); +extern int pad_uchar_image(unsigned char **, int *, int *, + unsigned char *, const int, const int, const int, + const int); +extern void fill_holes(unsigned char *, const int, const int); +extern int free_path(const int, const int, const int, const int, + unsigned char *, const int, const int, const LFSPARMS *); +extern int search_in_direction(int *, int *, int *, int *, const int, + const int, const int, const double, const double, + const int, unsigned char *, const int, const int); + +/* init.c */ +extern int init_dir2rad(DIR2RAD **, const int); +extern int init_dftwaves(DFTWAVES **, const double *, const int, const int); +extern int get_max_padding_V2(const int, const int, const int, const int); +extern int init_rotgrids(ROTGRIDS **, const int, const int, const int, + const double, const int, const int, const int, const int); +extern int alloc_dir_powers(double ***, const int, const int); +extern int alloc_power_stats(int **, double **, int **, double **, const int); + +/* line.c */ +extern int line_points(int **, int **, int *, + const int, const int, const int, const int); + +/* loop.c */ +extern int get_loop_list(int **, MINUTIAE *, const int, unsigned char *, + const int, const int); +extern int on_loop(const MINUTIA *, const int, unsigned char *, const int, + const int); +extern int on_island_lake(int **, int **, int **, int **, int *, + const MINUTIA *, const MINUTIA *, const int, + unsigned char *, const int, const int); +extern int on_hook(const MINUTIA *, const MINUTIA *, const int, + unsigned char *, const int, const int); +extern int is_loop_clockwise(const int *, const int *, const int, const int); +extern int process_loop(MINUTIAE *, const int *, const int *, + const int *, const int *, const int, + unsigned char *, const int, const int, const LFSPARMS *); +extern int process_loop_V2(MINUTIAE *, const int *, const int *, + const int *, const int *, const int, + unsigned char *, const int, const int, + int *, const LFSPARMS *); +extern int fill_loop(const int *, const int *, const int, + unsigned char *, const int, const int); + +/* maps.c */ +extern int gen_image_maps(int **, int **, int **, int **, int *, int *, + unsigned char *, const int, const int, + const DIR2RAD *, const DFTWAVES *, + const ROTGRIDS *, const LFSPARMS *); +extern int gen_initial_maps(int **, int **, int **, + int *, const int, const int, + unsigned char *, const int, const int, + const DFTWAVES *, const ROTGRIDS *, const LFSPARMS *); +extern int interpolate_direction_map(int *, int *, const int, const int, + const LFSPARMS *); +extern int morph_TF_map(int *, const int, const int, const LFSPARMS *); +extern int pixelize_map(int **, const int, const int, + int *, const int, const int, const int); +extern void smooth_direction_map(int *, int *, const int, const int, + const DIR2RAD *, const LFSPARMS *); +extern int gen_high_curve_map(int **, int *, const int, const int, + const LFSPARMS *); +extern int gen_initial_imap(int **, int *, const int, const int, + unsigned char *, const int, const int, + const DFTWAVES *, const ROTGRIDS *, const LFSPARMS *); +extern int primary_dir_test(double **, const int *, const double *, + const int *, const double *, const int, + const LFSPARMS *); +extern int secondary_fork_test(double **, const int *, const double *, + const int *, const double *, const int, + const LFSPARMS *); +extern void remove_incon_dirs(int *, const int, const int, + const DIR2RAD *, const LFSPARMS *); +extern int test_top_edge(const int, const int, const int, const int, + int *, const int, const int, const DIR2RAD *, + const LFSPARMS *); +extern int test_right_edge(const int, const int, const int, const int, + int *, const int, const int, const DIR2RAD *, + const LFSPARMS *); +extern int test_bottom_edge(const int, const int, const int, const int, + int *, const int, const int, const DIR2RAD *, + const LFSPARMS *); +extern int test_left_edge(const int, const int, const int, const int, + int *, const int, const int, const DIR2RAD *, + const LFSPARMS *); +extern int remove_dir(int *, const int, const int, const int, const int, + const DIR2RAD *, const LFSPARMS *); +extern void average_8nbr_dir(int *, double *, int *, int *, const int, + const int, const int, const int, const DIR2RAD *); +extern int num_valid_8nbrs(int *, const int, const int, const int, const int); +extern void smooth_imap(int *, const int, const int, const DIR2RAD *, + const LFSPARMS *); +extern int vorticity(int *, const int, const int, const int, const int, + const int); +extern void accum_nbr_vorticity(int *, const int, const int, const int); +extern int curvature(int *, const int, const int, const int, const int, + const int); + +/* matchpat.c */ +extern int match_1st_pair(unsigned char, unsigned char, int *, int *); +extern int match_2nd_pair(unsigned char, unsigned char, int *, int *); +extern int match_3rd_pair(unsigned char, unsigned char, int *, int *); +extern void skip_repeated_horizontal_pair(int *, const int, + unsigned char **, unsigned char **, const int, const int); +extern void skip_repeated_vertical_pair(int *, const int, + unsigned char **, unsigned char **, const int, const int); + +/* minutia.c */ +extern int alloc_minutiae(MINUTIAE **, const int); +extern int realloc_minutiae(MINUTIAE *, const int); +extern int detect_minutiae_V2(MINUTIAE *, + unsigned char *, const int, const int, + int *, int *, int *, const int, const int, + const LFSPARMS *); +extern int update_minutiae(MINUTIAE *, MINUTIA *, unsigned char *, + const int, const int, const LFSPARMS *); +extern int update_minutiae_V2(MINUTIAE *, MINUTIA *, const int, const int, + unsigned char *, const int, const int, + const LFSPARMS *); +extern int sort_minutiae(MINUTIAE *, const int, const int); +extern int sort_minutiae_y_x(MINUTIAE *, const int, const int); +extern int sort_minutiae_x_y(MINUTIAE *, const int, const int); +extern int rm_dup_minutiae(MINUTIAE *); +extern void dump_minutiae(FILE *, const MINUTIAE *); +extern void dump_minutiae_pts(FILE *, const MINUTIAE *); +extern void dump_reliable_minutiae_pts(FILE *, const MINUTIAE *, const double); +extern int create_minutia(MINUTIA **, const int, const int, + const int, const int, const int, const double, + const int, const int, const int); +extern void free_minutiae(MINUTIAE *); +extern void free_minutia(MINUTIA *); +extern int remove_minutia(const int, MINUTIAE *); +extern int join_minutia(const MINUTIA *, const MINUTIA *, unsigned char *, + const int, const int, const int, const int); +extern int minutia_type(const int); +extern int is_minutia_appearing(const int, const int, const int, const int); +extern int choose_scan_direction(const int, const int); +int scan4minutiae(MINUTIAE *, unsigned char *, const int, const int, + const int *, const int *, const int, const int, + const int, const int, const int, const int, + const int, const int, const int, const LFSPARMS *); +extern int scan4minutiae_horizontally(MINUTIAE *, unsigned char *, + const int, const int, const int, const int, + const int, const int, const int, const int, + const LFSPARMS *); +extern int scan4minutiae_horizontally_V2(MINUTIAE *, + unsigned char *, const int, const int, + int *, int *, int *, + const LFSPARMS *); +extern int scan4minutiae_vertically(MINUTIAE *, unsigned char *, + const int, const int, const int, const int, + const int, const int, const int, const int, + const LFSPARMS *); +extern int rescan4minutiae_horizontally(MINUTIAE *, unsigned char *bdata, + const int, const int, const int *, const int *, + const int, const int, const int, const int, + const int, const int, const int, const int, + const LFSPARMS *); +extern int scan4minutiae_vertically_V2(MINUTIAE *, + unsigned char *, const int, const int, + int *, int *, int *, const LFSPARMS *); +extern int rescan4minutiae_vertically(MINUTIAE *, unsigned char *, + const int, const int, const int *, const int *, + const int, const int, const int, const int, + const int, const int, const int, const int, + const LFSPARMS *); +extern int rescan_partial_horizontally(const int, MINUTIAE *, + unsigned char *, const int, const int, + const int *, const int *, + const int, const int, const int, const int, + const int, const int, const int, const int, + const LFSPARMS *); +extern int rescan_partial_vertically(const int, MINUTIAE *, + unsigned char *, const int, const int, + const int *, const int *, + const int, const int, const int, const int, + const int, const int, const int, const int, + const LFSPARMS *); +extern int get_nbr_block_index(int *, const int, const int, const int, + const int, const int); +extern int adjust_horizontal_rescan(const int, int *, int *, int *, int *, + const int, const int, const int, const int, const int); +extern int adjust_vertical_rescan(const int, int *, int *, int *, int *, + const int, const int, const int, const int, const int); +extern int process_horizontal_scan_minutia(MINUTIAE *, const int, const int, + const int, const int, + unsigned char *, const int, const int, + const int, const int, const LFSPARMS *); +extern int process_horizontal_scan_minutia_V2(MINUTIAE *, + const int, const int, const int, const int, + unsigned char *, const int, const int, + int *, int *, int *, const LFSPARMS *); +extern int process_vertical_scan_minutia(MINUTIAE *, const int, const int, + const int, const int, + unsigned char *, const int, const int, + const int, const int, const LFSPARMS *); +extern int process_vertical_scan_minutia_V2(MINUTIAE *, const int, const int, + const int, const int, + unsigned char *, const int, const int, + int *, int *, int *, const LFSPARMS *); +extern int update_minutiae_V2(MINUTIAE *, MINUTIA *, const int, const int, + unsigned char *, const int, const int, + const LFSPARMS *); +extern int adjust_high_curvature_minutia(int *, int *, int *, int *, int *, + const int, const int, const int, const int, + unsigned char *, const int, const int, + MINUTIAE *, const LFSPARMS *); +extern int adjust_high_curvature_minutia_V2(int *, int *, int *, + int *, int *, const int, const int, + const int, const int, + unsigned char *, const int, const int, + int *, MINUTIAE *, const LFSPARMS *); +extern int get_low_curvature_direction(const int, const int, const int, + const int); +void lfs2nist_minutia_XYT(int *ox, int *oy, int *ot, + const MINUTIA *minutia, const int iw, const int ih); + +/* quality.c */ +extern int gen_quality_map(int **, int *, int *, int *, int *, + const int, const int); +extern int combined_minutia_quality(MINUTIAE *, int *, const int, const int, + const int, unsigned char *, const int, const int, + const int, const double); + +/* remove.c */ +extern int remove_false_minutia(MINUTIAE *, + unsigned char *, const int, const int, + int *, const int, const int, const LFSPARMS *); +extern int remove_false_minutia_V2(MINUTIAE *, + unsigned char *, const int, const int, + int *, int *, int *, const int, const int, + const LFSPARMS *); + +/* ridges.c */ +extern int count_minutiae_ridges(MINUTIAE *, + unsigned char *, const int, const int, + const LFSPARMS *); + +/* shape.c */ +extern void free_shape(SHAPE *); +extern int shape_from_contour(SHAPE **, const int *, const int *, const int); + +/* sort.c */ +extern int sort_indices_int_inc(int **, int *, const int); +extern int sort_indices_double_inc(int **, double *, const int); +extern void bubble_sort_int_inc_2(int *, int *, const int); +extern void bubble_sort_double_inc_2(double *, int *, const int); +extern void bubble_sort_double_dec_2(double *, int *, const int); +extern void bubble_sort_int_inc(int *, const int); + +/* util.c */ +extern int maxv(const int *, const int); +extern int minv(const int *, const int); +extern int minmaxs(int **, int **, int **, int *, int *, + const int *, const int); +extern double distance(const int, const int, const int, const int); +extern double squared_distance(const int, const int, const int, const int); +extern int in_int_list(const int, const int *, const int); +extern int remove_from_int_list(const int, int *, const int); +extern int find_incr_position_dbl(const double, double *, const int); +extern double angle2line(const int, const int, const int, const int); +extern int line2direction(const int, const int, const int, const int, + const int); +extern int closest_dir_dist(const int, const int, const int); + +/*************************************************************************/ +/* EXTERNAL GLOBAL VARIABLE DEFINITIONS */ +/*************************************************************************/ +extern double dft_coefs[]; +extern LFSPARMS lfsparms; +extern LFSPARMS lfsparms_V2; +extern int nbr8_dx[]; +extern int nbr8_dy[]; +extern int chaincodes_nbr8[]; +extern FEATURE_PATTERN feature_patterns[]; + +#endif --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/sunrast.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/sunrast.h.svn-base @@ -0,0 +1,76 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef _SUNRAST_H +#define _SUNRAST_H + +/************************************************************/ +/* File Name: Sunrast.h */ +/* Package: Sun Rasterfile I/O */ +/* Author: Michael D. Garris */ +/* Date: 8/19/99 */ +/* Updated: 03/16/2005 by MDG */ +/* */ +/************************************************************/ + +/* Contains header information related to Sun Rasterfile images. */ + +typedef struct sunrasterhdr { + int magic; /* magic number */ + int width; /* width (in pixels) of image */ + int height; /* height (in pixels) of image */ + int depth; /* depth (1, 8, or 24 bits) of pixel */ + int raslength; /* length (in bytes) of image */ + int rastype; /* type of file; see SUN_* below */ + int maptype; /* type of colormap; see MAP_* below */ + int maplength; /* length (bytes) of following map */ + /* color map follows for maplength bytes, followed by image */ +} SUNHEAD; + +#define SUN_MAGIC 0x59a66a95 + + /* Sun supported ras_type's */ +#define SUN_STANDARD 1 /* Raw pixrect image in 68000 byte order */ +#define SUN_RUN_LENGTH 2 /* Run-length compression of bytes */ +#define SUN_FORMAT_RGB 3 /* XRGB or RGB instead of XBGR or BGR */ +#define SUN_FORMAT_TIFF 4 /* tiff <-> standard rasterfile */ +#define SUN_FORMAT_IFF 5 /* iff (TAAC format) <-> standard rasterfile */ + + /* Sun supported maptype's */ +#define MAP_RAW 2 +#define MAP_NONE 0 /* maplength is expected to be 0 */ +#define MAP_EQUAL_RGB 1 /* red[maplength/3],green[],blue[] */ + +/* + * NOTES: + * Each line of a bitmap image should be rounded out to a multiple + * of 16 bits. + */ + +/* sunrast.c */ +extern int ReadSunRaster(const char *, SUNHEAD **, unsigned char **, int *, + unsigned char **, int *, int *, int *, int *); +extern int WriteSunRaster(char *, unsigned char *, const int, const int, + const int); + +#endif --- libfprint-20081125git.orig/libfprint/nbis/include/.svn/text-base/bz_array.h.svn-base +++ libfprint-20081125git/libfprint/nbis/include/.svn/text-base/bz_array.h.svn-base @@ -0,0 +1,121 @@ +/******************************************************************************* + +License: +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +Disclaimer: +This software was developed to promote biometric standards and biometric +technology testing for the Federal Government in accordance with the USA +PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. +Specific hardware and software products identified in this software were used +in order to perform the software development. In no case does such +identification imply recommendation or endorsement by the National Institute +of Standards and Technology, nor does it imply that the products and equipment +identified are necessarily the best available for the purpose. + +*******************************************************************************/ + +#ifndef _BZ_ARRAY_H +#define _BZ_ARRAY_H + +#define STATIC static +/* #define BAD_BOUNDS 1 */ + +#define COLP_SIZE_1 20000 +#define COLP_SIZE_2 5 + +#define COLS_SIZE_2 6 +#define SCOLS_SIZE_1 20000 +#define FCOLS_SIZE_1 20000 + +#define SCOLPT_SIZE 20000 +#define FCOLPT_SIZE 20000 + +#define SC_SIZE 20000 + + +#define RQ_SIZE 20000 +#define TQ_SIZE 20000 +#define ZZ_SIZE 20000 + + + +#define RX_SIZE 100 +#define MM_SIZE 100 +#define NN_SIZE 20 + + + +#define RK_SIZE 20000 + + + +#define RR_SIZE 100 +#define AVN_SIZE 5 +#define AVV_SIZE_1 2000 +#define AVV_SIZE_2 5 +#define CT_SIZE 2000 +#define GCT_SIZE 2000 +#define CTT_SIZE 2000 + + +#ifdef BAD_BOUNDS +#define CTP_SIZE_1 2000 +#define CTP_SIZE_2 1000 +#else +#define CTP_SIZE_1 2000 +#define CTP_SIZE_2 2500 +#endif + + + +/* +rp[x] == ctp[][x] :: sct[x][] +*/ + + + + +#define RF_SIZE_1 100 +#define RF_SIZE_2 10 + +#define CF_SIZE_1 100 +#define CF_SIZE_2 10 + +#define Y_SIZE 20000 + + + + + + +#define YL_SIZE_1 2 +#define YL_SIZE_2 2000 + + + + +#define YY_SIZE_1 1000 +#define YY_SIZE_2 2 +#define YY_SIZE_3 2000 + + + +#ifdef BAD_BOUNDS +#define SCT_SIZE_1 1000 +#define SCT_SIZE_2 1000 +#else +#define SCT_SIZE_1 2500 +#define SCT_SIZE_2 1000 +#endif + +#define CP_SIZE 20000 +#define RP_SIZE 20000 + +#endif /* !_BZ_ARRAY_H */ --- libfprint-20081125git.orig/libfprint/drivers/.svn/entries +++ libfprint-20081125git/libfprint/drivers/.svn/entries @@ -0,0 +1,368 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/libfprint/drivers +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +uru4000.c +file + + + + +2009-01-13T22:22:22.000000Z +37a186f24512416634976caa4abb7eb8 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +32278 + +aes1610.c +file + + + + +2009-01-13T22:22:22.000000Z +441c2dc2e6d96527082313cdc06313b1 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +12551 + +aes2501.c +file + + + + +2009-01-13T22:22:22.000000Z +5b6e9ba9a719f9a032ad8bad7432a2c8 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +26452 + +fdu2000.c +file + + + + +2009-01-13T22:22:22.000000Z +0a2289c0373174d2bf090dce527a3608 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +7296 + +aes2501.h +file + + + + +2009-01-13T22:22:22.000000Z +9430eb01ca0d4b85a6a7d64f3737e5dc +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +6374 + +upeksonly.c +file + + + + +2009-01-13T22:22:22.000000Z +a99bb7f2d9d8ef57566711494ded234e +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +24600 + +upektc.c +file + + + + +2009-01-13T22:22:22.000000Z +61ce7613bee9df68d627bb95775bf741 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +22578 + +upekts.c +file + + + + +2009-01-13T22:22:22.000000Z +f1a48ae681fe15eef4954f8deef954b1 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +41363 + +aes4000.c +file + + + + +2009-01-13T22:22:22.000000Z +053b421fc079207a76f2d09dd8137ea3 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +7152 + +vcom5s.c +file + + + + +2009-01-13T22:22:22.000000Z +b9ec4c8c19f3e723e75260ffca603d3c +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9410 + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/upektc.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/upektc.c.svn-base @@ -0,0 +1,416 @@ +/* + * UPEK TouchChip driver for libfprint + * Copyright (C) 2007 Jan-Michael Brummer + * + * 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 + */ + +#define FP_COMPONENT "upektc" + +#include +#include + +#include +#include + +#include + +#define SENSOR_FULL_IMAGE 59904 +#define WAIT_COUNT 5 + +typedef char sint8; +typedef unsigned char uint8; +typedef int sint32; +typedef unsigned int uint32; + +/** scan command */ +static const unsigned char anScanCommand[ 0x40 ] = { + 0x0e, 0x00, 0x03, 0xa8, 0x00, 0xb6, 0xbb, 0xbb, + 0xb8, 0xb7, 0xb8, 0xb5, 0xb8, 0xb9, 0xb8, 0xb9, + 0xbb, 0xbb, 0xbe, 0xbb, 0x4e, 0x16, 0xf4, 0x77, + 0xa8, 0x07, 0x32, 0x00, 0x6a, 0x16, 0xf4, 0x77, + 0x78, 0x24, 0x61, 0x00, 0xc8, 0x00, 0xec, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x3c, 0xf3, 0x2f, 0x01, + 0x05, 0x90, 0xf6, 0x77, 0x84, 0xf5, 0x2f, 0x01, + 0x05, 0x90, 0xf6, 0x00, 0xc8, 0x00, 0xec, 0x00 +}; + +/** init command */ +static const unsigned char anInitCommand[ 0x40 ] = { + 0x03, 0x00, 0x00, 0x00, 0x02, 0xfb, 0x0f, 0x00, + 0xc4, 0xf9, 0x2f, 0x01, 0x6d, 0x4f, 0x01, 0x10, + 0x44, 0xf9, 0x2f, 0x01, 0x40, 0x00, 0x00, 0x00, + 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/** + * \brief Common interaktion routine for the sensor device + * \param dev fingerprint image device pointer + * \param pnRawString raw data string + * \param nLen length we want to read, if 0 do not read at all + * \param pnBuffer buffer pointer we want to store the read buffer + * \return error code + */ +static sint32 askScanner( struct fp_img_dev *dev, const unsigned char *pnRawString, sint32 nLen, sint8 *pnBuffer ) { + sint8 anBuf[ 65535 ]; + sint32 nRet; + int transferred; + struct libusb_bulk_transfer msg1 = { + .endpoint = 3, + .data = pnRawString, + .length = 0x40, + }; + struct libusb_bulk_transfer msg2 = { + .endpoint = 0x82, + .data = anBuf, + .length = nLen, + }; + + nRet = libusb_bulk_transfer(dev->udev, &msg1, &transferred, 1003); + if (transferred != 0x40) { + return -1; + } + + if ( !nLen ) { + return 0; + } + + nRet = libusb_bulk_transfer(dev->udev, &msg2, &transferred, 1003); + if ( ( transferred == nLen ) && ( pnBuffer != NULL ) ) { + memcpy( pnBuffer, anBuf, nLen ); + return transferred; + } + + return nRet; +} + +/** + * \brief Quick test if finger is on sensor + * \param pnImage image pointer + * \return 1 on yes, 0 on no + */ +static sint32 ValidScan( sint8 *pnImage ) { + sint32 nIndex, nSum; + + nSum = 0; + + for ( nIndex = 0; nIndex < SENSOR_FULL_IMAGE; nIndex++ ) { + if ( ( uint8 ) pnImage[ nIndex ] < 160 ) { + nSum++; + } + } + + return nSum < 500 ? 0 : 1; +} + +/** + * \brief Setup Sensor device + * \param dev fingerprint image device pointer + * \return error code + */ +static sint32 SetupSensor( struct fp_img_dev *dev ) { + libusb_claim_interface(dev->udev, 0); + + /* setup sensor */ + if ( askScanner( dev, "\x03\x00\x00\x00\x02\xfe\x00\x01\xc0\xbd\xf0\xff\xff\xff\xff\xff\x00\xf0\xfd\x7f\x00\x60\xfd\x7f\x14\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\xcc\xf8\x2f\x01\x09\x48\xe7\x77\xf0\xfa\x2f\x01\x09\x48\xe7\x77\xe0\x3a\xe6\x77", 0x00, NULL ) < 0 ) { + return -1; + } + + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf7\x00\x00\xc8\x01\x00\x00\x40\x00\x00\x00\x01\x00\x00\x00\x58\xf9\x2f\x01\xe9\x4f\x01\x10\xd8\xf8\x2f\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x02\xfe\x00\x01\xc0\xbd\xf0\xff\xff\xff\xff\xff\x00\xf0\xfd\x7f", 0x40, NULL ) < 0 ) { + return -2; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\xf7\xcd\x00\x2c\xf9\x2f\x01\x6d\x4f\x01\x10\xac\xf8\x2f\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x02\xfe\x16\x10\x03\xee\x00\x37\x01\x09\x02\x0e\x03\x18\x03\x1a\x03\x20\x10\x2f\x11\x3f\x12\x44\x01\x01\x07\x08\x0c\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -3; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf8\x00\x00\x02\xfe\x16\x10\x03\xee\x00\x37\x01\x09\x02\x0e\x03\x18\x03\x1a\x03\x20\x10\x2f\x11\x3f\x12\x44\x01\x01\x07\x08\x0c\x00\x6c\x6c\x00\xf9\x2f\x01\x97\x40\x01\x10\x03\x00\x00\x00\x00\x00\x00\x00\xfa\x45\x03\x10\x02\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -4; + }; + + if ( askScanner( dev, "\x8b\x00\x00\x00\x3a\x50\xf9\x2f\x01\x18\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x88\xf9\x2f\x01\x91\x99\x00\x10\xf8\x00\x00\x00\xbe\x99\x00\x10\xa0\xa6\x04\x10\x01\x9b\x00\x10\x18\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00\x00", 0x40, NULL ) < 0 ) { + return -5; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x3a\x00\x01\x02\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f\x20\x21\x22\x23\x24\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3d\x3f\xff\x00", 0x40, NULL ) < 0 ) { + return -6; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x3a\x00\x01\x02\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f\x20\x21\x22\x23\x24\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3d\x3f\xff\x00", 0x40, NULL ) < 0 ) { + return -7; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\x0d\xff\x36\xdc\xf8\x2f\x01\xf1\x9d\x00\x10\xfc\xf8\x2f\x01\x9d\xf8\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x9e\xbf\x85\x85\x02\x05\x26\x25\x4d\x13\x10\x00\x00\x00\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -8; + }; + if ( askScanner( dev, "\x03\x00\x00\x00\x0c\x37\x6a\x3d\x73\x3d\x71\x0e\x01\x0e\x81\x3d\x51\xf8\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x9e\xbf\x85\x85\x02\x05\x26\x25\x4d\x13\x10\x00\x00\x00\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\xf0\xf8\x2f\x01", 0x00, NULL ) < 0 ) { + return -9; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x3a\x00\x01\x02\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f\x20\x21\x22\x23\x24\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3d\x3f\xff\x00", 0x40, NULL ) < 0 ) { + return -10; + }; + + if ( askScanner( dev, "\x8b\x00\x01\x7c\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\x14\xf5\x2f\x01\xa0\x20\x14\x00\x40\xf8\x2f\x01\x05\x90\xf6\x77\x04\x00\x00\x00\x08\x00\x00\x00\x50\xf8\x2f\x01\x40\x39\xf4\x77\xa8\x20\x14\x00\x1c\xf6\x2f\x01\x2c\x20\xf4\x77\x80\x4d\xfb\x77", 0x40, NULL ) < 0 ) { + return -11; + }; + if ( askScanner( dev, "\x8b\x00\x03\xc8\x3a\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\x6c\x6c\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x6c\x00\x00\x00\x00\x00\x60\x62\x62\x62\x62\x62\x51\x6c\x00\x00\x00\x00\x00\x00\x40\xf9\x2f\x01\x4f\x9d\x00\x10\x3a\x00\x00\x00\x04\xf9\x01", 0x40, NULL ) < 0 ) { + return -12; + }; + if ( askScanner( dev, "\x8b\x00\x04\x02\x06\x0b\x07\x13\x0e\x55\x56\x01\x44\xf8\x2f\x01\x00\x00\x00\x00\x40\x00\x00\x00\x40\x40\x40\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8\x01\x00\x00\xc8\x01\x00\x00\x40\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -13; + }; + + if ( askScanner( dev, "\x07\x00\x20\x00\x3a\x0e\x13\x07\x0f\x14\x07\x10\x15\x07\x12\x16\x07\x13\x17\x07\x14\x18\x07\x15\x18\x07\x16\x19\x07\x17\x1a\x07\x19\x1b\x07\x1a\x1c\x07\x1b\x1d\x07\x1c\x1e\x07\x1d\x1f\x07\x1e\x20\x07\x1f\x21\x07\x20\x22\x07\x21\x23\x07\x23\x23\x07\x24\x55", 0x00, NULL ) < 0 ) { + return -14; + }; + if ( askScanner( dev, "\x07\x00\x20\x3a\x26\x24\x07\x25\x25\x07\x26\x25\x07\x27\x26\x07\x28\x27\x07\x29\x27\x07\x2a\x28\x07\x2b\x29\x07\x2d\x29\x07\x2e\x2a\x07\x2f\x2b\x07\x30\x2b\x07\x31\x2c\x07\x07\x1d\x1f\x07\x1e\x20\x07\x1f\x21\x07\x20\x22\x07\x21\x23\x07\x23\x23\x07\x24\x55", 0x00, NULL ) < 0 ) { + return -15; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x06\x0e\x81\x0e\x81\x09\x4d\x00\x07\x00\x20\x3a\x26\x24\x07\x25\x25\x07\x26\x25\x07\x27\x26\x07\x28\x27\x07\x29\x27\x07\x2a\x28\x07\x2b\x29\x07\x2d\x29\x07\x2e\x2a\x07\x2f\x2b\x07\x30\x2b\x07\x31\x2c\x07\x07\x1d\x1f\x07\x1e\x20\x07\x1f\x21", 0x00, NULL ) < 0 ) { + return -16; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x3a\x00\x01\x02\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f\x20\x21\x22\x23\x24\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3d\x3f\xff\x00", 0x40, NULL ) < 0 ) { + return -17; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\x0e\x85\x36\xd8\xf8\x2f\x01\xf1\x9d\x00\x10\xf8\xf8\x2f\x01\x99\xf8\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x9e\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -18; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\x0d\x00\x00\x02\x9e\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\xec\xf8\x2f\x01\x97\x40\x01\x10\x03\x00\x00\x00\x00\x00\x00\x00\xfa\x45\x03\x10\x02\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -19; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf7\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\x6c\x6c\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x6c\x00\x00\x00\x00\x00\x60\x62\x62\x62\x62\x62\x51\x6c\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -20; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf7\x00\x00\x02\xf9\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\x6c\x6c\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x6c\x00\x00\x00\x00\x00\x60\x62\x62\x62\x62\x62", 0x40, NULL ) < 0 ) { + return -21; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\xf7\xf4\x00\x14\xf9\x2f\x01\x6d\x4f\x01\x10\x94\xf8\x2f\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x02\xf9\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -22; + }; + if ( askScanner( dev, "\x03\x00\x00\x00\x02\x20\x6c\x01\x6d\x4f\x01\x10\x94\xf8\x2f\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x02\xf9\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\xe8\xf8\x2f\x01", 0x00, NULL ) < 0 ) { + return -23; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf9\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c\xe8\xf8\x2f\x01\xec\xf8\x2f\x01\x97\x40\x01\x10\x03\x00\x00\x00\x00\x00\x00\x00\xfa\x45\x03\x10\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -24; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\xf9\x01\x00\x1c\xf9\x2f\x01\x6d\x4f\x01\x10\x9c\xf8\x2f\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x02\x6c\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09\x0f\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -25; + }; + if ( askScanner( dev, "\x03\x00\x00\x00\x12\x1c\x0c\x1b\x08\x1a\x07\x30\x08\x09\x6d\x08\x27\x00\x9e\x00\x1e\x23\x47\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x02\x6c\xbf\x85\x85\x02\x05\x26\x25\x4d\x10\x10\x00\xff\x81\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x09\x09", 0x00, NULL ) < 0 ) { + return -26; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x3a\x00\x01\x02\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f\x20\x21\x22\x23\x24\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3d\x3f\xff\x00", 0x40, NULL ) < 0 ) { + return -27; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\x0d\xff\x36\xdc\xf8\x2f\x01\xf1\x9d\x00\x10\xfc\xf8\x2f\x01\x9d\xf8\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x1e\x3f\x05\x05\x02\x05\x26\x27\x6d\x10\x10\x00\xff\x85\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x07\x08\x0c\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -28; + }; + + if ( askScanner( dev, "\x08\x00\x00\x00\x0a\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x10\xfc\xf8\x2f\x01\x9d\xf8\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x1e\x3f\x05\x05\x02\x05\x26\x27\x6d\x10\x10\x00\xff\x85\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x07\x08\x0c\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -29; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x08\x0e\x85\x09\xed\x09\x6d\x09\xed\x1e\x3f\x05\x05\x02\x05\x26\x27\x6d\x10\x10\x00\xff\x85\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x07\x08\x0c\x00\x6c\x6c\xf0\xf8\x2f\x01\x97\x40\x01\x10\x08\x00\x00\x00\x00\x00\x00\x00\x3e\xf9\x2f\x01", 0x00, NULL ) < 0 ) { + return -30; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf3\x6c\x6c\xf0\xf8\x2f\x01\x97\x40\x01\x10\x08\x00\x00\x00\x00\x00\x00\x00\x3e\xf9\x2f\x01\x04\xf9\x2f\x01\x97\x40\x01\x10\x03\x00\x00\x00\x00\x00\x00\x00\x00\x46\x03\x10\x08\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -31; + }; + + if ( askScanner( dev, "\x84\x00\x00\x00\x32\x02\xa3\x04\x10\x3b\xa3\x04\x10\x1a\xa3\x04\x10\xf9\xa2\x04\x10\xd8\xa2\x00\xb9\x19\xe2\x87\xba\x56\x78\x72\x68\x9e\x7a\xf4\x65\x6d\xd9\xde\xf6\x33\xa2\x04\x10\x12\xa2\x04\x10\xf1\xa1\x04\x10\x04\x00\x00\x00\x00\x00\x00\xb4\x2d\x6c\xe9", 0x40, NULL ) < 0 ) { + return -32; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x06\x1a\x07\x1b\x08\x1c\x0c\x77\x21\xac\xe5\x77\x00\x00\x00\x00\xaa\x4e\x01\x10\x3c\x01\x00\x00\xc4\xf8\x2f\x01\xdc\xf8\x2f\x01\x00\x00\x00\x00\x40\x00\x00\x00\xb9\x19\xe2\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00", 0x00, NULL ) < 0 ) { + return -33; + }; + + if ( askScanner( dev, "\x08\x00\x00\x00\x0a\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8\x01\x00\x00\x40\x00\x00\x00\x01\x00\x00\x00\xcc\xf8\x2f\x01\x8b\x41\x01\x10\x8c\xf8\x2f\x01\x40\x00\x00\x00", 0x00, NULL ) < 0 ) { + return -34; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x04\x3d\x51\x0a\x00\x01\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xfc\xf9\x2f\x01\x31\x10\x01\x10\xd0\xf9\x2f\x01\x00\x00\x00\x00\x1a\x07\x1b\x08\x1c\x0c\xc6\xf8\x66\xbc\xc4\xbe\x0b\x25\xc5\x4c\xf4\x03\x10\x2f\x11\x3f\x12\x44", 0x00, NULL ) < 0 ) { + return -35; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x3a\x00\x01\x02\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f\x20\x21\x22\x23\x24\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3d\x3f\xff\x00", 0x40, NULL ) < 0 ) { + return -36; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\x0a\x10\x36\x88\xf9\x2f\x01\xf1\x9d\x00\x10\xa8\xf9\x2f\x01\x49\xf9\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x1e\x3f\x05\x05\x02\x05\x26\x27\xed\x00\x10\x00\xff\x85\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x07\x08\x0c\x00\x6c\x6c", 0x00, NULL ) < 0 ) { + return -37; + }; + if ( askScanner( dev, "\x8b\x00\x00\xbc\x3a\x40\xd3\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd8\xf4\x2f\x01\x80\x69\x67\xff\xff\xff\xff\xff\x00\xf0\xfd\x7f\x00\x60\xfd\x7f\x3c\x01\x00\x00\xa0\xf5\x2f\x01\x03\x01\x00\x00\x9a\x11\xf4\x77\x9f\x11\xf4\x77\x3c\x01\x00\x00\xa0\xf5\x01", 0x40, NULL ) < 0 ) { + return -38; + }; + if ( askScanner( dev, "\x8b\x00\x00\xf6\x3a\x0b\x07\xa5\x03\x2f\x63\x97\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -39; + }; + if ( askScanner( dev, "\x8b\x00\x01\x30\x3a\x0b\x00\x00\x00\x00\x00\x00\x12\xcd\xa6\x3c\x36\xec\x6a\x73\x00\x64\x75\xdf\x2e\x13\xec\xca\x3c\x03\x00\x00\x06\xa5\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -40; + }; + if ( askScanner( dev, "\x8b\x00\x01\x6a\x3a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -41; + }; + if ( askScanner( dev, "\x8b\x00\x01\xa4\x3a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\xa5\x83\x1b\x8e\xac\x00\x00\x0b\xa5\x08\x08\x03\x00\x00\x01\x02\x03\x06\x00\x00\x00\x00\x00\x8d\xa5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -42; + }; + if ( askScanner( dev, "\x8b\x00\x01\xde\x3a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -43; + }; + if ( askScanner( dev, "\x8b\x00\x02\x18\x3a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -44; + }; + if ( askScanner( dev, "\x8b\x00\x02\x52\x3a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -45; + }; + if ( askScanner( dev, "\x8b\x00\x02\x8c\x3a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -46; + }; + if ( askScanner( dev, "\x8b\x00\x02\xc6\x2a\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8\x01\x00\x00\xc8\x01\x00\x00\x40\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -47; + }; + + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xf1\x2f\x01\x49\xf9\x2f\x01\x3a\x00\x00\x00\x00\x00\x00\x00\x02\x1e\x3f\x05\x05\x02\x05\x26\x27\xed\x00\x10\x00\xff\x85\x6c\x00\x00\xcf\x00\x01\x00\x00\x1f\x01\x01\x07\x08\x0c\x00\x6c\x6c\x9c\xf9\x2f\x01\x97\x40\x01\x10\x03\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -48; + }; + + if ( askScanner( dev, "\x03\x00\x00\x00\x02\xf1\x01\x00\xb4\xf9\x2f\x01\x6d\x4f\x01\x10\x34\xf9\x2f\x01\x40\x00\x00\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x00, NULL ) < 0 ) { + return -49; + }; + if ( askScanner( dev, "\x8b\x00\x01\x10\x3a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -50; + }; + if ( askScanner( dev, "\x8b\x00\x01\x4a\x2e\x0b\x06\xa5\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8\x01\x00\x00\xc8\x01\x00\x00\x40\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -51; + }; + if ( askScanner( dev, "\x82\x00\x00\x00\x01\xfb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x88\xf9\x2f\x01\x97\x40\x01\x10\x03\x00\x00\x00\x00\x00\x00\x00\xfa\x45\x03\x10\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x40, NULL ) < 0 ) { + return -51; + }; + + /* enable sensor */ + if ( askScanner( dev, anInitCommand, 0x00, NULL ) < 0 ) { + return -52; + } + + return 0; +} + +static int DetectFinger( struct fp_img_dev *dev ) { + sint32 nRet = 0; + uint8 *pnData = NULL; + + pnData = g_malloc( SENSOR_FULL_IMAGE ); + + nRet = askScanner( dev, anScanCommand, SENSOR_FULL_IMAGE, pnData ); + + if ( nRet != SENSOR_FULL_IMAGE ) { + nRet = 0; + goto end; + } + + nRet = ValidScan( pnData ); + +end: + g_free( pnData ); + + return nRet; +} + +static int awaitFingerOn( struct fp_img_dev *dev ) { + int nRet = 0; + int nCount = WAIT_COUNT; + + /* wait until a finger is present */ + do { + nRet = DetectFinger( dev ); + } while ( nRet == 0 ); + + /* give user time to scan his full finger */ + while ( nCount-- ) { + nRet = DetectFinger( dev ); + } + + return nRet != 1 ? nRet : 0; +} + +static int capture( struct fp_img_dev *dev, gboolean unconditional, struct fp_img **ppsRet ) { + struct fp_img *psImg = NULL; + uint8 *pnData = NULL; + sint32 nRet = 0; + + psImg = fpi_img_new_for_imgdev( dev ); + pnData = g_malloc( SENSOR_FULL_IMAGE ); + + nRet = askScanner( dev, anScanCommand, SENSOR_FULL_IMAGE, pnData ); + if ( nRet == SENSOR_FULL_IMAGE ) { + memcpy( psImg -> data, pnData, SENSOR_FULL_IMAGE ); + *ppsRet = psImg; + nRet = 0; + } else { + nRet = -1; + } + + g_free( pnData ); + + return nRet; +} + +static int dev_init( struct fp_img_dev *dev, unsigned long driver_data ) { + int nResult; + + nResult = libusb_claim_interface(dev->udev, 0); + if ( nResult < 0 ) { + fp_err( "could not claim interface 0" ); + return nResult; + } + + nResult = SetupSensor( dev ); + + return nResult; +} + +static void dev_exit( struct fp_img_dev *dev ) { + libusb_release_interface(dev->udev, 0); +} + +static const struct usb_id id_table[] = { + { .vendor = 0x0483, .product = 0x2015 }, + { 0, 0, 0, }, +}; + +struct fp_img_driver upektc_driver = { + .driver = { + .id = 5, + .name = FP_COMPONENT, + .full_name = "UPEK TouchChip", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_PRESS, + }, + .flags = FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE, + .img_height = 288, + .img_width = 208, + + .bz3_threshold = 30, + .init = dev_init, + .exit = dev_exit, + .await_finger_on = awaitFingerOn, + .capture = capture, +}; --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/aes1610.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/aes1610.c.svn-base @@ -0,0 +1,552 @@ +/* + * AuthenTec AES1610 driver for libfprint + * Copyright (C) 2007 Anthony Bretaudeau + * Copyright (C) 2007 Daniel Drake + * Copyright (C) 2007 Cyrille Bagard + * Copyright (C) 2007 Vasily Khoruzhick + * + * Based on code from http://home.gna.org/aes2501, relicensed with permission + * + * 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 + */ + +#define FP_COMPONENT "aes1610" + +#include +#include + +#include + +#include +#include + +/* FIXME these need checking */ +#define EP_IN (1 | LIBUSB_ENDPOINT_IN) +#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) + +#define BULK_TIMEOUT 4000 + +#define FIRST_AES1610_REG 0x1B +#define LAST_AES1610_REG 0xFF + +/* + * The AES1610 is an imaging device using a swipe-type sensor. It samples + * the finger at preprogrammed intervals, sending a 128x8 frame to the + * computer. + * Unless the user is scanning their finger unreasonably fast, the frames + * *will* overlap. The implementation below detects this overlap and produces + * a contiguous image as the end result. + * The fact that the user determines the length of the swipe (and hence the + * number of useful frames) and also the fact that overlap varies means that + * images returned from this driver vary in height. + */ + +#define FRAME_WIDTH 128 +#define FRAME_HEIGHT 8 +#define FRAME_SIZE (FRAME_WIDTH * FRAME_HEIGHT) +/* maximum number of frames to read during a scan */ +/* FIXME reduce substantially */ +#define MAX_FRAMES 350 + +static int read_data(struct fp_img_dev *dev, unsigned char *data, size_t len) +{ + int r; + int transferred; + struct libusb_bulk_transfer msg = { + .endpoint = EP_IN, + .data = data, + .length = len, + }; + fp_dbg("len=%zd", len); + + r = libusb_bulk_transfer(dev->udev, &msg, &transferred, BULK_TIMEOUT); + if (r < 0) { + fp_err("bulk read error %d", r); + return r; + } else if (transferred < len) { + fp_err("unexpected short read %d/%zd", r, len); + return -EIO; + } + return 0; +} + +static const struct aes_regwrite init[] = { + { 0x82, 0x00 } +}; + +static const struct aes_regwrite stop_reader[] = { + { 0xFF, 0x00 } +}; + +static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + int r; + + r = libusb_claim_interface(dev->udev, 0); + if (r < 0) { + fp_err("could not claim interface 0"); + return r; + } + + /* FIXME check endpoints */ + + return aes_write_regv(dev, init, G_N_ELEMENTS(init)); +} + +static int do_exit(struct fp_img_dev *dev) +{ + return aes_write_regv(dev, stop_reader, G_N_ELEMENTS(stop_reader)); +} + +static void dev_exit(struct fp_img_dev *dev) +{ + do_exit(dev); + libusb_release_interface(dev->udev, 0); +} + +static const struct aes_regwrite finger_det_reqs[] = { + { 0x80, 0x01 }, + { 0x80, 0x12 }, + { 0x85, 0x00 }, + { 0x8A, 0x00 }, + { 0x8B, 0x0E }, + { 0x8C, 0x90 }, + { 0x8D, 0x83 }, + { 0x8E, 0x07 }, + { 0x8F, 0x07 }, + { 0x96, 0x00 }, + { 0x97, 0x48 }, + { 0xA1, 0x00 }, + { 0xA2, 0x50 }, + { 0xA6, 0xE4 }, + { 0xAD, 0x08 }, + { 0xAE, 0x5B }, + { 0xAF, 0x54 }, + { 0xB1, 0x28 }, + { 0xB5, 0xAB }, + { 0xB6, 0x0E }, + { 0x1B, 0x2D }, + { 0x81, 0x04 } +}; + +static const struct aes_regwrite finger_det_none[] = { + { 0x80, 0x01 }, + { 0x82, 0x00 }, + { 0x86, 0x00 }, + { 0xB1, 0x28 }, + { 0x1D, 0x00 } +}; + +static int detect_finger(struct fp_img_dev *dev) +{ + unsigned char buffer[19]; + int r; + int i; + int sum = 0; + + r = aes_write_regv(dev, finger_det_reqs, G_N_ELEMENTS(finger_det_reqs)); + if (r < 0) + return r; + + r = read_data(dev, buffer, 19); + if (r < 0) + return r; + + for (i = 3; i < 17; i++) + sum += (buffer[i] & 0xf) + (buffer[i] >> 4); + + /* We need to answer something if no finger has been detected */ + if (sum <= 20) { + r = aes_write_regv(dev, finger_det_none, G_N_ELEMENTS(finger_det_none)); + if (r < 0) + return r; + } + + return sum > 20; +} + +static int await_finger_on(struct fp_img_dev *dev) +{ + int r; + do { + r = detect_finger(dev); + } while (r == 0); + return (r < 0) ? r : 0; +} + +/* find overlapping parts of frames */ +static unsigned int find_overlap(unsigned char *first_frame, + unsigned char *second_frame, unsigned int *min_error) +{ + unsigned int dy; + unsigned int not_overlapped_height = 0; + *min_error = 255 * FRAME_SIZE; + for (dy = 0; dy < FRAME_HEIGHT; dy++) { + /* Calculating difference (error) between parts of frames */ + unsigned int i; + unsigned int error = 0; + for (i = 0; i < FRAME_WIDTH * (FRAME_HEIGHT - dy); i++) { + /* Using ? operator to avoid abs function */ + error += first_frame[i] > second_frame[i] ? + (first_frame[i] - second_frame[i]) : + (second_frame[i] - first_frame[i]); + } + + /* Normalize error */ + error *= 15; + error /= i; + if (error < *min_error) { + *min_error = error; + not_overlapped_height = dy; + } + first_frame += FRAME_WIDTH; + } + + return not_overlapped_height; +} + +/* assemble a series of frames into a single image */ +static unsigned int assemble(unsigned char *input, unsigned char *output, + int num_strips, gboolean reverse, unsigned int *errors_sum) +{ + uint8_t *assembled = output; + int frame; + uint32_t image_height = FRAME_HEIGHT; + unsigned int min_error; + *errors_sum = 0; + + if (num_strips < 1) + return 0; + + /* Rotating given data by 90 degrees + * Taken from document describing aes1610 image format + * TODO: move reversing detection here */ + + if (reverse) + output += (num_strips - 1) * FRAME_SIZE; + for (frame = 0; frame < num_strips; frame++) { + aes_assemble_image(input, FRAME_WIDTH, FRAME_HEIGHT, output); + input += FRAME_WIDTH * (FRAME_HEIGHT / 2); + + if (reverse) + output -= FRAME_SIZE; + else + output += FRAME_SIZE; + } + + /* Detecting where frames overlaped */ + output = assembled; + for (frame = 1; frame < num_strips; frame++) { + int not_overlapped; + + output += FRAME_SIZE; + not_overlapped = find_overlap(assembled, output, &min_error); + *errors_sum += min_error; + image_height += not_overlapped; + assembled += FRAME_WIDTH * not_overlapped; + memcpy(assembled, output, FRAME_SIZE); + } + return image_height; +} + +static const struct aes_regwrite capture_reqs[] = { + { 0x80, 0x01 }, + { 0x80, 0x12 }, + { 0x84, 0x01 }, + { 0x85, 0x00 }, + { 0x89, 0x64 }, + { 0x8A, 0x00 }, + { 0x8B, 0x0E }, + { 0x8C, 0x90 }, + { 0xBE, 0x23 }, + { 0x29, 0x06 }, + { 0x2A, 0x35 }, + { 0x96, 0x00 }, + { 0x98, 0x03 }, + { 0x99, 0x00 }, + { 0x9C, 0xA5 }, + { 0x9D, 0x40 }, + { 0x9E, 0xC6 }, + { 0x9F, 0x8E }, + { 0xA2, 0x50 }, + { 0xA3, 0xF0 }, + { 0xAD, 0x08 }, + { 0xBD, 0x4F }, + { 0xAF, 0x54 }, + { 0xB1, 0x08 }, + { 0xB5, 0xAB }, + { 0x1B, 0x2D }, + { 0xB6, 0x4E }, + { 0xB8, 0x70 }, + { 0x2B, 0xB3 }, + { 0x2C, 0x5D }, + { 0x2D, 0x98 }, + { 0x2E, 0xB0 }, + { 0x2F, 0x20 }, + { 0xA2, 0xD0 }, + { 0x1D, 0x21 }, + { 0x1E, 0xBE }, + { 0x1C, 0x00 }, + { 0x1D, 0x30 }, + { 0x1E, 0x29 }, + { 0x1C, 0x01 }, + { 0x1D, 0x00 }, + { 0x1E, 0x9E }, + { 0x1C, 0x02 }, + { 0x1D, 0x30 }, + { 0x1E, 0xBB }, + { 0x1C, 0x03 }, + { 0x1D, 0x00 }, + { 0x1E, 0x9D }, + { 0x1C, 0x04 }, + { 0x1D, 0x22 }, + { 0x1E, 0xFF }, + { 0x1C, 0x05 }, + { 0x1D, 0x1B }, + { 0x1E, 0x4E }, + { 0x1C, 0x06 }, + { 0x1D, 0x16 }, + { 0x1E, 0x28 }, + { 0x1C, 0x07 }, + { 0x1D, 0x22 }, + { 0x1E, 0xFF }, + { 0x1C, 0x08 }, + { 0x1D, 0x15 }, + { 0x1E, 0xF1 }, + { 0x1C, 0x09 }, + { 0x1D, 0x30 }, + { 0x1E, 0xD5 }, + { 0x1C, 0x0A }, + { 0x1D, 0x00 }, + { 0x1E, 0x9E }, + { 0x1C, 0x0B }, + { 0x1D, 0x17 }, + { 0x1E, 0x9D }, + { 0x1C, 0x0C }, + { 0x1D, 0x28 }, + { 0x1E, 0xD7 }, + { 0x1C, 0x0D }, + { 0x1D, 0x17 }, + { 0x1E, 0xD7 }, + { 0x1C, 0x0E }, + { 0x1D, 0x0A }, + { 0x1E, 0xCB }, + { 0x1C, 0x0F }, + { 0x1D, 0x24 }, + { 0x1E, 0x14 }, + { 0x1C, 0x10 }, + { 0x1D, 0x17 }, + { 0x1E, 0x85 }, + { 0x1C, 0x11 }, + { 0x1D, 0x15 }, + { 0x1E, 0x71 }, + { 0x1C, 0x12 }, + { 0x1D, 0x2B }, + { 0x1E, 0x36 }, + { 0x1C, 0x13 }, + { 0x1D, 0x12 }, + { 0x1E, 0x06 }, + { 0x1C, 0x14 }, + { 0x1D, 0x30 }, + { 0x1E, 0x97 }, + { 0x1C, 0x15 }, + { 0x1D, 0x21 }, + { 0x1E, 0x32 }, + { 0x1C, 0x16 }, + { 0x1D, 0x06 }, + { 0x1E, 0xE6 }, + { 0x1C, 0x17 }, + { 0x1D, 0x16 }, + { 0x1E, 0x06 }, + { 0x1C, 0x18 }, + { 0x1D, 0x30 }, + { 0x1E, 0x01 }, + { 0x1C, 0x19 }, + { 0x1D, 0x21 }, + { 0x1E, 0x37 }, + { 0x1C, 0x1A }, + { 0x1D, 0x00 }, + { 0x1E, 0x08 }, + { 0x1C, 0x1B }, + { 0x1D, 0x80 }, + { 0x1E, 0xD5 }, + { 0xA2, 0x50 }, + { 0xA2, 0x50 }, + { 0x81, 0x01 } +}; + +static const struct aes_regwrite strip_scan_reqs[] = { + { 0xBE, 0x23 }, + { 0x29, 0x06 }, + { 0x2A, 0x35 }, + { 0xBD, 0x4F }, + { 0xFF, 0x00 } +}; + +static const struct aes_regwrite capture_stop[] = { + { 0x81,0x00 } +}; + +static int capture(struct fp_img_dev *dev, gboolean unconditional, + struct fp_img **ret) +{ + int r; + struct fp_img *img; + unsigned int nstrips; + unsigned int errors_sum, r_errors_sum; + unsigned char *cooked; + unsigned char *imgptr; + unsigned char buf[665]; + int final_size; + int sum; + unsigned int count_blank = 0; + int i; + + /* FIXME can do better here in terms of buffer management? */ + fp_dbg(""); + + r = aes_write_regv(dev, capture_reqs, G_N_ELEMENTS(capture_reqs)); + if (r < 0) + return r; + + /* FIXME: use histogram data above for gain calibration (0x8e xx) */ + + img = fpi_img_new((3 * MAX_FRAMES * FRAME_SIZE) / 2); + imgptr = img->data; + cooked = imgptr + (MAX_FRAMES * FRAME_SIZE) / 2; + + r = read_data(dev, buf, 665); + if (r < 0) + goto err; + memcpy(imgptr, buf + 1, 128*4); + imgptr += 128*4; + + r = read_data(dev, buf, 665); + if (r < 0) + goto err; + memcpy(imgptr, buf + 1, 128*4); + imgptr += 128*4; + + /* we start at 2 because we captured 2 frames above. the above captures + * should possibly be moved into the loop below, or discarded altogether */ + for (nstrips = 2; nstrips < MAX_FRAMES - 2; nstrips++) { + r = aes_write_regv(dev, strip_scan_reqs, G_N_ELEMENTS(strip_scan_reqs)); + if (r < 0) + goto err; + r = read_data(dev, buf, 665); + if (r < 0) + goto err; + memcpy(imgptr, buf + 1, 128*4); + imgptr += 128*4; + + r = read_data(dev, buf, 665); + if (r < 0) + goto err; + memcpy(imgptr, buf + 1, 128*4); + imgptr += 128*4; + + sum = 0; + for (i = 515; i != 530; i++) + { + /* histogram[i] = number of pixels of value i + Only the pixel values from 10 to 15 are used to detect finger. */ + sum += buf[i]; + } + if (sum < 0) { + r = sum; + goto err; + } + fp_dbg("sum=%d", sum); + if (sum == 0) + count_blank++; + else + count_blank = 0; + + /* if we got 50 blank frames, assume scan has ended. */ + if (count_blank >= 50) + break; + } + + r = aes_write_regv(dev, capture_stop, G_N_ELEMENTS(capture_stop)); + if (r < 0) + goto err; + r = read_data(dev, buf, 665); + if (r < 0) + goto err; + memcpy(imgptr, buf + 1, 128*4); + imgptr += 128*4; + nstrips++; + + r = read_data(dev, buf, 665); + if (r < 0) + goto err; + memcpy(imgptr, buf + 1, 128*4); + imgptr += 128*4; + nstrips++; + + if (nstrips == MAX_FRAMES) + fp_warn("swiping finger too slow?"); + + img->flags = FP_IMG_COLORS_INVERTED; + img->height = assemble(img->data, cooked, nstrips, FALSE, &errors_sum); + img->height = assemble(img->data, cooked, nstrips, TRUE, &r_errors_sum); + + if (r_errors_sum > errors_sum) { + img->height = assemble(img->data, cooked, nstrips, FALSE, &errors_sum); + img->flags |= FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED; + fp_dbg("normal scan direction"); + } else { + fp_dbg("reversed scan direction"); + } + + final_size = img->height * FRAME_WIDTH; + memcpy(img->data, cooked, final_size); + img = fpi_img_resize(img, final_size); + *ret = img; + return 0; +err: + fp_img_free(img); + return r; +} + +static const struct usb_id id_table[] = { + { .vendor = 0x08ff, .product = 0x1600 }, + { 0, 0, 0, }, +}; + +struct fp_img_driver aes1610_driver = { + .driver = { + .id = 6, + .name = FP_COMPONENT, + .full_name = "AuthenTec AES1610", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_SWIPE, + }, + .flags = 0, + .img_height = -1, + .img_width = 128, + + /* temporarily lowered until we sort out image processing code + * binarized scan quality is good, minutiae detection is accurate, + * it's just that we get fewer minutiae than other scanners (less scanning + * area) */ + .bz3_threshold = 10, + + .init = dev_init, + .exit = dev_exit, + .await_finger_on = await_finger_on, + .capture = capture, +}; + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/aes4000.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/aes4000.c.svn-base @@ -0,0 +1,270 @@ +/* + * AuthenTec AES4000 driver for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "aes4000" + +#include + +#include +#include + +#include +#include + +#define CTRL_TIMEOUT 1000 +#define EP_IN (1 | LIBUSB_ENDPOINT_IN) +#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) +#define DATA_BUFLEN 0x1259 +#define NR_SUBARRAYS 6 +#define SUBARRAY_LEN 768 + +#define IMG_HEIGHT 96 +#define IMG_WIDTH 96 +#define ENLARGE_FACTOR 3 + +struct aes4k_dev { + struct libusb_transfer *img_trf; +}; + +static const struct aes_regwrite init_reqs[] = { + /* master reset */ + { 0x80, 0x01 }, + { 0, 0 }, + { 0x80, 0x00 }, + { 0, 0 }, + + { 0x81, 0x00 }, + { 0x80, 0x00 }, + { 0, 0 }, + + /* scan reset */ + { 0x80, 0x02 }, + { 0, 0 }, + { 0x80, 0x00 }, + { 0, 0 }, + + /* disable register buffering */ + { 0x80, 0x04 }, + { 0, 0 }, + { 0x80, 0x00 }, + { 0, 0 }, + + { 0x81, 0x00 }, + { 0, 0 }, + /* windows driver reads registers now (81 02) */ + { 0x80, 0x00 }, + { 0x81, 0x00 }, + + /* set excitation bias current: 2mhz drive ring frequency, + * 4V drive ring voltage, 16.5mA excitation bias */ + { 0x82, 0x04 }, + + /* continuously sample drive ring for finger detection, + * 62.50ms debounce delay */ + { 0x83, 0x13 }, + + { 0x84, 0x07 }, /* set calibration resistance to 12 kiloohms */ + { 0x85, 0x3d }, /* set calibration capacitance */ + { 0x86, 0x03 }, /* detect drive voltage */ + { 0x87, 0x01 }, /* set detection frequency to 125khz */ + { 0x88, 0x02 }, /* set column scan period */ + { 0x89, 0x02 }, /* set measure drive */ + { 0x8a, 0x33 }, /* set measure frequency and sense amplifier bias */ + { 0x8b, 0x33 }, /* set matrix pattern */ + { 0x8c, 0x0f }, /* set demodulation phase 1 */ + { 0x8d, 0x04 }, /* set demodulation phase 2 */ + { 0x8e, 0x23 }, /* set sensor gain */ + { 0x8f, 0x07 }, /* set image parameters */ + { 0x90, 0x00 }, /* carrier offset null */ + { 0x91, 0x1c }, /* set A/D reference high */ + { 0x92, 0x08 }, /* set A/D reference low */ + { 0x93, 0x00 }, /* set start row to 0 */ + { 0x94, 0x05 }, /* set end row to 5 */ + { 0x95, 0x00 }, /* set start column to 0 */ + { 0x96, 0x18 }, /* set end column to 24*4=96 */ + { 0x97, 0x04 }, /* data format and thresholds */ + { 0x98, 0x28 }, /* image data control */ + { 0x99, 0x00 }, /* disable general purpose outputs */ + { 0x9a, 0x0b }, /* set initial scan state */ + { 0x9b, 0x00 }, /* clear challenge word bits */ + { 0x9c, 0x00 }, /* clear challenge word bits */ + { 0x9d, 0x09 }, /* set some challenge word bits */ + { 0x9e, 0x53 }, /* clear challenge word bits */ + { 0x9f, 0x6b }, /* set some challenge word bits */ + { 0, 0 }, + + { 0x80, 0x00 }, + { 0x81, 0x00 }, + { 0, 0 }, + { 0x81, 0x04 }, + { 0, 0 }, + { 0x81, 0x00 }, +}; + +static void do_capture(struct fp_img_dev *dev); + +static void img_cb(struct libusb_transfer *transfer) +{ + struct fp_img_dev *dev = transfer->user_data; + struct aes4k_dev *aesdev = dev->priv; + unsigned char *ptr = transfer->buffer; + struct fp_img *tmp; + struct fp_img *img; + int i; + + if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { + goto err; + } else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_imgdev_session_error(dev, -EIO); + goto err; + } else if (transfer->length != transfer->actual_length) { + fpi_imgdev_session_error(dev, -EPROTO); + goto err; + } + + fpi_imgdev_report_finger_status(dev, TRUE); + + tmp = fpi_img_new(IMG_WIDTH * IMG_HEIGHT); + 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++) { + fp_dbg("subarray header byte %02x", *ptr); + ptr++; + aes_assemble_image(ptr, 96, 16, tmp->data + (i * 96 * 16)); + 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); + + /* FIXME: rather than assuming finger has gone, we should poll regs until + * it really has, then restart the capture */ + fpi_imgdev_report_finger_status(dev, FALSE); + + do_capture(dev); + +err: + g_free(transfer->buffer); + aesdev->img_trf = NULL; + libusb_free_transfer(transfer); +} + +static void do_capture(struct fp_img_dev *dev) +{ + struct aes4k_dev *aesdev = dev->priv; + unsigned char *data; + int r; + + aesdev->img_trf = libusb_alloc_transfer(0); + if (!aesdev->img_trf) { + fpi_imgdev_session_error(dev, -EIO); + return; + } + + data = g_malloc(DATA_BUFLEN); + libusb_fill_bulk_transfer(aesdev->img_trf, dev->udev, EP_IN, data, + DATA_BUFLEN, img_cb, dev, 0); + + r = libusb_submit_transfer(aesdev->img_trf); + if (r < 0) { + g_free(data); + libusb_free_transfer(aesdev->img_trf); + aesdev->img_trf = NULL; + fpi_imgdev_session_error(dev, r); + } +} + +static void init_reqs_cb(struct fp_img_dev *dev, int result, void *user_data) +{ + fpi_imgdev_activate_complete(dev, result); + if (result == 0) + do_capture(dev); +} + +static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + aes_write_regv(dev, init_reqs, G_N_ELEMENTS(init_reqs), init_reqs_cb, NULL); + return 0; +} + +static void dev_deactivate(struct fp_img_dev *dev) +{ + struct aes4k_dev *aesdev = dev->priv; + + /* FIXME: should wait for cancellation to complete before returning + * from deactivation, otherwise app may legally exit before we've + * cleaned up */ + if (aesdev->img_trf) + libusb_cancel_transfer(aesdev->img_trf); + fpi_imgdev_deactivate_complete(dev); +} + +static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + int r; + + r = libusb_claim_interface(dev->udev, 0); + if (r < 0) + fp_err("could not claim interface 0"); + + dev->priv = g_malloc0(sizeof(struct aes4k_dev)); + + if (r == 0) + fpi_imgdev_open_complete(dev, 0); + + return r; +} + +static void dev_deinit(struct fp_img_dev *dev) +{ + g_free(dev->priv); + libusb_release_interface(dev->udev, 0); + fpi_imgdev_close_complete(dev); +} + +static const struct usb_id id_table[] = { + { .vendor = 0x08ff, .product = 0x5501 }, + { 0, 0, 0, }, +}; + +struct fp_img_driver aes4000_driver = { + .driver = { + .id = 3, + .name = FP_COMPONENT, + .full_name = "AuthenTec AES4000", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_PRESS, + }, + .flags = 0, + .img_height = IMG_HEIGHT * ENLARGE_FACTOR, + .img_width = IMG_WIDTH * ENLARGE_FACTOR, + + /* temporarily lowered until image quality improves */ + .bz3_threshold = 9, + + .open = dev_init, + .close = dev_deinit, + .activate = dev_activate, + .deactivate = dev_deactivate, +}; + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/aes2501.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/aes2501.c.svn-base @@ -0,0 +1,963 @@ +/* + * AuthenTec AES2501 driver for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2007 Cyrille Bagard + * Copyright (C) 2007 Vasily Khoruzhick + * + * Based on code from http://home.gna.org/aes2501, relicensed with permission + * + * 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 + */ + +#define FP_COMPONENT "aes2501" + +#include +#include + +#include + +#include +#include +#include "aes2501.h" + +static void start_capture(struct fp_img_dev *dev); +static void complete_deactivation(struct fp_img_dev *dev); + +/* FIXME these need checking */ +#define EP_IN (1 | LIBUSB_ENDPOINT_IN) +#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) + +#define BULK_TIMEOUT 4000 + +/* + * The AES2501 is an imaging device using a swipe-type sensor. It samples + * the finger at preprogrammed intervals, sending a 192x16 frame to the + * computer. + * Unless the user is scanning their finger unreasonably fast, the frames + * *will* overlap. The implementation below detects this overlap and produces + * a contiguous image as the end result. + * The fact that the user determines the length of the swipe (and hence the + * number of useful frames) and also the fact that overlap varies means that + * images returned from this driver vary in height. + */ + +#define FRAME_WIDTH 192 +#define FRAME_HEIGHT 16 +#define FRAME_SIZE (FRAME_WIDTH * FRAME_HEIGHT) +/* maximum number of frames to read during a scan */ +/* FIXME reduce substantially */ +#define MAX_FRAMES 150 + +/****** GENERAL FUNCTIONS ******/ + +struct aes2501_dev { + uint8_t read_regs_retry_count; + GSList *strips; + size_t strips_len; + gboolean deactivating; +}; + +typedef void (*aes2501_read_regs_cb)(struct fp_img_dev *dev, int status, + unsigned char *regs, void *user_data); + +struct aes2501_read_regs { + struct fp_img_dev *dev; + aes2501_read_regs_cb callback; + struct aes_regwrite *regwrite; + void *user_data; +}; + +static void read_regs_data_cb(struct libusb_transfer *transfer) +{ + struct aes2501_read_regs *rdata = transfer->user_data; + unsigned char *retdata = NULL; + int r; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + r = -EIO; + } else if (transfer->length != transfer->actual_length) { + r = -EPROTO; + } else { + r = 0; + retdata = transfer->buffer; + } + + rdata->callback(rdata->dev, r, retdata, rdata->user_data); + g_free(rdata); + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data) +{ + struct aes2501_read_regs *rdata = user_data; + struct libusb_transfer *transfer; + unsigned char *data; + int r; + + g_free(rdata->regwrite); + if (result != 0) + goto err; + + transfer = libusb_alloc_transfer(0); + if (!transfer) { + result = -ENOMEM; + goto err; + } + + data = g_malloc(126); + libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, 126, + read_regs_data_cb, rdata, BULK_TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + result = -EIO; + goto err; + } + + return; +err: + rdata->callback(dev, result, NULL, rdata->user_data); + g_free(rdata); +} + +static void read_regs(struct fp_img_dev *dev, aes2501_read_regs_cb callback, + void *user_data) +{ + /* FIXME: regwrite is dynamic because of asynchronity. is this really + * required? */ + struct aes_regwrite *regwrite = g_malloc(sizeof(*regwrite)); + struct aes2501_read_regs *rdata = g_malloc(sizeof(*rdata)); + + fp_dbg(""); + regwrite->reg = AES2501_REG_CTRL2; + regwrite->value = AES2501_CTRL2_READ_REGS; + rdata->dev = dev; + rdata->callback = callback; + rdata->user_data = user_data; + rdata->regwrite = regwrite; + + aes_write_regv(dev, (const struct aes_regwrite *) regwrite, 1, + read_regs_rq_cb, rdata); +} + +/* Read the value of a specific register from a register dump */ +static int regval_from_dump(unsigned char *data, uint8_t target) +{ + if (*data != FIRST_AES2501_REG) { + fp_err("not a register dump"); + return -EILSEQ; + } + + if (!(FIRST_AES2501_REG <= target && target <= LAST_AES2501_REG)) { + fp_err("out of range"); + return -EINVAL; + } + + target -= FIRST_AES2501_REG; + target *= 2; + return data[target + 1]; +} + +static void generic_write_regv_cb(struct fp_img_dev *dev, int result, + void *user_data) +{ + struct fpi_ssm *ssm = user_data; + if (result == 0) + fpi_ssm_next_state(ssm); + else + fpi_ssm_mark_aborted(ssm, result); +} + +/* check that read succeeded but ignore all data */ +static void generic_ignore_data_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else if (transfer->length != transfer->actual_length) + fpi_ssm_mark_aborted(ssm, -EPROTO); + else + fpi_ssm_next_state(ssm); + + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +/* read the specified number of bytes from the IN endpoint but throw them + * away, then increment the SSM */ +static void generic_read_ignore_data(struct fpi_ssm *ssm, size_t bytes) +{ + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + data = g_malloc(bytes); + libusb_fill_bulk_transfer(transfer, ssm->dev->udev, EP_IN, data, bytes, + generic_ignore_data_cb, ssm, BULK_TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } +} + +/****** IMAGE PROCESSING ******/ + +static int sum_histogram_values(unsigned char *data, uint8_t threshold) +{ + int r = 0; + int i; + uint16_t *histogram = (uint16_t *)(data + 1); + + if (*data != 0xde) + return -EILSEQ; + + if (threshold > 0x0f) + return -EINVAL; + + /* FIXME endianness */ + for (i = threshold; i < 16; i++) + r += histogram[i]; + + return r; +} + +/* find overlapping parts of frames */ +static unsigned int find_overlap(unsigned char *first_frame, + unsigned char *second_frame, unsigned int *min_error) +{ + unsigned int dy; + unsigned int not_overlapped_height = 0; + *min_error = 255 * FRAME_SIZE; + for (dy = 0; dy < FRAME_HEIGHT; dy++) { + /* Calculating difference (error) between parts of frames */ + unsigned int i; + unsigned int error = 0; + for (i = 0; i < FRAME_WIDTH * (FRAME_HEIGHT - dy); i++) { + /* Using ? operator to avoid abs function */ + error += first_frame[i] > second_frame[i] ? + (first_frame[i] - second_frame[i]) : + (second_frame[i] - first_frame[i]); + } + + /* Normalize error */ + error *= 15; + error /= i; + if (error < *min_error) { + *min_error = error; + not_overlapped_height = dy; + } + first_frame += FRAME_WIDTH; + } + + return not_overlapped_height; +} + +/* assemble a series of frames into a single image */ +static unsigned int assemble(struct aes2501_dev *aesdev, unsigned char *output, + gboolean reverse, unsigned int *errors_sum) +{ + uint8_t *assembled = output; + int frame; + uint32_t image_height = FRAME_HEIGHT; + unsigned int min_error; + size_t num_strips = aesdev->strips_len; + GSList *list_entry = aesdev->strips; + *errors_sum = 0; + + /* Rotating given data by 90 degrees + * Taken from document describing aes2501 image format + * TODO: move reversing detection here */ + + if (reverse) + output += (num_strips - 1) * FRAME_SIZE; + for (frame = 0; frame < num_strips; frame++) { + aes_assemble_image(list_entry->data, FRAME_WIDTH, FRAME_HEIGHT, output); + + if (reverse) + output -= FRAME_SIZE; + else + output += FRAME_SIZE; + list_entry = g_slist_next(list_entry); + } + + /* Detecting where frames overlaped */ + output = assembled; + for (frame = 1; frame < num_strips; frame++) { + int not_overlapped; + + output += FRAME_SIZE; + not_overlapped = find_overlap(assembled, output, &min_error); + *errors_sum += min_error; + image_height += not_overlapped; + assembled += FRAME_WIDTH * not_overlapped; + memcpy(assembled, output, FRAME_SIZE); + } + return image_height; +} + +static void assemble_and_submit_image(struct fp_img_dev *dev) +{ + struct aes2501_dev *aesdev = dev->priv; + size_t final_size; + struct fp_img *img; + unsigned int errors_sum, r_errors_sum; + + BUG_ON(aesdev->strips_len == 0); + + /* reverse list */ + aesdev->strips = g_slist_reverse(aesdev->strips); + + /* create buffer big enough for max image */ + img = fpi_img_new(aesdev->strips_len * FRAME_SIZE); + + img->flags = FP_IMG_COLORS_INVERTED; + img->height = assemble(aesdev, img->data, FALSE, &errors_sum); + img->height = assemble(aesdev, img->data, TRUE, &r_errors_sum); + + if (r_errors_sum > errors_sum) { + img->height = assemble(aesdev, img->data, FALSE, &errors_sum); + img->flags |= FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED; + fp_dbg("normal scan direction"); + } else { + fp_dbg("reversed scan direction"); + } + + /* now that overlap has been removed, resize output image buffer */ + final_size = img->height * FRAME_WIDTH; + img = fpi_img_resize(img, final_size); + fpi_imgdev_image_captured(dev, img); + + /* free strips and strip list */ + g_slist_foreach(aesdev->strips, (GFunc) g_free, NULL); + g_slist_free(aesdev->strips); + aesdev->strips = NULL; +} + + +/****** FINGER PRESENCE DETECTION ******/ + +static const struct aes_regwrite finger_det_reqs[] = { + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_DETCTRL, + AES2501_DETCTRL_DRATE_CONTINUOUS | AES2501_DETCTRL_SDELAY_31_MS }, + { AES2501_REG_COLSCAN, AES2501_COLSCAN_SRATE_128_US }, + { AES2501_REG_MEASDRV, AES2501_MEASDRV_MDRIVE_0_325 | AES2501_MEASDRV_MEASURE_SQUARE }, + { AES2501_REG_MEASFREQ, AES2501_MEASFREQ_2M }, + { AES2501_REG_DEMODPHASE1, DEMODPHASE_NONE }, + { AES2501_REG_DEMODPHASE2, DEMODPHASE_NONE }, + { AES2501_REG_CHANGAIN, + AES2501_CHANGAIN_STAGE2_4X | AES2501_CHANGAIN_STAGE1_16X }, + { AES2501_REG_ADREFHI, 0x44 }, + { AES2501_REG_ADREFLO, 0x34 }, + { AES2501_REG_STRTCOL, 0x16 }, + { AES2501_REG_ENDCOL, 0x16 }, + { AES2501_REG_DATFMT, AES2501_DATFMT_BIN_IMG | 0x08 }, + { AES2501_REG_TREG1, 0x70 }, + { 0xa2, 0x02 }, + { 0xa7, 0x00 }, + { AES2501_REG_TREGC, AES2501_TREGC_ENABLE }, + { AES2501_REG_TREGD, 0x1a }, + { 0, 0 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_REG_UPDATE }, + { AES2501_REG_CTRL2, AES2501_CTRL2_SET_ONE_SHOT }, + { AES2501_REG_LPONT, AES2501_LPONT_MIN_VALUE }, +}; + +static void start_finger_detection(struct fp_img_dev *dev); + +static void finger_det_data_cb(struct libusb_transfer *transfer) +{ + struct fp_img_dev *dev = transfer->user_data; + unsigned char *data = transfer->buffer; + int i; + int sum = 0; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_imgdev_session_error(dev, -EIO); + goto out; + } else if (transfer->length != transfer->actual_length) { + fpi_imgdev_session_error(dev, -EPROTO); + goto out; + } + + /* examine histogram to determine finger presence */ + for (i = 1; i < 9; i++) + sum += (data[i] & 0xf) + (data[i] >> 4); + if (sum > 20) { + /* finger present, start capturing */ + fpi_imgdev_report_finger_status(dev, TRUE); + start_capture(dev); + } else { + /* no finger, poll for a new histogram */ + start_finger_detection(dev); + } + +out: + g_free(data); + libusb_free_transfer(transfer); +} + +static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, + void *user_data) +{ + struct libusb_transfer *transfer; + unsigned char *data; + int r; + + if (result) { + fpi_imgdev_session_error(dev, result); + return; + } + + transfer = libusb_alloc_transfer(0); + if (!transfer) { + fpi_imgdev_session_error(dev, -ENOMEM); + return; + } + + data = g_malloc(20); + libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, 20, + finger_det_data_cb, dev, BULK_TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_imgdev_session_error(dev, r); + } +} + +static void start_finger_detection(struct fp_img_dev *dev) +{ + struct aes2501_dev *aesdev = dev->priv; + fp_dbg(""); + + if (aesdev->deactivating) { + complete_deactivation(dev); + return; + } + + aes_write_regv(dev, finger_det_reqs, G_N_ELEMENTS(finger_det_reqs), + finger_det_reqs_cb, NULL); +} + +/****** CAPTURE ******/ + +static const struct aes_regwrite capture_reqs_1[] = { + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { 0, 0 }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_DETCTRL, + AES2501_DETCTRL_SDELAY_31_MS | AES2501_DETCTRL_DRATE_CONTINUOUS }, + { AES2501_REG_COLSCAN, AES2501_COLSCAN_SRATE_128_US }, + { AES2501_REG_DEMODPHASE2, 0x7c }, + { AES2501_REG_MEASDRV, + AES2501_MEASDRV_MEASURE_SQUARE | AES2501_MEASDRV_MDRIVE_0_325 }, + { AES2501_REG_DEMODPHASE1, 0x24 }, + { AES2501_REG_CHWORD1, 0x00 }, + { AES2501_REG_CHWORD2, 0x6c }, + { AES2501_REG_CHWORD3, 0x09 }, + { AES2501_REG_CHWORD4, 0x54 }, + { AES2501_REG_CHWORD5, 0x78 }, + { 0xa2, 0x02 }, + { 0xa7, 0x00 }, + { 0xb6, 0x26 }, + { 0xb7, 0x1a }, + { AES2501_REG_CTRL1, AES2501_CTRL1_REG_UPDATE }, + { AES2501_REG_IMAGCTRL, + AES2501_IMAGCTRL_TST_REG_ENABLE | AES2501_IMAGCTRL_HISTO_DATA_ENABLE | + AES2501_IMAGCTRL_IMG_DATA_DISABLE }, + { AES2501_REG_STRTCOL, 0x10 }, + { AES2501_REG_ENDCOL, 0x1f }, + { AES2501_REG_CHANGAIN, + AES2501_CHANGAIN_STAGE1_2X | AES2501_CHANGAIN_STAGE2_2X }, + { AES2501_REG_ADREFHI, 0x70 }, + { AES2501_REG_ADREFLO, 0x20 }, + { AES2501_REG_CTRL2, AES2501_CTRL2_SET_ONE_SHOT }, + { AES2501_REG_LPONT, AES2501_LPONT_MIN_VALUE }, +}; + +static const struct aes_regwrite capture_reqs_2[] = { + { AES2501_REG_IMAGCTRL, + AES2501_IMAGCTRL_TST_REG_ENABLE | AES2501_IMAGCTRL_HISTO_DATA_ENABLE | + AES2501_IMAGCTRL_IMG_DATA_DISABLE }, + { AES2501_REG_STRTCOL, 0x10 }, + { AES2501_REG_ENDCOL, 0x1f }, + { AES2501_REG_CHANGAIN, AES2501_CHANGAIN_STAGE1_16X }, + { AES2501_REG_ADREFHI, 0x70 }, + { AES2501_REG_ADREFLO, 0x20 }, + { AES2501_REG_CTRL2, AES2501_CTRL2_SET_ONE_SHOT }, +}; + +static const struct aes_regwrite strip_scan_reqs[] = { + { AES2501_REG_IMAGCTRL, + AES2501_IMAGCTRL_TST_REG_ENABLE | AES2501_IMAGCTRL_HISTO_DATA_ENABLE }, + { AES2501_REG_STRTCOL, 0x00 }, + { AES2501_REG_ENDCOL, 0x2f }, + { AES2501_REG_CHANGAIN, AES2501_CHANGAIN_STAGE1_16X }, + { AES2501_REG_ADREFHI, 0x5b }, + { AES2501_REG_ADREFLO, 0x20 }, + { AES2501_REG_CTRL2, AES2501_CTRL2_SET_ONE_SHOT }, +}; + +/* capture SM movement: + * write reqs and read data 1 + 2, + * request and read strip, + * jump back to request UNLESS theres no finger, in which case exit SM, + * report lack of finger presence, and move to finger detection */ + +enum capture_states { + CAPTURE_WRITE_REQS_1, + CAPTURE_READ_DATA_1, + CAPTURE_WRITE_REQS_2, + CAPTURE_READ_DATA_2, + CAPTURE_REQUEST_STRIP, + CAPTURE_READ_STRIP, + CAPTURE_NUM_STATES, +}; + +static void capture_read_strip_cb(struct libusb_transfer *transfer) +{ + unsigned char *stripdata; + struct fpi_ssm *ssm = transfer->user_data; + struct fp_img_dev *dev = ssm->priv; + struct aes2501_dev *aesdev = dev->priv; + unsigned char *data = transfer->buffer; + int sum; + int threshold; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_ssm_mark_aborted(ssm, -EIO); + goto out; + } else if (transfer->length != transfer->actual_length) { + fpi_ssm_mark_aborted(ssm, -EPROTO); + goto out; + } + + /* FIXME: would preallocating strip buffers be a decent optimization? */ + stripdata = g_malloc(192 * 8); + memcpy(stripdata, data + 1, 192*8); + aesdev->strips = g_slist_prepend(aesdev->strips, stripdata); + aesdev->strips_len++; + + threshold = regval_from_dump(data + 1 + 192*8 + 1 + 16*2 + 1 + 8, + AES2501_REG_DATFMT); + if (threshold < 0) { + fpi_ssm_mark_aborted(ssm, threshold); + goto out; + } + + sum = sum_histogram_values(data + 1 + 192*8, threshold & 0x0f); + if (sum < 0) { + fpi_ssm_mark_aborted(ssm, sum); + goto out; + } + fp_dbg("sum=%d", sum); + + /* FIXME: 0 might be too low as a threshold */ + /* FIXME: sometimes we get 0 in the middle of a scan, should we wait for + * a few consecutive zeroes? */ + /* FIXME: we should have an upper limit on the number of strips */ + + /* If sum is 0, finger has been removed */ + if (sum == 0) { + /* assemble image and submit it to library */ + assemble_and_submit_image(dev); + fpi_imgdev_report_finger_status(dev, FALSE); + /* marking machine complete will re-trigger finger detection loop */ + fpi_ssm_mark_completed(ssm); + } else { + /* obtain next strip */ + fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP); + } + +out: + g_free(data); + libusb_free_transfer(transfer); +} + +static void capture_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct aes2501_dev *aesdev = dev->priv; + int r; + + switch (ssm->cur_state) { + case CAPTURE_WRITE_REQS_1: + aes_write_regv(dev, capture_reqs_1, G_N_ELEMENTS(capture_reqs_1), + generic_write_regv_cb, ssm); + break; + case CAPTURE_READ_DATA_1: + generic_read_ignore_data(ssm, 159); + break; + case CAPTURE_WRITE_REQS_2: + aes_write_regv(dev, capture_reqs_2, G_N_ELEMENTS(capture_reqs_2), + generic_write_regv_cb, ssm); + break; + case CAPTURE_READ_DATA_2: + generic_read_ignore_data(ssm, 159); + break; + case CAPTURE_REQUEST_STRIP: + if (aesdev->deactivating) + fpi_ssm_mark_completed(ssm); + else + aes_write_regv(dev, strip_scan_reqs, G_N_ELEMENTS(strip_scan_reqs), + generic_write_regv_cb, ssm); + break; + case CAPTURE_READ_STRIP: ; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + break; + } + + data = g_malloc(1705); + libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, 1705, + capture_read_strip_cb, ssm, BULK_TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } + break; + }; +} + +static void capture_sm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct aes2501_dev *aesdev = dev->priv; + + fp_dbg(""); + if (aesdev->deactivating) + complete_deactivation(dev); + else if (ssm->error) + fpi_imgdev_session_error(dev, ssm->error); + else + start_finger_detection(dev); + fpi_ssm_free(ssm); +} + +static void start_capture(struct fp_img_dev *dev) +{ + struct aes2501_dev *aesdev = dev->priv; + struct fpi_ssm *ssm; + + if (aesdev->deactivating) { + complete_deactivation(dev); + return; + } + + ssm = fpi_ssm_new(dev->dev, capture_run_state, CAPTURE_NUM_STATES); + fp_dbg(""); + ssm->priv = dev; + fpi_ssm_start(ssm, capture_sm_complete); +} + +/****** INITIALIZATION/DEINITIALIZATION ******/ + +static const struct aes_regwrite init_1[] = { + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { 0, 0 }, + { 0xb0, 0x27 }, /* Reserved? */ + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { 0xff, 0x00 }, /* Reserved? */ + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_DETCTRL, + AES2501_DETCTRL_DRATE_CONTINUOUS | AES2501_DETCTRL_SDELAY_31_MS }, + { AES2501_REG_COLSCAN, AES2501_COLSCAN_SRATE_128_US }, + { AES2501_REG_MEASDRV, + AES2501_MEASDRV_MDRIVE_0_325 | AES2501_MEASDRV_MEASURE_SQUARE }, + { AES2501_REG_MEASFREQ, AES2501_MEASFREQ_2M }, + { AES2501_REG_DEMODPHASE1, DEMODPHASE_NONE }, + { AES2501_REG_DEMODPHASE2, DEMODPHASE_NONE }, + { AES2501_REG_CHANGAIN, + AES2501_CHANGAIN_STAGE2_4X | AES2501_CHANGAIN_STAGE1_16X }, + { AES2501_REG_ADREFHI, 0x44 }, + { AES2501_REG_ADREFLO, 0x34 }, + { AES2501_REG_STRTCOL, 0x16 }, + { AES2501_REG_ENDCOL, 0x16 }, + { AES2501_REG_DATFMT, AES2501_DATFMT_BIN_IMG | 0x08 }, + { AES2501_REG_TREG1, 0x70 }, + { 0xa2, 0x02 }, + { 0xa7, 0x00 }, + { AES2501_REG_TREGC, AES2501_TREGC_ENABLE }, + { AES2501_REG_TREGD, 0x1a }, + { AES2501_REG_CTRL1, AES2501_CTRL1_REG_UPDATE }, + { AES2501_REG_CTRL2, AES2501_CTRL2_SET_ONE_SHOT }, + { AES2501_REG_LPONT, AES2501_LPONT_MIN_VALUE }, +}; + +static const struct aes_regwrite init_2[] = { + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_AUTOCALOFFSET, 0x41 }, + { AES2501_REG_EXCITCTRL, 0x42 }, + { AES2501_REG_DETCTRL, 0x53 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_REG_UPDATE }, +}; + +static const struct aes_regwrite init_3[] = { + { 0xff, 0x00 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_AUTOCALOFFSET, 0x41 }, + { AES2501_REG_EXCITCTRL, 0x42 }, + { AES2501_REG_DETCTRL, 0x53 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_REG_UPDATE }, +}; + +static const struct aes_regwrite init_4[] = { + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { 0xb0, 0x27 }, + { AES2501_REG_ENDROW, 0x0a }, + { AES2501_REG_CTRL1, AES2501_CTRL1_REG_UPDATE }, + { AES2501_REG_DETCTRL, 0x45 }, + { AES2501_REG_AUTOCALOFFSET, 0x41 }, +}; + +static const struct aes_regwrite init_5[] = { + { 0xb0, 0x27 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { 0xff, 0x00 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_MASTER_RESET }, + { AES2501_REG_EXCITCTRL, 0x40 }, + { AES2501_REG_CTRL1, AES2501_CTRL1_SCAN_RESET }, + { AES2501_REG_CTRL1, AES2501_CTRL1_SCAN_RESET }, +}; + +enum activate_states { + WRITE_INIT_1, + READ_DATA_1, + WRITE_INIT_2, + READ_REGS, + WRITE_INIT_3, + WRITE_INIT_4, + WRITE_INIT_5, + ACTIVATE_NUM_STATES, +}; + +void activate_read_regs_cb(struct fp_img_dev *dev, int status, + unsigned char *regs, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + struct aes2501_dev *aesdev = dev->priv; + + if (status != 0) { + fpi_ssm_mark_aborted(ssm, status); + } else { + fp_dbg("reg 0xaf = %x", regs[0x5f]); + if (regs[0x5f] != 0x6b || ++aesdev->read_regs_retry_count == 13) + fpi_ssm_jump_to_state(ssm, WRITE_INIT_4); + else + fpi_ssm_next_state(ssm); + } +} + +static void activate_init3_cb(struct fp_img_dev *dev, int result, + void *user_data) +{ + struct fpi_ssm *ssm = user_data; + if (result == 0) + fpi_ssm_jump_to_state(ssm, READ_REGS); + else + fpi_ssm_mark_aborted(ssm, result); +} + +static void activate_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + + /* This state machine isn't as linear as it may appear. After doing init1 + * and init2 register configuration writes, we have to poll a register + * waiting for a specific value. READ_REGS checks the register value, and + * if we're ready to move on, we jump to init4. Otherwise, we write init3 + * and then jump back to READ_REGS. In a synchronous model: + + [...] + aes_write_regv(init_2); + read_regs(into buffer); + i = 0; + while (buffer[0x5f] == 0x6b) { + aes_write_regv(init_3); + read_regs(into buffer); + if (++i == 13) + break; + } + aes_write_regv(init_4); + */ + + switch (ssm->cur_state) { + case WRITE_INIT_1: + aes_write_regv(dev, init_1, G_N_ELEMENTS(init_1), + generic_write_regv_cb, ssm); + break; + case READ_DATA_1: + fp_dbg("read data 1"); + generic_read_ignore_data(ssm, 20); + break; + case WRITE_INIT_2: + aes_write_regv(dev, init_2, G_N_ELEMENTS(init_2), + generic_write_regv_cb, ssm); + break; + case READ_REGS: + read_regs(dev, activate_read_regs_cb, ssm); + break; + case WRITE_INIT_3: + aes_write_regv(dev, init_4, G_N_ELEMENTS(init_4), + activate_init3_cb, ssm); + break; + case WRITE_INIT_4: + aes_write_regv(dev, init_4, G_N_ELEMENTS(init_4), + generic_write_regv_cb, ssm); + break; + case WRITE_INIT_5: + aes_write_regv(dev, init_5, G_N_ELEMENTS(init_5), + generic_write_regv_cb, ssm); + break; + } +} + +static void activate_sm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + fp_dbg("status %d", ssm->error); + fpi_imgdev_activate_complete(dev, ssm->error); + + if (!ssm->error) + start_finger_detection(dev); + fpi_ssm_free(ssm); +} + +static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + struct aes2501_dev *aesdev = dev->priv; + struct fpi_ssm *ssm = fpi_ssm_new(dev->dev, activate_run_state, + ACTIVATE_NUM_STATES); + ssm->priv = dev; + aesdev->read_regs_retry_count = 0; + fpi_ssm_start(ssm, activate_sm_complete); + return 0; +} + +static void dev_deactivate(struct fp_img_dev *dev) +{ + struct aes2501_dev *aesdev = dev->priv; + /* FIXME: audit cancellation points, probably need more, specifically + * in error handling paths? */ + aesdev->deactivating = TRUE; +} + +static void complete_deactivation(struct fp_img_dev *dev) +{ + struct aes2501_dev *aesdev = dev->priv; + fp_dbg(""); + + /* FIXME: if we're in the middle of a scan, we should cancel the scan. + * maybe we can do this with a master reset, unconditionally? */ + + aesdev->deactivating = FALSE; + g_slist_free(aesdev->strips); + aesdev->strips = NULL; + aesdev->strips_len = 0; + fpi_imgdev_deactivate_complete(dev); +} + +static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + /* FIXME check endpoints */ + int r; + + r = libusb_claim_interface(dev->udev, 0); + if (r < 0) { + fp_err("could not claim interface 0"); + return r; + } + + dev->priv = g_malloc0(sizeof(struct aes2501_dev)); + fpi_imgdev_open_complete(dev, 0); + return 0; +} + +static void dev_deinit(struct fp_img_dev *dev) +{ + g_free(dev->priv); + libusb_release_interface(dev->udev, 0); + fpi_imgdev_close_complete(dev); +} + +static const struct usb_id id_table[] = { + { .vendor = 0x08ff, .product = 0x2500 }, /* AES2500 */ + { .vendor = 0x08ff, .product = 0x2580 }, /* AES2501 */ + { 0, 0, 0, }, +}; + +struct fp_img_driver aes2501_driver = { + .driver = { + .id = 4, + .name = FP_COMPONENT, + .full_name = "AuthenTec AES2501", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_SWIPE, + }, + .flags = 0, + .img_height = -1, + .img_width = 192, + + .open = dev_init, + .close = dev_deinit, + .activate = dev_activate, + .deactivate = dev_deactivate, +}; + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/aes2501.h.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/aes2501.h.svn-base @@ -0,0 +1,170 @@ +/* + * AuthenTec AES2501 driver for libfprint + * Copyright (C) 2007 Cyrille Bagard + * + * Based on code from http://home.gna.org/aes2501, relicensed with permission + * + * 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 + */ + +#ifndef __AES2501_H +#define __AES2501_H + +enum aes2501_regs { + AES2501_REG_CTRL1 = 0x80, + AES2501_REG_CTRL2 = 0x81, + AES2501_REG_EXCITCTRL = 0x82, /* excitation control */ + AES2501_REG_DETCTRL = 0x83, /* detect control */ + AES2501_REG_COLSCAN = 0x88, /* column scan rate register */ + AES2501_REG_MEASDRV = 0x89, /* measure drive */ + AES2501_REG_MEASFREQ = 0x8a, /* measure frequency */ + AES2501_REG_DEMODPHASE1 = 0x8d, + AES2501_REG_DEMODPHASE2 = 0x8c, + AES2501_REG_CHANGAIN = 0x8e, /* channel gain */ + AES2501_REG_ADREFHI = 0x91, /* A/D reference high */ + AES2501_REG_ADREFLO = 0x92, /* A/D reference low */ + AES2501_REG_STRTROW = 0x93, /* start row */ + AES2501_REG_ENDROW = 0x94, /* end row */ + AES2501_REG_STRTCOL = 0x95, /* start column */ + AES2501_REG_ENDCOL = 0x96, /* end column */ + AES2501_REG_DATFMT = 0x97, /* data format */ + AES2501_REG_IMAGCTRL = 0x98, /* image data */ + AES2501_REG_STAT = 0x9a, + AES2501_REG_CHWORD1 = 0x9b, /* challenge word 1 */ + AES2501_REG_CHWORD2 = 0x9c, + AES2501_REG_CHWORD3 = 0x9d, + AES2501_REG_CHWORD4 = 0x9e, + AES2501_REG_CHWORD5 = 0x9f, + AES2501_REG_TREG1 = 0xa1, /* test register 1 */ + AES2501_REG_AUTOCALOFFSET = 0xa8, + AES2501_REG_TREGC = 0xac, + AES2501_REG_TREGD = 0xad, + AES2501_REG_LPONT = 0xb4, /* low power oscillator on time */ +}; + +#define FIRST_AES2501_REG AES2501_REG_CTRL1 +#define LAST_AES2501_REG AES2501_REG_CHWORD5 + +#define AES2501_CTRL1_MASTER_RESET (1<<0) +#define AES2501_CTRL1_SCAN_RESET (1<<1) /* stop + restart scan sequencer */ +/* 1 = continuously updated, 0 = updated prior to starting a scan */ +#define AES2501_CTRL1_REG_UPDATE (1<<2) + +/* 1 = continuous scans, 0 = single scans */ +#define AES2501_CTRL2_CONTINUOUS 0x01 +#define AES2501_CTRL2_READ_REGS 0x02 /* dump registers */ +#define AES2501_CTRL2_SET_ONE_SHOT 0x04 +#define AES2501_CTRL2_CLR_ONE_SHOT 0x08 +#define AES2501_CTRL2_READ_ID 0x10 + +enum aes2501_detection_rate { + /* rate of detection cycles: */ + AES2501_DETCTRL_DRATE_CONTINUOUS = 0x00, /* continuously */ + AES2501_DETCTRL_DRATE_16_MS = 0x01, /* every 16.62ms */ + AES2501_DETCTRL_DRATE_31_MS = 0x02, /* every 31.24ms */ + AES2501_DETCTRL_DRATE_62_MS = 0x03, /* every 62.50ms */ + AES2501_DETCTRL_DRATE_125_MS = 0x04, /* every 125.0ms */ + AES2501_DETCTRL_DRATE_250_MS = 0x05, /* every 250.0ms */ + AES2501_DETCTRL_DRATE_500_MS = 0x06, /* every 500.0ms */ + AES2501_DETCTRL_DRATE_1_S = 0x07, /* every 1s */ +}; + +enum aes2501_settling_delay { + AES2501_DETCTRL_SDELAY_31_MS = 0x00, /* 31.25ms */ + AES2501_DETCTRL_SSDELAY_62_MS = 0x10, /* 62.5ms */ + AES2501_DETCTRL_SSDELAY_125_MS = 0x20, /* 125ms */ + AES2501_DETCTRL_SSDELAY_250_MS = 0x30 /* 250ms */ +}; + +enum aes2501_col_scan_rate { + AES2501_COLSCAN_SRATE_32_US = 0x00, /* 32us */ + AES2501_COLSCAN_SRATE_64_US = 0x01, /* 64us */ + AES2501_COLSCAN_SRATE_128_US = 0x02, /* 128us */ + AES2501_COLSCAN_SRATE_256_US = 0x03, /* 256us */ + AES2501_COLSCAN_SRATE_512_US = 0x04, /* 512us */ + AES2501_COLSCAN_SRATE_1024_US = 0x05, /* 1024us */ + AES2501_COLSCAN_SRATE_2048_US = 0x06, /* 2048us */ + +}; + +enum aes2501_mesure_drive { + AES2501_MEASDRV_MDRIVE_0_325 = 0x00, /* 0.325 Vpp */ + AES2501_MEASDRV_MDRIVE_0_65 = 0x01, /* 0.65 Vpp */ + AES2501_MEASDRV_MDRIVE_1_3 = 0x02, /* 1.3 Vpp */ + AES2501_MEASDRV_MDRIVE_2_6 = 0x03 /* 2.6 Vpp */ + +}; + +/* Select (1=square | 0=sine) wave drive during measure */ +#define AES2501_MEASDRV_SQUARE 0x20 +/* 0 = use mesure drive setting, 1 = when sine wave is selected */ +#define AES2501_MEASDRV_MEASURE_SQUARE 0x10 + +enum aes2501_measure_freq { + AES2501_MEASFREQ_125K = 0x01, /* 125 kHz */ + AES2501_MEASFREQ_250K = 0x02, /* 250 kHz */ + AES2501_MEASFREQ_500K = 0x03, /* 500 kHz */ + AES2501_MEASFREQ_1M = 0x04, /* 1 MHz */ + AES2501_MEASFREQ_2M = 0x05 /* 2 MHz */ +}; + +#define DEMODPHASE_NONE 0x00 +#define DEMODPHASE_180_00 0x40 /* 180 degrees */ +#define DEMODPHASE_2_81 0x01 /* 2.8125 degrees */ + +#define AES2501_REG_DEMODPHASE1 0x8d +#define DEMODPHASE_1_40 0x40 /* 1.40625 degrees */ +#define DEMODPHASE_0_02 0x01 /* 0.02197256 degrees */ + +enum aes2501_sensor_gain1 { + AES2501_CHANGAIN_STAGE1_2X = 0x00, /* 2x */ + AES2501_CHANGAIN_STAGE1_4X = 0x01, /* 4x */ + AES2501_CHANGAIN_STAGE1_8X = 0x02, /* 8x */ + AES2501_CHANGAIN_STAGE1_16X = 0x03 /* 16x */ +}; + +enum aes2501_sensor_gain2 { + AES2501_CHANGAIN_STAGE2_2X = 0x00, /* 2x */ + AES2501_CHANGAIN_STAGE2_4X = 0x10, /* 4x */ + AES2501_CHANGAIN_STAGE2_8X = 0x20, /* 8x */ + AES2501_CHANGAIN_STAGE2_16X = 0x30 /* 16x */ +}; + +#define AES2501_DATFMT_EIGHT 0x40 /* 1 = 8-bit data, 0 = 4-bit data */ +#define AES2501_DATFMT_LOW_RES 0x20 +#define AES2501_DATFMT_BIN_IMG 0x10 + +/* don't send image or authentication messages when imaging */ +#define AES2501_IMAGCTRL_IMG_DATA_DISABLE 0x01 +/* send histogram when imaging */ +#define AES2501_IMAGCTRL_HISTO_DATA_ENABLE 0x02 +/* send histogram at end of each row rather than each scan */ +#define AES2501_IMAGCTRL_HISTO_EACH_ROW 0x04 +/* send full image array rather than 64x64 center */ +#define AES2501_IMAGCTRL_HISTO_FULL_ARRAY 0x08 +/* return registers before data (rather than after) */ +#define AES2501_IMAGCTRL_REG_FIRST 0x10 +/* return test registers with register dump */ +#define AES2501_IMAGCTRL_TST_REG_ENABLE 0x20 + +#define AES2501_CHWORD1_IS_FINGER 0x01 /* If set, finger is present */ + +/* Enable the reading of the register in TREGD */ +#define AES2501_TREGC_ENABLE 0x01 + +#define AES2501_LPONT_MIN_VALUE 0x00 /* 0 ms */ +#define AES2501_LPONT_MAX_VALUE 0x1f /* About 16 ms */ + +#endif /* __AES2501_H */ --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/uru4000.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/uru4000.c.svn-base @@ -0,0 +1,1242 @@ +/* + * Digital Persona U.are.U 4000/4000B driver for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "uru4000" + +#include +#include +#include + +#include +#include + +#include + +#define EP_INTR (1 | LIBUSB_ENDPOINT_IN) +#define EP_DATA (2 | LIBUSB_ENDPOINT_IN) +#define USB_RQ 0x04 +#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN) +#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT) +#define CTRL_TIMEOUT 5000 +#define BULK_TIMEOUT 5000 +#define DATABLK_RQLEN 0x1b340 +#define DATABLK_EXPECT 0x1b1c0 +#define CAPTURE_HDRLEN 64 +#define IRQ_LENGTH 64 +#define CR_LENGTH 16 + +enum { + IRQDATA_SCANPWR_ON = 0x56aa, + IRQDATA_FINGER_ON = 0x0101, + IRQDATA_FINGER_OFF = 0x0200, + IRQDATA_DEATH = 0x0800, +}; + +enum { + REG_HWSTAT = 0x07, + REG_MODE = 0x4e, + /* firmware starts at 0x100 */ + REG_RESPONSE = 0x2000, + REG_CHALLENGE = 0x2010, +}; + +enum { + MODE_INIT = 0x00, + MODE_AWAIT_FINGER_ON = 0x10, + MODE_AWAIT_FINGER_OFF = 0x12, + MODE_CAPTURE = 0x20, + MODE_SHUT_UP = 0x30, + MODE_READY = 0x80, +}; + +enum { + MS_KBD, + MS_INTELLIMOUSE, + MS_STANDALONE, + MS_STANDALONE_V2, + DP_URU4000, + DP_URU4000B, +}; + +static const struct uru4k_dev_profile { + const char *name; + gboolean auth_cr; +} uru4k_dev_info[] = { + [MS_KBD] = { + .name = "Microsoft Keyboard with Fingerprint Reader", + .auth_cr = FALSE, + }, + [MS_INTELLIMOUSE] = { + .name = "Microsoft Wireless IntelliMouse with Fingerprint Reader", + .auth_cr = FALSE, + }, + [MS_STANDALONE] = { + .name = "Microsoft Fingerprint Reader", + .auth_cr = FALSE, + }, + [MS_STANDALONE_V2] = { + .name = "Microsoft Fingerprint Reader v2", + .auth_cr = TRUE, + }, + [DP_URU4000] = { + .name = "Digital Persona U.are.U 4000", + .auth_cr = FALSE, + }, + [DP_URU4000B] = { + .name = "Digital Persona U.are.U 4000B", + .auth_cr = FALSE, + }, +}; + +/* As we don't know the encryption scheme, we have to disable encryption + * by powering the device down and modifying the firmware. The location of + * the encryption control byte changes based on device revision. + * + * We use a search approach to find it: we look at the 3 bytes of data starting + * from these addresses, looking for a pattern "ff X7 41" (where X is dontcare) + * When we find a pattern we know that the encryption byte ius the X7 byte. + */ +static const uint16_t fwenc_offsets[] = { + 0x510, 0x62d, 0x792, 0x7f4, +}; + +typedef void (*irq_cb_fn)(struct fp_img_dev *dev, int status, uint16_t type, + void *user_data); +typedef void (*irqs_stopped_cb_fn)(struct fp_img_dev *dev); + +struct uru4k_dev { + const struct uru4k_dev_profile *profile; + uint8_t interface; + enum fp_imgdev_state activate_state; + unsigned char last_reg_rd; + unsigned char last_hwstat; + + struct libusb_transfer *irq_transfer; + struct libusb_transfer *img_transfer; + + irq_cb_fn irq_cb; + void *irq_cb_data; + irqs_stopped_cb_fn irqs_stopped_cb; + + int rebootpwr_ctr; + int powerup_ctr; + unsigned char powerup_hwstat; + + int scanpwr_irq_timeouts; + struct fpi_timeout *scanpwr_irq_timeout; + + int fwfixer_offset; + unsigned char fwfixer_value; + + AES_KEY aeskey; +}; + +/* For 2nd generation MS devices */ +static const unsigned char crkey[] = { + 0x79, 0xac, 0x91, 0x79, 0x5c, 0xa1, 0x47, 0x8e, + 0x98, 0xe0, 0x0f, 0x3c, 0x59, 0x8f, 0x5f, 0x4b, +}; + +/***** REGISTER I/O *****/ + +typedef void (*write_regs_cb_fn)(struct fp_img_dev *dev, int status, + void *user_data); + +struct write_regs_data { + struct fp_img_dev *dev; + write_regs_cb_fn callback; + void *user_data; +}; + +static void write_regs_cb(struct libusb_transfer *transfer) +{ + struct write_regs_data *wrdata = transfer->user_data; + struct libusb_control_setup *setup = + libusb_control_transfer_get_setup(transfer); + int r = 0; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + r = -EIO; + else if (transfer->actual_length != setup->wLength) + r = -EPROTO; + + g_free(transfer->buffer); + libusb_free_transfer(transfer); + wrdata->callback(wrdata->dev, r, wrdata->user_data); + g_free(wrdata); +} + +static int write_regs(struct fp_img_dev *dev, uint16_t first_reg, + uint16_t num_regs, unsigned char *values, write_regs_cb_fn callback, + void *user_data) +{ + struct write_regs_data *wrdata; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) + return -ENOMEM; + + wrdata = g_malloc(sizeof(*wrdata)); + wrdata->dev = dev; + wrdata->callback = callback; + wrdata->user_data = user_data; + + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + num_regs); + memcpy(data + LIBUSB_CONTROL_SETUP_SIZE, values, num_regs); + libusb_fill_control_setup(data, CTRL_OUT, USB_RQ, first_reg, 0, num_regs); + libusb_fill_control_transfer(transfer, dev->udev, data, write_regs_cb, + wrdata, CTRL_TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(wrdata); + g_free(data); + libusb_free_transfer(transfer); + } + return r; +} + +static int write_reg(struct fp_img_dev *dev, uint16_t reg, + unsigned char value, write_regs_cb_fn callback, void *user_data) +{ + return write_regs(dev, reg, 1, &value, callback, user_data); +} + +typedef void (*read_regs_cb_fn)(struct fp_img_dev *dev, int status, + unsigned char *data, void *user_data); + +struct read_regs_data { + struct fp_img_dev *dev; + read_regs_cb_fn callback; + void *user_data; +}; + +static void read_regs_cb(struct libusb_transfer *transfer) +{ + struct read_regs_data *rrdata = transfer->user_data; + struct libusb_control_setup *setup = + libusb_control_transfer_get_setup(transfer); + unsigned char *data = NULL; + int r = 0; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + r = -EIO; + else if (transfer->actual_length != setup->wLength) + r = -EPROTO; + else + data = libusb_control_transfer_get_data(transfer); + + rrdata->callback(rrdata->dev, r, data, rrdata->user_data); + g_free(rrdata); + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +static int read_regs(struct fp_img_dev *dev, uint16_t first_reg, + uint16_t num_regs, read_regs_cb_fn callback, void *user_data) +{ + struct read_regs_data *rrdata; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) + return -ENOMEM; + + rrdata = g_malloc(sizeof(*rrdata)); + rrdata->dev = dev; + rrdata->callback = callback; + rrdata->user_data = user_data; + + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + num_regs); + libusb_fill_control_setup(data, CTRL_IN, USB_RQ, first_reg, 0, num_regs); + libusb_fill_control_transfer(transfer, dev->udev, data, read_regs_cb, + rrdata, CTRL_TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(rrdata); + g_free(data); + libusb_free_transfer(transfer); + } + return r; +} + +static int read_reg(struct fp_img_dev *dev, uint16_t reg, + read_regs_cb_fn callback, void *user_data) +{ + return read_regs(dev, reg, 1, callback, user_data); +} + +/* + * HWSTAT + * + * This register has caused me a lot of headaches. It pretty much defines + * code flow, and if you don't get it right, the pretty lights don't come on. + * I think the situation is somewhat complicated by the fact that writing it + * doesn't affect the read results in the way you'd expect -- but then again + * it does have some obvious effects. Here's what we know + * + * BIT 7: LOW POWER MODE + * When this bit is set, the device is partially turned off or something. Some + * things, like firmware upload, need to be done in this state. But generally + * we want to clear this bit during late initialization, which can sometimes + * be tricky. + * + * BIT 2: SOMETHING WENT WRONG + * Not sure about this, but see the init function, as when we detect it, + * we reboot the device. Well, we mess with hwstat until this evil bit gets + * cleared. + * + * BIT 1: IRQ PENDING + * Just had a brainwave. This bit is set when the device is trying to deliver + * and interrupt to the host. Maybe? + */ + +static void response_cb(struct fp_img_dev *dev, int status, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + if (status == 0) + fpi_ssm_next_state(ssm); + else + fpi_ssm_mark_aborted(ssm, status); +} + +static void challenge_cb(struct fp_img_dev *dev, int status, + unsigned char *data, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + struct uru4k_dev *urudev = dev->priv; + unsigned char *respdata; + int r; + + if (status != 0) { + fpi_ssm_mark_aborted(ssm, status); + return; + } + + /* submit response */ + /* produce response from challenge */ + /* FIXME would this work in-place? */ + respdata = g_malloc(CR_LENGTH); + AES_encrypt(data, respdata, &urudev->aeskey); + + r = write_regs(dev, REG_RESPONSE, CR_LENGTH, respdata, response_cb, ssm); + g_free(respdata); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); +} + +/* + * 2nd generation MS devices added an AES-based challenge/response + * authentication scheme, where the device challenges the authenticity of the + * driver. + */ +static void sm_do_challenge_response(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + int r; + + fp_dbg(""); + r = read_regs(dev, REG_CHALLENGE, CR_LENGTH, challenge_cb, ssm); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); +} + +/***** INTERRUPT HANDLING *****/ + +#define IRQ_HANDLER_IS_RUNNING(urudev) ((urudev)->irq_transfer) + +static int start_irq_handler(struct fp_img_dev *dev); + +static void irq_handler(struct libusb_transfer *transfer) +{ + struct fp_img_dev *dev = transfer->user_data; + struct uru4k_dev *urudev = dev->priv; + unsigned char *data = transfer->buffer; + uint16_t type; + int r = 0; + + if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { + fp_dbg("cancelled"); + if (urudev->irqs_stopped_cb) + urudev->irqs_stopped_cb(dev); + urudev->irqs_stopped_cb = NULL; + goto out; + } else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + r = -EIO; + goto err; + } else if (transfer->actual_length != transfer->length) { + fp_err("short interrupt read? %d", transfer->actual_length); + r = -EPROTO; + goto err; + } + + type = GUINT16_FROM_BE(*((uint16_t *) data)); + fp_dbg("recv irq type %04x", type); + g_free(data); + libusb_free_transfer(transfer); + + /* The 0800 interrupt seems to indicate imminent failure (0 bytes transfer) + * of the next scan. It still appears on occasion. */ + if (type == IRQDATA_DEATH) + fp_warn("oh no! got the interrupt OF DEATH! expect things to go bad"); + + if (urudev->irq_cb) + urudev->irq_cb(dev, 0, type, urudev->irq_cb_data); + else + fp_dbg("ignoring interrupt"); + + r = start_irq_handler(dev); + if (r == 0) + return; + + transfer = NULL; + data = NULL; +err: + if (urudev->irq_cb) + urudev->irq_cb(dev, r, 0, urudev->irq_cb_data); +out: + g_free(data); + libusb_free_transfer(transfer); + urudev->irq_transfer = NULL; +} + +static int start_irq_handler(struct fp_img_dev *dev) +{ + struct uru4k_dev *urudev = dev->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) + return -ENOMEM; + + data = g_malloc(IRQ_LENGTH); + libusb_fill_bulk_transfer(transfer, dev->udev, EP_INTR, data, IRQ_LENGTH, + irq_handler, dev, 0); + + urudev->irq_transfer = transfer; + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + urudev->irq_transfer = NULL; + } + return r; +} + +static void stop_irq_handler(struct fp_img_dev *dev, irqs_stopped_cb_fn cb) +{ + struct uru4k_dev *urudev = dev->priv; + struct libusb_transfer *transfer = urudev->irq_transfer; + if (transfer) { + libusb_cancel_transfer(transfer); + urudev->irqs_stopped_cb = cb; + } +} + +/***** IMAGING LOOP *****/ + +static int start_imaging_loop(struct fp_img_dev *dev); + +static void image_cb(struct libusb_transfer *transfer) +{ + struct fp_img_dev *dev = transfer->user_data; + struct uru4k_dev *urudev = dev->priv; + int hdr_skip = CAPTURE_HDRLEN; + int image_size = DATABLK_EXPECT - CAPTURE_HDRLEN; + struct fp_img *img; + int r = 0; + + /* remove the global reference early: otherwise we may report results, + * leading to immediate deactivation of driver, which will potentially + * try to cancel an already-completed transfer */ + urudev->img_transfer = NULL; + + if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { + fp_dbg("cancelled"); + g_free(transfer->buffer); + libusb_free_transfer(transfer); + return; + } else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + r = -EIO; + goto out; + } + + if (transfer->actual_length == image_size) { + /* no header! this is rather odd, but it happens sometimes with my MS + * keyboard */ + fp_dbg("got image with no header!"); + hdr_skip = 0; + } else if (transfer->actual_length != DATABLK_EXPECT) { + fp_err("unexpected image capture size (%d)", transfer->actual_length); + r = -EPROTO; + goto out; + } + + img = fpi_img_new(image_size); + memcpy(img->data, transfer->buffer + hdr_skip, image_size); + img->flags = FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED | FP_IMG_COLORS_INVERTED; + fpi_imgdev_image_captured(dev, img); + +out: + g_free(transfer->buffer); + libusb_free_transfer(transfer); + if (r == 0) + r = start_imaging_loop(dev); + + if (r) + fpi_imgdev_session_error(dev, r); +} + +static int start_imaging_loop(struct fp_img_dev *dev) +{ + struct uru4k_dev *urudev = dev->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) + return -ENOMEM; + + data = g_malloc(DATABLK_RQLEN); + libusb_fill_bulk_transfer(transfer, dev->udev, EP_DATA, data, + DATABLK_RQLEN, image_cb, dev, 0); + + urudev->img_transfer = transfer; + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + } + + return r; +} + +static void stop_imaging_loop(struct fp_img_dev *dev) +{ + struct uru4k_dev *urudev = dev->priv; + struct libusb_transfer *transfer = urudev->img_transfer; + if (transfer) + libusb_cancel_transfer(transfer); + /* FIXME: should probably wait for cancellation to complete */ +} + +/***** STATE CHANGING *****/ + +static void finger_presence_irq_cb(struct fp_img_dev *dev, int status, + uint16_t type, void *user_data) +{ + if (status) + fpi_imgdev_session_error(dev, status); + else if (type == IRQDATA_FINGER_ON) + fpi_imgdev_report_finger_status(dev, TRUE); + else if (type == IRQDATA_FINGER_OFF) + fpi_imgdev_report_finger_status(dev, FALSE); + else + fp_warn("ignoring unexpected interrupt %04x", type); +} + +static void change_state_write_reg_cb(struct fp_img_dev *dev, int status, + void *user_data) +{ + if (status) + fpi_imgdev_session_error(dev, status); +} + +static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + struct uru4k_dev *urudev = dev->priv; + + stop_imaging_loop(dev); + + switch (state) { + case IMGDEV_STATE_AWAIT_FINGER_ON: + if (!IRQ_HANDLER_IS_RUNNING(urudev)) + return -EIO; + urudev->irq_cb = finger_presence_irq_cb; + return write_reg(dev, REG_MODE, MODE_AWAIT_FINGER_ON, + change_state_write_reg_cb, NULL); + + case IMGDEV_STATE_CAPTURE: + urudev->irq_cb = NULL; + start_imaging_loop(dev); + return write_reg(dev, REG_MODE, MODE_CAPTURE, change_state_write_reg_cb, + NULL); + + case IMGDEV_STATE_AWAIT_FINGER_OFF: + if (!IRQ_HANDLER_IS_RUNNING(urudev)) + return -EIO; + urudev->irq_cb = finger_presence_irq_cb; + return write_reg(dev, REG_MODE, MODE_AWAIT_FINGER_OFF, + change_state_write_reg_cb, NULL); + + default: + fp_err("unrecognised state %d", state); + return -EINVAL; + } +} + +/***** GENERIC STATE MACHINE HELPER FUNCTIONS *****/ + +static void sm_write_reg_cb(struct fp_img_dev *dev, int result, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + + if (result) + fpi_ssm_mark_aborted(ssm, result); + else + fpi_ssm_next_state(ssm); +} + +static void sm_write_reg(struct fpi_ssm *ssm, uint16_t reg, + unsigned char value) +{ + struct fp_img_dev *dev = ssm->priv; + int r = write_reg(dev, reg, value, sm_write_reg_cb, ssm); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); +} + +static void sm_read_reg_cb(struct fp_img_dev *dev, int result, + unsigned char *data, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + struct uru4k_dev *urudev = dev->priv; + + if (result) { + fpi_ssm_mark_aborted(ssm, result); + } else { + urudev->last_reg_rd = *data; + fp_dbg("reg value %x", urudev->last_reg_rd); + fpi_ssm_next_state(ssm); + } +} + +static void sm_read_reg(struct fpi_ssm *ssm, uint16_t reg) +{ + struct fp_img_dev *dev = ssm->priv; + int r; + + fp_dbg("read reg %x", reg); + r = read_reg(dev, reg, sm_read_reg_cb, ssm); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); +} + +static void sm_set_mode(struct fpi_ssm *ssm, unsigned char mode) +{ + fp_dbg("mode %02x", mode); + sm_write_reg(ssm, REG_MODE, mode); +} + +static void sm_set_hwstat(struct fpi_ssm *ssm, unsigned char value) +{ + fp_dbg("set %02x", value); + sm_write_reg(ssm, REG_HWSTAT, value); +} + +/***** INITIALIZATION *****/ + +enum fwfixer_states { + FWFIXER_INIT, + FWFIXER_READ_NEXT, + FWFIXER_WRITE, + FWFIXER_NUM_STATES, +}; + +static void fwfixer_read_cb(struct fp_img_dev *dev, int status, + unsigned char *data, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + struct uru4k_dev *urudev = dev->priv; + + if (status != 0) + fpi_ssm_mark_aborted(ssm, status); + + fp_dbg("data: %02x %02x %02x", data[0], data[1], data[2]); + if (data[0] == 0xff && (data[1] & 0x0f) == 0x07 && data[2] == 0x41) { + fp_dbg("using offset %x", fwenc_offsets[urudev->fwfixer_offset]); + urudev->fwfixer_value = data[1]; + fpi_ssm_jump_to_state(ssm, FWFIXER_WRITE); + } else { + fpi_ssm_jump_to_state(ssm, FWFIXER_READ_NEXT); + } +} + +static void fwfixer_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + int r; + + switch (ssm->cur_state) { + case FWFIXER_INIT: + urudev->fwfixer_offset = -1; + fpi_ssm_next_state(ssm); + break; + case FWFIXER_READ_NEXT: ; + int offset = ++urudev->fwfixer_offset; + uint16_t try_addr; + + if (offset == G_N_ELEMENTS(fwenc_offsets)) { + fp_err("could not find encryption byte"); + fpi_ssm_mark_aborted(ssm, -ENODEV); + return; + } + + try_addr = fwenc_offsets[offset]; + fp_dbg("looking for encryption byte at %x", try_addr); + + r = read_regs(dev, try_addr, 3, fwfixer_read_cb, ssm); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); + break; + case FWFIXER_WRITE: ; + uint16_t enc_addr = fwenc_offsets[urudev->fwfixer_offset] + 1; + unsigned char cur = urudev->fwfixer_value; + unsigned char new = cur & 0xef; + if (new == cur) { + fp_dbg("encryption is already disabled"); + fpi_ssm_next_state(ssm); + } else { + fp_dbg("fixing encryption byte at %x to %02x", enc_addr, new); + sm_write_reg(ssm, enc_addr, new); + } + break; + } +} + +/* After closing an app and setting hwstat to 0x80, my ms keyboard gets in a + * confused state and returns hwstat 0x85. On next app run, we don't get the + * 56aa interrupt. This is the best way I've found to fix it: mess around + * with hwstat until it starts returning more recognisable values. This + * doesn't happen on my other devices: uru4000, uru4000b, ms fp rdr v2 + * + * The windows driver copes with this OK, but then again it uploads firmware + * right after reading the 0x85 hwstat, allowing some time to pass before it + * attempts to tweak hwstat again... + * + * This is implemented with a reboot power state machine. the ssm runs during + * initialization if bits 2 and 7 are set in hwstat. it masks off the 4 high + * hwstat bits then checks that bit 1 is set. if not, it pauses before reading + * hwstat again. machine completes when reading hwstat shows bit 1 is set, + * and fails after 100 tries. */ + +enum rebootpwr_states { + REBOOTPWR_SET_HWSTAT = 0, + REBOOTPWR_GET_HWSTAT, + REBOOTPWR_CHECK_HWSTAT, + REBOOTPWR_PAUSE, + REBOOTPWR_NUM_STATES, +}; + +static void rebootpwr_pause_cb(void *data) +{ + struct fpi_ssm *ssm = data; + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + + if (!--urudev->rebootpwr_ctr) { + fp_err("could not reboot device power"); + fpi_ssm_mark_aborted(ssm, -EIO); + } else { + fpi_ssm_jump_to_state(ssm, REBOOTPWR_GET_HWSTAT); + } +} + +static void rebootpwr_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + + switch (ssm->cur_state) { + case REBOOTPWR_SET_HWSTAT: + urudev->rebootpwr_ctr = 100; + sm_set_hwstat(ssm, urudev->last_hwstat & 0xf); + break; + case REBOOTPWR_GET_HWSTAT: + sm_read_reg(ssm, REG_HWSTAT); + break; + case REBOOTPWR_CHECK_HWSTAT: + urudev->last_hwstat = urudev->last_reg_rd; + if (urudev->last_hwstat & 0x1) + fpi_ssm_mark_completed(ssm); + else + fpi_ssm_next_state(ssm); + break; + case REBOOTPWR_PAUSE: + if (fpi_timeout_add(10, rebootpwr_pause_cb, ssm) == NULL) + fpi_ssm_mark_aborted(ssm, -ETIME); + break; + } +} + +/* After messing with the device firmware in it's low-power state, we have to + * power it back up and wait for interrupt notification. It's not quite as easy + * as that: the combination of both modifying firmware *and* doing C-R auth on + * my ms fp v2 device causes us not to get to get the 56aa interrupt and + * for the hwstat write not to take effect. We have to loop a few times, + * authenticating each time, until the device wakes up. + * + * This is implemented as the powerup state machine below. Pseudo-code: + + status = get_hwstat(); + for (i = 0; i < 100; i++) { + set_hwstat(status & 0xf); + if ((get_hwstat() & 0x80) == 0) + break; + + usleep(10000); + if (need_auth_cr) + auth_cr(); + } + + if (tmp & 0x80) + error("could not power up device"); + + */ + +enum powerup_states { + POWERUP_INIT = 0, + POWERUP_SET_HWSTAT, + POWERUP_GET_HWSTAT, + POWERUP_CHECK_HWSTAT, + POWERUP_PAUSE, + POWERUP_CHALLENGE_RESPONSE, + POWERUP_CHALLENGE_RESPONSE_SUCCESS, + POWERUP_NUM_STATES, +}; + +static void powerup_pause_cb(void *data) +{ + struct fpi_ssm *ssm = data; + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + + if (!--urudev->powerup_ctr) { + fp_err("could not power device up"); + fpi_ssm_mark_aborted(ssm, -EIO); + } else if (!urudev->profile->auth_cr) { + fpi_ssm_jump_to_state(ssm, POWERUP_SET_HWSTAT); + } else { + fpi_ssm_next_state(ssm); + } +} + +static void powerup_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + + switch (ssm->cur_state) { + case POWERUP_INIT: + urudev->powerup_ctr = 100; + urudev->powerup_hwstat = urudev->last_hwstat & 0xf; + fpi_ssm_next_state(ssm); + break; + case POWERUP_SET_HWSTAT: + sm_set_hwstat(ssm, urudev->powerup_hwstat); + break; + case POWERUP_GET_HWSTAT: + sm_read_reg(ssm, REG_HWSTAT); + break; + case POWERUP_CHECK_HWSTAT: + urudev->last_hwstat = urudev->last_reg_rd; + if ((urudev->last_reg_rd & 0x80) == 0) + fpi_ssm_mark_completed(ssm); + else + fpi_ssm_next_state(ssm); + break; + case POWERUP_PAUSE: + if (fpi_timeout_add(10, powerup_pause_cb, ssm) == NULL) + fpi_ssm_mark_aborted(ssm, -ETIME); + break; + case POWERUP_CHALLENGE_RESPONSE: + sm_do_challenge_response(ssm); + break; + case POWERUP_CHALLENGE_RESPONSE_SUCCESS: + fpi_ssm_jump_to_state(ssm, POWERUP_SET_HWSTAT); + break; + } +} + +/* + * This is the main initialization state machine. As pseudo-code: + + status = get_hwstat(); + + // correct device power state + if ((status & 0x84) == 0x84) + run_reboot_sm(); + + // power device down + if ((status & 0x80) == 0) + set_hwstat(status | 0x80); + + // disable encryption + fwenc = read_firmware_encryption_byte(); + new = fwenc & 0xef; + if (new != fwenc) + write_firmware_encryption_byte(new); + + // power device up + run_powerup_sm(); + await_irq(IRQDATA_SCANPWR_ON); + */ + +enum init_states { + INIT_GET_HWSTAT = 0, + INIT_CHECK_HWSTAT_REBOOT, + INIT_REBOOT_POWER, + INIT_CHECK_HWSTAT_POWERDOWN, + INIT_FIX_FIRMWARE, + INIT_POWERUP, + INIT_AWAIT_SCAN_POWER, + INIT_DONE, + INIT_NUM_STATES, +}; + +static void init_scanpwr_irq_cb(struct fp_img_dev *dev, int status, + uint16_t type, void *user_data) +{ + struct fpi_ssm *ssm = user_data; + + if (status) + fpi_ssm_mark_aborted(ssm, status); + else if (type != IRQDATA_SCANPWR_ON) + fp_dbg("ignoring interrupt"); + else if (ssm->cur_state != INIT_AWAIT_SCAN_POWER) + fp_err("ignoring scanpwr interrupt due to being in wrong state %d", + ssm->cur_state); + else + fpi_ssm_next_state(ssm); +} + +static void init_scanpwr_timeout(void *user_data) +{ + struct fpi_ssm *ssm = user_data; + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + + fp_warn("powerup timed out"); + urudev->irq_cb = NULL; + urudev->scanpwr_irq_timeout = NULL; + + if (++urudev->scanpwr_irq_timeouts >= 3) { + fp_err("powerup timed out 3 times, giving up"); + fpi_ssm_mark_aborted(ssm, -ETIMEDOUT); + } else { + fpi_ssm_jump_to_state(ssm, INIT_GET_HWSTAT); + } +} + +static void init_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + + switch (ssm->cur_state) { + case INIT_GET_HWSTAT: + sm_read_reg(ssm, REG_HWSTAT); + break; + case INIT_CHECK_HWSTAT_REBOOT: + urudev->last_hwstat = urudev->last_reg_rd; + if ((urudev->last_hwstat & 0x84) == 0x84) + fpi_ssm_next_state(ssm); + else + fpi_ssm_jump_to_state(ssm, INIT_CHECK_HWSTAT_POWERDOWN); + break; + case INIT_REBOOT_POWER: ; + struct fpi_ssm *rebootsm = fpi_ssm_new(dev->dev, rebootpwr_run_state, + REBOOTPWR_NUM_STATES); + rebootsm->priv = dev; + fpi_ssm_start_subsm(ssm, rebootsm); + break; + case INIT_CHECK_HWSTAT_POWERDOWN: + if ((urudev->last_hwstat & 0x80) == 0) + sm_set_hwstat(ssm, urudev->last_hwstat | 0x80); + else + fpi_ssm_next_state(ssm); + break; + case INIT_FIX_FIRMWARE: ; + struct fpi_ssm *fwsm = fpi_ssm_new(dev->dev, fwfixer_run_state, + FWFIXER_NUM_STATES); + fwsm->priv = dev; + fpi_ssm_start_subsm(ssm, fwsm); + break; + case INIT_POWERUP: ; + struct fpi_ssm *powerupsm = fpi_ssm_new(dev->dev, powerup_run_state, + POWERUP_NUM_STATES); + powerupsm->priv = dev; + fpi_ssm_start_subsm(ssm, powerupsm); + break; + case INIT_AWAIT_SCAN_POWER: + if (!IRQ_HANDLER_IS_RUNNING(urudev)) { + fpi_ssm_mark_aborted(ssm, -EIO); + break; + } + + /* sometimes the 56aa interrupt that we are waiting for never arrives, + * so we include this timeout loop to retry the whole process 3 times + * if we don't get an irq any time soon. */ + urudev->scanpwr_irq_timeout = fpi_timeout_add(300, + init_scanpwr_timeout, ssm); + if (!urudev->scanpwr_irq_timeout) { + fpi_ssm_mark_aborted(ssm, -ETIME); + break; + } + + urudev->irq_cb_data = ssm; + urudev->irq_cb = init_scanpwr_irq_cb; + break; + case INIT_DONE: + fpi_timeout_cancel(urudev->scanpwr_irq_timeout); + urudev->scanpwr_irq_timeout = NULL; + urudev->irq_cb_data = NULL; + urudev->irq_cb = NULL; + fpi_ssm_mark_completed(ssm); + break; + } +} + +static void activate_initsm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct uru4k_dev *urudev = dev->priv; + int r = ssm->error; + fpi_ssm_free(ssm); + + if (r) { + fpi_imgdev_activate_complete(dev, r); + return; + } + + r = dev_change_state(dev, urudev->activate_state); + fpi_imgdev_activate_complete(dev, r); +} + +/* FIXME: having state parameter here is kinda useless, will we ever + * see a scenario where the parameter is useful so early on in the activation + * process? asynchronity means that it'll only be used in a later function + * call. */ +static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + struct uru4k_dev *urudev = dev->priv; + struct fpi_ssm *ssm; + int r; + + r = start_irq_handler(dev); + if (r < 0) + return r; + + urudev->scanpwr_irq_timeouts = 0; + urudev->activate_state = state; + ssm = fpi_ssm_new(dev->dev, init_run_state, INIT_NUM_STATES); + ssm->priv = dev; + fpi_ssm_start(ssm, activate_initsm_complete); + return 0; +} + +/***** DEINITIALIZATION *****/ + +enum deinit_states { + DEINIT_SET_MODE_INIT = 0, + DEINIT_POWERDOWN, + DEINIT_NUM_STATES, +}; + +static void deinit_run_state(struct fpi_ssm *ssm) +{ + switch (ssm->cur_state) { + case DEINIT_SET_MODE_INIT: + sm_set_mode(ssm, MODE_INIT); + break; + case DEINIT_POWERDOWN: + sm_set_hwstat(ssm, 0x80); + break; + } +} + +static void deactivate_irqs_stopped(struct fp_img_dev *dev) +{ + fpi_imgdev_deactivate_complete(dev); +} + +static void deactivate_deinitsm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + fpi_ssm_free(ssm); + stop_irq_handler(dev, deactivate_irqs_stopped); +} + +static void dev_deactivate(struct fp_img_dev *dev) +{ + struct uru4k_dev *urudev = dev->priv; + struct fpi_ssm *ssm = fpi_ssm_new(dev->dev, deinit_run_state, + DEINIT_NUM_STATES); + + stop_imaging_loop(dev); + urudev->irq_cb = NULL; + urudev->irq_cb_data = NULL; + ssm->priv = dev; + fpi_ssm_start(ssm, deactivate_deinitsm_complete); +} + +/***** LIBRARY STUFF *****/ + +static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + struct libusb_config_descriptor *config; + const struct libusb_interface *iface = NULL; + const struct libusb_interface_descriptor *iface_desc; + const struct libusb_endpoint_descriptor *ep; + struct uru4k_dev *urudev; + int i; + int r; + + /* Find fingerprint interface */ + r = libusb_get_config_descriptor(libusb_get_device(dev->udev), 0, &config); + if (r < 0) { + fp_err("Failed to get config descriptor"); + return r; + } + for (i = 0; i < config->bNumInterfaces; i++) { + const struct libusb_interface *cur_iface = &config->interface[i]; + + if (cur_iface->num_altsetting < 1) + continue; + + iface_desc = &cur_iface->altsetting[0]; + if (iface_desc->bInterfaceClass == 255 + && iface_desc->bInterfaceSubClass == 255 + && iface_desc->bInterfaceProtocol == 255) { + iface = cur_iface; + break; + } + } + + if (iface == NULL) { + fp_err("could not find interface"); + r = -ENODEV; + goto out; + } + + /* Find/check endpoints */ + + if (iface_desc->bNumEndpoints != 2) { + fp_err("found %d endpoints!?", iface_desc->bNumEndpoints); + r = -ENODEV; + goto out; + } + + ep = &iface_desc->endpoint[0]; + if (ep->bEndpointAddress != EP_INTR + || (ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) != + LIBUSB_TRANSFER_TYPE_INTERRUPT) { + fp_err("unrecognised interrupt endpoint"); + r = -ENODEV; + goto out; + } + + ep = &iface_desc->endpoint[1]; + if (ep->bEndpointAddress != EP_DATA + || (ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) != + LIBUSB_TRANSFER_TYPE_BULK) { + fp_err("unrecognised bulk endpoint"); + r = -ENODEV; + goto out; + } + + /* Device looks like a supported reader */ + + r = libusb_claim_interface(dev->udev, iface_desc->bInterfaceNumber); + if (r < 0) { + fp_err("interface claim failed"); + goto out; + } + + urudev = g_malloc0(sizeof(*urudev)); + urudev->profile = &uru4k_dev_info[driver_data]; + urudev->interface = iface_desc->bInterfaceNumber; + AES_set_encrypt_key(crkey, 128, &urudev->aeskey); + dev->priv = urudev; + fpi_imgdev_open_complete(dev, 0); + +out: + libusb_free_config_descriptor(config); + return r; +} + +static void dev_deinit(struct fp_img_dev *dev) +{ + struct uru4k_dev *urudev = dev->priv; + libusb_release_interface(dev->udev, urudev->interface); + g_free(urudev); + fpi_imgdev_close_complete(dev); +} + +static const struct usb_id id_table[] = { + /* ms kbd with fp rdr */ + { .vendor = 0x045e, .product = 0x00bb, .driver_data = MS_KBD }, + + /* ms intellimouse with fp rdr */ + { .vendor = 0x045e, .product = 0x00bc, .driver_data = MS_INTELLIMOUSE }, + + /* ms fp rdr (standalone) */ + { .vendor = 0x045e, .product = 0x00bd, .driver_data = MS_STANDALONE }, + + /* ms fp rdr (standalone) v2 */ + { .vendor = 0x045e, .product = 0x00ca, .driver_data = MS_STANDALONE_V2 }, + + /* dp uru4000 (standalone) */ + { .vendor = 0x05ba, .product = 0x0007, .driver_data = DP_URU4000 }, + + /* dp uru4000 (keyboard) */ + { .vendor = 0x05ba, .product = 0x0008, .driver_data = DP_URU4000 }, + + /* dp uru4000b (standalone) */ + { .vendor = 0x05ba, .product = 0x000a, .driver_data = DP_URU4000B }, + + /* terminating entry */ + { 0, 0, 0, }, +}; + +struct fp_img_driver uru4000_driver = { + .driver = { + .id = 2, + .name = FP_COMPONENT, + .full_name = "Digital Persona U.are.U 4000/4000B", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_PRESS, + }, + .flags = FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE, + .img_height = 289, + .img_width = 384, + + .open = dev_init, + .close = dev_deinit, + .activate = dev_activate, + .deactivate = dev_deactivate, + .change_state = dev_change_state, +}; + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/vcom5s.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/vcom5s.c.svn-base @@ -0,0 +1,386 @@ +/* + * Veridicom 5thSense driver for libfprint + * Copyright (C) 2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "vcom5s" + +/* TODO: + * calibration? + * image size: windows gets 300x300 through vpas enrollment util? + * (probably just increase bulk read size?) + * powerdown? does windows do anything special on exit? + */ + +#include +#include + +#include +#include + +#include + +#define CTRL_IN 0xc0 +#define CTRL_OUT 0x40 +#define CTRL_TIMEOUT 1000 +#define EP_IN (1 | LIBUSB_ENDPOINT_IN) + +#define IMG_WIDTH 300 +#define IMG_HEIGHT 288 +#define ROWS_PER_RQ 12 +#define NR_REQS (IMG_HEIGHT / ROWS_PER_RQ) +#define RQ_SIZE (IMG_WIDTH * ROWS_PER_RQ) +#define IMG_SIZE (IMG_WIDTH * IMG_HEIGHT) + +struct v5s_dev { + int capture_iteration; + struct fp_img *capture_img; + gboolean loop_running; + gboolean deactivating; +}; + +enum v5s_regs { + /* when using gain 0x29: + * a value of 0x00 produces mostly-black image + * 0x09 destroys ridges (too white) + * 0x01 or 0x02 seem good values */ + REG_CONTRAST = 0x02, + + /* when using contrast 0x01: + * a value of 0x00 will produce an all-black image. + * 0x29 produces a good contrast image: ridges quite dark, but some + * light grey noise as background + * 0x46 produces all-white image with grey ridges (not very dark) */ + REG_GAIN = 0x03, +}; + +enum v5s_cmd { + /* scan one row. has parameter, at a guess this is which row to scan? */ + CMD_SCAN_ONE_ROW = 0xc0, + + /* scan whole image */ + CMD_SCAN = 0xc1, +}; + +/***** REGISTER I/O *****/ + +static void sm_write_reg_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else + fpi_ssm_next_state(ssm); + + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +static void sm_write_reg(struct fpi_ssm *ssm, unsigned char reg, + unsigned char value) +{ + struct fp_img_dev *dev = ssm->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + fp_dbg("set %02x=%02x", reg, value); + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE); + libusb_fill_control_setup(data, CTRL_OUT, reg, value, 0, 0); + libusb_fill_control_transfer(transfer, dev->udev, data, sm_write_reg_cb, + ssm, CTRL_TIMEOUT); + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } +} + +static void sm_exec_cmd_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else + fpi_ssm_next_state(ssm); + + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +static void sm_exec_cmd(struct fpi_ssm *ssm, unsigned char cmd, + unsigned char param) +{ + struct fp_img_dev *dev = ssm->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + fp_dbg("cmd %02x param %02x", cmd, param); + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE); + libusb_fill_control_setup(data, CTRL_IN, cmd, param, 0, 0); + libusb_fill_control_transfer(transfer, dev->udev, data, sm_exec_cmd_cb, + ssm, CTRL_TIMEOUT); + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } +} + +/***** FINGER DETECTION *****/ + +/* We take 64x64 pixels at the center of the image, determine the average + * pixel intensity, and threshold it. */ +#define DETBOX_ROW_START 111 +#define DETBOX_COL_START 117 +#define DETBOX_ROWS 64 +#define DETBOX_COLS 64 +#define DETBOX_ROW_END (DETBOX_ROW_START + DETBOX_ROWS) +#define DETBOX_COL_END (DETBOX_COL_START + DETBOX_COLS) +#define FINGER_PRESENCE_THRESHOLD 100 + +static gboolean finger_is_present(unsigned char *data) +{ + int row; + uint16_t imgavg = 0; + + for (row = DETBOX_ROW_START; row < DETBOX_ROW_END; row++) { + unsigned char *rowdata = data + (row * IMG_WIDTH); + uint16_t rowavg = 0; + int col; + + for (col = DETBOX_COL_START; col < DETBOX_COL_END; col++) + rowavg += rowdata[col]; + rowavg /= DETBOX_COLS; + imgavg += rowavg; + } + imgavg /= DETBOX_ROWS; + fp_dbg("img avg %d", imgavg); + + return (imgavg <= FINGER_PRESENCE_THRESHOLD); +} + + + +/***** IMAGE ACQUISITION *****/ + +static void capture_iterate(struct fpi_ssm *ssm); + +static void capture_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + struct fp_img_dev *dev = ssm->priv; + struct v5s_dev *vdev = dev->priv; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_ssm_mark_aborted(ssm, -EIO); + goto out; + } + + if (++vdev->capture_iteration == NR_REQS) { + struct fp_img *img = vdev->capture_img; + /* must clear this early, otherwise the call chain takes us into + * loopsm_complete where we would free it, when in fact we are + * supposed to be handing off this image */ + vdev->capture_img = NULL; + + fpi_imgdev_report_finger_status(dev, finger_is_present(img->data)); + fpi_imgdev_image_captured(dev, img); + fpi_ssm_next_state(ssm); + } else { + capture_iterate(ssm); + } + +out: + libusb_free_transfer(transfer); +} + +static void capture_iterate(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct v5s_dev *vdev = dev->priv; + int iteration = vdev->capture_iteration; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, + vdev->capture_img->data + (RQ_SIZE * iteration), RQ_SIZE, + capture_cb, ssm, CTRL_TIMEOUT); + transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK; + r = libusb_submit_transfer(transfer); + if (r < 0) { + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } +} + + +static void sm_do_capture(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct v5s_dev *vdev = dev->priv; + + fp_dbg(""); + vdev->capture_img = fpi_img_new_for_imgdev(dev); + vdev->capture_iteration = 0; + capture_iterate(ssm); +} + +/***** CAPTURE LOOP *****/ + +enum loop_states { + LOOP_SET_CONTRAST, + LOOP_SET_GAIN, + LOOP_CMD_SCAN, + LOOP_CAPTURE, + LOOP_CAPTURE_DONE, + LOOP_NUM_STATES, +}; + +static void loop_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct v5s_dev *vdev = dev->priv; + + switch (ssm->cur_state) { + case LOOP_SET_CONTRAST: + sm_write_reg(ssm, REG_CONTRAST, 0x01); + break; + case LOOP_SET_GAIN: + sm_write_reg(ssm, REG_GAIN, 0x29); + break; + case LOOP_CMD_SCAN: + if (vdev->deactivating) { + fp_dbg("deactivating, marking completed"); + fpi_ssm_mark_completed(ssm); + } else + sm_exec_cmd(ssm, CMD_SCAN, 0x00); + break; + case LOOP_CAPTURE: + sm_do_capture(ssm); + break; + case LOOP_CAPTURE_DONE: + fpi_ssm_jump_to_state(ssm, LOOP_CMD_SCAN); + break; + } +} + +static void loopsm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct v5s_dev *vdev = dev->priv; + int r = ssm->error; + + fpi_ssm_free(ssm); + fp_img_free(vdev->capture_img); + vdev->capture_img = NULL; + vdev->loop_running = FALSE; + + if (r) + fpi_imgdev_session_error(dev, r); + + if (vdev->deactivating) + fpi_imgdev_deactivate_complete(dev); +} + +static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + struct v5s_dev *vdev = dev->priv; + struct fpi_ssm *ssm = fpi_ssm_new(dev->dev, loop_run_state, + LOOP_NUM_STATES); + ssm->priv = dev; + vdev->deactivating = FALSE; + fpi_ssm_start(ssm, loopsm_complete); + vdev->loop_running = TRUE; + fpi_imgdev_activate_complete(dev, 0); + return 0; +} + +static void dev_deactivate(struct fp_img_dev *dev) +{ + struct v5s_dev *vdev = dev->priv; + if (vdev->loop_running) + vdev->deactivating = TRUE; + else + fpi_imgdev_deactivate_complete(dev); +} + +static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + int r; + dev->priv = g_malloc0(sizeof(struct v5s_dev)); + + r = libusb_claim_interface(dev->udev, 0); + if (r < 0) + fp_err("could not claim interface 0"); + + if (r == 0) + fpi_imgdev_open_complete(dev, 0); + + return r; +} + +static void dev_deinit(struct fp_img_dev *dev) +{ + g_free(dev->priv); + libusb_release_interface(dev->udev, 0); + fpi_imgdev_close_complete(dev); +} + +static const struct usb_id id_table[] = { + { .vendor = 0x061a, .product = 0x0110 }, + { 0, 0, 0, }, +}; + +struct fp_img_driver vcom5s_driver = { + .driver = { + .id = 8, + .name = FP_COMPONENT, + .full_name = "Veridicom 5thSense", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_PRESS, + }, + .flags = 0, + .img_height = IMG_HEIGHT, + .img_width = IMG_WIDTH, + + .open = dev_init, + .close = dev_deinit, + .activate = dev_activate, + .deactivate = dev_deactivate, +}; + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/upeksonly.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/upeksonly.c.svn-base @@ -0,0 +1,1036 @@ +/* + * UPEK TouchStrip Sensor-Only driver for libfprint + * Copyright (C) 2008 Daniel Drake + * + * 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 + */ + +#define FP_COMPONENT "upeksonly" + +#include +#include + +#include +#include + +#include + +#define CTRL_TIMEOUT 1000 +#define IMG_WIDTH 288 +#define NUM_BULK_TRANSFERS 24 +#define MAX_ROWS 700 + +struct img_transfer_data { + int idx; + struct fp_img_dev *dev; + gboolean flying; + gboolean cancelling; +}; + +enum sonly_kill_transfers_action { + NOT_KILLING = 0, + + /* abort a SSM with an error code */ + ABORT_SSM, + + /* report an image session error */ + IMG_SESSION_ERROR, + + /* iterate a SSM to the next state */ + ITERATE_SSM, + + /* call a callback */ + EXEC_CALLBACK, +}; + +struct sonly_dev { + gboolean capturing; + gboolean deactivating; + uint8_t read_reg_result; + + struct fpi_ssm *loopsm; + struct libusb_transfer *img_transfer[NUM_BULK_TRANSFERS]; + struct img_transfer_data *img_transfer_data; + int num_flying; + + GSList *rows; + size_t num_rows; + unsigned char *rowbuf; + int rowbuf_offset; + + int wraparounds; + int num_blank; + int finger_removed; + int last_seqnum; + + enum sonly_kill_transfers_action killing_transfers; + int kill_status_code; + union { + struct fpi_ssm *kill_ssm; + void (*kill_cb)(struct fp_img_dev *dev); + }; +}; + +struct sonly_regwrite { + uint8_t reg; + uint8_t value; +}; + +/***** IMAGE PROCESSING *****/ + +static void free_img_transfers(struct sonly_dev *sdev) +{ + int i; + for (i = 0; i < NUM_BULK_TRANSFERS; i++) { + struct libusb_transfer *transfer = sdev->img_transfer[i]; + if (!transfer) + continue; + + g_free(transfer->buffer); + libusb_free_transfer(transfer); + } + g_free(sdev->img_transfer_data); +} + +static void last_transfer_killed(struct fp_img_dev *dev) +{ + struct sonly_dev *sdev = dev->priv; + switch (sdev->killing_transfers) { + case ABORT_SSM: + fp_dbg("abort ssm error %d", sdev->kill_status_code); + fpi_ssm_mark_aborted(sdev->kill_ssm, sdev->kill_status_code); + return; + case ITERATE_SSM: + fp_dbg("iterate ssm"); + fpi_ssm_next_state(sdev->kill_ssm); + return; + case IMG_SESSION_ERROR: + fp_dbg("session error %d", sdev->kill_status_code); + fpi_imgdev_session_error(dev, sdev->kill_status_code); + return; + default: + return; + } +} + +static void cancel_img_transfers(struct fp_img_dev *dev) +{ + struct sonly_dev *sdev = dev->priv; + int i; + + if (sdev->num_flying == 0) { + last_transfer_killed(dev); + return; + } + + for (i = 0; i < NUM_BULK_TRANSFERS; i++) { + struct img_transfer_data *idata = &sdev->img_transfer_data[i]; + if (!idata->flying || idata->cancelling) + continue; + fp_dbg("cancelling transfer %d", i); + int r = libusb_cancel_transfer(sdev->img_transfer[i]); + if (r < 0) + fp_dbg("cancel failed error %d", r); + idata->cancelling = TRUE; + } +} + +static gboolean is_capturing(struct sonly_dev *sdev) +{ + return sdev->num_rows < MAX_ROWS && !sdev->finger_removed; +} + +static void handoff_img(struct fp_img_dev *dev) +{ + struct sonly_dev *sdev = dev->priv; + size_t size = IMG_WIDTH * sdev->num_rows; + struct fp_img *img = fpi_img_new(size); + GSList *elem = sdev->rows; + size_t offset = 0; + + if (!elem) { + fp_err("no rows?"); + return; + } + + fp_dbg("%d rows", sdev->num_rows); + img->height = sdev->num_rows; + + do { + memcpy(img->data + offset, elem->data, IMG_WIDTH); + g_free(elem->data); + offset += IMG_WIDTH; + } while ((elem = g_slist_next(elem)) != NULL); + + g_slist_free(sdev->rows); + sdev->rows = NULL; + + fpi_imgdev_image_captured(dev, img); + fpi_imgdev_report_finger_status(dev, FALSE); + + sdev->killing_transfers = ITERATE_SSM; + sdev->kill_ssm = sdev->loopsm; + cancel_img_transfers(dev); +} + +static void compute_rows(unsigned char *a, unsigned char *b, int *diff, + int *total) +{ + int i; + int _total = 0; + int _diff = 0; + + for (i = 0; i < IMG_WIDTH; i++) { + if (a[i] > b[i]) + _diff += a[i] - b[i]; + else + _diff += b[i] - a[i]; + _total += b[i]; + } + *diff = _diff; + *total = _total; +} + +static void row_complete(struct fp_img_dev *dev) +{ + struct sonly_dev *sdev = dev->priv; + sdev->rowbuf_offset = -1; + + if (sdev->num_rows > 0) { + unsigned char *lastrow = sdev->rows->data; + int diff; + int total; + + compute_rows(lastrow, sdev->rowbuf, &diff, &total); + if (total < 52000) { + sdev->num_blank = 0; + } else { + sdev->num_blank++; + if (sdev->num_blank > 500) { + sdev->finger_removed = 1; + fp_dbg("detected finger removal"); + handoff_img(dev); + return; + } + } + if (diff < 3000) + return; + } + + sdev->rows = g_slist_prepend(sdev->rows, sdev->rowbuf); + sdev->num_rows++; + sdev->rowbuf = NULL; + + if (sdev->num_rows >= MAX_ROWS) { + fp_dbg("row limit met"); + handoff_img(dev); + } +} + +/* add data to row buffer */ +static void add_to_rowbuf(struct fp_img_dev *dev, unsigned char *data, int size) +{ + struct sonly_dev *sdev = dev->priv; + + memcpy(sdev->rowbuf + sdev->rowbuf_offset, data, size); + sdev->rowbuf_offset += size; + if (sdev->rowbuf_offset >= IMG_WIDTH) + row_complete(dev); +} + +static void start_new_row(struct sonly_dev *sdev, unsigned char *data, int size) +{ + if (!sdev->rowbuf) + sdev->rowbuf = g_malloc(IMG_WIDTH); + memcpy(sdev->rowbuf + IMG_WIDTH - 2, data, 2); + memcpy(sdev->rowbuf, data + 2, size - 2); + sdev->rowbuf_offset = size; +} + +/* returns number of bytes left to be copied into rowbuf (capped to 62) + * or -1 if we aren't capturing anything */ +static int rowbuf_remaining(struct sonly_dev *sdev) +{ + int r; + + if (sdev->rowbuf_offset == -1) + return -1; + + r = IMG_WIDTH - sdev->rowbuf_offset; + if (r > 62) + r = 62; + return r; +} + +static void handle_packet(struct fp_img_dev *dev, unsigned char *data) +{ + struct sonly_dev *sdev = dev->priv; + uint16_t seqnum = data[0] << 8 | data[1]; + int abs_base_addr; + int for_rowbuf; + int next_row_addr; + int diff; + + data += 2; /* skip sequence number */ + if (seqnum != sdev->last_seqnum + 1) { + if (seqnum != 0 && sdev->last_seqnum != 16383) + fp_warn("lost some data"); + } + if (seqnum <= sdev->last_seqnum) { + fp_dbg("detected wraparound"); + sdev->wraparounds++; + } + + sdev->last_seqnum = seqnum; + seqnum += sdev->wraparounds * 16384; + abs_base_addr = seqnum * 62; + + /* are we already capturing a row? if so append the data to the + * row buffer */ + for_rowbuf = rowbuf_remaining(sdev); + if (for_rowbuf != -1) { + add_to_rowbuf(dev, data, for_rowbuf); + /* FIXME: we drop a row here */ + return; + } + + /* does the packet START on a boundary? if so we want it in full */ + if (abs_base_addr % IMG_WIDTH == 0) { + start_new_row(sdev, data, 62); + return; + } + + /* does the data in the packet reside on a row boundary? + * if so capture it */ + next_row_addr = ((abs_base_addr / IMG_WIDTH) + 1) * IMG_WIDTH; + diff = next_row_addr - abs_base_addr; + if (diff < 62) + start_new_row(sdev, data + diff, 62 - diff); +} + +static void img_data_cb(struct libusb_transfer *transfer) +{ + struct img_transfer_data *idata = transfer->user_data; + struct fp_img_dev *dev = idata->dev; + struct sonly_dev *sdev = dev->priv; + int i; + + idata->flying = FALSE; + idata->cancelling = FALSE; + sdev->num_flying--; + + if (sdev->killing_transfers) { + if (sdev->num_flying == 0) + last_transfer_killed(dev); + + /* don't care about error or success if we're terminating */ + return; + } + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fp_warn("bad status %d, terminating session", transfer->status); + sdev->killing_transfers = IMG_SESSION_ERROR; + sdev->kill_status_code = transfer->status; + cancel_img_transfers(dev); + } + + /* there are 64 packets in the transfer buffer + * each packet is 64 bytes in length + * the first 2 bytes are a sequence number + * then there are 62 bytes for image data + */ + for (i = 0; i < 4096; i += 64) { + if (!is_capturing(sdev)) + return; + handle_packet(dev, transfer->buffer + i); + } + + if (is_capturing(sdev)) { + int r = libusb_submit_transfer(transfer); + if (r < 0) { + fp_warn("failed resubmit, error %d", r); + sdev->killing_transfers = IMG_SESSION_ERROR; + sdev->kill_status_code = r; + cancel_img_transfers(dev); + return; + } + sdev->num_flying++; + idata->flying = TRUE; + } +} + +/***** STATE MACHINE HELPERS *****/ + +struct write_regs_data { + struct fpi_ssm *ssm; + struct libusb_transfer *transfer; + const struct sonly_regwrite *regs; + size_t num_regs; + size_t regs_written; +}; + +static void write_regs_finished(struct write_regs_data *wrdata, int result) +{ + g_free(wrdata->transfer->buffer); + libusb_free_transfer(wrdata->transfer); + if (result == 0) + fpi_ssm_next_state(wrdata->ssm); + else + fpi_ssm_mark_aborted(wrdata->ssm, result); + g_free(wrdata); +} + + +static void write_regs_iterate(struct write_regs_data *wrdata) +{ + struct fpi_ssm *ssm; + struct libusb_control_setup *setup; + const struct sonly_regwrite *regwrite; + int r; + + if (wrdata->regs_written >= wrdata->num_regs) { + write_regs_finished(wrdata, 0); + return; + } + + regwrite = &wrdata->regs[wrdata->regs_written]; + ssm = wrdata->ssm; + + fp_dbg("set %02x=%02x", regwrite->reg, regwrite->value); + setup = libusb_control_transfer_get_setup(wrdata->transfer); + setup->wIndex = regwrite->reg; + wrdata->transfer->buffer[LIBUSB_CONTROL_SETUP_SIZE] = regwrite->value; + + r = libusb_submit_transfer(wrdata->transfer); + if (r < 0) + write_regs_finished(wrdata, r); +} + +static void write_regs_cb(struct libusb_transfer *transfer) +{ + struct write_regs_data *wrdata = transfer->user_data; + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + write_regs_finished(wrdata, transfer->status); + return; + } + + wrdata->regs_written++; + write_regs_iterate(wrdata); +} + +static void sm_write_regs(struct fpi_ssm *ssm, + const struct sonly_regwrite *regs, size_t num_regs) +{ + struct write_regs_data *wrdata = g_malloc(sizeof(*wrdata)); + unsigned char *data; + + wrdata->transfer = libusb_alloc_transfer(0); + if (!wrdata->transfer) { + g_free(wrdata); + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); + libusb_fill_control_setup(data, 0x40, 0x0c, 0, 0, 1); + libusb_fill_control_transfer(wrdata->transfer, ssm->dev->udev, data, + write_regs_cb, wrdata, CTRL_TIMEOUT); + wrdata->transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK; + + wrdata->ssm = ssm; + wrdata->regs = regs; + wrdata->num_regs = num_regs; + wrdata->regs_written = 0; + write_regs_iterate(wrdata); +} + +static void sm_write_reg_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + g_free(transfer->buffer); + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else + fpi_ssm_next_state(ssm); + +} + +static void sm_write_reg(struct fpi_ssm *ssm, uint8_t reg, uint8_t value) +{ + struct fp_img_dev *dev = ssm->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + fp_dbg("set %02x=%02x", reg, value); + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); + libusb_fill_control_setup(data, 0x40, 0x0c, 0, reg, 1); + libusb_fill_control_transfer(transfer, dev->udev, data, sm_write_reg_cb, + ssm, CTRL_TIMEOUT); + + data[LIBUSB_CONTROL_SETUP_SIZE] = value; + transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK | + LIBUSB_TRANSFER_FREE_TRANSFER; + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } +} + +static void sm_read_reg_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_ssm_mark_aborted(ssm, -EIO); + } else { + sdev->read_reg_result = libusb_control_transfer_get_data(transfer)[0]; + fp_dbg("read reg result = %02x", sdev->read_reg_result); + fpi_ssm_next_state(ssm); + } + + g_free(transfer->buffer); +} + +static void sm_read_reg(struct fpi_ssm *ssm, uint8_t reg) +{ + struct fp_img_dev *dev = ssm->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + fp_dbg("read reg %02x", reg); + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 8); + libusb_fill_control_setup(data, 0xc0, 0x0c, 0, reg, 8); + libusb_fill_control_transfer(transfer, dev->udev, data, sm_read_reg_cb, + ssm, CTRL_TIMEOUT); + transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK | + LIBUSB_TRANSFER_FREE_TRANSFER; + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } +} + +static void sm_await_intr_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + struct fp_img_dev *dev = ssm->priv; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + g_free(transfer->buffer); + fpi_ssm_mark_aborted(ssm, transfer->status); + return; + } + + fp_dbg("interrupt received: %02x %02x %02x %02x", + transfer->buffer[0], transfer->buffer[1], + transfer->buffer[2], transfer->buffer[3]); + g_free(transfer->buffer); + + fpi_imgdev_report_finger_status(dev, TRUE); + fpi_ssm_next_state(ssm); +} + +static void sm_await_intr(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + unsigned char *data; + int r; + + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + fp_dbg(""); + data = g_malloc(4); + libusb_fill_interrupt_transfer(transfer, dev->udev, 0x83, data, 4, + sm_await_intr_cb, ssm, 0); + transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK | + LIBUSB_TRANSFER_FREE_TRANSFER; + + r = libusb_submit_transfer(transfer); + if (r < 0) { + libusb_free_transfer(transfer); + g_free(data); + fpi_ssm_mark_aborted(ssm, r); + } +} + +/***** AWAIT FINGER *****/ + +static const struct sonly_regwrite awfsm_writev_1[] = { + { 0x0a, 0x00 }, { 0x0a, 0x00 }, { 0x09, 0x20 }, { 0x03, 0x3b }, + { 0x00, 0x67 }, { 0x00, 0x67 }, +}; + +static const struct sonly_regwrite awfsm_writev_2[] = { + { 0x01, 0xc6 }, { 0x0c, 0x13 }, { 0x0d, 0x0d }, { 0x0e, 0x0e }, + { 0x0f, 0x0d }, { 0x0b, 0x00 }, +}; + +static const struct sonly_regwrite awfsm_writev_3[] = { + { 0x13, 0x45 }, { 0x30, 0xe0 }, { 0x12, 0x01 }, { 0x20, 0x01 }, + { 0x09, 0x20 }, { 0x0a, 0x00 }, { 0x30, 0xe0 }, { 0x20, 0x01 }, +}; + +static const struct sonly_regwrite awfsm_writev_4[] = { + { 0x08, 0x00 }, { 0x10, 0x00 }, { 0x12, 0x01 }, { 0x11, 0xbf }, + { 0x12, 0x01 }, { 0x07, 0x10 }, { 0x07, 0x10 }, { 0x04, 0x00 },\ + { 0x05, 0x00 }, { 0x0b, 0x00 }, + + /* enter finger detection mode */ + { 0x15, 0x20 }, { 0x30, 0xe1 }, { 0x15, 0x24 }, { 0x15, 0x04 }, + { 0x15, 0x84 }, +}; + +enum awfsm_states { + AWFSM_WRITEV_1, + AWFSM_READ_01, + AWFSM_WRITE_01, + AWFSM_WRITEV_2, + AWFSM_READ_13, + AWFSM_WRITE_13, + AWFSM_WRITEV_3, + AWFSM_READ_07, + AWFSM_WRITE_07, + AWFSM_WRITEV_4, + AWFSM_NUM_STATES, +}; + +static void awfsm_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + + switch (ssm->cur_state) { + case AWFSM_WRITEV_1: + sm_write_regs(ssm, awfsm_writev_1, G_N_ELEMENTS(awfsm_writev_1)); + break; + case AWFSM_READ_01: + sm_read_reg(ssm, 0x01); + break; + case AWFSM_WRITE_01: + if (sdev->read_reg_result != 0xc6) + sm_write_reg(ssm, 0x01, 0x46); + else + sm_write_reg(ssm, 0x01, 0xc6); + break; + case AWFSM_WRITEV_2: + sm_write_regs(ssm, awfsm_writev_2, G_N_ELEMENTS(awfsm_writev_2)); + break; + case AWFSM_READ_13: + sm_read_reg(ssm, 0x13); + break; + case AWFSM_WRITE_13: + if (sdev->read_reg_result != 0x45) + sm_write_reg(ssm, 0x13, 0x05); + else + sm_write_reg(ssm, 0x13, 0x45); + break; + case AWFSM_WRITEV_3: + sm_write_regs(ssm, awfsm_writev_3, G_N_ELEMENTS(awfsm_writev_3)); + break; + case AWFSM_READ_07: + sm_read_reg(ssm, 0x07); + break; + case AWFSM_WRITE_07: + if (sdev->read_reg_result != 0x10 && sdev->read_reg_result != 0x90) + fp_warn("odd reg7 value %x", sdev->read_reg_result); + sm_write_reg(ssm, 0x07, sdev->read_reg_result); + break; + case AWFSM_WRITEV_4: + sm_write_regs(ssm, awfsm_writev_4, G_N_ELEMENTS(awfsm_writev_4)); + break; + } +} + +/***** CAPTURE MODE *****/ + +static const struct sonly_regwrite capsm_writev[] = { + /* enter capture mode */ + { 0x09, 0x28 }, { 0x13, 0x55 }, { 0x0b, 0x80 }, { 0x04, 0x00 }, + { 0x05, 0x00 }, +}; + +enum capsm_states { + CAPSM_INIT, + CAPSM_WRITE_15, + CAPSM_WRITE_30, + CAPSM_FIRE_BULK, + CAPSM_WRITEV, + CAPSM_NUM_STATES, +}; + +static void capsm_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + + switch (ssm->cur_state) { + case CAPSM_INIT: + sdev->rowbuf_offset = -1; + sdev->num_rows = 0; + sdev->wraparounds = -1; + sdev->num_blank = 0; + sdev->finger_removed = 0; + sdev->last_seqnum = 16383; + sdev->killing_transfers = 0; + fpi_ssm_next_state(ssm); + break; + case CAPSM_WRITE_15: + sm_write_reg(ssm, 0x15, 0x20); + break; + case CAPSM_WRITE_30: + sm_write_reg(ssm, 0x30, 0xe0); + break; + case CAPSM_FIRE_BULK: ; + int i; + for (i = 0; i < NUM_BULK_TRANSFERS; i++) { + int r = libusb_submit_transfer(sdev->img_transfer[i]); + if (r < 0) { + if (i == 0) { + /* first one failed: easy peasy */ + fpi_ssm_mark_aborted(ssm, r); + return; + } + + /* cancel all flying transfers, and request that the SSM + * gets aborted when the last transfer has dropped out of + * the sky */ + sdev->killing_transfers = ABORT_SSM; + sdev->kill_ssm = ssm; + sdev->kill_status_code = r; + cancel_img_transfers(dev); + return; + } + sdev->img_transfer_data[i].flying = TRUE; + sdev->num_flying++; + } + sdev->capturing = TRUE; + fpi_ssm_next_state(ssm); + break; + case CAPSM_WRITEV: + sm_write_regs(ssm, capsm_writev, G_N_ELEMENTS(capsm_writev)); + break; + } +} + +/***** DEINITIALIZATION *****/ + +static const struct sonly_regwrite deinitsm_writev[] = { + /* reset + enter low power mode */ + { 0x0b, 0x00 }, { 0x09, 0x20 }, { 0x13, 0x45 }, { 0x13, 0x45 }, +}; + +enum deinitsm_states { + DEINITSM_WRITEV, + DEINITSM_NUM_STATES, +}; + +static void deinitsm_run_state(struct fpi_ssm *ssm) +{ + switch (ssm->cur_state) { + case DEINITSM_WRITEV: + sm_write_regs(ssm, deinitsm_writev, G_N_ELEMENTS(deinitsm_writev)); + break; + } +} + +/***** INITIALIZATION *****/ + +static const struct sonly_regwrite initsm_writev_1[] = { + { 0x49, 0x00 }, + + /* BSAPI writes different values to register 0x3e each time. I initially + * thought this was some kind of clever authentication, but just blasting + * these sniffed values each time seems to work. */ + { 0x3e, 0x83 }, { 0x3e, 0x4f }, { 0x3e, 0x0f }, { 0x3e, 0xbf }, + { 0x3e, 0x45 }, { 0x3e, 0x35 }, { 0x3e, 0x1c }, { 0x3e, 0xae }, + + { 0x44, 0x01 }, { 0x43, 0x06 }, { 0x43, 0x05 }, { 0x43, 0x04 }, + { 0x44, 0x00 }, { 0x0b, 0x00 }, +}; + +enum initsm_states { + INITSM_WRITEV_1, + INITSM_READ_09, + INITSM_WRITE_09, + INITSM_READ_13, + INITSM_WRITE_13, + INITSM_WRITE_04, + INITSM_WRITE_05, + INITSM_NUM_STATES, +}; + +static void initsm_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + + switch (ssm->cur_state) { + case INITSM_WRITEV_1: + sm_write_regs(ssm, initsm_writev_1, G_N_ELEMENTS(initsm_writev_1)); + break; + case INITSM_READ_09: + sm_read_reg(ssm, 0x09); + break; + case INITSM_WRITE_09: + sm_write_reg(ssm, 0x09, sdev->read_reg_result & ~0x08); + break; + case INITSM_READ_13: + sm_read_reg(ssm, 0x13); + break; + case INITSM_WRITE_13: + sm_write_reg(ssm, 0x13, sdev->read_reg_result & ~0x10); + break; + case INITSM_WRITE_04: + sm_write_reg(ssm, 0x04, 0x00); + break; + case INITSM_WRITE_05: + sm_write_reg(ssm, 0x05, 0x00); + break; + } +} + +/***** CAPTURE LOOP *****/ + +enum loopsm_states { + LOOPSM_RUN_AWFSM, + LOOPSM_AWAIT_FINGER, + LOOPSM_RUN_CAPSM, + LOOPSM_CAPTURE, + LOOPSM_RUN_DEINITSM, + LOOPSM_FINAL, + LOOPSM_NUM_STATES, +}; + +static void loopsm_run_state(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + + switch (ssm->cur_state) { + case LOOPSM_RUN_AWFSM: ; + if (sdev->deactivating) { + fpi_ssm_mark_completed(ssm); + } else { + struct fpi_ssm *awfsm = fpi_ssm_new(dev->dev, awfsm_run_state, + AWFSM_NUM_STATES); + awfsm->priv = dev; + fpi_ssm_start_subsm(ssm, awfsm); + } + break; + case LOOPSM_AWAIT_FINGER: + sm_await_intr(ssm); + break; + case LOOPSM_RUN_CAPSM: ; + struct fpi_ssm *capsm = fpi_ssm_new(dev->dev, capsm_run_state, + CAPSM_NUM_STATES); + capsm->priv = dev; + fpi_ssm_start_subsm(ssm, capsm); + break; + case LOOPSM_CAPTURE: + /* bulk URBs already flying, so just wait for image completion + * to push us into next state */ + break; + case LOOPSM_RUN_DEINITSM: ; + struct fpi_ssm *deinitsm = fpi_ssm_new(dev->dev, deinitsm_run_state, + DEINITSM_NUM_STATES); + sdev->capturing = FALSE; + deinitsm->priv = dev; + fpi_ssm_start_subsm(ssm, deinitsm); + break; + case LOOPSM_FINAL: + fpi_ssm_jump_to_state(ssm, LOOPSM_RUN_AWFSM); + break; + } + +} + +/***** DRIVER STUFF *****/ + +static void deactivate_done(struct fp_img_dev *dev) +{ + struct sonly_dev *sdev = dev->priv; + + fp_dbg(""); + free_img_transfers(sdev); + g_free(sdev->rowbuf); + sdev->rowbuf = NULL; + + if (sdev->rows) { + g_slist_foreach(sdev->rows, (GFunc) g_free, NULL); + sdev->rows = NULL; + } + + fpi_imgdev_deactivate_complete(dev); +} + +static void dev_deactivate(struct fp_img_dev *dev) +{ + struct sonly_dev *sdev = dev->priv; + + if (!sdev->capturing) { + deactivate_done(dev); + return; + } + + sdev->deactivating = TRUE; + sdev->killing_transfers = ITERATE_SSM; + sdev->kill_ssm = sdev->loopsm; + cancel_img_transfers(dev); +} + +static void loopsm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + int r = ssm->error; + + fpi_ssm_free(ssm); + + if (sdev->deactivating) { + deactivate_done(dev); + return; + } + + if (r) { + fpi_imgdev_session_error(dev, r); + return; + } +} + +static void initsm_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = ssm->priv; + struct sonly_dev *sdev = dev->priv; + int r = ssm->error; + + fpi_ssm_free(ssm); + fpi_imgdev_activate_complete(dev, r); + if (r != 0) + return; + + sdev->loopsm = fpi_ssm_new(dev->dev, loopsm_run_state, LOOPSM_NUM_STATES); + sdev->loopsm->priv = dev; + fpi_ssm_start(sdev->loopsm, loopsm_complete); +} + +static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + struct sonly_dev *sdev = dev->priv; + struct fpi_ssm *ssm; + int i; + + sdev->deactivating = FALSE; + sdev->capturing = FALSE; + + memset(sdev->img_transfer, 0, + NUM_BULK_TRANSFERS * sizeof(struct libusb_transfer *)); + sdev->img_transfer_data = + g_malloc0(sizeof(struct img_transfer_data) * NUM_BULK_TRANSFERS); + sdev->num_flying = 0; + for (i = 0; i < NUM_BULK_TRANSFERS; i++) { + unsigned char *data; + sdev->img_transfer[i] = libusb_alloc_transfer(0); + if (!sdev->img_transfer[i]) { + free_img_transfers(sdev); + return -ENOMEM; + } + sdev->img_transfer_data[i].idx = i; + sdev->img_transfer_data[i].dev = dev; + data = g_malloc(4096); + libusb_fill_bulk_transfer(sdev->img_transfer[i], dev->udev, 0x81, data, + 4096, img_data_cb, &sdev->img_transfer_data[i], 0); + } + + ssm = fpi_ssm_new(dev->dev, initsm_run_state, INITSM_NUM_STATES); + ssm->priv = dev; + fpi_ssm_start(ssm, initsm_complete); + return 0; +} + +static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + int r; + + r = libusb_set_configuration(dev->udev, 1); + if (r < 0) { + fp_err("could not set configuration 1"); + return r; + } + + r = libusb_claim_interface(dev->udev, 0); + if (r < 0) { + fp_err("could not claim interface 0"); + return r; + } + + dev->priv = g_malloc0(sizeof(struct sonly_dev)); + fpi_imgdev_open_complete(dev, 0); + return 0; +} + +static void dev_deinit(struct fp_img_dev *dev) +{ + g_free(dev->priv); + libusb_release_interface(dev->udev, 0); + fpi_imgdev_close_complete(dev); +} + +static const struct usb_id id_table[] = { + { .vendor = 0x147e, .product = 0x2016 }, + { 0, 0, 0, }, +}; + +struct fp_img_driver upeksonly_driver = { + .driver = { + .id = 9, + .name = FP_COMPONENT, + .full_name = "UPEK TouchStrip Sensor-Only", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_SWIPE, + }, + .flags = 0, + .img_width = IMG_WIDTH, + .img_height = -1, + + .open = dev_init, + .close = dev_deinit, + .activate = dev_activate, + .deactivate = dev_deactivate, +}; + --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/fdu2000.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/fdu2000.c.svn-base @@ -0,0 +1,321 @@ +/* + * Secugen FDU2000 driver for libfprint + * Copyright (C) 2007 Gustavo Chain + * + * 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 +#include +#include + +#include + +#define FP_COMPONENT "fdu2000" +#include + +#ifndef HAVE_MEMMEM +gpointer +memmem(const gpointer haystack, size_t haystack_len, const gpointer needle, size_t needle_len) { + const gchar *begin; + const char *const last_possible = (const char *) haystack + haystack_len - needle_len; + + /* The first occurrence of the empty string is deemed to occur at + * the beginning of the string. */ + if (needle_len == 0) + return (void *) haystack; + + /* Sanity check, otherwise the loop might search through the whole + * memory. */ + if (haystack_len < needle_len) + return NULL; + + for (begin = (const char *) haystack; begin <= last_possible; ++begin) + if (begin[0] == ((const char *) needle)[0] && + !memcmp((const void *) &begin[1], + (const void *) ((const char *) needle + 1), + needle_len - 1)) + return (void *) begin; + + return NULL; +} +#endif /* HAVE_MEMMEM */ + +#define EP_IMAGE ( 0x02 | LIBUSB_ENDPOINT_IN ) +#define EP_REPLY ( 0x01 | LIBUSB_ENDPOINT_IN ) +#define EP_CMD ( 0x01 | LIBUSB_ENDPOINT_OUT ) +#define BULK_TIMEOUT 200 + +/* fdu_req[] index */ +typedef enum { + CAPTURE_READY, + CAPTURE_READ, + CAPTURE_END, + LED_OFF, + LED_ON +} req_index; + + +#define CMD_LEN 2 +#define ACK_LEN 8 +static const struct fdu2000_req { + const gchar cmd[CMD_LEN]; // Command to send + const gchar ack[ACK_LEN]; // Expected ACK + const guint ack_len; // ACK has variable length +} fdu_req[] = { + /* Capture */ + { + .cmd = { 0x00, 0x04 }, + .ack = { 0x00, 0x04, 0x01, 0x01 }, + .ack_len = 4 + }, + + { + .cmd = { 0x00, 0x01 }, + .ack = { 0x00, 0x01, 0x01, 0x01 }, + .ack_len = 4 + }, + + { + .cmd = { 0x00, 0x05 }, + .ack = { 0x00, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, + .ack_len = 8 + }, + + /* Led */ + { + .cmd = { 0x05, 0x00 }, + .ack = {}, + .ack_len = 0 + }, + + { + .cmd = { 0x05, 0x01 }, + .ack = {}, + .ack_len = 0 + } +}; + +/* + * Write a command and verify reponse + */ +static gint +bulk_write_safe(libusb_dev_handle *dev, req_index rIndex) { + + gchar reponse[ACK_LEN]; + gint r; + gchar *cmd = (gchar *)fdu_req[rIndex].cmd; + gchar *ack = (gchar *)fdu_req[rIndex].ack; + gint ack_len = fdu_req[rIndex].ack_len; + struct libusb_bulk_transfer wrmsg = { + .endpoint = EP_CMD, + .data = cmd, + .length = sizeof(cmd), + }; + struct libusb_bulk_transfer readmsg = { + .endpoint = EP_REPLY, + .data = reponse, + .length = sizeof(reponse), + }; + int trf; + + r = libusb_bulk_transfer(dev, &wrmsg, &trf, BULK_TIMEOUT); + if (r < 0) + return r; + + if (ack_len == 0) + return 0; + + /* Check reply from FP */ + r = libusb_bulk_transfer(dev, &readmsg, &trf, BULK_TIMEOUT); + if (r < 0) + return r; + + if (!strncmp(ack, reponse, ack_len)) + return 0; + + fp_err("Expected different ACK from dev"); + return 1; /* Error */ +} + +static gint +capture(struct fp_img_dev *dev, gboolean unconditional, + struct fp_img **ret) +{ +#define RAW_IMAGE_WIDTH 398 +#define RAW_IMAGE_HEIGTH 301 +#define RAW_IMAGE_SIZE (RAW_IMAGE_WIDTH * RAW_IMAGE_HEIGTH) + + struct fp_img *img = NULL; + int bytes, r; + const gchar SOF[] = { 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x0c, 0x07 }; // Start of frame + const gchar SOL[] = { 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x0b, 0x06 }; // Start of line + { L L } (L: Line num) (8 nibbles) + gchar *buffer = g_malloc0(RAW_IMAGE_SIZE * 6); + gchar *image; + gchar *p; + guint offset; + struct libusb_bulk_transfer msg = { + .endpoint = EP_IMAGE, + .data = buffer, + .length = RAW_IMAGE_SIZE * 6, + }; + + image = g_malloc0(RAW_IMAGE_SIZE); + + if ((r = bulk_write_safe(dev->udev, LED_ON))) { + fp_err("Command: LED_ON"); + goto out; + } + + if ((r = bulk_write_safe(dev->udev, CAPTURE_READY))) { + fp_err("Command: CAPTURE_READY"); + goto out; + } + +read: + if ((r = bulk_write_safe(dev->udev, CAPTURE_READ))) { + fp_err("Command: CAPTURE_READ"); + goto out; + } + + /* Now we are ready to read from dev */ + + r = libusb_bulk_transfer(dev->udev, &msg, &bytes, BULK_TIMEOUT * 10); + if (r < 0 || bytes < 1) + goto read; + + /* + * Find SOF (start of line) + */ + p = memmem(buffer, RAW_IMAGE_SIZE * 6, + (const gpointer)SOF, sizeof SOF); + fp_dbg("Read %d byte/s from dev", bytes); + if (!p) + goto out; + + p += sizeof SOF; + + int i = 0; + bytes = 0; + while(p) { + if ( i >= RAW_IMAGE_HEIGTH ) + break; + + offset = p - buffer; + p = memmem(p, (RAW_IMAGE_SIZE * 6) - (offset), + (const gpointer)SOL, sizeof SOL); + if (p) { + p += sizeof SOL + 4; + int j; + for (j = 0; j < RAW_IMAGE_WIDTH; j++) { + /** + * Convert from 4 to 8 bits + * The SECUGEN-FDU2000 has 4 lines of data, so we need to join 2 bytes into 1 + */ + *(image + bytes + j) = *(p + (j * 2) + 0) << 4 & 0xf0; + *(image + bytes + j) |= *(p + (j * 2) + 1) & 0x0f; + } + p += RAW_IMAGE_WIDTH * 2; + bytes += RAW_IMAGE_WIDTH; + i++; + } + } + + if ((r = bulk_write_safe(dev->udev, CAPTURE_END))) { + fp_err("Command: CAPTURE_END"); + goto out; + } + + if ((r = bulk_write_safe(dev->udev, LED_OFF))) { + fp_err("Command: LED_OFF"); + goto out; + } + + img = fpi_img_new_for_imgdev(dev); + memcpy(img->data, image, RAW_IMAGE_SIZE); + img->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED; + *ret = img; + +out: + g_free(buffer); + g_free(image); + + return r; +} + +static +gint dev_init(struct fp_img_dev *dev, unsigned long driver_data) +{ + gint r; + //if ( (r = usb_set_configuration(dev->udev, 1)) < 0 ) + // goto out; + + if ( (r = libusb_claim_interface(dev->udev, 0)) < 0 ) + goto out; + + //if ( (r = usb_set_altinterface(dev->udev, 1)) < 0 ) + // goto out; + + //if ( (r = usb_clear_halt(dev->udev, EP_CMD)) < 0 ) + // goto out; + + /* Make sure sensor mode is not capture_{ready|read} */ + if ((r = bulk_write_safe(dev->udev, CAPTURE_END))) { + fp_err("Command: CAPTURE_END"); + goto out; + } + + if ((r = bulk_write_safe(dev->udev, LED_OFF))) { + fp_err("Command: LED_OFF"); + goto out; + } + + return 0; + +out: + fp_err("could not init dev"); + return r; +} + +static +void dev_exit(struct fp_img_dev *dev) +{ + if (bulk_write_safe(dev->udev, CAPTURE_END)) + fp_err("Command: CAPTURE_END"); + + libusb_release_interface(dev->udev, 0); +} + +static const struct usb_id id_table[] = { + { .vendor = 0x1162, .product = 0x0300 }, + { 0, 0, 0, }, +}; + +struct fp_img_driver fdu2000_driver = { + .driver = { + .id = 7, + .name = FP_COMPONENT, + .full_name = "Secugen FDU 2000", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_PRESS, + }, + .img_height = RAW_IMAGE_HEIGTH, + .img_width = RAW_IMAGE_WIDTH, + .bz3_threshold = 23, + + .init = dev_init, + .exit = dev_exit, + .capture = capture, +}; --- libfprint-20081125git.orig/libfprint/drivers/.svn/text-base/upekts.c.svn-base +++ libfprint-20081125git/libfprint/drivers/.svn/text-base/upekts.c.svn-base @@ -0,0 +1,1479 @@ +/* + * UPEK TouchStrip driver for libfprint + * Copyright (C) 2007-2008 Daniel Drake + * + * Based in part on libthinkfinger: + * Copyright (C) 2006-2007 Timo Hoenig + * Copyright (C) 2006 Pavel Machek + * + * LGPL CRC code copied from GStreamer-0.10.10: + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2004,2006 Thomas Vander Stichele + + * 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; version + * 2.1 of the License. + * + * 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 + */ + +#define FP_COMPONENT "upekts" + +#include +#include + +#include +#include + +#include + +#define EP_IN (1 | LIBUSB_ENDPOINT_IN) +#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) +#define TIMEOUT 5000 + +#define MSG_READ_BUF_SIZE 0x40 +#define MAX_DATA_IN_READ_BUF (MSG_READ_BUF_SIZE - 9) + +struct upekts_dev { + gboolean enroll_passed; + gboolean first_verify_iteration; + gboolean stop_verify; + uint8_t seq; /* FIXME: improve/automate seq handling */ +}; + +static const uint16_t crc_table[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +static uint16_t udf_crc(unsigned char *buffer, size_t size) +{ + uint16_t crc = 0; + while (size--) + crc = (uint16_t) ((crc << 8) ^ + crc_table[((crc >> 8) & 0x00ff) ^ *buffer++]); + return crc; +} + +/* + * MESSAGE FORMAT + * + * Messages to and from the device have the same format. + * + * Byte-wise: + * 'C' 'i' 'a' 'o' A B L C1 C2 + * + * Ciao prefixes all messages. The rightmost 4 bits of B become the uppermost + * 4 bits of L, and when combined with the lower 8 bits listed as 'L', L is + * the length of the data, is L bytes long. C1 and C2 are the + * UDF-CRC16 for the whole message minus the Ciao prefix. + * + * When the device wants to command the driver to do something, it sends + * a message where B=0 and A!=0. The A value indicates the type of command. + * If the system is expected to respond to the command, it sends a message back + * with B=0 and A incremented. + * + * When the driver sends a command to the device, A=0 and B is used as a + * sequence counter. It starts at 0, increments by 0x10 on each command, and + * wraps around. + * After each command is sent, the device responds with another message + * indicating completion of the command including any data that was requested. + * This message has the same A and B values. + * + * When the driver is sending commands as above, and when the device is + * responding, the seems to follow this structure: + * + * 28 L1 L2 0 0 S + * + * Where the length of is L-3, and S is some kind of subcommand + * code. L1 is the least significant bits of L, L2 is the most significant. In + * the device's response to a command, the subcommand code will be unchanged. + * + * After deducing and documenting the above, I found a few places where the + * above doesn't hold true. Those are marked with FIXME's below. + */ + +#define CMD_SEQ_INCREMENT 0x10 + +static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev, + unsigned char seq_a, unsigned char seq_b, const unsigned char *data, + uint16_t len, libusb_transfer_cb_fn callback, void *user_data) +{ + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + uint16_t crc; + + /* 9 bytes extra for: 4 byte 'Ciao', 1 byte A, 1 byte B | lenHI, + * 1 byte lenLO, 2 byte CRC */ + size_t urblen = len + 9; + unsigned char *buf; + + if (!transfer) + return NULL; + + if (!data && len > 0) { + fp_err("len>0 but no data?"); + return NULL; + } + + buf = g_malloc(urblen); + + /* Write header */ + strncpy(buf, "Ciao", 4); + len = GUINT16_TO_LE(len); + buf[4] = seq_a; + buf[5] = seq_b | ((len & 0xf00) >> 8); + buf[6] = len & 0x00ff; + + /* Copy data */ + if (data) + memcpy(buf + 7, data, len); + + /* Append CRC */ + crc = GUINT16_TO_BE(udf_crc(buf + 4, urblen - 6)); + buf[urblen - 2] = crc >> 8; + buf[urblen - 1] = crc & 0xff; + + libusb_fill_bulk_transfer(transfer, dev->udev, EP_OUT, buf, urblen, + callback, user_data, TIMEOUT); + return transfer; +} + +static struct libusb_transfer *alloc_send_cmd28_transfer(struct fp_dev *dev, + unsigned char subcmd, const unsigned char *data, uint16_t innerlen, + libusb_transfer_cb_fn callback, void *user_data) +{ + uint16_t _innerlen = innerlen; + size_t len = innerlen + 6; + unsigned char *buf = g_malloc0(len); + struct upekts_dev *upekdev = dev->priv; + uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT; + struct libusb_transfer *ret; + + fp_dbg("seq=%02x subcmd=%02x with %d bytes of data", seq, subcmd, innerlen); + + _innerlen = GUINT16_TO_LE(innerlen + 3); + buf[0] = 0x28; + buf[1] = _innerlen & 0x00ff; + buf[2] = (_innerlen & 0xff00) >> 8; + buf[5] = subcmd; + memcpy(buf + 6, data, innerlen); + + ret = alloc_send_cmd_transfer(dev, 0, seq, buf, len, callback, user_data); + upekdev->seq = seq; + + g_free(buf); + return ret; +} + +static struct libusb_transfer *alloc_send_cmdresponse_transfer( + struct fp_dev *dev, unsigned char seq, const unsigned char *data, + uint8_t len, libusb_transfer_cb_fn callback, void *user_data) +{ + fp_dbg("seq=%02x len=%d", seq, len); + return alloc_send_cmd_transfer(dev, seq, 0, data, len, callback, user_data); +} + +enum read_msg_status { + READ_MSG_ERROR, + READ_MSG_CMD, + READ_MSG_RESPONSE, +}; + +typedef void (*read_msg_cb_fn)(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data); + +struct read_msg_data { + struct fp_dev *dev; + read_msg_cb_fn callback; + void *user_data; +}; + +static int __read_msg_async(struct read_msg_data *udata); + +#define READ_MSG_DATA_CB_ERR(udata) (udata)->callback((udata)->dev, \ + READ_MSG_ERROR, 0, 0, NULL, 0, (udata)->user_data) + +static void busy_ack_sent_cb(struct libusb_transfer *transfer) +{ + struct read_msg_data *udata = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED || + transfer->length != transfer->actual_length) { + READ_MSG_DATA_CB_ERR(udata); + g_free(udata); + } else { + int r = __read_msg_async(udata); + if (r < 0) { + READ_MSG_DATA_CB_ERR(udata); + g_free(udata); + } + } + libusb_free_transfer(transfer); +} + +static int busy_ack_retry_read(struct read_msg_data *udata) +{ + struct libusb_transfer *transfer; + int r; + + transfer = alloc_send_cmdresponse_transfer(udata->dev, 0x09, NULL, 0, + busy_ack_sent_cb, udata); + if (!transfer) + return -ENOMEM; + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + } + return r; +} + +/* Returns 0 if message was handled, 1 if it was a device-busy message, and + * negative on error. */ +static int __handle_incoming_msg(struct read_msg_data *udata, + unsigned char *buf) +{ + uint16_t len = GUINT16_FROM_LE(((buf[5] & 0xf) << 8) | buf[6]); + uint16_t computed_crc = udf_crc(buf + 4, len + 3); + uint16_t msg_crc = GUINT16_FROM_LE((buf[len + 8] << 8) | buf[len + 7]); + unsigned char *retdata = NULL; + unsigned char code_a, code_b; + + if (computed_crc != msg_crc) { + fp_err("CRC failed, got %04x expected %04x", msg_crc, computed_crc); + return -1; + } + + code_a = buf[4]; + code_b = buf[5] & 0xf0; + len = GUINT16_FROM_LE(((buf[5] & 0xf) << 8) | buf[6]); + fp_dbg("A=%02x B=%02x len=%d", code_a, code_b, len); + + if (code_a && !code_b) { + /* device sends command to driver */ + fp_dbg("cmd %x from device to driver", code_a); + + if (code_a == 0x08) { + int r; + fp_dbg("device busy, send busy-ack"); + r = busy_ack_retry_read(udata); + return (r < 0) ? r : 1; + } + + if (len > 0) { + retdata = g_malloc(len); + memcpy(retdata, buf + 7, len); + } + udata->callback(udata->dev, READ_MSG_CMD, code_a, 0, retdata, len, + udata->user_data); + g_free(retdata); + } else if (!code_a) { + /* device sends response to a previously executed command */ + unsigned char *innerbuf = buf + 7; + unsigned char _subcmd; + uint16_t innerlen; + + if (len < 6) { + fp_err("cmd response too short (%d)", len); + return -1; + } + if (innerbuf[0] != 0x28) { + fp_err("cmd response without 28 byte?"); + return -1; + } + + /* not really sure what these 2 bytes are. on most people's hardware, + * these bytes are always 0. However, Alon Bar-Lev's hardware gives + * 0xfb 0xff during the READ28_OB initsm stage. so don't error out + * if they are different... */ + if (innerbuf[3] || innerbuf[4]) + fp_dbg("non-zero bytes in cmd response"); + + innerlen = innerbuf[1] | (innerbuf[2] << 8); + innerlen = GUINT16_FROM_LE(innerlen) - 3; + _subcmd = innerbuf[5]; + fp_dbg("device responds to subcmd %x with %d bytes", _subcmd, innerlen); + if (innerlen > 0) { + retdata = g_malloc(innerlen); + memcpy(retdata, innerbuf + 6, innerlen); + } + udata->callback(udata->dev, READ_MSG_RESPONSE, code_b, _subcmd, + retdata, innerlen, udata->user_data); + g_free(retdata); + } else { + fp_err("don't know how to handle this message"); + return -1; + } + return 0; +} + +static void read_msg_extend_cb(struct libusb_transfer *transfer) +{ + struct read_msg_data *udata = transfer->user_data; + unsigned char *buf = transfer->buffer - MSG_READ_BUF_SIZE; + int handle_result = 0; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fp_err("extended msg read failed, code %d", transfer->status); + goto err; + } + if (transfer->actual_length < transfer->length) { + fp_err("extended msg short read (%d/%d)", transfer->actual_length, + transfer->length); + goto err; + } + + handle_result = __handle_incoming_msg(udata, buf); + if (handle_result < 0) + goto err; + goto out; + +err: + READ_MSG_DATA_CB_ERR(udata); +out: + if (handle_result != 1) + g_free(udata); + g_free(buf); + libusb_free_transfer(transfer); +} + +static void read_msg_cb(struct libusb_transfer *transfer) +{ + struct read_msg_data *udata = transfer->user_data; + unsigned char *data = transfer->buffer; + uint16_t len; + int handle_result = 0; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fp_err("async msg read failed, code %d", transfer->status); + goto err; + } + if (transfer->actual_length < 9) { + fp_err("async msg read too short (%d)", transfer->actual_length); + goto err; + } + + if (strncmp(data, "Ciao", 4) != 0) { + fp_err("no Ciao for you!!"); + goto err; + } + + len = GUINT16_FROM_LE(((data[5] & 0xf) << 8) | data[6]); + if (transfer->actual_length != MSG_READ_BUF_SIZE + && (len + 9) > transfer->actual_length) { + /* Check that the length claimed inside the message is in line with + * the amount of data that was transferred over USB. */ + fp_err("msg didn't include enough data, expected=%d recv=%d", + len + 9, transfer->actual_length); + goto err; + } + + /* We use a 64 byte buffer for reading messages. However, sometimes + * messages are longer, in which case we have to do another USB bulk read + * to read the remainder. This is handled below. */ + if (len > MAX_DATA_IN_READ_BUF) { + int needed = len - MAX_DATA_IN_READ_BUF; + struct libusb_transfer *etransfer = libusb_alloc_transfer(0); + int r; + + if (!transfer) + goto err; + + fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed); + data = g_realloc((gpointer) data, MSG_READ_BUF_SIZE + needed); + + libusb_fill_bulk_transfer(etransfer, udata->dev->udev, EP_IN, + data + MSG_READ_BUF_SIZE, needed, read_msg_extend_cb, udata, + TIMEOUT); + + r = libusb_submit_transfer(etransfer); + if (r < 0) { + fp_err("extended read submission failed"); + /* FIXME memory leak here? */ + goto err; + } + libusb_free_transfer(transfer); + return; + } + + handle_result = __handle_incoming_msg(udata, data); + if (handle_result < 0) + goto err; + goto out; + +err: + READ_MSG_DATA_CB_ERR(udata); +out: + libusb_free_transfer(transfer); + if (handle_result != 1) + g_free(udata); + g_free(data); +} + +static int __read_msg_async(struct read_msg_data *udata) +{ + unsigned char *buf = g_malloc(MSG_READ_BUF_SIZE); + struct libusb_transfer *transfer = libusb_alloc_transfer(0); + int r; + + if (!transfer) { + g_free(buf); + return -ENOMEM; + } + + libusb_fill_bulk_transfer(transfer, udata->dev->udev, EP_IN, buf, + MSG_READ_BUF_SIZE, read_msg_cb, udata, TIMEOUT); + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(buf); + libusb_free_transfer(transfer); + } + + return r; +} + +static int read_msg_async(struct fp_dev *dev, read_msg_cb_fn callback, + void *user_data) +{ + struct read_msg_data *udata = g_malloc(sizeof(*udata)); + int r; + + udata->dev = dev; + udata->callback = callback; + udata->user_data = user_data; + r = __read_msg_async(udata); + if (r) + g_free(udata); + return r; +} + +static const unsigned char init_resp03[] = { + 0x01, 0x00, 0xe8, 0x03, 0x00, 0x00, 0xff, 0x07 +}; +static const unsigned char init28_08[] = { + 0x04, 0x83, 0x00, 0x2c, 0x22, 0x23, 0x97, 0xc9, 0xa7, 0x15, 0xa0, 0x8a, + 0xab, 0x3c, 0xd0, 0xbf, 0xdb, 0xf3, 0x92, 0x6f, 0xae, 0x3b, 0x1e, 0x44, + 0xc4 +}; +static const unsigned char init28_0c[] = { + 0x04, 0x03, 0x00, 0x00, 0x00 +}; +static const unsigned char init28_0b[] = { + 0x04, 0x03, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x64, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0a, + 0x00, 0x64, 0x00, 0xf4, 0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 +}; + +/* device initialisation state machine */ + +enum initsm_states { + WRITE_CTRL400 = 0, + READ_MSG03, + SEND_RESP03, + READ_MSG05, + SEND28_06, + READ28_06, + SEND28_07, + READ28_07, + SEND28_08, + READ28_08, + SEND28_0C, + READ28_0C, + SEND28_0B, + READ28_0B, + INITSM_NUM_STATES, +}; + +static void initsm_read_msg_response_cb(struct fpi_ssm *ssm, + enum read_msg_status status, uint8_t seq, + unsigned char expect_subcmd, unsigned char subcmd) +{ + struct fp_dev *dev = ssm->dev; + struct upekts_dev *upekdev = dev->priv; + + if (status != READ_MSG_RESPONSE) { + fp_err("expected response, got %d seq=%x in state %d", status, seq, + ssm->cur_state); + fpi_ssm_mark_aborted(ssm, -1); + } else if (subcmd != expect_subcmd) { + fp_warn("expected response to subcmd 0x%02x, got response to %02x in " + "state %d", expect_subcmd, subcmd, ssm->cur_state); + fpi_ssm_mark_aborted(ssm, -1); + } else if (seq != upekdev->seq) { + fp_err("expected response to cmd seq=%02x, got response to %02x " + "in state %d", upekdev->seq, seq, ssm->cur_state); + fpi_ssm_mark_aborted(ssm, -1); + } else { + fp_dbg("state %d completed", ssm->cur_state); + fpi_ssm_next_state(ssm); + } +} + +static void read28_0b_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + 0x0b, subcmd); +} + +static void read28_0c_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + 0x0c, subcmd); +} + +static void read28_08_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + 0x08, subcmd); +} + +static void read28_07_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + 0x07, subcmd); +} + +static void read28_06_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + 0x06, subcmd); +} + +static void initsm_read_msg_cmd_cb(struct fpi_ssm *ssm, + enum read_msg_status status, uint8_t expect_seq, uint8_t seq) +{ + struct fp_dev *dev = ssm->dev; + struct upekts_dev *upekdev = dev->priv; + + if (status == READ_MSG_ERROR) { + fpi_ssm_mark_aborted(ssm, -1); + return; + } else if (status != READ_MSG_CMD) { + fp_err("expected command, got %d seq=%x in state %d", status, seq, + ssm->cur_state); + fpi_ssm_mark_aborted(ssm, -1); + return; + } + upekdev->seq = seq; + if (seq != expect_seq) { + fp_err("expected seq=%x, got %x in state %d", expect_seq, seq, + ssm->cur_state); + fpi_ssm_mark_aborted(ssm, -1); + return; + } + + fpi_ssm_next_state(ssm); +} + +static void read_msg05_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_cmd_cb((struct fpi_ssm *) user_data, status, 5, seq); +} + +static void read_msg03_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + initsm_read_msg_cmd_cb((struct fpi_ssm *) user_data, status, 3, seq); +} + +static void ctrl400_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + /* FIXME check length? */ + if (transfer->status == LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_next_state(ssm); + else + fpi_ssm_mark_aborted(ssm, -1); + g_free(transfer->buffer); + libusb_free_transfer(transfer); +} + +static void initsm_read_msg_handler(struct fpi_ssm *ssm, + read_msg_cb_fn callback) +{ + int r = read_msg_async(ssm->dev, callback, ssm); + if (r < 0) { + fp_err("async read msg failed in state %d", ssm->cur_state); + fpi_ssm_mark_aborted(ssm, r); + } +} + +static void initsm_send_msg_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + if (transfer->status == LIBUSB_TRANSFER_COMPLETED + && transfer->length == transfer->actual_length) { + fp_dbg("state %d completed", ssm->cur_state); + fpi_ssm_next_state(ssm); + } else { + fp_err("failed, state=%d rqlength=%d actual_length=%d", ssm->cur_state, + transfer->length, transfer->actual_length); + fpi_ssm_mark_aborted(ssm, -1); + } + libusb_free_transfer(transfer); +} + +static void initsm_send_msg28_handler(struct fpi_ssm *ssm, + unsigned char subcmd, const unsigned char *data, uint16_t innerlen) +{ + struct fp_dev *dev = ssm->dev; + struct libusb_transfer *transfer; + int r; + + transfer = alloc_send_cmd28_transfer(dev, subcmd, data, innerlen, + initsm_send_msg_cb, ssm); + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + return; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + fp_err("urb submission failed error %d in state %d", r, ssm->cur_state); + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, -EIO); + } +} + +static void initsm_run_state(struct fpi_ssm *ssm) +{ + struct fp_dev *dev = ssm->dev; + struct upekts_dev *upekdev = dev->priv; + struct libusb_transfer *transfer; + int r; + + switch (ssm->cur_state) { + case WRITE_CTRL400: ; + unsigned char *data; + + transfer = libusb_alloc_transfer(0); + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + break; + } + + data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); + libusb_fill_control_setup(data, + LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1); + libusb_fill_control_transfer(transfer, ssm->dev->udev, data, + ctrl400_cb, ssm, TIMEOUT); + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(data); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } + break; + case READ_MSG03: + initsm_read_msg_handler(ssm, read_msg03_cb); + break; + case SEND_RESP03: ; + transfer = alloc_send_cmdresponse_transfer(dev, ++upekdev->seq, + init_resp03, sizeof(init_resp03), initsm_send_msg_cb, ssm); + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + break; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } + break; + case READ_MSG05: + initsm_read_msg_handler(ssm, read_msg05_cb); + break; + case SEND28_06: ; + unsigned char dummy28_06 = 0x04; + upekdev->seq = 0xf0; + initsm_send_msg28_handler(ssm, 0x06, &dummy28_06, 1); + break; + case READ28_06: + initsm_read_msg_handler(ssm, read28_06_cb); + break; + case SEND28_07: ; + unsigned char dummy28_07 = 0x04; + initsm_send_msg28_handler(ssm, 0x07, &dummy28_07, 1); + break; + case READ28_07: + initsm_read_msg_handler(ssm, read28_07_cb); + break; + case SEND28_08: + initsm_send_msg28_handler(ssm, 0x08, init28_08, sizeof(init28_08)); + break; + case READ28_08: + initsm_read_msg_handler(ssm, read28_08_cb); + break; + case SEND28_0C: + initsm_send_msg28_handler(ssm, 0x0c, init28_0c, sizeof(init28_0c)); + break; + case READ28_0C: + initsm_read_msg_handler(ssm, read28_0c_cb); + break; + case SEND28_0B: + initsm_send_msg28_handler(ssm, 0x0b, init28_0b, sizeof(init28_0b)); + break; + case READ28_0B: + initsm_read_msg_handler(ssm, read28_0b_cb); + break; + } +} + +static struct fpi_ssm *initsm_new(struct fp_dev *dev) +{ + return fpi_ssm_new(dev, initsm_run_state, INITSM_NUM_STATES); +} + +enum deinitsm_states { + SEND_RESP07 = 0, + READ_MSG01, + DEINITSM_NUM_STATES, +}; + +static void send_resp07_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else if (transfer->length != transfer->actual_length) + fpi_ssm_mark_aborted(ssm, -EPROTO); + else + fpi_ssm_next_state(ssm); + libusb_free_transfer(transfer); +} + +static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + struct fpi_ssm *ssm = user_data; + struct upekts_dev *upekdev = dev->priv; + + if (status == READ_MSG_ERROR) { + fpi_ssm_mark_aborted(ssm, -1); + return; + } else if (status != READ_MSG_CMD) { + fp_err("expected command, got %d seq=%x", status, seq); + fpi_ssm_mark_aborted(ssm, -1); + return; + } + upekdev->seq = seq; + if (seq != 1) { + fp_err("expected seq=1, got %x", seq); + fpi_ssm_mark_aborted(ssm, -1); + return; + } + + fpi_ssm_next_state(ssm); +} + +static void deinitsm_state_handler(struct fpi_ssm *ssm) +{ + struct fp_dev *dev = ssm->dev; + int r; + + switch (ssm->cur_state) { + case SEND_RESP07: ; + struct libusb_transfer *transfer; + unsigned char dummy = 0; + + transfer = alloc_send_cmdresponse_transfer(dev, 0x07, &dummy, 1, + send_resp07_cb, ssm); + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + break; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } + break; + case READ_MSG01: ; + r = read_msg_async(dev, read_msg01_cb, ssm); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); + break; + } +} + +static struct fpi_ssm *deinitsm_new(struct fp_dev *dev) +{ + return fpi_ssm_new(dev, deinitsm_state_handler, DEINITSM_NUM_STATES); +} + +static int dev_init(struct fp_dev *dev, unsigned long driver_data) +{ + struct upekts_dev *upekdev = NULL; + int r; + + r = libusb_claim_interface(dev->udev, 0); + if (r < 0) + return r; + + upekdev = g_malloc(sizeof(*upekdev)); + upekdev->seq = 0xf0; /* incremented to 0x00 before first cmd */ + dev->priv = upekdev; + dev->nr_enroll_stages = 3; + + fpi_drvcb_open_complete(dev, 0); + return 0; +} + +static void dev_exit(struct fp_dev *dev) +{ + libusb_release_interface(dev->udev, 0); + g_free(dev->priv); + fpi_drvcb_close_complete(dev); +} + +static const unsigned char enroll_init[] = { + 0x02, 0xc0, 0xd4, 0x01, 0x00, 0x04, 0x00, 0x08 +}; +static const unsigned char scan_comp[] = { + 0x12, 0xff, 0xff, 0xff, 0xff /* scan completion, prefixes print data */ +}; + +/* used for enrollment and verification */ +static const unsigned char poll_data[] = { 0x30, 0x01 }; + +enum enroll_start_sm_states { + RUN_INITSM = 0, + ENROLL_INIT, + READ_ENROLL_MSG28, + ENROLL_START_NUM_STATES, +}; + +/* Called when the device initialization state machine completes */ +static void enroll_start_sm_cb_initsm(struct fpi_ssm *initsm) +{ + struct fpi_ssm *enroll_start_ssm = initsm->priv; + int error = initsm->error; + + fpi_ssm_free(initsm); + if (error) + fpi_ssm_mark_aborted(enroll_start_ssm, error); + else + fpi_ssm_next_state(enroll_start_ssm); +} + +/* called when enroll init URB has completed */ +static void enroll_start_sm_cb_init(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else if (transfer->length != transfer->actual_length) + fpi_ssm_mark_aborted(ssm, -EPROTO); + else + fpi_ssm_next_state(ssm); + libusb_free_transfer(transfer); +} + +static void enroll_start_sm_cb_msg28(struct fp_dev *dev, + enum read_msg_status status, uint8_t seq, unsigned char subcmd, + unsigned char *data, size_t data_len, void *user_data) +{ + struct upekts_dev *upekdev = dev->priv; + struct fpi_ssm *ssm = user_data; + + if (status != READ_MSG_RESPONSE) { + fp_err("expected response, got %d seq=%x", status, seq); + fpi_ssm_mark_aborted(ssm, -1); + } else if (subcmd != 0) { + fp_warn("expected response to subcmd 0, got response to %02x", + subcmd); + fpi_ssm_mark_aborted(ssm, -1); + } else if (seq != upekdev->seq) { + fp_err("expected response to cmd seq=%02x, got response to %02x", + upekdev->seq, seq); + fpi_ssm_mark_aborted(ssm, -1); + } else { + fpi_ssm_next_state(ssm); + } +} + +static void enroll_start_sm_run_state(struct fpi_ssm *ssm) +{ + struct fp_dev *dev = ssm->dev; + int r; + + switch (ssm->cur_state) { + case RUN_INITSM: ; + struct fpi_ssm *initsm = initsm_new(dev); + initsm->priv = ssm; + fpi_ssm_start(initsm, enroll_start_sm_cb_initsm); + break; + case ENROLL_INIT: ; + struct libusb_transfer *transfer; + transfer = alloc_send_cmd28_transfer(dev, 0x02, enroll_init, + sizeof(enroll_init), enroll_start_sm_cb_init, ssm); + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + break; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, r); + } + break; + case READ_ENROLL_MSG28: ; + /* FIXME: protocol misunderstanding here. device receives response + * to subcmd 0 after submitting subcmd 2? */ + /* actually this is probably a poll response? does the above cmd + * include a 30 01 poll somewhere? */ + r = read_msg_async(dev, enroll_start_sm_cb_msg28, ssm); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); + break; + } +} + +static void enroll_iterate(struct fp_dev *dev); + +static void e_handle_resp00(struct fp_dev *dev, unsigned char *data, + size_t data_len) +{ + struct upekts_dev *upekdev = dev->priv; + unsigned char status; + int result = 0; + + if (data_len != 14) { + fp_err("received 3001 poll response of %d bytes?", data_len); + fpi_drvcb_enroll_stage_completed(dev, -EPROTO, NULL, NULL); + return; + } + + status = data[5]; + fp_dbg("poll result = %02x", status); + + switch (status) { + case 0x0c: + case 0x0d: + case 0x0e: + /* if we previously completed a non-last enrollment stage, we'll + * get this code to indicate successful stage completion */ + if (upekdev->enroll_passed) { + result = FP_ENROLL_PASS; + upekdev->enroll_passed = FALSE; + } + /* otherwise it just means "no news" so we poll again */ + break; + case 0x1c: /* FIXME what does this one mean? */ + case 0x0b: /* FIXME what does this one mean? */ + case 0x23: /* FIXME what does this one mean? */ + result = FP_ENROLL_RETRY; + break; + case 0x0f: /* scan taking too long, remove finger and try again */ + result = FP_ENROLL_RETRY_REMOVE_FINGER; + break; + case 0x1e: /* swipe too short */ + result = FP_ENROLL_RETRY_TOO_SHORT; + break; + case 0x24: /* finger not centered */ + result = FP_ENROLL_RETRY_CENTER_FINGER; + break; + case 0x20: + /* finger scanned successfully */ + /* need to look at the next poll result to determine if enrollment is + * complete or not */ + upekdev->enroll_passed = 1; + break; + case 0x00: /* enrollment complete */ + /* we can now expect the enrollment data on the next poll, so we + * have nothing to do here */ + break; + default: + fp_err("unrecognised scan status code %02x", status); + result = -EPROTO; + break; + } + + if (result) { + fpi_drvcb_enroll_stage_completed(dev, result, NULL, NULL); + if (result > 0) + enroll_iterate(dev); + } else { + enroll_iterate(dev); + } + + /* FIXME: need to extend protocol research to handle the case when + * enrolment fails, e.g. you scan a different finger on each stage */ + /* FIXME: should do proper tracking of when we expect cmd0 results and + * cmd2 results and enforce it */ +} + +static void e_handle_resp02(struct fp_dev *dev, unsigned char *data, + size_t data_len) +{ + struct fp_print_data *fdata = NULL; + int result = -EPROTO; + + if (data_len < sizeof(scan_comp)) { + fp_err("fingerprint data too short (%d bytes)", data_len); + } else if (memcmp(data, scan_comp, sizeof(scan_comp)) != 0) { + fp_err("unrecognised data prefix %x %x %x %x %x", + data[0], data[1], data[2], data[3], data[4]); + } else { + fdata = fpi_print_data_new(dev, data_len - sizeof(scan_comp)); + memcpy(fdata->data, data + sizeof(scan_comp), + data_len - sizeof(scan_comp)); + + result = FP_ENROLL_COMPLETE; + } + + fpi_drvcb_enroll_stage_completed(dev, result, fdata, NULL); +} + +static void enroll_iterate_msg_cb(struct fp_dev *dev, + enum read_msg_status msgstat, uint8_t seq, unsigned char subcmd, + unsigned char *data, size_t data_len, void *user_data) +{ + if (msgstat != READ_MSG_RESPONSE) { + fp_err("expected response, got %d seq=%x", msgstat, seq); + fpi_drvcb_enroll_stage_completed(dev, -EPROTO, NULL, NULL); + return; + } + if (subcmd == 0) { + e_handle_resp00(dev, data, data_len); + } else if (subcmd == 2) { + e_handle_resp02(dev, data, data_len); + } else { + fp_err("unexpected subcmd %d", subcmd); + fpi_drvcb_enroll_stage_completed(dev, -EPROTO, NULL, NULL); + } + +} + +static void enroll_iterate_cmd_cb(struct libusb_transfer *transfer) +{ + struct fp_dev *dev = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_drvcb_enroll_stage_completed(dev, -EIO, NULL, NULL); + } else if (transfer->length != transfer->actual_length) { + fpi_drvcb_enroll_stage_completed(dev, -EPROTO, NULL, NULL); + } else { + int r = read_msg_async(dev, enroll_iterate_msg_cb, NULL); + if (r < 0) + fpi_drvcb_enroll_stage_completed(dev, r, NULL, NULL); + } + libusb_free_transfer(transfer); +} + +static void enroll_iterate(struct fp_dev *dev) +{ + int r; + struct libusb_transfer *transfer = alloc_send_cmd28_transfer(dev, 0x00, + poll_data, sizeof(poll_data), enroll_iterate_cmd_cb, dev); + + if (!transfer) { + fpi_drvcb_enroll_stage_completed(dev, -ENOMEM, NULL, NULL); + return; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_drvcb_enroll_stage_completed(dev, -EIO, NULL, NULL); + } +} + +static void enroll_started(struct fpi_ssm *ssm) +{ + struct fp_dev *dev = ssm->dev; + fpi_drvcb_enroll_started(dev, ssm->error); + + if (!ssm->error) + enroll_iterate(dev); + + fpi_ssm_free(ssm); +} + +static int enroll_start(struct fp_dev *dev) +{ + struct upekts_dev *upekdev = dev->priv; + + /* do_init state machine first */ + struct fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, + ENROLL_START_NUM_STATES); + + upekdev->enroll_passed = FALSE; + fpi_ssm_start(ssm, enroll_started); + return 0; +} + +static void enroll_stop_deinit_cb(struct fpi_ssm *ssm) +{ + /* don't really care about errors */ + fpi_drvcb_enroll_stopped(ssm->dev); + fpi_ssm_free(ssm); +} + +static int enroll_stop(struct fp_dev *dev) +{ + struct fpi_ssm *ssm = deinitsm_new(dev); + fpi_ssm_start(ssm, enroll_stop_deinit_cb); + return 0; +} + +static void verify_stop_deinit_cb(struct fpi_ssm *ssm) +{ + /* don't really care about errors */ + fpi_drvcb_verify_stopped(ssm->dev); + fpi_ssm_free(ssm); +} + +static void do_verify_stop(struct fp_dev *dev) +{ + struct fpi_ssm *ssm = deinitsm_new(dev); + fpi_ssm_start(ssm, verify_stop_deinit_cb); +} + +static const unsigned char verify_hdr[] = { + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xd4, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00 +}; + +enum { + VERIFY_RUN_INITSM = 0, + VERIFY_INIT, + VERIFY_NUM_STATES, +}; + +/* Called when the device initialization state machine completes */ +static void verify_start_sm_cb_initsm(struct fpi_ssm *initsm) +{ + struct fpi_ssm *verify_start_ssm = initsm->priv; + if (initsm->error) + fpi_ssm_mark_aborted(verify_start_ssm, initsm->error); + else + fpi_ssm_next_state(verify_start_ssm); + fpi_ssm_free(initsm); +} + +static void verify_init_2803_cb(struct libusb_transfer *transfer) +{ + struct fpi_ssm *ssm = transfer->user_data; + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) + fpi_ssm_mark_aborted(ssm, -EIO); + else if (transfer->length != transfer->actual_length) + fpi_ssm_mark_aborted(ssm, -EPROTO); + else + fpi_ssm_next_state(ssm); + libusb_free_transfer(transfer); +} + +static void verify_start_sm_run_state(struct fpi_ssm *ssm) +{ + struct fp_dev *dev = ssm->dev; + int r; + + switch (ssm->cur_state) { + case VERIFY_RUN_INITSM: ; + struct fpi_ssm *initsm = initsm_new(dev); + initsm->priv = ssm; + fpi_ssm_start(initsm, verify_start_sm_cb_initsm); + break; + case VERIFY_INIT: ; + struct fp_print_data *print = dev->verify_data; + size_t data_len = sizeof(verify_hdr) + print->length; + unsigned char *data = g_malloc(data_len); + struct libusb_transfer *transfer; + + memcpy(data, verify_hdr, sizeof(verify_hdr)); + memcpy(data + sizeof(verify_hdr), print->data, print->length); + transfer = alloc_send_cmd28_transfer(dev, 0x03, data, data_len, + verify_init_2803_cb, ssm); + g_free(data); + if (!transfer) { + fpi_ssm_mark_aborted(ssm, -ENOMEM); + break; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_ssm_mark_aborted(ssm, -EIO); + } + break; + } +} + +static void verify_iterate(struct fp_dev *dev); + +static void v_handle_resp00(struct fp_dev *dev, unsigned char *data, + size_t data_len) +{ + unsigned char status; + int r = 0; + + if (data_len != 14) { + fp_err("received 3001 poll response of %d bytes?", data_len); + r = -EPROTO; + goto out; + } + + status = data[5]; + fp_dbg("poll result = %02x", status); + + /* These codes indicate that we're waiting for a finger scan, so poll + * again */ + switch (status) { + case 0x0c: /* no news, poll again */ + break; + case 0x20: + fp_dbg("processing scan for verification"); + break; + case 0x00: + fp_dbg("good image"); + break; + case 0x1c: /* FIXME what does this one mean? */ + case 0x0b: /* FIXME what does this one mean? */ + case 0x23: /* FIXME what does this one mean? */ + r = FP_VERIFY_RETRY; + break; + case 0x0f: /* scan taking too long, remove finger and try again */ + r = FP_VERIFY_RETRY_REMOVE_FINGER; + break; + case 0x1e: /* swipe too short */ + r = FP_VERIFY_RETRY_TOO_SHORT; + break; + case 0x24: /* finger not centered */ + r = FP_VERIFY_RETRY_CENTER_FINGER; + break; + default: + fp_err("unrecognised verify status code %02x", status); + r = -EPROTO; + } + +out: + if (r) + fpi_drvcb_report_verify_result(dev, r, NULL); + if (r >= 0) + verify_iterate(dev); +} + +static void v_handle_resp03(struct fp_dev *dev, unsigned char *data, + size_t data_len) +{ + int r; + + if (data_len < 2) { + fp_err("verify result abnormally short!"); + r = -EPROTO; + } else if (data[0] != 0x12) { + fp_err("unexpected verify header byte %02x", data[0]); + r = -EPROTO; + } else if (data[1] == 0x00) { + r = FP_VERIFY_NO_MATCH; + } else if (data[1] == 0x01) { + r = FP_VERIFY_MATCH; + } else { + fp_err("unrecognised verify result %02x", data[1]); + r = -EPROTO; + } + fpi_drvcb_report_verify_result(dev, r, NULL); +} + +static void verify_rd2800_cb(struct fp_dev *dev, enum read_msg_status msgstat, + uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, + void *user_data) +{ + struct upekts_dev *upekdev = dev->priv; + + if (msgstat != READ_MSG_RESPONSE) { + fp_err("expected response, got %d seq=%x", msgstat, seq); + fpi_drvcb_report_verify_result(dev, -EPROTO, NULL); + return; + } else if (seq != upekdev->seq) { + fp_err("expected response to cmd seq=%02x, got response to %02x", + upekdev->seq, seq); + fpi_drvcb_report_verify_result(dev, -EPROTO, NULL); + return; + } + + if (subcmd == 0) + v_handle_resp00(dev, data, data_len); + else if (subcmd == 3) + v_handle_resp03(dev, data, data_len); + else + fpi_drvcb_report_verify_result(dev, -EPROTO, NULL); +} + +static void verify_wr2800_cb(struct libusb_transfer *transfer) +{ + struct fp_dev *dev = transfer->user_data; + + if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fpi_drvcb_report_verify_result(dev, -EIO, NULL); + } else if (transfer->length != transfer->actual_length) { + fpi_drvcb_report_verify_result(dev, -EIO, NULL); + } else { + int r = read_msg_async(dev, verify_rd2800_cb, NULL); + if (r < 0) + fpi_drvcb_report_verify_result(dev, r, NULL); + } + libusb_free_transfer(transfer); +} + +static void verify_iterate(struct fp_dev *dev) +{ + struct upekts_dev *upekdev = dev->priv; + + if (upekdev->stop_verify) { + do_verify_stop(dev); + return; + } + + /* FIXME: this doesn't flow well, should the first cmd be moved from + * verify init to here? */ + if (upekdev->first_verify_iteration) { + int r = read_msg_async(dev, verify_rd2800_cb, NULL); + upekdev->first_verify_iteration = FALSE; + if (r < 0) + fpi_drvcb_report_verify_result(dev, r, NULL); + } else { + int r; + struct libusb_transfer *transfer = alloc_send_cmd28_transfer(dev, + 0x00, poll_data, sizeof(poll_data), verify_wr2800_cb, dev); + + if (!transfer) { + fpi_drvcb_report_verify_result(dev, -ENOMEM, NULL); + return; + } + + r = libusb_submit_transfer(transfer); + if (r < 0) { + g_free(transfer->buffer); + libusb_free_transfer(transfer); + fpi_drvcb_report_verify_result(dev, -EIO, NULL); + } + } +} + +static void verify_started(struct fpi_ssm *ssm) +{ + struct fp_dev *dev = ssm->dev; + struct upekts_dev *upekdev = dev->priv; + + fpi_drvcb_verify_started(dev, ssm->error); + if (!ssm->error) { + upekdev->first_verify_iteration = TRUE; + verify_iterate(dev); + } + + fpi_ssm_free(ssm); +} + +static int verify_start(struct fp_dev *dev) +{ + struct upekts_dev *upekdev = dev->priv; + struct fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, + VERIFY_NUM_STATES); + upekdev->stop_verify = FALSE; + fpi_ssm_start(ssm, verify_started); + return 0; +} + +static int verify_stop(struct fp_dev *dev, gboolean iterating) +{ + struct upekts_dev *upekdev = dev->priv; + + if (!iterating) + do_verify_stop(dev); + else + upekdev->stop_verify = TRUE; + return 0; +} + +static const struct usb_id id_table[] = { + { .vendor = 0x0483, .product = 0x2016 }, + { 0, 0, 0, }, /* terminating entry */ +}; + +struct fp_driver upekts_driver = { + .id = 1, + .name = FP_COMPONENT, + .full_name = "UPEK TouchStrip", + .id_table = id_table, + .scan_type = FP_SCAN_TYPE_SWIPE, + .open = dev_init, + .close = dev_exit, + .enroll_start = enroll_start, + .enroll_stop = enroll_stop, + .verify_start = verify_start, + .verify_stop = verify_stop, +}; + --- libfprint-20081125git.orig/.svn/entries +++ libfprint-20081125git/.svn/entries @@ -0,0 +1,448 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2009-07-24T10:44:07.713746Z +132 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +debian +dir + +AUTHORS +file + + + + +2009-01-13T22:22:22.000000Z +fb3802317bff3b9849b22beeaffee512 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +478 + +THANKS +file + + + + +2009-01-13T22:22:22.000000Z +f6790e3150c3d89811d92d6340e29a58 +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +347 + +libfprint +dir + +README +file + + + + +2009-01-13T22:22:22.000000Z +9d3523d19099eaf7902e87c300fe1bc4 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +1920 + +libfprint.pc.in +file + + + + +2009-01-13T22:22:22.000000Z +388ac8f1bedc3aaa56c2a48c1e335430 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +237 + +configure.ac +file + + + + +2009-06-21T15:05:34.000000Z +00a737f8b4aba2845abda4c83b6fed81 +2009-07-24T10:44:07.713746Z +132 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +5524 + +HACKING +file + + + + +2009-01-13T22:22:22.000000Z +1ebab5ef8b552960f574cc44fe9455f4 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2897 + +TODO +file + + + + +2009-01-13T22:22:22.000000Z +4b4f6a114084c64a351879f07c6443c5 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +836 + +doc +dir + +INSTALL +file + + + + +2009-01-13T22:22:22.000000Z +c59cbaf0df9bcf35feca0d0f1fc01dae +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +9416 + +COPYING +file + + + + +2009-01-13T22:22:22.000000Z +fbc093901857fcd118f065f900982c24 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +26436 + +Makefile.am +file + + + + +2009-06-21T15:05:43.000000Z +be2cfa1bafea6e7a9b563fca37fd1d78 +2009-07-24T10:44:07.713746Z +132 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +474 + +autogen.sh +file + + + + +2009-01-13T22:22:22.000000Z +111fb11569c5753298e14261d68e4903 +2008-09-19T21:33:01.041477Z +116 +dererk-guest +has-props + + + + + + + + + + + + + + + + + + + + +243 + +NEWS +file + + + + +2009-01-13T22:22:22.000000Z +85d68e0040e041e8d7dd446e506ff1ff +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +887 + +examples +dir + --- libfprint-20081125git.orig/.svn/prop-base/autogen.sh.svn-base +++ libfprint-20081125git/.svn/prop-base/autogen.sh.svn-base @@ -0,0 +1,5 @@ +K 14 +svn:executable +V 1 +* +END --- libfprint-20081125git.orig/.svn/text-base/README.svn-base +++ libfprint-20081125git/.svn/text-base/README.svn-base @@ -0,0 +1,41 @@ +libfprint +========= + +libfprint is part of the fprint project: +http://www.reactivated.net/fprint + +libfprint was originally developed as part of an academic project at the +University of Manchester with the aim of hiding differences between different +consumer fingerprint scanners and providing a single uniform API to application +developers. The ultimate goal of the fprint project is to make fingerprint +scanners widely and easily usable under common Linux environments. + +The academic university project runs off a codebase maintained separately +from this one, although I try to keep them as similar as possible (I'm not +hiding anything in the academic branch, it's just the open source release +contains some commits excluded from the academic project). + +THE UNIVERSITY OF MANCHESTER DOES NOT ENDORSE THIS THIS SOFTWARE RELEASE AND +IS IN NO WAY RESPONSIBLE FOR THE CODE CONTAINED WITHIN, OR ANY DAMAGES CAUSED +BY USING OR DISTRIBUTING THE SOFTWARE. Development does not happen on +university computers and the project is not hosted at the university either. + +For more information on libfprint, supported devices, API documentation, etc., +see the homepage: +http://www.reactivated.net/fprint/Libfprint + +libfprint is licensed under the GNU LGPL version 2.1. See the COPYING file +for the license text. + +Section 6 of the license states that for compiled works that use this +library, such works must include libfprint copyright notices alongside the +copyright notices for the other parts of the work. We have attempted to +make this process slightly easier for you by grouping these all in one place: +the AUTHORS file. + +libfprint includes code from NIST's NBIS software distribution: +http://fingerprint.nist.gov/NBIS/index.html +We include bozorth3 from the US export controlled distribution. We have +determined that it is fine to ship bozorth3 in an open source project, +see http://reactivated.net/fprint/wiki/US_export_control + --- libfprint-20081125git.orig/.svn/text-base/COPYING.svn-base +++ libfprint-20081125git/.svn/text-base/COPYING.svn-base @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + --- libfprint-20081125git.orig/.svn/text-base/TODO.svn-base +++ libfprint-20081125git/.svn/text-base/TODO.svn-base @@ -0,0 +1,30 @@ +LIBRARY +======= +test suite against NFIQ compliance set +make library optionally asynchronous and maybe thread-safe +nbis cleanups +API function to determine if img device supports uncond. capture +race-free way of saying "save this print but don't overwrite" + +NEW DRIVERS +=========== +Sunplus 895 driver +AES3400/3500 driver +ID Mouse driver +Support for 2nd generation MS devices +Support for 2nd generation UPEK devices + +IMAGING +======= +ignore first frame or two with aes2501 +aes2501: increase threshold "sum" for end-of-image detection +aes2501 gain calibration +aes4000 gain calibration +aes4000 resampling +PPMM parameter to get_minutiae seems to have no effect +nbis minutiae should be stored in endian-independent format + +PORTABILITY +=========== +OpenBSD can't do -Wshadow or visibility +OpenBSD: add compat codes for ENOTSUP ENODATA and EPROTO --- libfprint-20081125git.orig/.svn/text-base/INSTALL.svn-base +++ libfprint-20081125git/.svn/text-base/INSTALL.svn-base @@ -0,0 +1,234 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + --- libfprint-20081125git.orig/.svn/text-base/Makefile.am.svn-base +++ libfprint-20081125git/.svn/text-base/Makefile.am.svn-base @@ -0,0 +1,22 @@ +AUTOMAKE_OPTIONS = dist-bzip2 +ACLOCAL_AMFLAGS = -I m4 +EXTRA_DIST = THANKS TODO HACKING libfprint.pc.in +DISTCLEANFILES = ChangeLog libfprint.pc + +SUBDIRS = libfprint doc + +if BUILD_EXAMPLES +SUBDIRS += examples +endif + +pkgconfigdir=$(libdir)/pkgconfig +pkgconfig_DATA=libfprint.pc + +.PHONY: ChangeLog dist-up +ChangeLog: + git --git-dir $(top_srcdir)/.git log > ChangeLog || touch ChangeLog + +dist-hook: ChangeLog + +dist-up: dist + rsync $(distdir).tar.bz2 frs.sourceforge.net:uploads/ --- libfprint-20081125git.orig/.svn/text-base/autogen.sh.svn-base +++ libfprint-20081125git/.svn/text-base/autogen.sh.svn-base @@ -0,0 +1,8 @@ +#!/bin/sh +libtoolize --copy --force || exit 1 +aclocal || exit 1 +autoheader || exit 1 +autoconf || exit 1 +automake -a -c || exit 1 +./configure --enable-maintainer-mode --enable-examples-build \ + --enable-x11-examples-build --enable-debug-log $* --- libfprint-20081125git.orig/.svn/text-base/HACKING.svn-base +++ libfprint-20081125git/.svn/text-base/HACKING.svn-base @@ -0,0 +1,96 @@ +Copyright notices +================= + +If you make a contribution substantial enough to add or update a copyright +notice on a file, such notice must be mirrored in the AUTHORS file. This is +to make it easy for people to comply to section 6 of the LGPL, which states +that a "work that uses the Library" must include copyright notices from +this library. By providing them all in one place, hopefully we save such +users some time. + + +USB +=== + +At the time of development, there are no known consumer fingerprint readers +which do not operate over the USB bus. Therefore the library is designed around +the fact that each driver drivers USB devices, and each device is a USB device. +If we were to ever support a non-USB device, some rearchitecting would be +needed, but this would not be a substantial task. + + +GLib +==== + +Although the library uses GLib internally, libfprint is designed to provide +a completely neutral interface to it's application users. So, the public +APIs should never return GLib data types or anything like that. + + +Two-faced-ness +============== + +Like any decent library, this one is designed to provide a stable and +documented API to it's users: applications. Clear distinction is made between +data available internally in the library, and data/functions available to +the applications. + +This library is confused a little by the fact that there is another 'interface' +at hand: the internal interface provided to drivers. So, we effectively end +up with 2 APIs: + + 1. The external-facing API for applications + 2. The internal API for fingerprint drivers + +Non-static functions which are intended for internal use only are prepended +with the "fpi_" prefix. + + +API stability +============= + +No API stability has been promised to anyone: go wild, there's no issue with +breaking APIs at this point in time. + + +Portability +=========== + +libfprint is primarily written for Linux. However, I'm interested in +supporting efforts to port this to other operating systems too. + +You should ensure code is portable wherever possible. Try and use GLib rather +than OS-specific features. + +Endianness must be considered in all code. libfprint must support both big- +and little-endian systems. + + +Coding Style +============ + +This project follows Linux kernel coding style but with a tab width of 4. + + +Documentation +============= + +All additions of public API functions must be accompanied with doxygen +comments. + +All changes which potentially change the behaviour of the public API must +be reflected by updating the appropriate doxygen comments. + + +Contributing +============ + +Patches should be sent to the fprint mailing list detailed on the website. +A subscription is required. + +Information about libfprint development repositories can be found here: +http://www.reactivated.net/fprint/Libfprint_development + +If you're looking for ideas for things to work on, look at the TODO file or +grep the source code for FIXMEs. + --- libfprint-20081125git.orig/.svn/text-base/configure.ac.svn-base +++ libfprint-20081125git/.svn/text-base/configure.ac.svn-base @@ -0,0 +1,185 @@ +AC_INIT([libfprint], [0.1.0-pre2]) +AM_INIT_AUTOMAKE +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_SRCDIR([libfprint/core.c]) +AM_CONFIG_HEADER([config.h]) + +AC_PREREQ([2.50]) +AC_PROG_CC +AC_PROG_LIBTOOL +AC_C_INLINE +AM_PROG_CC_C_O +AC_DEFINE([_GNU_SOURCE], [], [Use GNU extensions]) + +# Library versioning +lt_major="0" +lt_revision="0" +lt_age="0" +AC_SUBST(lt_major) +AC_SUBST(lt_revision) +AC_SUBST(lt_age) + +all_drivers="upekts upektc upeksonly vcom5s uru4000 fdu2000 aes1610 aes2501 aes4000" + +require_imagemagick='no' +require_aeslib='no' +enable_upekts='no' +enable_upektc='no' +enable_upeksonly='no' +enable_vcom5s='no' +enable_uru4000='no' +enable_fdu2000='no' +enable_aes1610='no' +enable_aes2501='no' +enable_aes4000='no' + +AC_ARG_WITH([drivers],[AS_HELP_STRING([--with-drivers], + [List of drivers to enable])], + [drivers="$withval"], + [drivers="$all_drivers"]) + +for driver in `echo ${drivers} | sed -e 's/,/ /g' -e 's/,$//g'`; do + case ${driver} in + upekts) + AC_DEFINE([ENABLE_UPEKTS], [], [Build UPEK TouchStrip driver]) + enable_upekts="yes" + ;; + upektc) + AC_DEFINE([ENABLE_UPEKTC], [], [Build UPEK TouchChip driver]) + enable_upektc="yes" + ;; + upeksonly) + AC_DEFINE([ENABLE_UPEKSONLY], [], [Build UPEK TouchStrip sensor-only driver]) + enable_upeksonly="yes" + ;; + uru4000) + AC_DEFINE([ENABLE_URU4000], [], [Build Digital Persona U.are.U 4000 driver]) + enable_uru4000="yes" + ;; + fdu2000) + AC_DEFINE([ENABLE_FDU2000], [], [Build Secugen FDU 2000 driver]) + enable_fdu2000="yes" + ;; + vcom5s) + AC_DEFINE([ENABLE_VCOM5S], [], [Build Veridicom 5thSense driver]) + enable_vcom5s="yes" + ;; + aes2501) + AC_DEFINE([ENABLE_AES2501], [], [Build AuthenTec AES2501 driver]) + require_aeslib="yes" + enable_aes2501="yes" + ;; + aes1610) + AC_DEFINE([ENABLE_AES1610], [], [Build AuthenTec AES1610 driver]) + require_aeslib="yes" + enable_aes1610="yes" + ;; + aes4000) + AC_DEFINE([ENABLE_AES4000], [], [Build AuthenTec AES4000 driver]) + require_aeslib="yes" + require_imagemagick="yes" + enable_aes4000="yes" + ;; + esac +done + +AM_CONDITIONAL([ENABLE_UPEKTS], [test "$enable_upekts" != "no"]) +#AM_CONDITIONAL([ENABLE_UPEKTC], [test "$enable_upektc" != "no"]) +AM_CONDITIONAL([ENABLE_UPEKSONLY], [test "$enable_upeksonly" != "no"]) +AM_CONDITIONAL([ENABLE_VCOM5S], [test "$enable_vcom5s" != "no"]) +AM_CONDITIONAL([ENABLE_URU4000], [test "$enable_uru4000" != "no"]) +#AM_CONDITIONAL([ENABLE_FDU2000], [test "$enable_fdu2000" != "no"]) +#AM_CONDITIONAL([ENABLE_AES1610], [test "$enable_aes1610" != "no"]) +AM_CONDITIONAL([ENABLE_AES2501], [test "$enable_aes2501" != "no"]) +AM_CONDITIONAL([ENABLE_AES4000], [test "$enable_aes4000" != "no"]) +AM_CONDITIONAL([REQUIRE_IMAGEMAGICK], [test "$require_imagemagick" != "no"]) +AM_CONDITIONAL([REQUIRE_AESLIB], [test "$require_aeslib" != "no"]) + + +PKG_CHECK_MODULES(LIBUSB, [libusb-1.0 >= 0.9.1]) +AC_SUBST(LIBUSB_CFLAGS) +AC_SUBST(LIBUSB_LIBS) + +# check for OpenSSL's libcrypto +PKG_CHECK_MODULES(CRYPTO, "libcrypto") +AC_SUBST(CRYPTO_CFLAGS) +AC_SUBST(CRYPTO_LIBS) + +PKG_CHECK_MODULES(GLIB, "glib-2.0") +AC_SUBST(GLIB_CFLAGS) +AC_SUBST(GLIB_LIBS) + +if test "$require_imagemagick" != "no"; then +PKG_CHECK_MODULES(IMAGEMAGICK, "ImageMagick") +AC_SUBST(IMAGEMAGICK_CFLAGS) +AC_SUBST(IMAGEMAGICK_LIBS) +fi; + +# Examples build +AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build], + [build example applications (default n)])], + [build_examples=$enableval], + [build_examples='no']) +AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"]) + +# Examples build +AC_ARG_ENABLE([x11-examples-build], [AS_HELP_STRING([--enable-x11-examples-build], + [build X11 example applications (default n)])], + [build_x11_examples=$enableval], + [build_x11_examples='no']) +AM_CONDITIONAL([BUILD_X11_EXAMPLES], [test "x$build_x11_examples" != "xno"]) + + +if test "x$build_x11_examples" != "xno"; then + # check for Xv extensions + # imported from Coriander + AC_DEFUN([AC_CHECK_XV],[ + AC_SUBST(XV_CFLAGS) + AC_SUBST(XV_LIBS) + AC_MSG_CHECKING(for Xv extensions) + AC_TRY_COMPILE([ + #include + #include ],[ + int main(void) { (void) XvGetPortAttribute(0, 0, 0, 0); return 0; } + ],xv=yes,xv=no); + AC_MSG_RESULT($xv) + if test x$xv = xyes; then + XV_LIBS="-lXv -lXext" + XV_CFLAGS="" + AC_DEFINE(HAVE_XV,1,[defined if XV video overlay is available]) + else + AC_MSG_ERROR([XV is required for X11 examples]) + fi + ]) + AC_CHECK_XV +fi + +# Message logging +AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])], + [log_enabled=$enableval], + [log_enabled='yes']) +if test "x$log_enabled" != "xno"; then + AC_DEFINE([ENABLE_LOGGING], 1, [Message logging]) +fi + +AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log], + [enable debug logging (default n)])], + [debug_log_enabled=$enableval], + [debug_log_enabled='no']) +if test "x$debug_log_enabled" != "xno"; then + AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging]) +fi + +# Restore gnu89 inline semantics on gcc 4.3 and newer +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -fgnu89-inline" +AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), inline_cflags="-fgnu89-inline", inline_cflags="") +CFLAGS="$saved_cflags" + +AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility]) +AM_CFLAGS="-std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow" +AC_SUBST(AM_CFLAGS) + +AC_CONFIG_FILES([libfprint.pc] [Makefile] [libfprint/Makefile] [examples/Makefile] [doc/Makefile]) +AC_OUTPUT + --- libfprint-20081125git.orig/.svn/text-base/NEWS.svn-base +++ libfprint-20081125git/.svn/text-base/NEWS.svn-base @@ -0,0 +1,27 @@ +This file lists notable changes in each release. For the full history of all +changes, see ChangeLog. + +2007-12-07: v0.0.5 release + * AES1610 imaging improvements + * Internal cleanups for Authentec drivers + * Add support for latest Microsoft Fingerprint Scanner hardware revision + +2007-11-22: v0.0.4 release + * Enable AES1610 driver thanks to Michele B + * Implement identification: one-to-many fingerprint matching (Daniel Drake) + +2007-11-19: v0.0.3 release + * Add API to access minutiae (Daniel Drake) + * Add API to delete enroll data (Daniel Drake) + * Add Authentec AES1610 driver (Anthony Bretaudeau) + +2007-11-17: v0.0.2 release + * Detect reversed scans on AES2501 (Vasily Khoruzhick) + * Improved AES2501 scanning + * Compatibility with older ImageMagick versions + * Add UPEK TouchChip driver (Jan-Michael Brummer) + * Add binarization API + +2007-11-15: v0.0.1 release + * Initial release + --- libfprint-20081125git.orig/.svn/text-base/libfprint.pc.in.svn-base +++ libfprint-20081125git/.svn/text-base/libfprint.pc.in.svn-base @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libfprint +Description: Generic C API for fingerprint reader access +Version: @VERSION@ +Libs: -L${libdir} -lfprint +Cflags: -I${includedir}/libfprint + --- libfprint-20081125git.orig/.svn/text-base/THANKS.svn-base +++ libfprint-20081125git/.svn/text-base/THANKS.svn-base @@ -0,0 +1,10 @@ +Tony Vroon - hardware donations +Gerrie Mansur from Security Database BV (http://www.securitydatabase.net/) - hardware donations +Joaquin Custodio - hardware donations +TimeTrex (http://www.timetrex.com/) - hardware donations +Craig Watson (NIST) +James Vasile (SFLC) +Toby Howard (University of Manchester) +Seemant Kulleen +Pavel Herrman +Bastien Nocera --- libfprint-20081125git.orig/.svn/text-base/AUTHORS.svn-base +++ libfprint-20081125git/.svn/text-base/AUTHORS.svn-base @@ -0,0 +1,9 @@ +Copyright (C) 2007 Daniel Drake +Copyright (C) 2006-2007 Timo Hoenig +Copyright (C) 2006 Pavel Machek +Copyright (C) 1999 Erik Walthinsen +Copyright (C) 2004,2006 Thomas Vander Stichele +Copyright (C) 2007 Cyrille Bagard +Copyright (C) 2007 Vasily Khoruzhick +Copyright (C) 2007 Jan-Michael Brummer +Copyright (C) 2007 Anthony Bretaudeau --- libfprint-20081125git.orig/doc/.svn/entries +++ libfprint-20081125git/doc/.svn/entries @@ -0,0 +1,96 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/doc +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2008-11-28T05:45:16.054996Z +124 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +Makefile.am +file + + + + +2009-01-13T22:22:22.000000Z +dfad8bd19d98bebc84670e38bf753ba5 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +164 + +doxygen.cfg +file + + + + +2009-01-13T22:22:22.000000Z +aa9c1506c8a090c514f83b15db892d47 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +54037 + --- libfprint-20081125git.orig/doc/.svn/text-base/Makefile.am.svn-base +++ libfprint-20081125git/doc/.svn/text-base/Makefile.am.svn-base @@ -0,0 +1,10 @@ +EXTRA_DIST = doxygen.cfg + +docs: doxygen.cfg + doxygen $^ + +docs-upload: docs + ln -s html api + ncftpput -f ~/.ncftp/reactivated -m -R httpdocs/fprint api/ + rm -f api + --- libfprint-20081125git.orig/doc/.svn/text-base/doxygen.cfg.svn-base +++ libfprint-20081125git/doc/.svn/text-base/doxygen.cfg.svn-base @@ -0,0 +1,1294 @@ +# Doxyfile 1.5.3 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file that +# follow. The default is UTF-8 which is also the encoding used for all text before +# the first occurrence of this tag. Doxygen uses libiconv (or the iconv built into +# libc) for the transcoding. See http://www.gnu.org/software/libiconv for the list of +# possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = libfprint + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian, +# Italian, Japanese, Japanese-en (Japanese with English messages), Korean, +# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian, +# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = NO + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be extracted +# and appear in the documentation as a namespace called 'anonymous_namespace{file}', +# where file will be replaced with the base name of the file that contains the anonymous +# namespace. By default anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = NO + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = ../libfprint + +# This tag can be used to specify the character encoding of the source files that +# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default +# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding. +# See http://www.gnu.org/software/libiconv for the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = ../libfprint/fp_internal.h + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the output. +# The symbol name can be a fully qualified name, a word, or if the wildcard * is used, +# a substring. Examples: ANamespace, AClass, AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. If you have enabled CALL_GRAPH or CALLER_GRAPH +# then you must also enable this option. If you don't then doxygen will produce +# a warning and turn it on anyway + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = YES + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = API_EXPORTED= + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to +# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to +# specify the directory where the mscgen tool resides. If left empty the tool is assumed to +# be found in the default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the number +# of direct children of the root node in a graph is already larger than +# MAX_DOT_GRAPH_NOTES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO --- libfprint-20081125git.orig/debian/control +++ libfprint-20081125git/debian/control @@ -0,0 +1,55 @@ +Source: libfprint +Priority: extra +Maintainer: FingerForce Team +Uploaders: Ulises Vitulli , Miguel Gea Milvaques +Build-Depends: debhelper (>= 5), autotools-dev, libtool, automake, libglib2.0-dev, + libxv-dev, libusb-1.0-0-dev, libssl-dev, libmagickcore-dev +Standards-Version: 3.8.2 +Homepage: http://reactivated.net/fprint/ +Section: libs + +Package: libfprint-dev +Section: libdevel +Architecture: any +Depends: libfprint0 (= ${binary:Version}) +Description: async fingerprint library of fprint project, development headers + The fprint project aims to support for consumer fingerprint reader devices. + . + Previously, Linux support for such devices has been scattered amongst different + projects (many incomplete) and inconsistent in that application developers + would have to implement support for each type of fingerprint reader separately. + The idea is to change that by providing a central system to support all the + fingerprint readers as it's possible to get hands on. + . + libfprint is the centre of efforts, it is the component which does the dirty + work of talking to fingerprint reading devices, and processing fingerprint + data. + . + This library is based on new aproach of libusb-1.0, which handles asynchronous + callback model allowing to perform a non-blocking device task. Old synchronous + library has been renamed to libfprint-old. + . + This package provides development headers. + +Package: libfprint0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends} +Description: async fingerprint library of fprint project, shared libraries + The fprint project aims to support for consumer fingerprint reader devices. + . + Previously, Linux support for such devices has been scattered amongst different + projects (many incomplete) and inconsistent in that application developers + would have to implement support for each type of fingerprint reader separately. + The idea is to change that by providing a central system to support all the + fingerprint readers as it's possible to get hands on. + . + libfprint is the centre of efforts, it is the component which does the dirty + work of talking to fingerprint reading devices, and processing fingerprint + data. + . + This library is based on new aproach of libusb-1.0, which handles asynchronous + callback model allowing to perform a non-blocking device task. Old synchronous + library has been renamed to libfprint-old. + . + This package provides shared libraries. --- libfprint-20081125git.orig/debian/libfprint0.install +++ libfprint-20081125git/debian/libfprint0.install @@ -0,0 +1 @@ +usr/lib/lib*.so.* --- libfprint-20081125git.orig/debian/copyright +++ libfprint-20081125git/debian/copyright @@ -0,0 +1,45 @@ +This package was debianized by Ulises Vitulli on +Fri, 19 Sep 2008 05:14:30 -0300. + +It was downloaded from + +Upstream Authors, and Copyright: + +Copyright © 2007 Daniel Drake +Copyright © 2006-2007 Timo Hoenig +Copyright © 2006 Pavel Machek +Copyright © 1999 Erik Walthinsen +Copyright © 2004,2006 Thomas Vander Stichele +Copyright © 2007 Cyrille Bagard +Copyright © 2007 Vasily Khoruzhick +Copyright © 2007 Jan-Michael Brummer +Copyright © 2007 Anthony Bretaudeau + + +License: +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 + +The files under libfprint/nbis directory has this license: + +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +The Debian packaging is © 2008, Ulises Vitulli and is +licensed under the LGPL v2.1, see `/usr/share/common-licenses/LGPL-2.1'. --- libfprint-20081125git.orig/debian/rules +++ libfprint-20081125git/debian/rules @@ -0,0 +1,84 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + + +# These are used for cross-compiling and for saving the configure script +# from having to guess our platform (since we know it already) +DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) + +config.status: autogen.sh + dh_testdir + # Add here commands to configure the package. +ifneq "$(wildcard /usr/share/misc/config.sub)" "" + cp -f /usr/share/misc/config.sub config.sub +endif +ifneq "$(wildcard /usr/share/misc/config.guess)" "" + cp -f /usr/share/misc/config.guess config.guess +endif + ./autogen.sh + ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-z,defs" + + +build: build-stamp +build-stamp: config.status + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure aclocal.m4 + find $(CURDIR) -type f -name Makefile.in -exec rm {} \; + # Add here commands to clean up after the build process. + [ ! -f Makefile ] || $(MAKE) distclean + rm -rf depcomp compile config.guess config.sub ltmain.sh missing install-sh config.h.in + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installudev -n libfprint + dh_installdocs + dh_install --sourcedir=debian/tmp + dh_installman + dh_installchangelogs NEWS + dh_link + dh_strip + dh_compress + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build binary-indep binary-arch binary install --- libfprint-20081125git.orig/debian/libfprint0.udev +++ libfprint-20081125git/debian/libfprint0.udev @@ -0,0 +1,27 @@ +## +# udev rules file for Fprint's libpfprint0 library + +# Device aes1610 +ATTRS{idVendor}=="08ff", ATTRS{idProduct}=="1600", MODE="0664", GROUP="plugdev" +# Device aes2501 +ATTRS{idVendor}=="08ff", ATTRS{idProduct}=="2580", MODE="0664", GROUP="plugdev" +# Device aes4000 +ATTRS{idVendor}=="08ff", ATTRS{idProduct}=="5501", MODE="0664", GROUP="plugdev" +# Device fdu2000 +ATTRS{idVendor}=="1162", ATTRS{idProduct}=="0300", MODE="0664", GROUP="plugdev" +# Device upektc +ATTRS{idVendor}=="0483", ATTRS{idProduct}=="2015", MODE="0664", GROUP="plugdev" +# Device upekts +ATTRS{idVendor}=="0483", ATTRS{idProduct}=="2016", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00bb", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00bc", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00bd", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00ca", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="05ba", ATTRS{idProduct}=="0007", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="05ba", ATTRS{idProduct}=="000a", MODE="0664", GROUP="plugdev" --- libfprint-20081125git.orig/debian/libfprint-dev.install +++ libfprint-20081125git/debian/libfprint-dev.install @@ -0,0 +1,5 @@ +usr/include/* +usr/lib/lib*.a +usr/lib/lib*.so +usr/lib/pkgconfig/* +usr/lib/*.la --- libfprint-20081125git.orig/debian/docs +++ libfprint-20081125git/debian/docs @@ -0,0 +1,3 @@ +README +TODO +NEWS --- libfprint-20081125git.orig/debian/get.udev.rules.sh +++ libfprint-20081125git/debian/get.udev.rules.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +grep -r ".vendor" libfprint/drivers/*.c | sed -e s'/ },/,/' | sed s'/0x//g' | awk '{print $1 " " "ATTRS{idVendor}=="$5 " ATTRS{idProduct}==" $8 " MODE=\"0664\", GROUP=\"plugdev\"" }' +| sed s/'==/&\"/g' | sed s/'==\"[[:alnum:]]*/&\"/g' | sed s'/libfprint\/drivers\//# Device /' | sed s'/\.c: /\n/' --- libfprint-20081125git.orig/debian/libfprint0.dirs +++ libfprint-20081125git/debian/libfprint0.dirs @@ -0,0 +1 @@ +usr/lib --- libfprint-20081125git.orig/debian/changelog +++ libfprint-20081125git/debian/changelog @@ -0,0 +1,54 @@ +libfprint (20081125git-2) experimental; urgency=low + + * Fix missing dependence (Closes: #539085). + * Updated package description. + * Updated copyright format. + + -- Ulises Vitulli Wed, 29 Jul 2009 08:21:37 -0300 + +libfprint (20081125git-1) experimental; urgency=low + + * Synchronized to upstream v0.1.0-pre1 release. + * Upstream git checkout fixing little issues: + - Fixes libtool problem. + - Add more debuging support. + * Minor package updates to comply with 3.8.2 standard. + * Now depends on libusb-1.0. + + -- Ulises Vitulli Sat, 06 Jun 2009 12:00:26 -0300 + +libfprint (0.0.6-2) experimental; urgency=low + + * Fixing to non-native pkg (Closes: 481434) + + -- Ulises Vitulli Thu, 15 May 2008 21:56:24 -0300 + +libfprint (0.0.6-1) experimental; urgency=low + + * New upstream release (Closes: #472780). + * Adding udev rule allowing 'plugdev' group access fprint known devices. + + -- Ulises Vitulli Wed, 26 Mar 2008 10:59:55 -0300 + +libfprint (0.0.5-3) experimental; urgency=low + + * Fixing dependences (Closes: #469813) + + -- Ulises Vitulli Fri, 07 Mar 2008 08:47:18 -0200 + +libfprint (0.0.5-2) experimental; urgency=low + + * Added license for nbis/* files in copyright file + + -- Miguel Gea Milvaques Mon, 04 Feb 2008 21:02:48 +0100 + +libfprint (0.0.5-1) experimental; urgency=low + + [ Emfox Zhou ] + * Initial release (Closes: #460493, #438922) + + [ Miguel Gea Milvaques ] + * Moved target from unstable to experimental + * Lintian clean ( makefile distclean in rules) + + -- Miguel Gea Milvaques Sat, 02 Feb 2008 22:56:51 +0100 --- libfprint-20081125git.orig/debian/libfprint-dev.dirs +++ libfprint-20081125git/debian/libfprint-dev.dirs @@ -0,0 +1,2 @@ +usr/lib +usr/include --- libfprint-20081125git.orig/debian/compat +++ libfprint-20081125git/debian/compat @@ -0,0 +1 @@ +5 --- libfprint-20081125git.orig/debian/.svn/entries +++ libfprint-20081125git/debian/.svn/entries @@ -0,0 +1,436 @@ +10 + +dir +132 +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce/packages/fprint/libfprint/async-lib/trunk/debian +svn+ssh://dererk-guest@svn.debian.org/svn/fingerforce + + + +2009-07-24T10:44:07.713746Z +132 +dererk-guest + + + + + + + + + + + + + + +f111ec0d-ca28-0410-9338-ffc5d71c0255 + +control +file +133 + + + +2009-07-29T11:40:07.000000Z +28241c85dfef58638501e1b1a8eff67c +2009-07-29T11:40:47.069890Z +133 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2493 + +compat +file + + + + +2009-01-13T22:22:20.000000Z +1dcca23355272056f04fe8bf20edfce0 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2 + +get.udev.rules.sh +file + + + + +2009-01-13T22:22:20.000000Z +c4c77dfb82566ddf6d214d42a8677143 +2008-09-19T21:33:01.041477Z +116 +dererk-guest +has-props + + + + + + + + + + + + + + + + + + + + +311 + +libfprint-dev.dirs +file + + + + +2009-01-13T22:22:20.000000Z +b5d2b430b3d16ec06cc6de41972021d3 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +20 + +changelog +file +133 + + + +2009-07-29T11:22:12.000000Z +b71e743223a810b191aec280b032a99a +2009-07-29T11:40:47.069890Z +133 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +1618 + +copyright +file +133 + + + +2009-07-29T11:31:35.000000Z +6e52e91585ac19490cebca891244b9a3 +2009-07-29T11:40:47.069890Z +133 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +2102 + +docs +file + + + + +2009-07-24T10:41:38.000000Z +fca6ff008da12742459d8a497a92b0f9 +2009-07-24T10:44:07.713746Z +132 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +17 + +libfprint0.dirs +file + + + + +2009-01-13T22:22:20.000000Z +3dbf8c38685cfb2a60a98bddcf25b292 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +8 + +libfprint-dev.install +file + + + + +2009-01-13T22:22:20.000000Z +ff38f6a450fe0d705e3a5cc7f18b9478 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +78 + +rules +file + + + + +2009-06-21T15:03:09.000000Z +38e71c657759f2fbaa9be36d6e55fea1 +2009-06-06T15:34:55.893749Z +130 +dererk-guest +has-props + + + + + + + + + + + + + + + + + + + + +2344 + +libfprint0.udev +file + + + + +2009-01-13T22:22:20.000000Z +47be541a95c4a0df321df5d1dcd4e281 +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +1217 + +libfprint0.install +file + + + + +2009-01-13T22:22:20.000000Z +d579348da0508f38cb82973b762fe19b +2008-09-19T21:33:01.041477Z +116 +dererk-guest + + + + + + + + + + + + + + + + + + + + + +18 + --- libfprint-20081125git.orig/debian/.svn/prop-base/get.udev.rules.sh.svn-base +++ libfprint-20081125git/debian/.svn/prop-base/get.udev.rules.sh.svn-base @@ -0,0 +1,5 @@ +K 14 +svn:executable +V 1 +* +END --- libfprint-20081125git.orig/debian/.svn/prop-base/rules.svn-base +++ libfprint-20081125git/debian/.svn/prop-base/rules.svn-base @@ -0,0 +1,5 @@ +K 14 +svn:executable +V 1 +* +END --- libfprint-20081125git.orig/debian/.svn/text-base/get.udev.rules.sh.svn-base +++ libfprint-20081125git/debian/.svn/text-base/get.udev.rules.sh.svn-base @@ -0,0 +1,4 @@ +#!/bin/bash + +grep -r ".vendor" libfprint/drivers/*.c | sed -e s'/ },/,/' | sed s'/0x//g' | awk '{print $1 " " "ATTRS{idVendor}=="$5 " ATTRS{idProduct}==" $8 " MODE=\"0664\", GROUP=\"plugdev\"" }' +| sed s/'==/&\"/g' | sed s/'==\"[[:alnum:]]*/&\"/g' | sed s'/libfprint\/drivers\//# Device /' | sed s'/\.c: /\n/' --- libfprint-20081125git.orig/debian/.svn/text-base/compat.svn-base +++ libfprint-20081125git/debian/.svn/text-base/compat.svn-base @@ -0,0 +1 @@ +5 --- libfprint-20081125git.orig/debian/.svn/text-base/docs.svn-base +++ libfprint-20081125git/debian/.svn/text-base/docs.svn-base @@ -0,0 +1,3 @@ +README +TODO +NEWS --- libfprint-20081125git.orig/debian/.svn/text-base/libfprint-dev.dirs.svn-base +++ libfprint-20081125git/debian/.svn/text-base/libfprint-dev.dirs.svn-base @@ -0,0 +1,2 @@ +usr/lib +usr/include --- libfprint-20081125git.orig/debian/.svn/text-base/control.svn-base +++ libfprint-20081125git/debian/.svn/text-base/control.svn-base @@ -0,0 +1,55 @@ +Source: libfprint +Priority: extra +Maintainer: FingerForce Team +Uploaders: Ulises Vitulli , Miguel Gea Milvaques +Build-Depends: debhelper (>= 5), autotools-dev, libtool, automake, libglib2.0-dev, + libxv-dev, libusb-1.0-0-dev, libssl-dev, libmagickcore-dev +Standards-Version: 3.8.2 +Homepage: http://reactivated.net/fprint/ +Section: libs + +Package: libfprint-dev +Section: libdevel +Architecture: any +Depends: libfprint0 (= ${binary:Version}) +Description: async fingerprint library of fprint project, development headers + The fprint project aims to support for consumer fingerprint reader devices. + . + Previously, Linux support for such devices has been scattered amongst different + projects (many incomplete) and inconsistent in that application developers + would have to implement support for each type of fingerprint reader separately. + The idea is to change that by providing a central system to support all the + fingerprint readers as it's possible to get hands on. + . + libfprint is the centre of efforts, it is the component which does the dirty + work of talking to fingerprint reading devices, and processing fingerprint + data. + . + This library is based on new aproach of libusb-1.0, which handles asynchronous + callback model allowing to perform a non-blocking device task. Old synchronous + library has been renamed to libfprint-old. + . + This package provides development headers. + +Package: libfprint0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends} +Description: async fingerprint library of fprint project, shared libraries + The fprint project aims to support for consumer fingerprint reader devices. + . + Previously, Linux support for such devices has been scattered amongst different + projects (many incomplete) and inconsistent in that application developers + would have to implement support for each type of fingerprint reader separately. + The idea is to change that by providing a central system to support all the + fingerprint readers as it's possible to get hands on. + . + libfprint is the centre of efforts, it is the component which does the dirty + work of talking to fingerprint reading devices, and processing fingerprint + data. + . + This library is based on new aproach of libusb-1.0, which handles asynchronous + callback model allowing to perform a non-blocking device task. Old synchronous + library has been renamed to libfprint-old. + . + This package provides shared libraries. --- libfprint-20081125git.orig/debian/.svn/text-base/libfprint0.dirs.svn-base +++ libfprint-20081125git/debian/.svn/text-base/libfprint0.dirs.svn-base @@ -0,0 +1 @@ +usr/lib --- libfprint-20081125git.orig/debian/.svn/text-base/copyright.svn-base +++ libfprint-20081125git/debian/.svn/text-base/copyright.svn-base @@ -0,0 +1,45 @@ +This package was debianized by Ulises Vitulli on +Fri, 19 Sep 2008 05:14:30 -0300. + +It was downloaded from + +Upstream Authors, and Copyright: + +Copyright © 2007 Daniel Drake +Copyright © 2006-2007 Timo Hoenig +Copyright © 2006 Pavel Machek +Copyright © 1999 Erik Walthinsen +Copyright © 2004,2006 Thomas Vander Stichele +Copyright © 2007 Cyrille Bagard +Copyright © 2007 Vasily Khoruzhick +Copyright © 2007 Jan-Michael Brummer +Copyright © 2007 Anthony Bretaudeau + + +License: +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 + +The files under libfprint/nbis directory has this license: + +This software was developed at the National Institute of Standards and +Technology (NIST) by employees of the Federal Government in the course +of their official duties. Pursuant to title 17 Section 105 of the +United States Code, this software is not subject to copyright protection +and is in the public domain. NIST assumes no responsibility whatsoever for +its use by other parties, and makes no guarantees, expressed or implied, +about its quality, reliability, or any other characteristic. + +The Debian packaging is © 2008, Ulises Vitulli and is +licensed under the LGPL v2.1, see `/usr/share/common-licenses/LGPL-2.1'. --- libfprint-20081125git.orig/debian/.svn/text-base/libfprint0.udev.svn-base +++ libfprint-20081125git/debian/.svn/text-base/libfprint0.udev.svn-base @@ -0,0 +1,27 @@ +## +# udev rules file for Fprint's libpfprint0 library + +# Device aes1610 +ATTRS{idVendor}=="08ff", ATTRS{idProduct}=="1600", MODE="0664", GROUP="plugdev" +# Device aes2501 +ATTRS{idVendor}=="08ff", ATTRS{idProduct}=="2580", MODE="0664", GROUP="plugdev" +# Device aes4000 +ATTRS{idVendor}=="08ff", ATTRS{idProduct}=="5501", MODE="0664", GROUP="plugdev" +# Device fdu2000 +ATTRS{idVendor}=="1162", ATTRS{idProduct}=="0300", MODE="0664", GROUP="plugdev" +# Device upektc +ATTRS{idVendor}=="0483", ATTRS{idProduct}=="2015", MODE="0664", GROUP="plugdev" +# Device upekts +ATTRS{idVendor}=="0483", ATTRS{idProduct}=="2016", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00bb", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00bc", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00bd", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="045e", ATTRS{idProduct}=="00ca", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="05ba", ATTRS{idProduct}=="0007", MODE="0664", GROUP="plugdev" +# Device uru4000 +ATTRS{idVendor}=="05ba", ATTRS{idProduct}=="000a", MODE="0664", GROUP="plugdev" --- libfprint-20081125git.orig/debian/.svn/text-base/changelog.svn-base +++ libfprint-20081125git/debian/.svn/text-base/changelog.svn-base @@ -0,0 +1,52 @@ +libfprint (20081125git-2) experimental; urgency=low + + * Fix missing dependence (Closes: #539085). + + -- Ulises Vitulli Wed, 29 Jul 2009 08:21:37 -0300 + +libfprint (20081125git-1) experimental; urgency=low + + * Synchronized to upstream v0.1.0-pre1 release. + * Upstream git checkout fixing little issues: + - Fixes libtool problem. + - Add more debuging support. + * Minor package updates to comply with 3.8.2 standard. + * Now depends on libusb-1.0. + + -- Ulises Vitulli Sat, 06 Jun 2009 12:00:26 -0300 + +libfprint (0.0.6-2) experimental; urgency=low + + * Fixing to non-native pkg (Closes: 481434) + + -- Ulises Vitulli Thu, 15 May 2008 21:56:24 -0300 + +libfprint (0.0.6-1) experimental; urgency=low + + * New upstream release (Closes: #472780). + * Adding udev rule allowing 'plugdev' group access fprint known devices. + + -- Ulises Vitulli Wed, 26 Mar 2008 10:59:55 -0300 + +libfprint (0.0.5-3) experimental; urgency=low + + * Fixing dependences (Closes: #469813) + + -- Ulises Vitulli Fri, 07 Mar 2008 08:47:18 -0200 + +libfprint (0.0.5-2) experimental; urgency=low + + * Added license for nbis/* files in copyright file + + -- Miguel Gea Milvaques Mon, 04 Feb 2008 21:02:48 +0100 + +libfprint (0.0.5-1) experimental; urgency=low + + [ Emfox Zhou ] + * Initial release (Closes: #460493, #438922) + + [ Miguel Gea Milvaques ] + * Moved target from unstable to experimental + * Lintian clean ( makefile distclean in rules) + + -- Miguel Gea Milvaques Sat, 02 Feb 2008 22:56:51 +0100 --- libfprint-20081125git.orig/debian/.svn/text-base/libfprint0.install.svn-base +++ libfprint-20081125git/debian/.svn/text-base/libfprint0.install.svn-base @@ -0,0 +1 @@ +usr/lib/lib*.so.* --- libfprint-20081125git.orig/debian/.svn/text-base/libfprint-dev.install.svn-base +++ libfprint-20081125git/debian/.svn/text-base/libfprint-dev.install.svn-base @@ -0,0 +1,5 @@ +usr/include/* +usr/lib/lib*.a +usr/lib/lib*.so +usr/lib/pkgconfig/* +usr/lib/*.la --- libfprint-20081125git.orig/debian/.svn/text-base/rules.svn-base +++ libfprint-20081125git/debian/.svn/text-base/rules.svn-base @@ -0,0 +1,84 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + + +# These are used for cross-compiling and for saving the configure script +# from having to guess our platform (since we know it already) +DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) + +config.status: autogen.sh + dh_testdir + # Add here commands to configure the package. +ifneq "$(wildcard /usr/share/misc/config.sub)" "" + cp -f /usr/share/misc/config.sub config.sub +endif +ifneq "$(wildcard /usr/share/misc/config.guess)" "" + cp -f /usr/share/misc/config.guess config.guess +endif + ./autogen.sh + ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-z,defs" + + +build: build-stamp +build-stamp: config.status + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure aclocal.m4 + find $(CURDIR) -type f -name Makefile.in -exec rm {} \; + # Add here commands to clean up after the build process. + [ ! -f Makefile ] || $(MAKE) distclean + rm -rf depcomp compile config.guess config.sub ltmain.sh missing install-sh config.h.in + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installudev -n libfprint + dh_installdocs + dh_install --sourcedir=debian/tmp + dh_installman + dh_installchangelogs NEWS + dh_link + dh_strip + dh_compress + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build binary-indep binary-arch binary install --- libfprint-20081125git.orig/m4/lt~obsolete.m4 +++ libfprint-20081125git/m4/lt~obsolete.m4 @@ -0,0 +1,92 @@ +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 4 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) --- libfprint-20081125git.orig/m4/ltversion.m4 +++ libfprint-20081125git/m4/ltversion.m4 @@ -0,0 +1,23 @@ +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# Generated from ltversion.in. + +# serial 3012 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.2.6]) +m4_define([LT_PACKAGE_REVISION], [1.3012]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.2.6' +macro_revision='1.3012' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) --- libfprint-20081125git.orig/m4/ltoptions.m4 +++ libfprint-20081125git/m4/ltoptions.m4 @@ -0,0 +1,368 @@ +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option `$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl `shared' nor `disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + ]) +])# _LT_SET_OPTIONS + + +## --------------------------------- ## +## Macros to handle LT_INIT options. ## +## --------------------------------- ## + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [0], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the `shared' and +# `disable-shared' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the `static' and +# `disable-static' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the `fast-install' +# and `disable-fast-install' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the `pic-only' and `no-pic' +# LT_INIT options. +# MODE is either `yes' or `no'. If omitted, it defaults to `both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [pic_mode="$withval"], + [pic_mode=default]) + +test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + +## ----------------- ## +## LTDL_INIT Options ## +## ----------------- ## + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) --- libfprint-20081125git.orig/m4/libtool.m4 +++ libfprint-20081125git/m4/libtool.m4 @@ -0,0 +1,7376 @@ +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, or +# obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +]) + +# serial 56 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ltmain" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_CC_BASENAME(CC) +# ------------------- +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +m4_defun([_LT_CC_BASENAME], +[for cc_temp in $1""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options which allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl +_LT_PROG_ECHO_BACKSLASH + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld="$lt_cv_prog_gnu_ld" + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from `configure', and `config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# `config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain="$ac_aux_dir/ltmain.sh" +])# _LT_PROG_LTMAIN + + +## ------------------------------------- ## +## Accumulate code for creating libtool. ## +## ------------------------------------- ## + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the `libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + +## ------------------------ ## +## FIXME: Eliminate VARNAME ## +## ------------------------ ## + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to `config.status' so that its +# declaration there will have the same value as in `configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "X$" | $Xsed -e "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags="_LT_TAGS"dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the `libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into `config.status', and then the shell code to quote escape them in +# for loops in `config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Fix-up fallback echo if it was mangled by the above quoting rules. +case \$lt_ECHO in +*'\\\[$]0 --fallback-echo"')dnl " + lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\` + ;; +esac + +_LT_OUTPUT_LIBTOOL_INIT +]) + + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +cat >"$CONFIG_LT" <<_LTEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate a libtool stub with the current configuration. + +lt_cl_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AS_SHELL_SANITIZE +_AS_PREPARE + +exec AS_MESSAGE_FD>&1 +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +\`$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2008 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test $[#] != 0 +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try \`$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try \`$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +if test "$no_create" != yes; then + lt_cl_success=: + test "$silent" = yes && + lt_config_lt_args="$lt_config_lt_args --quiet" + exec AS_MESSAGE_LOG_FD>/dev/null + $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false + exec AS_MESSAGE_LOG_FD>>config.log + $lt_cl_success || AS_EXIT(1) +fi +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options which allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + + cfgfile="${ofile}T" + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL + +# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +_LT_COPYING +_LT_LIBTOOL_TAGS + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + _LT_PROG_XSI_SHELLFNS + + sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + TIMESTAMP='$TIMESTAMP' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "${LT_MULTI_MODULE}"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS="$save_LDFLAGS" + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + 10.[[012]]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then + _lt_dar_single_mod='$single_module' + fi + if test "$lt_cv_ld_exported_symbols_list" = "yes"; then + _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + if test "$DSYMUTIL" != ":"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES +# -------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" + case $cc_basename in + ifort*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=echo + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + m4_if([$1], [CXX], +[ if test "$lt_cv_apple_cc_single_mod" != "yes"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX +# ----------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +AC_LINK_IFELSE(AC_LANG_PROGRAM,[ +lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\(.*\)$/\1/ + p + } + }' +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +fi],[]) +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[ifdef([AC_DIVERSION_NOTICE], + [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], + [AC_DIVERT_PUSH(NOTICE)]) +$1 +AC_DIVERT_POP +])# _LT_SHELL_INIT + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Add some code to the start of the generated configure script which +# will find an echo command which doesn't interpret backslashes. +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[_LT_SHELL_INIT([ +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$lt_ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` + ;; +esac + +ECHO=${lt_ECHO-echo} +if test "X[$]1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X[$]1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then + # Yippee, $ECHO works! + : +else + # Restart under the correct shell. + exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} +fi + +if test "X[$]1" = X--fallback-echo; then + # used as fallback echo + shift + cat <<_LT_EOF +[$]* +_LT_EOF + exit 0 +fi + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test -z "$lt_ECHO"; then + if test "X${echo_test_string+set}" != Xset; then + # find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if { echo_test_string=`eval $cmd`; } 2>/dev/null && + { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null + then + break + fi + done + fi + + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : + else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$ECHO" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + ECHO='print -r' + elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} + else + # Try using printf. + ECHO='printf %s\n' + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do + if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "[$]0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} + else + # Oops. We lost completely, so just stick with echo. + ECHO=echo + fi + fi + fi + fi + fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +lt_ECHO=$ECHO +if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then + lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" +fi + +AC_SUBST(lt_ECHO) +]) +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], + [An echo program that does not interpret backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks="$enable_libtool_lock" +])# _LT_ENABLE_LOCK + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[AC_CHECK_TOOL(AR, ar, false) +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1]) + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test x"[$]$2" = xyes; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS="$save_LDFLAGS" +]) + +if test x"[$]$2" = xyes; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8 ; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ + = "XX$teststring$teststring"; } >/dev/null 2>&1 && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n $lt_cv_sys_max_cmd_len ; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "$cross_compiling" = yes; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line __oline__ "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen="shl_load"], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen="dlopen"], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links="nottested" +if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test "$hard_links" = no; then + AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/", + [Define to the sub-directory in which libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then + + # We can hardcode non-existent directories. + if test "$_LT_TAGVAR(hardcode_direct, $1)" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test "$_LT_TAGVAR(hardcode_action, $1)" = relink || + test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test "$GCC" = yes; then + case $host_os in + darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; + *) lt_awk_arg="/^libraries:/" ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` + else + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary. + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path/$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" + else + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' +BEGIN {RS=" "; FS="/|\n";} { + lt_foo=""; + lt_count=0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo="/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix[[4-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[123]]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix[[3-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # Some binutils ld are patched to set DT_RUNPATH + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[[89]] | openbsd2.[[89]].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then + sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" +fi +if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then + sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" +fi + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([], [sys_lib_dlsearch_path_spec], [2], + [Run-time system search path for libraries]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program which can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$1; then + lt_cv_path_MAGIC_CMD="$ac_dir/$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac]) +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program which can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test "$withval" = no || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method == "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + : ${lt_cv_path_NM=no} +fi]) +if test "$lt_cv_path_NM" != "no"; then + NM="$lt_cv_path_NM" +else + # Didn't find any BSD compatible name lister, look for dumpbin. + AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :) + AC_SUBST([DUMPBIN]) + if test "$DUMPBIN" != ":"; then + NM="$DUMPBIN" + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM="-lm") + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test "$host_cpu" = ia64; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p'" +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"lib\2\", (void *) \&\2},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function + # and D for any global variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ +" {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ +" s[1]~/^[@?]/{print s[1], s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +AC_MSG_CHECKING([for $compiler option to produce PIC]) +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + if test "$host_cpu" != ia64; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64 which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC*) + # IBM XL 8.0 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd* | netbsdelf*-gnu) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu) + case $cc_basename in + # old Intel for x86_64 which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Sun\ F*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac +AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" + ;; + cygwin* | mingw* | cegcc*) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + ;; + linux* | k*bsd*-gnu) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + linux* | k*bsd*-gnu) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu) + tmp_diet=no + if test "$host_os" = linux-dietlibc; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test "$tmp_diet" = no + then + tmp_addflag= + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + xl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + xlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GCC" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + _LT_TAGVAR(link_all_deplibs, $1)=no + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + freebsd1*) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" + AC_LINK_IFELSE(int foo(void) {}, + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' + ) + LDFLAGS="$save_LDFLAGS" + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + netbsd* | netbsdelf*-gnu) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + else + case $host_os in + openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + ;; + esac + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test "$GCC" = yes; then + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. GCC discards it without `$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test "$GCC" = yes; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test x$host_vendor = xsni; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_MSG_CHECKING([whether -lc should be explicitly linked in]) + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1], + [[If ld is used when linking, flag to hardcode $libdir into a binary + during linking. This must work even if $libdir does not exist]]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting ${shlibpath_var} if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [fix_srcfile_path], [1], + [Fix the shell variable $srcfile for the compiler]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC="$CC" +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report which library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC="$lt_save_CC" +])# _LT_LANG_C_CONFIG + + +# _LT_PROG_CXX +# ------------ +# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++ +# compiler, we have our own version here. +m4_defun([_LT_PROG_CXX], +[ +pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes]) +AC_PROG_CXX +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_CXX + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_CXX], []) + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[AC_REQUIRE([_LT_PROG_CXX])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_caught_CXX_error" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GXX" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared + # libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd[[12]]*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + gnu*) + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + *) # Version 6 will use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + xl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd2*) + # C++ shared libraries are fairly broken + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd=echo + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + + _LT_TAGVAR(GCC, $1)="$GXX" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test "$_lt_caught_CXX_error" != yes + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +]) +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test $p = "-L" || + test $p = "-R"; then + prev=$p + continue + else + prev= + fi + + if test "$pre_test_object_deps_done" = no; then + case $p in + -L* | -R*) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)="${prev}${p}" + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" + fi + fi + ;; + + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test "$pre_test_object_deps_done" = no; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)="$p" + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)="$p" + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; + +linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; + +solaris*) + case $cc_basename in + CC*) + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + # Adding this requires a known-good setup of shared libraries for + # Sun compiler versions before 5.6, else PIC objects from an old + # archive will be linked into the output, leading to subtle bugs. + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_PROG_F77 +# ------------ +# Since AC_PROG_F77 is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_F77], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes]) +AC_PROG_F77 +if test -z "$F77" || test "X$F77" = "Xno"; then + _lt_disable_F77=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_F77 + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_F77], []) + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_REQUIRE([_LT_PROG_F77])dnl +AC_LANG_PUSH(Fortran 77) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_F77" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${F77-"f77"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$G77" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_F77" != yes + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_PROG_FC +# ----------- +# Since AC_PROG_FC is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_FC], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes]) +AC_PROG_FC +if test -z "$FC" || test "X$FC" = "Xno"; then + _lt_disable_FC=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_FC + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_FC], []) + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_REQUIRE([_LT_PROG_FC])dnl +AC_LANG_PUSH(Fortran) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_FC" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${FC-"f95"} + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_FC" != yes + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)="$LD" +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC="$lt_save_CC" +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code="$lt_simple_compile_test_code" + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC="$lt_save_CC" +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[AC_MSG_CHECKING([whether the shell understands some XSI constructs]) +# Try some XSI features +xsi_shell=no +( _lt_dummy="a/b/c" + test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ + = c,a/b,, \ + && eval 'test $(( 1 + 1 )) -eq 2 \ + && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ + && xsi_shell=yes +AC_MSG_RESULT([$xsi_shell]) +_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell']) + +AC_MSG_CHECKING([whether the shell understands "+="]) +lt_shell_append=no +( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \ + >/dev/null 2>&1 \ + && lt_shell_append=yes +AC_MSG_RESULT([$lt_shell_append]) +_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append']) + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PROG_XSI_SHELLFNS +# --------------------- +# Bourne and XSI compatible variants of some useful shell functions. +m4_defun([_LT_PROG_XSI_SHELLFNS], +[case $xsi_shell in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac +} + +# func_basename file +func_basename () +{ + func_basename_result="${1##*/}" +} + +# func_dirname_and_basename file append nondir_replacement +# perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# Implementation must be kept synchronized with func_dirname +# and func_basename. For efficiency, we do not delegate to +# those functions but instead duplicate the functionality here. +func_dirname_and_basename () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac + func_basename_result="${1##*/}" +} + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +func_stripname () +{ + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary parameter first. + func_stripname_result=${3} + func_stripname_result=${func_stripname_result#"${1}"} + func_stripname_result=${func_stripname_result%"${2}"} +} + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=${1%%=*} + func_opt_split_arg=${1#*=} +} + +# func_lo2o object +func_lo2o () +{ + case ${1} in + *.lo) func_lo2o_result=${1%.lo}.${objext} ;; + *) func_lo2o_result=${1} ;; + esac +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=${1%.*}.lo +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=$(( $[*] )) +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=${#1} +} + +_LT_EOF + ;; + *) # Bourne compatible functions. + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + # Extract subdirectory from the argument. + func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` + if test "X$func_dirname_result" = "X${1}"; then + func_dirname_result="${3}" + else + func_dirname_result="$func_dirname_result${2}" + fi +} + +# func_basename file +func_basename () +{ + func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` +} + +dnl func_dirname_and_basename +dnl A portable version of this function is already defined in general.m4sh +dnl so there is no need for it here. + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# func_strip_suffix prefix name +func_stripname () +{ + case ${2} in + .*) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; + *) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; + esac +} + +# sed scripts: +my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q' +my_sed_long_arg='1s/^-[[^=]]*=//' + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` + func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` +} + +# func_lo2o object +func_lo2o () +{ + func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'` +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=`expr "$[@]"` +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len` +} + +_LT_EOF +esac + +case $lt_shell_append in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]+=\$[2]" +} +_LT_EOF + ;; + *) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]=\$$[1]\$[2]" +} + +_LT_EOF + ;; + esac +]) --- libfprint-20081125git.orig/m4/ltsugar.m4 +++ libfprint-20081125git/m4/ltsugar.m4 @@ -0,0 +1,123 @@ +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59 which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +])