NV21格式和奇数图像尺寸

NV21格式和奇数图像尺寸

本文介绍了NV21格式和奇数图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Android中的NV21图像工作了一段时间,我一直在跟踪可能由NV21图像中的错误索引字节引起的错误。




  1. 当图像具有奇数尺寸(如奇偶校验)时会发生什么?这种格式甚至可以吗?

  2. 我们在某处有这种格式的官方规范吗?


解决方案

对于具有奇数尺寸的图像(即W或H中的一个,在WxH图像中是奇数),您希望Y平面一如既往地被完全采样,使用WxH样本,然后是2(⌈ W / 2⌉ x⌈ H / 2⌉)色度样本,我们除以每个图像尺寸为2但是向上舍入而不是向下舍入。



因此,图像边缘的一些像素具有仅对应于1或2的色度样本原始像素,而不是4.我希望这是有道理的。您可以在中看到其他几个图书馆之前在YUV图像中处理奇怪维度的问题。



对于你的第二个问题,我还没有看到官方规范,但我在android框架中看到了一些代码处理这种格式,我会看看是否可以找到它的链接,并将其附加到这个答案。


I have been working for some time with NV21 images in Android and I have been tracking a bug that might be caused by incorrect indexing bytes in an NV21 image.

The image in the answer of this question has a nice overview of how the Y, U and V bytes are positioned in the image buffer. Not sure it is allowed, but I am embedding it below:

  1. What happens when the image has odd dimensions (as in parity)? Is that even possible in this format?
  2. Do we have an official specification of this format somewhere?
解决方案

In the case of an image with odd dimensions (i.e one of W or H, in a WxH image is odd), you'd expect the Y plane to be fully sampled as always, with WxH samples, followed by 2(⌈W/2⌉ x ⌈H/2⌉) chroma samples, where we divide each image dimension by 2 but round up rather than round down.

So some of the pixels at the very edge of the image have chroma samples that correspond to only 1 or 2 original pixels, rather than 4. I hope that makes sense. You can see in this link that a couple of other libraries have had issues handling odd dimensions in YUV images previously.

For your second question, I haven't seen an official specification, but I have seen some code in the android framework that handles this format, I will see if I can dig up a link to it, and append it to this answer.

这篇关于NV21格式和奇数图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:38