YuvConverter.java 文件源码

java
阅读 21 收藏 0 点赞 0 评论 0

项目:DeviceConnect-Android 作者:
/**
 * YuvImage converter (line by line).
 * @param width The width of image.
 * @param height The height of image.
 * @param yuvStrides yuvStrides array.
 * @param yuvPlanes yuvPlanes array.
 * @return YuvImage data.
 */
public static YuvImage convertToYuvImageLineByLine(final int width, final int height, final int[] yuvStrides, final ByteBuffer[] yuvPlanes) {
    byte[] bytes = new byte[width * height * 3 / 2];
    byte[] yuvPlanes0 = yuvPlanes[0].array();
    byte[] yuvPlanes1 = yuvPlanes[1].array();
    byte[] yuvPlanes2 = yuvPlanes[2].array();

    int i = 0;
    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            bytes[i++] = yuvPlanes0[col + row * yuvStrides[0]];
        }
    }
    for (int row = 0; row < height / 2; row++) {
        for (int col = 0; col < width / 2; col++) {
            bytes[i++] = yuvPlanes2[col + row * yuvStrides[2]];
            bytes[i++] = yuvPlanes1[col + row * yuvStrides[1]];
        }
    }
    return new YuvImage(bytes, ImageFormat.NV21, width, height, null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号