use of android.renderscript.ScriptIntrinsicYuvToRGB in project PolarrCameraAndroidSDK by Polarrco.
the class MainActivity method renderScriptNV21ToRGBA888.
public Allocation renderScriptNV21ToRGBA888(Context context, int width, int height, byte[] nv21) {
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length);
Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
in.copyFrom(nv21);
yuvToRgbIntrinsic.setInput(in);
yuvToRgbIntrinsic.forEach(out);
return out;
}
use of android.renderscript.ScriptIntrinsicYuvToRGB in project android_packages_apps_Snap by LineageOS.
the class CaptureUI method getMonoDummySurface.
public Surface getMonoDummySurface() {
if (mMonoDummyAllocation == null) {
RenderScript rs = RenderScript.create(mActivity);
Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs));
yuvTypeBuilder.setX(mPreviewWidth);
yuvTypeBuilder.setY(mPreviewHeight);
yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888);
mMonoDummyAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(), Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);
ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(rs));
yuvToRgbIntrinsic.setInput(mMonoDummyAllocation);
if (mSettingsManager.getValue(SettingsManager.KEY_MONO_PREVIEW).equalsIgnoreCase("on")) {
Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
rgbTypeBuilder.setX(mPreviewWidth);
rgbTypeBuilder.setY(mPreviewHeight);
mMonoDummyOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT);
mMonoDummyOutputAllocation.setSurface(mSurfaceHolderMono.getSurface());
mActivity.runOnUiThread(new Runnable() {
public void run() {
mSurfaceHolderMono.setFixedSize(mPreviewWidth, mPreviewHeight);
mSurfaceViewMono.setVisibility(View.VISIBLE);
}
});
}
mMonoDummyAllocation.setOnBufferAvailableListener(new MonoDummyListener(yuvToRgbIntrinsic));
mIsMonoDummyAllocationEverUsed = false;
}
return mMonoDummyAllocation.getSurface();
}
Aggregations