diff --git a/src/api-impl-jni/android_graphics_Bitmap.c b/src/api-impl-jni/android_graphics_Bitmap.c index 64f15b93..c764d34b 100644 --- a/src/api-impl-jni/android_graphics_Bitmap.c +++ b/src/api-impl-jni/android_graphics_Bitmap.c @@ -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); +} diff --git a/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h b/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h index 86227c49..3e585156 100644 --- a/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h +++ b/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h @@ -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 diff --git a/src/api-impl/android/graphics/Bitmap.java b/src/api-impl/android/graphics/Bitmap.java index 094eb257..cce03b5f 100644 --- a/src/api-impl/android/graphics/Bitmap.java +++ b/src/api-impl/android/graphics/Bitmap.java @@ -540,7 +540,7 @@ public final class Bitmap { throw new RuntimeException("Buffer not large enough for pixels"); } - nativeCopyPixelsToBuffer(mNativeBitmap, dst); + nativeCopyPixelsToBuffer(pixbuf, dst); // now update the buffer's position int position = dst.position(); @@ -1618,7 +1618,7 @@ public final class Bitmap { private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig, boolean isMutable); private static native void nativeDestructor(int nativeBitmap); - private static native boolean nativeRecycle(long nativeBitmap, long texture); + private static native boolean nativeRecycle(long pixbuf, long texture); private static native void nativeReconfigure(int nativeBitmap, int width, int height, int config, int allocSize); @@ -1626,12 +1626,12 @@ public final class Bitmap { int quality, OutputStream stream, byte[] tempStorage); private static native void nativeErase(int nativeBitmap, int color); - private static native int nativeRowBytes(long nativeBitmap); + private static native int nativeRowBytes(long pixbuf); private static native int nativeConfig(int nativeBitmap); private static native int nativeGetPixel(int nativeBitmap, int x, int y, boolean isPremultiplied); - private static native void nativeGetPixels(long nativeBitmap, int[] pixels, + private static native void nativeGetPixels(long pixbuf, int[] pixels, int offset, int stride, int x, int y, int width, int height, boolean isPremultiplied); @@ -1640,7 +1640,7 @@ 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(int nativeBitmap, + private static native void nativeCopyPixelsToBuffer(long pixbuf, Buffer dst); private static native void nativeCopyPixelsFromBuffer(int nb, Buffer src); private static native int nativeGenerationId(int nativeBitmap);