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
Comments
Yes, if somebody helps with #151 I'm not using Windows, so I can't do it myself. |
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. |
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. |
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. |
Oh, OK, that will be very useful then! |
Here are the steps I've been using to compile pngquant on Windows using mingw-w64 and CMake:
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. |
I've got it working in C#: https://github.com/pornel/pngquant/blob/msvc/lib/libimagequant.cs |
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 : |
Hello,
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 |
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. |
Thank you kindly, @jibsen! 🎆 |
Thanks for tagging a new release, I've updated pngquant-winbuild. |
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. |
I am trying to build pngquant with this script cmake script. But during compilation I have this error:
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. |
OpenMP is optional, so you can probably just delete all lines referring to it. @jibsen may know more about that. |
Thanks for the answer. Has just removed these lines from code and the library was built. What it can affect? |
@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. |
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. |
just in case it could help, barely tested but it should work same with fast tweaks (should compress a bit better/faster, but less safe probably) edit : i used https://upload.wikimedia.org/wikipedia/fr/d/df/Firefox_2013_logo.png |
What changes are in the |
@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 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; |
Got it. Thanks. Library libimagequant built. |
Thanks for the new release, pngquant-winbuild updated to 2.9.0. |
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 |
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? |
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. |
I don't think CMake solves the problem of having libpng built. It will fail with missing headers, missing lib, like all the others. |
have such issue when try to install pngquant-bin on win10.
|
I can't help you with npm modules. Node is a completely different thing. Please ask npm module author about this. |
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 |
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. |
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 : |
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 Also try this: ./configure --extra-cflags=-m64 --extra-ldflags=-m64 |
I now use Rust/Cargo to build it on Windows. cargo build --release |
It seems pngquant can be complied on Windows platform, but need extra tools and there are not step-by-step guide for it available.
The text was updated successfully, but these errors were encountered: