Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we make the pngquant compiled on Windows platform? #166

Closed
henrygg opened this issue Aug 26, 2015 · 35 comments
Closed

Can we make the pngquant compiled on Windows platform? #166

henrygg opened this issue Aug 26, 2015 · 35 comments

Comments

@henrygg
Copy link

henrygg commented Aug 26, 2015

It seems pngquant can be complied on Windows platform, but need extra tools and there are not step-by-step guide for it available.

@kornelski
Copy link
Owner

Yes, if somebody helps with #151

I'm not using Windows, so I can't do it myself.

@rolftimmermans
Copy link
Contributor

We maintain a fork that uses CMake to build libimagequant for OS X/Linux/Windows. We chose CMake in favour of a VS project file, because CMake files can be maintained for all platforms. CMake appears to be the least horrible build system that works on Windows and Unix-like OSes.

If there's interest in switching to CMake for better Windows compatibility we can contribute the relevant changes. It also includes some changes to the C code similar to those in the msvc branch, which I guess would have to be incorporated somehow into master for this to work well.

Let me know if there's any interest.

@kornelski
Copy link
Owner

Does your CMake build use Visual Studio compiler and runtime DLLs? I'm interested in creating static libraries that VS projects like irfanview can use.

@rolftimmermans
Copy link
Contributor

CMake generates NMake files. NMake is a standard Makefile-like build tool that ships with and uses the MSVC compiler. There should no difference with a similarly compiled binary produced by Visual Studio, because the toolchain is the same.

CMake can also generate VS project files, but we find NMake easier to integrate.

@kornelski
Copy link
Owner

Oh, OK, that will be very useful then!

@jibsen
Copy link
Contributor

jibsen commented Oct 10, 2015

Here are the steps I've been using to compile pngquant on Windows using mingw-w64 and CMake:

  • Get zlib, libpng, and pngquant. Unpack all three in a folder, this should give you a subfolder for each.
  • Go into the zlib folder, and do cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=.. ., then make and make install. This will build zlib and install it into the top folder.
  • Go into the libpng folder, and do the same
  • Put this CMake script into the pngquant folder, enter it and do the same steps as for the other folders.

Now you have pngquant.exe along with the zlib and libpng dll files in the bin folder.

It is possible to build a static pngquant as well, but it requires a little more work.

This could work for MSVC as well, except for the fact that it does not support C99.

@kornelski
Copy link
Owner

I've got it working in C#:

https://github.com/pornel/pngquant/blob/msvc/lib/libimagequant.cs

@ghost
Copy link

ghost commented Jun 21, 2016

it's 2.7.2 - June 2016 with libpng 1.6.23 and zlib 1.2.8 with gcc 6.1.1. it should use the latest openmp implementation. it's barely tested, but should work :
http://css-ig.net/tools/public/pngquant.zip

@paperboyo
Copy link

paperboyo commented Aug 28, 2016

Hello,
I hardly know how to run cmd.exe. I have built pngquant.exe and libraries, but I have failed building little cms using above procedure (and https://github.com/mindw/little-CMS-cmake) :-(

make[2]: *** [CMakeFiles\testcms.dir\build.make:113: CMakeFiles/testcms.dir/testbed/zoo_icc.c.obj] Error 1
make[1]: *** [CMakeFiles\Makefile2:289: CMakeFiles/testcms.dir/all] Error 2
make: *** [Makefile:138: all] Error 2

And I have searched the whole of the interwebz to find Windows binary of pngquant with little cms colour profile support built in (ideally all as one exe).

I don’t suppose @cssignet would have one? 😊 All this is waaay above my understanding...

Regards
m.

@jibsen
Copy link
Contributor

jibsen commented Aug 29, 2016

I put the setup I currently use for building pngquant on Windows here, it includes Little CMS (though not tested). There are also some binaries built with mingw-w64.

@paperboyo
Copy link

Thank you kindly, @jibsen! 🎆

@ghost
Copy link

ghost commented Nov 16, 2016

@jibsen
Copy link
Contributor

jibsen commented Nov 16, 2016

Thanks for tagging a new release, I've updated pngquant-winbuild.

@jibsen
Copy link
Contributor

jibsen commented Dec 24, 2016

pngquant-winbuild updated to 2.8.2.

If you are interested @pornel, I have a branch that uses parg instead of getopt for parsing the command line options, which works with MSVC and other compilers that do not supply getopt.

@definename
Copy link

definename commented Dec 28, 2016

I am trying to build pngquant with this script cmake script. But during compilation I have this error:

Error 117 error C3019: increment in OpenMP 'for' statement has improper form [D:\install\libs\libpng\libpng_samples\build\vc12-x86\static_mt\libimagequant-prefix\src\libimagequant-build\imagequant.vcxproj] D:\install\libs\libpng\libpng_samples\build\vc12-x86\static_mt\libimagequant-prefix\src\libimagequant\lib\libimagequant.c 1196 1 libimagequant

The error occurs in this file in line 1196

What am I doing wrong and how can I fix this. Thanks.

P.S. I am using Visual Studio 2013, pngquant-2.8.2 from msvc branch.

@kornelski
Copy link
Owner

OpenMP is optional, so you can probably just delete all lines referring to it.

@jibsen may know more about that.

@definename
Copy link

Thanks for the answer. Has just removed these lines from code and the library was built. What it can affect?

@jibsen
Copy link
Contributor

jibsen commented Dec 28, 2016

@pornel, there were a few places I missed fixing for MSVC, but I didn't make a PR for them due to the getopt issue holding back compiling with MSVC as well. I'll take a look.

@definename, OpenMP support allows pngquant to use multithreading to speed up processing. Unless you are converting many large images it will probably not make a big difference. It's easier to build pngquant with mingw-w64.

@definename
Copy link

Got it. But I am going to use libimagequant internaly in my project in order to convert *.png images and my build system is Microsoft Visual Studio.

@ghost
Copy link

ghost commented Dec 28, 2016

just in case it could help, barely tested but it should work
2.8.2 - http://css-ig.net/tools/public/pngquant.zip

same with fast tweaks (should compress a bit better/faster, but less safe probably)
2.8.2m - http://css-ig.net/tools/public/pngquantm.zip

edit : i used m for my tests - it uses cloudflares zlib, and some changes like idat max size or critical chunks support only. gains are barely noticeable actually on G1820-2.7ghz, default option:

https://upload.wikimedia.org/wikipedia/fr/d/df/Firefox_2013_logo.png
659589 bytes - 2.917s - if you compare critical chunks only and idat combined, file is 658579 bytes
658450 bytes - 2.808s (m)

@kornelski
Copy link
Owner

What changes are in the m version?

@jibsen
Copy link
Contributor

jibsen commented Dec 28, 2016

@definename In that case you only need to build libimagequant. I believe you just have to move the declarations of the loop variables outside the loops in libimagequant.c and viter.c.

diff --git a/libimagequant.c b/libimagequant.c
index 3c78dcd..1c2b3b3 100644
--- a/libimagequant.c
+++ b/libimagequant.c
@@ -1191,9 +1191,10 @@ LIQ_NONNULL static float remap_to_palette(liq_image *const input_image, unsigned
     }
     viter_init(map, max_threads, average_color);
 
+    int row;
     #pragma omp parallel for if (rows*cols > 3000) \
         schedule(static) default(none) shared(average_color) reduction(+:remapping_error)
-    for(int row = 0; row < rows; ++row) {
+    for(row = 0; row < rows; ++row) {
         const f_pixel *const row_pixels = liq_image_get_row_f(input_image, row);
         unsigned int last_match=0;
         for(unsigned int col = 0; col < cols; ++col) {
diff --git a/viter.c b/viter.c
index a6e8b2d..d71f528 100644
--- a/viter.c
+++ b/viter.c
@@ -87,9 +87,10 @@ LIQ_PRIVATE double viter_do_iteration(histogram *hist, colormap *const map, vite
     const int hist_size = hist->size;
 
     double total_diff=0;
+    int j;
     #pragma omp parallel for if (hist_size > 3000) \
         schedule(static) default(none) shared(average_color,callback) reduction(+:total_diff)
-    for(int j=0; j < hist_size; j++) {
+    for(j=0; j < hist_size; j++) {
         float diff;
         unsigned int match = nearest_search(n, &achv[j].acolor, achv[j].tmp.likely_colormap_index, &diff);
         achv[j].tmp.likely_colormap_index = match;

@definename
Copy link

Got it. Thanks. Library libimagequant built.

@jibsen
Copy link
Contributor

jibsen commented Mar 3, 2017

Thanks for the new release, pngquant-winbuild updated to 2.9.0.

@JPeterMugaas
Copy link

If it helps, I did build libimagequant 2.8.2 for MINGW in the MSYS environment. I did have to tweek the configure script to do it. The work I had done is at:

https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-libimagequant

@kornelski
Copy link
Owner

kornelski commented Mar 22, 2017

I'm working on getting pngquant built via msvc toolchain. The main problem is getting libpng and zlib compiled.

I've heard nuget can help.

Can anybody help me how to download/configure/compile/install libpng via nuget, from a script?

@JPeterMugaas
Copy link

I'm thinking that maybe, one possibility might be redoing the configure build script to as a CMake (http://cmake.org) CMakeLists.txt file which Cmake could generate into a makefile. That way, it could possibly with with Visual Studio, MINGW, as well as some Unix-like systems.

@kornelski
Copy link
Owner

I don't think CMake solves the problem of having libpng built. It will fail with missing headers, missing lib, like all the others.

@TonyLuo
Copy link

TonyLuo commented Apr 5, 2017

have such issue when try to install pngquant-bin on win10.

PS D:\dev\jhipster\myApp> npm install --save pngquant-bin

pngquant-bin@3.1.1 postinstall D:\dev\jhipster\myApp\node_modules\pngquant-bin
node lib/install.js

‼ unable to verify the first certificate
‼ pngquant pre-build test failed
i compiling from source
× RequestError: pngquant failed to build, make sure that libpng-dev is installed
at ClientRequest. (D:\dev\jhipster\myApp\node_modules\got\index.js:74:21)
at ClientRequest.g (events.js:291:16)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at emitErrorNT (net.js:1278:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
my-app@0.0.0 D:\dev\jhipster\myApp
+-- UNMET PEER DEPENDENCY @angular/compiler@2.4.9
+-- UNMET PEER DEPENDENCY @angular/core@2.4.9
+-- pngquant-bin@3.1.1
`-- UNMET PEER DEPENDENCY zone.js@0.8.2

@kornelski
Copy link
Owner

I can't help you with npm modules. Node is a completely different thing. Please ask npm module author about this.

@Aliceljm1
Copy link

Aliceljm1 commented Apr 6, 2017

Hi @pornel ,I am trying to use libimagequant in c#, I just build imagequant.dll successful, when I use https://github.com/ImageOptim/libimagequant/blob/msvc/libimagequant.cs this class to test the dll get a error "System.BadImageFormatException An attempt was ma
de to load a program with an incorrect format.." Do you know why? If you can send your c# demo to my it's help a lot PS: I use .net 4.

@kornelski
Copy link
Owner

This errors means your DLL is 32-bit and C# program is 64-bit (or the DLL is 64-bit and C# is 32-bit). Build the DLL again with settings to match requirements of C# programs.

@Aliceljm1
Copy link

Thanks @pornel ,I change c# project target to x86 and the dll is load success.But when I try to build a 64-bit imagequant.dll get errors :
gcc -m64 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall -std=c99 -I.
-O3 -DNDEBUG -DUSE_SSE=1 -msse -mfpmath=sse -Wno-unknown-pragmas -fexcess-precis
ion=fast -c -o pam.o pam.c
pam.c:1:0: sorry, unimplemented: 64-bit mode not compiled in
/* pam.c - pam (portable alpha map) utility library
^
: recipe for target 'pam.o' failed
I just add -m64 in CFLAGS, is that means pam.c can not build whit 64-mode?
PS: OS Is win7, mingw64

@kornelski
Copy link
Owner

The error means you have an old 32-bit-only version of mingw (it could be from an old installation that you have in PATH). Uninstall any 32-bit mingw and make sure only 64-bit mingw is installed and in PATH.

Also try this:

./configure --extra-cflags=-m64 --extra-ldflags=-m64

@kornelski
Copy link
Owner

I now use Rust/Cargo to build it on Windows.

cargo build --release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants