안드로이드앱에서 TurboJpeg library를 사용하기
방법
Android Framework에 포함시키기 위해서는 Android.mk Application.mk 작업이 필요함.
GitHub등에서서 소개되는 방식이나 소개되는 version이 1.1.x 대로 1.4.x version을 적용하려고 함.
사전준비
NDK 설치 Linux Machine
StandAlone NDK 설치된 Linux Machine
ndk-build를 이용하는 경우 Android.mk 필요
$NDK/ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_ABI=armeabi-v7a
or
$NDK/ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_ABI=armeabi
Android.mk
# Makefile for libjpeg-turbo
ifneq ($(TARGET_SIMULATOR),true)
##################################################
### simd ###
##################################################
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
ifeq ($(ARCH_ARM_HAVE_NEON),true)
LOCAL_CFLAGS += -D__ARM_HAVE_NEON
endif
# From autoconf-generated Makefile
EXTRA_DIST = simd/nasm_lt.sh simd/jcclrmmx.asm simd/jcclrss2.asm simd/jdclrmmx.asm simd/jdclrss2.asm \
simd/jdmrgmmx.asm simd/jdmrgss2.asm simd/jcclrss2-64.asm simd/jdclrss2-64.asm \
simd/jdmrgss2-64.asm simd/CMakeLists.txt
libsimd_SOURCES_DIST = simd/jsimd_arm_neon.S \
simd/jsimd_arm.c
LOCAL_SRC_FILES := $(libsimd_SOURCES_DIST)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/simd \
$(LOCAL_PATH)/android
AM_CFLAGS := -march=armv7-a -mfpu=neon
AM_CCASFLAGS := -march=armv7-a -mfpu=neon
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := libsimd
include $(BUILD_STATIC_LIBRARY)
######################################################
### libjpeg.so ##
######################################################
include $(CLEAR_VARS)
# From autoconf-generated Makefile
libjpeg_SOURCES_DIST = jcapimin.c jcapistd.c jccoefct.c jccolor.c \
jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
jcomapi.c jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c \
jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \
jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c \
jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c \
jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c \
jaricom.c jcarith.c jdarith.c \
turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c \
turbojpeg-mapfile
LOCAL_SRC_FILES:= $(libjpeg_SOURCES_DIST)
#LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_STATIC_LIBRARIES := libsimd
LOCAL_C_INCLUDES := $(LOCAL_PATH)
standalone toolchain 을 사용하는 경우
ToolChain 위치
aarch64 : /opt/crosstools/ndkr16b64/
arm : /opt/crosstools/ndkr16b32/
aarch64용
./configure --host=aarch64-linux-android --build=x86_64-linux-gnu --target=aarch64-linux-android CC=/opt/crosstools/ndkr16b64/bin/aarch64-linux-android-gcc AR=/opt/crosstools/ndkr16b64/bin/aarch64-linux-android-ar STRIP=/opt/crosstools/ndkr16b64/bin/aarch64-linux-android-strip RANLIB=/opt/crosstools/ndkr16b64/bin/aarch64-linux-android-ranlib --prefix=/home/jhlim SYSROOT=/opt/crosstools/ndkr16b64
arm(32bit)용
./configure --host=aarch64-linux-android --build=x86_64-linux-gnu --target=arm-linux-androideabi CC=/opt/crosstools/ndkr16b32/bin/arm-linux-androideabi-gcc AR=/opt/crosstools/ndkr16b32/bin/arm-linux-androideabi-ar STRIP=/opt/crosstools/ndkr16b32/bin/arm-linux-androideabi-strip RANLIB=/opt/crosstools/ndkr16b32/bin/arm-linux-androideabi-ranlib --prefix=/home/jhlim SYSROOT=/opt/crosstools/ndkr16b32
빌드결과 libturbojpeg.so
Android Studio 적용
CMakeLists.txt
# turbojpeg
add_library(jpeg-lib SHARED IMPORTED)
set_target_properties(jpeg-lib PROPERTIES IMPORTED_LOCATION ${CPP_DIR}/libs/${ANDROID_ABI}/libturbojpeg.so)
정리
- BSP에 포함시키려면 Android.mk를 작성하는것이 필요함.
- Apk에 포함시키려면 StandAlone Toolchain으로 crosscompile하는것이 용이함
댓글