将每pixel 12bit的RAW12转为 每pixel 16bit
程序员文章站
2022-03-04 23:42:11
...
关于图片格式的文章有很多,就不赘述。
YUV420:
采样方式推荐看:https://zhuanlan.zhihu.com/p/137836227
存储方式推荐看:https://blog.51cto.com/u_7335580/2060931
RAW数据格式:https://blog.csdn.net/HuddHeaven/article/details/37807379
用客户的工具将抓的RAW12转bmp时,提示文件大小不对,百度发现RAW12 每pixel占2个字节,高4位没用,用低12bit表示一个G/R/B/G。所以需要对RAW12图片进行填充
unsigned int u32H, u32W;
unsigned short *pu16Data = (unsigned short*)malloc(VDO_SIZE_W * 2U);
for(u32H = 0; u32H < video_frame[i].dim.h; u32H++)
{
int s32OutCnt = 0;
/* 2 pixels consist of 3 bytes */
unsigned int u32Tmp = video_frame[i].dim.w / 2;
for(u32W = 0; u32W < u32Tmp; u32W++)
{
/* byte2 byte1 byte0 */
unsigned char *pu8Tmp = ptr + 3 * u32W;
unsigned int u32Val = pu8Tmp[0] + (pu8Tmp[1] << 8) + (pu8Tmp[2] << 16);
pu16Data[s32OutCnt++] = u32Val & 0xfff;
pu16Data[s32OutCnt++] = (u32Val >> 12) & 0xfff;
}
fwrite(pu16Data, video_frame[i].dim.w, 2, f_out_main);
ptr += video_frame[i].dim.w * 3 / 2;
}
fflush(f_out_main);
假如需要将低四位填充0呢?
pu16OutData[s32OutCnt++] = (((pu8Tmp[1] & 0xf) << 8) + pu8Tmp[0]) << 4;
pu16OutData[s32OutCnt++] = ((pu8Tmp[2] << 4) + ((pu8Tmp[1] & 0xf0) >> 4)) << 4;
上一篇: 语音识别职位信息汇总
下一篇: Lucene全文检索中用到方法