最近解碼視頻生成的是yuv數據,然後需要生成jpg圖片,之前的方案是yuv-rgb-bmp-jpg這樣的話是很慢的,計算了時間大概要300ms左右,導致多次點擊照相,會造成視頻畫面的延遲,所以只能使用別的方案替代,在網上查詢libjpeg,但是又看了一篇文章說libjpeg-turbo比libjpeg快了2-3倍時間,所以打算使用libjpg-turbo來實現yuv轉換為jpg圖像。下面是使用ndk來交叉編譯libjpeg-turbo生成libjpeg-turbo.so。
1、從官網下載最新的libjpeg-turbo源碼,http://sourceforge.net/projects/libjpeg-turbo/ ,現在最新的版本是libjpeg-turbo-1.2.1
2、解壓縮下載的文件,然後進入,並創建jni文件夾,最後將裡面的文件都拷貝到jni文件中
3、進入jni目錄,然後創建配置文件(例如jconfig.h,config.h),在終端輸入:
./configure --with-jpeg8
就會生成
config.status: creating config.h
config.status: creating jconfig.h
4、接下來是創建Android.mk文件
# Makefile for libjpeg-turbo
##################################################
### simd ###
##################################################
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -D__ARM_HAVE_NEON
# 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_ARM_MODE=arm
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_ARM_MODE=arm
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS :=-O3 -fstrict-aliasing -fprefetch-loop-arrays -DANDROID \
-DANDROID_TILE_BASED_DECODE -DENABLE_ANDROID_NULL_CONVERT -D__ARM_HAVE_NEON
AM_CFLAGS := -march=armv7-a -mfpu=neon
AM_CCASFLAGS := -march=armv7-a -mfpu=neon
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_STATIC_LIBRARY)
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := libjpeg
include $(BUILD_SHARED_LIBRARY)