GithubHelp home page GithubHelp logo

renderscript-intrinsics-replacement-toolkit's Introduction

RenderScript Intrinsics Replacement Toolkit - v0.8 BETA

This Toolkit provides a collection of high-performance image manipulation functions like blur, blend, and resize. It can be used as a stand-alone replacement for most of the deprecated RenderScript Intrinsics functions.

The Toolkit provides ten image manipulation functions:

  • blend,
  • blur,
  • color matrix,
  • convolve,
  • histogram and histogramDot,
  • LUT (lookup table) and LUT 3D,
  • resize, and
  • YUV to RGB.

The Toolkit provides a C++ and a Java/Kotlin interface. It is packaged as an Android library that you can add to your project.

These functions execute multithreaded on the CPU. They take advantage of Neon/AdvSimd on Arm processors and SSE on Intel's.

Compared to the RenderScript Intrinsics, this Toolkit is simpler to use and twice as fast when executing on the CPU. However RenderScript Intrinsics allow more flexibility for the type of allocations supported. This toolkit does not support allocations of floats; most the functions support ByteArrays and Bitmaps.

You should instantiate the Toolkit once and reuse it throughout your application. On instantiation, the Toolkit creates a thread pool that's used for processing all the functions. You can limit the number of poolThreads used by the Toolkit via the constructor. The poolThreads are destroyed once the Toolkit is destroyed, after any pending work is done.

This library is thread safe. You can call methods from different poolThreads. The functions will execute sequentially.

Future improvement ideas:

  • Turn the Java version of the Toolkit into a singleton, to reduce the chance that someone inadventarly create multiple threadpools.

  • Support ByteBuffer. It should be straightforward to use GetDirectBufferAddress in JniEntryPoints.cpp. See https://developer.android.com/training/articles/perf-jni and jni_helper.h.

  • The RenderScript Intrinsics support floats for colorMatrix, convolve, and resize. The Toolkit does not.

  • Allow in place update of buffers, or writing to an existing byte array.

  • For Blur, we could have a version that accepts a mask. This is commonly used for background blurring. We should allow the mask to be smaller than the original, since neural networks models that do segmentation are downscaled.

  • Allow yuvToRgb to have a Restriction.

  • Add support for YUV_420_888, the YUV format favored by Camera2. Allow various strides to be specified.

  • When passing a Restriction, it would be nice to say "Create a smaller output". The original RenderScript does not allow that. It's not that useful when outputing new buffers as our Java library does.

  • For Resize, Restriction working on input buffer would be more useful but that's not RenderScript.

  • Integrate and test with imageprocessing_jb. Do the same for github/renderscript-samples/

  • Allow Bitmaps with rowSize != width * vectorSize. We could do this also for ByteArray.

  • In TaskProcessor.cpp, the code below is fine and clean, but probably a bit inefficient. When this wakes up another thread, it may have to immediately go back to sleep, since we still hold the lock. It could instead set a need_to_notify flag and test that after releasing the lock (both places). That might avoid some context switches.
