Executing ScriptIntrinsicYuvToRgb

家住魔仙堡 提交于 2019-11-30 00:23:53

问题


I want to convert a byte[] in Yuv into a byte[] in Rgb. The ScriptIntrinsic (ScriptIntrinsicYuvToRgb) is supposed to do this (based on this example).

Here's some code I have right now:

byte[] imageData = ...gatheryuvbuffer...

Type.Builder tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
tb.setX(outputWidth);
tb.setY(outputHeight);
tb.setMipmaps(false);
tb.setYuvFormat(ImageFormat.NV21);
Allocation ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
ain.copyFrom(imageData);

Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS));
tb2.setX(outputWidth);
tb2.setY(outputHeight);
tb2.setMipmaps(false);

// Allocation aOutBitmap = Allocation.createFromBitmap(mRS, bitmap);
Allocation aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_IO_OUTPUT);
aOut.setSurface(null);

mYuvToRgb.setInput(ain);
mYuvToRgb.forEach(aOut);

Bitmap bitmap = Bitmap.createBitmap(outputWidth, outputHeight, Bitmap.Config.ARGB_8888);
aOut.copyTo(bitmap);

By the end of this script, I expect bitmap to contain something (I'm displaying it in an ImageView). But the bitmap shows up blank. What's wwrong with this code snippet?


回答1:


I think the problem is the output allocation is created with USAGE_IO_OUTPUT but a surface is never attached. I would try with (USAGE_SCRIPT & USAGE_SHARED) or just use the defaults.



来源:https://stackoverflow.com/questions/18435680/executing-scriptintrinsicyuvtorgb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!