Porting ImageMagick to Android platform under Windows

Source: Internet
Author: User
Tags imagemagick

Porting ImageMagick to Android platform under Windows

Original link Http://www.pedant.cn/2014/06/18/imagemagick-ported-android/

ImageMagick is a software used to create, edit, and synthesize pictures. It can read, convert, and write images in many formats. In the mobile platform to do some more complex image processing, it is inevitable that the great God. The official website also shows that it can run on multiple platforms, including Android. However, the official releases version is only UNIX, Mac OS X, IOS, Windows, and has a ready-made binary package for all Android architectures. But fortunately it is completely open source, we can completely download the source code and then cross-compile (cross-compile) out of the arm, x86, MIPS operating system of static link library, so that the current Android full platform to run up.

Generally we are in the Windows platform, but to cross-compile with the source code (source Cross-compile) to use the GNU environment, if the installation of a single Linux virtual machine to compile the process is too cumbersome. We can use the MinGW tool on Windows to simulate a set of GNU environments.

In addition, compiling ImageMagick is not enough, our program usually reads in some common format pictures (JPEG, PNG), and may need to do some graphics matching and color scatter statistics (FFTW), etc. This way we need to compile some other projects and then hand it over to the ImageMagick agent. It also requires some dependency packages, and the entire compilation process will require you to have other environments on your machine. On the whole I used the following:

    • MinGW v0.6.2
    • Android NDK (android-ndk-r9c)
    • fftw-3.3.4 (Fast discrete Fourier transform processing library)
    • JPEGSRC.V9A (JPEG, JPG picture format processing library)
    • libpng-1.6.13 (PNG image format processing library)
    • ImageMagick-6.8.8 (Main Library)

All the resources are used here. Http://yunpan.cn/Q7Uxr5T3XRxIa (Extract code: 2B2F) at the cloud disk.

1.MinGW Installation

工欲善其事 its prerequisite. Only when the necessary environment is ready, the work will be more effective. The latest version of MinGW you can download from here Http://sourceforge.net/projects/mingw to the latest EXE installer. Http://www.wowotech.net/soft/6.html also has a detailed installation process here, but it is important to note that we choose the C + + compiler and some msys make tools when MinGW Installation Manager chooses the installation package.

After the installation is complete, we can find Msys.bat under the msys\1.0 of the installation directory and from here we can start the command line. Before starting, we use the following command to download the beautification program mintty (the command line that comes with mintty is too difficult to use)

\$ Mingw-get Install Msys-mintty

After that, set up a shortcut to "install directory \msys\1.0\msys.bat-mintty" on the desktop and we'll start the command line from here.

2. Create independent tool chains for each platform

First the CD to the NDK directory (I'm android-ndk-r9c here)/build/tools, run the following three lines of code:

\$ make-standalone-toolchain.sh-platform=android-19-system=windows-x86_64-ndk-dir=/d/envcom/android-ndk-r9c- Install-dir=/d/opensrc/arm-19-toolchain

\$ make-standalone-toolchain.sh-platform=android-19-system=windows-x86_64-ndk-dir=/d/envcom/android-ndk-r9c- Install-dir=/d/opensrc/x86-19-toolchain-arch=x86

\$ make-standalone-toolchain.sh-platform=android-19-system=windows-x86_64-ndk-dir=/d/envcom/android-ndk-r9c- Install-dir=/d/opensrc/mips-19-toolchain-arch=mips

Note:/d/envcom/android-ndk-r9c is the NDK installation directory.

This generates the ARM, x86, MIPS three independent toolchain to Arm-19-toolchain, X86-19-toolchain, mips-19-toolchain three directories.

3. Cross-compiling each arm platform 1). Setting Environment Variables Path

Before compiling the static link library under the ARM platform, first set the environment variable path with the following command:

\$ Export path=.:/ D/opensrc/arm-19-toolchain/bin:/usr/local/bin:/mingw/bin:/bin

In this way, the compile-time lookup of the various executing programs (compiler gcc,g++, linker) will go to these directories to match.

2). Set environment variable Include_path

If you do not set the header file default lookup location, MinGW will go down to the Include folder of its installation directory, which is quite dangerous. Because the set of instructions run varies according to the target platform for cross-compilation, the configuration and Parameter objects in the header file will be different. Exceptions can occur at cross-compilation if the header file references an error, configure or make. We now have to execute the following command against the arm instruction set:

\$ Export C_include_path=/d/opensrc/arm-19-toolchain/sysroot/usr/include

\$ Export Cplus_include_path=/d/opensrc/arm-19-toolchain/sysroot/usr/include

Try to use-with-sysroot=/d/opensrc/arm-19-toolchain/sysroot to replace the above approach when configure, but it doesn't work.

Another attempt is to append the C_include_path and Cplus_include_path configurations directly to the end of the Configure command to replace the above, although the last listed manifest does not have an exception, but an exception occurs next to make.

