Commit bae6b4aa authored by Andreas Tille's avatar Andreas Tille

Imported Upstream version 2.3.0

parent e194018e
version 2.3
-----------
- added ./configure script for better support of Intel C compiler and dependencies [thanks to pdknsk]
- tweaked quality metric to better estimate quality of images with large solid backgrounds [thanks to Rolf Timmermans]
version 2.2
-----------
- preserving of unknown PNG chunks (enables optimized Android 9-patch images)
- improved color profile support: cHRM & gAMA as alternative to ICC profiles, OpenMP acceleration
- improved support for Intel C Compiler, speedup in 32-bit GCC, and some workarounds for Visual Studio's incomplete C support
version 2.1
-----------
- option to save files only if they're compressed better than the original
- option to generate posterized output (for use with 16-bit textures)
- improved support for custom memory allocators and fixed compatibility with 32-bit CPUs using SSE
- support for ICC profiles via Little CMS library
version 2.0
-----------
......
......@@ -5,11 +5,9 @@ Greg Roelofs hacked it into a (in his words) "slightly cheesy" 'pamquant' back
in 1997 (see http://pobox.com/~newt/greg_rgba.html) and finally he ripped out
the cheesy file-I/O parts and replaced them with nice PNG code in December
2000. The PNG reading and writing code is a merged and slightly simplified
version of readpng, readpng2, and writepng from his book:
"PNG: The Definitive Guide."
Pngquant therefore inherits both licenses, one for each source file.
version of readpng, readpng2, and writepng from his book "PNG: The Definitive
Guide."
In 2014 Greg has relicensed the code under the simplified BSD license.
Note that both licenses are basically BSD-like; that is, use the code however
you like, as long as you acknowledge its origins.
......@@ -18,10 +16,7 @@ you like, as long as you acknowledge its origins.
pngquant.c:
Copyright (C) 1989, 1991 by Jef Poskanzer.
Copyright (C) 1997, 2000, 2002 by Greg Roelofs; based on an idea by
Stefan Schneider.
Copyright 2009-2013 by Kornel Lesinski.
© 1989, 1991 by Jef Poskanzer.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
......@@ -32,29 +27,30 @@ pngquant.c:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rwpng.c (and rwpng.h):
pngquant.c and rwpng.c/h:
Copyright (c) 1998-2002 Greg Roelofs. All rights reserved.
© 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
© 2009-2014 by Kornel Lesiński.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
All rights reserved.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, disclaimer, and this list of conditions in the documenta-
tion and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive Guide,"
published by O'Reilly and Associates.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
......@@ -9,35 +9,47 @@ to install it system-wide:
$ sudo make install
By default it will be installed in /usr/local/bin. To install it in another
directory set PREFIX or DESTDIR environmental variables.
directory run `./configure --prefix=dir && make`.
pngquant uses GNU Makefile. To compile on FreeBSD you will need to use gmake,
and on Windows the MinGW compiler (MSVC does not support C99).
pngquant will compile with libpng 1.2, but you should use 1.5 or later.
##Compilation with OpenMP
$ make openmp
$ ./configure --with-openmp && make
This makes pngquant faster in wall-clock time on multicore machines when one
image at a time is processed.
However, it significantly increases total CPU time used, and thus it's not
recommended for server-side and parallelized batch jobs which run many pngquant
However, it increases total CPU time used, and thus it's not most optimal
for server-side and parallelized batch jobs which run many pngquant
instances at a time.
On OS X you may need to install gcc and add `CC=gcc-4.9` to `./configure`,
because clang doesn't support OpenMP (yet).
##Compilation without Cocoa image reader
##Compilation with Cocoa image reader
Mac OS X version uses Cocoa to read images. This adds support for color profiles
and other image formats as input. `./configure --without-cocoa` switches back
to libpng.
$ USE_COCOA=1 make
On Mac OS X pngquant can use Cocoa framework to load images. This enables
support for color profiles and other input file formats.
##Compilation with Little CMS 2
$ ./configure --with-lcms2 && make
Enables support for ICC v2/v4 color profiles when reading images.
Requires Little CMS library available via `pgk-config` (e.g. install `liblcms2-dev`).
##Compilation of `libimagequant.a` only
If you want to use pngquant's conversion algorithm without loading/saving PNG
files, then you can run make in the `lib/` directory.
files, then you can run `make` in the `lib/` directory.
The library doesn't need libpng or zlib.
# Makefile for pngquant
VERSION = $(shell grep 'define PNGQUANT_VERSION' pngquant.c | grep -Eo '[12]\.[0-9.]*')
# This changes default "cc" to "gcc", but still allows customization of the CC variable
# if this line causes problems with non-GNU make, just remove it:
CC := $(patsubst cc,gcc,$(CC))
-include config.mk
BIN ?= pngquant
PREFIX ?= /usr/local
BINPREFIX = $(PREFIX)/bin
# Alternatively, build libpng and zlib in these directories:
CUSTOMLIBPNG ?= ../libpng
CUSTOMZLIB ?= ../zlib
CFLAGSOPT ?= -DNDEBUG -O3 -ffast-math -funroll-loops -fomit-frame-pointer
CFLAGS ?= -Wall -Wno-unknown-pragmas -I. -I/usr/local/include/ -I/usr/include/ $(CFLAGSOPT)
CFLAGS += -std=c99 $(CFLAGSADD)
LDFLAGS ?= -L/usr/local/lib/ -L/usr/lib/
ifneq "$(wildcard $(CUSTOMZLIB))" ""
LDFLAGS += -L$(CUSTOMZLIB) -L$(CUSTOMZLIB)/lib
CFLAGS += -I$(CUSTOMZLIB) -I$(CUSTOMZLIB)/include
endif
ifneq "$(wildcard $(CUSTOMLIBPNG))" ""
LDFLAGS += -L$(CUSTOMLIBPNG) -L$(CUSTOMLIBPNG)/lib
CFLAGS += -I$(CUSTOMLIBPNG) -I$(CUSTOMLIBPNG)/include
else ifneq "$(wildcard /usr/local/include/png.h)" ""
else ifneq "$(wildcard /opt/local/include/libpng15)" ""
LDFLAGS += -L/opt/local/lib
CFLAGS += -I/opt/local/include/libpng15
else ifneq "$(wildcard /opt/X11/include/libpng15/)" ""
LDFLAGS += -L/opt/X11/lib
CFLAGS += -I/opt/X11/include/libpng15/
OBJS = pngquant.o rwpng.o
COCOA_OBJS = rwpng_cocoa.o
else ifneq "$(wildcard /usr/X11/lib/)" ""
LDFLAGS += -L/usr/X11/lib/
CFLAGS += -I/usr/X11/include/
ifeq (1, $(COCOA_READER))
OBJS += $(COCOA_OBJS)
endif
LDFLAGS += -lpng -lz -lm lib/libimagequant.a -lm $(LDFLAGSADD)
STATICLIB = lib/libimagequant.a
OBJS = pngquant.o rwpng.o
COCOA_OBJS = rwpng_cocoa.o
DISTLIBFILES = lib/*.[ch] lib/Makefile lib/COPYRIGHT lib/MANUAL.md
DISTFILES = $(OBJS:.o=.c) *.[hm] pngquant.1 Makefile README.md INSTALL CHANGELOG COPYRIGHT
DISTFILES = *.[chm] pngquant.1 Makefile configure README.md INSTALL CHANGELOG COPYRIGHT
TARNAME = pngquant-$(VERSION)
TARFILE = $(TARNAME)-src.tar.bz2
ifdef USE_COCOA
CFLAGS += -mmacosx-version-min=10.6 -DUSE_COCOA=1
LDLAGS += -mmacosx-version-min=10.6
OBJS += $(COCOA_OBJS)
FRAMEWORKS += -framework Cocoa
endif
LIBDISTFILES = lib/*.[ch] lib/COPYRIGHT lib/MANUAL.md lib/configure lib/Makefile
BUILD_CONFIGURATION="$(CC) $(CFLAGS) $(LDFLAGS)"
DLL=libimagequant.dll
DLLIMP=libimagequant_dll.a
DLLDEF=libimagequant_dll.def
all: $(BIN)
lib/libimagequant.a::
$(STATICLIB):: config.mk
$(MAKE) -C lib static
openmp::
$(MAKE) CFLAGSADD="$(CFLAGSADD) -fopenmp" OPENMPFLAGS="-Bstatic -lgomp" -j8 $(MKFLAGS)
$(BIN): $(OBJS) lib/libimagequant.a
$(CC) $(OBJS) $(LDFLAGS) $(OPENMPFLAGS) $(FRAMEWORKS) -o $@
$(OBJS): $(wildcard *.h) config.mk
rwpng_cocoa.o: rwpng_cocoa.m
clang -c $(CFLAGS) -o $@ $<
$(OBJS): rwpng.h build_configuration
install: $(BIN)
install -m 0755 -p $(BIN) $(DESTDIR)$(BINPREFIX)/$(BIN)
$(CC) -Wno-enum-conversion -c $(CFLAGS) -o $@ $< || clang -Wno-enum-conversion -c -O3 -o $@ $<
uninstall:
rm -f $(DESTDIR)$(BINPREFIX)/$(BIN)
$(BIN): $(STATICLIB) $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@
dist: $(TARFILE)
......@@ -91,17 +41,27 @@ $(TARFILE): $(DISTFILES)
rm -rf $(TARFILE) $(TARNAME)
mkdir -p $(TARNAME)/lib
cp $(DISTFILES) $(TARNAME)
cp $(DISTLIBFILES) $(TARNAME)/lib
cp $(LIBDISTFILES) $(TARNAME)/lib
tar -cjf $(TARFILE) --numeric-owner --exclude='._*' $(TARNAME)
rm -rf $(TARNAME)
shasum $(TARFILE)
-shasum $(TARFILE)
install: $(BIN)
install -m 0755 -p $(BIN) $(BINPREFIX)/$(BIN)
uninstall:
rm -f $(BINPREFIX)/$(BIN)
clean:
rm -f $(BIN) $(OBJS) $(COCOA_OBJS) $(TARFILE) build_configuration
$(MAKE) -C lib clean
rm -f $(BIN) $(OBJS) $(COCOA_OBJS) $(STATICLIB) $(TARFILE)
distclean: clean
rm -f config.mk
build_configuration::
@test -f build_configuration && test $(BUILD_CONFIGURATION) = "`cat build_configuration`" || echo > build_configuration $(BUILD_CONFIGURATION)
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
config.mk:
./configure
endif
.PHONY: all openmp install uninstall dist clean
.PHONY: all clean dist distclean dll install uninstall
.DELETE_ON_ERROR:
......@@ -57,6 +57,10 @@ See `pngquant -h` for full list.
Set custom extension (suffix) for output filename. By default `-or8.png` or `-fs8.png` is used. If you use `--ext=.png --force` options pngquant will overwrite input files in place (use with caution).
###`--skip-if-larger`
Don't write converted files if the conversion isn't worth it.
###`--speed N`
Speed/quality trade-off from 1 (brute-force) to 11 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default. Speed 11 disables dithering and lowers compression level.
......@@ -65,9 +69,13 @@ Speed/quality trade-off from 1 (brute-force) to 11 (fastest). The default is 3.
Disables Floyd-Steinberg dithering.
###`--iebug`
###`--floyd=0.5`
Controls level of dithering (0 = none, 1 = full).
###`--posterize bits`
Workaround for IE6, which only displays fully opaque pixels. pngquant will make almost-opaque pixels fully opaque and will avoid creating new transparent colors.
Reduce precision of the palette by number of bits. Use when the image will be displayed on low-depth screens (e.g. 16-bit displays or compressed textures).
###`--version`
......
This diff is collapsed.
© 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
© 2009-2014 by Kornel Lesiński.
© 2009-2013 by Kornel Lesiński.
Copyright (C) 1989, 1991 by Jef Poskanzer.
Copyright (C) 1997, 2000, 2002 by Greg Roelofs; based on an idea by Stefan Schneider.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
© 1989, 1991 by Jef Poskanzer.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
......
......@@ -5,7 +5,7 @@ It's powering [pngquant2](http://pngquant.org).
## License
[BSD-like](https://raw.github.com/pornel/improved-pngquant/master/lib/COPYRIGHT).
[BSD](https://raw.github.com/pornel/improved-pngquant/master/lib/COPYRIGHT).
It can be linked with both free and closed-source software.
## Download
......@@ -34,11 +34,10 @@ Alternatively you can compile the library with your program simply by including
### Compiling on Windows/Visual Studio
The library can be compiled with any C compiler that has at least basic support for C99 (GCC, clang, ICC, C++ Builder, even Tiny C Compiler), but Visual Studio 2012 and older are not up to date with the 1999 C standard. There are 3 options for using `libimagequant` with Visual Studio:
The library can be compiled with any C compiler that has at least basic support for C99 (GCC, clang, ICC, C++ Builder, even Tiny C Compiler), but Visual Studio 2012 and older are not up to date with the 1999 C standard. There are 2 options for using `libimagequant` on Windows:
* Use Visual Studio **2013** (MSVC12) or newer.
* Or use GCC from [MinGW](http://www.mingw.org). Use GCC to build `libimagequant.a` (using above instructions for Unix) and add it along with `libgcc.a` (shipped with the MinGW compiler) to your VC project.
* Or use [C++ version of `libimagequant`](https://github.com/pornel/pngquant/tree/cpp). The C++ version is not as up-to-date as C version, but should be compatible with Visual Studio older than 2013 (VC12).
* Use Visual Studio **2013** (MSVC 18) and an [MSVC-compatible branch of the library](https://github.com/pornel/pngquant/tree/msvc/lib)
* Or use GCC from [MinGW](http://www.mingw.org). Use GCC to build `libimagequant.a` (using the instructions above for Unix) and add it along with `libgcc.a` (shipped with the MinGW compiler) to your VC project.
## Overview
......@@ -85,7 +84,7 @@ There are 3 ways to create image object for quantization:
Returns object that will hold initial settings (attributes) for the library. The object should be freed using `liq_attr_destroy()` after it's no longer needed.
Returns `NULL` in the unlikely case that the library cannot run on the current machine (e.g. the library has been compiled for SSE2-capable x86 CPU and run on VIA C3 CPU).
Returns `NULL` in the unlikely case that the library cannot run on the current machine (e.g. the library has been compiled for SSE-capable x86 CPU and run on VIA C3 CPU).
----
......@@ -111,7 +110,7 @@ Quantization will attempt to use the lowest number of colors needed to achieve `
If it's not possible to convert the image with at least `minimum` quality (i.e. 256 colors is not enough to meet the minimum quality), then `liq_quantize_image()` will fail. The default minumum is `0` (proceeds regardless of quality).
Quality measures how well generated palette fits image given to `liq_quantize_image()`. If a different image is remapped with `liq_write_remapped_image()` then actual quality may be different.
Quality measures how well the generated palette fits image given to `liq_quantize_image()`. If a different image is remapped with `liq_write_remapped_image()` then actual quality may be different.
Regardless of the quality settings the number of colors won't exceed the maximum (see `liq_set_max_colors()`).
......@@ -123,9 +122,15 @@ Returns `LIQ_INVALID_POINTER` if `attr` appears to be invalid.
----
liq_error liq_set_quality(liq_attr* attr, int* minimum, int* maximum);
int liq_get_min_quality(liq_attr* attr);
Returns the quality set by `liq_set_quality()` in `* minimum` and `* maximum`. Returns `LIQ_INVALID_POINTER` if any of the pointers is `NULL`.
Returns the lower bound set by `liq_set_quality()`.
----
int liq_get_max_quality(liq_attr* attr);
Returns the upper bound set by `liq_set_quality()`.
----
......@@ -189,7 +194,7 @@ Returns `LIQ_VALUE_OUT_OF_RANGE` if the dithering level is outside the 0-1 range
liq_error liq_write_remapped_image(liq_result *result, liq_image *input_image, void *buffer, size_t buffer_size);
Remaps the image to palette and writes it to the given buffer, 1 pixel per byte. Buffer must be large enough to fit entire image (at least width×height bytes). For safety, pass size of the buffer as `buffer_size`.
Remaps the image to palette and writes its pixels to the given buffer, 1 pixel per byte. Buffer must be large enough to fit the entire image, i.e. width×height bytes large. For safety, pass size of the buffer as `buffer_size`.
For best performance call `liq_get_palette()` *after* this function, as palette is improved during remapping.
......
VERSION=2.0.0
# This changes default "cc" to "gcc", but still allows customization of the CC variable
# if this line causes problems with non-GNU make, just remove it:
CC := $(patsubst cc,gcc,$(CC))
-include config.mk
STATICLIB=libimagequant.a
DLL=libimagequant.dll
DLLIMP=libimagequant_dll.a
DLLDEF=libimagequant_dll.def
CFLAGSOPT ?= -DNDEBUG -O3 -ffast-math -funroll-loops -fomit-frame-pointer
CFLAGS ?= -Wall -Wno-unknown-pragmas -I. $(CFLAGSOPT)
CFLAGS += -std=c99 $(CFLAGSADD)
ifdef USE_SSE
CFLAGS += -msse2 -DUSE_SSE=$(USE_SSE)
endif
OBJS = pam.o mediancut.o blur.o mempool.o viter.o nearest.o libimagequant.o
BUILD_CONFIGURATION="$(CC) $(CFLAGS) $(LDFLAGS)"
DISTFILES = $(OBJS:.o=.c) *.h MANUAL.md COPYRIGHT Makefile
DISTFILES = $(OBJS:.o=.c) *.h MANUAL.md COPYRIGHT Makefile configure
TARNAME = libimagequant-$(VERSION)
TARFILE = $(TARNAME)-src.tar.bz2
......@@ -33,8 +21,6 @@ static: $(STATICLIB)
dll:
$(MAKE) CFLAGSADD="-DLIQ_EXPORT='__declspec(dllexport)'" $(DLL)
openmp::
$(MAKE) CFLAGSADD=-fopenmp OPENMPFLAGS="-Bstatic -lgomp" -j8
$(DLL) $(DLLIMP): $(OBJS)
$(CC) -fPIC -shared -o $(DLL) $(OBJS) $(LDFLAGS) -Wl,--out-implib,$(DLLIMP),--output-def,$(DLLDEF)
......@@ -42,7 +28,7 @@ $(DLL) $(DLLIMP): $(OBJS)
$(STATICLIB): $(OBJS)
$(AR) $(ARFLAGS) $@ $^
$(OBJS): pam.h build_configuration
$(OBJS): $(wildcard *.h) config.mk
dist: $(TARFILE)
......@@ -55,10 +41,15 @@ $(TARFILE): $(DISTFILES)
-shasum $(TARFILE)
clean:
rm -f $(OBJS) $(STATICLIB) $(TARFILE) build_configuration
rm -f $(OBJS) $(STATICLIB) $(TARFILE) $(DLL) $(DLLIMP) $(DLLDEF)
build_configuration::
@test -f build_configuration && test $(BUILD_CONFIGURATION) = "`cat build_configuration`" || echo > build_configuration $(BUILD_CONFIGURATION)
distclean: clean
rm -f config.mk
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
config.mk:
./configure
endif
.PHONY: all openmp static clean dist dll
.PHONY: all static clean dist distclean dll
.DELETE_ON_ERROR:
......@@ -46,7 +46,7 @@ static void transposing_1d_blur(unsigned char *restrict src, unsigned char *rest
/**
* Picks maximum of neighboring pixels (blur + lighten)
*/
LIQ_PRIVATE void max3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height)
LIQ_PRIVATE void liq_max3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height)
{
for(unsigned int j=0; j < height; j++) {
const unsigned char *row = src + j*width,
......@@ -73,7 +73,7 @@ LIQ_PRIVATE void max3(unsigned char *src, unsigned char *dst, unsigned int width
/**
* Picks minimum of neighboring pixels (blur + darken)
*/
LIQ_PRIVATE void min3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height)
LIQ_PRIVATE void liq_min3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height)
{
for(unsigned int j=0; j < height; j++) {
const unsigned char *row = src + j*width,
......@@ -101,10 +101,12 @@ LIQ_PRIVATE void min3(unsigned char *src, unsigned char *dst, unsigned int width
Filters src image and saves it to dst, overwriting tmp in the process.
Image must be width*height pixels high. Size controls radius of box blur.
*/
LIQ_PRIVATE void blur(unsigned char *src, unsigned char *tmp, unsigned char *dst, unsigned int width, unsigned int height, unsigned int size)
LIQ_PRIVATE void liq_blur(unsigned char *src, unsigned char *tmp, unsigned char *dst, unsigned int width, unsigned int height, unsigned int size)
{
assert(size > 0);
if (width < 2*size+1 || height < 2*size+1) return;
if (width < 2*size+1 || height < 2*size+1) {
return;
}
transposing_1d_blur(src, tmp, width, height, size);
transposing_1d_blur(tmp, dst, height, width, size);
}
LIQ_PRIVATE void blur(unsigned char *src, unsigned char *tmp, unsigned char *dst, unsigned int width, unsigned int height, unsigned int size);
LIQ_PRIVATE void max3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height);
LIQ_PRIVATE void min3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height);
LIQ_PRIVATE void liq_blur(unsigned char *src, unsigned char *tmp, unsigned char *dst, unsigned int width, unsigned int height, unsigned int size);
LIQ_PRIVATE void liq_max3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height);
LIQ_PRIVATE void liq_min3(unsigned char *src, unsigned char *dst, unsigned int width, unsigned int height);
#!/usr/bin/env bash
CONFIG="config.mk"
PREFIX="/usr/local"
VERSION=$(grep "define PNGQUANT_VERSION" ../pngquant.c | grep -Eo "[12]\.[0-9.]+")
DEBUG=
SSE=auto
OPENMP=
EXTRA_CFLAGS=
EXTRA_LDFLAGS=
# make gcc default compiler unless CC is already set
CC=${CC:-gcc}
help() {
printf "%4s %s\n" "" "$1"
}
for i in "$@"; do
case $i in
--help)
echo
help "--prefix= installation directory [$PREFIX]"
help "--extra-cflags= append to CFLAGS"
help "--extra-ldflags= append to LDFLAGS"
echo
help "--enable-debug"
help "--enable-sse/--disable-sse enable/disable SSE instructions"
echo
help "--with-openmp compile with multicore support"
echo
exit 0
;;
# Can be set before or after configure. Latter overrides former.
CC=*)
CC=${i#*=}
;;
CFLAGS=*)
CFLAGS=${i#*=}
;;
LDFLAGS=*)
LDFLAGS=${i#*=}
;;
--enable-debug)
DEBUG=1
;;
--enable-sse)
SSE=1
;;
--disable-sse)
SSE=0
;;
--with-openmp)
OPENMP=1
;;
--prefix=*)
PREFIX=${i#*=}
;;
# can be used multiple times or in quotes to set multiple flags
--extra-cflags=*)
EXTRA_CFLAGS="$EXTRA_CFLAGS ${i#*=}"
;;
--extra-ldflags=*)
EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
;;
*)
echo "error: unknown switch ${i%%=*}"
exit 1
;;
esac
done
# If someone runs sudo make install as very first command, and configure later,
# $CONFIG cannot be overwritten, and must be deleted before continuing.
if [[ -f "$CONFIG" && ! -w "$CONFIG" ]]; then
echo "Cannot overwrite file $CONFIG! Please delete it."
exit 1
fi
cflags() {
CFLAGS="$CFLAGS $1"
}
lflags() {
LDFLAGS="$LDFLAGS $1"
}
status() {
printf "%10s: %s\n" "$1" "$2"
}
# Append to CFLAGS if compiler supports flag, with optional prerequisite.
# Fails on errors and warnings.
conditional_cflags() {
if [ -z "$("$CC" -xc -S -o /dev/null $2 $1 <(echo) 2>&1)" ]; then
cflags "$1"
fi
}
error() {
status "$1" "error ... $2"
echo
exit 1
}
echo
# basic check
if ! "$CC" -xc -std=c99 <(echo "int main(){}") -o /dev/null &> /dev/null; then
error "Compiler" "$CC is no C compiler"
fi
status "Compiler" "$CC"
# init flags
CFLAGS=${CFLAGS:--O3 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
cflags "-std=c99 -I."
lflags "-lm lib/libimagequant.a"
# DEBUG
if [ -z "$DEBUG" ]; then
cflags "-DNDEBUG"
status "Debug" "no"
else
cflags "-g"
status "Debug" "yes"
fi
# SSE
if [ "$SSE" = 'auto' ]; then
if [[ "$(uname -m)" =~ (amd|x86_)64 ||
"$(grep -E -m1 "^flags" /proc/cpuinfo)" =~ "sse" ]]; then
SSE=1
fi
fi
if [ "$SSE" -eq 1 ]; then
status "SSE" "yes"
cflags "-DUSE_SSE=1"
cflags "-msse"
# Silence a later ICC warning due to -msse working slightly different.
conditional_cflags "-wd10121"
# Must be set explicitly for GCC on x86_32. Other compilers imply it.
conditional_cflags "-mfpmath=sse" "-msse"
elif [ "$SSE" -eq 0 ]; then
status "SSE" "no"
cflags "-DUSE_SSE=0"
fi
# OpenMP
if [ -n "$OPENMP" ]; then
if [[ "$("$CC" -xc -E -fopenmp <(echo -e \
"#ifdef _OPENMP
#include <omp.h>
#endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
cflags "-fopenmp"
lflags "-fopenmp"
status "OpenMP" "yes"
else
error "OpenMP" "not supported by compiler"
fi
else
# silence warnings about omp pragmas
cflags "-Wno-unknown-pragmas"
conditional_cflags "-wd3180" # ICC
status "OpenMP" "no"
fi
echo
# As of GCC 4.5, 387 fp math is significantly slower in C99 mode without this.
# Note: CPUs without SSE2 use 387 for doubles, even when SSE fp math is set.
conditional_cflags "-fexcess-precision=fast"
# Intel C++ Compiler
# ICC does usually only produce fast(er) code when it can optimize to the full
# capabilites of the (Intel) CPU. This is equivalent to -march=native for GCC.
conditional_cflags "-xHOST"
# Disable unsafe fp optimizations and enforce fp precision as set in the source.
conditional_cflags "-fp-model source"
# Silence a gold linker warning about string misalignment.
conditional_cflags "-falign-stack=maintain-16-byte"
lflags "-lm" # Ubuntu requires this library last, issue #38
if [ -n "$EXTRA_CFLAGS" ]; then
cflags "$EXTRA_CFLAGS"
fi
if [ -n "$EXTRA_LDFLAGS" ]; then
lflags "$EXTRA_LDFLAGS"
fi
# Overwrite previous configuration.
echo "
# auto-generated by configure
PREFIX = $PREFIX
VERSION = $VERSION
CC = $CC
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
" > $CONFIG
This diff is collapsed.
......@@ -37,6 +37,7 @@ typedef struct liq_palette {
typedef enum liq_error {
LIQ_OK = 0,
LIQ_QUALITY_TOO_LOW = 99,
LIQ_VALUE_OUT_OF_RANGE = 100,
LIQ_OUT_OF_MEMORY,
LIQ_NOT_READY,
......@@ -53,15 +54,16 @@ LIQ_EXPORT liq_attr* liq_attr_copy(liq_attr* orig);
LIQ_EXPORT void liq_attr_destroy(liq_attr* attr);
LIQ_EXPORT liq_error liq_set_max_colors(liq_attr* attr, int colors);
LIQ_EXPORT int liq_get_max_colors(liq_attr* attr);
LIQ_EXPORT int liq_get_max_colors(const liq_attr* attr);
LIQ_EXPORT liq_error liq_set_speed(liq_attr* attr, int speed);
LIQ_EXPORT int liq_get_speed(liq_attr* attr);
LIQ_EXPORT int liq_get_speed(const liq_attr* attr);
LIQ_EXPORT liq_error liq_set_min_opacity(liq_attr* attr, int min);
LIQ_EXPORT int liq_get_min_opacity(liq_attr* attr);
LIQ_EXPORT int liq_get_min_opacity(const liq_attr* attr);
LIQ_EXPORT liq_error liq_set_min_posterization(liq_attr* attr, int bits);
LIQ_EXPORT