Code Monkey home page Code Monkey logo

libimagequant's Introduction

libimagequant — Image Quantization Library

Imagequant library converts RGBA images to palette-based 8-bit indexed images, including alpha component. It's ideal for generating tiny PNG images and nice-looking GIFs.

Image encoding/decoding isn't handled by the library itself, bring your own encoder. If you're looking for a command-line tool, see pngquant.

Getting started in C

This library can be used in C programs via imagequant-sys Rust package.

rustup update
git clone https://github.com/ImageOptim/libimagequant
cd imagequant-sys
cargo build --release
# makes target/release/libimagequant_sys.a

See the C library documentation for more details.

Getting started in Rust

Add to Cargo.toml:

rustup update
cargo add imagequant

See docs.rs for the library API documentation.

License

Libimagequant is dual-licensed:

  • For Free/Libre Open Source Software it's available under GPL v3 or later with additional copyright notices for historical reasons.
  • For use in closed-source software, AppStore distribution, and other non-GPL uses, you can obtain a commercial license. Feel free to ask [email protected] for details and custom licensing terms if you need them.

Upgrading instructions

libimagequant v2 used to be a C library. libimagequant v4 is written entirely in Rust, but still exports the same C interface for C programs. You will need to install Rust 1.70+ to build it, and adjust your build commands. If you do not want to upgrade, you can keep using the C version of the library in the 2.x branch of the repo.

C static library users

Files for C/C++ are now in the imagequant-sys/ subdirectory, not in the root of the repo. There is no configure && make any more.

To build the library, install Rust via rustup, and run:

rustup update
cd imagequant-sys
cargo build --release

It produces target/release/libimagequant_sys.a static library. The API, ABI, and header files remain the same, so everything else should work the same. If you're building for macOS or iOS, see included xcodeproj file (add it as a subproject to yours).

If you're building for Android, run rustup target add aarch64-linux-android; cargo build --release --target aarch64-linux-android and use target/aarch64-linux-android/release/libimagequant_sys.a. Same for cross-compiling to other platforms. See rustup target list.

C dynamic library for package maintainers

If you're an application developer, please use the static linking option above — that option is much easier, and gives smaller executables.

The API and ABI of this library remains the same. It has the same sover, so it can be a drop-in replacement for the previous C version.

