Upgrading to GitLab 12.1.0.

Commit 313ff529 authored by Andreas Tille's avatar Andreas Tille

Imported Upstream version 2.5.0

parent bae6b4aa
version 2.5
-----------
- replaced color search algorithm with vantage point tree, which is much faster and more reliable
- deprecated IE6 workaround
version 2.4
-----------
- fixed remapping of bright colors when dithering
- added libimagequant API to add fixed preset colors to the palette
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]
- atomic file saves and fixed --skip-if-larger
- avoid applying quality setting to images that use palette already
- preserving standard PNG chunks (requires libpng 1.6)
- deprecated libpng 1.2 support
version 2.2
-----------
......
......@@ -30,7 +30,7 @@ pngquant.c:
pngquant.c and rwpng.c/h:
© 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
© 2009-2014 by Kornel Lesiński.
© 2009-2015 by Kornel Lesiński.
All rights reserved.
......
-include config.mk
BIN ?= pngquant
BINPREFIX = $(PREFIX)/bin
BINPREFIX = $(DESTDIR)$(PREFIX)/bin
OBJS = pngquant.o rwpng.o
COCOA_OBJS = rwpng_cocoa.o
......@@ -24,16 +24,21 @@ DLLDEF=libimagequant_dll.def
all: $(BIN)
$(STATICLIB):: config.mk
staticlib:
$(MAKE) -C lib static
$(STATICLIB): config.mk staticlib
$(OBJS): $(wildcard *.h) config.mk
rwpng_cocoa.o: rwpng_cocoa.m
$(CC) -Wno-enum-conversion -c $(CFLAGS) -o $@ $< || clang -Wno-enum-conversion -c -O3 -o $@ $<
$(CC) -Wno-enum-conversion -c $(CFLAGS) -o $@ $< &> /dev/null || clang -Wno-enum-conversion -c -O3 $(CFLAGS) -o $@ $<
$(BIN): $(OBJS) $(STATICLIB)
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
$(BIN): $(STATICLIB) $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@
test: $(BIN)
./test/test.sh ./test $(BIN)
dist: $(TARFILE)
......@@ -47,21 +52,24 @@ $(TARFILE): $(DISTFILES)
-shasum $(TARFILE)
install: $(BIN)
install -m 0755 -p $(BIN) $(BINPREFIX)/$(BIN)
-mkdir -p '$(BINPREFIX)'
install -m 0755 -p '$(BIN)' '$(BINPREFIX)/$(BIN)'
uninstall:
rm -f $(BINPREFIX)/$(BIN)
rm -f '$(BINPREFIX)/$(BIN)'
clean:
rm -f $(BIN) $(OBJS) $(COCOA_OBJS) $(STATICLIB) $(TARFILE)
$(MAKE) -C lib clean
rm -f '$(BIN)' $(OBJS) $(COCOA_OBJS) $(STATICLIB) $(TARFILE)
distclean: clean
rm -f config.mk
$(MAKE) -C lib distclean
rm -f config.mk pngquant-*-src.tar.bz2
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
config.mk:
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
./configure
endif
.PHONY: all clean dist distclean dll install uninstall
.PHONY: all clean dist distclean dll install uninstall test staticlib
.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).
###`-o out.png` or `--output out.png`
Writes converted file to the given path. When this option is used only single input file is allowed.
###`--skip-if-larger`
Don't write converted files if the conversion isn't worth it.
......@@ -75,7 +79,7 @@ Controls level of dithering (0 = none, 1 = full).
###`--posterize bits`
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).
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 in ARGB444 format).
###`--version`
......
......@@ -2,11 +2,12 @@
CONFIG="config.mk"
PREFIX="/usr/local"
VERSION=$(grep "define PNGQUANT_VERSION" pngquant.c | grep -Eo "[12]\.[0-9.]+")
VERSION=$(grep LIQ_VERSION_STRING lib/libimagequant.h | grep -Eo "2\.[0-9.]+")
DEBUG=
SSE=auto
OPENMP=
LIBPNG_DIR=.
if [[ "$OSTYPE" =~ "darwin" ]]; then
COCOA_READER=auto
LCMS2=0
......@@ -28,17 +29,18 @@ 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"
help "--prefix=<dir> installation directory [$PREFIX]"
help "--extra-cflags=<flags> append to CFLAGS"
help "--extra-ldflags=<flags> append to LDFLAGS"
echo
help "--enable-debug"
help "--enable-sse/--disable-sse enable/disable SSE instructions"
echo
help "--with-openmp compile with multicore support"
help "--with-openmp=static compile with multicore support"
help "--with-lcms2/--without-lcms2 compile with color profile support"
if [[ "$OSTYPE" =~ "darwin" ]]; then
help "--with-cocoa/--without-cocoa use Cocoa framework to read images"
help "--with-libpng=<dir> search for libpng in directory"
fi
echo
help "CC=<compiler> use given compiler command"
......@@ -69,6 +71,9 @@ fi
--with-openmp)
OPENMP=1
;;
--with-openmp=static)
OPENMP=static
;;
--with-lcms2)
LCMS2=1
COCOA_READER=0
......@@ -83,6 +88,9 @@ fi
--without-cocoa)
COCOA_READER=0
;;
--with-libpng=*)
LIBPNG_DIR=${i#*=}
;;
--prefix=*)
PREFIX=${i#*=}
;;
......@@ -122,7 +130,7 @@ status() {
# 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
if [ -z "echo | $("$CC" -xc -S -o /dev/null $2 $1 2>&1)" ]; then
cflags "$1"
fi
}
......@@ -221,8 +229,8 @@ error() {
echo
# basic check
if ! "$CC" -xc -std=c99 <(echo "int main(){}") -o /dev/null &> /dev/null; then
error "Compiler" "$CC is no C compiler"
if ! echo "int main(){}" | "$CC" -xc -std=c99 -o /dev/null - &> /dev/null; then
error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
fi
status "Compiler" "$CC"
......@@ -230,7 +238,6 @@ 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
......@@ -264,12 +271,16 @@ fi
# OpenMP
if [ -n "$OPENMP" ]; then
if [[ "$("$CC" -xc -E -fopenmp <(echo -e \
"#ifdef _OPENMP
if [ "static" = "$OPENMP" ]; then
OPENMPFLAGS="-static-libgcc -Bstatic -fopenmp -Bdynamic"
else
OPENMPFLAGS="-fopenmp"
fi
if [[ "$("$CC" -xc -E $OPENMPFLAGS <(echo "#ifdef _OPENMP
#include <omp.h>
#endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
cflags "-fopenmp"
lflags "-fopenmp"
cflags "$OPENMPFLAGS"
lflags "$OPENMPFLAGS"
status "OpenMP" "yes"
else
error "OpenMP" "not supported by compiler (please install a compiler that supports OpenMP (e.g. gcc) and specify it with the CC= argument)"
......@@ -283,10 +294,10 @@ fi
# Cocoa
if [[ "$OSTYPE" =~ "darwin" ]]; then
cflags "-mmacosx-version-min=10.6.8"
lflags "-mmacosx-version-min=10.6.8"
cflags "-mmacosx-version-min=10.6"
lflags "-mmacosx-version-min=10.6"
if [ "$COCOA_READER" != 0 ]; then
if [ "$COCOA_READER" != 0 ] && "$CC" 2>/dev/null 1>/dev/null -xc -E <(echo "#import <Cocoa/Cocoa.h>"); then
COCOA_READER=1
cflags "-DUSE_COCOA=1"
lflags "-framework Cocoa"
......@@ -296,30 +307,50 @@ if [[ "$OSTYPE" =~ "darwin" ]]; then
fi
fi
# pairs of possible *.h and lib*.so locations
DIRS=("/usr/local/include /usr/local/lib"
"/usr/include /usr/lib"
"/opt/local/include /opt/local/lib" # macports
)
if [[ "$OSTYPE" =~ "darwin" ]]; then
SOLIBSUFFIX=dylib
# Search Developer SDK paths, since Apple seems to have dropped the standard Unixy ones
XCODE_CMD="xcode-select"
XCODE_PATH=$($XCODE_CMD -p)
DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib")
DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib")
else
SOLIBSUFFIX=so
fi
# pairs of possible *.h and lib*.so locations
DIRS=("/usr/local/include /usr/local/lib"
"/usr/include /usr/lib")
# libpng
# try if given flags are enough
SUCCESS=0
# try static in current directory first
PNGH=$(find_h . "png.h")
if [ -n "$PNGH" ]; then
PNGH_STRING=$(pngh_string "$PNGH")
PNGH_MAJMIN=$(pngh_majmin "$PNGH")
if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
LIBPNGA=$(find_f . "libpng${PNGH_MAJMIN}.a")
if [ -n "$LIBPNGA" ]; then
cflags "-I${PNGH%/*}"
lflags "${LIBPNGA}"
status "libpng" "static (${PNGH_STRING})"
SUCCESS=1
if echo "#include \"png.h\"
int main(){
return !png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
}" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then
status "libpng" "custom flags"
SUCCESS=1
fi
if [ "$SUCCESS" -eq 0 ]; then
# try static in the given directory
PNGH=$(find_h "$LIBPNG_DIR" "png.h")
if [ -n "$PNGH" ]; then
PNGH_STRING=$(pngh_string "$PNGH")
PNGH_MAJMIN=$(pngh_majmin "$PNGH")
if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
LIBPNGA=$(find_f "$LIBPNG_DIR" "libpng${PNGH_MAJMIN}.a")
if [ -n "$LIBPNGA" ]; then
cflags "-I${PNGH%/*}"
lflags "${LIBPNGA}"
status "libpng" "static (${PNGH_STRING})"
SUCCESS=1
fi
fi
fi
fi
......@@ -350,11 +381,11 @@ if [ "$SUCCESS" -eq 0 ]; then
fi
if [ "$SUCCESS" -eq 0 ]; then
if [[ "$OSTYPE" =~ "darwin" ]]; then
LIBPNGCOMMAND='`brew install libpng`'
LIBPNG_CMD='`brew install libpng`'
else
LIBPNGCOMMAND='`apt-get install libpng-dev` or `yum install libpng-devel`'
LIBPNG_CMD='`apt-get install libpng-dev` or `yum install libpng-devel`'
fi
error "libpng" "not found (try: $LIBPNGCOMMAND)"
error "libpng" "not found (try: $LIBPNG_CMD)"
fi
# zlib
......
© 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
© 2009-2014 by Kornel Lesiński.
© 2009-2015 by Kornel Lesiński.
All rights reserved.
......
......@@ -5,12 +5,12 @@ It's powering [pngquant2](http://pngquant.org).
## License
[BSD](https://raw.github.com/pornel/improved-pngquant/master/lib/COPYRIGHT).
[BSD](https://raw.github.com/pornel/pngquant/master/lib/COPYRIGHT).
It can be linked with both free and closed-source software.
## Download
The [library](http://pngquant.org/lib) is currently a part of the [pngquant2 project](https://github.com/pornel/improved-pngquant/tree/lib/lib).
The [library](http://pngquant.org/lib) is currently a part of the [pngquant2 project](https://github.com/pornel/pngquant/tree/master/lib).
Files needed for the library are only in the `lib/` directory inside the repository (and you can ignore the rest).
......@@ -49,6 +49,8 @@ The basic flow is:
4. Store remapped image and final palette.
5. Free memory.
Please note that libimagequant only handles raw uncompressed bitmaps in memory and is completely independent of any file format.
<p>
#include "lib/libimagequant.h"
......@@ -76,6 +78,8 @@ There are 3 ways to create image object for quantization:
* `liq_image_create_rgba_rows()` for non-contiguous RGBA bitmaps (that have padding between rows or reverse order, e.g. BMP).
* `liq_image_create_custom()` for RGB, ABGR, YUV and all other formats that can be converted on-the-fly to RGBA (you have to supply the conversion function).
Note that "image" here means raw uncompressed pixels. If you have a compressed image file, such as PNG, you must use another library (e.g. libpng or lodepng) to decode it first.
## Functions
----
......@@ -209,6 +213,8 @@ Returns `LIQ_BUFFER_TOO_SMALL` if given size of the buffer is not enough to fit
See `liq_get_palette()` and `liq_write_remapped_image_rows()`.
Please note that it only writes raw uncompressed pixels to memory. It does not perform any compression. If you'd like to create a PNG file then you need to pass the raw pixel data to another library, e.g. libpng or lodepng. See `rwpng.c` in `pngquant` project for an example how to do that.
----
const liq_palette *liq_get_palette(liq_result *result);
......@@ -262,7 +268,7 @@ Returns the value set by `liq_set_speed()`.
liq_error liq_set_min_opacity(liq_attr* attr, int min);
Alpha values higher than this will be rounded to opaque. This is a workaround for Internet Explorer 6 that truncates semitransparent values to completely transparent. The default is `255` (no change). 238 is a suggested value.
Alpha values higher than this will be rounded to opaque. This is a workaround for Internet Explorer 6, but because this browser is not used any more, this option is deprecated and will be removed. The default is `255` (no change).
Returns `LIQ_VALUE_OUT_OF_RANGE` if the value is outside the 0-255 range.
......@@ -442,6 +448,24 @@ Getters for `width`, `height` and `gamma` of the input image.
If the input is invalid, these all return -1.
---
liq_error liq_image_add_fixed_color(liq_image* img, liq_color color);
Reserves a color in the output palette created from this image. It behaves as if the given color was used in the image and was very important.
RGB values of `liq_color` are assumed to have the same gamma as the image.
It must be called before the image is quantized.
Returns error if more than 256 colors are added. If image is quantized to fewer colors than the number of fixed colors added, then excess fixed colors will be ignored.
---
int liq_version();
Returns version of the library as an integer. Same as `LIQ_VERSION`. Human-readable version is defined as `LIQ_VERSION_STRING`.
## Multithreading
The library is stateless and doesn't use any global or thread-local storage. It doesn't use any locks.
......
-include config.mk
STATICLIB=libimagequant.a
SHAREDLIB=libimagequant.so.0
DLL=libimagequant.dll
DLLIMP=libimagequant_dll.a
DLLDEF=libimagequant_dll.def
OBJS = pam.o mediancut.o blur.o mempool.o viter.o nearest.o libimagequant.o
SHAREDOBJS = $(subst .o,.lo,$(OBJS))
BUILD_CONFIGURATION="$(CC) $(CFLAGS) $(LDFLAGS)"
......@@ -14,20 +16,28 @@ DISTFILES = $(OBJS:.o=.c) *.h MANUAL.md COPYRIGHT Makefile configure
TARNAME = libimagequant-$(VERSION)
TARFILE = $(TARNAME)-src.tar.bz2
all: static
all: static shared
static: $(STATICLIB)
shared: $(SHAREDLIB)
dll:
$(MAKE) CFLAGSADD="-DLIQ_EXPORT='__declspec(dllexport)'" $(DLL)
$(DLL) $(DLLIMP): $(OBJS)
$(CC) -fPIC -shared -o $(DLL) $(OBJS) $(LDFLAGS) -Wl,--out-implib,$(DLLIMP),--output-def,$(DLLDEF)
$(CC) -fPIC -shared -o $(DLL) $^ $(LDFLAGS) -Wl,--out-implib,$(DLLIMP),--output-def,$(DLLDEF)
$(STATICLIB): $(OBJS)
$(AR) $(ARFLAGS) $@ $^
$(SHAREDOBJS):
$(CC) -fPIC $(CFLAGS) -c $(@:.lo=.c) -o $@
$(SHAREDLIB): $(SHAREDOBJS)
$(CC) -shared -o $@ $^ $(LDFLAGS)
$(OBJS): $(wildcard *.h) config.mk
dist: $(TARFILE)
......@@ -41,15 +51,15 @@ $(TARFILE): $(DISTFILES)
-shasum $(TARFILE)
clean:
rm -f $(OBJS) $(STATICLIB) $(TARFILE) $(DLL) $(DLLIMP) $(DLLDEF)
rm -f $(OBJS) $(SHAREDOBJS) $(SHAREDLIB) $(STATICLIB) $(TARFILE) $(DLL) $(DLLIMP) $(DLLDEF)
distclean: clean
rm -f config.mk
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
config.mk:
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
./configure
endif
.PHONY: all static clean dist distclean dll
.PHONY: all static shared clean dist distclean dll
.DELETE_ON_ERROR:
/*
** © 2011-2015 by Kornel Lesiński.
** All rights reserved.
** See COPYRIGHT file for full license.
*/
#include "libimagequant.h"
#include "pam.h"
......@@ -8,6 +13,8 @@
*/
static void transposing_1d_blur(unsigned char *restrict src, unsigned char *restrict dst, unsigned int width, unsigned int height, const unsigned int size)
{
assert(size > 0);
for(unsigned int j=0; j < height; j++) {
unsigned char *restrict row = src + j*width;
......
......@@ -2,7 +2,7 @@
CONFIG="config.mk"
PREFIX="/usr/local"
VERSION=$(grep "define PNGQUANT_VERSION" ../pngquant.c | grep -Eo "[12]\.[0-9.]+")
VERSION=$(grep LIQ_VERSION_STRING libimagequant.h | grep -Eo "2\.[0-9.]+")
DEBUG=
SSE=auto
......@@ -116,7 +116,6 @@ 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
......
This diff is collapsed.
......@@ -8,11 +8,19 @@
#ifndef LIQ_EXPORT
#define LIQ_EXPORT extern
#endif
#define LIQ_VERSION 20500
#define LIQ_VERSION_STRING "2.5.0"
#ifndef LIQ_PRIVATE
#if defined(__GNUC__) || defined (__llvm__)
#define LIQ_PRIVATE __attribute__((visibility("hidden")))
#define LIQ_NONNULL __attribute__((nonnull))
#define LIQ_USERESULT __attribute__((warn_unused_result))
#else
#define LIQ_PRIVATE
#define LIQ_NONNULL
#define LIQ_USERESULT
#endif
#endif
......@@ -48,55 +56,56 @@ typedef enum liq_error {
enum liq_ownership {LIQ_OWN_ROWS=4, LIQ_OWN_PIXELS=8};
LIQ_EXPORT liq_attr* liq_attr_create(void);
LIQ_EXPORT liq_attr* liq_attr_create_with_allocator(void* (*malloc)(size_t), void (*free)(void*));
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(const liq_attr* attr);
LIQ_EXPORT liq_error liq_set_speed(liq_attr* attr, int speed);
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(const liq_attr* attr);
LIQ_EXPORT liq_error liq_set_min_posterization(liq_attr* attr, int bits);
LIQ_EXPORT int liq_get_min_posterization(const liq_attr* attr);
LIQ_EXPORT liq_error liq_set_quality(liq_attr* attr, int minimum, int maximum);
LIQ_EXPORT int liq_get_min_quality(const liq_attr* attr);
LIQ_EXPORT int liq_get_max_quality(const liq_attr* attr);
LIQ_EXPORT void liq_set_last_index_transparent(liq_attr* attr, int is_last);
typedef void liq_log_callback_function(const liq_attr*, const char* message, void* user_info);
LIQ_EXPORT LIQ_USERESULT liq_attr* liq_attr_create(void);
LIQ_EXPORT LIQ_USERESULT liq_attr* liq_attr_create_with_allocator(void* (*malloc)(size_t), void (*free)(void*));
LIQ_EXPORT LIQ_USERESULT liq_attr* liq_attr_copy(liq_attr *orig) LIQ_NONNULL;
LIQ_EXPORT void liq_attr_destroy(liq_attr *attr) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_max_colors(liq_attr* attr, int colors) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_get_max_colors(const liq_attr* attr) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_speed(liq_attr* attr, int speed) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_get_speed(const liq_attr* attr) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_min_opacity(liq_attr* attr, int min) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_get_min_opacity(const liq_attr* attr) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_min_posterization(liq_attr* attr, int bits) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_get_min_posterization(const liq_attr* attr) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_quality(liq_attr* attr, int minimum, int maximum) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_get_min_quality(const liq_attr* attr) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_get_max_quality(const liq_attr* attr) LIQ_NONNULL;
LIQ_EXPORT void liq_set_last_index_transparent(liq_attr* attr, int is_last) LIQ_NONNULL;
typedef void liq_log_callback_function(const liq_attr*, const char *message, void* user_info);
typedef void liq_log_flush_callback_function(const liq_attr*, void* user_info);
LIQ_EXPORT void liq_set_log_callback(liq_attr*, liq_log_callback_function*, void* user_info);
LIQ_EXPORT void liq_set_log_flush_callback(liq_attr*, liq_log_flush_callback_function*, void* user_info);
LIQ_EXPORT liq_image* liq_image_create_rgba_rows(liq_attr* attr, void* rows[], int width, int height, double gamma);
LIQ_EXPORT liq_image* liq_image_create_rgba(liq_attr* attr, void* bitmap, int width, int height, double gamma);
LIQ_EXPORT LIQ_USERESULT liq_image *liq_image_create_rgba_rows(liq_attr *attr, void* rows[], int width, int height, double gamma) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT liq_image *liq_image_create_rgba(liq_attr *attr, void* bitmap, int width, int height, double gamma) LIQ_NONNULL;
typedef void liq_image_get_rgba_row_callback(liq_color row_out[], int row, int width, void* user_info);
LIQ_EXPORT liq_image* liq_image_create_custom(liq_attr* attr, liq_image_get_rgba_row_callback* row_callback, void* user_info, int width, int height, double gamma);
LIQ_EXPORT LIQ_USERESULT liq_image *liq_image_create_custom(liq_attr *attr, liq_image_get_rgba_row_callback *row_callback, void* user_info, int width, int height, double gamma);
LIQ_EXPORT liq_error liq_image_set_memory_ownership(liq_image* image, int ownership_flags);
LIQ_EXPORT int liq_image_get_width(const liq_image* img);
LIQ_EXPORT int liq_image_get_height(const liq_image* img);
LIQ_EXPORT void liq_image_destroy(liq_image* img);
LIQ_EXPORT liq_error liq_image_set_memory_ownership(liq_image *image, int ownership_flags) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_image_add_fixed_color(liq_image *img, liq_color color) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_image_get_width(const liq_image *img) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT int liq_image_get_height(const liq_image *img) LIQ_NONNULL;
LIQ_EXPORT void liq_image_destroy(liq_image *img) LIQ_NONNULL;
LIQ_EXPORT liq_result* liq_quantize_image(liq_attr* options, liq_image* input_image);
LIQ_EXPORT LIQ_USERESULT liq_result *liq_quantize_image(liq_attr *options, liq_image *input_image) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_dithering_level(liq_result* res, float dither_level);
LIQ_EXPORT liq_error liq_set_output_gamma(liq_result* res, double gamma);
LIQ_EXPORT double liq_get_output_gamma(const liq_result* result);
LIQ_EXPORT liq_error liq_set_dithering_level(liq_result *res, float dither_level) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_set_output_gamma(liq_result* res, double gamma) LIQ_NONNULL;
LIQ_EXPORT LIQ_USERESULT double liq_get_output_gamma(const liq_result *result) LIQ_NONNULL;
LIQ_EXPORT const liq_palette* liq_get_palette(liq_result* result);
LIQ_EXPORT LIQ_USERESULT const liq_palette *liq_get_palette(liq_result *result) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_write_remapped_image(liq_result* result, liq_image* input_image, void* buffer, size_t buffer_size);
LIQ_EXPORT liq_error liq_write_remapped_image_rows(liq_result* result, liq_image* input_image, unsigned char** row_pointers);
LIQ_EXPORT liq_error liq_write_remapped_image(liq_result *result, liq_image *input_image, void *buffer, size_t buffer_size) LIQ_NONNULL;
LIQ_EXPORT liq_error liq_write_remapped_image_rows(liq_result *result, liq_image *input_image, unsigned char **row_pointers) LIQ_NONNULL;
LIQ_EXPORT double liq_get_quantization_error(liq_result* result);
LIQ_EXPORT int liq_get_quantization_quality(liq_result* result);
LIQ_EXPORT double liq_get_quantization_error(liq_result *result) LIQ_NONNULL;
LIQ_EXPORT int liq_get_quantization_quality(liq_result *result) LIQ_NONNULL;
LIQ_EXPORT void liq_result_destroy(liq_result*);
LIQ_EXPORT void liq_result_destroy(liq_result *) LIQ_NONNULL;
#ifdef __cplusplus
}
......
......@@ -2,7 +2,7 @@
** Copyright (C) 1989, 1991 by Jef Poskanzer.
** Copyright (C) 1997, 2000, 2002 by Greg Roelofs; based on an idea by
** Stefan Schneider.
** © 2009-2013 by Kornel Lesinski.
** © 2009-2015 by Kornel Lesinski.
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
......@@ -21,7 +21,7 @@
#define index_of_channel(ch) (offsetof(f_pixel,ch)/sizeof(float))
static f_pixel averagepixels(unsigned int clrs, const hist_item achv[], float min_opaque_val, const f_pixel center);
static f_pixel averagepixels(unsigned int clrs, const hist_item achv[], const f_pixel center);
struct box {
f_pixel color;
......@@ -228,7 +228,7 @@ static f_pixel get_median(const struct box *b, hist_item achv[])
// technically the second color is not guaranteed to be sorted correctly
// but most of the time it is good enough to be useful
return averagepixels(2, &achv[b->ind + median_start], 1.0, (f_pixel){0.5,0.5,0.5,0.5});
return averagepixels(2, &achv[b->ind + median_start], (f_pixel){0.5,0.5,0.5,0.5});
}
/*
......@@ -311,7 +311,7 @@ static bool total_box_error_below_target(double target_mse, struct box bv[], uns
** on Paul Heckbert's paper, "Color Image Quantization for Frame Buffer
** Display," SIGGRAPH 1982 Proceedings, page 297.
*/
LIQ_PRIVATE colormap *mediancut(histogram *hist, const float min_opaque_val, unsigned int newcolors, const double target_mse, const double max_mse, void* (*malloc)(size_t), void (*free)(void*))
LIQ_PRIVATE colormap *mediancut(histogram *hist, unsigned int newcolors, const double target_mse, const double max_mse, void* (*malloc)(size_t), void (*free)(void*))
{
hist_item *achv = hist->achv;
struct box bv[newcolors];
......@@ -321,7 +321,7 @@ LIQ_PRIVATE colormap *mediancut(histogram *hist, const float min_opaque_val, uns
*/
bv[0].ind = 0;
bv[0].colors = hist->size;
bv[0].color = averagepixels(bv[0].colors, &achv[bv[0].ind], min_opaque_val, (f_pixel){0.5,0.5,0.5,0.5});
bv[0].color = averagepixels(bv[0].colors, &achv[bv[0].ind], (f_pixel){0.5,0.5,0.5,0.5});
bv[0].variance = box_variance(achv, &bv[0]);
bv[0].max_error = box_max_error(achv, &bv[0]);
bv[0].sum = 0;
......@@ -330,20 +330,11 @@ LIQ_PRIVATE colormap *mediancut(histogram *hist, const float min_opaque_val, uns
unsigned int boxes = 1;
// remember smaller palette for fast searching
colormap *representative_subset = NULL;
unsigned int subset_size = ceilf(powf(newcolors,0.7f));
/*
** Main loop: split boxes until we have enough.
*/
while (boxes < newcolors) {
if (boxes == subset_size) {
representative_subset = pam_colormap(boxes, malloc, free);
set_colormap_from_boxes(representative_subset, bv, boxes, achv);
}
// first splits boxes that exceed quality limit (to have colors for things like odd green pixel),
// later raises the limit to allow large smooth areas/gradients get colors.
const double current_max_mse = max_mse + (boxes/(double)newcolors)*16.0*max_mse;
......@@ -383,14 +374,14 @@ LIQ_PRIVATE colormap *mediancut(histogram *hist, const float min_opaque_val, uns
const f_pixel previous_center = bv[bi].color;
bv[bi].colors = break_at;
bv[bi].sum = lowersum;
bv[bi].color = averagepixels(bv[bi].colors, &achv[bv[bi].ind], min_opaque_val, previous_center);
bv[bi].color = averagepixels(bv[bi].colors, &achv[bv[bi].ind], previous_center);
bv[bi].total_error = -1;
bv[bi].variance = box_variance(achv, &bv[bi]);
bv[bi].max_error = box_max_error(achv, &bv[bi]);
bv[boxes].ind = indx + break_at;
bv[boxes].colors = clrs - break_at;
bv[boxes].sum = sm - lowersum;
bv[boxes].color = averagepixels(bv[boxes].colors, &achv[bv[boxes].ind], min_opaque_val, previous_center);
bv[boxes].color = averagepixels(bv[boxes].colors, &achv[bv[boxes].ind], previous_center);
bv[boxes].total_error = -1;
bv[boxes].variance = box_variance(achv, &bv[boxes]);
bv[boxes].max_error = box_max_error(achv, &bv[boxes]);
......@@ -405,7 +396,6 @@ LIQ_PRIVATE colormap *mediancut(histogram *hist, const float min_opaque_val, uns
colormap *map = pam_colormap(boxes, malloc, free);
set_colormap_from_boxes(map, bv, boxes, achv);
map->subset_palette = representative_subset;
adjust_histogram(achv, map, bv, boxes);
return map;
......@@ -443,7 +433,7 @@ static void adjust_histogram(hist_item *achv, const colormap *map, const struct
}
}
static f_pixel averagepixels(unsigned int clrs, const hist_item achv[], const float min_opaque_val, const f_pixel center)
static f_pixel averagepixels(unsigned int clrs, const hist_item achv[], const f_pixel center)
{
double r = 0, g = 0, b = 0, a = 0, new_a=0, sum = 0;
float maxa = 0;
......@@ -460,9 +450,6 @@ static f_pixel averagepixels(unsigned int clrs, const hist_item achv[], const fl
if (sum) new_a /= sum;
/** if there was at least one completely opaque color, "round" final color to opaque */
if (new_a >= min_opaque_val && maxa >= (255.0/256.0)) new_a = 1;
sum=0;
// reverse iteration for cache locality with previous loop
for(int i = clrs-1; i >= 0; i--) {
......
LIQ_PRIVATE colormap *mediancut(histogram *hist, const float min_opaque_val, unsigned int newcolors, const double target_mse, const double max_mse, void* (*malloc)(size_t), void (*free)(void*));
LIQ_PRIVATE colormap *mediancut(histogram *hist, unsigned int newcolors, const double target_mse, const double max_mse, void* (*malloc)(size_t), void (*free)(void*));
/*
** © 2011-2015 by Kornel Lesiński.
** All rights reserved.
** See COPYRIGHT file for full license.
*/
#include "libimagequant.h"
#include "mempool.h"
......