summaryrefslogtreecommitdiff
path: root/libfprint
diff options
context:
space:
mode:
authorVasily Khoruzhick <anarsoul@gmail.com>2013-05-24 12:34:45 +0300
committerVasily Khoruzhick <anarsoul@gmail.com>2013-08-19 11:13:50 +0300
commit948ab02d1a9d321e31dfd501646c29b880c1e5d0 (patch)
tree2acd317c6814d0623d375774070ac7803f8cd2ea /libfprint
parenta6101026d2ddff76efe9f46669e24db3a0a6a0e4 (diff)
lib: use pixman for imaging utils
pixman is very lightweight library for pixel manipulation, and it has no dependencies except glibc, so using it instead of gdkpixbuf/imagemagick makes list for libfprint dependencies a bit shorter.
Diffstat (limited to 'libfprint')
-rw-r--r--libfprint/Makefile.am15
-rw-r--r--libfprint/gdkpixbuf.c88
-rw-r--r--libfprint/pixman.c (renamed from libfprint/imagemagick.c)52
3 files changed, 28 insertions, 127 deletions
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 <dsd@gentoo.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <errno.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-#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
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 <dsd@gentoo.org>
+ * Copyright (C) 2013 Vasily Khoruzhick <anarsoul@gmail.com>
*
* 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 <errno.h>
-#include <magick/ImageMagick.h>
+#include <pixman.h>
+#include <string.h>
#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. */
-
- 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);
+ 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);
+
+ 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;
}