1

I am using libyuv to convert NV21 image format to I420:

void convert(uint8* input, int width, int height) {

  int size = width * height * 3/2;
  uint8* output = new uint8[size];

  uint8* src_y = input;
  int src_stride_y = width;
  uint8* src_vu = input + (width * height);
  int src_stride_vu = width / 2;
  uint8* dst_y = output;
  int dst_stride_y = width;
  uint8* dst_u = dst_y + (width * height);
  int dst_stride_u = width / 2;
  uint8* dst_v = dst_u + (width * height) / 4;
  int dst_stride_v = width / 2;

  libyuv::NV21ToI420(src_y, src_stride_y,
           src_vu, src_stride_vu,
           dst_y, dst_stride_y,
           dst_u, dst_stride_u,
           dst_v, dst_stride_v,
           width, height);

  dumpToFile(dst_y, size);
  ...
}

The size of my input is 640x480.

I display the dumped file using ImageMagick's display:

$ display -size 640x480 -depth 8 -sampling-factor 4:2:0 -colorspace srgb MyI420_1.yuv

However, the colors are messed up in the displayed image. The other aspects of the image look okay.

I am wondering if I am making a mistake in my code. Perhaps my stride calculations are not correct.

Note that if I use my custom function to rearrange V1U1V2U2... as U1U2...V1V2... and dump the output, it displays fine. However, I prefer to use libyuv as it has some optimization for neon, SSE2, etc. Regards.

4

1 回答 1

0

你的src_stride_vu需要是一样的,width因为它结合了跨行的 UV 像素的步幅。

于 2021-03-05T08:22:46.397 回答