繁体   English   中英

android - 使用RenderScript进行YUV NV12到RGB的转换

[英]android - YUV NV12 to RGB conversion with RenderScript

Android具有YUV到RGB的buildin转换功能,下面的代码适用于NV21 YUV输入,但如果使用NV12输入,它会崩溃。

public Bitmap YUV_toRGB(byte[] yuvByteArray,int W,int H) {
    RenderScript rs = RenderScript.create(this);
    ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));

    Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(yuvByteArray.length);
    Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);

    Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(W).setY(H);
    Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);

    in.copyFrom(yuvByteArray);

    yuvToRgbIntrinsic.setInput(in);
    yuvToRgbIntrinsic.forEach(out);
    Bitmap bmp = Bitmap.createBitmap(W, H, Bitmap.Config.ARGB_8888);
    out.copyTo(bmp);

    yuvToRgbIntrinsic.destroy();
    rs.destroy();
    return bmp;
}

如何更改代码以将NV12转换为RGB? 没有文件说明支持的输入格式是什么以及如何配置它。

ScriptIntrinsicYuvToRGB上的Android文档明确指出:

输入分配以NV21格式提供,作为U8元素类型。 输出为RGBA,alpha通道将设置为255。

如果您需要不同的YUV格式,则必须编写自己的RS内核来进行转换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM