From 626c12f7a5f40ffcb548fccca8c09a0d98f63cee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 6 Dec 2015 23:13:21 -0500 Subject: [PATCH] lib/android: demultiply pixel data from alpha value on request only MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/load_image.nit | 9 ++++++--- lib/mnit/android/android_assets.nit | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/android/load_image.nit b/lib/android/load_image.nit index bc3cb02..cea5502 100644 --- a/lib/android/load_image.nit +++ b/lib/android/load_image.nit @@ -31,8 +31,11 @@ redef extern class NativeBitmap # Copy the pixel data into a new `CByteArray` # # If `pad_to_pow2` the new buffer contains artificial pixels used to make - # the width and the height powers of 2 for compatibility with OpenGL. - fun copy_pixels(pad_to_pow2: nullable Bool): CByteArray + # the width and the height powers of 2 for compatibility with older OpenGL. + # + # If `unmultiply`, extra work is done to revert the multiplication of color + # values per the alpha channel applied by the Android system. + fun copy_pixels(pad_to_pow2, unmultiply: nullable Bool): CByteArray do var height = height var row_bytes = row_bytes @@ -49,7 +52,7 @@ redef extern class NativeBitmap var java_buf = buf.to_java_nio_buffer copy_pixels_to_buffer java_buf - if has_alpha then buf.native_array.unmultiply(width, height) + if has_alpha and unmultiply == true then buf.native_array.unmultiply(width, height) if pad_to_pow2 == true then for r in [height-1..0[.step(-1) do diff --git a/lib/mnit/android/android_assets.nit b/lib/mnit/android/android_assets.nit index 06af952..e30db6d 100644 --- a/lib/mnit/android/android_assets.nit +++ b/lib/mnit/android/android_assets.nit @@ -67,7 +67,7 @@ redef class App jni_env.push_local_frame 4 var bmp = asset_manager.bitmap(path) - var buf = bmp.copy_pixels(true) + var buf = bmp.copy_pixels(true, true) var w2 = bmp.width.next_pow(2) var h2 = bmp.height.next_pow(2) var png = new Opengles1Image.from_data(buf.native_array, bmp.width, bmp.height, w2, h2, true) -- 1.7.9.5