diff --git a/configure.ac b/configure.ac index 4fbaad8..d9faeb0 100644 --- a/configure.ac +++ b/configure.ac @@ -184,8 +184,7 @@ PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.28]) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) -imagemagick_found=no -gdkpixbuf_found=no +pixman_found=no AC_ARG_ENABLE(udev-rules, AC_HELP_STRING([--enable-udev-rules],[Update the udev rules]), @@ -213,20 +212,13 @@ AC_MSG_NOTICE([installing udev rules in ${ac_with_udev_rules_dir}]) AC_SUBST([udev_rulesdir],[${ac_with_udev_rules_dir}]) if test "$require_imaging" = "yes"; then - PKG_CHECK_MODULES(IMAGING, gthread-2.0 gdk-pixbuf-2.0, [gdkpixbuf_found=yes], [gdkpixbuf_found=no]) - if test "$gdkpixbuf_found" != "yes"; then - PKG_CHECK_MODULES(IMAGING, ImageMagick, [imagemagick_found=yes], [imagemagick_found=no]) + PKG_CHECK_MODULES(IMAGING, pixman-1, [pixman_found=yes], [pixman_found=no]) + if test "$pixman_found" != "yes"; then + AC_MSG_ERROR([pixman is required for imaging support]) fi fi -if test "$require_imaging" = "yes"; then - if test "$gdkpixbuf_found" != "yes" && test "$imagemagick_found" != "yes"; then - AC_MSG_ERROR([gdk-pixbuf or ImageMagick is required for imaging support]) - fi -fi - -AM_CONDITIONAL([REQUIRE_GDKPIXBUF], [test "$gdkpixbuf_found" = "yes"]) -AM_CONDITIONAL([REQUIRE_IMAGEMAGICK], [test "$imagemagick_found" = "yes"]) +AM_CONDITIONAL([REQUIRE_PIXMAN], [test "$pixman_found" = "yes"]) AC_SUBST(IMAGING_CFLAGS) AC_SUBST(IMAGING_LIBS) @@ -296,10 +288,8 @@ AM_CFLAGS="-std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes AC_SUBST(AM_CFLAGS) if test "$require_imaging" = "yes"; then - if test x$gdkpixbuf_found != no; then - AC_MSG_NOTICE([** Using gdk-pixbuf for imaging]) - else - AC_MSG_NOTICE([** Using ImageMagick for imaging]) + if test x$pixman_found != no; then + AC_MSG_NOTICE([** Using pixman for imaging]) fi else AC_MSG_NOTICE([ Imaging support disabled]) diff --git a/libfprint/Makefile.am b/libfprint/Makefile.am index 7ceb90d..c216d49 100644 --- a/libfprint/Makefile.am +++ b/libfprint/Makefile.am @@ -46,8 +46,7 @@ EXTRA_DIST = \ drivers/aes3k.h \ drivers/driver_ids.h \ aeslib.c aeslib.h \ - imagemagick.c \ - gdkpixbuf.c \ + pixman.c \ 60-fprint-autosuspend.rules DRIVER_SRC = @@ -95,7 +94,7 @@ libfprint_la_LDFLAGS = -version-info @lt_major@:@lt_revision@:@lt_age@ libfprint_la_LIBADD = -lm $(LIBUSB_LIBS) $(GLIB_LIBS) $(CRYPTO_LIBS) fprint_list_udev_rules_SOURCES = fprint-list-udev-rules.c -fprint_list_udev_rules_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(IMAGEMAGICK_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS) +fprint_list_udev_rules_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS) fprint_list_udev_rules_LDADD = $(builddir)/libfprint.la $(GLIB_LIBS) udev_rules_DATA = 60-fprint-autosuspend.rules @@ -177,14 +176,8 @@ if ENABLE_ETES603 DRIVER_SRC += $(ETES603_SRC) endif -if REQUIRE_IMAGEMAGICK -OTHER_SRC += imagemagick.c -libfprint_la_CFLAGS += $(IMAGING_CFLAGS) -libfprint_la_LIBADD += $(IMAGING_LIBS) -endif - -if REQUIRE_GDKPIXBUF -OTHER_SRC += gdkpixbuf.c +if REQUIRE_PIXMAN +OTHER_SRC += pixman.c libfprint_la_CFLAGS += $(IMAGING_CFLAGS) libfprint_la_LIBADD += $(IMAGING_LIBS) endif diff --git a/libfprint/gdkpixbuf.c b/libfprint/gdkpixbuf.c deleted file mode 100644 index 4de6151..0000000 --- a/libfprint/gdkpixbuf.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 w_factor, unsigned int h_factor) -{ - int new_width = img->width * w_factor; - int new_height = img->height * h_factor; - GdkPixbuf *orig, *resized; - struct fp_img *newimg; - guchar *pixels; - guint y; - int rowstride; - - g_type_init (); - - /* It is possible to implement resizing using a simple algorithm, however - * we use gdk-pixbuf because it applies some kind of smoothing to the - * result, which improves matching performances in my experiments. */ - - /* Create the original pixbuf, and fill it in from the grayscale data */ - orig = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - FALSE, - 8, - img->width, - img->height); - rowstride = gdk_pixbuf_get_rowstride (orig); - pixels = gdk_pixbuf_get_pixels (orig); - for (y = 0; y < img->height; y++) { - guint x; - for (x = 0; x < img->width; x++) { - guchar *p, *r; - - p = pixels + y * rowstride + x * 3; - r = img->data + y * img->width + x; - p[0] = r[0]; - p[1] = r[0]; - p[2] = r[0]; - } - } - - /* Resize the pixbuf, and create the new fp_img */ - resized = gdk_pixbuf_scale_simple (orig, new_width, new_height, GDK_INTERP_HYPER); - g_object_unref (orig); - - newimg = fpi_img_new(new_width * new_height); - newimg->width = new_width; - newimg->height = new_height; - newimg->flags = img->flags; - - rowstride = gdk_pixbuf_get_rowstride (resized); - pixels = gdk_pixbuf_get_pixels (resized); - for (y = 0; y < newimg->height; y++) { - guint x; - for (x = 0; x < newimg->width; x++) { - guchar *p, *r; - - r = newimg->data + y * newimg->width + x; - p = pixels + y * rowstride + x * 3; - r[0] = p[0]; - } - } - - g_object_unref (resized); - - return newimg; -} - diff --git a/libfprint/imagemagick.c b/libfprint/pixman.c similarity index 56% rename from libfprint/imagemagick.c rename to libfprint/pixman.c index 68e7146..1b4ca06 100644 --- a/libfprint/imagemagick.c +++ b/libfprint/pixman.c @@ -1,6 +1,7 @@ /* * Imaging utility functions for libfprint * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2013 Vasily Khoruzhick * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,50 +18,45 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include +#include +#include #include "fp_internal.h" struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor) { - Image *mimg; - Image *resized; - ExceptionInfo exception; - MagickBooleanType ret; int new_width = img->width * w_factor; int new_height = img->height * h_factor; + pixman_image_t *orig, *resized; + pixman_transform_t transform; 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. */ + orig = pixman_image_create_bits(PIXMAN_a8, img->width, img->height, (uint32_t *)img->data, img->width); + resized = pixman_image_create_bits(PIXMAN_a8, new_width, new_height, NULL, new_width); - 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); + pixman_transform_init_identity(&transform); + pixman_transform_scale(NULL, &transform, pixman_int_to_fixed(w_factor), pixman_int_to_fixed(h_factor)); + pixman_image_set_transform(orig, &transform); + pixman_image_set_filter(orig, PIXMAN_FILTER_BILINEAR, NULL, 0); + pixman_image_composite32(PIXMAN_OP_SRC, + orig, /* src */ + NULL, /* mask */ + resized, /* dst */ + 0, 0, /* src x y */ + 0, 0, /* mask x y */ + 0, 0, /* dst x y */ + new_width, new_height /* width height */ + ); 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; - } + memcpy(newimg->data, pixman_image_get_data(resized), new_width * new_height); - DestroyImage(mimg); - DestroyImage(resized); + pixman_image_unref(orig); + pixman_image_unref(resized); return newimg; }