if (mTilesInProcess == 0 && mTilesNotYetStarted == 0) {
    mWorkIsFinished.notify_one();
  • When compiled as part of Android, librenderscript_toolkit.so is 101,456 bytes. When compiled by Android Studio as part of an .aar, it's 387K. Figure out why and slim it down.

renderscript-intrinsics-replacement-toolkit's People

Contributors

ggfan avatar jeanlucbr avatar kottsone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

renderscript-intrinsics-replacement-toolkit's Issues

Add Surface support for input & output.

In RenderScript, we can use Allocation.getSurface() to attach GraphicBuffer for input, and Allocation.setSurface() to get the result directly into a Surface.

Thats very useful for stream rendering. Please add Surface support in Toolkit.
Best Regards!

How to use the AAR?

I built and added the AAR into my project. But when I invoke Toolkit.blur nothing shows up. It says it's unresolved.
How to use its functions?

How to apply LUT3D from a file?

Hello,

I am trying to apply LUT3D to a photo with an image that comes from a file(we have it as png or 3DL).

I am trying to read the png into a bitmap and read all pixels and add them to a Rgba3dArray but I don't know how.

I am not familiar with LUT3D and I can't get it working.

Input

image

I need to know how to put the pixels from the bitmap to a Rgba3dArray.
An example of how to do this would really help me.

Question

How do I set intensity to this filter?

Any plans beyond 0.8 beta?

This toolkit is version 0.8 beta, which implies it's not production-ready. Is there any plan to make a release version, or is this project abandoned?

Error while compiling this project

I am getting following error when I am trying to build this module.

 C/C++ debug|armeabi-v7a : CMake Error at /home/vikram/Documents/src/renderscript-intrinsics-replacement-toolkit/renderscript-toolkit/src/main/cpp/CMakeLists.txt:117 (include):
  include could not find load file:

    AndroidNdkModules

Your library no longer works

I tried running IntrinsicYuvToRgb.kt but I get an intellisense error:

Unresolved reference: renderscript at import com.google.android.renderscript.YuvFormat

Feature

Add support to have BluredEdgeTrwatment like Android 12s

Convolution

Not getting expected results in convolving, it seems when sum of the coefficients is zero the result is empty.
Untitled-1

Crash on Motorola G30 but works on Motorola play G9 ?

Hi,

I'm facing a crash with the toolkit in my app on one specific smartphone, not the other.

Before i was using Renderscript to convert yuv in rgb, and it was working well for a year on : Motorola G9 and Motorola G30

        final RenderScript rs = RenderScript.create(this.applicationContext);
        final Bitmap        bitmap     = Bitmap.createBitmap(analyseImageNv21.width, analyseImageNv21.height, Bitmap.Config.ARGB_8888);
        final Allocation allocationRgb = Allocation.createFromBitmap(rs, bitmap);
        final Allocation allocationYuv = Allocation.createSized(rs, Element.U8(rs), analyseImageNv21.nv21.length);
        allocationYuv.copyFrom(analyseImageNv21.nv21);
        ScriptIntrinsicYuvToRGB scriptYuvToRgb = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
        scriptYuvToRgb.setInput(allocationYuv);
        scriptYuvToRgb.forEach(allocationRgb);
        allocationRgb.copyTo(bitmap);
        allocationYuv.destroy();
        allocationRgb.destroy();
        rs.destroy();
        return bitmap;

AnalyseImageNv21 is just a simple POJO holding a NV21 format image

public class AnalyseImageNv21  {
    public byte[] nv21;
    public int width;
    public int height;
}

Now I import the renderscript-toolkit module, with the following code

return Toolkit.INSTANCE.yuvToRgbBitmap(analyseImageNv21.nv21, analyseImageNv21.width, analyseImageNv21.height, YuvFormat.NV21);

It works well on motorola G9 Play, but crash on motorola G30 with theses lines in logcat.

        02-26 10:11:14.302 21262 21262 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        02-26 10:11:14.302 21262 21262 F DEBUG   : Build fingerprint: 'motorola/caprip_retailen/caprip:12/S0RCS32.41-10-19-21/adced5-adb6a:user/release-keys'
        02-26 10:11:14.302 21262 21262 F DEBUG   : Revision: 'pvt'
        02-26 10:11:14.302 21262 21262 F DEBUG   : ABI: 'arm64'
        02-26 10:11:14.302 21262 21262 F DEBUG   : Timestamp: 2024-02-26 10:11:13.712196673+0100
        02-26 10:11:14.302 21262 21262 F DEBUG   : Process uptime: 0s
        02-26 10:11:14.302 21262 21262 F DEBUG   : Cmdline: com.laposte.bscc.mobiliatri
        02-26 10:11:14.302 21262 21262 F DEBUG   : pid: 20876, tid: 21259, name: RenderScToolkit  >>> com.laposte.bscc.mobiliatri <<<
        02-26 10:11:14.302 21262 21262 F DEBUG   : uid: 10005
        02-26 10:11:14.302 21262 21262 F DEBUG   : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x6f2c2ea000
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x0  b400006f2c2ea000  x1  0000000077d613f4  x2  00000000000007f8  x3  00000000782219f4
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x4  0000000000001070  x5  0000000000004528  x6  00000000ffffffff  x7  7f7f7f7f7f7f7f7f
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x8  0000000000000838  x9  0000000077d60b9c  x10 000000007822119c  x11 000000007822119d
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x12 0000000000001070  x13 0000000077d61c0c  x14 0000000077d61c0d  x15 0000000000001070
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x16 0000006f61cf6ff0  x17 0000006f61cc79b0  x18 0000006f2c750000  x19 0000000000000940
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x20 0000000000001070  x21 000000000000093f  x22 0000000000000838  x23 0000006f37d63ef0
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x24 0000000000000001  x25 000000000000093f  x26 0000006f2e3e4ff8  x27 00000000000fc000
        02-26 10:11:14.302 21262 21262 F DEBUG   :     x28 0000006f2e2ec000  x29 0000006f2e3e4b80
        02-26 10:11:14.302 21262 21262 F DEBUG   :     lr  0000006f61cba74c  sp  0000006f2e3e4b40  pc  0000006f61cc7b30  pst 0000000020000000
        02-26 10:11:14.303 21262 21262 F DEBUG   : backtrace:
        02-26 10:11:14.303 21262 21262 F DEBUG   :       #00 pc 0000000000044b30  /data/app/~~cVvc8P2rx3wCZUZM-lA1-w==/com.laposte.bscc.mobiliatri-g-R111V7MZzU7FoITbOvJA==/base.apk!librenderscript-toolkit.so (rsdIntrinsicYuv_K+384) (BuildId: 6e2ec30a534239faea020c0a132cc508217bbfc6)
        02-26 10:11:14.303 21262 21262 F DEBUG   :       #01 pc 0000000000037748  /data/app/~~cVvc8P2rx3wCZUZM-lA1-w==/com.laposte.bscc.mobiliatri-g-R111V7MZzU7FoITbOvJA==/base.apk!librenderscript-toolkit.so (renderscript::YuvToRgbTask::processData(int, unsigned long, unsigned long, unsigned long, unsigned long)+80) (BuildId: 6e2ec30a534239faea020c0a132cc508217bbfc6)
        02-26 10:11:14.303 21262 21262 F DEBUG   :       #02 pc 0000000000036e2c  /data/app/~~cVvc8P2rx3wCZUZM-lA1-w==/com.laposte.bscc.mobiliatri-g-R111V7MZzU7FoITbOvJA==/base.apk!librenderscript-toolkit.so (renderscript::TaskProcessor::processTilesOfWork(int, bool)+464) (BuildId: 6e2ec30a534239faea020c0a132cc508217bbfc6)
        02-26 10:11:14.303 21262 21262 F DEBUG   :       #03 pc 00000000000374a4  /data/app/~~cVvc8P2rx3wCZUZM-lA1-w==/com.laposte.bscc.mobiliatri-g-R111V7MZzU7FoITbOvJA==/base.apk!librenderscript-toolkit.so (BuildId: 6e2ec30a534239faea020c0a132cc508217bbfc6)
        02-26 10:11:14.303 21262 21262 F DEBUG   :       #04 pc 00000000000b6a74  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+264) (BuildId: 9eba7d8c708c66b9a276c7f5010c97b3)
        02-26 10:11:14.303 21262 21262 F DEBUG   :       #05 pc 0000000000053310  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+68) (BuildId: 9eba7d8c708c66b9a276c7f5010c97b3)

Any ideas ?

Incorrect gamma when resizing?

Using test image from this website, Resize seems to use linear gamma instead of sRGB gamma.

original resized
gamma_dalai_lama_gray test-resize53078175886776102
code
@RunWith(AndroidJUnit4::class)
class ImageResizeTest {

    @Test
    fun gamma_correct_rescaling() {

        val appContext = ApplicationProvider.getApplicationContext<Context>()

        val fis = appContext.assets.open("gamma.jpg")

        val input = BitmapFactory.decodeStream(fis)
        val output = Toolkit.resize(input, input.width / 2, input.height / 2)

        val outputFile = File.createTempFile("test-resize", ".png")
        outputFile.outputStream().use {
            output.compress(Bitmap.CompressFormat.PNG, 100, it)
        }

    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.