Bitmap: implement copyPixelsToBuffer

This commit is contained in:
Mis012
2024-05-27 18:58:04 +02:00
parent c5e0f8a7fd
commit 97e59437b9
3 changed files with 19 additions and 7 deletions

View File

@@ -146,3 +146,15 @@ JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1paintable_1from_1pi
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
return _INTPTR(gdk_texture_new_for_pixbuf(pixbuf));
}
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsToBuffer(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(pixels, pixbuf, pixbuf_size);
release_nio_buffer(env, array_ref, array);
}

View File

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