3). Cross-compiling FFTW

First CD to FFTW source directory, configure project. There are different commands and configurations depending on where the target files are installed. You can choose to install directly into the MINGW environment (the default) for all future projects that need to be used. can also be installed directly to the ImageMagick source directory under the FFTW, only for ImageMagick project cross-compilation use. I'll explain both of them here.

to install to the MINGW environment , perform the following commands:

\$./configure-host=arm-linux-androideabi-disable-shared

\$ make

\$ make Install

Also need to change the environment variables, tell the link library file and header file explicit reference location

\$ Export C_include_path=/d/opensrc/arm-19-toolchain/sysroot/usr/include:/usr/local/include

\$ export libs= "-l/usr/local/lib"

to install to the ImageMagick directory , you only need to perform the following three commands:

\$./configure-host=arm-linux-androideabi-disable-shared-prefix=/d/opensrc/imgic-6.8.8/fftw-libdir=/d/opensrc/ Imgic-6.8.8/fftw-includedir=/d/opensrc/imgic-6.8.8/fftw

\$ make

\$ make Install

Note:/d/opensrc/imgic-6.8.8 for ImageMagick source directory

Here you need to explain why the FFTW and the following JPEG, PNG project generated target files are installed in both of these ways? whether installing to the MINGW environment or the ImageMagick directory, the goal is to allow configure programs to discover FFTW, JPEG, and PNG when cross-compiling imagemagick, so that ImageMagick-generated target files support them. Otherwise ImageMagick test failed, we can not use this kind of image format or function in the ImageMagick static library when the Android JNI is developed.

4). Cross-compiling Libjpeg

First CD to the JPEG source directory, configure project. The whole process is similar to FFTW cross-compiling. The difference is that if you install to the MINGW environment, it is no longer necessary to set the environment variables, because the FFTW compilation has been set up ( Note that FFTW, JPEG, PNG can only choose the same installation method, not two items installed to different locations ). If you install to the ImageMagick directory, change the directory name FFTW to JPEG. Details are as follows:

Install to MINGW environment:

\$./configure-host=arm-linux-androideabi-disable-shared

\$ make

\$ make Install

To install to the ImageMagick directory, you only need to perform the following three commands:

\$./configure-host=arm-linux-androideabi-disable-shared-prefix=/d/opensrc/imgic-6.8.8/jpeg-libdir=/d/opensrc/ Imgic-6.8.8/jpeg-includedir=/d/opensrc/imgic-6.8.8/jpeg

\$ make

\$ make Install

5). Cross-compiling libpng

First CD to PNG source directory, configure project. The whole process is similar to FFTW cross-compiling. If you install to the ImageMagick directory, just change the directory name FFTW to PNG.

6). Cross-compiling ImageMagick

With these preparatory work, cross-compiling imagemagick is much easier.

Direct CD to ImageMagick source directory, execute the following command:

\$./configure-host=arm-linux-androideabi-prefix=/d/opensrc/imgic-out-disable-shared-disable-opencl- disable-largefile-without-perl-without-x-disable-openmp-without-bzlib-without-freetype-without-rsvg- Enable-delegate-build

If you install FFTW, JPEG, and PNG into the ImageMagick directory, be sure to turn on the-enable-delegate-build switch.

Here we close some unused switches,-prefix=/d/opensrc/imgic-out the output directory. After knocking in, a cup of coffee time, you will see the command line generated a list like the following.

Look at the FFTW, JPEG, PNG, imagemagick++ are yes, you can safely continue to perform make, but also a cup of coffee time, you can make the install. So our first set of ImageMagick static link libraries based on the arm mobile platform is done.

4. Cross-compiling the x86 platform

Cross-compiling the x86 platform is basically the same as the cross-compiling arm platform, and the difference between some directories and settings is slightly different .

    • Make clean before each source directory make
    • Replace the arm-19-toolchain of all commands in the arm process with X86-19-toolchain
    • Replace the-host=arm-linux-androideabi of all commands in the arm process with -host=i686-linux-android
5. Cross-compiling MIPS platform

Cross-compiling MIPS platform and cross-compiling arm platform is basically the same process, the difference is the middle of some directories and settings slightly different .

    • Make clean before each source directory make
    • Replace the arm-19-toolchain of all commands in the arm process with Mips-19-toolchain
    • Replace the-host=arm-linux-androideabi of all commands in the arm process with -host=mipsel-linux-android

At this point, the static link libraries under all instruction set schemas in the Android platform are cross-compiled. This allows us to use each static library (. A file) as a separate module when the JNI encoding is packaged.

Final generated target file collection Package I also put it on the cloud disk. Http://yunpan.cn/Q7UxIiMiaDyXG (extract code: f297).

Porting ImageMagick to Android platform under Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.