vImageConvert_RGB888toARGB8888
和vImagePermuteChannels_ARGB8888
。首先将它从RGB24更改为ARGB,因为OPENGL ES不支持ARGB,因此需要使用vImagePermuteChannels_ARGB8888
将ARGB更改为BGRA。但是当需要改变的数据很大时,成本很高,那么有人用更好的方法吗?谢谢!我的代码是这样的:
- (void)transformRGBToBGRA:(const UInt8 *)pict{
rgb.data = (void *)pict;
vImage_Error error = vImageConvert_RGB888toARGB8888(&rgb,NULL,0,&argb,NO,kvImageNoFlags);
if (error != kvImageNoError) {
NSLog(@"vImageConvert_RGB888toARGB8888 error");
}
const uint8_t permuteMap[4] = {3,2,1,0};
error = vImagePermuteChannels_ARGB8888(&argb,&bgra,permuteMap,kvImageNoFlags);
if (error != kvImageNoError) {
NSLog(@"vImagePermuteChannels_ARGB8888 error");
}
free((void *)pict);
}
答案 0 :(得分:1)
现在我发现最快的解决方案是装配。就像这样:
__asm__ volatile(
"0: \n"
"# load 3 64-bit regs with interleave: \n"
"vld3.8 {d0,d1,d2}, [%0]! \n"
"# swap d0 and d2 - R and B\n"
"vswp d0, d2 \n"
"# store 4 64-bit regs: \n"
"vst4.8 {d0,d1,d2,d3}, [%2]! \n"
"subs %1, %1, #1 \n"
"bne 0b \n"
:
: "r"(img), "r"(numPixels24), "+r"(bgraData)
: "r6", "r7","r8"
);