问题
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