libyuv—AndroidStudio 编译libyuv

来源:互联网 发布:二手索尼z3淘宝 编辑:程序博客网 时间:2024/05/17 22:20

libyuv是google 开源的用于实现对各种yuv数据之间的转换包括裁剪、缩放、旋转,以及yuv和rgb 之间的转换,底层有一部分代码是基于汇编实现的,大大提高了转换速度。在Android 平台下一般用于处理直接从摄像头获取的原始yuv数据。 Android studio 最新版的已经支持了ndk 编译了,支持原先的Android.mk方式编译个Cmake编译方式,这里才用原始的编译方式。我用的版本是2.3.2,ndk版本是r13b。

1.下载NDK r3b

https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip

2.在Project Structure 设置ndk 路径



Android.mk 文件内容

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_C_INCLUDES := \    ./jni/includeLOCAL_MODULE := libyuvLOCAL_LDLIBS := -ljnigraphics -llogLOCAL_SRC_FILES := \source/compare_common.cc \source/compare_gcc.cc \source/compare_neon64.cc \source/compare_win.cc \source/compare.cc \source/convert_argb.cc \source/convert_from_argb.cc \source/convert_from.cc \source/convert_jpeg.cc \source/convert_to_argb.cc \source/convert_to_i420.cc \source/convert.cc \source/cpu_id.cc \source/mjpeg_decoder.cc \source/mjpeg_validate.cc \source/planar_functions.cc \source/rotate_any.cc \source/rotate_argb.cc \source/rotate_common.cc \source/rotate_gcc.cc \source/rotate_mips.cc \source/rotate_neon64.cc \source/rotate_win.cc \source/rotate.cc \source/row_any.cc \source/row_common.cc \source/row_gcc.cc \source/row_mips.cc \source/row_neon64.cc \source/row_win.cc \source/scale_any.cc \source/scale_argb.cc \source/scale_common.cc \source/scale_gcc.cc \source/scale_mips.cc \source/scale_neon64.cc \source/scale_win.cc \source/scale.cc \source/video_common.ccifeq ($(TARGET_ARCH_ABI),armeabi-v7a)    LOCAL_CFLAGS += -DLIBYUV_NEON    LOCAL_SRC_FILES += \        source/compare_neon.cc.neon    \        source/rotate_neon.cc.neon     \        source/row_neon.cc.neon        \        source/scale_neon.cc.neonendifinclude $(BUILD_SHARED_LIBRARY)

Application.mk 内容

APP_PLATFORM := android-14APP_ABI := armeabi-v7a

gradle 配置

apply plugin: 'com.android.application'android {    compileSdkVersion 25    buildToolsVersion "25.0.3"    defaultConfig {        applicationId "com.example.libyuv"        minSdkVersion 15        targetSdkVersion 25        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    externalNativeBuild {        ndkBuild {            path "jni/Android.mk"        }    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    defaultConfig {        externalNativeBuild {            ndkBuild {                arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-14"                abiFilters "armeabi-v7a"            }        }    }}dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        exclude group: 'com.android.support', module: 'support-annotations'    })    compile 'com.android.support:appcompat-v7:25.3.1'    compile 'com.android.support.constraint:constraint-layout:1.0.2'    testCompile 'junit:junit:4.12'}

下载地址

https://github.com/XIAIBIANCHENG/android-libyuv