我正在研究Android的YuvImage.java代码http://androidxref.com/4.2.2_r1/xref/frameworks/base/graphics/java/android/graphics/YuvImage.java#199:
为什么YUY2的步幅为width * 2,而NV21的步幅为width?
这是代码:
199 private int[] calculateStrides(int width, int format) {
200 int[] strides = null;
201 if (format == ImageFormat.NV21) {
202 strides = new int[] {width, width};
203 return strides;
204 }
205
206 if (format == ImageFormat.YUY2) {
207 strides = new int[] {width * 2};
208 return strides;
209 }
210
211 return strides;
212 }
最佳答案
NV21格式有两个平面,一个平面用于亮度,一个平面用于颜色值。第一个的步幅是宽度(在数组的第一个元素中找到)和第二个平面的宽度(在数组的第二个元素中找到)。因此,它是宽度加宽度。
在YUY2格式中,亮度和颜色信息被交织,步幅(单个像素行的数据长度)是宽度的两倍(存储在生成的数组的唯一元素中)。