Bitmap: implement nativeCopyPixelsFromBuffer

This commit is contained in:
Mis012
2024-06-28 22:15:57 +02:00
parent 26d6337a34
commit 2c1e0dd3b8
3 changed files with 17 additions and 6 deletions

View File

@@ -159,6 +159,18 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsToBuffer(JNI
release_nio_buffer(env, array_ref, array);
}
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsFromBuffer(JNIEnv *env, jclass this, jlong _pixbuf, jobject buffer)
{
GdkPixbuf *pixbuf = _PTR(_pixbuf);
size_t pixbuf_size = gdk_pixbuf_get_rowstride(pixbuf) * (gdk_pixbuf_get_height(pixbuf) - 1)
+ /* last row: */ gdk_pixbuf_get_width(pixbuf) * ((gdk_pixbuf_get_n_channels(pixbuf) * gdk_pixbuf_get_bits_per_sample(pixbuf) + 7) / 8);
jarray array_ref;
jbyte *array;
uint8_t *pixels = get_nio_buffer(env, buffer, &array_ref, &array);
memcpy(gdk_pixbuf_get_pixels(pixbuf), pixels, pixbuf_size);
release_nio_buffer(env, array_ref, array);
}
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1unref_1texture(JNIEnv *env, jclass class, jlong texture_ptr)
{
GdkTexture *texture = GDK_TEXTURE(_PTR(texture_ptr));

View File

@@ -182,10 +182,10 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsToBuffer
/*
* Class: android_graphics_Bitmap
* Method: nativeCopyPixelsFromBuffer
* Signature: (ILjava/nio/Buffer;)V
* Signature: (JLjava/nio/Buffer;)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsFromBuffer
(JNIEnv *, jclass, jint, jobject);
(JNIEnv *, jclass, jlong, jobject);
/*
* Class: android_graphics_Bitmap

View File

@@ -580,7 +580,7 @@ public final class Bitmap {
throw new RuntimeException("Buffer not large enough for pixels");
}
nativeCopyPixelsFromBuffer(mNativeBitmap, src);
nativeCopyPixelsFromBuffer(pixbuf, src);
// now update the buffer's position
int position = src.position();
@@ -1651,9 +1651,8 @@ public final class Bitmap {
private static native void nativeSetPixels(int nativeBitmap, int[] colors,
int offset, int stride, int x, int y,
int width, int height, boolean isPremultiplied);
private static native void nativeCopyPixelsToBuffer(long pixbuf,
Buffer dst);
private static native void nativeCopyPixelsFromBuffer(int nb, Buffer src);
private static native void nativeCopyPixelsToBuffer(long pixbuf, Buffer dst);
private static native void nativeCopyPixelsFromBuffer(long pixbuf, Buffer src);
private static native int nativeGenerationId(int nativeBitmap);
// returns a new bitmap built from the native bitmap's alpha, and the paint