[Share] Compile IM6 with FFTW+HDRI using mingw64

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

[Share] Compile IM6 with FFTW+HDRI using mingw64

Post by henrywho »

A) Download the following:
  1. Minimalist GNU for Windows (http://sourceforge.net/projects/mingw/f ... -get-inst/)
  2. MinGW-builds (http://sourceforge.net/projects/mingwbu ... in32/sjlj/)
  3. zlib-1.2.7.tar.gz
  4. bzip2-1.0.6.tar.gz
  5. xz-5.0.4.tar.gz
  6. freetype-2.4.10.tar.gz
  7. libjpeg-turbo-1.2.1.tar.gz
  8. jbigkit-2.0.tar.gz
  9. jasper-1.900.1.zip
  10. libpng-1.5.13.tar.gz
  11. tiff-4.0.3.tar.gz
  12. libwebp-0.2.0.tar.gz
  13. lcms2-2.4.tar.gz
  14. fftw-3.3.2.tar.gz
  15. ImageMagick-6.8.0-1.tar.xz
B) Preparation:
  1. I believe we need a 64-bit Windows. I tried this procedure on XP64.
  2. run "mingw-get-inst-20120426.exe" and install everything, say, to c:\MinGW
  3. copy C:\MinGW\msys\1.0 to C:\msys
  4. extract "x64-4.7.2-release-win32-sjlj-rev0.7z" to, say, c:\mingw_gcc_472_x64_sjlj_rev0
  5. edit C:\msys\etc\fstab and keep one line only:

    Code: Select all

    c:/mingw_gcc_472_x64_sjlj_rev0 /mingw
  6. copy crypt32.dll, gdi32.dll, msimg32.dll, wldap32.dll, ws2_32.dll from C:\WINDOWS\system32 to c:\mingw_gcc_472_x64_sjlj_rev0\x86_64-w64-mingw32\lib as libcrypt32.dll, libgdi32.dll, libmsimg32.dll, libwldap32.dll, libws2_32.dll
  7. (not sure if this is correct) In c:\mingw_gcc_472_x64_sjlj_rev0\bin, make a copy of every .exe and name it as x86_64-w64-mingw32-[orig_name].exe (e.g. copy windres.exe as x86_64-w64-mingw32-windres.exe) in the same directory.
C) run C:\msys\msys.bat to start the MSYS environment.

D) run the following in the MSYS prompt to set up some parameters:

Code: Select all

export    CHOST="x86_64-w64-mingw32"
export  PREFDIR="/usr/local"
export  LDFLAGS="-L${PREFDIR}/lib"
export CPPFLAGS="-I${PREFDIR}/include"
export     LIBS=""
export   CFLAGS="-O2 -march=core2 -mfpmath=sse -mmmx -msse -msse2 -msse3 -mssse3"
export CXXFLAGS="-O2 -march=core2 -mfpmath=sse -mmmx -msse -msse2 -msse3 -mssse3"
(I choose these CFLAGS and CXXFLAGS for Core2-based CPU. If you are not sure, simply use "-O2 -mcpu=native")

E) compile and install the static library of zlib
  1. extract zlib-1.2.7.tar.gz and edit its "configure" script to suppress its checking of mingw. Change the line "MINGW* | mingw*)" to "MIINGW* | miingw*)"
  2. Code: Select all

    ./configure --static --64
    make clean
    make -j 4
    make install
F) compile and install the static library of bzip2
  1. extract bzip2-1.0.6.tar.gz and edit the corresponding lines of its Makefile:

    Code: Select all

    ...
    CC=$(CHOST)-gcc
    AR=$(CHOST)-ar
    RANLIB=$(CHOST)-ranlib
    ....
    CFLAGS=-Wall -Winline $(BIGFILES) -O2 -march=core2 -mfpmath=sse -mmmx -msse -msse2 -msse3 -mssse3
    ....
    	chmod a+x $(PREFIX)/bin/bzip2.exe
    	chmod a+x $(PREFIX)/bin/bunzip2.exe
    	chmod a+x $(PREFIX)/bin/bzcat.exe
    	chmod a+x $(PREFIX)/bin/bzip2recover.exe
    ....
    
  2. then compile and install:

    Code: Select all

    make clean
    make -j 4
    make install
    
G) compile and install the static library of xz

Code: Select all

export LIBS=""
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
make clean
make -j 4
make install-strip
H) compile and install the static library of freetype

Code: Select all

export LIBS=""
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
make clean
make -j 4
make install-strip
I) compile and install the static library of libjpeg-turbo
  1. Edit jmorecfg.h to avoid declaration clash with another mingw64 header

    Code: Select all

    ....
    /* typedef int boolean; */
    typedef unsigned char boolean;
    ....
    /* typedef long INT32; */
    typedef signed int INT32;
    ....
    
  2. then compile and install:

    Code: Select all

    export LIBS=""
    make distclean
    make clean
    ./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
    make clean
    make -j 4
    make install-strip
    
