使用 Libyuv 将 YUV_420 _888 转换为 ARGB

Convert YUV_420 _888 to ARGB using Libyuv

我正在通过调用 Libyuv 库中的方法 I420ToARGB 来处理编码为 YUV_420 _888 的 Android camera2 预览帧,但我得到的图像颜色错误。

 libyuv::I420ToARGB(
    ysrc, //const uint8* src_y,
    ystride, //int src_stride_y,
    usrc, //const uint8* src_u,
    ustride, ///int src_stride_u,
    vsrc, //const uint8* src_v,
    vstride, //int src_stride_v,
    argb, //uint8* dst_argb,
    w*4, //int dst_stride_argb,
    w, //int width,
    h //int height
);

如果红色对象显示为蓝色,反之亦然,则 U 和 V 颜色平面倒转。根据 Android 开发者文档,飞机是:

http://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888

The order of planes in the array returned by Image#getPlanes() is guaranteed such that plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr).

此外,这个 libyuv 方法似乎不支持像素步幅,对于 YUY_420_888 图像,像素步幅可能大于 1。在这种情况下,当像素步幅大于 1 时,您需要将平面预处理为连续的,或者使用一种从 libyuv 接受半平面 420(如果存在)的方法。