常用的图象格式包括RGBA(32位), RGB(24位)及BGRA(24位)在ARM 32位及64位平台上转换有什么好的方法。
清华大学AOSP代码镜像
1. https://aosp.tuna.tsinghua.edu.cn
2. https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
3. 代码下载:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.1_r1 --repo-url=https://aosp.tuna.tsinghua.edu.cn/tools/repo.git
NOTE: 这里会参考skia的代码。
C语言实现
CPU为小端模式,RGBA 在内存中从低到高排列为 RR GG BB AA, 用int32_t表示为0xAABBGGRR
1. RGBA转RGB
void rgba_to_rgb(unsigned char *src, unsigned char *dst, int numPixels)
{
int col;
for (col = 0; col < numPixels; col++, src += 4, dst += 3) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
}
2. RGBA转BGRA ,又称之为RB swap
void rgba_to_bgra(unsigned char *src, unsigned char