libimagequant: fix integration
The symbol was being set up in cmake but not on the autotools side. Clean this up to be like other external libraries. We need to pull in some openmp logic as it's not uncommon for the lib to be built with openmp support. When we test for it, we need to do so with openmp flags. Fixes #137.master
parent
6e054c42cf
commit
c9a4a85f38
|
@ -157,7 +157,7 @@ else (USE_EXT_GD)
|
|||
|
||||
IF(LIQ_FOUND)
|
||||
INCLUDE_DIRECTORIES(${LIQ_INCLUDE_DIR})
|
||||
SET(HAVE_LIBIMAGEQUANT_H 1)
|
||||
SET(HAVE_LIBIMAGEQUANT 1)
|
||||
ENDIF(LIQ_FOUND)
|
||||
|
||||
IF(XPM_FOUND)
|
||||
|
|
|
@ -23,7 +23,7 @@ FIND_LIBRARY(LIQ_LIBRARY
|
|||
IF (LIQ_LIBRARY AND LIQ_INCLUDE_DIR)
|
||||
SET(LIQ_FOUND "YES")
|
||||
SET(LIQ_LIBRARIES ${LIQ_LIBRARY})
|
||||
SET(HAVE_LIBIMAGEQUANT_H 1)
|
||||
SET(HAVE_LIBIMAGEQUANT 1)
|
||||
ENDIF (LIQ_LIBRARY AND LIQ_INCLUDE_DIR)
|
||||
|
||||
IF (LIQ_FOUND)
|
||||
|
@ -51,7 +51,7 @@ ELSE (LIQ_FOUND)
|
|||
SET(LIQ_BUILD "YES")
|
||||
SET(LIQ_LIBRARIES "${PROJECT_BINARY_DIR}/libimagequant/libimagequant.a")
|
||||
SET(LIQ_INCLUDE_DIR "${PROJECT_BINARY_DIR}/libimagequant/")
|
||||
SET(HAVE_LIBIMAGEQUANT_H 1)
|
||||
SET(HAVE_LIBIMAGEQUANT 1)
|
||||
ENDIF(CMAKE_VERSION VERSION_GREATER "2.8.1")
|
||||
ENDIF(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
ENDIF (LIQ_FOUND)
|
||||
|
|
19
configure.ac
19
configure.ac
|
@ -119,6 +119,9 @@ AC_CHECK_HEADERS(iconv.h,
|
|||
dnl do we need to specify -lm explicitly?
|
||||
AC_CHECK_FUNC(sin,,[AC_CHECK_LIB(m,sin)])
|
||||
|
||||
AX_PTHREAD()
|
||||
AX_OPENMP()
|
||||
|
||||
dnl Helper macro for working with external libraries.
|
||||
dnl GD_LIB_CHECK([SYM], [FEATURE], [name], [...test...])
|
||||
dnl $1 - upper case symbol
|
||||
|
@ -238,6 +241,19 @@ GD_LIB_CHECK([LIBJPEG], [JPEG], [jpeg], [
|
|||
])
|
||||
])
|
||||
|
||||
dnl Check for libimagequant support.
|
||||
GD_LIB_CHECK([LIBIMAGEQUANT], [LIQ], [liq], [
|
||||
AC_CHECK_HEADER([libimagequant.h], [
|
||||
save_CFLAGS=$CFLAGS
|
||||
CFLAGS="$CFLAGS $OPENMP_CFLAGS"
|
||||
AC_CHECK_LIB([imagequant], [liq_attr_create_with_allocator], [dnl
|
||||
AS_VAR_APPEND([LIBIMAGEQUANT_LIBS], [" -limagequant $OPENMP_CFLAGS"])
|
||||
gd_found_lib=yes
|
||||
])
|
||||
CFLAGS=$save_CFLAGS
|
||||
])
|
||||
])
|
||||
|
||||
dnl Check for xpm support.
|
||||
GD_LIB_PKG_CHECK([LIBXPM], [XPM], [xpm], [xpm], [
|
||||
AC_CHECK_LIB([Xpm], [XpmReadFileToXpmImage], [dnl
|
||||
|
@ -265,8 +281,6 @@ GD_LIB_CHECK([LIBWEBP], [WEBP], [webp], [
|
|||
gl_VISIBILITY()
|
||||
CFLAGS="$CFLAGS $CFLAG_VISIBILITY"
|
||||
|
||||
AX_PTHREAD()
|
||||
|
||||
MINGW_AC_WIN32_NATIVE_HOST()
|
||||
|
||||
if test "$mingw_cv_win32_host" = yes; then
|
||||
|
@ -292,6 +306,7 @@ AC_MSG_RESULT([
|
|||
Support for Freetype 2.x library: $gd_with_LIBFREETYPE
|
||||
Support for Fontconfig library: $gd_with_LIBFONTCONFIG
|
||||
Support for Xpm library: $gd_with_LIBXPM
|
||||
Support for liq library: $gd_with_LIBIMAGEQUANT
|
||||
Support for pthreads: $ax_pthread_ok
|
||||
])
|
||||
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_openmp.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_OPENMP([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macro tries to find out how to compile programs that use OpenMP a
|
||||
# standard API and set of compiler directives for parallel programming
|
||||
# (see http://www-unix.mcs/)
|
||||
#
|
||||
# On success, it sets the OPENMP_CFLAGS/OPENMP_CXXFLAGS/OPENMP_F77FLAGS
|
||||
# output variable to the flag (e.g. -omp) used both to compile *and* link
|
||||
# OpenMP programs in the current language.
|
||||
#
|
||||
# NOTE: You are assumed to not only compile your program with these flags,
|
||||
# but also link it with them as well.
|
||||
#
|
||||
# If you want to compile everything with OpenMP, you should set:
|
||||
#
|
||||
# CFLAGS="$CFLAGS $OPENMP_CFLAGS"
|
||||
# #OR# CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
|
||||
# #OR# FFLAGS="$FFLAGS $OPENMP_FFLAGS"
|
||||
#
|
||||
# (depending on the selected language).
|
||||
#
|
||||
# The user can override the default choice by setting the corresponding
|
||||
# environment variable (e.g. OPENMP_CFLAGS).
|
||||
#
|
||||
# ACTION-IF-FOUND is a list of shell commands to run if an OpenMP flag is
|
||||
# found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is
|
||||
# not found. If ACTION-IF-FOUND is not specified, the default action will
|
||||
# define HAVE_OPENMP.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
|
||||
# Copyright (c) 2015 John W. Peterson <jwpeterson@gmail.com>
|
||||
#
|
||||
# This program 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 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 11
|
||||
|
||||
AC_DEFUN([AX_OPENMP], [
|
||||
AC_PREREQ([2.69]) dnl for _AC_LANG_PREFIX
|
||||
|
||||
AC_CACHE_CHECK([for OpenMP flag of _AC_LANG compiler], ax_cv_[]_AC_LANG_ABBREV[]_openmp, [save[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
ax_cv_[]_AC_LANG_ABBREV[]_openmp=unknown
|
||||
# Flags to try: -fopenmp (gcc), -openmp (icc), -mp (SGI & PGI),
|
||||
# -xopenmp (Sun), -omp (Tru64), -qsmp=omp (AIX), none
|
||||
ax_openmp_flags="-fopenmp -openmp -mp -xopenmp -omp -qsmp=omp none"
|
||||
if test "x$OPENMP_[]_AC_LANG_PREFIX[]FLAGS" != x; then
|
||||
ax_openmp_flags="$OPENMP_[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flags"
|
||||
fi
|
||||
for ax_openmp_flag in $ax_openmp_flags; do
|
||||
case $ax_openmp_flag in
|
||||
none) []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[] ;;
|
||||
*) []_AC_LANG_PREFIX[]FLAGS="$save[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flag" ;;
|
||||
esac
|
||||
AC_LINK_IFELSE([AC_LANG_SOURCE([[
|
||||
@%:@include <omp.h>
|
||||
|
||||
static void
|
||||
parallel_fill(int * data, int n)
|
||||
{
|
||||
int i;
|
||||
@%:@pragma omp parallel for
|
||||
for (i = 0; i < n; ++i)
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int arr[100000];
|
||||
omp_set_num_threads(2);
|
||||
parallel_fill(arr, 100000);
|
||||
return 0;
|
||||
}
|
||||
]])],[ax_cv_[]_AC_LANG_ABBREV[]_openmp=$ax_openmp_flag; break],[])
|
||||
done
|
||||
[]_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[]FLAGS
|
||||
])
|
||||
if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" = "xunknown"; then
|
||||
m4_default([$2],:)
|
||||
else
|
||||
if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" != "xnone"; then
|
||||
OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ax_cv_[]_AC_LANG_ABBREV[]_openmp
|
||||
fi
|
||||
m4_default([$1], [AC_DEFINE(HAVE_OPENMP,1,[Define if OpenMP is enabled])])
|
||||
fi
|
||||
])dnl AX_OPENMP
|
|
@ -33,6 +33,9 @@
|
|||
/* Define if you have freetype */
|
||||
#cmakedefine HAVE_LIBFREETYPE
|
||||
|
||||
/* Define if you have liq */
|
||||
#cmakedefine HAVE_LIBIMAGEQUANT
|
||||
|
||||
/* Define if you have jpeg */
|
||||
#cmakedefine HAVE_LIBJPEG
|
||||
|
||||
|
@ -60,6 +63,9 @@
|
|||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#cmakedefine HAVE_MEMORY_H
|
||||
|
||||
/* Define if OpenMP is enabled */
|
||||
#cmakedefine HAVE_OPENMP
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#cmakedefine HAVE_PTHREAD
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#ifdef HAVE_LIBIMAGEQUANT_H
|
||||
#include <libimagequant.h> /* if this fails then set -DENABLE_LIQ=NO in cmake or make static libimagequant.a in libimagequant/ */
|
||||
#ifdef HAVE_LIBIMAGEQUANT
|
||||
#include <libimagequant.h>
|
||||
#endif
|
||||
|
||||
/* (Re)define some defines known by libjpeg */
|
||||
|
@ -1375,7 +1375,7 @@ zeroHistogram (hist3d histogram)
|
|||
*/
|
||||
BGD_DECLARE(int) gdImageTrueColorToPaletteSetMethod (gdImagePtr im, int method, int speed)
|
||||
{
|
||||
#ifndef HAVE_LIBIMAGEQUANT_H
|
||||
#ifndef HAVE_LIBIMAGEQUANT
|
||||
if (method == GD_QUANT_LIQ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -1424,7 +1424,7 @@ BGD_DECLARE(int) gdImageTrueColorToPalette (gdImagePtr im, int dither, int color
|
|||
return gdImageTrueColorToPaletteBody(im, dither, colorsWanted, 0);
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBIMAGEQUANT_H
|
||||
#ifdef HAVE_LIBIMAGEQUANT
|
||||
/**
|
||||
LIQ library needs pixels in RGBA order with alpha 0-255 (opaque 255).
|
||||
This callback is run whenever source rows need to be converted from GD's format.
|
||||
|
@ -1532,7 +1532,7 @@ static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colors
|
|||
}
|
||||
|
||||
|
||||
#ifdef HAVE_LIBIMAGEQUANT_H
|
||||
#ifdef HAVE_LIBIMAGEQUANT
|
||||
if (oim->paletteQuantizationMethod == GD_QUANT_DEFAULT ||
|
||||
oim->paletteQuantizationMethod == GD_QUANT_LIQ) {
|
||||
liq_attr *attr = liq_attr_create_with_allocator(gdMalloc, gdFree);
|
||||
|
|
Loading…
Reference in New Issue