Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Endianness of Android NDK

I'm working with my new app which processed captured image from cellphone camera. My phone is Nexus S, 2.3.4.

I create a ARGB_8888 Bitmap with captured data. I know the ndk image lib, but it's only support 2.2 and above. So I pass the int[] of Bitmap to NDK and found the color byte order is little-endian.

I searched the wiki and found arm architecture is bi-endian. http://en.wikipedia.org/wiki/Endianness#Bi-endian_hardware

My question is if arm is bi-endian, how to judge the byte order in specific device? Should I test the byte order every time before access the data?

like image 879
Matrix Bai Avatar asked Jun 02 '11 09:06

Matrix Bai


2 Answers

Directly from my Nexus S:

> import java.nio.*; > System.out.println(ByteOrder.nativeOrder()); LITTLE_ENDIAN 

There should also be some way to get the ordering in the NDK.

like image 132
lxgr Avatar answered Oct 05 '22 22:10

lxgr


Yes most cpus bi-endian, but most end user operating systems in use today choose to use the cpus in little-endian. Along those lines, ARM can operate in both as a convenience, its actual default after ARM 3 is little-endianess which is the endian mode it starts up in. I think one can safely assume that all Android devices are little endian, otherwise it would be extra work if different android devices were a mixture of endianess.

Because network byte order is big-endian, it can be helpful to convert any format you plan on using for data interchange to network byte order. Again, though, Mac OS X on Intel, Windows, iOS and Android are little-endian, so you might just code up structures with the native endianness and hope the next great OS you want to port data to doesn't go big-endian.

like image 33
mP. Avatar answered Oct 05 '22 21:10

mP.