kornelski / pngquant

Lossy PNG compressor — pngquant command based on libimagequant library
https://pngquant.org
Other
5.16k stars 480 forks source link

Reorganisation #252

Open kornelski opened 7 years ago

kornelski commented 7 years ago

libimagequant separation

I'm increasing separation between pngquant CLI executable and imagequant library. Currently pngquant's build system assumes that files are lib/. I'm working on removing that assumption.

I'm rewriting the CLI part in Rust

I've had great success with Rust for my internal projects. For pngquant it has been a pain to support Windows and use 3rd party dependencies, and Rust fixes these problems (among many others).

Use of Rust is invisible from outside (it doesn't have any special runtime requirements), so for end users nothing will change.

Rust+Cargo will be required to build the pngquant executable, so this might require Linux distros shipping pngquant to figure out how to package it. Please open issues about this.

libimagequant stays backwards-compatible

For now the imagequant library will stay in pure C, and will support both Makefile-based build and Cargo. Nothing will change for you if you're embedding libimagequant as a static library or using it via .so, .dll, Java JNI or C# P/Invoke.

sergiomb2 commented 7 years ago

Due lack of time I hadn't do more but in Linux Fedora, we already have libimagequant built in separated package , also as tradition we use shared libraries , the current .so number is 0 [1] , numbering .so and do soname bumps should means abi/api changes ... So use just pngquant source + [2] ( to ./configure ignore git ) and [3] , I built pngquant package against already build libimagequant. What I like do ? add option --use-external-libimagequant to pngquant

[2]

 ln -s /usr/include/libimagequant.h lib/ 

[3] diff --git a/Makefile b/Makefile index 351a91e..4d601f0 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,9 @@ TESTBIN = test/test

all: $(BIN)

-ifeq ($(SHARED),1)
+ifeq ($(EXTERN_SHARED),1)
+  LIB = -limagequant
+else ifeq ($(SHARED),1)
   LIB=$(SHAREDLIB)
 else
   LIB=$(STATICLIB)

[1] /usr/lib64/libimagequant.so.0 https://koji.fedoraproject.org/koji/rpminfo?rpmID=9511806 https://koji.fedoraproject.org/koji/buildinfo?buildID=881445 https://koji.fedoraproject.org/koji/packageinfo?packageID=23506

kornelski commented 7 years ago

I've pushed changes to the build system.

./configure --with-libimagequant

will search for external library.

There are two things Fedora needs to change to make it work:

  1. /usr/lib64/libimagequant.so.0 is not found by -L/usr/lib64 -limagequant. It needs a symlink for libimagequant.so.

  2. libimagequant.h must be in /usr/include or use ./configure --with-libimagequant=<dir> and <dir>/include.

sergiomb2 commented 7 years ago

hello in reply , I'm testing build git master with new option --with-libimagequant and fail in make test when test run test/test, running test/test exit 1 and prints [1] even if build and run test/test.c just with

int main(void) {
    assert(printf("OK\n"));
    return 0;
}

[1]

<mock-chroot> sh-4.4#  test/test 
pngquant, 2.9.1 (June 2017), by Kornel Lesinski, Greg Roelofs.
   Compiled with OpenMP (multicore support).
   Color profiles are supported via Little CMS. Using libpng 1.6.29.

usage:  pngquant [options] [ncolors] -- pngfile [pngfile ...]
        pngquant [options] [ncolors] - >stdout <stdin

options:
  --force           overwrite existing output files (synonym: -f)
  --skip-if-larger  only save converted files if they're smaller than original
  --output file     destination file path to use instead of --ext (synonym: -o)
  --ext new.png     set custom suffix/extension for output filenames
  --quality min-max don't save below min, use fewer colors below max (0-100)
  --speed N         speed/quality trade-off. 1=slow, 3=default, 11=fast & rough
  --nofs            disable Floyd-Steinberg dithering
  --posterize N     output lower-precision color (e.g. for ARGB4444 output)
  --strip           remove optional metadata (default on Mac)
  --verbose         print status messages (synonym: -v)

Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette.
The output filename is the same as the input name except that
it ends in "-fs8.png", "-or8.png" or your custom extension (unless the
input is stdin, in which case the quantized image will go to stdout).
If you pass the special output path "-" and a single input file, that file
will be processed and the quantized image will go to stdout.
The default behavior if the output file exists is to skip the conversion;
use --force to overwrite. See man page for full list of options.
<mock-chroot> sh-4.4# echo $?
1
kornelski commented 7 years ago

Thanks. Fixed in 276f735178c9987226c11c0142ecb9695dca2370

sergiomb2 commented 7 years ago

It works correctly , thanks

sergiomb2 commented 7 years ago

Built it in Fedora rawhide [1] ... , maybe we can also add rust build , Fedora now got rust SIG [2], ah and now, at least for Linux Fedora (or shared libraries builds) , pngquant and libimagequant may have different versioning.

Best regards.

[1] https://koji.fedoraproject.org/koji/buildinfo?buildID=914580 https://src.fedoraproject.org/cgit/rpms/pngquant.git/diff/pngquant.spec?id=8d2ddda1c3e8db74415374e3c2a2bc9c5eb49e14

[2] https://fedoraproject.org/wiki/SIGs/Rust

kornelski commented 6 years ago

80f8d935fb75832b1f13199d356cedd5326c949e removes Cocoa reader from C/Makefile toolchain, and it's available only if built via Rust/Cargo.