From f50de7e2660498d0c606597982639090ac1a8235 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Tue, 18 Jan 2011 14:27:36 -0800 Subject: Fix Magic Smoke crash and clarify why we use getPixels Change-Id: Ica61181aedc98d30dc0960387064f253b78177e9 --- src/com/android/magicsmoke/MagicSmokeRS.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/android/magicsmoke/MagicSmokeRS.java b/src/com/android/magicsmoke/MagicSmokeRS.java index 0731ef2..6b0e8ff 100644 --- a/src/com/android/magicsmoke/MagicSmokeRS.java +++ b/src/com/android/magicsmoke/MagicSmokeRS.java @@ -253,6 +253,8 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange opts.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap in = BitmapFactory.decodeResource(mResources, id, opts); + // Bitmaps are stored in memory in premultiplied form. We want non-premultiplied, + // which is what getPixels gives us. int pixels[] = new int[65536]; in.getPixels(pixels, 0, 256, 0, 0, 256, 256); mRealTextures[index] = Allocation.createTyped(mRS, mTextureType, @@ -262,7 +264,16 @@ class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChange mSourceTextures[index] = Allocation.createTyped(mRS, mTextureType, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); - mSourceTextures[index].copyFrom(pixels); + + // copyFrom needs a byte[], not an int[], so we need to copy the data first + byte bpixels[] = new byte[65536*4]; + for (int i = 0; i < 65536; i++) { + bpixels[i * 4 + 0] = (byte)(pixels[i] & 0xff); + bpixels[i * 4 + 1] = (byte)((pixels[i] >> 8) & 0xff); + bpixels[i * 4 + 2] = (byte)((pixels[i] >>16) & 0xff); + bpixels[i * 4 + 3] = (byte)((pixels[i] >> 24) & 0xff); + } + mSourceTextures[index].copyFrom(bpixels); in.recycle(); } -- cgit v1.2.3