J) compile and install the static library of jbigkit
  1. edit Makefile

    Code: Select all

    ....
    CCFLAGS = -W -O2 -march=core2 -mfpmath=sse -mmmx -msse -msse2 -msse3 -mssse3
    ....
    
  2. then compile and install:

    Code: Select all

    make clean
    make -j 4
    mkdir ${PREFDIR}/man/man1
    mkdir ${PREFDIR}/man/man5
    cp ./libjbig/jbig.h             ${PREFDIR}/include
    cp ./libjbig/jbig85.h           ${PREFDIR}/include
    cp ./libjbig/jbig_ar.h          ${PREFDIR}/include
    cp ./libjbig/libjbig.a          ${PREFDIR}/lib
    cp ./libjbig/libjbig85.a        ${PREFDIR}/lib
    cp ./libjbig/tstcodec.exe       ${PREFDIR}/bin
    cp ./libjbig/tstcodec85.exe     ${PREFDIR}/bin
    cp ./pbmtools/jbgtopbm.exe      ${PREFDIR}/bin
    cp ./pbmtools/jbgtopbm85.exe    ${PREFDIR}/bin
    cp ./pbmtools/pbmtojbg.exe      ${PREFDIR}/bin
    cp ./pbmtools/pbmtojbg85.exe    ${PREFDIR}/bin
    cp ./pbmtools/jbgtopbm.1        ${PREFDIR}/man/man1
    cp ./pbmtools/pbmtojbg.1        ${PREFDIR}/man/man1
    cp ./pbmtools/pbm.5             ${PREFDIR}/man/man5
    cp ./pbmtools/pgm.5             ${PREFDIR}/man/man5
    
K) compile and install the static library of jasper

Code: Select all

export LIBS=""
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
make clean
make -j 4
make install-strip
L) compile and install the static library of tiff

Code: Select all

export LIBS=""
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
make clean
make -j 4
make install-strip
M) compile and install the static library of libwebp

Code: Select all

export LIBS=""
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
make clean
make -j 4
make install-strip
N) compile and install the static library of lcms2

Code: Select all

export LIBS="-ljbig -llzma"
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared
make clean
make -j 4
make install-strip
O) compile and install the static library of fftw

Code: Select all

export LIBS=""
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared --with-our-malloc --with-windows-f77-mangling --enable-threads --with-combined-threads --enable-fma --disable-alloca --enable-sse2
make clean
make -j 4
make install-strip
P) finally, compile ImageMagick 6

Code: Select all

export LIBS="-ljbig -llzma"
make distclean
make clean
./configure --host=${CHOST} --build=${CHOST} --target=${CHOST} --prefix=${PREFDIR} --enable-static --disable-shared --without-perl --without-magick-plus-plus --enable-hdri 
make clean
make -j 4
make install-strip
Q) To test and use the compiled static executables....
  1. create the directory you desire, say, c:\IM6
  2. copy ImageMagick-6.8.0-1/utilities/*.exe to c:\IM6
  3. copy ImageMagick-6.8.0-1/config/*.xml to c:\IM6
  4. before using the compiled executables, set the environmental variable:

    Code: Select all

    set MAGICK_CONFIGURE_PATH=c:\IM6
    
  5. as you can tell from the syntax, you do not need MSYS to run the executables
Comments welcomed.... especially on any mistakes.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [Share] Compile IM6 with FFTW+HDRI using mingw64

Post by fmw42 »

This would make a nice addition if a copy was place at viewtopic.php?f=4&t=14251
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: [Share] Compile IM6 with FFTW+HDRI using mingw64

Post by henrywho »

Should a "-fft -ift" roundtrip be producing a padded square picture? Both command below are producing a padded square picture with my own compile:

convert wizard.png wizard.png -fft -ift -quality 95 w3.png
convert wizard.png wizard.png +fft +ift -quality 95 w4.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [Share] Compile IM6 with FFTW+HDRI using mingw64

Post by fmw42 »

Yes. Unfortunately, the IM implementation of FFT will do that unless the image is square and even dimensions. Otherwise, it gets padded. See
http://www.imagemagick.org/script/comma ... ns.php#fft.

It was that way in the prototype development when converted to a proper IM command. The IM developers have not had the time to fix that issue. So you need to find the input image dimensions and if needed or anyway just crop the round trip back to the same size as the input.

For more details of using FFT/IFT in IM, see http://www.fmwconcepts.com/imagemagick/ ... urier.html and my FFT scripts below if using Linux, Mac OSX or presumably Windows/Cygwin or some other unix system under Windows, though limited testing in the Windows environment.

Note for use of +FFT +IFT, you properly need HDRI compilation of IM.

Any intermediate images from +FFT should be saved in some floating point format such as MPC or PFM (or MIFF or TIFF if -define quantum:format=floating-point as per http://www.imagemagick.org/script/comma ... php#define and http://www.imagemagick.org/script/forma ... tin-images
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: [Share] Compile IM6 with FFTW+HDRI using mingw64

Post by henrywho »

fmw42 wrote:This would make a nice addition if a copy was place at viewtopic.php?f=4&t=14251
I will do so after some fine-tuning.

My compile is HDRI enabled already and it has FFTW statically linked in.

Actually, I want to build a shared-library compile of ImageMagick but its configure script is not generating DLLs when I specify "--disable-static --enable-shared".
Post Reply