-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: android inference with faster yuv->rgb conversion
- Loading branch information
Charles Parker
authored and
Charles Parker
committed
Apr 18, 2024
1 parent
7ad0e38
commit 588f2e6
Showing
25 changed files
with
992 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Config for clang-format version 16 | ||
|
||
# Standard | ||
BasedOnStyle: llvm | ||
Standard: c++14 | ||
|
||
# Indentation | ||
IndentWidth: 2 | ||
ColumnLimit: 140 | ||
|
||
# Includes | ||
SortIncludes: true | ||
SortUsingDeclarations: true | ||
|
||
# Pointer and reference alignment | ||
PointerAlignment: Left | ||
ReferenceAlignment: Left | ||
ReflowComments: true | ||
|
||
# Line breaking options | ||
BreakBeforeBraces: Attach | ||
BreakConstructorInitializers: BeforeColon | ||
AllowShortFunctionsOnASingleLine: Empty | ||
IndentCaseLabels: true | ||
NamespaceIndentation: Inner | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
project(ResizeConvertLib) | ||
cmake_minimum_required(VERSION 3.9.0) | ||
|
||
set (PACKAGE_NAME "ResizeConvertLib") | ||
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build) | ||
set (CMAKE_VERBOSE_MAKEFILE ON) | ||
set (CMAKE_CXX_STANDARD 17) | ||
|
||
# Third party libraries (Prefabs) | ||
find_package(fbjni REQUIRED CONFIG) | ||
find_library(LOG_LIB log) | ||
|
||
# libyuv | ||
add_subdirectory(../libyuv libyuv) | ||
|
||
add_library(${PACKAGE_NAME} SHARED | ||
src/main/cpp/ResizeConvert.cpp | ||
src/main/cpp/JImage.cpp | ||
src/main/cpp/JImagePlane.cpp | ||
src/main/cpp/ResizeConvertLib.cpp | ||
) | ||
|
||
# Specifies a path to native header files. | ||
target_include_directories( | ||
${PACKAGE_NAME} PRIVATE | ||
src/main/cpp | ||
../libyuv/include | ||
) | ||
|
||
target_link_libraries( | ||
${PACKAGE_NAME} | ||
${LOG_LIB} # <-- Logcat logger | ||
android # <-- Android JNI core | ||
fbjni::fbjni # <-- fbjni | ||
yuv # <-- libyuv | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.