之前需要将yuv转换为jpg图像,查看网上说libjpeg-turbo比libjpeg快2-3倍,但是在android手机上实践了一下,需要40-60个ms,这个虽然比以前的300ms好多了,但是还是不能满足我的要求,进一步查看了网上信息,libjpeg-turbo是为x86和x86-64进行优化的使用了SIMD指令,而手机上不支持,所以需要在试验一下libjpeg的需要。下面是我的编译步骤:
1、先到官网上下载源码http://www.ijg.org/files/jpegsr9.zip 最新的是jpegsr9
2、然后加压,生成jpeg-9,进入并创建jni目录,将里面的内容都拷贝到jni里面
3、生成配置文件,在jni目录下面创建config.sh文件,然后在里面添加:
NDK=/opt/android-ndk-r8d PLATFORM=$NDK/platforms/android-8/arch-arm/ PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 CC=$PREBUILT/bin/arm-linux-androideabi-gcc ./configure --prefix=/home/jpeg-9/jni/dist --host=arm CC="$CC --sysroot=$PLATFORM"4、然后改变config.sh的权限,并执行,得到配置文件:
chmod 775 config.sh sh config.sh
LOCAL_PATH := $(my-dir) include $(CLEAR_VARS) # From autoconf-generated Makefile LOCAL_MODULE := libjpeg LOCAL_ARM_MODE=arm LOCAL_SRC_FILES := \ jaricom.c \ jcapimin.c \ jcapistd.c \ jcarith.c \ jccoefct.c \ jccolor.c \ jcdctmgr.c \ jchuff.c \ jcinit.c \ jcmainct.c \ jcmarker.c \ jcmaster.c \ jcomapi.c \ jcparam.c \ jcprepct.c \ jcsample.c \ jctrans.c \ jdapimin.c \ jdapistd.c \ jdarith.c \ jdatadst.c \ jdatasrc.c \ jdcoefct.c \ jdcolor.c \ jddctmgr.c \ jdhuff.c \ jdinput.c \ jdmainct.c \ jdmarker.c \ jdmaster.c \ jdmerge.c \ jdpostct.c \ jdsample.c \ jdtrans.c \ jerror.c \ jfdctflt.c \ jfdctfst.c \ jfdctint.c \ jidctflt.c \ jidctfst.c \ jidctint.c \ jquant1.c \ jquant2.c \ jutils.c \ jmemmgr.c \ jmemnobs.c LOCAL_C_INCLUDES := $(LOCAL_PATH) LOCAL_CFLAGS :=-O3 -fstrict-aliasing -fprefetch-loop-arrays -DANDROID \ -DANDROID_TILE_BASED_DECODE -DENABLE_ANDROID_NULL_CONVERT include $(BUILD_SHARED_LIBRARY)
root@zhangjie:/home/jpeg-9/jni# ndk-build Compile arm : jpeg <= jaricom.c Compile arm : jpeg <= jcapimin.c Compile arm : jpeg <= jcapistd.c Compile arm : jpeg <= jcarith.c Compile arm : jpeg <= jccoefct.c Compile arm : jpeg <= jccolor.c Compile arm : jpeg <= jcdctmgr.c Compile arm : jpeg <= jchuff.c Compile arm : jpeg <= jcinit.c Compile arm : jpeg <= jcmainct.c Compile arm : jpeg <= jcmarker.c Compile arm : jpeg <= jcmaster.c Compile arm : jpeg <= jcomapi.c Compile arm : jpeg <= jcparam.c Compile arm : jpeg <= jcprepct.c Compile arm : jpeg <= jcsample.c Compile arm : jpeg <= jctrans.c Compile arm : jpeg <= jdapimin.c Compile arm : jpeg <= jdapistd.c Compile arm : jpeg <= jdarith.c Compile arm : jpeg <= jdatadst.c Compile arm : jpeg <= jdatasrc.c Compile arm : jpeg <= jdcoefct.c Compile arm : jpeg <= jdcolor.c Compile arm : jpeg <= jddctmgr.c Compile arm : jpeg <= jdhuff.c Compile arm : jpeg <= jdinput.c Compile arm : jpeg <= jdmainct.c Compile arm : jpeg <= jdmarker.c Compile arm : jpeg <= jdmaster.c Compile arm : jpeg <= jdmerge.c Compile arm : jpeg <= jdpostct.c Compile arm : jpeg <= jdsample.c Compile arm : jpeg <= jdtrans.c Compile arm : jpeg <= jerror.c Compile arm : jpeg <= jfdctflt.c Compile arm : jpeg <= jfdctfst.c Compile arm : jpeg <= jfdctint.c Compile arm : jpeg <= jidctflt.c Compile arm : jpeg <= jidctfst.c Compile arm : jpeg <= jidctint.c Compile arm : jpeg <= jquant1.c Compile arm : jpeg <= jquant2.c Compile arm : jpeg <= jutils.c Compile arm : jpeg <= jmemmgr.c Compile arm : jpeg <= jmemnobs.c SharedLibrary : libjpeg.so Install : libjpeg.so => libs/armeabi/libjpeg.so
7、由于我只想要编码所以精简了代码,将编译出的库只包含编码,不包含解码库,下面的代码如下,只需要替换Android.mk文件相同部分就可以:
LOCAL_SRC_FILES := jniffmpeg/AppDecodeH264.c \ jniffmpeg/yuv420rgb565.s \ jniffmpeg/yuv2jpg.c \ jpeg-9/jaricom.c \ jpeg-9/jcapimin.c \ jpeg-9/jcapistd.c \ jpeg-9/jcarith.c \ jpeg-9/jccoefct.c \ jpeg-9/jccolor.c \ jpeg-9/jcdctmgr.c \ jpeg-9/jchuff.c \ jpeg-9/jcinit.c \ jpeg-9/jcmainct.c \ jpeg-9/jcmarker.c \ jpeg-9/jcmaster.c \ jpeg-9/jcomapi.c \ jpeg-9/jcparam.c \ jpeg-9/jcprepct.c \ jpeg-9/jcsample.c \ jpeg-9/jctrans.c \ jpeg-9/jdatadst.c \ jpeg-9/jerror.c \ jpeg-9/jfdctflt.c \ jpeg-9/jfdctfst.c \ jpeg-9/jfdctint.c \ jpeg-9/jidctflt.c \ jpeg-9/jidctfst.c \ jpeg-9/jidctint.c \ jpeg-9/jquant1.c \ jpeg-9/jquant2.c \ jpeg-9/jutils.c \ jpeg-9/jmemmgr.c \ jpeg-9/jmemnobs.c