clip.cpp
clip.cpp copied to clipboard
Add Android sample (JNI binding + Java wrapper class)
This PR adds examples/clip.android, an Android sample that interfaces with the shared libraries of clip.cpp through JNI. The structure of the project is highly inspired from llama.cpp/examples/llama.android.
Summary of changes
-
examples/clip.androidis an Android project with two modulesappandclip. - The
appmodule contains the sources for a demo application which allows the user to select an image and enter a text description to compare them (uses Kotlin/Compose) - The
clipmodule containsclip/src/main/cpp/clip-androidthat contains the JNI interfaces which allow communication with the underlying functions fromclip.h. - Also, the
clipmodule containsclip/src/main/java/android/clip/cpp/CLIPAndroid.javawhich is wrapper class containingnativemethods. - The
clipmodule also houses an instrumented testclip/src/androidTest/java/android/example/clip/CLIPInstrumentedTest.ktwritten in Kotlin - A
README.mdis included in theexamples/clip.androiddirectory which describes how to run the sample app and the instrumented test -
clip.cppis modified to address issue #99 -
CMakeLists.txtis modified to add-mcpu=nativewhen${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"only if-DCLIP_NATIVEis enabled - added a new method
clip_image_preprocess_no_resizeinclip.handclip.cppwhich does works exactly likeclip_image_preprocessbut does not perform linear interpolation (no image resizing). Android'sBitmapclass and Python's PIL can handle bilinear interpolation easily, so it would be great to have a method that skips resizing.
[!NOTE] Though the
clipmodule here in built as an Android library module, it can be built into a 'Java library' module (packaged as a JAR) and used in other Java-only projects as a port toclip.cpp
It was fun working on this sample, and I would like @monatis to review it and share feedback.