Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 編譯libjpeg-turbo

android 編譯libjpeg-turbo

編輯:關於Android編程

最近解碼視頻生成的是yuv數據,然後需要生成jpg圖片,之前的方案是yuv-rgb-bmp-jpg這樣的話是很慢的,計算了時間大概要300ms左右,導致多次點擊照相,會造成視頻畫面的延遲,所以只能使用別的方案替代,在網上查詢libjpeg,所以打算使用libjpg-turbo來實現yuv轉換為jpg圖像。下面是使用ndk來交叉編譯libjpeg-turbo生成libjpeg-turbo.so。

1、從官網下載最新的libjpeg-turbo源碼,

2、解壓縮下載的文件,然後進入,並創建jni文件夾,最後將裡面的文件都拷貝到jni文件中

3、進入jni目錄,然後創建配置文件(例如jconfig.h,config.h),在終端輸入:


[cpp]
./configure --with-jpeg8 

 ./configure --with-jpeg8
就會生成


[cpp]
config.status: creating config.h 
config.status: creating jconfig.h 

config.status: creating config.h
config.status: creating jconfig.h4、接下來是創建Android.mk文件


[cpp] 
# 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) 

# 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)
5、然後在終端輸入ndk-build,結果如下:


[cpp]
root@zhangjie:/home/libjpeg-turbo-1.2.1/jni# ndk-build 
Android NDK: WARNING: Unsupported source file extensions in /home/libjpeg-turbo-1.2.1/jni/Android.mk for module jpeg     
Android NDK:   turbojpeg-mapfile     
Compile arm    : jpeg <= jcapimin.c 
Compile arm    : jpeg <= jcapistd.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 <= jcphuff.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 <= 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 <= jdphuff.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 <= jidctred.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 
Compile arm    : jpeg <= jaricom.c 
Compile arm    : jpeg <= jcarith.c 
Compile arm    : jpeg <= jdarith.c 
Compile arm    : jpeg <= turbojpeg.c 
Compile arm    : jpeg <= transupp.c 
Compile arm    : jpeg <= jdatadst-tj.c 
Compile arm    : jpeg <= jdatasrc-tj.c 
Compile arm    : simd <= jsimd_arm_neon.S 
Compile arm    : simd <= jsimd_arm.c 
StaticLibrary  : libsimd.a 
SharedLibrary  : libjpeg.so 
Install        : libjpeg.so => libs/armeabi/libjpeg.so 

root@zhangjie:/home/libjpeg-turbo-1.2.1/jni# ndk-build
Android NDK: WARNING: Unsupported source file extensions in /home/libjpeg-turbo-1.2.1/jni/Android.mk for module jpeg   
Android NDK:   turbojpeg-mapfile   
Compile arm    : jpeg <= jcapimin.c
Compile arm    : jpeg <= jcapistd.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 <= jcphuff.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 <= 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 <= jdphuff.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 <= jidctred.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
Compile arm    : jpeg <= jaricom.c
Compile arm    : jpeg <= jcarith.c
Compile arm    : jpeg <= jdarith.c
Compile arm    : jpeg <= turbojpeg.c
Compile arm    : jpeg <= transupp.c
Compile arm    : jpeg <= jdatadst-tj.c
Compile arm    : jpeg <= jdatasrc-tj.c
Compile arm    : simd <= jsimd_arm_neon.S
Compile arm    : simd <= jsimd_arm.c
StaticLibrary  : libsimd.a
SharedLibrary  : libjpeg.so
Install        : libjpeg.so => libs/armeabi/libjpeg.so


 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved