参考了 以下2篇文章 并作了一小点修改
http://recursify.com/blog/2013/05/25/building-freeimage-for-android
http://blog.sina.com.cn/s/blog_4119bd830100w7ov.html
1. 从官网下载FreeImage 3.15.4 的源码 http://freeimage.sourceforge.net/download.html
2. 新建安卓工程 Add Native Support
把FreeImage目录下的Source目录 和 Makefile.srcs复制到jni根目录下
3. 修改Android.mk为
- LOCAL_PATH := $(call my-dir)
- include $(LOCAL_PATH)/Makefile.srcs
- include $(CLEAR_VARS)
- LOCAL_MODULE := FreeImage
- LOCAL_C_INCLUDES := $(LOCAL_PATH)/Source \
- $(LOCAL_PATH)/Source/Metadata \
- $(LOCAL_PATH)/Source/FreeImageToolkit \
- $(LOCAL_PATH)/Source/LibJPEG \
- $(LOCAL_PATH)/Source/LibPNG \
- $(LOCAL_PATH)/Source/LibTIFF4 \
- $(LOCAL_PATH)/Source/ZLib \
- $(LOCAL_PATH)/Source/LibOpenJPEG \
- $(LOCAL_PATH)/Source/OpenEXR \
- $(LOCAL_PATH)/Source/OpenEXR/Half \
- $(LOCAL_PATH)/Source/OpenEXR/Iex \
- $(LOCAL_PATH)/Source/OpenEXR/IlmImf \
- $(LOCAL_PATH)/Source/OpenEXR/IlmThread \
- $(LOCAL_PATH)/Source/OpenEXR/Imath \
- $(LOCAL_PATH)/Source/LibRawLite \
- $(LOCAL_PATH)/Source/LibRawLite/dcraw \
- $(LOCAL_PATH)/Source/LibRawLite/internal \
- $(LOCAL_PATH)/Source/LibRawLite/libraw \
- $(LOCAL_PATH)/Source/LibRawLite/src
- LOCAL_SRC_FILES := $(SRCS)
- LOCAL_CPP_FEATURES := rtti exceptions
- #LOCAL_CFLAGS := -O3 -fPIC
- include $(BUILD_SHARED_LIBRARY)
4. 修改Application.mk为 全平台编译
- APP_STL := gnustl_static
- APP_ABI := all
- APP_OPTIM := release
或者只是ARM的
- NDK_TOOLCHAIN_VERSION:=4.8
- APP_STL := gnustl_static
- APP_CPPFLAGS := -std=c++11
- APP_ABI := armeabi
5. 找到LibTIFF4/tif_config.h 注释掉
- //#define HAVE_SEARCH_H 1
6. 由于编译会找不到LibRawLite\internal\dcraw_common.cpp最上面添加swab函数
- #include <stdint.h>
- #include <asm/byteorder.h>
- static void swab(const void *from, void *to, ssize_t n)
- {
- ssize_t i;
- if (n < 0)
- {
- return;
- }
- for (i = 0; i < (n / 2) * 2; i += 2)
- {
- *((uint16_t*)to + i) = __arch__swab16(*((uint16_t*)from + i));
- }
- }
OpenEXR有点兼容性的小BUG
解决办法是找到ImfHuf.cpp 修改下头文件包含的顺序
- #include <string.h>
- #include <cstring>
- #include <algorithm>
- #include <ImfHuf.h>
- #include <ImfInt64.h>
- #include <ImfAutoArray.h>
- #include "Iex.h"
- #include <assert.h>
8. 编译