Any way to access pixel data in 2.1 without OpenGL?

91 views
Skip to first unread message

Hans L

unread,
Jul 14, 2010, 10:15:48 PM7/14/10
to andro...@googlegroups.com
I was excited to try the bitmap-plasma sample included in the NDK, until I saw that the project requires Android 2.2 or higher.  
My goal is to be able to write something for android 2.1 using the NDK, that can somehow manipulate pixel data and get it to the screen.  
Is OpenGL the only possible option for graphics development in NDK targeting 2.1 users?  Or is there maybe some other workaround besides the Bitmap interface in 2.2.



Angus Lees

unread,
Jul 14, 2010, 11:07:22 PM7/14/10
to andro...@googlegroups.com
You can create arrays of pixel data and pass it to/from JNI functions easily enough - and then use Android Bitmap functions like copyPixelsFromBuffer or setPixels.  These all involve an extra copy to use unfortunately, which is why the froyo bitmap functions were added.  There are also annoying limitations in the Bitmap API when used with JNI, like no way to do partial updates from a Buffer, etc.

 - Gus 

Onur Cinar

unread,
Jul 15, 2010, 1:10:49 AM7/15/10
to andro...@googlegroups.com

Hi Hans,

I wouldn't suggest OpenGL for this purpose, since based on my tests, for simple 2D rendering, the direct Surface drawing is much faster.

You can pass the pixel data through Java NIO to the Java layer for painting, which performs very well compared to ByteArray approach.

The Java Bitmap itself does some memory copying, and even color space conversions, so if you have your pixel data in RGB565 color space you can prevent these steps as well. When I did a few tests on a Motorola Droid, I was able to achieve 230 fps with VGA using RGB565 color space. Using ARGB 16bit about 82 fps, and ARGB 32 bit about 140 fps.

There are few other ways, but these are the only options available through the public API.

Regards,

-onur



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

---
www.zdo.com

Hans L

unread,
Jul 16, 2010, 2:59:53 AM7/16/10
to andro...@googlegroups.com
On Thu, Jul 15, 2010 at 12:10 AM, Onur Cinar <onur....@gmail.com> wrote:

Hi Hans,

I wouldn't suggest OpenGL for this purpose, since based on my tests, for simple 2D rendering, the direct Surface drawing is much faster. 

You can pass the pixel data through Java NIO to the Java layer for painting, which performs very well compared to ByteArray approach. 

The Java Bitmap itself does some memory copying, and even color space conversions, so if you have your pixel data in RGB565 color space you can prevent these steps as well. When I did a few tests on a Motorola Droid, I was able to achieve 230 fps with VGA using RGB565 color space. Using ARGB 16bit about 82 fps, and ARGB 32 bit about 140 fps.

There are few other ways, but these are the only options available through the public API.

Regards,

-onur

Thanks for the reply, but I'm very new to this, and your post is too vague for me to understand what methods you are referring to exactly.  What do you mean by the ByteArray approach?  Is that even a class?  Or are you literally talking about "byte[]"?

Could you possibly give a snippet of example code or even just name the class methods that you are using?  What dataype exactly are you passing back and forth to native code?

Hans

Onur Cinar

unread,
Jul 16, 2010, 2:00:51 PM7/16/10
to andro...@googlegroups.com

Hi Hans,

Sure, I'll type more details tonight on all these approaches. FYI.

Regards,

-onur


--
Reply all
Reply to author
Forward
0 new messages