Android NDK 的字节顺序 [英] Endianness of Android NDK

查看:16
本文介绍了Android NDK 的字节顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的新应用程序来处理从手机摄像头捕获的图像.我的手机是 Nexus S,2.3.4.

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

我用捕获的数据创建了一个 ARGB_8888 位图.我知道 ndk 镜像库,但它只支持 2.2 及更高版本.于是我把Bitmap的int[]传给NDK,发现颜色字节序是little-endian.

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.

我搜索了 wiki,发现 arm 架构是双端的.http://en.wikipedia.org/wiki/Endianness#Bi-endian_hardware

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

我的问题是如果arm是双端的,如何判断特定设备中的字节顺序?每次访问数据之前是否应该测试字节顺序?

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?

推荐答案

是的,大多数 cpu 是双端的,但当今使用的大多数最终用户操作系统都选择使用小端的 cpu.沿着这些思路,ARM 可以方便地在这两种模式下运行,它在 ARM 3 之后的实际默认设置是 little-endianess,这是它​​启动的字节序模式.我认为可以安全地假设所有 Android 设备都是小端序,否则它会如果不同的 android 设备是字节序的混合体,那就是额外的工作.

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.

由于网络字节顺序是大端顺序,因此将您计划用于数据交换的任何格式转换为网络字节顺序会很有帮助.不过,英特尔、Windows、iOS 和 Android 上的 Mac OS X 还是小端序,因此您可能只是使用本机字节序编写结构,并希望下一个您想要将数据移植到的出色操作系统不会采用大端序.

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.

这篇关于Android NDK 的字节顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