This library is now a typical Rust/Cargo library. If you want to set up off-line builds or override dependencies, it works the same as for every other Rust project. See Cargo docs for things like cargo fetch or cargo vendor (but I don't recommend vendoring).

If you want to build a dynamic library, but aren't bothered by soname and rpath being wrong, modify imagequant-sys/Cargo.toml and add "cdylib" to the existing crate-type property, and then cargo build --release will do its usual half-finished job and build target/release/libimagequant.{so,dylib,dll}.

Building with make

configure && make is gone. I hoped I could build a dynamic library just by wrapping the static library, but apparently that won't work, so I can't easily recreate the old make install. I wish there was a more standard and lightweight solution than using the cargo-c tool, so if you're good at wrangling linker flags and symbol visibility, please send pull requests.

Building with cargo-c

The cargo-c tool knows how to build and link so/dylib properly, and generates an accurate pkg-config file, so it's de-facto required for a correct system-wide install of a dynamic library.

rustup update
cd imagequant-sys
cargo install cargo-c
cargo cinstall --prefix=/usr/local --destdir=.

This makes Rust 1.70 and cargo-c package a build-time dependency. No runtime deps (apart from Cargo-internal ones). OpenMP has been dropped entirely.

Interaction with pngquant

pngquant v2 can use this library as a dynamic library. However, pngquant v4 does not support unbundling. It uses this library as a Cargo dependency via its Rust-native interface. The shared libimagequant library exports only a stable ABI for C programs, and this interface is not useful for Rust programs.

Upgrading for Rust users

If you've used the imagequant-sys crate, switch to the higher-level imagequant crate. The imagequant v4 is almost entirely backwards-compatible, with small changes that the Rust compiler will point out (e.g. changed use of c_int to u32). See docs. Please fix any deprecation warnings you may get, because the deprecated functions will be removed.

The openmp Cargo feature has been renamed to threads.

.new_image() can now take ownership of its argument to avoid copying. If you get an error that From<&Vec<RGBA>> is not implemented, then either don't pass by reference (moves, avoids copying), or call .as_slice() on it (to copy the pixels), or use .new_image_borrowed() method instead.

Threads support and WASM

By default, when the threads Cargo feature is enabled, this library uses multi-threading. Number of threads can be controlled via RAYON_NUM_THREADS environment variable.

Threads in WASM are experimental, and require special handling. If you're targeting WASM, you'll most likely want to disable threads.

To disable threads when using this library as a dependency, disable default features like this in Cargo.toml:

[dependencies]
imagequant = { version = "4.0", default-features = false }

When you compile the library directly, add --no-default-features flag instead.

libimagequant's People

Contributors

alextmjugador avatar andylizi avatar benkasminbullock avatar craigbarnes avatar dwbuiten avatar erwanvivien avatar felixbuenemann avatar jaalto avatar joshuamsager avatar kloczek avatar kornelski avatar larrabee avatar leleliu008 avatar manisandro avatar pdknsk avatar ph0b avatar philippec avatar pps83 avatar radarhere avatar rflynn avatar roadrunnerwmc avatar rolftimmermans avatar sergiomb2 avatar skal65535 avatar smokes avatar stephengroat avatar swillits avatar undercooled avatar xhmikosr avatar znerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libimagequant's Issues

configure script does not correctly set SOLIBSUFFIX

Looks like there is a misplaced fi in this section

libimagequant/configure

Lines 179 to 196 in a425e83

# Cocoa
if [[ "$OSTYPE" =~ "darwin" ]]; then
cflags "-mmacosx-version-min=10.6"
lflags "-mmacosx-version-min=10.6"
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
fi

Here is my config.mk on CentOS 7.2

# auto-generated by configure
PREFIX = /usr/local
VERSION = 2.8.0
CC = gcc
CFLAGS = -O3 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall -std=c99 -I. -DNDEBUG -DUSE_SSE=1 -msse -mfpmath=sse -fopenmp -fexcess-precision=fast
LDFLAGS =  -fopenmp -lm
SOLIBSUFFIX =

2.15.0: cmake install unversioned library

DSO produced from 2.14.1:

$ objdump -x /usr/lib64/libimagequant.so.0 |grep SONAME
  SONAME               libimagequant.so.0

and 2.15.0:

[tkloczko@barrel x86_64-redhat-linux-gnu]$ objdump -x libimagequant.so |grep SONAME
  SONAME               libimagequant.so

2.18.0: build fails on linking

Looks like something is missing ..

[tkloczko@pers-jacek x86_64-redhat-linux-gnu]$ make
/usr/bin/cmake -S/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0 -B/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu/CMakeFiles /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu'
make  -f CMakeFiles/imagequant.dir/build.make CMakeFiles/imagequant.dir/depend
make[2]: Entering directory '/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu'
cd /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0 /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0 /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu/CMakeFiles/imagequant.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu'
make  -f CMakeFiles/imagequant.dir/build.make CMakeFiles/imagequant.dir/build
make[2]: Entering directory '/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu'
[ 12%] Linking C shared library libimagequant.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/imagequant.dir/link.txt --verbose=1
/usr/bin/gcc -fPIC -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fopenmp -DNDEBUG -Wl,--as-needed -Wl,--gc-sections -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,--build-id=sha1 -shared -Wl,-soname,libimagequant.so.0 -o libimagequant.so.0.0 CMakeFiles/imagequant.dir/libimagequant.c.o CMakeFiles/imagequant.dir/blur.c.o CMakeFiles/imagequant.dir/mediancut.c.o CMakeFiles/imagequant.dir/mempool.c.o CMakeFiles/imagequant.dir/nearest.c.o CMakeFiles/imagequant.dir/pam.c.o CMakeFiles/imagequant.dir/kmeans.c.o
/usr/bin/ld: /tmp/cciQ6eA7.lto.o: in function `liq_write_remapped_image_rows':
/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/libimagequant.c:1797: undefined reference to `remap_to_palette_floyd'
/usr/bin/ld: /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/libimagequant.c:1786: undefined reference to `remap_to_palette'
/usr/bin/ld: /home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/libimagequant.c:1779: undefined reference to `remap_to_palette'
/usr/bin/ld: libimagequant.so.0.0: hidden symbol `remap_to_palette_floyd' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/imagequant.dir/build.make:196: libimagequant.so.0.0] Error 1
make[2]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu'
make[1]: *** [CMakeFiles/Makefile2:86: CMakeFiles/imagequant.dir/all] Error 2
make[1]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/libimagequant-2.18.0/x86_64-redhat-linux-gnu'
make: *** [Makefile:139: all] Error 2

Treating alpha like RGB

Hello!

I am using libimagequant to optimize PNGs to be used as textures in a game, and it mostly works very well - thanks!

But there are some textures where the alpha channel means something else entirely, and I see that in regions that would be transparent if alpha was interpreted as transparency, the RGB values are very wrong. That makes sense if those pixels were actually transparent of course, but not in this case.

Is there a way to make the library treat alpha as just another colour channel?

Thanks!

Different results on ppc64le

https://github.com/python-pillow/Pillow uses libimagequant as a dependency, but when running the Pillow test suite on GitHub Actions in different environments, one of the tests using libimagequant gives different results on ppc64le architecture.

In trying to create with a minimal example, here is the code I've come up with - https://github.com/radarhere/Pillow/blob/8c8e22c4c29d82a8ca9b5b6930fd2b03622ffdc9/src/libImaging/QuantPngQuant.c#L40-L81. It's clearly still embedded in Pillow, but only uses variables declared in the highlighted section, so hopefully that makes it self-contained enough for you to replicate without worrying about the Pillow context.

Looking at the output of my printf statements on other architectures like arm64v8 and s390x, the palette is returned with a variety of colors. On ppc64le, the palette is a repeated single color.

Let me know if that isn't sufficient information to demonstrate the problem.

make java failed

os:
Linux version 4.4.0-112-generic (buildd@lgw01-amd64-010) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) ) #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018

gcc -g -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall -std=c99 -I. -O3 -DNDEBUG -
DUSE_SSE=1 -msse -mfpmath=sse -Wno-unknown-pragmas -fexcess-precision=fast -lm -I'/home/wzhsh90/jdk/jdk1.8.0_121/include' -I'/home/wzhsh90/jdk/jdk1.8.0_121/include/linux' -I'/home/wzhsh90/jdk/jdk1.8.0_121/include/win32' -I'/home/wzhsh90/jdk/jdk1.8.0_121/include/darwin' -shared -o libimagequant.jnilib libimagequant.a org/pngquant/PngQuant.c
/usr/bin/ld: /tmp/ccKZ1Wdl.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/tmp/ccKZ1Wdl.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:68: recipe for target 'libimagequant.jnilib' failed

liq_histogram_add_fixed_color not found

I can't find liq_histogram_add_fixed_color function in libimagequant.h, but it's in the source code and documentation. I added it to libimagequant.h and it works, but I'm not sure I'm doing it right.

Optimize image with Rust API and lodepng

I couldn't find a suitable API in Rust to optimize and encode PNG data, here are pseudo codes:

#![deny(clippy::all)]

use napi::bindgen_prelude::*;
use napi_derive::napi;

#[napi(object)]
#[derive(Default)]
pub struct Options {
  // default is 70
  pub min_quality: Option<u32>,
  // default is 99
  pub max_quality: Option<u32>,
  // 1- 10
  // Faster speeds generate images of lower quality, but may be useful for real-time generation of images.
  // default: 5
  pub speed: Option<u32>,
  // Number of least significant bits to ignore.
  // Useful for generating palettes for VGA, 15-bit textures, or other retro platforms.
  pub posterization: Option<u32>,
}

#[napi]
pub fn quantize(input: Buffer, options: Option<Options>) -> Result<Buffer> {
  let bitmap = lodepng::decode32(input.as_ref()).map_err(|err| {
    Error::new(
      Status::InvalidArg,
      format!("Decode png from buffer failed{}", err),
    )
  })?;
  let options = options.unwrap_or_default();
  let width = bitmap.width;
  let height = bitmap.height;
  let mut liq = imagequant::new();
  liq.set_speed(options.speed.unwrap_or(5) as i32);
  liq.set_quality(
    options.min_quality.unwrap_or(70) as u8,
    options.max_quality.unwrap_or(99) as u8,
  );
  let mut img = liq
    .new_image(
      bitmap.buffer.as_slice(),
      width as usize,
      height as usize,
      0.0,
    )
    .map_err(|err| {
      Error::new(
        Status::GenericFailure,
        format!("Create image failed {}", err),
      )
    })?;
  let mut quantization_result = liq
    .quantize(&mut img)
    .map_err(|err| Error::new(Status::GenericFailure, format!("quantize failed {}", err)))?;
  quantization_result.set_dithering_level(1.0);
  let (palette, pixels) = quantization_result
    .remapped(&mut img)
    .map_err(|err| Error::new(Status::GenericFailure, format!("remap failed {}", err)))?;
  let mut encoder = lodepng::Encoder::new();
  let info_png = encoder.info_png().clone();
  let inner_state = encoder.info_raw_mut();
  for p in palette {
    inner_state.palette_add(p).map_err(|err| {
      Error::new(
        Status::GenericFailure,
        format!("Add palette failed {}", err),
      )
    })?;
  }
  inner_state.set_bitdepth(8);
  let mut state = lodepng::State {
    info_raw: inner_state.clone(),
    info_png,
    ..Default::default()
  };
  let mut out_png = std::ptr::null_mut();
  let mut outsize = 0usize;
  unsafe {
    lodepng::ffi::lodepng_encode(
      &mut out_png,
      &mut outsize,
      pixels.as_ptr(),
      width as u32,
      height as u32,
      &mut state,
    )
  };
  println!("{:?}", out_png);
  Ok(unsafe { Vec::from_raw_parts(out_png, outsize, outsize) }.into())
}

Commit rustfmt.toml

You seem to use your own rustfmt.toml else lines like

if bad_object!(attr, LIQ_ATTR_MAGIC) { return };
or
if bad_object!(result, LIQ_RESULT_MAGIC) { return None; }
would be formatted differently.

For easier tinkering with your rust code I'd like either
a) you to commit your rustfmt.toml that you used during the project
b) reformat the current code to match the default rustfmt guides

Big resolution images crash the library

I'm trying to process a quite large PNG (7680 × 4320, ~100Mb) but the library seems to not be able to handle it, panicking with
thread 'main' panicked at 'attempt to add with overflow' on src/hist.rs:206:34.

The issue is quite easy to reproduce by running the provided example and just setting

let width = 5000;
let height = 5000;

or anything bigger than that. Crashes all the time on my machine.

Additional info:

  • imagequant 4.0.2
  • macOS 12.5.1 (MacbookPro 2017, Intel chipset)
  • Rust 1.63

The color channel of the palette, red and blue reverse,Only the following code is the correct color result

    LodePNGState state;
    lodepng_state_init(&state);
    state.info_raw.colortype = LCT_PALETTE;
    state.info_raw.bitdepth = 8;
    state.info_png.color.colortype = LCT_PALETTE;
    state.info_png.color.bitdepth = 8;
    state.encoder.auto_convert = 0;

    for(int i=0; i < palette->count; i++) {
        auto r = palette->entries[i].b;
        auto g = palette->entries[i].g;
        auto b = palette->entries[i].r;
        auto a = palette->entries[i].a;
        lodepng_palette_add(&state.info_png.color, r, g, b, a);
        lodepng_palette_add(&state.info_raw, r, g, b, a);
    }

2.14.0 'background' not specified in enclosing 'parallel'

I have packaged libimagequant for conda at https://github.com/conda-forge/libimagequant-feedstock. I get these errors when attempting to build version 2.14.0: https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=282739&view=logs&j=656edd35-690f-5c53-9ba3-09c10d0bea97&t=e5c8ab1d-8ff9-5cae-b332-e15ae582ed2d&l=162

I'm not sure if this is a bug or an issue with the cond-forge build environment -- any thoughts or suggestions will be much appreciated.

Also, if there is anyone here who would like to help maintain the conda package please let me know -- I would be delighted to have a co-mantainer.

More than 256 color quantization

Hello, I am wondering how hard it would be to add greater than 256 colors for histograms/palettes? I'm seeing some magic numbers in the code and wanted to make sure it wouldn't be too crazy of a modification if I went down that route -- or if there's some gotchas to watch out for. Thanks!

Latest version doesn't appear to be compiled

The latest version of the library does not appear to be compiled normally.
Function set_importance_map_raw() is used in capi.rs, but I can't find it on any source, including lib.rs.
Please check it.

error

  • Windows 11
  • rustc 1.57.0 (f1edd0429 2021-11-29)
  • rustup 1.24.3 (ce5817a94 2021-05-31)

liq_aligned_malloc could be replaced by aligned_alloc from stdlib

static void *liq_aligned_malloc(size_t size)
{
unsigned char *ptr = malloc(size + 16);
if (!ptr) {
return NULL;
}
uintptr_t offset = 16 - ((uintptr_t)ptr & 15); // also reserves 1 byte for ptr[-1]
ptr += offset;
assert(0 == (((uintptr_t)ptr) & 15));
ptr[-1] = offset ^ 0x59; // store how much pointer was shifted to get the original for free()
return ptr;
}
LIQ_NONNULL static void liq_aligned_free(void *inptr)
{
unsigned char *ptr = inptr;
size_t offset = ptr[-1] ^ 0x59;
assert(offset > 0 && offset <= 16);
free(ptr - offset);
}

Since this library could be compiled with c11, aligned_malloc should be available.

-std=gnu11 has already become default since GCC 5: https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Standards.html

Google's squoosh under Apache 2.0 license uses imagequant (GPL3)

I filed an issue with them:
screenshot
GoogleChromeLabs/squoosh#842
However judging by their reply seems like they just plan to ignore it, even though they have been using and relicensing it under Apache 2.0 since 2+ years.

Your imagequant library used is under GPL3.

Squoosh is under Apache 2.0 and very likely to be considered a derviative work as defined by GPL3.

However, GPLv3 software cannot be included in Apache projects.

So I am asking you if you are aware of them relencensing your library under incompatible terms and if this is legal from your point of view.

Monochrome images when OpenMP is enabled

Hello,

When I apply a 256-colors quantization on some image, it generates a monochrome image (see the following examples).
It is not deterministic, with a probability of 0.25 to output a monochrome.
It doesn't occur when OpenMP is disabled.

Some examples (the original followed by its output):
original_0
monochrome_0
original_1
monochrome_1

Another example (I lose the original image):
monochrome_2

Cargo build error

'stdio.h' file not found

this is report :

process didn't exit successfully: E:\Wangbang\android-app\gifski\app\src\main\cpp\gifski\target\release\build\imagequant-sys-c84454afaa630a30\build-script-build (exit code: 1)
--- stdout
OPT_LEVEL = Some("3")
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-pc-windows-msvc")
CC_aarch64-linux-android = None
CC_aarch64_linux_android = None
TARGET_CC = None
CC = None
CFLAGS_aarch64-linux-android = None
CFLAGS_aarch64_linux_android = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
cargo:include=\?\C:\Users\Administrator.cargo\registry\src\mirrors.ustc.edu.cn-b63e9dae659fc205\imagequant-sys-3.1.0+sys2.16.0
running: "clang.exe" "--target=aarch64-linux-android" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=aarch64-linux-android" "-std=c99" "-DNDEBUG=1" "-o" "
E:\Wangbang\android-app\gifski\app\src\main\cpp\gifski\target\aarch64-linux-android\release\build\imagequant-sys-d2bff4053fd2c583\out\libimagequant.o" "-c" "libimagequant
.c"
cargo:warning=libimagequant.c:9:10: fatal error: 'stdio.h' file not found
cargo:warning=#include <stdio.h>
cargo:warning= ^
cargo:warning=1 error generated.
exit code: 1

New Release

It would be nice for a new release to be tagged, since the current one fails to build with GCC 9.1 and the fix has been merged upstream. Thanks!

can not get the target .a file by use cargo build

D:\libimagequant-main\imagequant-sys>cargo build --release
warning: cross-crate traits with a default impl, like Send, should not be specialized
--> src\seacow.rs:12:1
|
12 | unsafe impl<T: Send> Send for SeaCow<', *const T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(suspicious_auto_trait_impls)] on by default
= warning: this will change its meaning in a future release!
= note: for more information, see issue #93367 rust-lang/rust#93367
= note: *const T is not a generic parameter
note: try using the same sequence of generic parameters as the struct definition
--> src\seacow.rs:5:1
|
5 | / pub struct SeaCow<'a, T> {
6 | | inner: SeaCowInner<'a, T>,
7 | | }
| |
^

warning: cross-crate traits with a default impl, like Sync, should not be specialized
--> src\seacow.rs:13:1
|
13 | unsafe impl<T: Sync> Sync for SeaCow<', *const T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= note: for more information, see issue #93367 rust-lang/rust#93367
= note: *const T is not a generic parameter
note: try using the same sequence of generic parameters as the struct definition
--> src\seacow.rs:5:1
|
5 | / pub struct SeaCow<'a, T> {
6 | | inner: SeaCowInner<'a, T>,
7 | | }
| |
^

warning: imagequant (lib) generated 2 warnings
Finished release [optimized] target(s) in 0.08s

make java fails

I am trying to compile this for Java. Any idea how to fix this?

sto@big:~/workspace/libimagequant$ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
sto@big:~/workspace/libimagequant$ make java
gcc -g -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall -std=c99 -I. -O3 -DNDEBUG -DUSE_SSE=1 -msse -mfpmath=sse -Wno-unknown-pragmas -fexcess-precision=fast -lm -I'/usr/lib/jvm/java-8-openjdk-amd64//include' -I'/usr/lib/jvm/java-8-openjdk-amd64//include/linux' -I'/usr/lib/jvm/java-8-openjdk-amd64//include/win32' -I'/usr/lib/jvm/java-8-openjdk-amd64//include/darwin' -shared -o libimagequant.jnilib org/pngquant/PngQuant.c libimagequant.a
/usr/bin/ld: libimagequant.a(libimagequant.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:68: recipe for target 'libimagequant.jnilib' failed
make: *** [libimagequant.jnilib] Error 1

smarter color reducer? (considering visual similarity)

Hello,

Would it be possible to have a smarter color reducer?
Converting the attached png
serbia

pngquant -o serbia_quantized.png 6 serbia.png

results in ~5 colors visually (I'm sure pixels are slightly different):
white, yellow, brown, red, black
serbia_quantized

The blue in crown was converted to brown. Instead, black outlines could be converted to brown (closer visually) and leave blue alone.
If the colors are close visually, I'd prefer to have just one instead of two separate black and dark brown (the one with most pixels).

What do you think?

2.9.0: too many arguments to function ‘nearest_init’

$ sha1sum libimagequant-2.9.0.tar.gz
3ee01906a5d1660364c23cc2d3d2eb2458f5da8b *libimagequant-2.9.0.tar.gz
..\..\viter.c: In function ‘viter_do_iteration’:
..\..\viter.c:85:35: error: too many arguments to function ‘nearest_init’
     struct nearest_map *const n = nearest_init(map, fast_palette);
                                   ^
In file included from ..\..\viter.c:23:0:
..\..\nearest.h:6:33: note: declared here
 LIQ_PRIVATE struct nearest_map *nearest_init(const colormap *palette);
                                 ^

Makefile: Target "make dll" produce library with garbage exports

I use latest versions MSYS2 and MinGW-w64 (x86) to build library. After compilation I see this exports in my dll:

EXPORTS
    kmeans_do_iteration @1
    kmeans_finalize @2
    kmeans_init @3
    kmeans_update_color @4
    liq_attr_copy @5
    liq_attr_create @6
    liq_attr_create_with_allocator @7
    liq_attr_destroy @8
    liq_attr_set_progress_callback @9
    liq_blur @10
    liq_crash_if_invalid_handle_pointer_given @11
    liq_crash_if_invalid_pointer_given @12
    liq_executing_user_callback @13
    liq_get_max_colors @14
    liq_get_max_quality @15
    liq_get_min_opacity @16
    liq_get_min_posterization @17
    liq_get_min_quality @18
    liq_get_output_gamma @19
    liq_get_palette @20
    liq_get_quantization_error @21
    liq_get_quantization_quality @22
    liq_get_remapping_error @23
    liq_get_remapping_quality @24
    liq_get_speed @25
    liq_histogram_add_colors @26
    liq_histogram_add_fixed_color @27
    liq_histogram_add_image @28
    liq_histogram_create @29
    liq_histogram_destroy @30
    liq_histogram_quantize @31
    liq_image_add_fixed_color @32
    liq_image_create_custom @33
    liq_image_create_rgba @34
    liq_image_create_rgba_rows @35
    liq_image_destroy @36
    liq_image_get_height @37
    liq_image_get_width @38
    liq_image_quantize @39
    liq_image_set_background @40
    liq_image_set_importance_map @41
    liq_image_set_memory_ownership @42
    liq_max3 @43
    liq_min3 @44
    liq_quantize_image @45
    liq_result_destroy @46
    liq_result_set_progress_callback @47
    liq_set_dithering_level @48
    liq_set_last_index_transparent @49
    liq_set_log_callback @50
    liq_set_log_flush_callback @51
    liq_set_max_colors @52
    liq_set_min_opacity @53
    liq_set_min_posterization @54
    liq_set_output_gamma @55
    liq_set_quality @56
    liq_set_speed @57
    liq_version @58
    liq_write_remapped_image @59
    liq_write_remapped_image_rows @60
    mediancut @61
    mempool_alloc @62
    mempool_create @63
    mempool_destroy @64
    nearest_free @65
    nearest_init @66
    nearest_search @67
    pam_acolorhashtoacolorhist @68
    pam_add_to_hash @69
    pam_allocacolorhash @70
    pam_colormap @71
    pam_computeacolorhash @72
    pam_duplicate_colormap @73
    pam_freeacolorhash @74
    pam_freeacolorhist @75
    pam_freecolormap @76
    to_f_set_gamma @77

As you can see, all functions that do not start with liq_* are garbage.

It can be fixed by replacing this:

dll:
	$(MAKE) CFLAGSADD="-DIMAGEQUANT_EXPORTS" $(DLL)

to this:

dll:
	$(MAKE) CFLAGS="$(CFLAGS) -DIMAGEQUANT_EXPORTS" $(DLL)

It seems that CFLAGSADD in current Makefile has no any effect to build lib:

gcc -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall -std=c99 -I. -O3 -DNDEBUG -DUSE_SSE=1 -msse -mfpmath=sse -Wno-unknown-pragmas -fexcess-precision=fast -c -o libimagequant.o libimagequant.c

Consider adding an API to set the number of threads used internally

Recent changes made libimagequant use rayon parallel iterators to speed up some operations:

// chunk size is a trade-off between parallelization and overhead
hist.items.par_chunks_mut(256).for_each(|batch| {
let kmeans = tls.get_or(move || RefCell::new(Kmeans::new(len)));
if let Ok(ref mut kmeans) = *kmeans.borrow_mut() {
kmeans.iterate_batch(batch, &n, colors, adjust_weight);
}
});

I can see how this change is a good thing for most use cases. However, applications using libimagequant may already be processing several images in parallel, maxing out CPU usage. In those cases, spawning additional threads may lead to worse performance. In addition, there might be other good reasons why client code would want to touch the number of threads used.

As far as I know, the latest libimagequant code at the time of writing does not offer an API to change the number of threads used within libimagequant. Applications can force libimagequant to use a different number of threads by building their own rayon global thread pool, but this might not be a satisfactory solution because it affects all crates using rayon, not only libimagequant.

While I'm aware that the code currently in main might be work in progress, I think that nevertheless it's a good idea to create this issue to know if there are any plans to support this configuration at some point. Thank you for your great work on this library!

pkg-config, installation script

Hi there,

I noticed this project has transitioned to using cargo instead of autoconf, and as a part of that transition it no longer produces the pkg-config file (*.pc), nor a script to install *.pc, *.h, and the libraries. Are these deprecated or will they be making a comeback?

We have a C-based project, Tux Paint, that uses libimagequant that expects it to work with pkg-config. I was wondering if we need to make changes to Tux Paint or we can just wait for the libimagequant project to make it available again.

Thank you

VS build fail help

image
image
Error C3015 OpenMP "for" statement has an incorrect initialization format of Imagequant :\ workSpace.net \libimagequant\ mediancut-c 202

Process images with premultiplied alpha

libimagequant/src/pal.rs

Lines 103 to 111 in 260e963

pub fn from_rgba(gamma_lut: &[f32; 256], px: RGBA) -> Self {
let a = px.a as f32 / 255.;
Self(ARGBF {
a: a * LIQ_WEIGHT_A,
r: gamma_lut[px.r as usize] * LIQ_WEIGHT_R * a,
g: gamma_lut[px.g as usize] * LIQ_WEIGHT_G * a,
b: gamma_lut[px.b as usize] * LIQ_WEIGHT_B * a,
})
}

It seems that here the color is pre-multiplied and stored into the palette, which messes up the colors when processing images that already contains premultiplied alpha (exported from some program).

Is it possible to add an option that treats the input colors as premultiplied (or is it a bad idea to do quantization on premultiplied images)?

New Release and README

Hello.
It's me again. ;)
Can you do few things?

  1. Create new release. I need this because I'm using the releases to build the package and I need the latest changes.
  2. Update link to GO bindings in readme to my repository (https://github.com/larrabee/go-imagequant). Original code not updated since 03.2017 and have few bugs. I forked it, repaired it and made a few small improvements.

Some question about LISENCE.

Libimagequant is dual-licensed:

If I use libimagequant in my Open Source Software, and also publish it to AppStore, users can download it either from github's releases page or from AppStore, what type of license should it has?

make java error

make java
javah -o org/pngquant/LiqObject.h org.pngquant.LiqObject && touch org/pngquant/LiqObject.h
错误: 找不到 'org.pngquant.LiqObject' 的类文件。
Makefile:77: recipe for target 'org/pngquant/LiqObject.h' failed
make: *** [org/pngquant/LiqObject.h] Error 1

Clarification of License

Hi,

First, congrats on the great work on this license. The project http://github.com/hughsie/appstream-glib considers making use of pngquant, but due to licensing reasons cannot use the library (so far, as a 'workaround', the as-glib library calls out to the pngquant binary)

Of course it would be cleaner to link the library instead of using an external command line tool, but due to licensing, this is not possible.

  • as-glib is licensed LGPL-2.1 or later
  • pngquant is licensed GPL-3.0 or later

This combination would make as-glib GPL-3.0, which in turn would make it impossible to be used in the way it is used now.

Was GPL intentionally chosed for the library part too? (it is common for libraries to be licensed LGPL, hence asking) or would you see a chance to relicense this to LGPL (preferably 2.1 or later)?

Thanks for your considerations,
Dominique

liq_add_fixed_histogram_color exact matches

I've been using liq_add_fixed_histogram_color which is working quite well. However, when the palette size limit is reached and images are quantized against the histogram, colors such as (0,0,255) might match with (0,0,254). With the requested functionality, an input color must exactly match the specified color, otherwise it will not be indexed at that location, and instead be located elsewhere. I imagine this could be added as a separate flag or function.

I'm wondering if this is doable, if so I can try taking a look through the code and see if I can add it myself. Any guidance would be much appreciated!

Test failure on big-endian

Hi. Yes, I created #75 about ppc64le, it was fixed in libimagequant 4.0, and now I'm back again.

I've found a failure with libimagequant 4.0 that occurs on s390x, but not ppc64le, arm64v8 or amd64. The difference is presumably that s390x is big-endian.

Rather than trying to figure out exactly what is happening in libimagequant terms during my test, I've run the tests that you suggested.

They give a failure at the last step -

c_test-1911acffb39972b4: test.c:84: test_histogram: Assertion `LIQ_OK == err' failed.
error: test failed, to rerun pass '-p c_test --lib'

Let me know if there is anything further I can do to assist.

CMakeLists.txt needs to be improved

1. BUILD_SHARED_LIBS option not used. can be removed.

2. generates both static and shared library, append following code to CMakeLists.txt

add_library(imagequant_a STATIC
  libimagequant.c
  blur.c
  mediancut.c
  mempool.c
  nearest.c
  pam.c
  kmeans.c
)

3. modify imagequant.pc.in

change  PREFIX    to   @PREFIX@
change  VERSION   to   @VERSION@

4. generate imagequant.pc from imagequant.pc.in

set(PREFIX ${CMAKE_INSTALL_PREFIX})
set(VERSION 2.14.1)
configure_file(imagequant.pc.in imagequant.pc @ONLY)

5. support install target

install(TARGETS imagequant   LIBRARY                DESTINATION lib)
install(FILES                     libimagequant.h   DESTINATION include)
install(FILES ${CMAKE_BINARY_DIR}/libimagequant_a.a DESTINATION lib RENAME libimagequant.a)
install(FILES ${CMAKE_BINARY_DIR}/imagequant.pc     DESTINATION lib/pkgconfig)

symbol lookup error on linux

/usr/lib/jvm/java-8-openjdk/bin/java: symbol lookup error: xxx/libimagequant/libimagequant.jnilib: undefined symbol: liq_attr_create

Duplicate transparency palette entry generated since v4.0.0 with some inputs

We noticed that for some inputs with an alpha channel component, duplicate palette entries are generated starting with version v4.0.0.
v2.17.0 doesn't seem to be affected.

Reproducer:
https://gist.github.com/dloebl/b4f77fe718ce43020bac70ec33b2d4a5/archive/4443b4faffcd8b933d976ecbcccd0e061e2167e0.zip

Steps:

gcc test.c $(pkg-config --libs --cflags imagequant) -o test
./test
Output v4.0.4:
count: 255
r: 71 g: 112 b: 76 a: 0
r: 71 g: 112 b: 76 a: 0
r: 255 g: 255 b: 255 a: 255
r: 1 g: 0 b: 1 a: 255
r: 22 g: 23 b: 22 a: 255
r: 21 g: 21 b: 21 a: 255
r: 24 g: 25 b: 24 a: 255
r: 252 g: 251 b: 252 a: 255
r: 11 g: 10 b: 11 a: 255
r: 253 g: 253 b: 253 a: 255
r: 4 g: 5 b: 4 a: 255
r: 8 g: 8 b: 8 a: 255
r: 18 g: 18 b: 18 a: 255
r: 112 g: 113 b: 112 a: 255
r: 15 g: 16 b: 15 a: 255
r: 19 g: 21 b: 19 a: 255
r: 21 g: 15 b: 21 a: 255
r: 22 g: 21 b: 22 a: 255
r: 14 g: 14 b: 14 a: 255
r: 28 g: 27 b: 28 a: 255
r: 143 g: 143 b: 143 a: 255
r: 95 g: 97 b: 95 a: 255
r: 139 g: 140 b: 139 a: 255
r: 94 g: 94 b: 94 a: 255
r: 218 g: 218 b: 218 a: 255
r: 32 g: 32 b: 32 a: 255
r: 134 g: 133 b: 134 a: 255
r: 243 g: 242 b: 243 a: 255
r: 22 g: 18 b: 22 a: 255
r: 110 g: 110 b: 110 a: 255
r: 122 g: 123 b: 122 a: 255
r: 224 g: 224 b: 224 a: 255
r: 85 g: 85 b: 85 a: 255
r: 250 g: 250 b: 250 a: 255
r: 71 g: 70 b: 71 a: 255
r: 126 g: 125 b: 126 a: 255
r: 93 g: 92 b: 93 a: 255
r: 230 g: 230 b: 230 a: 255
r: 136 g: 135 b: 136 a: 255
r: 255 g: 252 b: 255 a: 255
r: 131 g: 131 b: 131 a: 255
r: 22 g: 12 b: 22 a: 255
r: 196 g: 196 b: 196 a: 255
r: 206 g: 204 b: 206 a: 255
r: 49 g: 49 b: 49 a: 255
r: 118 g: 118 b: 118 a: 255
r: 20 g: 41 b: 20 a: 255
r: 18 g: 8 b: 18 a: 255
r: 252 g: 255 b: 252 a: 255
r: 113 g: 107 b: 113 a: 255
r: 250 g: 253 b: 250 a: 255
r: 5 g: 74 b: 5 a: 255
r: 159 g: 160 b: 159 a: 255
r: 93 g: 86 b: 93 a: 255
r: 215 g: 216 b: 215 a: 255
r: 116 g: 116 b: 116 a: 255
r: 45 g: 45 b: 45 a: 255
r: 102 g: 101 b: 102 a: 255
r: 221 g: 222 b: 221 a: 255
r: 56 g: 58 b: 56 a: 255
r: 40 g: 40 b: 40 a: 255
r: 135 g: 138 b: 135 a: 255
r: 76 g: 75 b: 76 a: 255
r: 0 g: 34 b: 0 a: 255
r: 62 g: 63 b: 62 a: 255
r: 168 g: 168 b: 168 a: 255
r: 152 g: 152 b: 152 a: 255
r: 167 g: 168 b: 167 a: 255
r: 16 g: 68 b: 16 a: 255
r: 121 g: 121 b: 121 a: 255
r: 19 g: 28 b: 19 a: 255
r: 1 g: 23 b: 1 a: 255
r: 90 g: 90 b: 90 a: 255
r: 130 g: 129 b: 130 a: 255
r: 224 g: 245 b: 224 a: 255
r: 98 g: 99 b: 98 a: 255
r: 79 g: 78 b: 79 a: 255
r: 210 g: 209 b: 210 a: 255
r: 157 g: 156 b: 157 a: 255
r: 9 g: 86 b: 9 a: 255
r: 245 g: 245 b: 245 a: 255
r: 52 g: 54 b: 52 a: 255
r: 16 g: 92 b: 16 a: 255
r: 87 g: 88 b: 87 a: 255
r: 20 g: 34 b: 20 a: 255
r: 188 g: 188 b: 188 a: 255
r: 198 g: 199 b: 198 a: 255
r: 238 g: 237 b: 238 a: 255
r: 0 g: 15 b: 0 a: 255
r: 18 g: 60 b: 18 a: 255
r: 145 g: 146 b: 145 a: 255
r: 166 g: 165 b: 166 a: 255
r: 171 g: 172 b: 171 a: 255
r: 202 g: 201 b: 202 a: 255
r: 192 g: 192 b: 192 a: 255
r: 234 g: 233 b: 234 a: 255
r: 10 g: 54 b: 10 a: 255
r: 101 g: 93 b: 101 a: 255
r: 180 g: 179 b: 180 a: 255
r: 82 g: 82 b: 82 a: 255
r: 103 g: 104 b: 103 a: 255
r: 174 g: 165 b: 174 a: 255
r: 176 g: 176 b: 176 a: 255
r: 231 g: 250 b: 231 a: 255
r: 7 g: 43 b: 7 a: 255
r: 3 g: 82 b: 3 a: 255
r: 217 g: 251 b: 217 a: 255
r: 105 g: 106 b: 105 a: 255
r: 203 g: 203 b: 203 a: 255
r: 160 g: 164 b: 160 a: 255
r: 226 g: 227 b: 226 a: 255
r: 248 g: 247 b: 248 a: 255
r: 253 g: 245 b: 253 a: 255
r: 1 g: 61 b: 1 a: 255
r: 112 g: 103 b: 112 a: 255
r: 203 g: 232 b: 203 a: 255
r: 117 g: 112 b: 117 a: 255
r: 208 g: 207 b: 208 a: 255
r: 234 g: 235 b: 234 a: 255
r: 107 g: 122 b: 107 a: 255
r: 64 g: 72 b: 64 a: 255
r: 50 g: 132 b: 50 a: 255
r: 185 g: 183 b: 185 a: 255
r: 12 g: 112 b: 12 a: 255
r: 169 g: 241 b: 169 a: 255
r: 143 g: 137 b: 143 a: 255
r: 239 g: 230 b: 239 a: 255
r: 6 g: 0 b: 6 a: 255
r: 87 g: 108 b: 87 a: 255
r: 6 g: 129 b: 6 a: 255
r: 6 g: 104 b: 6 a: 255
r: 2 g: 67 b: 2 a: 255
r: 6 g: 120 b: 6 a: 255
r: 177 g: 180 b: 177 a: 255
r: 83 g: 101 b: 83 a: 255
r: 70 g: 169 b: 70 a: 255
r: 191 g: 242 b: 191 a: 255
r: 9 g: 144 b: 9 a: 255
r: 120 g: 157 b: 120 a: 255
r: 201 g: 219 b: 201 a: 255
r: 21 g: 82 b: 21 a: 255
r: 109 g: 126 b: 109 a: 255
r: 143 g: 133 b: 143 a: 255
r: 177 g: 170 b: 177 a: 255
r: 122 g: 114 b: 122 a: 255
r: 20 g: 47 b: 20 a: 255
r: 162 g: 177 b: 162 a: 255
r: 131 g: 120 b: 131 a: 255
r: 3 g: 183 b: 3 a: 255
r: 87 g: 154 b: 87 a: 255
r: 90 g: 114 b: 90 a: 255
r: 182 g: 182 b: 182 a: 255
r: 203 g: 196 b: 203 a: 255
r: 62 g: 150 b: 62 a: 255
r: 56 g: 160 b: 56 a: 255
r: 104 g: 169 b: 104 a: 255
r: 152 g: 218 b: 152 a: 255
r: 219 g: 210 b: 219 a: 255
r: 84 g: 137 b: 84 a: 255
r: 12 g: 99 b: 12 a: 255
r: 83 g: 208 b: 83 a: 255
r: 137 g: 125 b: 137 a: 255
r: 83 g: 119 b: 83 a: 255
r: 242 g: 255 b: 242 a: 255
r: 190 g: 236 b: 190 a: 255
r: 65 g: 66 b: 65 a: 255
r: 136 g: 185 b: 136 a: 255
r: 148 g: 151 b: 148 a: 255
r: 223 g: 238 b: 223 a: 255
r: 186 g: 208 b: 186 a: 255
r: 83 g: 190 b: 83 a: 255
r: 188 g: 191 b: 188 a: 255
r: 246 g: 252 b: 246 a: 255
r: 106 g: 109 b: 106 a: 255
r: 121 g: 146 b: 121 a: 255
r: 213 g: 213 b: 213 a: 255
r: 64 g: 94 b: 64 a: 255
r: 152 g: 181 b: 152 a: 255
r: 117 g: 134 b: 117 a: 255
r: 154 g: 190 b: 154 a: 255
r: 4 g: 172 b: 4 a: 255
r: 100 g: 241 b: 100 a: 255
r: 103 g: 153 b: 103 a: 255
r: 98 g: 143 b: 98 a: 255
r: 48 g: 98 b: 48 a: 255
r: 203 g: 228 b: 203 a: 255
r: 152 g: 149 b: 152 a: 255
r: 80 g: 126 b: 80 a: 255
r: 190 g: 230 b: 190 a: 255
r: 53 g: 110 b: 53 a: 255
r: 90 g: 164 b: 90 a: 255
r: 146 g: 173 b: 146 a: 255
r: 102 g: 200 b: 102 a: 255
r: 65 g: 218 b: 65 a: 255
r: 121 g: 129 b: 121 a: 255
r: 103 g: 120 b: 103 a: 255
r: 142 g: 237 b: 142 a: 255
r: 214 g: 235 b: 214 a: 255
r: 89 g: 148 b: 89 a: 255
r: 202 g: 246 b: 202 a: 255
r: 3 g: 48 b: 3 a: 255
r: 63 g: 182 b: 63 a: 255
r: 182 g: 204 b: 182 a: 255
r: 166 g: 158 b: 166 a: 255
r: 56 g: 45 b: 56 a: 255
r: 53 g: 191 b: 53 a: 255
r: 75 g: 136 b: 75 a: 255
r: 111 g: 150 b: 111 a: 255
r: 95 g: 223 b: 95 a: 255
r: 133 g: 215 b: 133 a: 255
r: 203 g: 224 b: 203 a: 255
r: 195 g: 213 b: 195 a: 255
r: 127 g: 198 b: 127 a: 255
r: 240 g: 248 b: 240 a: 255
r: 240 g: 223 b: 240 a: 255
r: 139 g: 250 b: 139 a: 255
r: 75 g: 142 b: 75 a: 255
r: 91 g: 128 b: 91 a: 255
r: 110 g: 119 b: 110 a: 255
r: 27 g: 123 b: 27 a: 255
r: 206 g: 243 b: 206 a: 255
r: 67 g: 156 b: 67 a: 255
r: 151 g: 228 b: 151 a: 255
r: 228 g: 221 b: 228 a: 255
r: 173 g: 201 b: 173 a: 255
r: 226 g: 253 b: 226 a: 255
r: 112 g: 139 b: 112 a: 255
r: 66 g: 206 b: 66 a: 255
r: 53 g: 119 b: 53 a: 255
r: 4 g: 164 b: 4 a: 255
r: 74 g: 242 b: 74 a: 255
r: 183 g: 225 b: 183 a: 255
r: 153 g: 255 b: 153 a: 255
r: 75 g: 89 b: 75 a: 255
r: 175 g: 231 b: 175 a: 255
r: 1 g: 159 b: 1 a: 255
r: 130 g: 234 b: 130 a: 255
r: 94 g: 250 b: 94 a: 255
r: 152 g: 139 b: 152 a: 255
r: 184 g: 186 b: 184 a: 255
r: 227 g: 216 b: 227 a: 255
r: 26 g: 18 b: 26 a: 255
r: 193 g: 196 b: 193 a: 255
r: 15 g: 21 b: 15 a: 255
r: 36 g: 104 b: 36 a: 255
r: 179 g: 218 b: 179 a: 255
r: 239 g: 240 b: 239 a: 255
r: 50 g: 83 b: 50 a: 255
r: 133 g: 164 b: 133 a: 255
r: 105 g: 193 b: 105 a: 255
r: 168 g: 167 b: 168 a: 255
r: 79 g: 181 b: 79 a: 255
r: 86 g: 95 b: 86 a: 255
r: 209 g: 254 b: 209 a: 255
r: 75 g: 55 b: 75 a: 255
Output v2.17.0:
count: 255
r: 71 g: 112 b: 76 a: 0
r: 253 g: 253 b: 253 a: 255
r: 251 g: 251 b: 251 a: 255
r: 16 g: 16 b: 16 a: 255
r: 22 g: 22 b: 22 a: 255
r: 24 g: 24 b: 24 a: 255
r: 22 g: 19 b: 22 a: 255
r: 255 g: 255 b: 255 a: 255
r: 0 g: 0 b: 0 a: 255
r: 20 g: 20 b: 20 a: 255
r: 18 g: 18 b: 18 a: 255
r: 21 g: 15 b: 21 a: 255
r: 254 g: 255 b: 254 a: 255
r: 8 g: 8 b: 8 a: 255
r: 14 g: 14 b: 14 a: 255
r: 169 g: 170 b: 169 a: 255
r: 111 g: 111 b: 111 a: 255
r: 92 g: 88 b: 92 a: 255
r: 5 g: 5 b: 5 a: 255
r: 91 g: 92 b: 91 a: 255
r: 46 g: 46 b: 46 a: 255
r: 22 g: 11 b: 22 a: 255
r: 223 g: 222 b: 223 a: 255
r: 12 g: 11 b: 12 a: 255
r: 8 g: 10 b: 8 a: 255
r: 82 g: 82 b: 82 a: 255
r: 190 g: 191 b: 190 a: 255
r: 124 g: 126 b: 124 a: 255
r: 3 g: 1 b: 3 a: 255
r: 109 g: 110 b: 109 a: 255
r: 229 g: 229 b: 229 a: 255
r: 250 g: 250 b: 250 a: 255
r: 70 g: 70 b: 70 a: 255
r: 153 g: 153 b: 153 a: 255
r: 252 g: 253 b: 252 a: 255
r: 78 g: 77 b: 78 a: 255
r: 94 g: 93 b: 94 a: 255
r: 26 g: 29 b: 26 a: 255
r: 55 g: 57 b: 55 a: 255
r: 130 g: 132 b: 130 a: 255
r: 20 g: 26 b: 20 a: 255
r: 144 g: 144 b: 144 a: 255
r: 113 g: 114 b: 113 a: 255
r: 123 g: 121 b: 123 a: 255
r: 184 g: 182 b: 184 a: 255
r: 120 g: 121 b: 120 a: 255
r: 117 g: 116 b: 117 a: 255
r: 136 g: 139 b: 136 a: 255
r: 22 g: 24 b: 22 a: 255
r: 31 g: 30 b: 31 a: 255
r: 40 g: 40 b: 40 a: 255
r: 87 g: 87 b: 87 a: 255
r: 135 g: 135 b: 135 a: 255
r: 1 g: 18 b: 1 a: 255
r: 107 g: 103 b: 107 a: 255
r: 133 g: 133 b: 133 a: 255
r: 99 g: 97 b: 99 a: 255
r: 52 g: 50 b: 52 a: 255
r: 242 g: 242 b: 242 a: 255
r: 201 g: 200 b: 201 a: 255
r: 210 g: 208 b: 210 a: 255
r: 3 g: 77 b: 3 a: 255
r: 218 g: 217 b: 218 a: 255
r: 167 g: 167 b: 167 a: 255
r: 206 g: 206 b: 206 a: 255
r: 203 g: 204 b: 203 a: 255
r: 146 g: 147 b: 146 a: 255
r: 13 g: 6 b: 13 a: 255
r: 139 g: 140 b: 139 a: 255
r: 178 g: 178 b: 178 a: 255
r: 118 g: 118 b: 118 a: 255
r: 117 g: 111 b: 117 a: 255
r: 0 g: 28 b: 0 a: 255
r: 162 g: 161 b: 162 a: 255
r: 6 g: 45 b: 6 a: 255
r: 235 g: 233 b: 235 a: 255
r: 216 g: 215 b: 216 a: 255
r: 65 g: 66 b: 65 a: 255
r: 15 g: 58 b: 15 a: 255
r: 105 g: 106 b: 105 a: 255
r: 239 g: 238 b: 239 a: 255
r: 14 g: 90 b: 14 a: 255
r: 16 g: 68 b: 16 a: 255
r: 94 g: 96 b: 94 a: 255
r: 144 g: 135 b: 144 a: 255
r: 0 g: 6 b: 0 a: 255
r: 219 g: 221 b: 219 a: 255
r: 139 g: 135 b: 139 a: 255
r: 197 g: 197 b: 197 a: 255
r: 100 g: 101 b: 100 a: 255
r: 2 g: 85 b: 2 a: 255
r: 132 g: 127 b: 132 a: 255
r: 0 g: 58 b: 0 a: 255
r: 227 g: 249 b: 227 a: 255
r: 175 g: 174 b: 175 a: 255
r: 95 g: 96 b: 95 a: 255
r: 87 g: 110 b: 87 a: 255
r: 18 g: 43 b: 18 a: 255
r: 187 g: 186 b: 187 a: 255
r: 217 g: 209 b: 217 a: 255
r: 114 g: 105 b: 114 a: 255
r: 225 g: 226 b: 225 a: 255
r: 217 g: 252 b: 217 a: 255
r: 232 g: 250 b: 232 a: 255
r: 246 g: 245 b: 246 a: 255
r: 1 g: 70 b: 1 a: 255
r: 252 g: 245 b: 252 a: 255
r: 174 g: 164 b: 174 a: 255
r: 245 g: 251 b: 245 a: 255
r: 11 g: 120 b: 11 a: 255
r: 134 g: 130 b: 134 a: 255
r: 177 g: 169 b: 177 a: 255
r: 183 g: 207 b: 183 a: 255
r: 104 g: 120 b: 104 a: 255
r: 159 g: 156 b: 159 a: 255
r: 101 g: 92 b: 101 a: 255
r: 112 g: 121 b: 112 a: 255
r: 108 g: 152 b: 108 a: 255
r: 62 g: 61 b: 62 a: 255
r: 91 g: 150 b: 91 a: 255
r: 166 g: 164 b: 166 a: 255
r: 204 g: 231 b: 204 a: 255
r: 222 g: 244 b: 222 a: 255
r: 213 g: 214 b: 213 a: 255
r: 141 g: 141 b: 141 a: 255
r: 188 g: 229 b: 188 a: 255
r: 5 g: 65 b: 5 a: 255
r: 194 g: 196 b: 194 a: 255
r: 109 g: 107 b: 109 a: 255
r: 20 g: 36 b: 20 a: 255
r: 5 g: 131 b: 5 a: 255
r: 201 g: 198 b: 201 a: 255
r: 244 g: 245 b: 244 a: 255
r: 232 g: 232 b: 232 a: 255
r: 13 g: 83 b: 13 a: 255
r: 207 g: 202 b: 207 a: 255
r: 74 g: 74 b: 74 a: 255
r: 202 g: 226 b: 202 a: 255
r: 234 g: 237 b: 234 a: 255
r: 77 g: 139 b: 77 a: 255
r: 1 g: 166 b: 1 a: 255
r: 91 g: 160 b: 91 a: 255
r: 67 g: 92 b: 67 a: 255
r: 82 g: 121 b: 82 a: 255
r: 16 g: 52 b: 16 a: 255
r: 245 g: 255 b: 245 a: 255
r: 150 g: 173 b: 150 a: 255
r: 122 g: 151 b: 122 a: 255
r: 149 g: 150 b: 149 a: 255
r: 71 g: 152 b: 71 a: 255
r: 69 g: 163 b: 69 a: 255
r: 1 g: 37 b: 1 a: 255
r: 204 g: 238 b: 204 a: 255
r: 132 g: 120 b: 132 a: 255
r: 190 g: 239 b: 190 a: 255
r: 69 g: 172 b: 69 a: 255
r: 103 g: 101 b: 103 a: 255
r: 3 g: 184 b: 3 a: 255
r: 94 g: 194 b: 94 a: 255
r: 18 g: 38 b: 18 a: 255
r: 8 g: 30 b: 8 a: 255
r: 118 g: 133 b: 118 a: 255
r: 14 g: 111 b: 14 a: 255
r: 12 g: 97 b: 12 a: 255
r: 6 g: 102 b: 6 a: 255
r: 104 g: 125 b: 104 a: 255
r: 94 g: 100 b: 94 a: 255
r: 20 g: 42 b: 20 a: 255
r: 164 g: 178 b: 164 a: 255
r: 146 g: 184 b: 146 a: 255
r: 159 g: 159 b: 159 a: 255
r: 248 g: 247 b: 248 a: 255
r: 91 g: 82 b: 91 a: 255
r: 208 g: 246 b: 208 a: 255
r: 53 g: 105 b: 53 a: 255
r: 147 g: 140 b: 147 a: 255
r: 242 g: 226 b: 242 a: 255
r: 244 g: 237 b: 244 a: 255
r: 41 g: 129 b: 41 a: 255
r: 155 g: 215 b: 155 a: 255
r: 143 g: 237 b: 143 a: 255
r: 87 g: 221 b: 87 a: 255
r: 162 g: 164 b: 162 a: 255
r: 219 g: 237 b: 219 a: 255
r: 100 g: 245 b: 100 a: 255
r: 32 g: 36 b: 32 a: 255
r: 16 g: 75 b: 16 a: 255
r: 194 g: 202 b: 194 a: 255
r: 52 g: 153 b: 52 a: 255
r: 18 g: 7 b: 18 a: 255
r: 255 g: 248 b: 255 a: 255
r: 10 g: 145 b: 10 a: 255
r: 165 g: 239 b: 165 a: 255
r: 132 g: 207 b: 132 a: 255
r: 85 g: 102 b: 85 a: 255
r: 83 g: 243 b: 83 a: 255
r: 108 g: 163 b: 108 a: 255
r: 92 g: 112 b: 92 a: 255
r: 83 g: 130 b: 83 a: 255
r: 74 g: 210 b: 74 a: 255
r: 235 g: 227 b: 235 a: 255
r: 53 g: 132 b: 53 a: 255
r: 53 g: 44 b: 53 a: 255
r: 100 g: 139 b: 100 a: 255
r: 59 g: 194 b: 59 a: 255
r: 179 g: 181 b: 179 a: 255
r: 40 g: 94 b: 40 a: 255
r: 142 g: 144 b: 142 a: 255
r: 81 g: 89 b: 81 a: 255
r: 118 g: 141 b: 118 a: 255
r: 131 g: 189 b: 131 a: 255
r: 55 g: 70 b: 55 a: 255
r: 146 g: 226 b: 146 a: 255
r: 5 g: 110 b: 5 a: 255
r: 176 g: 241 b: 176 a: 255
r: 229 g: 220 b: 229 a: 255
r: 190 g: 249 b: 190 a: 255
r: 158 g: 193 b: 158 a: 255
r: 233 g: 235 b: 233 a: 255
r: 198 g: 220 b: 198 a: 255
r: 106 g: 171 b: 106 a: 255
r: 73 g: 187 b: 73 a: 255
r: 68 g: 106 b: 68 a: 255
r: 213 g: 218 b: 213 a: 255
r: 28 g: 60 b: 28 a: 255
r: 160 g: 183 b: 160 a: 255
r: 86 g: 207 b: 86 a: 255
r: 185 g: 217 b: 185 a: 255
r: 89 g: 139 b: 89 a: 255
r: 199 g: 215 b: 199 a: 255
r: 40 g: 82 b: 40 a: 255
r: 140 g: 250 b: 140 a: 255
r: 74 g: 61 b: 74 a: 255
r: 125 g: 162 b: 125 a: 255
r: 55 g: 217 b: 55 a: 255
r: 8 g: 174 b: 8 a: 255
r: 87 g: 177 b: 87 a: 255
r: 129 g: 124 b: 129 a: 255
r: 71 g: 134 b: 71 a: 255
r: 149 g: 222 b: 149 a: 255
r: 36 g: 103 b: 36 a: 255
r: 153 g: 255 b: 153 a: 255
r: 49 g: 187 b: 49 a: 255
r: 61 g: 122 b: 61 a: 255
r: 37 g: 34 b: 37 a: 255
r: 104 g: 203 b: 104 a: 255
r: 27 g: 155 b: 27 a: 255
r: 157 g: 159 b: 157 a: 255
r: 100 g: 225 b: 100 a: 255
r: 60 g: 181 b: 60 a: 255
r: 157 g: 161 b: 157 a: 255
r: 177 g: 195 b: 177 a: 255
r: 159 g: 161 b: 159 a: 255
r: 126 g: 235 b: 126 a: 255
r: 161 g: 159 b: 161 a: 255

As you can see, there are two transparency entries right at the beginning of the palette with v4.0.4:

$ ./test | sort | uniq -d                                    
r: 71 g: 112 b: 76 a: 0

We assume that there is only one transparency index (a=0), right at the beginning of the palette. Does libimagequant guarantee that's the case (important for writing GIFs)?

Original issue: libvips/libvips#3090

wasm-pack build fail

error: failed to run custom build command for imagequant-sys v2.12.5
process didn't exit successfully: /Users/huangwutao/work/wx/rust/compress/target/release/build/imagequant-sys-819a3a811686dc69/build-script-build (exit code: 1)
--- stdout
OPT_LEVEL = Some("s")
TARGET = Some("wasm32-unknown-unknown")
HOST = Some("x86_64-apple-darwin")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
cargo:include=/Users/huangwutao/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/imagequant-sys-2.12.5
running: "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-std=c99" "-DNDEBUG=1" "-o" "/Users/huangwutao/work/wx/rust/compress/target/wasm32-unknown-unknown/release/build/imagequant-sys-6f6e8e655a58e3b1/out/libimagequant.o" "-c" "libimagequant.c"
cargo:warning=libimagequant.c:9:10: fatal error: 'stdio.h' file not found
cargo:warning=#include <stdio.h>
cargo:warning= ^~~~~~~~~
cargo:warning=1 error generated.
exit code: 1

--- stderr

error occurred: Command "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-std=c99" "-DNDEBUG=1" "-o" "/Users/huangwutao/work/wx/rust/compress/target/wasm32-unknown-unknown/release/build/imagequant-sys-6f6e8e655a58e3b1/out/libimagequant.o" "-c" "libimagequant.c" with args "clang" did not execute successfully (status code exit code: 1).

warning: build failed, waiting for other jobs to finish...
error[E0721]: await is a keyword in the 2018 edition
--> /Users/huangwutao/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/wasm-bindgen-backend-0.2.55/src/codegen.rs:454:79
|
454 | wasm_bindgen::__rt::IntoJsResult::into_js_result(#ret.await)
| ^^^^^ help: you can use a raw identifier to stay compatible: r#await

error: aborting due to previous error

For more information about this error, try rustc --explain E0721.
error: Could not compile wasm-bindgen-backend.

make static command doesnot work on Windows ,with minGW

I did as the README says. use "make static" command to build this library.But it failed.

this is the error:
./configure
process_begin: CreateProcess(NULL, env bash D:\Librarys\libimagequant-master\configure, ...) failed.
make (e=2):
mingw32-make: *** No rule to make target 'config.mk', needed by 'pam.o'. Stop.

I am not good at Makefile build system.Don't know what is going on.

Any help will be appreciated~

BTW, msvc brunch build fail with VS2015 too...

Missing link to GitHub Releases page

libimagequant has a useful GitHub releases page that lists each release tag; however, as far as I can tell, there's currently no link to it from anywhere. (I had to manually type the URL in.)

After the somewhat recent GitHub site layout change, the link to a repo's Releases page is normally located in the right sidebar, between About and Contributors. It can optionally be hidden, though, and that seems to be the case here. Since this project does have actual releases, the absence of a link to them is kind of confusing and misleading.

If this is a mistake, you can unhide the link by clicking the gear icon in the top-right corner of the sidebar, scrolling down a bit, and checking the "Releases" checkbox under "Include in the home page."

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.