Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libyuv"]
path = libyuv
url = https://android.googlesource.com/platform/external/libyuv/
5 changes: 5 additions & 0 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set (PACKAGE_NAME "ResizeConvertLib")
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 17)
set (ANDROID_STL c++_shared)

# Third party libraries (Prefabs)
find_package(fbjni REQUIRED CONFIG)
Expand Down Expand Up @@ -34,3 +35,7 @@ target_link_libraries(
fbjni::fbjni # <-- fbjni
yuv # <-- libyuv
)

# Add 16KB page size support
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=0x4000")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,max-page-size=0x4000")
27 changes: 25 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,35 @@ android {
buildFeatures {
prefab true
}

// Add CMake configuration for 16KB page size support
externalNativeBuild {
cmake {
path "CMakeLists.txt"
version "3.22.1"
}
}

ndkVersion getExtOrDefault("ndkVersion")
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")


// Add 16KB page size support
externalNativeBuild {
cmake {
arguments "-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=0x4000",
"-DCMAKE_EXE_LINKER_FLAGS=-Wl,-z,max-page-size=0x4000",
"-DANDROID_STL=c++_shared"
cppFlags "-std=c++17"
}
}

ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}

buildTypes {
Expand Down Expand Up @@ -102,7 +123,9 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation project(':react-native-vision-camera')
implementation 'com.google.mediapipe:tasks-vision:0.10.26'
// Updated to 0.10.29 for Android 16KB page size support
// See: https://github.com/google-ai-edge/mediapipe/issues/6105
implementation 'com.google.mediapipe:tasks-vision:0.10.29'
implementation 'androidx.camera:camera-core:1.3.3'
}

4 changes: 4 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ Mediapipe_minSdkVersion=21
Mediapipe_targetSdkVersion=31
Mediapipe_compileSdkVersion=31
Mediapipe_ndkversion=21.4.7075529

# Enable 16KB page size support
android.bundle.enableUncompressedNativeLibs=false
android.enableJetifier=true
33 changes: 33 additions & 0 deletions android/src/main/cpp/JImage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by Marc Rousavy on 25.01.24.
//

#include "JImage.h"

#include <fbjni/fbjni.h>
#include <jni.h>

namespace resizeconvert {

using namespace facebook;
using namespace jni;

int JImage::getWidth() const {
auto method = getClass()->getMethod<jint()>("getWidth");
auto result = method(self());
return result;
}

int JImage::getHeight() const {
auto method = getClass()->getMethod<jint()>("getHeight");
auto result = method(self());
return result;
}

jni::local_ref<jni::JArrayClass<JImagePlane>> JImage::getPlanes() const {
auto method = getClass()->getMethod<jni::JArrayClass<JImagePlane>()>("getPlanes");
auto result = method(self());
return result;
}

} // namespace resizeconvert
27 changes: 27 additions & 0 deletions android/src/main/cpp/JImage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by Marc Rousavy on 25.01.24.
//

#pragma once

#include "JImagePlane.h"
#include <fbjni/fbjni.h>
#include <jni.h>

namespace resizeconvert
{

using namespace facebook;
using namespace jni;

struct JImage : public JavaClass<JImage>
{
static constexpr auto kJavaDescriptor = "Landroid/media/Image;";

public:
int getWidth() const;
int getHeight() const;
jni::local_ref<jni::JArrayClass<JImagePlane>> getPlanes() const;
};

} // namespace resizeconvert
34 changes: 34 additions & 0 deletions android/src/main/cpp/JImagePlane.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by Marc Rousavy on 25.01.24.
//

#include "JImagePlane.h"

namespace resizeconvert
{

using namespace facebook;
using namespace jni;

int JImagePlane::getPixelStride() const
{
auto method = getClass()->getMethod<jint()>("getPixelStride");
auto result = method(self());
return result;
}

int JImagePlane::getRowStride() const
{
auto method = getClass()->getMethod<jint()>("getRowStride");
auto result = method(self());
return result;
}

jni::local_ref<JByteBuffer> JImagePlane::getBuffer() const
{
auto method = getClass()->getMethod<JByteBuffer()>("getBuffer");
auto result = method(self());
return result;
}

} // namespace resizeconvert
27 changes: 27 additions & 0 deletions android/src/main/cpp/JImagePlane.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by Marc Rousavy on 25.01.24.
//

#pragma once

#include <fbjni/ByteBuffer.h>
#include <fbjni/fbjni.h>
#include <jni.h>

namespace resizeconvert
{

using namespace facebook;
using namespace jni;

struct JImagePlane : public JavaClass<JImagePlane>
{
static constexpr auto kJavaDescriptor = "Landroid/media/Image$Plane;";

public:
jni::local_ref<JByteBuffer> getBuffer() const;
int getPixelStride() const;
int getRowStride() const;
};

} // namespace resizeconvert
Loading