Android copyPixelsFromBuffer () for a specific bitmap offset?

I am working on an Android application that deals with graphical operations in native code in a shared memory buffer. I made functions to call my own Java code using JNI, and my own code uses the JNI API to call Java from native code. Since copying large arrays of pixels has a significant impact on performance, I need to avoid this as much as possible.

The Android documentation for the Bitmap class talks about two ways to copy pixels to the internal Bitmap bit: http://developer.android.com/reference/android/graphics/Bitmap.html

setPixels (int [] pixels, int offset, int stride, int x, int y, int width, int height) Replace the pixels in the raster array with the colors in the array.

copyPixelsFromBuffer (Buffer src) Copy the pixels from the buffer, starting at the current position, overwriting the raster pixels.

The problem with the API documentation is that it is very vague as to what happens behind the scenes when using these functions. However, it is mentioned somewhere that copyPixelsFromBuffer () copies pixels directly without any internal color format conversion, unlike setPixels (), which in all cases will do this conversion, even if the source pixels are in the target pixel format. Obviously, this is not what I want, since the pixels in my buffer are already in good format.

Now copyPixelsFromBuffer () looks very good since it will not do this conversion, but the documentation does not say how to copy pixels from the buffer to a specific offset in the target bitmap. Unfortunately, this is very important, because I do not want to copy the entire buffer every time, but only the region on it. Yes, the documentation says that it is going to copy from the current position in the source buffer, but nothing is said about the target buffer. SetPixels () performs an unnecessary conversion, but allows you to specify an offset in the destination buffer.

So, I am stuck between:

Copying only the area in which I want due to pixel conversion

OR

Avoid pixel conversion by copying the entire buffer every time

, , 1024x768, , (300 300) (400 400).

, , 100 * 100 1024 * 768 . 100x100 , , . .

- , ? , , .

+3
1

, , , . .

-n

0

Source: https://habr.com/ru/post/1773114/


All Articles