├── yuv
├── consumer-rules.pro
├── src
│ └── main
│ │ ├── cpp
│ │ ├── lib
│ │ │ ├── x86
│ │ │ │ └── libyuv.so
│ │ │ ├── x86_64
│ │ │ │ └── libyuv.so
│ │ │ ├── arm64-v8a
│ │ │ │ └── libyuv.so
│ │ │ └── armeabi-v7a
│ │ │ │ └── libyuv.so
│ │ ├── utils
│ │ │ └── logger.h
│ │ ├── include
│ │ │ ├── libyuv
│ │ │ │ ├── version.h
│ │ │ │ ├── rotate_argb.h
│ │ │ │ ├── basic_types.h
│ │ │ │ ├── scale_argb.h
│ │ │ │ ├── compare.h
│ │ │ │ ├── cpu_id.h
│ │ │ │ ├── convert_from.h
│ │ │ │ ├── compare_row.h
│ │ │ │ ├── rotate.h
│ │ │ │ ├── scale.h
│ │ │ │ ├── mjpeg_decoder.h
│ │ │ │ ├── video_common.h
│ │ │ │ ├── rotate_row.h
│ │ │ │ ├── convert_from_argb.h
│ │ │ │ ├── macros_msa.h
│ │ │ │ └── convert.h
│ │ │ └── libyuv.h
│ │ ├── CMakeLists.txt
│ │ └── easyyuv.cpp
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── theeasiestway
│ │ └── yuv
│ │ ├── entities
│ │ ├── ArgbFrame.kt
│ │ └── YuvFrame.kt
│ │ ├── Constants.kt
│ │ ├── FramesFactory.kt
│ │ └── YuvUtils.kt
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── yuv.aar
├── settings.gradle
├── app
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── drawable
│ │ │ ├── ic_camera_rear_24dp.xml
│ │ │ ├── ic_camera_front_24dp.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── java
│ │ └── com
│ │ │ └── theeasiestway
│ │ │ └── libyuvwrapper
│ │ │ ├── App.kt
│ │ │ ├── ControllerVideo.kt
│ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .idea
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── misc.xml
├── runConfigurations.xml
└── gradle.xml
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/yuv/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yuv.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/yuv.aar
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='LibyuvWrapper'
2 | include ':app'
3 | include ':yuv'
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EasyYUV
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/yuv/src/main/cpp/lib/x86/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/yuv/src/main/cpp/lib/x86/libyuv.so
--------------------------------------------------------------------------------
/yuv/src/main/cpp/lib/x86_64/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/yuv/src/main/cpp/lib/x86_64/libyuv.so
--------------------------------------------------------------------------------
/yuv/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/lib/arm64-v8a/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/yuv/src/main/cpp/lib/arm64-v8a/libyuv.so
--------------------------------------------------------------------------------
/yuv/src/main/cpp/lib/armeabi-v7a/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/yuv/src/main/cpp/lib/armeabi-v7a/libyuv.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | *.cxx
9 | app/.cxx/*
10 | .externalNativeBuild
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | *.cxx
9 | app/.cxx/*
10 | .externalNativeBuild
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/yuv/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | *.cxx
9 | app/.cxx/*
10 | .externalNativeBuild
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theeasiestway/android-yuv-utils/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jun 22 14:56:56 KRAT 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/theeasiestway/libyuvwrapper/App.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.libyuvwrapper
2 |
3 | import android.app.Application
4 | import androidx.camera.camera2.Camera2Config
5 | import androidx.camera.core.CameraXConfig
6 |
7 | class App: Application(), CameraXConfig.Provider {
8 |
9 | override fun getCameraXConfig(): CameraXConfig {
10 | return Camera2Config.defaultConfig()
11 | }
12 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_camera_rear_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/utils/logger.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Loboda Alexey on 27.03.2020.
3 | //
4 |
5 | #ifndef ANDROIDCODECPACK_LOGGER_H
6 | #define ANDROIDCODECPACK_LOGGER_H
7 | #include
8 |
9 |
10 | #define LOGE(tag, ...) __android_log_print(ANDROID_LOG_ERROR, tag, __VA_ARGS__)
11 | #define LOGW(tag, ...) __android_log_print(ANDROID_LOG_WARN, tag, __VA_ARGS__)
12 | #define LOGI(tag, ...) __android_log_print(ANDROID_LOG_INFO, tag, __VA_ARGS__)
13 | #define LOGD(tag, ...) __android_log_print(ANDROID_LOG_DEBUG, tag, __VA_ARGS__)
14 |
15 | #endif //ANDROIDCODECPACK_LOGGER_H
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_camera_front_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_VERSION_H_
12 | #define INCLUDE_LIBYUV_VERSION_H_
13 |
14 | #define LIBYUV_VERSION 1759
15 |
16 | #endif // INCLUDE_LIBYUV_VERSION_H_
17 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/yuv/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/yuv/src/main/java/com/theeasiestway/yuv/entities/ArgbFrame.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.yuv.entities
2 |
3 | import java.nio.ByteBuffer
4 |
5 | //
6 | // Created by Loboda Alexey on 25.06.2020.
7 | //
8 |
9 | class ArgbFrame {
10 |
11 | lateinit var data: ByteBuffer; private set
12 | var dataStride: Int = 0; private set
13 |
14 | var width: Int = 0; private set
15 | var height: Int = 0; private set
16 |
17 | fun fill(data: ByteBuffer, dataStride: Int, width: Int, height: Int) {
18 | this.data = data
19 | this.dataStride = dataStride
20 | this.width = width
21 | this.height = height
22 | }
23 |
24 | fun asArray(): ByteArray {
25 | return ByteBuffer.allocate(data.capacity()).put(data).array()
26 | }
27 |
28 | fun free() {
29 | data = ByteBuffer.allocate(1)
30 | dataStride = 0
31 | width = 0
32 | height = 0
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_H_
12 | #define INCLUDE_LIBYUV_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/compare.h"
16 | #include "libyuv/convert.h"
17 | #include "libyuv/convert_argb.h"
18 | #include "libyuv/convert_from.h"
19 | #include "libyuv/convert_from_argb.h"
20 | #include "libyuv/cpu_id.h"
21 | #include "libyuv/mjpeg_decoder.h"
22 | #include "libyuv/planar_functions.h"
23 | #include "libyuv/rotate.h"
24 | #include "libyuv/rotate_argb.h"
25 | #include "libyuv/row.h"
26 | #include "libyuv/scale.h"
27 | #include "libyuv/scale_argb.h"
28 | #include "libyuv/scale_row.h"
29 | #include "libyuv/version.h"
30 | #include "libyuv/video_common.h"
31 |
32 | #endif // INCLUDE_LIBYUV_H_
33 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/rotate_argb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_ROTATE_ARGB_H_
12 | #define INCLUDE_LIBYUV_ROTATE_ARGB_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/rotate.h" // For RotationMode.
16 |
17 | #ifdef __cplusplus
18 | namespace libyuv {
19 | extern "C" {
20 | #endif
21 |
22 | // Rotate ARGB frame
23 | LIBYUV_API
24 | int ARGBRotate(const uint8_t* src_argb,
25 | int src_stride_argb,
26 | uint8_t* dst_argb,
27 | int dst_stride_argb,
28 | int src_width,
29 | int src_height,
30 | enum RotationMode mode);
31 |
32 | #ifdef __cplusplus
33 | } // extern "C"
34 | } // namespace libyuv
35 | #endif
36 |
37 | #endif // INCLUDE_LIBYUV_ROTATE_ARGB_H_
38 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/yuv/src/main/java/com/theeasiestway/yuv/Constants.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.yuv
2 |
3 | //
4 | // Created by Loboda Alexey on 22.06.2020.
5 | //
6 |
7 | object Constants {
8 |
9 | //
10 | // Scale
11 | //
12 |
13 | /** If filtering is FILTER_NONE, a simple nearest-neighbor algorithm is
14 | * used. This produces basic (blocky) quality at the fastest speed.
15 | * If filtering is FILTER_BILINEAR, interpolation is used to produce a better
16 | * quality image, at the expense of speed.
17 | * If filtering is FILTER_BOX, averaging is used to produce ever better
18 | * quality image, at further expense of speed. */
19 |
20 | const val FILTER_NONE = 0 // Point sample; Fastest.
21 | const val FILTER_LINEAR = 1 // Filter horizontally only.
22 | const val FILTER_BILINEAR = 2 // Faster than box, but lower quality scaling down.
23 | const val FILTER_BOX = 3 // Highest quality.
24 |
25 | //
26 | // Rotate
27 | //
28 |
29 | const val ROTATE_0 = 0 // No rotation.
30 | const val ROTATE_90 = 90 // Rotate 90 degrees clockwise.
31 | const val ROTATE_180 = 180 // Rotate 180 degrees.
32 | const val ROTATE_270 = 270 // Rotate 270 degrees clockwise.
33 |
34 | }
--------------------------------------------------------------------------------
/yuv/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | consumerProguardFiles 'consumer-rules.pro'
16 |
17 | externalNativeBuild {
18 | cmake {
19 | cppFlags ""
20 | }
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 |
31 | externalNativeBuild {
32 | cmake {
33 | path "src/main/cpp/CMakeLists.txt"
34 | version "3.10.2"
35 | }
36 | }
37 |
38 | sourceSets.main {
39 | jniLibs.srcDir 'src/main/cpp/lib'
40 | }
41 | }
42 |
43 | dependencies {
44 | implementation fileTree(dir: 'libs', include: ['*.jar'])
45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46 | implementation 'androidx.appcompat:appcompat:1.1.0'
47 | implementation 'androidx.core:core-ktx:1.3.0'
48 | }
49 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | applicationId "com.theeasiestway.libyuvwrapper"
11 | minSdkVersion 21
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | externalNativeBuild {
17 | ndk {
18 | abiFilters 'armeabi-v7a' , 'arm64-v8a', 'x86', 'x86_64'
19 | }
20 | }
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 |
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 | implementation project (':yuv')
39 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
40 | implementation 'androidx.appcompat:appcompat:1.1.0'
41 | implementation 'androidx.core:core-ktx:1.3.0'
42 | implementation "androidx.camera:camera-camera2:1.0.0-beta05"
43 | implementation "androidx.camera:camera-view:1.0.0-alpha12"
44 | implementation "androidx.camera:camera-extensions:1.0.0-alpha12"
45 | implementation "androidx.camera:camera-lifecycle:1.0.0-beta05"
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/yuv/src/main/java/com/theeasiestway/yuv/FramesFactory.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.yuv
2 |
3 | import com.theeasiestway.yuv.entities.ArgbFrame
4 | import com.theeasiestway.yuv.entities.YuvFrame
5 | import java.nio.ByteBuffer
6 |
7 | //
8 | // Created by Loboda Alexey on 25.06.2020.
9 | //
10 |
11 | object FramesFactory {
12 |
13 | fun instanceYuv(dstWidth: Int, dstHeight: Int): YuvFrame {
14 | val yuvFrame = YuvFrame()
15 | val ySize = dstWidth * dstHeight
16 | val uvSize = dstWidth * dstHeight / 4
17 | val y = ByteBuffer.allocateDirect(ySize)
18 | val u = ByteBuffer.allocateDirect(uvSize)
19 | val v = ByteBuffer.allocateDirect(uvSize)
20 | val extra = if (dstWidth % 2 == 0) 0 else 1
21 | yuvFrame.fill(y, u, v, dstWidth, dstWidth / 2 + extra, dstWidth / 2 + extra, dstWidth, dstHeight)
22 | return yuvFrame
23 | }
24 |
25 | fun instanceYuv(width: Int, height: Int, rotationMode: Int): YuvFrame {
26 | val newFrame = YuvFrame()
27 | val outWidth = if (rotationMode == 90 || rotationMode == 270) height else width
28 | val outHeight = if (rotationMode == 90 || rotationMode == 270) width else height
29 | val ySize = outWidth * outHeight
30 | val uvSize = outWidth * outHeight / 4
31 | val y = ByteBuffer.allocateDirect(ySize)
32 | val u = ByteBuffer.allocateDirect(uvSize)
33 | val v = ByteBuffer.allocateDirect(uvSize)
34 | val extra = if (outWidth % 2 == 0) 0 else 1
35 | newFrame.fill(y, u, v, outWidth, outWidth / 2 + extra, outWidth / 2 + extra, outWidth, outHeight)
36 | return newFrame
37 | }
38 |
39 | fun instanceArgb(width: Int, height: Int): ArgbFrame {
40 | val newFrame = ArgbFrame()
41 | val data = ByteBuffer.allocateDirect((width * height) * 32)
42 | val extra = if (width % 2 == 0) 0 else 1
43 | val dataStride = width * 4 + extra
44 | newFrame.fill(data, dataStride, width, height)
45 | return newFrame
46 | }
47 | }
--------------------------------------------------------------------------------
/yuv/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.4.1)
7 |
8 | # Creates and names a library, sets it as either STATIC
9 | # or SHARED, and provides the relative paths to its source code.
10 | # You can define multiple libraries, and CMake builds them for you.
11 | # Gradle automatically packages shared libraries with your APK.
12 |
13 | add_library( # Sets the name of the library.
14 | easyyuv
15 |
16 | # Sets the library as a shared library.
17 | SHARED
18 |
19 | # Provides a relative path to your source file(s).
20 | easyyuv.cpp )
21 |
22 | include_directories(${PROJECT_SOURCE_DIR}/include)
23 |
24 | #add other prebuilt libraries
25 | add_library(yuv SHARED IMPORTED)
26 |
27 | set_target_properties(yuv PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/lib/${ANDROID_ABI}/libyuv.so)
28 |
29 | # Searches for a specified prebuilt library and stores the path as a
30 | # variable. Because CMake includes system libraries in the search path by
31 | # default, you only need to specify the name of the public NDK library
32 | # you want to add. CMake verifies that the library exists before
33 | # completing its build.
34 |
35 | find_library( # Sets the name of the path variable.
36 | log-lib
37 |
38 | # Specifies the name of the NDK library that
39 | # you want CMake to locate.
40 | log )
41 |
42 | # Specifies libraries CMake should link to your target library. You
43 | # can link multiple libraries, such as libraries you define in this
44 | # build script, prebuilt third-party libraries, or system libraries.
45 |
46 | target_link_libraries( # Specifies the target library.
47 | easyyuv
48 | yuv
49 | # Links the target library to the log library
50 | # included in the NDK.
51 | ${log-lib} )
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/basic_types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_
12 | #define INCLUDE_LIBYUV_BASIC_TYPES_H_
13 |
14 | #include // For size_t and NULL
15 |
16 | #if !defined(INT_TYPES_DEFINED) && !defined(GG_LONGLONG)
17 | #define INT_TYPES_DEFINED
18 |
19 | #if defined(_MSC_VER) && (_MSC_VER < 1600)
20 | #include // for uintptr_t on x86
21 | typedef unsigned __int64 uint64_t;
22 | typedef __int64 int64_t;
23 | typedef unsigned int uint32_t;
24 | typedef int int32_t;
25 | typedef unsigned short uint16_t;
26 | typedef short int16_t;
27 | typedef unsigned char uint8_t;
28 | typedef signed char int8_t;
29 | #else
30 | #include // for uintptr_t and C99 types
31 | #endif // defined(_MSC_VER) && (_MSC_VER < 1600)
32 | // Types are deprecated. Enable this macro for legacy types.
33 | #ifdef LIBYUV_LEGACY_TYPES
34 | typedef uint64_t uint64;
35 | typedef int64_t int64;
36 | typedef uint32_t uint32;
37 | typedef int32_t int32;
38 | typedef uint16_t uint16;
39 | typedef int16_t int16;
40 | typedef uint8_t uint8;
41 | typedef int8_t int8;
42 | #endif // LIBYUV_LEGACY_TYPES
43 | #endif // INT_TYPES_DEFINED
44 |
45 | #if !defined(LIBYUV_API)
46 | #if defined(_WIN32) || defined(__CYGWIN__)
47 | #if defined(LIBYUV_BUILDING_SHARED_LIBRARY)
48 | #define LIBYUV_API __declspec(dllexport)
49 | #elif defined(LIBYUV_USING_SHARED_LIBRARY)
50 | #define LIBYUV_API __declspec(dllimport)
51 | #else
52 | #define LIBYUV_API
53 | #endif // LIBYUV_BUILDING_SHARED_LIBRARY
54 | #elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__APPLE__) && \
55 | (defined(LIBYUV_BUILDING_SHARED_LIBRARY) || \
56 | defined(LIBYUV_USING_SHARED_LIBRARY))
57 | #define LIBYUV_API __attribute__((visibility("default")))
58 | #else
59 | #define LIBYUV_API
60 | #endif // __GNUC__
61 | #endif // LIBYUV_API
62 |
63 | // TODO(fbarchard): Remove bool macros.
64 | #define LIBYUV_BOOL int
65 | #define LIBYUV_FALSE 0
66 | #define LIBYUV_TRUE 1
67 |
68 | #endif // INCLUDE_LIBYUV_BASIC_TYPES_H_
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/scale_argb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_SCALE_ARGB_H_
12 | #define INCLUDE_LIBYUV_SCALE_ARGB_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/scale.h" // For FilterMode
16 |
17 | #ifdef __cplusplus
18 | namespace libyuv {
19 | extern "C" {
20 | #endif
21 |
22 | LIBYUV_API
23 | int ARGBScale(const uint8_t* src_argb,
24 | int src_stride_argb,
25 | int src_width,
26 | int src_height,
27 | uint8_t* dst_argb,
28 | int dst_stride_argb,
29 | int dst_width,
30 | int dst_height,
31 | enum FilterMode filtering);
32 |
33 | // Clipped scale takes destination rectangle coordinates for clip values.
34 | LIBYUV_API
35 | int ARGBScaleClip(const uint8_t* src_argb,
36 | int src_stride_argb,
37 | int src_width,
38 | int src_height,
39 | uint8_t* dst_argb,
40 | int dst_stride_argb,
41 | int dst_width,
42 | int dst_height,
43 | int clip_x,
44 | int clip_y,
45 | int clip_width,
46 | int clip_height,
47 | enum FilterMode filtering);
48 |
49 | // Scale with YUV conversion to ARGB and clipping.
50 | LIBYUV_API
51 | int YUVToARGBScaleClip(const uint8_t* src_y,
52 | int src_stride_y,
53 | const uint8_t* src_u,
54 | int src_stride_u,
55 | const uint8_t* src_v,
56 | int src_stride_v,
57 | uint32_t src_fourcc,
58 | int src_width,
59 | int src_height,
60 | uint8_t* dst_argb,
61 | int dst_stride_argb,
62 | uint32_t dst_fourcc,
63 | int dst_width,
64 | int dst_height,
65 | int clip_x,
66 | int clip_y,
67 | int clip_width,
68 | int clip_height,
69 | enum FilterMode filtering);
70 |
71 | #ifdef __cplusplus
72 | } // extern "C"
73 | } // namespace libyuv
74 | #endif
75 |
76 | #endif // INCLUDE_LIBYUV_SCALE_ARGB_H_
77 |
--------------------------------------------------------------------------------
/yuv/src/main/java/com/theeasiestway/yuv/entities/YuvFrame.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.yuv.entities
2 |
3 | import android.media.Image
4 | import java.nio.ByteBuffer
5 |
6 | //
7 | // Created by Loboda Alexey on 22.06.2020.
8 | //
9 |
10 | class YuvFrame {
11 |
12 | lateinit var y: ByteBuffer; private set
13 | lateinit var u: ByteBuffer; private set
14 | lateinit var v: ByteBuffer; private set
15 |
16 | var yStride: Int = 0; private set
17 | var uStride: Int = 0; private set
18 | var vStride: Int = 0; private set
19 |
20 | var width: Int = 0; private set
21 | var height: Int = 0; private set
22 |
23 | fun fill(y: ByteBuffer, u: ByteBuffer, v: ByteBuffer, yStride: Int, uStride: Int, vStride: Int, width: Int, height: Int) {
24 | this.y = y
25 | this.u = u
26 | this.v = v
27 | this.yStride = yStride
28 | this.uStride = uStride
29 | this.vStride = vStride
30 | this.width = width
31 | this.height = height
32 | }
33 |
34 | fun fill(image: Image) {
35 | for (i in 0 until 3) {
36 | when(i) {
37 | 0 -> {
38 | y = image.planes[i].buffer
39 | yStride = image.planes[i].rowStride
40 | }
41 | 1 -> {
42 | u = image.planes[i].buffer
43 | uStride = image.planes[i].rowStride
44 | }
45 | 2 -> {
46 | v = image.planes[i].buffer
47 | vStride = image.planes[i].rowStride
48 | }
49 | }
50 | }
51 | width = image.width
52 | height = image.height
53 | }
54 |
55 | /** experimental method */
56 | fun fill(width: Int, height: Int, data: ByteArray) {
57 | this.width = width
58 | this.height = height
59 |
60 | val yArr = ByteArray(width * height)
61 | val uArr = ByteArray(width * height / 4)
62 | val vArr = ByteArray(width * height / 4)
63 |
64 | System.arraycopy(data, 0, yArr, 0, yArr.size)
65 | System.arraycopy(data, yArr.size, uArr, 0, uArr.size)
66 | System.arraycopy(data, yArr.size + uArr.size, vArr, 0, uArr.size)
67 |
68 | y = ByteBuffer.allocateDirect(yArr.size).put(yArr)
69 | u = ByteBuffer.allocateDirect(uArr.size).put(uArr)
70 | v = ByteBuffer.allocateDirect(vArr.size).put(vArr)
71 |
72 | y.position(0)
73 | u.position(0)
74 | v.position(0)
75 | }
76 |
77 | fun asArray(): ByteArray {
78 | var array: ByteArray
79 |
80 | val yPos = y.position()
81 | val uPos = u.position()
82 | val vPos = v.position()
83 |
84 | try {
85 | array = ByteBuffer.allocate(y.capacity() + u.capacity() + v.capacity()).put(y).put(u).put(v).array()
86 | y.position(yPos)
87 | u.position(uPos)
88 | v.position(vPos)
89 | } catch (e: Exception) {
90 |
91 | array = ByteArray(size())
92 |
93 | y.get(array, 0, y.remaining())
94 | y.position(yPos)
95 |
96 | u.get(array, y.remaining(), u.remaining())
97 | u.position(uPos)
98 |
99 | v.get(array, y.remaining() + u.remaining(), v.remaining())
100 | v.position(vPos)
101 | }
102 | return array
103 | }
104 |
105 | fun size() = y.remaining() + u.remaining() + v.remaining()
106 |
107 | fun free() {
108 | y = ByteBuffer.allocate(1)
109 | u = ByteBuffer.allocate(1)
110 | v = ByteBuffer.allocate(1)
111 | yStride = 0
112 | uStride = 0
113 | vStride = 0
114 | width = 0
115 | height = 0
116 | }
117 | }
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/compare.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_COMPARE_H_
12 | #define INCLUDE_LIBYUV_COMPARE_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | // Compute a hash for specified memory. Seed of 5381 recommended.
22 | LIBYUV_API
23 | uint32_t HashDjb2(const uint8_t* src, uint64_t count, uint32_t seed);
24 |
25 | // Hamming Distance
26 | LIBYUV_API
27 | uint64_t ComputeHammingDistance(const uint8_t* src_a,
28 | const uint8_t* src_b,
29 | int count);
30 |
31 | // Scan an opaque argb image and return fourcc based on alpha offset.
32 | // Returns FOURCC_ARGB, FOURCC_BGRA, or 0 if unknown.
33 | LIBYUV_API
34 | uint32_t ARGBDetect(const uint8_t* argb,
35 | int stride_argb,
36 | int width,
37 | int height);
38 |
39 | // Sum Square Error - used to compute Mean Square Error or PSNR.
40 | LIBYUV_API
41 | uint64_t ComputeSumSquareError(const uint8_t* src_a,
42 | const uint8_t* src_b,
43 | int count);
44 |
45 | LIBYUV_API
46 | uint64_t ComputeSumSquareErrorPlane(const uint8_t* src_a,
47 | int stride_a,
48 | const uint8_t* src_b,
49 | int stride_b,
50 | int width,
51 | int height);
52 |
53 | static const int kMaxPsnr = 128;
54 |
55 | LIBYUV_API
56 | double SumSquareErrorToPsnr(uint64_t sse, uint64_t count);
57 |
58 | LIBYUV_API
59 | double CalcFramePsnr(const uint8_t* src_a,
60 | int stride_a,
61 | const uint8_t* src_b,
62 | int stride_b,
63 | int width,
64 | int height);
65 |
66 | LIBYUV_API
67 | double I420Psnr(const uint8_t* src_y_a,
68 | int stride_y_a,
69 | const uint8_t* src_u_a,
70 | int stride_u_a,
71 | const uint8_t* src_v_a,
72 | int stride_v_a,
73 | const uint8_t* src_y_b,
74 | int stride_y_b,
75 | const uint8_t* src_u_b,
76 | int stride_u_b,
77 | const uint8_t* src_v_b,
78 | int stride_v_b,
79 | int width,
80 | int height);
81 |
82 | LIBYUV_API
83 | double CalcFrameSsim(const uint8_t* src_a,
84 | int stride_a,
85 | const uint8_t* src_b,
86 | int stride_b,
87 | int width,
88 | int height);
89 |
90 | LIBYUV_API
91 | double I420Ssim(const uint8_t* src_y_a,
92 | int stride_y_a,
93 | const uint8_t* src_u_a,
94 | int stride_u_a,
95 | const uint8_t* src_v_a,
96 | int stride_v_a,
97 | const uint8_t* src_y_b,
98 | int stride_y_b,
99 | const uint8_t* src_u_b,
100 | int stride_u_b,
101 | const uint8_t* src_v_b,
102 | int stride_v_b,
103 | int width,
104 | int height);
105 |
106 | #ifdef __cplusplus
107 | } // extern "C"
108 | } // namespace libyuv
109 | #endif
110 |
111 | #endif // INCLUDE_LIBYUV_COMPARE_H_
112 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # android-yuv-utils
2 | CAUTION! The version from master branch actually works but has some issues like a lot of memory consumption and some other issues..
3 |
4 | Compiled [libyuv](https://chromium.googlesource.com/libyuv/libyuv/) Google library and wrapper for it for easy and fast scale, rotate, mirror and convert frames from android Camera2 or CameraX.
5 |
6 | ## Supported features:
7 | 1. Horizontal and/or vertical scaling.
8 | 2. Rotating by 90, 180 or 270 degrees.
9 | 3. Mirror horizontally or vertically.
10 | 4. Convert android YUV_420_8888 frame to ARGB.
11 |
12 | ## Supported ABIs:
13 | armeabi-v7a, arm64-v8a, x86, x86_64
14 |
15 | ## How to use
16 |
17 | #### Init library:
18 | ```kotlin
19 | val yuvUtils = YuvUtils() // getting library instance
20 | ```
21 |
22 | #### Prepare a frame from Camera2 or CameraX for scaling, rotating etc.:
23 | ```kotlin
24 | val image = ... // getting an image from Camera2 or CameraX api
25 | var yuvFrame = yuvUtils.convertToI420(image) // this step isn't mandatory but it may help you in case if the colors of the output frame (after scale, rotate etc.) are distorted
26 | ```
27 |
28 | #### Scale:
29 | ```kotlin
30 | /* the first way */
31 | val image = ... // getting an image from Camera2 or CameraX api
32 | val scaledWidth = image.width * 2 // getting current width and height
33 | val scaledHeight = image.height * 2 // of the image and for example double them
34 | yuvFrame = yuvUtils.scale(image, scaledWidth, scaledHeight, Constants.FILTER_BOX)
35 |
36 | /* the second way here yuvFrame was taken from the yuvUtils.convertToI420 method as showed above */
37 | val scaledWidth = yuvFrame.width * 2 // getting current width and height
38 | val scaledHeight = yuvFrame.height * 2 // of the image and for example double them
39 | yuvFrame = yuvUtils.scale(yuvFrame, scaledWidth, scaledHeight, Constants.FILTER_BOX)
40 | ```
41 |
42 | #### Rotate:
43 | ```kotlin
44 | val rotate = Constants.ROTATE_270 // setting the rotation angle
45 | yuvFrame = yuvUtils.rotate(image, rotate)
46 | /* or */
47 | yuvFrame = yuvUtils.rotate(yuvFrame, rotate)
48 | ```
49 |
50 | #### Mirror:
51 | ```kotlin
52 | /* for mirror horizontally */
53 | yuvFrame = yuvUtils.mirrorH(image)
54 | /* or */
55 | yuvFrame = yuvUtils.mirrorH(yuvFrame)
56 |
57 | /* for mirror vertically */
58 | yuvFrame = yuvUtils.mirrorV(image)
59 | /* or */
60 | yuvFrame = yuvUtils.mirrorV(yuvFrame)
61 | ```
62 |
63 | #### Convert to ARGB:
64 | ```kotlin
65 | val argbFrame = yuvUtils.yuv420ToArgb(image)
66 | /* or */
67 | val argbFrame = yuvUtils.yuv420ToArgb(yuvFrame)
68 | ```
69 |
70 | ## Project structure
71 | #### The project consists of two modules:
72 | - **app** - here you can find a sample app that demonsrates scaling, rotating, mirroring and converting procedures by capturing frames from device's camera.
73 | - **yuv** - here you can find a C++ class that interacts with [libyuv 1759](https://chromium.googlesource.com/libyuv/libyuv/+/c5e45dcae58f5cb3eb893f8000c1de88a8fe3c4e) and JNI wrapper for interacting with it from Java/Kotlin layer.
74 |
75 | #### Compiled library:
76 | - **yuv.aar** - it's a compiled library of **yuv** module that mentioned above, it placed in a root directory of the project, you can easily add it to your project using gradle dependencies. First you have to place **yuv.aar** in the libs folder of your project and then add to your build.gradle the following:
77 | ````groovy
78 | dependencies {
79 | implementation fileTree(dir: 'libs', include: '*.jar') // this line is necessary in order to allow gradle to take yuv.aar from "libs" dir
80 | implementation files('libs/yuv.aar') // dependency for yuv.aar library
81 | ... // other dependencies
82 | }
83 | ````
84 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/cpu_id.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_CPU_ID_H_
12 | #define INCLUDE_LIBYUV_CPU_ID_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | // Internal flag to indicate cpuid requires initialization.
22 | static const int kCpuInitialized = 0x1;
23 |
24 | // These flags are only valid on ARM processors.
25 | static const int kCpuHasARM = 0x2;
26 | static const int kCpuHasNEON = 0x4;
27 | // 0x8 reserved for future ARM flag.
28 |
29 | // These flags are only valid on x86 processors.
30 | static const int kCpuHasX86 = 0x10;
31 | static const int kCpuHasSSE2 = 0x20;
32 | static const int kCpuHasSSSE3 = 0x40;
33 | static const int kCpuHasSSE41 = 0x80;
34 | static const int kCpuHasSSE42 = 0x100; // unused at this time.
35 | static const int kCpuHasAVX = 0x200;
36 | static const int kCpuHasAVX2 = 0x400;
37 | static const int kCpuHasERMS = 0x800;
38 | static const int kCpuHasFMA3 = 0x1000;
39 | static const int kCpuHasF16C = 0x2000;
40 | static const int kCpuHasGFNI = 0x4000;
41 | static const int kCpuHasAVX512BW = 0x8000;
42 | static const int kCpuHasAVX512VL = 0x10000;
43 | static const int kCpuHasAVX512VBMI = 0x20000;
44 | static const int kCpuHasAVX512VBMI2 = 0x40000;
45 | static const int kCpuHasAVX512VBITALG = 0x80000;
46 | static const int kCpuHasAVX512VPOPCNTDQ = 0x100000;
47 |
48 | // These flags are only valid on MIPS processors.
49 | static const int kCpuHasMIPS = 0x200000;
50 | static const int kCpuHasMSA = 0x400000;
51 | static const int kCpuHasMMI = 0x800000;
52 |
53 | // Optional init function. TestCpuFlag does an auto-init.
54 | // Returns cpu_info flags.
55 | LIBYUV_API
56 | int InitCpuFlags(void);
57 |
58 | // Detect CPU has SSE2 etc.
59 | // Test_flag parameter should be one of kCpuHas constants above.
60 | // Returns non-zero if instruction set is detected
61 | static __inline int TestCpuFlag(int test_flag) {
62 | LIBYUV_API extern int cpu_info_;
63 | #ifdef __ATOMIC_RELAXED
64 | int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED);
65 | #else
66 | int cpu_info = cpu_info_;
67 | #endif
68 | return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag;
69 | }
70 |
71 | // Internal function for parsing /proc/cpuinfo.
72 | LIBYUV_API
73 | int ArmCpuCaps(const char* cpuinfo_name);
74 | LIBYUV_API
75 | int MipsCpuCaps(const char* cpuinfo_name);
76 |
77 | // For testing, allow CPU flags to be disabled.
78 | // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3.
79 | // MaskCpuFlags(-1) to enable all cpu specific optimizations.
80 | // MaskCpuFlags(1) to disable all cpu specific optimizations.
81 | // MaskCpuFlags(0) to reset state so next call will auto init.
82 | // Returns cpu_info flags.
83 | LIBYUV_API
84 | int MaskCpuFlags(int enable_flags);
85 |
86 | // Sets the CPU flags to |cpu_flags|, bypassing the detection code. |cpu_flags|
87 | // should be a valid combination of the kCpuHas constants above and include
88 | // kCpuInitialized. Use this method when running in a sandboxed process where
89 | // the detection code might fail (as it might access /proc/cpuinfo). In such
90 | // cases the cpu_info can be obtained from a non sandboxed process by calling
91 | // InitCpuFlags() and passed to the sandboxed process (via command line
92 | // parameters, IPC...) which can then call this method to initialize the CPU
93 | // flags.
94 | // Notes:
95 | // - when specifying 0 for |cpu_flags|, the auto initialization is enabled
96 | // again.
97 | // - enabling CPU features that are not supported by the CPU will result in
98 | // undefined behavior.
99 | // TODO(fbarchard): consider writing a helper function that translates from
100 | // other library CPU info to libyuv CPU info and add a .md doc that explains
101 | // CPU detection.
102 | static __inline void SetCpuFlags(int cpu_flags) {
103 | LIBYUV_API extern int cpu_info_;
104 | #ifdef __ATOMIC_RELAXED
105 | __atomic_store_n(&cpu_info_, cpu_flags, __ATOMIC_RELAXED);
106 | #else
107 | cpu_info_ = cpu_flags;
108 | #endif
109 | }
110 |
111 | // Low level cpuid for X86. Returns zeros on other CPUs.
112 | // eax is the info type that you want.
113 | // ecx is typically the cpu number, and should normally be zero.
114 | LIBYUV_API
115 | void CpuId(int info_eax, int info_ecx, int* cpu_info);
116 |
117 | #ifdef __cplusplus
118 | } // extern "C"
119 | } // namespace libyuv
120 | #endif
121 |
122 | #endif // INCLUDE_LIBYUV_CPU_ID_H_
123 |
--------------------------------------------------------------------------------
/app/src/main/java/com/theeasiestway/libyuvwrapper/ControllerVideo.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.codec_h264.camera
2 |
3 | import android.content.Context
4 | import android.content.res.Configuration
5 | import android.hardware.display.DisplayManager
6 | import android.media.Image
7 | import android.util.Log
8 | import android.util.Size
9 | import android.widget.Toast
10 | import androidx.camera.core.CameraSelector
11 | import androidx.camera.core.ImageAnalysis
12 | import androidx.camera.core.Preview
13 | import androidx.camera.lifecycle.ProcessCameraProvider
14 | import androidx.camera.view.PreviewView
15 | import androidx.core.content.ContextCompat
16 | import androidx.lifecycle.LifecycleOwner
17 | import com.google.common.util.concurrent.ListenableFuture
18 | import java.lang.ref.WeakReference
19 | import java.util.concurrent.Executors
20 |
21 | //
22 | // Created by Loboda Alexey on 22.06.2020.
23 | //
24 |
25 | object ControllerVideo {
26 |
27 | private lateinit var cameraProviderFuture: ListenableFuture
28 | private lateinit var cameraProvider: ProcessCameraProvider
29 | private lateinit var displayManager: DisplayManager
30 |
31 | private val executor = Executors.newSingleThreadExecutor()
32 | private var subscriptions = HashMap Unit>()
33 | private var isLandscape = false
34 | private var rotationCurrent = 0
35 | private var displayId = -1
36 | private var released = false
37 |
38 | fun initCamera(context: Context, @CameraSelector.LensFacing lensFacing: Int, previewView: PreviewView) {
39 | val lifecycleOwner = WeakReference(context as LifecycleOwner)
40 | destroyCamera()
41 | cameraProviderFuture = ProcessCameraProvider.getInstance(context).apply {
42 | addListener(Runnable {
43 | cameraProvider = cameraProviderFuture.get()
44 | val preview = Preview.Builder().setTargetName("CameraPreview").build()
45 | preview.setSurfaceProvider(previewView.createSurfaceProvider())
46 | startCamera(lifecycleOwner, cameraProvider, preview, lensFacing, displayId = previewView.display.displayId, onError = {
47 | Toast.makeText(context, "Unable to init camera", Toast.LENGTH_LONG).show()
48 | })
49 | }, ContextCompat.getMainExecutor(context))
50 | }
51 | }
52 |
53 | private fun startCamera(lifecycleOwner: WeakReference, cameraProvider: ProcessCameraProvider, preview: Preview, facing: Int, displayId: Int, onError: () -> Unit) {
54 | try {
55 | cameraProvider.unbindAll()
56 |
57 | if (lifecycleOwner.get() == null) return
58 |
59 | displayManager = (lifecycleOwner.get() as Context).getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
60 | displayManager.registerDisplayListener(rotationListener, null)
61 |
62 | this.displayId = displayId
63 |
64 | rotationCurrent = displayManager.getDisplay(displayId).rotation
65 |
66 | isLandscape = (lifecycleOwner.get() as Context).resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
67 |
68 | val cameraSelector = CameraSelector.Builder().requireLensFacing(facing).build()
69 |
70 | val imageAnalysis = ImageAnalysis.Builder()
71 | .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
72 | .build()
73 | imageAnalysis.setAnalyzer(executor, ImageAnalysis.Analyzer { imageProxy ->
74 | if (imageProxy.image == null || imageProxy.planes.size < 3) return@Analyzer
75 |
76 | for (i in subscriptions) i.value.invoke(imageProxy.image!!)
77 |
78 | imageProxy.close()
79 | })
80 |
81 | released = false
82 |
83 | cameraProvider.bindToLifecycle(lifecycleOwner.get()!!, cameraSelector, preview, imageAnalysis)
84 | } catch (e: Exception) {
85 | cameraProvider.unbindAll()
86 | released = true
87 | onError.invoke()
88 | }
89 | }
90 |
91 | object rotationListener : DisplayManager.DisplayListener {
92 | override fun onDisplayAdded(displayId: Int) = Unit
93 | override fun onDisplayRemoved(displayId: Int) = Unit
94 | override fun onDisplayChanged(displayId: Int) {
95 | if (ControllerVideo.displayId == displayId)
96 | rotationCurrent = displayManager.getDisplay(displayId).rotation
97 | }
98 | }
99 |
100 | fun subscribe(tag: String, onFrame: (Image) -> Unit) {
101 | subscriptions.remove(tag)
102 | subscriptions[tag] = onFrame
103 | }
104 |
105 | fun unsubscribe(tag: String) {
106 | subscriptions.remove(tag)
107 | }
108 |
109 | fun destroyCamera() {
110 | if (this::cameraProvider.isInitialized) {
111 | try { cameraProvider.unbindAll() }
112 | catch (e: Exception) { Log.e("ControllerVideo", "[destroyCamera] error: $e") }
113 | }
114 | if (this::displayManager.isInitialized) displayManager.unregisterDisplayListener(rotationListener)
115 | released = true
116 | }
117 | }
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/convert_from.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_CONVERT_FROM_H_
12 | #define INCLUDE_LIBYUV_CONVERT_FROM_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/rotate.h"
16 |
17 | #ifdef __cplusplus
18 | namespace libyuv {
19 | extern "C" {
20 | #endif
21 |
22 | // See Also convert.h for conversions from formats to I420.
23 |
24 | // Convert 8 bit YUV to 10 bit.
25 | #define H420ToH010 I420ToI010
26 | LIBYUV_API
27 | int I420ToI010(const uint8_t* src_y,
28 | int src_stride_y,
29 | const uint8_t* src_u,
30 | int src_stride_u,
31 | const uint8_t* src_v,
32 | int src_stride_v,
33 | uint16_t* dst_y,
34 | int dst_stride_y,
35 | uint16_t* dst_u,
36 | int dst_stride_u,
37 | uint16_t* dst_v,
38 | int dst_stride_v,
39 | int width,
40 | int height);
41 |
42 | LIBYUV_API
43 | int I420ToI422(const uint8_t* src_y,
44 | int src_stride_y,
45 | const uint8_t* src_u,
46 | int src_stride_u,
47 | const uint8_t* src_v,
48 | int src_stride_v,
49 | uint8_t* dst_y,
50 | int dst_stride_y,
51 | uint8_t* dst_u,
52 | int dst_stride_u,
53 | uint8_t* dst_v,
54 | int dst_stride_v,
55 | int width,
56 | int height);
57 |
58 | LIBYUV_API
59 | int I420ToI444(const uint8_t* src_y,
60 | int src_stride_y,
61 | const uint8_t* src_u,
62 | int src_stride_u,
63 | const uint8_t* src_v,
64 | int src_stride_v,
65 | uint8_t* dst_y,
66 | int dst_stride_y,
67 | uint8_t* dst_u,
68 | int dst_stride_u,
69 | uint8_t* dst_v,
70 | int dst_stride_v,
71 | int width,
72 | int height);
73 |
74 | // Copy to I400. Source can be I420, I422, I444, I400, NV12 or NV21.
75 | LIBYUV_API
76 | int I400Copy(const uint8_t* src_y,
77 | int src_stride_y,
78 | uint8_t* dst_y,
79 | int dst_stride_y,
80 | int width,
81 | int height);
82 |
83 | LIBYUV_API
84 | int I420ToNV12(const uint8_t* src_y,
85 | int src_stride_y,
86 | const uint8_t* src_u,
87 | int src_stride_u,
88 | const uint8_t* src_v,
89 | int src_stride_v,
90 | uint8_t* dst_y,
91 | int dst_stride_y,
92 | uint8_t* dst_uv,
93 | int dst_stride_uv,
94 | int width,
95 | int height);
96 |
97 | LIBYUV_API
98 | int I420ToNV21(const uint8_t* src_y,
99 | int src_stride_y,
100 | const uint8_t* src_u,
101 | int src_stride_u,
102 | const uint8_t* src_v,
103 | int src_stride_v,
104 | uint8_t* dst_y,
105 | int dst_stride_y,
106 | uint8_t* dst_vu,
107 | int dst_stride_vu,
108 | int width,
109 | int height);
110 |
111 | LIBYUV_API
112 | int I420ToYUY2(const uint8_t* src_y,
113 | int src_stride_y,
114 | const uint8_t* src_u,
115 | int src_stride_u,
116 | const uint8_t* src_v,
117 | int src_stride_v,
118 | uint8_t* dst_yuy2,
119 | int dst_stride_yuy2,
120 | int width,
121 | int height);
122 |
123 | LIBYUV_API
124 | int I420ToUYVY(const uint8_t* src_y,
125 | int src_stride_y,
126 | const uint8_t* src_u,
127 | int src_stride_u,
128 | const uint8_t* src_v,
129 | int src_stride_v,
130 | uint8_t* dst_uyvy,
131 | int dst_stride_uyvy,
132 | int width,
133 | int height);
134 |
135 | // Convert I420 to specified format.
136 | // "dst_sample_stride" is bytes in a row for the destination. Pass 0 if the
137 | // buffer has contiguous rows. Can be negative. A multiple of 16 is optimal.
138 | LIBYUV_API
139 | int ConvertFromI420(const uint8_t* y,
140 | int y_stride,
141 | const uint8_t* u,
142 | int u_stride,
143 | const uint8_t* v,
144 | int v_stride,
145 | uint8_t* dst_sample,
146 | int dst_sample_stride,
147 | int width,
148 | int height,
149 | uint32_t fourcc);
150 |
151 | #ifdef __cplusplus
152 | } // extern "C"
153 | } // namespace libyuv
154 | #endif
155 |
156 | #endif // INCLUDE_LIBYUV_CONVERT_FROM_H_
157 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
22 |
23 |
29 |
30 |
35 |
36 |
40 |
41 |
45 |
46 |
47 |
53 |
54 |
60 |
61 |
65 |
66 |
67 |
68 |
73 |
74 |
80 |
81 |
84 |
85 |
91 |
92 |
96 |
97 |
103 |
104 |
108 |
109 |
115 |
116 |
121 |
122 |
128 |
129 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/compare_row.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_COMPARE_ROW_H_
12 | #define INCLUDE_LIBYUV_COMPARE_ROW_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | #if defined(__pnacl__) || defined(__CLR_VER) || \
22 | (defined(__native_client__) && defined(__x86_64__)) || \
23 | (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
24 | #define LIBYUV_DISABLE_X86
25 | #endif
26 | #if defined(__native_client__)
27 | #define LIBYUV_DISABLE_NEON
28 | #endif
29 | // MemorySanitizer does not support assembly code yet. http://crbug.com/344505
30 | #if defined(__has_feature)
31 | #if __has_feature(memory_sanitizer)
32 | #define LIBYUV_DISABLE_X86
33 | #endif
34 | #endif
35 | // Visual C 2012 required for AVX2.
36 | #if defined(_M_IX86) && !defined(__clang__) && defined(_MSC_VER) && \
37 | _MSC_VER >= 1700
38 | #define VISUALC_HAS_AVX2 1
39 | #endif // VisualStudio >= 2012
40 |
41 | // clang >= 3.4.0 required for AVX2.
42 | #if defined(__clang__) && (defined(__x86_64__) || defined(__i386__))
43 | #if (__clang_major__ > 3) || (__clang_major__ == 3 && (__clang_minor__ >= 4))
44 | #define CLANG_HAS_AVX2 1
45 | #endif // clang >= 3.4
46 | #endif // __clang__
47 |
48 | // The following are available for Visual C and GCC:
49 | #if !defined(LIBYUV_DISABLE_X86) && \
50 | (defined(__x86_64__) || defined(__i386__) || defined(_M_IX86))
51 | #define HAS_HASHDJB2_SSE41
52 | #define HAS_SUMSQUAREERROR_SSE2
53 | #define HAS_HAMMINGDISTANCE_SSE42
54 | #endif
55 |
56 | // The following are available for Visual C and clangcl 32 bit:
57 | #if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \
58 | (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2))
59 | #define HAS_HASHDJB2_AVX2
60 | #define HAS_SUMSQUAREERROR_AVX2
61 | #endif
62 |
63 | // The following are available for GCC and clangcl 64 bit:
64 | #if !defined(LIBYUV_DISABLE_X86) && \
65 | (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
66 | #define HAS_HAMMINGDISTANCE_SSSE3
67 | #endif
68 |
69 | // The following are available for GCC and clangcl 64 bit:
70 | #if !defined(LIBYUV_DISABLE_X86) && defined(CLANG_HAS_AVX2) && \
71 | (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
72 | #define HAS_HAMMINGDISTANCE_AVX2
73 | #endif
74 |
75 | // The following are available for Neon:
76 | #if !defined(LIBYUV_DISABLE_NEON) && \
77 | (defined(__ARM_NEON__) || defined(LIBYUV_NEON) || defined(__aarch64__))
78 | #define HAS_SUMSQUAREERROR_NEON
79 | #define HAS_HAMMINGDISTANCE_NEON
80 | #endif
81 |
82 | #if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa)
83 | #define HAS_HAMMINGDISTANCE_MSA
84 | #define HAS_SUMSQUAREERROR_MSA
85 | #endif
86 |
87 | #if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A)
88 | #define HAS_HAMMINGDISTANCE_MMI
89 | #define HAS_SUMSQUAREERROR_MMI
90 | #endif
91 |
92 | uint32_t HammingDistance_C(const uint8_t* src_a,
93 | const uint8_t* src_b,
94 | int count);
95 | uint32_t HammingDistance_SSE42(const uint8_t* src_a,
96 | const uint8_t* src_b,
97 | int count);
98 | uint32_t HammingDistance_SSSE3(const uint8_t* src_a,
99 | const uint8_t* src_b,
100 | int count);
101 | uint32_t HammingDistance_AVX2(const uint8_t* src_a,
102 | const uint8_t* src_b,
103 | int count);
104 | uint32_t HammingDistance_NEON(const uint8_t* src_a,
105 | const uint8_t* src_b,
106 | int count);
107 | uint32_t HammingDistance_MSA(const uint8_t* src_a,
108 | const uint8_t* src_b,
109 | int count);
110 | uint32_t HammingDistance_MMI(const uint8_t* src_a,
111 | const uint8_t* src_b,
112 | int count);
113 | uint32_t SumSquareError_C(const uint8_t* src_a,
114 | const uint8_t* src_b,
115 | int count);
116 | uint32_t SumSquareError_SSE2(const uint8_t* src_a,
117 | const uint8_t* src_b,
118 | int count);
119 | uint32_t SumSquareError_AVX2(const uint8_t* src_a,
120 | const uint8_t* src_b,
121 | int count);
122 | uint32_t SumSquareError_NEON(const uint8_t* src_a,
123 | const uint8_t* src_b,
124 | int count);
125 | uint32_t SumSquareError_MSA(const uint8_t* src_a,
126 | const uint8_t* src_b,
127 | int count);
128 | uint32_t SumSquareError_MMI(const uint8_t* src_a,
129 | const uint8_t* src_b,
130 | int count);
131 |
132 | uint32_t HashDjb2_C(const uint8_t* src, int count, uint32_t seed);
133 | uint32_t HashDjb2_SSE41(const uint8_t* src, int count, uint32_t seed);
134 | uint32_t HashDjb2_AVX2(const uint8_t* src, int count, uint32_t seed);
135 |
136 | #ifdef __cplusplus
137 | } // extern "C"
138 | } // namespace libyuv
139 | #endif
140 |
141 | #endif // INCLUDE_LIBYUV_COMPARE_ROW_H_
142 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/rotate.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_ROTATE_H_
12 | #define INCLUDE_LIBYUV_ROTATE_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | // Supported rotation.
22 | typedef enum RotationMode {
23 | kRotate0 = 0, // No rotation.
24 | kRotate90 = 90, // Rotate 90 degrees clockwise.
25 | kRotate180 = 180, // Rotate 180 degrees.
26 | kRotate270 = 270, // Rotate 270 degrees clockwise.
27 |
28 | // Deprecated.
29 | kRotateNone = 0,
30 | kRotateClockwise = 90,
31 | kRotateCounterClockwise = 270,
32 | } RotationModeEnum;
33 |
34 | // Rotate I420 frame.
35 | LIBYUV_API
36 | int I420Rotate(const uint8_t* src_y,
37 | int src_stride_y,
38 | const uint8_t* src_u,
39 | int src_stride_u,
40 | const uint8_t* src_v,
41 | int src_stride_v,
42 | uint8_t* dst_y,
43 | int dst_stride_y,
44 | uint8_t* dst_u,
45 | int dst_stride_u,
46 | uint8_t* dst_v,
47 | int dst_stride_v,
48 | int width,
49 | int height,
50 | enum RotationMode mode);
51 |
52 | // Rotate I444 frame.
53 | LIBYUV_API
54 | int I444Rotate(const uint8_t* src_y,
55 | int src_stride_y,
56 | const uint8_t* src_u,
57 | int src_stride_u,
58 | const uint8_t* src_v,
59 | int src_stride_v,
60 | uint8_t* dst_y,
61 | int dst_stride_y,
62 | uint8_t* dst_u,
63 | int dst_stride_u,
64 | uint8_t* dst_v,
65 | int dst_stride_v,
66 | int width,
67 | int height,
68 | enum RotationMode mode);
69 |
70 | // Rotate NV12 input and store in I420.
71 | LIBYUV_API
72 | int NV12ToI420Rotate(const uint8_t* src_y,
73 | int src_stride_y,
74 | const uint8_t* src_uv,
75 | int src_stride_uv,
76 | uint8_t* dst_y,
77 | int dst_stride_y,
78 | uint8_t* dst_u,
79 | int dst_stride_u,
80 | uint8_t* dst_v,
81 | int dst_stride_v,
82 | int width,
83 | int height,
84 | enum RotationMode mode);
85 |
86 | // Rotate a plane by 0, 90, 180, or 270.
87 | LIBYUV_API
88 | int RotatePlane(const uint8_t* src,
89 | int src_stride,
90 | uint8_t* dst,
91 | int dst_stride,
92 | int width,
93 | int height,
94 | enum RotationMode mode);
95 |
96 | // Rotate planes by 90, 180, 270. Deprecated.
97 | LIBYUV_API
98 | void RotatePlane90(const uint8_t* src,
99 | int src_stride,
100 | uint8_t* dst,
101 | int dst_stride,
102 | int width,
103 | int height);
104 |
105 | LIBYUV_API
106 | void RotatePlane180(const uint8_t* src,
107 | int src_stride,
108 | uint8_t* dst,
109 | int dst_stride,
110 | int width,
111 | int height);
112 |
113 | LIBYUV_API
114 | void RotatePlane270(const uint8_t* src,
115 | int src_stride,
116 | uint8_t* dst,
117 | int dst_stride,
118 | int width,
119 | int height);
120 |
121 | // Rotations for when U and V are interleaved.
122 | // These functions take one input pointer and
123 | // split the data into two buffers while
124 | // rotating them. Deprecated.
125 | LIBYUV_API
126 | void RotateUV90(const uint8_t* src,
127 | int src_stride,
128 | uint8_t* dst_a,
129 | int dst_stride_a,
130 | uint8_t* dst_b,
131 | int dst_stride_b,
132 | int width,
133 | int height);
134 |
135 | LIBYUV_API
136 | void RotateUV180(const uint8_t* src,
137 | int src_stride,
138 | uint8_t* dst_a,
139 | int dst_stride_a,
140 | uint8_t* dst_b,
141 | int dst_stride_b,
142 | int width,
143 | int height);
144 |
145 | LIBYUV_API
146 | void RotateUV270(const uint8_t* src,
147 | int src_stride,
148 | uint8_t* dst_a,
149 | int dst_stride_a,
150 | uint8_t* dst_b,
151 | int dst_stride_b,
152 | int width,
153 | int height);
154 |
155 | // The 90 and 270 functions are based on transposes.
156 | // Doing a transpose with reversing the read/write
157 | // order will result in a rotation by +- 90 degrees.
158 | // Deprecated.
159 | LIBYUV_API
160 | void TransposePlane(const uint8_t* src,
161 | int src_stride,
162 | uint8_t* dst,
163 | int dst_stride,
164 | int width,
165 | int height);
166 |
167 | LIBYUV_API
168 | void TransposeUV(const uint8_t* src,
169 | int src_stride,
170 | uint8_t* dst_a,
171 | int dst_stride_a,
172 | uint8_t* dst_b,
173 | int dst_stride_b,
174 | int width,
175 | int height);
176 |
177 | #ifdef __cplusplus
178 | } // extern "C"
179 | } // namespace libyuv
180 | #endif
181 |
182 | #endif // INCLUDE_LIBYUV_ROTATE_H_
183 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/scale.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_SCALE_H_
12 | #define INCLUDE_LIBYUV_SCALE_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | // Supported filtering.
22 | typedef enum FilterMode {
23 | kFilterNone = 0, // Point sample; Fastest.
24 | kFilterLinear = 1, // Filter horizontally only.
25 | kFilterBilinear = 2, // Faster than box, but lower quality scaling down.
26 | kFilterBox = 3 // Highest quality.
27 | } FilterModeEnum;
28 |
29 | // Scale a YUV plane.
30 | LIBYUV_API
31 | void ScalePlane(const uint8_t* src,
32 | int src_stride,
33 | int src_width,
34 | int src_height,
35 | uint8_t* dst,
36 | int dst_stride,
37 | int dst_width,
38 | int dst_height,
39 | enum FilterMode filtering);
40 |
41 | LIBYUV_API
42 | void ScalePlane_16(const uint16_t* src,
43 | int src_stride,
44 | int src_width,
45 | int src_height,
46 | uint16_t* dst,
47 | int dst_stride,
48 | int dst_width,
49 | int dst_height,
50 | enum FilterMode filtering);
51 |
52 | // Scales a YUV 4:2:0 image from the src width and height to the
53 | // dst width and height.
54 | // If filtering is kFilterNone, a simple nearest-neighbor algorithm is
55 | // used. This produces basic (blocky) quality at the fastest speed.
56 | // If filtering is kFilterBilinear, interpolation is used to produce a better
57 | // quality image, at the expense of speed.
58 | // If filtering is kFilterBox, averaging is used to produce ever better
59 | // quality image, at further expense of speed.
60 | // Returns 0 if successful.
61 |
62 | LIBYUV_API
63 | int I420Scale(const uint8_t* src_y,
64 | int src_stride_y,
65 | const uint8_t* src_u,
66 | int src_stride_u,
67 | const uint8_t* src_v,
68 | int src_stride_v,
69 | int src_width,
70 | int src_height,
71 | uint8_t* dst_y,
72 | int dst_stride_y,
73 | uint8_t* dst_u,
74 | int dst_stride_u,
75 | uint8_t* dst_v,
76 | int dst_stride_v,
77 | int dst_width,
78 | int dst_height,
79 | enum FilterMode filtering);
80 |
81 | LIBYUV_API
82 | int I420Scale_16(const uint16_t* src_y,
83 | int src_stride_y,
84 | const uint16_t* src_u,
85 | int src_stride_u,
86 | const uint16_t* src_v,
87 | int src_stride_v,
88 | int src_width,
89 | int src_height,
90 | uint16_t* dst_y,
91 | int dst_stride_y,
92 | uint16_t* dst_u,
93 | int dst_stride_u,
94 | uint16_t* dst_v,
95 | int dst_stride_v,
96 | int dst_width,
97 | int dst_height,
98 | enum FilterMode filtering);
99 |
100 | // Scales a YUV 4:4:4 image from the src width and height to the
101 | // dst width and height.
102 | // If filtering is kFilterNone, a simple nearest-neighbor algorithm is
103 | // used. This produces basic (blocky) quality at the fastest speed.
104 | // If filtering is kFilterBilinear, interpolation is used to produce a better
105 | // quality image, at the expense of speed.
106 | // If filtering is kFilterBox, averaging is used to produce ever better
107 | // quality image, at further expense of speed.
108 | // Returns 0 if successful.
109 |
110 | LIBYUV_API
111 | int I444Scale(const uint8_t* src_y,
112 | int src_stride_y,
113 | const uint8_t* src_u,
114 | int src_stride_u,
115 | const uint8_t* src_v,
116 | int src_stride_v,
117 | int src_width,
118 | int src_height,
119 | uint8_t* dst_y,
120 | int dst_stride_y,
121 | uint8_t* dst_u,
122 | int dst_stride_u,
123 | uint8_t* dst_v,
124 | int dst_stride_v,
125 | int dst_width,
126 | int dst_height,
127 | enum FilterMode filtering);
128 |
129 | LIBYUV_API
130 | int I444Scale_16(const uint16_t* src_y,
131 | int src_stride_y,
132 | const uint16_t* src_u,
133 | int src_stride_u,
134 | const uint16_t* src_v,
135 | int src_stride_v,
136 | int src_width,
137 | int src_height,
138 | uint16_t* dst_y,
139 | int dst_stride_y,
140 | uint16_t* dst_u,
141 | int dst_stride_u,
142 | uint16_t* dst_v,
143 | int dst_stride_v,
144 | int dst_width,
145 | int dst_height,
146 | enum FilterMode filtering);
147 |
148 | #ifdef __cplusplus
149 | // Legacy API. Deprecated.
150 | LIBYUV_API
151 | int Scale(const uint8_t* src_y,
152 | const uint8_t* src_u,
153 | const uint8_t* src_v,
154 | int src_stride_y,
155 | int src_stride_u,
156 | int src_stride_v,
157 | int src_width,
158 | int src_height,
159 | uint8_t* dst_y,
160 | uint8_t* dst_u,
161 | uint8_t* dst_v,
162 | int dst_stride_y,
163 | int dst_stride_u,
164 | int dst_stride_v,
165 | int dst_width,
166 | int dst_height,
167 | LIBYUV_BOOL interpolate);
168 |
169 | // For testing, allow disabling of specialized scalers.
170 | LIBYUV_API
171 | void SetUseReferenceImpl(LIBYUV_BOOL use);
172 | #endif // __cplusplus
173 |
174 | #ifdef __cplusplus
175 | } // extern "C"
176 | } // namespace libyuv
177 | #endif
178 |
179 | #endif // INCLUDE_LIBYUV_SCALE_H_
180 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/mjpeg_decoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_
12 | #define INCLUDE_LIBYUV_MJPEG_DECODER_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | // NOTE: For a simplified public API use convert.h MJPGToI420().
18 |
19 | struct jpeg_common_struct;
20 | struct jpeg_decompress_struct;
21 | struct jpeg_source_mgr;
22 |
23 | namespace libyuv {
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | LIBYUV_BOOL ValidateJpeg(const uint8_t* sample, size_t sample_size);
30 |
31 | #ifdef __cplusplus
32 | } // extern "C"
33 | #endif
34 |
35 | static const uint32_t kUnknownDataSize = 0xFFFFFFFF;
36 |
37 | enum JpegSubsamplingType {
38 | kJpegYuv420,
39 | kJpegYuv422,
40 | kJpegYuv444,
41 | kJpegYuv400,
42 | kJpegUnknown
43 | };
44 |
45 | struct Buffer {
46 | const uint8_t* data;
47 | int len;
48 | };
49 |
50 | struct BufferVector {
51 | Buffer* buffers;
52 | int len;
53 | int pos;
54 | };
55 |
56 | struct SetJmpErrorMgr;
57 |
58 | // MJPEG ("Motion JPEG") is a pseudo-standard video codec where the frames are
59 | // simply independent JPEG images with a fixed huffman table (which is omitted).
60 | // It is rarely used in video transmission, but is common as a camera capture
61 | // format, especially in Logitech devices. This class implements a decoder for
62 | // MJPEG frames.
63 | //
64 | // See http://tools.ietf.org/html/rfc2435
65 | class LIBYUV_API MJpegDecoder {
66 | public:
67 | typedef void (*CallbackFunction)(void* opaque,
68 | const uint8_t* const* data,
69 | const int* strides,
70 | int rows);
71 |
72 | static const int kColorSpaceUnknown;
73 | static const int kColorSpaceGrayscale;
74 | static const int kColorSpaceRgb;
75 | static const int kColorSpaceYCbCr;
76 | static const int kColorSpaceCMYK;
77 | static const int kColorSpaceYCCK;
78 |
79 | MJpegDecoder();
80 | ~MJpegDecoder();
81 |
82 | // Loads a new frame, reads its headers, and determines the uncompressed
83 | // image format.
84 | // Returns LIBYUV_TRUE if image looks valid and format is supported.
85 | // If return value is LIBYUV_TRUE, then the values for all the following
86 | // getters are populated.
87 | // src_len is the size of the compressed mjpeg frame in bytes.
88 | LIBYUV_BOOL LoadFrame(const uint8_t* src, size_t src_len);
89 |
90 | // Returns width of the last loaded frame in pixels.
91 | int GetWidth();
92 |
93 | // Returns height of the last loaded frame in pixels.
94 | int GetHeight();
95 |
96 | // Returns format of the last loaded frame. The return value is one of the
97 | // kColorSpace* constants.
98 | int GetColorSpace();
99 |
100 | // Number of color components in the color space.
101 | int GetNumComponents();
102 |
103 | // Sample factors of the n-th component.
104 | int GetHorizSampFactor(int component);
105 |
106 | int GetVertSampFactor(int component);
107 |
108 | int GetHorizSubSampFactor(int component);
109 |
110 | int GetVertSubSampFactor(int component);
111 |
112 | // Public for testability.
113 | int GetImageScanlinesPerImcuRow();
114 |
115 | // Public for testability.
116 | int GetComponentScanlinesPerImcuRow(int component);
117 |
118 | // Width of a component in bytes.
119 | int GetComponentWidth(int component);
120 |
121 | // Height of a component.
122 | int GetComponentHeight(int component);
123 |
124 | // Width of a component in bytes with padding for DCTSIZE. Public for testing.
125 | int GetComponentStride(int component);
126 |
127 | // Size of a component in bytes.
128 | int GetComponentSize(int component);
129 |
130 | // Call this after LoadFrame() if you decide you don't want to decode it
131 | // after all.
132 | LIBYUV_BOOL UnloadFrame();
133 |
134 | // Decodes the entire image into a one-buffer-per-color-component format.
135 | // dst_width must match exactly. dst_height must be <= to image height; if
136 | // less, the image is cropped. "planes" must have size equal to at least
137 | // GetNumComponents() and they must point to non-overlapping buffers of size
138 | // at least GetComponentSize(i). The pointers in planes are incremented
139 | // to point to after the end of the written data.
140 | // TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded.
141 | LIBYUV_BOOL DecodeToBuffers(uint8_t** planes, int dst_width, int dst_height);
142 |
143 | // Decodes the entire image and passes the data via repeated calls to a
144 | // callback function. Each call will get the data for a whole number of
145 | // image scanlines.
146 | // TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded.
147 | LIBYUV_BOOL DecodeToCallback(CallbackFunction fn,
148 | void* opaque,
149 | int dst_width,
150 | int dst_height);
151 |
152 | // The helper function which recognizes the jpeg sub-sampling type.
153 | static JpegSubsamplingType JpegSubsamplingTypeHelper(
154 | int* subsample_x,
155 | int* subsample_y,
156 | int number_of_components);
157 |
158 | private:
159 | void AllocOutputBuffers(int num_outbufs);
160 | void DestroyOutputBuffers();
161 |
162 | LIBYUV_BOOL StartDecode();
163 | LIBYUV_BOOL FinishDecode();
164 |
165 | void SetScanlinePointers(uint8_t** data);
166 | LIBYUV_BOOL DecodeImcuRow();
167 |
168 | int GetComponentScanlinePadding(int component);
169 |
170 | // A buffer holding the input data for a frame.
171 | Buffer buf_;
172 | BufferVector buf_vec_;
173 |
174 | jpeg_decompress_struct* decompress_struct_;
175 | jpeg_source_mgr* source_mgr_;
176 | SetJmpErrorMgr* error_mgr_;
177 |
178 | // LIBYUV_TRUE iff at least one component has scanline padding. (i.e.,
179 | // GetComponentScanlinePadding() != 0.)
180 | LIBYUV_BOOL has_scanline_padding_;
181 |
182 | // Temporaries used to point to scanline outputs.
183 | int num_outbufs_; // Outermost size of all arrays below.
184 | uint8_t*** scanlines_;
185 | int* scanlines_sizes_;
186 | // Temporary buffer used for decoding when we can't decode directly to the
187 | // output buffers. Large enough for just one iMCU row.
188 | uint8_t** databuf_;
189 | int* databuf_strides_;
190 | };
191 |
192 | } // namespace libyuv
193 |
194 | #endif // __cplusplus
195 | #endif // INCLUDE_LIBYUV_MJPEG_DECODER_H_
196 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/easyyuv.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "libyuv.h"
6 | #include "utils/logger.h"
7 |
8 | //
9 | // Created by Loboda Alexey on 22.06.2020.
10 | //
11 |
12 | //
13 | // Scale
14 | //
15 |
16 | extern "C"
17 | JNIEXPORT void JNICALL
18 | Java_com_theeasiestway_yuv_YuvUtils_scale__Ljava_nio_ByteBuffer_2Ljava_nio_ByteBuffer_2Ljava_nio_ByteBuffer_2IIILjava_nio_ByteBuffer_2Ljava_nio_ByteBuffer_2Ljava_nio_ByteBuffer_2IIIIIIII(
19 | JNIEnv *env, jobject thiz, jobject y, jobject u, jobject v,
20 | jint yStride, jint uStride, jint vStride,
21 | jobject yOut, jobject uOut, jobject vOut,
22 | jint yOutStride, jint uOutStride, jint vOutStride,
23 | jint srcWidth, jint srcHeight, jint dstWidth, jint dstHeight, jint filterMode) {
24 |
25 | uint8_t *yNative = (uint8_t *) env->GetDirectBufferAddress(y);
26 | uint8_t *uNative = (uint8_t *) env->GetDirectBufferAddress(u);
27 | uint8_t *vNative = (uint8_t *) env->GetDirectBufferAddress(v);
28 |
29 |
30 | uint8_t *yOutNative = (uint8_t *) env->GetDirectBufferAddress(yOut);
31 | uint8_t *uOutNative = (uint8_t *) env->GetDirectBufferAddress(uOut);
32 | uint8_t *vOutNative = (uint8_t *) env->GetDirectBufferAddress(vOut);
33 |
34 | libyuv::I420Scale(yNative, yStride,
35 | uNative, uStride,
36 | vNative, vStride,
37 | srcWidth, srcHeight,
38 | yOutNative, yOutStride,
39 | uOutNative, uOutStride,
40 | vOutNative, vOutStride,
41 | dstWidth, dstHeight,
42 | libyuv::FilterMode(filterMode));
43 | }
44 |
45 | //
46 | // Rotate
47 | //
48 |
49 | extern "C"
50 | JNIEXPORT void JNICALL
51 | Java_com_theeasiestway_yuv_YuvUtils_rotate(JNIEnv *env, jobject thiz, jobject y, jobject u,
52 | jobject v, jint yStride, jint uStride, jint vStride,
53 | jobject yOut, jobject uOut, jobject vOut,
54 | jint yOutStride, jint uOutStride, jint vOutStride,
55 | jint width, jint height, jint rotationMode) {
56 |
57 | uint8_t *yNative = (uint8_t *) env->GetDirectBufferAddress(y);
58 | uint8_t *uNative = (uint8_t *) env->GetDirectBufferAddress(u);
59 | uint8_t *vNative = (uint8_t *) env->GetDirectBufferAddress(v);
60 |
61 | uint8_t *yOutNative = (uint8_t *) env->GetDirectBufferAddress(yOut);
62 | uint8_t *uOutNative = (uint8_t *) env->GetDirectBufferAddress(uOut);
63 | uint8_t *vOutNative = (uint8_t *) env->GetDirectBufferAddress(vOut);
64 |
65 | libyuv::I420Rotate(yNative, yStride,
66 | uNative, uStride,
67 | vNative, vStride,
68 | yOutNative, yOutStride,
69 | uOutNative, uOutStride,
70 | vOutNative, vOutStride,
71 | width, height,
72 | libyuv::RotationMode(rotationMode));
73 | }
74 |
75 | //
76 | // Mirror
77 | //
78 |
79 | extern "C"
80 | JNIEXPORT void JNICALL
81 | Java_com_theeasiestway_yuv_YuvUtils_mirrorH(JNIEnv *env, jobject thiz, jobject y, jobject u,
82 | jobject v, jint yStride, jint uStride, jint vStride,
83 | jobject yOut, jobject uOut, jobject vOut,
84 | jint yOutStride, jint uOutStride, jint vOutStride,
85 | jint width, jint height) {
86 |
87 | uint8_t *yNative = (uint8_t *) env->GetDirectBufferAddress(y);
88 | uint8_t *uNative = (uint8_t *) env->GetDirectBufferAddress(u);
89 | uint8_t *vNative = (uint8_t *) env->GetDirectBufferAddress(v);
90 |
91 | uint8_t *yOutNative = (uint8_t *) env->GetDirectBufferAddress(yOut);
92 | uint8_t *uOutNative = (uint8_t *) env->GetDirectBufferAddress(uOut);
93 | uint8_t *vOutNative = (uint8_t *) env->GetDirectBufferAddress(vOut);
94 |
95 | libyuv::I420Mirror(yNative, yStride,
96 | uNative, uStride,
97 | vNative, vStride,
98 | yOutNative, yOutStride,
99 | uOutNative, uOutStride,
100 | vOutNative, vOutStride,
101 | width, height);
102 | }
103 |
104 | //
105 | // YUV to ARGB
106 | //
107 |
108 | extern "C"
109 | JNIEXPORT void JNICALL
110 | Java_com_theeasiestway_yuv_YuvUtils_yuv420ToArgb(JNIEnv *env, jobject thiz, jobject y, jobject u,
111 | jobject v, jint yStride, jint uStride, jint vStride,
112 | jobject out, jint outStride,
113 | jint width, jint height) {
114 |
115 | uint8_t *yNative = (uint8_t *) env->GetDirectBufferAddress(y);
116 | uint8_t *uNative = (uint8_t *) env->GetDirectBufferAddress(u);
117 | uint8_t *vNative = (uint8_t *) env->GetDirectBufferAddress(v);
118 |
119 | uint8_t *outNative = (uint8_t *) env->GetDirectBufferAddress(out);
120 |
121 | libyuv::I420ToARGB(yNative, yStride,
122 | vNative, vStride, // exactly this order "YVU" and not "YUV", otherwise the colors are inverted
123 | uNative, uStride,
124 | outNative, outStride,
125 | width, height);
126 |
127 | }
128 |
129 | //
130 | // Convert to I420
131 | //
132 |
133 | extern "C"
134 | JNIEXPORT void JNICALL
135 | Java_com_theeasiestway_yuv_YuvUtils_convertToI420(JNIEnv *env, jobject thiz, jobject y, jobject u,
136 | jobject v, jint yStride, jint uStride, jint vStride, jint srcPixelStrideUv,
137 | jobject yOut, jobject uOut, jobject vOut,
138 | jint yOutStride, jint uOutStride, jint vOutStride,
139 | jint width, jint height) {
140 |
141 | uint8_t *yNative = (uint8_t *) env->GetDirectBufferAddress(y);
142 | uint8_t *uNative = (uint8_t *) env->GetDirectBufferAddress(u);
143 | uint8_t *vNative = (uint8_t *) env->GetDirectBufferAddress(v);
144 |
145 | uint8_t *yOutNative = (uint8_t *) env->GetDirectBufferAddress(yOut);
146 | uint8_t *uOutNative = (uint8_t *) env->GetDirectBufferAddress(uOut);
147 | uint8_t *vOutNative = (uint8_t *) env->GetDirectBufferAddress(vOut);
148 |
149 | libyuv::Android420ToI420(yNative, yStride,
150 | uNative, uStride,
151 | vNative, vStride,
152 | srcPixelStrideUv,
153 | yOutNative, yOutStride,
154 | uOutNative, uOutStride,
155 | vOutNative, vOutStride,
156 | width, height);
157 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/theeasiestway/libyuvwrapper/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.libyuvwrapper
2 |
3 | import android.Manifest
4 | import android.content.pm.PackageManager
5 | import android.graphics.Bitmap
6 | import android.media.Image
7 | import android.os.Build
8 | import android.os.Bundle
9 | import android.view.View
10 | import android.widget.*
11 | import androidx.appcompat.app.AppCompatActivity
12 | import androidx.camera.core.CameraSelector
13 | import androidx.camera.view.PreviewView
14 | import androidx.lifecycle.LifecycleOwner
15 | import com.theeasiestway.codec_h264.camera.ControllerVideo
16 | import com.theeasiestway.yuv.Constants
17 | import com.theeasiestway.yuv.YuvUtils
18 | import java.nio.ByteBuffer
19 |
20 | //
21 | // Created by Loboda Alexey on 22.06.2020.
22 | //
23 |
24 | class MainActivity : AppCompatActivity(), LifecycleOwner {
25 |
26 | private val PERMISSION_CAMERA = Manifest.permission.CAMERA
27 | private val yuvUtils = YuvUtils()
28 | private lateinit var vCameraFacing: ImageView
29 | private lateinit var vCameraView: PreviewView
30 | private lateinit var vImageView: ImageView
31 | private lateinit var vPlay: Button
32 | private lateinit var vStop: Button
33 | private lateinit var vWidth: SeekBar
34 | private lateinit var vWidthLabel: TextView
35 | private lateinit var vHeight: SeekBar
36 | private lateinit var vHeightLabel: TextView
37 | private lateinit var vRotate: Button
38 | private lateinit var vMirrorH: Button
39 | private lateinit var vMirrorV: Button
40 |
41 | private var facing = CameraSelector.LENS_FACING_FRONT
42 | private var widthCurrent = 0
43 | private var heightCurrent = 0
44 | private var width = 0
45 | private var height = 0
46 | private var rotate = 0
47 | private var mirrorH = false
48 | private var mirrorV = false
49 | private var started = false
50 | private var needToUpdateWH = true
51 |
52 | override fun onCreate(savedInstanceState: Bundle?) {
53 | super.onCreate(savedInstanceState)
54 | setContentView(R.layout.activity_main)
55 |
56 | vCameraFacing = findViewById(R.id.vCameraFacing)
57 | vCameraFacing.setImageResource(R.drawable.ic_camera_rear_24dp)
58 | vCameraFacing.setOnClickListener {
59 | facing = if (facing == CameraSelector.LENS_FACING_FRONT) {
60 | vCameraFacing.setImageResource(R.drawable.ic_camera_front_24dp)
61 | CameraSelector.LENS_FACING_BACK
62 | } else {
63 | vCameraFacing.setImageResource(R.drawable.ic_camera_rear_24dp)
64 | CameraSelector.LENS_FACING_FRONT
65 | }
66 | if (started) {
67 | stopCamera()
68 | requestPermissions()
69 | }
70 | }
71 |
72 | vCameraView = findViewById(R.id.vCameraPreview)
73 | vImageView = findViewById(R.id.vImageView)
74 |
75 | vPlay = findViewById(R.id.vPlay)
76 | vPlay.setOnClickListener { requestPermissions() }
77 |
78 | vStop = findViewById(R.id.vStop)
79 | vStop.setOnClickListener { stopCamera() }
80 |
81 | vWidthLabel = findViewById(R.id.vWidthLabel)
82 | vHeightLabel = findViewById(R.id.vHeightLabel)
83 |
84 | vWidth = findViewById(R.id.vWidth)
85 | vWidth.isEnabled = false
86 | vWidth.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
87 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { updateWidth(progress) }
88 | override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
89 | override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit
90 | })
91 |
92 | vHeight = findViewById(R.id.vHeight)
93 | vHeight.isEnabled = false
94 | vHeight.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
95 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { updateHeight(progress) }
96 | override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
97 | override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit
98 | })
99 |
100 | vRotate = findViewById(R.id.vRotate)
101 | vRotate.setOnClickListener { rotate = when(rotate) {
102 | 0 -> Constants.ROTATE_90
103 | 90 -> Constants.ROTATE_180
104 | 180 -> Constants.ROTATE_270
105 | else -> Constants.ROTATE_0
106 | }}
107 |
108 | vMirrorH = findViewById(R.id.vMirrorH)
109 | vMirrorH.setOnClickListener { mirrorH = !mirrorH }
110 |
111 | vMirrorV = findViewById(R.id.vMirrorV)
112 | vMirrorV.setOnClickListener { mirrorV = !mirrorV }
113 | }
114 |
115 | private fun updateHeight(progress: Int = 0) {
116 | heightCurrent = height + progress * 100
117 | vHeightLabel.text = heightCurrent.toString()
118 | }
119 |
120 | private fun updateWidth(progress: Int = 0) {
121 | widthCurrent = width + progress * 100
122 | vWidthLabel.text = widthCurrent.toString()
123 | }
124 |
125 | private fun requestPermissions() {
126 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) requestPermissions(arrayOf(PERMISSION_CAMERA), 1)
127 | else startCamera()
128 | }
129 |
130 | override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) {
131 | if (requestCode == 1 && permissions[0] == PERMISSION_CAMERA && grantResults[0] == PackageManager.PERMISSION_GRANTED)
132 | startCamera()
133 | else Toast.makeText(this, "App doesn't have enough permissions to continue", Toast.LENGTH_LONG).show()
134 | }
135 |
136 | private fun startCamera() {
137 | vPlay.visibility = View.GONE
138 | vStop.visibility = View.VISIBLE
139 | ControllerVideo.subscribe(javaClass.name) { image -> processImage(image) }
140 | ControllerVideo.initCamera(this, facing, vCameraView)
141 | started = true
142 | }
143 |
144 | private fun stopCamera() {
145 | vStop.visibility = View.GONE
146 | vPlay.visibility = View.VISIBLE
147 | vWidth.isEnabled = false
148 | vHeight.isEnabled = false
149 | ControllerVideo.destroyCamera()
150 | started = false
151 | vWidth.progress = 0
152 | vHeight.progress = 0
153 | rotate = Constants.ROTATE_0
154 | mirrorH = false
155 | mirrorV = false
156 | needToUpdateWH = true
157 | }
158 |
159 | private fun processImage(image: Image) {
160 |
161 | width = image.width
162 | height = image.height
163 |
164 | if(needToUpdateWH) {
165 | runOnUiThread {
166 | updateWidth()
167 | updateHeight()
168 | needToUpdateWH = false
169 | vWidth.isEnabled = true
170 | vHeight.isEnabled = true
171 | }
172 | }
173 |
174 | if (widthCurrent <= 0 || heightCurrent <= 0) return
175 |
176 | var yuvFrame = yuvUtils.convertToI420(image)
177 | yuvFrame = yuvUtils.scale(yuvFrame, widthCurrent, heightCurrent, Constants.FILTER_BOX)
178 | yuvFrame = yuvUtils.rotate(yuvFrame, rotate)
179 | if (mirrorH) yuvFrame = yuvUtils.mirrorH(yuvFrame)
180 | if (mirrorV) yuvFrame = yuvUtils.mirrorV(yuvFrame)
181 | val argbFrame = yuvUtils.yuv420ToArgb(yuvFrame)
182 |
183 | val bm = Bitmap.createBitmap(argbFrame.width, argbFrame.height, Bitmap.Config.ARGB_8888)
184 | bm.copyPixelsFromBuffer(ByteBuffer.wrap(argbFrame.asArray())) // for displaying argb
185 |
186 | vImageView.post { vImageView.setImageBitmap(bm) }
187 | }
188 | }
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/video_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | // Common definitions for video, including fourcc and VideoFormat.
12 |
13 | #ifndef INCLUDE_LIBYUV_VIDEO_COMMON_H_
14 | #define INCLUDE_LIBYUV_VIDEO_COMMON_H_
15 |
16 | #include "libyuv/basic_types.h"
17 |
18 | #ifdef __cplusplus
19 | namespace libyuv {
20 | extern "C" {
21 | #endif
22 |
23 | //////////////////////////////////////////////////////////////////////////////
24 | // Definition of FourCC codes
25 | //////////////////////////////////////////////////////////////////////////////
26 |
27 | // Convert four characters to a FourCC code.
28 | // Needs to be a macro otherwise the OS X compiler complains when the kFormat*
29 | // constants are used in a switch.
30 | #ifdef __cplusplus
31 | #define FOURCC(a, b, c, d) \
32 | ((static_cast(a)) | (static_cast(b) << 8) | \
33 | (static_cast(c) << 16) | /* NOLINT */ \
34 | (static_cast(d) << 24)) /* NOLINT */
35 | #else
36 | #define FOURCC(a, b, c, d) \
37 | (((uint32_t)(a)) | ((uint32_t)(b) << 8) | /* NOLINT */ \
38 | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) /* NOLINT */
39 | #endif
40 |
41 | // Some pages discussing FourCC codes:
42 | // http://www.fourcc.org/yuv.php
43 | // http://v4l2spec.bytesex.org/spec/book1.htm
44 | // http://developer.apple.com/quicktime/icefloe/dispatch020.html
45 | // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12
46 | // http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt
47 |
48 | // FourCC codes grouped according to implementation efficiency.
49 | // Primary formats should convert in 1 efficient step.
50 | // Secondary formats are converted in 2 steps.
51 | // Auxilliary formats call primary converters.
52 | enum FourCC {
53 | // 10 Primary YUV formats: 5 planar, 2 biplanar, 2 packed.
54 | FOURCC_I420 = FOURCC('I', '4', '2', '0'),
55 | FOURCC_I422 = FOURCC('I', '4', '2', '2'),
56 | FOURCC_I444 = FOURCC('I', '4', '4', '4'),
57 | FOURCC_I400 = FOURCC('I', '4', '0', '0'),
58 | FOURCC_NV21 = FOURCC('N', 'V', '2', '1'),
59 | FOURCC_NV12 = FOURCC('N', 'V', '1', '2'),
60 | FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'),
61 | FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'),
62 | FOURCC_I010 = FOURCC('I', '0', '1', '0'), // bt.601 10 bit 420
63 | FOURCC_I210 = FOURCC('I', '0', '1', '0'), // bt.601 10 bit 422
64 |
65 | // 1 Secondary YUV format: row biplanar. deprecated.
66 | FOURCC_M420 = FOURCC('M', '4', '2', '0'),
67 |
68 | // 11 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc
69 | FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'),
70 | FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'),
71 | FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'),
72 | FOURCC_AR30 = FOURCC('A', 'R', '3', '0'), // 10 bit per channel. 2101010.
73 | FOURCC_AB30 = FOURCC('A', 'B', '3', '0'), // ABGR version of 10 bit
74 | FOURCC_24BG = FOURCC('2', '4', 'B', 'G'),
75 | FOURCC_RAW = FOURCC('r', 'a', 'w', ' '),
76 | FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'),
77 | FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), // rgb565 LE.
78 | FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'), // argb1555 LE.
79 | FOURCC_R444 = FOURCC('R', '4', '4', '4'), // argb4444 LE.
80 |
81 | // 1 Primary Compressed YUV format.
82 | FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'),
83 |
84 | // 14 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias.
85 | FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'),
86 | FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'),
87 | FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'),
88 | FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420.
89 | FOURCC_J420 =
90 | FOURCC('J', '4', '2', '0'), // jpeg (bt.601 full), unofficial fourcc
91 | FOURCC_J422 =
92 | FOURCC('J', '4', '2', '2'), // jpeg (bt.601 full), unofficial fourcc
93 | FOURCC_J444 =
94 | FOURCC('J', '4', '4', '4'), // jpeg (bt.601 full), unofficial fourcc
95 | FOURCC_J400 =
96 | FOURCC('J', '4', '0', '0'), // jpeg (bt.601 full), unofficial fourcc
97 | FOURCC_H420 = FOURCC('H', '4', '2', '0'), // bt.709, unofficial fourcc
98 | FOURCC_H422 = FOURCC('H', '4', '2', '2'), // bt.709, unofficial fourcc
99 | FOURCC_H444 = FOURCC('H', '4', '4', '4'), // bt.709, unofficial fourcc
100 | FOURCC_U420 = FOURCC('U', '4', '2', '0'), // bt.2020, unofficial fourcc
101 | FOURCC_U422 = FOURCC('U', '4', '2', '2'), // bt.2020, unofficial fourcc
102 | FOURCC_U444 = FOURCC('U', '4', '4', '4'), // bt.2020, unofficial fourcc
103 | FOURCC_H010 = FOURCC('H', '0', '1', '0'), // bt.709 10 bit 420
104 | FOURCC_U010 = FOURCC('U', '0', '1', '0'), // bt.2020 10 bit 420
105 | FOURCC_H210 = FOURCC('H', '0', '1', '0'), // bt.709 10 bit 422
106 | FOURCC_U210 = FOURCC('U', '0', '1', '0'), // bt.2020 10 bit 422
107 |
108 | // 14 Auxiliary aliases. CanonicalFourCC() maps these to canonical fourcc.
109 | FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420.
110 | FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422.
111 | FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444.
112 | FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2.
113 | FOURCC_YUVS = FOURCC('y', 'u', 'v', 's'), // Alias for YUY2 on Mac.
114 | FOURCC_HDYC = FOURCC('H', 'D', 'Y', 'C'), // Alias for UYVY.
115 | FOURCC_2VUY = FOURCC('2', 'v', 'u', 'y'), // Alias for UYVY on Mac.
116 | FOURCC_JPEG = FOURCC('J', 'P', 'E', 'G'), // Alias for MJPG.
117 | FOURCC_DMB1 = FOURCC('d', 'm', 'b', '1'), // Alias for MJPG on Mac.
118 | FOURCC_BA81 = FOURCC('B', 'A', '8', '1'), // Alias for BGGR.
119 | FOURCC_RGB3 = FOURCC('R', 'G', 'B', '3'), // Alias for RAW.
120 | FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG.
121 | FOURCC_CM32 = FOURCC(0, 0, 0, 32), // Alias for BGRA kCMPixelFormat_32ARGB
122 | FOURCC_CM24 = FOURCC(0, 0, 0, 24), // Alias for RAW kCMPixelFormat_24RGB
123 | FOURCC_L555 = FOURCC('L', '5', '5', '5'), // Alias for RGBO.
124 | FOURCC_L565 = FOURCC('L', '5', '6', '5'), // Alias for RGBP.
125 | FOURCC_5551 = FOURCC('5', '5', '5', '1'), // Alias for RGBO.
126 |
127 | // deprecated formats. Not supported, but defined for backward compatibility.
128 | FOURCC_I411 = FOURCC('I', '4', '1', '1'),
129 | FOURCC_Q420 = FOURCC('Q', '4', '2', '0'),
130 | FOURCC_RGGB = FOURCC('R', 'G', 'G', 'B'),
131 | FOURCC_BGGR = FOURCC('B', 'G', 'G', 'R'),
132 | FOURCC_GRBG = FOURCC('G', 'R', 'B', 'G'),
133 | FOURCC_GBRG = FOURCC('G', 'B', 'R', 'G'),
134 | FOURCC_H264 = FOURCC('H', '2', '6', '4'),
135 |
136 | // Match any fourcc.
137 | FOURCC_ANY = -1,
138 | };
139 |
140 | enum FourCCBpp {
141 | // Canonical fourcc codes used in our code.
142 | FOURCC_BPP_I420 = 12,
143 | FOURCC_BPP_I422 = 16,
144 | FOURCC_BPP_I444 = 24,
145 | FOURCC_BPP_I411 = 12,
146 | FOURCC_BPP_I400 = 8,
147 | FOURCC_BPP_NV21 = 12,
148 | FOURCC_BPP_NV12 = 12,
149 | FOURCC_BPP_YUY2 = 16,
150 | FOURCC_BPP_UYVY = 16,
151 | FOURCC_BPP_M420 = 12, // deprecated
152 | FOURCC_BPP_Q420 = 12,
153 | FOURCC_BPP_ARGB = 32,
154 | FOURCC_BPP_BGRA = 32,
155 | FOURCC_BPP_ABGR = 32,
156 | FOURCC_BPP_RGBA = 32,
157 | FOURCC_BPP_AR30 = 32,
158 | FOURCC_BPP_AB30 = 32,
159 | FOURCC_BPP_24BG = 24,
160 | FOURCC_BPP_RAW = 24,
161 | FOURCC_BPP_RGBP = 16,
162 | FOURCC_BPP_RGBO = 16,
163 | FOURCC_BPP_R444 = 16,
164 | FOURCC_BPP_RGGB = 8,
165 | FOURCC_BPP_BGGR = 8,
166 | FOURCC_BPP_GRBG = 8,
167 | FOURCC_BPP_GBRG = 8,
168 | FOURCC_BPP_YV12 = 12,
169 | FOURCC_BPP_YV16 = 16,
170 | FOURCC_BPP_YV24 = 24,
171 | FOURCC_BPP_YU12 = 12,
172 | FOURCC_BPP_J420 = 12,
173 | FOURCC_BPP_J400 = 8,
174 | FOURCC_BPP_H420 = 12,
175 | FOURCC_BPP_H422 = 16,
176 | FOURCC_BPP_H010 = 24,
177 | FOURCC_BPP_MJPG = 0, // 0 means unknown.
178 | FOURCC_BPP_H264 = 0,
179 | FOURCC_BPP_IYUV = 12,
180 | FOURCC_BPP_YU16 = 16,
181 | FOURCC_BPP_YU24 = 24,
182 | FOURCC_BPP_YUYV = 16,
183 | FOURCC_BPP_YUVS = 16,
184 | FOURCC_BPP_HDYC = 16,
185 | FOURCC_BPP_2VUY = 16,
186 | FOURCC_BPP_JPEG = 1,
187 | FOURCC_BPP_DMB1 = 1,
188 | FOURCC_BPP_BA81 = 8,
189 | FOURCC_BPP_RGB3 = 24,
190 | FOURCC_BPP_BGR3 = 24,
191 | FOURCC_BPP_CM32 = 32,
192 | FOURCC_BPP_CM24 = 24,
193 |
194 | // Match any fourcc.
195 | FOURCC_BPP_ANY = 0, // 0 means unknown.
196 | };
197 |
198 | // Converts fourcc aliases into canonical ones.
199 | LIBYUV_API uint32_t CanonicalFourCC(uint32_t fourcc);
200 |
201 | #ifdef __cplusplus
202 | } // extern "C"
203 | } // namespace libyuv
204 | #endif
205 |
206 | #endif // INCLUDE_LIBYUV_VIDEO_COMMON_H_
207 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/rotate_row.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_ROTATE_ROW_H_
12 | #define INCLUDE_LIBYUV_ROTATE_ROW_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | #if defined(__pnacl__) || defined(__CLR_VER) || \
22 | (defined(__native_client__) && defined(__x86_64__)) || \
23 | (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
24 | #define LIBYUV_DISABLE_X86
25 | #endif
26 | #if defined(__native_client__)
27 | #define LIBYUV_DISABLE_NEON
28 | #endif
29 | // MemorySanitizer does not support assembly code yet. http://crbug.com/344505
30 | #if defined(__has_feature)
31 | #if __has_feature(memory_sanitizer)
32 | #define LIBYUV_DISABLE_X86
33 | #endif
34 | #endif
35 | // The following are available for Visual C and clangcl 32 bit:
36 | #if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER)
37 | #define HAS_TRANSPOSEWX8_SSSE3
38 | #define HAS_TRANSPOSEUVWX8_SSE2
39 | #endif
40 |
41 | // The following are available for GCC 32 or 64 bit:
42 | #if !defined(LIBYUV_DISABLE_X86) && (defined(__i386__) || defined(__x86_64__))
43 | #define HAS_TRANSPOSEWX8_SSSE3
44 | #endif
45 |
46 | // The following are available for 64 bit GCC:
47 | #if !defined(LIBYUV_DISABLE_X86) && defined(__x86_64__)
48 | #define HAS_TRANSPOSEWX8_FAST_SSSE3
49 | #define HAS_TRANSPOSEUVWX8_SSE2
50 | #endif
51 |
52 | #if !defined(LIBYUV_DISABLE_NEON) && \
53 | (defined(__ARM_NEON__) || defined(LIBYUV_NEON) || defined(__aarch64__))
54 | #define HAS_TRANSPOSEWX8_NEON
55 | #define HAS_TRANSPOSEUVWX8_NEON
56 | #endif
57 |
58 | #if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa)
59 | #define HAS_TRANSPOSEWX16_MSA
60 | #define HAS_TRANSPOSEUVWX16_MSA
61 | #endif
62 |
63 | #if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A)
64 | #define HAS_TRANSPOSEWX8_MMI
65 | #define HAS_TRANSPOSEUVWX8_MMI
66 | #endif
67 |
68 | void TransposeWxH_C(const uint8_t* src,
69 | int src_stride,
70 | uint8_t* dst,
71 | int dst_stride,
72 | int width,
73 | int height);
74 |
75 | void TransposeWx8_C(const uint8_t* src,
76 | int src_stride,
77 | uint8_t* dst,
78 | int dst_stride,
79 | int width);
80 | void TransposeWx16_C(const uint8_t* src,
81 | int src_stride,
82 | uint8_t* dst,
83 | int dst_stride,
84 | int width);
85 | void TransposeWx8_NEON(const uint8_t* src,
86 | int src_stride,
87 | uint8_t* dst,
88 | int dst_stride,
89 | int width);
90 | void TransposeWx8_SSSE3(const uint8_t* src,
91 | int src_stride,
92 | uint8_t* dst,
93 | int dst_stride,
94 | int width);
95 | void TransposeWx8_MMI(const uint8_t* src,
96 | int src_stride,
97 | uint8_t* dst,
98 | int dst_stride,
99 | int width);
100 | void TransposeWx8_Fast_SSSE3(const uint8_t* src,
101 | int src_stride,
102 | uint8_t* dst,
103 | int dst_stride,
104 | int width);
105 | void TransposeWx16_MSA(const uint8_t* src,
106 | int src_stride,
107 | uint8_t* dst,
108 | int dst_stride,
109 | int width);
110 |
111 | void TransposeWx8_Any_NEON(const uint8_t* src,
112 | int src_stride,
113 | uint8_t* dst,
114 | int dst_stride,
115 | int width);
116 | void TransposeWx8_Any_SSSE3(const uint8_t* src,
117 | int src_stride,
118 | uint8_t* dst,
119 | int dst_stride,
120 | int width);
121 | void TransposeWx8_Any_MMI(const uint8_t* src,
122 | int src_stride,
123 | uint8_t* dst,
124 | int dst_stride,
125 | int width);
126 | void TransposeWx8_Fast_Any_SSSE3(const uint8_t* src,
127 | int src_stride,
128 | uint8_t* dst,
129 | int dst_stride,
130 | int width);
131 | void TransposeWx16_Any_MSA(const uint8_t* src,
132 | int src_stride,
133 | uint8_t* dst,
134 | int dst_stride,
135 | int width);
136 |
137 | void TransposeUVWxH_C(const uint8_t* src,
138 | int src_stride,
139 | uint8_t* dst_a,
140 | int dst_stride_a,
141 | uint8_t* dst_b,
142 | int dst_stride_b,
143 | int width,
144 | int height);
145 |
146 | void TransposeUVWx8_C(const uint8_t* src,
147 | int src_stride,
148 | uint8_t* dst_a,
149 | int dst_stride_a,
150 | uint8_t* dst_b,
151 | int dst_stride_b,
152 | int width);
153 | void TransposeUVWx16_C(const uint8_t* src,
154 | int src_stride,
155 | uint8_t* dst_a,
156 | int dst_stride_a,
157 | uint8_t* dst_b,
158 | int dst_stride_b,
159 | int width);
160 | void TransposeUVWx8_SSE2(const uint8_t* src,
161 | int src_stride,
162 | uint8_t* dst_a,
163 | int dst_stride_a,
164 | uint8_t* dst_b,
165 | int dst_stride_b,
166 | int width);
167 | void TransposeUVWx8_NEON(const uint8_t* src,
168 | int src_stride,
169 | uint8_t* dst_a,
170 | int dst_stride_a,
171 | uint8_t* dst_b,
172 | int dst_stride_b,
173 | int width);
174 | void TransposeUVWx8_MMI(const uint8_t* src,
175 | int src_stride,
176 | uint8_t* dst_a,
177 | int dst_stride_a,
178 | uint8_t* dst_b,
179 | int dst_stride_b,
180 | int width);
181 | void TransposeUVWx16_MSA(const uint8_t* src,
182 | int src_stride,
183 | uint8_t* dst_a,
184 | int dst_stride_a,
185 | uint8_t* dst_b,
186 | int dst_stride_b,
187 | int width);
188 |
189 | void TransposeUVWx8_Any_SSE2(const uint8_t* src,
190 | int src_stride,
191 | uint8_t* dst_a,
192 | int dst_stride_a,
193 | uint8_t* dst_b,
194 | int dst_stride_b,
195 | int width);
196 | void TransposeUVWx8_Any_NEON(const uint8_t* src,
197 | int src_stride,
198 | uint8_t* dst_a,
199 | int dst_stride_a,
200 | uint8_t* dst_b,
201 | int dst_stride_b,
202 | int width);
203 | void TransposeUVWx8_Any_MMI(const uint8_t* src,
204 | int src_stride,
205 | uint8_t* dst_a,
206 | int dst_stride_a,
207 | uint8_t* dst_b,
208 | int dst_stride_b,
209 | int width);
210 | void TransposeUVWx16_Any_MSA(const uint8_t* src,
211 | int src_stride,
212 | uint8_t* dst_a,
213 | int dst_stride_a,
214 | uint8_t* dst_b,
215 | int dst_stride_b,
216 | int width);
217 |
218 | #ifdef __cplusplus
219 | } // extern "C"
220 | } // namespace libyuv
221 | #endif
222 |
223 | #endif // INCLUDE_LIBYUV_ROTATE_ROW_H_
224 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/convert_from_argb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_
12 | #define INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #ifdef __cplusplus
17 | namespace libyuv {
18 | extern "C" {
19 | #endif
20 |
21 | // Copy ARGB to ARGB.
22 | #define ARGBToARGB ARGBCopy
23 | LIBYUV_API
24 | int ARGBCopy(const uint8_t* src_argb,
25 | int src_stride_argb,
26 | uint8_t* dst_argb,
27 | int dst_stride_argb,
28 | int width,
29 | int height);
30 |
31 | // Convert ARGB To BGRA.
32 | LIBYUV_API
33 | int ARGBToBGRA(const uint8_t* src_argb,
34 | int src_stride_argb,
35 | uint8_t* dst_bgra,
36 | int dst_stride_bgra,
37 | int width,
38 | int height);
39 |
40 | // Convert ARGB To ABGR.
41 | LIBYUV_API
42 | int ARGBToABGR(const uint8_t* src_argb,
43 | int src_stride_argb,
44 | uint8_t* dst_abgr,
45 | int dst_stride_abgr,
46 | int width,
47 | int height);
48 |
49 | // Convert ARGB To RGBA.
50 | LIBYUV_API
51 | int ARGBToRGBA(const uint8_t* src_argb,
52 | int src_stride_argb,
53 | uint8_t* dst_rgba,
54 | int dst_stride_rgba,
55 | int width,
56 | int height);
57 |
58 | // Aliases
59 | #define ARGBToAB30 ABGRToAR30
60 | #define ABGRToAB30 ARGBToAR30
61 |
62 | // Convert ABGR To AR30.
63 | LIBYUV_API
64 | int ABGRToAR30(const uint8_t* src_abgr,
65 | int src_stride_abgr,
66 | uint8_t* dst_ar30,
67 | int dst_stride_ar30,
68 | int width,
69 | int height);
70 |
71 | // Convert ARGB To AR30.
72 | LIBYUV_API
73 | int ARGBToAR30(const uint8_t* src_argb,
74 | int src_stride_argb,
75 | uint8_t* dst_ar30,
76 | int dst_stride_ar30,
77 | int width,
78 | int height);
79 |
80 | // Convert ARGB To RGB24.
81 | LIBYUV_API
82 | int ARGBToRGB24(const uint8_t* src_argb,
83 | int src_stride_argb,
84 | uint8_t* dst_rgb24,
85 | int dst_stride_rgb24,
86 | int width,
87 | int height);
88 |
89 | // Convert ARGB To RAW.
90 | LIBYUV_API
91 | int ARGBToRAW(const uint8_t* src_argb,
92 | int src_stride_argb,
93 | uint8_t* dst_raw,
94 | int dst_stride_raw,
95 | int width,
96 | int height);
97 |
98 | // Convert ARGB To RGB565.
99 | LIBYUV_API
100 | int ARGBToRGB565(const uint8_t* src_argb,
101 | int src_stride_argb,
102 | uint8_t* dst_rgb565,
103 | int dst_stride_rgb565,
104 | int width,
105 | int height);
106 |
107 | // Convert ARGB To RGB565 with 4x4 dither matrix (16 bytes).
108 | // Values in dither matrix from 0 to 7 recommended.
109 | // The order of the dither matrix is first byte is upper left.
110 | // TODO(fbarchard): Consider pointer to 2d array for dither4x4.
111 | // const uint8_t(*dither)[4][4];
112 | LIBYUV_API
113 | int ARGBToRGB565Dither(const uint8_t* src_argb,
114 | int src_stride_argb,
115 | uint8_t* dst_rgb565,
116 | int dst_stride_rgb565,
117 | const uint8_t* dither4x4,
118 | int width,
119 | int height);
120 |
121 | // Convert ARGB To ARGB1555.
122 | LIBYUV_API
123 | int ARGBToARGB1555(const uint8_t* src_argb,
124 | int src_stride_argb,
125 | uint8_t* dst_argb1555,
126 | int dst_stride_argb1555,
127 | int width,
128 | int height);
129 |
130 | // Convert ARGB To ARGB4444.
131 | LIBYUV_API
132 | int ARGBToARGB4444(const uint8_t* src_argb,
133 | int src_stride_argb,
134 | uint8_t* dst_argb4444,
135 | int dst_stride_argb4444,
136 | int width,
137 | int height);
138 |
139 | // Convert ARGB To I444.
140 | LIBYUV_API
141 | int ARGBToI444(const uint8_t* src_argb,
142 | int src_stride_argb,
143 | uint8_t* dst_y,
144 | int dst_stride_y,
145 | uint8_t* dst_u,
146 | int dst_stride_u,
147 | uint8_t* dst_v,
148 | int dst_stride_v,
149 | int width,
150 | int height);
151 |
152 | // Convert ARGB To I422.
153 | LIBYUV_API
154 | int ARGBToI422(const uint8_t* src_argb,
155 | int src_stride_argb,
156 | uint8_t* dst_y,
157 | int dst_stride_y,
158 | uint8_t* dst_u,
159 | int dst_stride_u,
160 | uint8_t* dst_v,
161 | int dst_stride_v,
162 | int width,
163 | int height);
164 |
165 | // Convert ARGB To I420. (also in convert.h)
166 | LIBYUV_API
167 | int ARGBToI420(const uint8_t* src_argb,
168 | int src_stride_argb,
169 | uint8_t* dst_y,
170 | int dst_stride_y,
171 | uint8_t* dst_u,
172 | int dst_stride_u,
173 | uint8_t* dst_v,
174 | int dst_stride_v,
175 | int width,
176 | int height);
177 |
178 | // Convert ARGB to J420. (JPeg full range I420).
179 | LIBYUV_API
180 | int ARGBToJ420(const uint8_t* src_argb,
181 | int src_stride_argb,
182 | uint8_t* dst_yj,
183 | int dst_stride_yj,
184 | uint8_t* dst_u,
185 | int dst_stride_u,
186 | uint8_t* dst_v,
187 | int dst_stride_v,
188 | int width,
189 | int height);
190 |
191 | // Convert ARGB to J422.
192 | LIBYUV_API
193 | int ARGBToJ422(const uint8_t* src_argb,
194 | int src_stride_argb,
195 | uint8_t* dst_yj,
196 | int dst_stride_yj,
197 | uint8_t* dst_u,
198 | int dst_stride_u,
199 | uint8_t* dst_v,
200 | int dst_stride_v,
201 | int width,
202 | int height);
203 |
204 | // Convert ARGB to J400. (JPeg full range).
205 | LIBYUV_API
206 | int ARGBToJ400(const uint8_t* src_argb,
207 | int src_stride_argb,
208 | uint8_t* dst_yj,
209 | int dst_stride_yj,
210 | int width,
211 | int height);
212 |
213 | // Convert RGBA to J400. (JPeg full range).
214 | LIBYUV_API
215 | int RGBAToJ400(const uint8_t* src_rgba,
216 | int src_stride_rgba,
217 | uint8_t* dst_yj,
218 | int dst_stride_yj,
219 | int width,
220 | int height);
221 |
222 | // Convert ARGB to I400.
223 | LIBYUV_API
224 | int ARGBToI400(const uint8_t* src_argb,
225 | int src_stride_argb,
226 | uint8_t* dst_y,
227 | int dst_stride_y,
228 | int width,
229 | int height);
230 |
231 | // Convert ARGB to G. (Reverse of J400toARGB, which replicates G back to ARGB)
232 | LIBYUV_API
233 | int ARGBToG(const uint8_t* src_argb,
234 | int src_stride_argb,
235 | uint8_t* dst_g,
236 | int dst_stride_g,
237 | int width,
238 | int height);
239 |
240 | // Convert ARGB To NV12.
241 | LIBYUV_API
242 | int ARGBToNV12(const uint8_t* src_argb,
243 | int src_stride_argb,
244 | uint8_t* dst_y,
245 | int dst_stride_y,
246 | uint8_t* dst_uv,
247 | int dst_stride_uv,
248 | int width,
249 | int height);
250 |
251 | // Convert ARGB To NV21.
252 | LIBYUV_API
253 | int ARGBToNV21(const uint8_t* src_argb,
254 | int src_stride_argb,
255 | uint8_t* dst_y,
256 | int dst_stride_y,
257 | uint8_t* dst_vu,
258 | int dst_stride_vu,
259 | int width,
260 | int height);
261 |
262 | // Convert ABGR To NV12.
263 | LIBYUV_API
264 | int ABGRToNV12(const uint8_t* src_abgr,
265 | int src_stride_abgr,
266 | uint8_t* dst_y,
267 | int dst_stride_y,
268 | uint8_t* dst_uv,
269 | int dst_stride_uv,
270 | int width,
271 | int height);
272 |
273 | // Convert ABGR To NV21.
274 | LIBYUV_API
275 | int ABGRToNV21(const uint8_t* src_abgr,
276 | int src_stride_abgr,
277 | uint8_t* dst_y,
278 | int dst_stride_y,
279 | uint8_t* dst_vu,
280 | int dst_stride_vu,
281 | int width,
282 | int height);
283 |
284 | // Convert ARGB To YUY2.
285 | LIBYUV_API
286 | int ARGBToYUY2(const uint8_t* src_argb,
287 | int src_stride_argb,
288 | uint8_t* dst_yuy2,
289 | int dst_stride_yuy2,
290 | int width,
291 | int height);
292 |
293 | // Convert ARGB To UYVY.
294 | LIBYUV_API
295 | int ARGBToUYVY(const uint8_t* src_argb,
296 | int src_stride_argb,
297 | uint8_t* dst_uyvy,
298 | int dst_stride_uyvy,
299 | int width,
300 | int height);
301 |
302 | #ifdef __cplusplus
303 | } // extern "C"
304 | } // namespace libyuv
305 | #endif
306 |
307 | #endif // INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_
308 |
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/macros_msa.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_MACROS_MSA_H_
12 | #define INCLUDE_LIBYUV_MACROS_MSA_H_
13 |
14 | #if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa)
15 | #include
16 | #include
17 |
18 | #if (__mips_isa_rev >= 6)
19 | #define LW(psrc) \
20 | ({ \
21 | const uint8_t* psrc_lw_m = (const uint8_t*)(psrc); \
22 | uint32_t val_m; \
23 | asm volatile("lw %[val_m], %[psrc_lw_m] \n" \
24 | : [val_m] "=r"(val_m) \
25 | : [psrc_lw_m] "m"(*psrc_lw_m)); \
26 | val_m; \
27 | })
28 |
29 | #if (__mips == 64)
30 | #define LD(psrc) \
31 | ({ \
32 | const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \
33 | uint64_t val_m = 0; \
34 | asm volatile("ld %[val_m], %[psrc_ld_m] \n" \
35 | : [val_m] "=r"(val_m) \
36 | : [psrc_ld_m] "m"(*psrc_ld_m)); \
37 | val_m; \
38 | })
39 | #else // !(__mips == 64)
40 | #define LD(psrc) \
41 | ({ \
42 | const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \
43 | uint32_t val0_m, val1_m; \
44 | uint64_t val_m = 0; \
45 | val0_m = LW(psrc_ld_m); \
46 | val1_m = LW(psrc_ld_m + 4); \
47 | val_m = (uint64_t)(val1_m); /* NOLINT */ \
48 | val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); /* NOLINT */ \
49 | val_m = (uint64_t)(val_m | (uint64_t)val0_m); /* NOLINT */ \
50 | val_m; \
51 | })
52 | #endif // (__mips == 64)
53 |
54 | #define SW(val, pdst) \
55 | ({ \
56 | uint8_t* pdst_sw_m = (uint8_t*)(pdst); /* NOLINT */ \
57 | uint32_t val_m = (val); \
58 | asm volatile("sw %[val_m], %[pdst_sw_m] \n" \
59 | : [pdst_sw_m] "=m"(*pdst_sw_m) \
60 | : [val_m] "r"(val_m)); \
61 | })
62 |
63 | #if (__mips == 64)
64 | #define SD(val, pdst) \
65 | ({ \
66 | uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \
67 | uint64_t val_m = (val); \
68 | asm volatile("sd %[val_m], %[pdst_sd_m] \n" \
69 | : [pdst_sd_m] "=m"(*pdst_sd_m) \
70 | : [val_m] "r"(val_m)); \
71 | })
72 | #else // !(__mips == 64)
73 | #define SD(val, pdst) \
74 | ({ \
75 | uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \
76 | uint32_t val0_m, val1_m; \
77 | val0_m = (uint32_t)((val)&0x00000000FFFFFFFF); \
78 | val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \
79 | SW(val0_m, pdst_sd_m); \
80 | SW(val1_m, pdst_sd_m + 4); \
81 | })
82 | #endif // !(__mips == 64)
83 | #else // !(__mips_isa_rev >= 6)
84 | #define LW(psrc) \
85 | ({ \
86 | const uint8_t* psrc_lw_m = (const uint8_t*)(psrc); \
87 | uint32_t val_m; \
88 | asm volatile("ulw %[val_m], %[psrc_lw_m] \n" \
89 | : [val_m] "=r"(val_m) \
90 | : [psrc_lw_m] "m"(*psrc_lw_m)); \
91 | val_m; \
92 | })
93 |
94 | #if (__mips == 64)
95 | #define LD(psrc) \
96 | ({ \
97 | const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \
98 | uint64_t val_m = 0; \
99 | asm volatile("uld %[val_m], %[psrc_ld_m] \n" \
100 | : [val_m] "=r"(val_m) \
101 | : [psrc_ld_m] "m"(*psrc_ld_m)); \
102 | val_m; \
103 | })
104 | #else // !(__mips == 64)
105 | #define LD(psrc) \
106 | ({ \
107 | const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \
108 | uint32_t val0_m, val1_m; \
109 | uint64_t val_m = 0; \
110 | val0_m = LW(psrc_ld_m); \
111 | val1_m = LW(psrc_ld_m + 4); \
112 | val_m = (uint64_t)(val1_m); /* NOLINT */ \
113 | val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); /* NOLINT */ \
114 | val_m = (uint64_t)(val_m | (uint64_t)val0_m); /* NOLINT */ \
115 | val_m; \
116 | })
117 | #endif // (__mips == 64)
118 |
119 | #define SW(val, pdst) \
120 | ({ \
121 | uint8_t* pdst_sw_m = (uint8_t*)(pdst); /* NOLINT */ \
122 | uint32_t val_m = (val); \
123 | asm volatile("usw %[val_m], %[pdst_sw_m] \n" \
124 | : [pdst_sw_m] "=m"(*pdst_sw_m) \
125 | : [val_m] "r"(val_m)); \
126 | })
127 |
128 | #define SD(val, pdst) \
129 | ({ \
130 | uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \
131 | uint32_t val0_m, val1_m; \
132 | val0_m = (uint32_t)((val)&0x00000000FFFFFFFF); \
133 | val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \
134 | SW(val0_m, pdst_sd_m); \
135 | SW(val1_m, pdst_sd_m + 4); \
136 | })
137 | #endif // (__mips_isa_rev >= 6)
138 |
139 | // TODO(fbarchard): Consider removing __VAR_ARGS versions.
140 | #define LD_B(RTYPE, psrc) *((RTYPE*)(psrc)) /* NOLINT */
141 | #define LD_UB(...) LD_B(const v16u8, __VA_ARGS__)
142 |
143 | #define LD_H(RTYPE, psrc) *((RTYPE*)(psrc)) /* NOLINT */
144 | #define LD_UH(...) LD_H(const v8u16, __VA_ARGS__)
145 |
146 | #define ST_B(RTYPE, in, pdst) *((RTYPE*)(pdst)) = (in) /* NOLINT */
147 | #define ST_UB(...) ST_B(v16u8, __VA_ARGS__)
148 |
149 | #define ST_H(RTYPE, in, pdst) *((RTYPE*)(pdst)) = (in) /* NOLINT */
150 | #define ST_UH(...) ST_H(v8u16, __VA_ARGS__)
151 |
152 | /* Description : Load two vectors with 16 'byte' sized elements
153 | Arguments : Inputs - psrc, stride
154 | Outputs - out0, out1
155 | Return Type - as per RTYPE
156 | Details : Load 16 byte elements in 'out0' from (psrc)
157 | Load 16 byte elements in 'out1' from (psrc + stride)
158 | */
159 | #define LD_B2(RTYPE, psrc, stride, out0, out1) \
160 | { \
161 | out0 = LD_B(RTYPE, (psrc)); \
162 | out1 = LD_B(RTYPE, (psrc) + stride); \
163 | }
164 | #define LD_UB2(...) LD_B2(const v16u8, __VA_ARGS__)
165 |
166 | #define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) \
167 | { \
168 | LD_B2(RTYPE, (psrc), stride, out0, out1); \
169 | LD_B2(RTYPE, (psrc) + 2 * stride, stride, out2, out3); \
170 | }
171 | #define LD_UB4(...) LD_B4(const v16u8, __VA_ARGS__)
172 |
173 | /* Description : Store two vectors with stride each having 16 'byte' sized
174 | elements
175 | Arguments : Inputs - in0, in1, pdst, stride
176 | Details : Store 16 byte elements from 'in0' to (pdst)
177 | Store 16 byte elements from 'in1' to (pdst + stride)
178 | */
179 | #define ST_B2(RTYPE, in0, in1, pdst, stride) \
180 | { \
181 | ST_B(RTYPE, in0, (pdst)); \
182 | ST_B(RTYPE, in1, (pdst) + stride); \
183 | }
184 | #define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)
185 |
186 | #define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride) \
187 | { \
188 | ST_B2(RTYPE, in0, in1, (pdst), stride); \
189 | ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
190 | }
191 | #define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)
192 |
193 | /* Description : Store vectors of 8 halfword elements with stride
194 | Arguments : Inputs - in0, in1, pdst, stride
195 | Details : Store 8 halfword elements from 'in0' to (pdst)
196 | Store 8 halfword elements from 'in1' to (pdst + stride)
197 | */
198 | #define ST_H2(RTYPE, in0, in1, pdst, stride) \
199 | { \
200 | ST_H(RTYPE, in0, (pdst)); \
201 | ST_H(RTYPE, in1, (pdst) + stride); \
202 | }
203 | #define ST_UH2(...) ST_H2(v8u16, __VA_ARGS__)
204 |
205 | // TODO(fbarchard): Consider using __msa_vshf_b and __msa_ilvr_b directly.
206 | /* Description : Shuffle byte vector elements as per mask vector
207 | Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
208 | Outputs - out0, out1
209 | Return Type - as per RTYPE
210 | Details : Byte elements from 'in0' & 'in1' are copied selectively to
211 | 'out0' as per control vector 'mask0'
212 | */
213 | #define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \
214 | { \
215 | out0 = (RTYPE)__msa_vshf_b((v16i8)mask0, (v16i8)in1, (v16i8)in0); \
216 | out1 = (RTYPE)__msa_vshf_b((v16i8)mask1, (v16i8)in3, (v16i8)in2); \
217 | }
218 | #define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)
219 |
220 | /* Description : Interleave both left and right half of input vectors
221 | Arguments : Inputs - in0, in1
222 | Outputs - out0, out1
223 | Return Type - as per RTYPE
224 | Details : Right half of byte elements from 'in0' and 'in1' are
225 | interleaved and written to 'out0'
226 | */
227 | #define ILVRL_B2(RTYPE, in0, in1, out0, out1) \
228 | { \
229 | out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
230 | out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \
231 | }
232 | #define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)
233 |
234 | #endif /* !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) */
235 |
236 | #endif // INCLUDE_LIBYUV_MACROS_MSA_H_
237 |
--------------------------------------------------------------------------------
/yuv/src/main/java/com/theeasiestway/yuv/YuvUtils.kt:
--------------------------------------------------------------------------------
1 | package com.theeasiestway.yuv
2 |
3 | import android.media.Image
4 | import android.util.Log
5 | import com.theeasiestway.yuv.entities.ArgbFrame
6 | import com.theeasiestway.yuv.entities.YuvFrame
7 | import java.nio.ByteBuffer
8 |
9 | //
10 | // Created by Loboda Alexey on 22.06.2020.
11 | //
12 |
13 | class YuvUtils {
14 |
15 | companion object {
16 |
17 | val TAG = "YuvUtils"
18 |
19 | init {
20 | try { System.loadLibrary("easyyuv") }
21 | catch (e: Exception) { Log.e(TAG, "Couldn't load easyyuv library: $e") }
22 | }
23 | }
24 |
25 | //
26 | // Scale
27 | //
28 |
29 | fun scale(image: Image, dstWidth: Int, dstHeight: Int, filerMode: Int): YuvFrame {
30 | require(filerMode in 0..3) { "filterMode: $filerMode is not unsupported. Check supported values in com.theeasiestway.libyuv.Constant.kt" }
31 | val outFrame = FramesFactory.instanceYuv(dstWidth, dstHeight)
32 | scale(image.planes[0].buffer,
33 | image.planes[1].buffer,
34 | image.planes[2].buffer,
35 | image.planes[0].rowStride,
36 | image.planes[1].rowStride,
37 | image.planes[2].rowStride,
38 | outFrame.y,
39 | outFrame.u,
40 | outFrame.v,
41 | outFrame.yStride,
42 | outFrame.uStride,
43 | outFrame.vStride,
44 | image.width,
45 | image.height,
46 | dstWidth,
47 | dstHeight,
48 | filerMode)
49 | return outFrame
50 | }
51 |
52 | fun scale(yuvFrame: YuvFrame, dstWidth: Int, dstHeight: Int, filerMode: Int): YuvFrame {
53 | require(filerMode in 0..3) { "filterMode: $filerMode is not unsupported. Check supported values in com.theeasiestway.libyuv.Constant.kt" }
54 | val outFrame = FramesFactory.instanceYuv(dstWidth, dstHeight)
55 | scale(yuvFrame.y,
56 | yuvFrame.u,
57 | yuvFrame.v,
58 | yuvFrame.yStride,
59 | yuvFrame.uStride,
60 | yuvFrame.vStride,
61 | outFrame.y,
62 | outFrame.u,
63 | outFrame.v,
64 | outFrame.yStride,
65 | outFrame.uStride,
66 | outFrame.vStride,
67 | yuvFrame.width,
68 | yuvFrame.height,
69 | dstWidth,
70 | dstHeight,
71 | filerMode)
72 | return outFrame
73 | }
74 |
75 | private external fun scale(y: ByteBuffer,
76 | u: ByteBuffer,
77 | v: ByteBuffer,
78 | yStride: Int,
79 | uStride: Int,
80 | vStride: Int,
81 | yOut: ByteBuffer,
82 | uOut: ByteBuffer,
83 | vOut: ByteBuffer,
84 | yOutStride: Int,
85 | uOutStride: Int,
86 | vOutStride: Int,
87 | srcWidth: Int,
88 | srcHeight: Int,
89 | dstWidth: Int,
90 | dstHeight: Int,
91 | filterMode: Int)
92 |
93 | //
94 | // Rotate
95 | //
96 |
97 | fun rotate(image: Image, rotationMode: Int): YuvFrame {
98 | require(rotationMode == 0 || rotationMode == 90 || rotationMode == 180 || rotationMode == 270) { "rotationMode: $rotationMode is not unsupported. Check supported values in com.theeasiestway.libyuv.Constant.kt" }
99 | val outFrame = FramesFactory.instanceYuv(image.width, image.height, rotationMode)
100 | rotate(image.planes[0].buffer,
101 | image.planes[1].buffer,
102 | image.planes[2].buffer,
103 | image.planes[0].rowStride,
104 | image.planes[1].rowStride,
105 | image.planes[2].rowStride,
106 | outFrame.y,
107 | outFrame.u,
108 | outFrame.v,
109 | outFrame.yStride,
110 | outFrame.uStride,
111 | outFrame.vStride,
112 | image.width,
113 | image.height,
114 | rotationMode)
115 | return outFrame
116 | }
117 |
118 | fun rotate(yuvFrame: YuvFrame, rotationMode: Int): YuvFrame {
119 | require(rotationMode == 0 || rotationMode == 90 || rotationMode == 180 || rotationMode == 270) { "rotationMode: $rotationMode is not unsupported. Check supported values in com.theeasiestway.libyuv.Constant.kt" }
120 | val outFrame = FramesFactory.instanceYuv(yuvFrame.width, yuvFrame.height, rotationMode)
121 | rotate(yuvFrame.y,
122 | yuvFrame.u,
123 | yuvFrame.v,
124 | yuvFrame.yStride,
125 | yuvFrame.uStride,
126 | yuvFrame.vStride,
127 | outFrame.y,
128 | outFrame.u,
129 | outFrame.v,
130 | outFrame.yStride,
131 | outFrame.uStride,
132 | outFrame.vStride,
133 | yuvFrame.width,
134 | yuvFrame.height,
135 | rotationMode)
136 | return outFrame
137 | }
138 |
139 | private external fun rotate(y: ByteBuffer,
140 | u: ByteBuffer,
141 | v: ByteBuffer,
142 | yStride: Int,
143 | uStride: Int,
144 | vStride: Int,
145 | yOut: ByteBuffer,
146 | uOut: ByteBuffer,
147 | vOut: ByteBuffer,
148 | yOutStride: Int,
149 | uOutStride: Int,
150 | vOutStride: Int,
151 | width: Int,
152 | height: Int,
153 | rotationMode: Int)
154 |
155 | //
156 | // Mirror
157 | //
158 |
159 | fun mirrorH(image: Image): YuvFrame {
160 | val outFrame = FramesFactory.instanceYuv(image.width, image.height)
161 | mirrorH(image.planes[0].buffer,
162 | image.planes[1].buffer,
163 | image.planes[2].buffer,
164 | image.planes[0].rowStride,
165 | image.planes[1].rowStride,
166 | image.planes[2].rowStride,
167 | outFrame.y,
168 | outFrame.u,
169 | outFrame.v,
170 | outFrame.yStride,
171 | outFrame.uStride,
172 | outFrame.vStride,
173 | image.width,
174 | image.height)
175 | return outFrame
176 | }
177 |
178 | fun mirrorH(yuvFrame: YuvFrame): YuvFrame {
179 | val outFrame = FramesFactory.instanceYuv(yuvFrame.width, yuvFrame.height)
180 | mirrorH(yuvFrame.y,
181 | yuvFrame.u,
182 | yuvFrame.v,
183 | yuvFrame.yStride,
184 | yuvFrame.uStride,
185 | yuvFrame.vStride,
186 | outFrame.y,
187 | outFrame.u,
188 | outFrame.v,
189 | outFrame.yStride,
190 | outFrame.uStride,
191 | outFrame.vStride,
192 | yuvFrame.width,
193 | yuvFrame.height)
194 | return outFrame
195 | }
196 |
197 | fun mirrorV(image: Image): YuvFrame {
198 | val outFrame = FramesFactory.instanceYuv(image.width, image.height)
199 | rotate(image.planes[0].buffer,
200 | image.planes[1].buffer,
201 | image.planes[2].buffer,
202 | image.planes[0].rowStride,
203 | image.planes[1].rowStride,
204 | image.planes[2].rowStride,
205 | outFrame.y,
206 | outFrame.u,
207 | outFrame.v,
208 | outFrame.yStride,
209 | outFrame.uStride,
210 | outFrame.vStride,
211 | image.width,
212 | -image.height,
213 | Constants.ROTATE_0)
214 | return outFrame
215 | }
216 |
217 | fun mirrorV(yuvFrame: YuvFrame): YuvFrame {
218 | val outFrame = FramesFactory.instanceYuv(yuvFrame.width, yuvFrame.height)
219 | rotate(yuvFrame.y,
220 | yuvFrame.u,
221 | yuvFrame.v,
222 | yuvFrame.yStride,
223 | yuvFrame.uStride,
224 | yuvFrame.vStride,
225 | outFrame.y,
226 | outFrame.u,
227 | outFrame.v,
228 | outFrame.yStride,
229 | outFrame.uStride,
230 | outFrame.vStride,
231 | yuvFrame.width,
232 | -yuvFrame.height,
233 | Constants.ROTATE_0)
234 | return outFrame
235 | }
236 |
237 | private external fun mirrorH(y: ByteBuffer,
238 | u: ByteBuffer,
239 | v: ByteBuffer,
240 | yStride: Int,
241 | uStride: Int,
242 | vStride: Int,
243 | yOut: ByteBuffer,
244 | uOut: ByteBuffer,
245 | vOut: ByteBuffer,
246 | yOutStride: Int,
247 | uOutStride: Int,
248 | vOutStride: Int,
249 | width: Int,
250 | height: Int)
251 |
252 | //
253 | // YUV to ARGB
254 | //
255 |
256 | fun yuv420ToArgb(image: Image): ArgbFrame {
257 | val outFrame = FramesFactory.instanceArgb(image.width, image.height)
258 | yuv420ToArgb(image.planes[0].buffer,
259 | image.planes[1].buffer,
260 | image.planes[2].buffer,
261 | image.planes[0].rowStride,
262 | image.planes[1].rowStride,
263 | image.planes[2].rowStride,
264 | outFrame.data,
265 | outFrame.dataStride,
266 | image.width,
267 | image.height)
268 | return outFrame
269 | }
270 |
271 | fun yuv420ToArgb(yuvFrame: YuvFrame): ArgbFrame {
272 | val outFrame = FramesFactory.instanceArgb(yuvFrame.width, yuvFrame.height)
273 | yuv420ToArgb(yuvFrame.y,
274 | yuvFrame.u,
275 | yuvFrame.v,
276 | yuvFrame.yStride,
277 | yuvFrame.uStride,
278 | yuvFrame.vStride,
279 | outFrame.data,
280 | outFrame.dataStride,
281 | yuvFrame.width,
282 | yuvFrame.height)
283 | return outFrame
284 | }
285 |
286 | private external fun yuv420ToArgb(y: ByteBuffer,
287 | u: ByteBuffer,
288 | v: ByteBuffer,
289 | yStride: Int,
290 | uStride: Int,
291 | vStride: Int,
292 | out: ByteBuffer,
293 | outStride: Int,
294 | width: Int,
295 | height: Int)
296 |
297 | //
298 | // Convert Android YUV to libyuv YUV
299 | //
300 |
301 | fun convertToI420(image: Image): YuvFrame {
302 | val outFrame = FramesFactory.instanceYuv(image.width, image.height)
303 | convertToI420(image.planes[0].buffer,
304 | image.planes[1].buffer,
305 | image.planes[2].buffer,
306 | image.planes[0].rowStride,
307 | image.planes[1].rowStride,
308 | image.planes[2].rowStride,
309 | image.planes[2].pixelStride,
310 | outFrame.y,
311 | outFrame.u,
312 | outFrame.v,
313 | outFrame.yStride,
314 | outFrame.uStride,
315 | outFrame.vStride,
316 | image.width,
317 | image.height)
318 | return outFrame
319 | }
320 |
321 | fun convertToI420(yuvFrame: YuvFrame, uvPixelStride: Int): YuvFrame {
322 | val outFrame = FramesFactory.instanceYuv(yuvFrame.width, yuvFrame.height)
323 | convertToI420(yuvFrame.y,
324 | yuvFrame.u,
325 | yuvFrame.v,
326 | yuvFrame.yStride,
327 | yuvFrame.uStride,
328 | yuvFrame.vStride,
329 | uvPixelStride,
330 | outFrame.y,
331 | outFrame.u,
332 | outFrame.v,
333 | outFrame.yStride,
334 | outFrame.uStride,
335 | outFrame.vStride,
336 | yuvFrame.width,
337 | yuvFrame.height)
338 | return outFrame
339 | }
340 |
341 | private external fun convertToI420(y: ByteBuffer,
342 | u: ByteBuffer,
343 | v: ByteBuffer,
344 | yStride: Int,
345 | uStride: Int,
346 | vStride: Int,
347 | srcPixelStrideUv: Int,
348 | yOut: ByteBuffer,
349 | uOut: ByteBuffer,
350 | vOut: ByteBuffer,
351 | yOutStride: Int,
352 | uOutStride: Int,
353 | vOutStride: Int,
354 | width: Int,
355 | height: Int)
356 | }
--------------------------------------------------------------------------------
/yuv/src/main/cpp/include/libyuv/convert.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_CONVERT_H_
12 | #define INCLUDE_LIBYUV_CONVERT_H_
13 |
14 | #include "libyuv/basic_types.h"
15 |
16 | #include "libyuv/rotate.h" // For enum RotationMode.
17 |
18 | // TODO(fbarchard): fix WebRTC source to include following libyuv headers:
19 | #include "libyuv/convert_argb.h" // For WebRTC I420ToARGB. b/620
20 | #include "libyuv/convert_from.h" // For WebRTC ConvertFromI420. b/620
21 | #include "libyuv/planar_functions.h" // For WebRTC I420Rect, CopyPlane. b/618
22 |
23 | #ifdef __cplusplus
24 | namespace libyuv {
25 | extern "C" {
26 | #endif
27 |
28 | // Convert I444 to I420.
29 | LIBYUV_API
30 | int I444ToI420(const uint8_t* src_y,
31 | int src_stride_y,
32 | const uint8_t* src_u,
33 | int src_stride_u,
34 | const uint8_t* src_v,
35 | int src_stride_v,
36 | uint8_t* dst_y,
37 | int dst_stride_y,
38 | uint8_t* dst_u,
39 | int dst_stride_u,
40 | uint8_t* dst_v,
41 | int dst_stride_v,
42 | int width,
43 | int height);
44 |
45 | // Convert I444 to NV12.
46 | LIBYUV_API
47 | int I444ToNV12(const uint8_t* src_y,
48 | int src_stride_y,
49 | const uint8_t* src_u,
50 | int src_stride_u,
51 | const uint8_t* src_v,
52 | int src_stride_v,
53 | uint8_t* dst_y,
54 | int dst_stride_y,
55 | uint8_t* dst_uv,
56 | int dst_stride_uv,
57 | int width,
58 | int height);
59 |
60 | // Convert I444 to NV21.
61 | LIBYUV_API
62 | int I444ToNV21(const uint8_t* src_y,
63 | int src_stride_y,
64 | const uint8_t* src_u,
65 | int src_stride_u,
66 | const uint8_t* src_v,
67 | int src_stride_v,
68 | uint8_t* dst_y,
69 | int dst_stride_y,
70 | uint8_t* dst_vu,
71 | int dst_stride_vu,
72 | int width,
73 | int height);
74 |
75 | // Convert I422 to I420.
76 | LIBYUV_API
77 | int I422ToI420(const uint8_t* src_y,
78 | int src_stride_y,
79 | const uint8_t* src_u,
80 | int src_stride_u,
81 | const uint8_t* src_v,
82 | int src_stride_v,
83 | uint8_t* dst_y,
84 | int dst_stride_y,
85 | uint8_t* dst_u,
86 | int dst_stride_u,
87 | uint8_t* dst_v,
88 | int dst_stride_v,
89 | int width,
90 | int height);
91 |
92 | // Convert I422 to NV21.
93 | LIBYUV_API
94 | int I422ToNV21(const uint8_t* src_y,
95 | int src_stride_y,
96 | const uint8_t* src_u,
97 | int src_stride_u,
98 | const uint8_t* src_v,
99 | int src_stride_v,
100 | uint8_t* dst_y,
101 | int dst_stride_y,
102 | uint8_t* dst_vu,
103 | int dst_stride_vu,
104 | int width,
105 | int height);
106 |
107 | // Copy I420 to I420.
108 | #define I420ToI420 I420Copy
109 | LIBYUV_API
110 | int I420Copy(const uint8_t* src_y,
111 | int src_stride_y,
112 | const uint8_t* src_u,
113 | int src_stride_u,
114 | const uint8_t* src_v,
115 | int src_stride_v,
116 | uint8_t* dst_y,
117 | int dst_stride_y,
118 | uint8_t* dst_u,
119 | int dst_stride_u,
120 | uint8_t* dst_v,
121 | int dst_stride_v,
122 | int width,
123 | int height);
124 |
125 | // Copy I010 to I010
126 | #define I010ToI010 I010Copy
127 | #define H010ToH010 I010Copy
128 | LIBYUV_API
129 | int I010Copy(const uint16_t* src_y,
130 | int src_stride_y,
131 | const uint16_t* src_u,
132 | int src_stride_u,
133 | const uint16_t* src_v,
134 | int src_stride_v,
135 | uint16_t* dst_y,
136 | int dst_stride_y,
137 | uint16_t* dst_u,
138 | int dst_stride_u,
139 | uint16_t* dst_v,
140 | int dst_stride_v,
141 | int width,
142 | int height);
143 |
144 | // Convert 10 bit YUV to 8 bit
145 | #define H010ToH420 I010ToI420
146 | LIBYUV_API
147 | int I010ToI420(const uint16_t* src_y,
148 | int src_stride_y,
149 | const uint16_t* src_u,
150 | int src_stride_u,
151 | const uint16_t* src_v,
152 | int src_stride_v,
153 | uint8_t* dst_y,
154 | int dst_stride_y,
155 | uint8_t* dst_u,
156 | int dst_stride_u,
157 | uint8_t* dst_v,
158 | int dst_stride_v,
159 | int width,
160 | int height);
161 |
162 | // Convert I400 (grey) to I420.
163 | LIBYUV_API
164 | int I400ToI420(const uint8_t* src_y,
165 | int src_stride_y,
166 | uint8_t* dst_y,
167 | int dst_stride_y,
168 | uint8_t* dst_u,
169 | int dst_stride_u,
170 | uint8_t* dst_v,
171 | int dst_stride_v,
172 | int width,
173 | int height);
174 |
175 | // Convert I400 (grey) to NV21.
176 | LIBYUV_API
177 | int I400ToNV21(const uint8_t* src_y,
178 | int src_stride_y,
179 | uint8_t* dst_y,
180 | int dst_stride_y,
181 | uint8_t* dst_vu,
182 | int dst_stride_vu,
183 | int width,
184 | int height);
185 |
186 | #define J400ToJ420 I400ToI420
187 |
188 | // Convert NV12 to I420.
189 | LIBYUV_API
190 | int NV12ToI420(const uint8_t* src_y,
191 | int src_stride_y,
192 | const uint8_t* src_uv,
193 | int src_stride_uv,
194 | uint8_t* dst_y,
195 | int dst_stride_y,
196 | uint8_t* dst_u,
197 | int dst_stride_u,
198 | uint8_t* dst_v,
199 | int dst_stride_v,
200 | int width,
201 | int height);
202 |
203 | // Convert NV21 to I420.
204 | LIBYUV_API
205 | int NV21ToI420(const uint8_t* src_y,
206 | int src_stride_y,
207 | const uint8_t* src_vu,
208 | int src_stride_vu,
209 | uint8_t* dst_y,
210 | int dst_stride_y,
211 | uint8_t* dst_u,
212 | int dst_stride_u,
213 | uint8_t* dst_v,
214 | int dst_stride_v,
215 | int width,
216 | int height);
217 |
218 | // Convert YUY2 to I420.
219 | LIBYUV_API
220 | int YUY2ToI420(const uint8_t* src_yuy2,
221 | int src_stride_yuy2,
222 | uint8_t* dst_y,
223 | int dst_stride_y,
224 | uint8_t* dst_u,
225 | int dst_stride_u,
226 | uint8_t* dst_v,
227 | int dst_stride_v,
228 | int width,
229 | int height);
230 |
231 | // Convert UYVY to I420.
232 | LIBYUV_API
233 | int UYVYToI420(const uint8_t* src_uyvy,
234 | int src_stride_uyvy,
235 | uint8_t* dst_y,
236 | int dst_stride_y,
237 | uint8_t* dst_u,
238 | int dst_stride_u,
239 | uint8_t* dst_v,
240 | int dst_stride_v,
241 | int width,
242 | int height);
243 |
244 | // Convert AYUV to NV12.
245 | LIBYUV_API
246 | int AYUVToNV12(const uint8_t* src_ayuv,
247 | int src_stride_ayuv,
248 | uint8_t* dst_y,
249 | int dst_stride_y,
250 | uint8_t* dst_uv,
251 | int dst_stride_uv,
252 | int width,
253 | int height);
254 |
255 | // Convert AYUV to NV21.
256 | LIBYUV_API
257 | int AYUVToNV21(const uint8_t* src_ayuv,
258 | int src_stride_ayuv,
259 | uint8_t* dst_y,
260 | int dst_stride_y,
261 | uint8_t* dst_vu,
262 | int dst_stride_vu,
263 | int width,
264 | int height);
265 |
266 | // Convert Android420 to I420.
267 | LIBYUV_API
268 | int Android420ToI420(const uint8_t* src_y,
269 | int src_stride_y,
270 | const uint8_t* src_u,
271 | int src_stride_u,
272 | const uint8_t* src_v,
273 | int src_stride_v,
274 | int src_pixel_stride_uv,
275 | uint8_t* dst_y,
276 | int dst_stride_y,
277 | uint8_t* dst_u,
278 | int dst_stride_u,
279 | uint8_t* dst_v,
280 | int dst_stride_v,
281 | int width,
282 | int height);
283 |
284 | // ARGB little endian (bgra in memory) to I420.
285 | LIBYUV_API
286 | int ARGBToI420(const uint8_t* src_argb,
287 | int src_stride_argb,
288 | uint8_t* dst_y,
289 | int dst_stride_y,
290 | uint8_t* dst_u,
291 | int dst_stride_u,
292 | uint8_t* dst_v,
293 | int dst_stride_v,
294 | int width,
295 | int height);
296 |
297 | // BGRA little endian (argb in memory) to I420.
298 | LIBYUV_API
299 | int BGRAToI420(const uint8_t* src_bgra,
300 | int src_stride_bgra,
301 | uint8_t* dst_y,
302 | int dst_stride_y,
303 | uint8_t* dst_u,
304 | int dst_stride_u,
305 | uint8_t* dst_v,
306 | int dst_stride_v,
307 | int width,
308 | int height);
309 |
310 | // ABGR little endian (rgba in memory) to I420.
311 | LIBYUV_API
312 | int ABGRToI420(const uint8_t* src_abgr,
313 | int src_stride_abgr,
314 | uint8_t* dst_y,
315 | int dst_stride_y,
316 | uint8_t* dst_u,
317 | int dst_stride_u,
318 | uint8_t* dst_v,
319 | int dst_stride_v,
320 | int width,
321 | int height);
322 |
323 | // RGBA little endian (abgr in memory) to I420.
324 | LIBYUV_API
325 | int RGBAToI420(const uint8_t* src_rgba,
326 | int src_stride_rgba,
327 | uint8_t* dst_y,
328 | int dst_stride_y,
329 | uint8_t* dst_u,
330 | int dst_stride_u,
331 | uint8_t* dst_v,
332 | int dst_stride_v,
333 | int width,
334 | int height);
335 |
336 | // RGB little endian (bgr in memory) to I420.
337 | LIBYUV_API
338 | int RGB24ToI420(const uint8_t* src_rgb24,
339 | int src_stride_rgb24,
340 | uint8_t* dst_y,
341 | int dst_stride_y,
342 | uint8_t* dst_u,
343 | int dst_stride_u,
344 | uint8_t* dst_v,
345 | int dst_stride_v,
346 | int width,
347 | int height);
348 |
349 | // RGB little endian (bgr in memory) to J420.
350 | LIBYUV_API
351 | int RGB24ToJ420(const uint8_t* src_rgb24,
352 | int src_stride_rgb24,
353 | uint8_t* dst_y,
354 | int dst_stride_y,
355 | uint8_t* dst_u,
356 | int dst_stride_u,
357 | uint8_t* dst_v,
358 | int dst_stride_v,
359 | int width,
360 | int height);
361 |
362 | // RGB big endian (rgb in memory) to I420.
363 | LIBYUV_API
364 | int RAWToI420(const uint8_t* src_raw,
365 | int src_stride_raw,
366 | uint8_t* dst_y,
367 | int dst_stride_y,
368 | uint8_t* dst_u,
369 | int dst_stride_u,
370 | uint8_t* dst_v,
371 | int dst_stride_v,
372 | int width,
373 | int height);
374 |
375 | // RGB16 (RGBP fourcc) little endian to I420.
376 | LIBYUV_API
377 | int RGB565ToI420(const uint8_t* src_rgb565,
378 | int src_stride_rgb565,
379 | uint8_t* dst_y,
380 | int dst_stride_y,
381 | uint8_t* dst_u,
382 | int dst_stride_u,
383 | uint8_t* dst_v,
384 | int dst_stride_v,
385 | int width,
386 | int height);
387 |
388 | // RGB15 (RGBO fourcc) little endian to I420.
389 | LIBYUV_API
390 | int ARGB1555ToI420(const uint8_t* src_argb1555,
391 | int src_stride_argb1555,
392 | uint8_t* dst_y,
393 | int dst_stride_y,
394 | uint8_t* dst_u,
395 | int dst_stride_u,
396 | uint8_t* dst_v,
397 | int dst_stride_v,
398 | int width,
399 | int height);
400 |
401 | // RGB12 (R444 fourcc) little endian to I420.
402 | LIBYUV_API
403 | int ARGB4444ToI420(const uint8_t* src_argb4444,
404 | int src_stride_argb4444,
405 | uint8_t* dst_y,
406 | int dst_stride_y,
407 | uint8_t* dst_u,
408 | int dst_stride_u,
409 | uint8_t* dst_v,
410 | int dst_stride_v,
411 | int width,
412 | int height);
413 |
414 | // RGB little endian (bgr in memory) to J400.
415 | LIBYUV_API
416 | int RGB24ToJ400(const uint8_t* src_rgb24,
417 | int src_stride_rgb24,
418 | uint8_t* dst_yj,
419 | int dst_stride_yj,
420 | int width,
421 | int height);
422 |
423 | // RGB big endian (rgb in memory) to J400.
424 | LIBYUV_API
425 | int RAWToJ400(const uint8_t* src_raw,
426 | int src_stride_raw,
427 | uint8_t* dst_yj,
428 | int dst_stride_yj,
429 | int width,
430 | int height);
431 |
432 | // src_width/height provided by capture.
433 | // dst_width/height for clipping determine final size.
434 | LIBYUV_API
435 | int MJPGToI420(const uint8_t* sample,
436 | size_t sample_size,
437 | uint8_t* dst_y,
438 | int dst_stride_y,
439 | uint8_t* dst_u,
440 | int dst_stride_u,
441 | uint8_t* dst_v,
442 | int dst_stride_v,
443 | int src_width,
444 | int src_height,
445 | int dst_width,
446 | int dst_height);
447 |
448 | // JPEG to NV21
449 | LIBYUV_API
450 | int MJPGToNV21(const uint8_t* sample,
451 | size_t sample_size,
452 | uint8_t* dst_y,
453 | int dst_stride_y,
454 | uint8_t* dst_vu,
455 | int dst_stride_vu,
456 | int src_width,
457 | int src_height,
458 | int dst_width,
459 | int dst_height);
460 |
461 | // Query size of MJPG in pixels.
462 | LIBYUV_API
463 | int MJPGSize(const uint8_t* sample,
464 | size_t sample_size,
465 | int* width,
466 | int* height);
467 |
468 | // Convert camera sample to I420 with cropping, rotation and vertical flip.
469 | // "src_size" is needed to parse MJPG.
470 | // "dst_stride_y" number of bytes in a row of the dst_y plane.
471 | // Normally this would be the same as dst_width, with recommended alignment
472 | // to 16 bytes for better efficiency.
473 | // If rotation of 90 or 270 is used, stride is affected. The caller should
474 | // allocate the I420 buffer according to rotation.
475 | // "dst_stride_u" number of bytes in a row of the dst_u plane.
476 | // Normally this would be the same as (dst_width + 1) / 2, with
477 | // recommended alignment to 16 bytes for better efficiency.
478 | // If rotation of 90 or 270 is used, stride is affected.
479 | // "crop_x" and "crop_y" are starting position for cropping.
480 | // To center, crop_x = (src_width - dst_width) / 2
481 | // crop_y = (src_height - dst_height) / 2
482 | // "src_width" / "src_height" is size of src_frame in pixels.
483 | // "src_height" can be negative indicating a vertically flipped image source.
484 | // "crop_width" / "crop_height" is the size to crop the src to.
485 | // Must be less than or equal to src_width/src_height
486 | // Cropping parameters are pre-rotation.
487 | // "rotation" can be 0, 90, 180 or 270.
488 | // "fourcc" is a fourcc. ie 'I420', 'YUY2'
489 | // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
490 | LIBYUV_API
491 | int ConvertToI420(const uint8_t* sample,
492 | size_t sample_size,
493 | uint8_t* dst_y,
494 | int dst_stride_y,
495 | uint8_t* dst_u,
496 | int dst_stride_u,
497 | uint8_t* dst_v,
498 | int dst_stride_v,
499 | int crop_x,
500 | int crop_y,
501 | int src_width,
502 | int src_height,
503 | int crop_width,
504 | int crop_height,
505 | enum RotationMode rotation,
506 | uint32_t fourcc);
507 |
508 | #ifdef __cplusplus
509 | } // extern "C"
510 | } // namespace libyuv
511 | #endif
512 |
513 | #endif // INCLUDE_LIBYUV_CONVERT_H_
514 |
--------------------------------------------------------------------------------