1.buffer地址偏移
以分辨率 1280*720 格式为YV12 为例,Y起始地址为0x100000000 ,且是连续
y_addr = 0x100000000;
cb_addr = y_addr + 1280×720;
cr_addr = cb_addr + 1280*720/4;
2.line stride计算
需要考虑到不同硬件使用相同的地址,如camera 写buffer display去显示。而两个硬件的line stride 要求不同,则需要计算一个line stride 来满足他们。下面是android 官网给的计算方式.
PS: line stride 可以理解为硬件写实际一行后,下一行起始地址的累加长度,
如 1028 ×720 对齐后 1280×720 .则硬件每次写一行数据为1280,一共写720行,这样就把对应的Y数据写完
Android YUV format.
This format is exposed to software decoders and applications.
YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed by (W/2) x (H/2) Cr and Cb planes.
This format assumes
an even width
an even height
a horizontal stride multiple of 16 pixels
a vertical stride equal to the height
y_size = stride * height
c_stride = ALIGN(stride/2, 16)
c_size = c_stride * height/2
size = y_size + c_size * 2
cr_offset = y_size
cb_offset = y_size + c_size
NV21 的line stride
cb_stride = y_stride;
cr_stride = 0;