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.
This commit is contained in:
parent
a6101026d2
commit
948ab02d1a
4 changed files with 34 additions and 143 deletions
24
configure.ac
24
configure.ac
|
@ -184,8 +184,7 @@ PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.28])
|
||||||
AC_SUBST(GLIB_CFLAGS)
|
AC_SUBST(GLIB_CFLAGS)
|
||||||
AC_SUBST(GLIB_LIBS)
|
AC_SUBST(GLIB_LIBS)
|
||||||
|
|
||||||
imagemagick_found=no
|
pixman_found=no
|
||||||
gdkpixbuf_found=no
|
|
||||||
|
|
||||||
AC_ARG_ENABLE(udev-rules,
|
AC_ARG_ENABLE(udev-rules,
|
||||||
AC_HELP_STRING([--enable-udev-rules],[Update the 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}])
|
AC_SUBST([udev_rulesdir],[${ac_with_udev_rules_dir}])
|
||||||
|
|
||||||
if test "$require_imaging" = "yes"; then
|
if test "$require_imaging" = "yes"; then
|
||||||
PKG_CHECK_MODULES(IMAGING, gthread-2.0 gdk-pixbuf-2.0, [gdkpixbuf_found=yes], [gdkpixbuf_found=no])
|
PKG_CHECK_MODULES(IMAGING, pixman-1, [pixman_found=yes], [pixman_found=no])
|
||||||
if test "$gdkpixbuf_found" != "yes"; then
|
if test "$pixman_found" != "yes"; then
|
||||||
PKG_CHECK_MODULES(IMAGING, ImageMagick, [imagemagick_found=yes], [imagemagick_found=no])
|
AC_MSG_ERROR([pixman is required for imaging support])
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$require_imaging" = "yes"; then
|
AM_CONDITIONAL([REQUIRE_PIXMAN], [test "$pixman_found" = "yes"])
|
||||||
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"])
|
|
||||||
AC_SUBST(IMAGING_CFLAGS)
|
AC_SUBST(IMAGING_CFLAGS)
|
||||||
AC_SUBST(IMAGING_LIBS)
|
AC_SUBST(IMAGING_LIBS)
|
||||||
|
|
||||||
|
@ -296,10 +288,8 @@ AM_CFLAGS="-std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes
|
||||||
AC_SUBST(AM_CFLAGS)
|
AC_SUBST(AM_CFLAGS)
|
||||||
|
|
||||||
if test "$require_imaging" = "yes"; then
|
if test "$require_imaging" = "yes"; then
|
||||||
if test x$gdkpixbuf_found != no; then
|
if test x$pixman_found != no; then
|
||||||
AC_MSG_NOTICE([** Using gdk-pixbuf for imaging])
|
AC_MSG_NOTICE([** Using pixman for imaging])
|
||||||
else
|
|
||||||
AC_MSG_NOTICE([** Using ImageMagick for imaging])
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
AC_MSG_NOTICE([ Imaging support disabled])
|
AC_MSG_NOTICE([ Imaging support disabled])
|
||||||
|
|
|
@ -46,8 +46,7 @@ EXTRA_DIST = \
|
||||||
drivers/aes3k.h \
|
drivers/aes3k.h \
|
||||||
drivers/driver_ids.h \
|
drivers/driver_ids.h \
|
||||||
aeslib.c aeslib.h \
|
aeslib.c aeslib.h \
|
||||||
imagemagick.c \
|
pixman.c \
|
||||||
gdkpixbuf.c \
|
|
||||||
60-fprint-autosuspend.rules
|
60-fprint-autosuspend.rules
|
||||||
|
|
||||||
DRIVER_SRC =
|
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)
|
libfprint_la_LIBADD = -lm $(LIBUSB_LIBS) $(GLIB_LIBS) $(CRYPTO_LIBS)
|
||||||
|
|
||||||
fprint_list_udev_rules_SOURCES = fprint-list-udev-rules.c
|
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)
|
fprint_list_udev_rules_LDADD = $(builddir)/libfprint.la $(GLIB_LIBS)
|
||||||
|
|
||||||
udev_rules_DATA = 60-fprint-autosuspend.rules
|
udev_rules_DATA = 60-fprint-autosuspend.rules
|
||||||
|
@ -177,14 +176,8 @@ if ENABLE_ETES603
|
||||||
DRIVER_SRC += $(ETES603_SRC)
|
DRIVER_SRC += $(ETES603_SRC)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if REQUIRE_IMAGEMAGICK
|
if REQUIRE_PIXMAN
|
||||||
OTHER_SRC += imagemagick.c
|
OTHER_SRC += pixman.c
|
||||||
libfprint_la_CFLAGS += $(IMAGING_CFLAGS)
|
|
||||||
libfprint_la_LIBADD += $(IMAGING_LIBS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if REQUIRE_GDKPIXBUF
|
|
||||||
OTHER_SRC += gdkpixbuf.c
|
|
||||||
libfprint_la_CFLAGS += $(IMAGING_CFLAGS)
|
libfprint_la_CFLAGS += $(IMAGING_CFLAGS)
|
||||||
libfprint_la_LIBADD += $(IMAGING_LIBS)
|
libfprint_la_LIBADD += $(IMAGING_LIBS)
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Imaging utility functions for libfprint
|
* Imaging utility functions for libfprint
|
||||||
* Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
|
* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <pixman.h>
|
||||||
#include <magick/ImageMagick.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "fp_internal.h"
|
#include "fp_internal.h"
|
||||||
|
|
||||||
struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor)
|
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_width = img->width * w_factor;
|
||||||
int new_height = img->height * h_factor;
|
int new_height = img->height * h_factor;
|
||||||
|
pixman_image_t *orig, *resized;
|
||||||
|
pixman_transform_t transform;
|
||||||
struct fp_img *newimg;
|
struct fp_img *newimg;
|
||||||
|
|
||||||
/* It is possible to implement resizing using a simple algorithm, however
|
orig = pixman_image_create_bits(PIXMAN_a8, img->width, img->height, (uint32_t *)img->data, img->width);
|
||||||
* we use ImageMagick because it applies some kind of smoothing to the
|
resized = pixman_image_create_bits(PIXMAN_a8, new_width, new_height, NULL, new_width);
|
||||||
* result, which improves matching performances in my experiments. */
|
|
||||||
|
|
||||||
if (!IsMagickInstantiated())
|
pixman_transform_init_identity(&transform);
|
||||||
InitializeMagick(NULL);
|
pixman_transform_scale(NULL, &transform, pixman_int_to_fixed(w_factor), pixman_int_to_fixed(h_factor));
|
||||||
|
pixman_image_set_transform(orig, &transform);
|
||||||
GetExceptionInfo(&exception);
|
pixman_image_set_filter(orig, PIXMAN_FILTER_BILINEAR, NULL, 0);
|
||||||
mimg = ConstituteImage(img->width, img->height, "I", CharPixel, img->data,
|
pixman_image_composite32(PIXMAN_OP_SRC,
|
||||||
&exception);
|
orig, /* src */
|
||||||
|
NULL, /* mask */
|
||||||
GetExceptionInfo(&exception);
|
resized, /* dst */
|
||||||
resized = ResizeImage(mimg, new_width, new_height, 0, 1.0, &exception);
|
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 = fpi_img_new(new_width * new_height);
|
||||||
newimg->width = new_width;
|
newimg->width = new_width;
|
||||||
newimg->height = new_height;
|
newimg->height = new_height;
|
||||||
newimg->flags = img->flags;
|
newimg->flags = img->flags;
|
||||||
|
|
||||||
GetExceptionInfo(&exception);
|
memcpy(newimg->data, pixman_image_get_data(resized), new_width * new_height);
|
||||||
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);
|
pixman_image_unref(orig);
|
||||||
DestroyImage(resized);
|
pixman_image_unref(resized);
|
||||||
|
|
||||||
return newimg;
|
return newimg;
|
||||||
}
|
}
|
Loading…
Reference in a new issue