private void UpdateRawImage(ref Texture2D texture, XRCpuImage cpuImage) { if (texture == null || texture.width != cpuImage.width || texture.height != cpuImage.height) { texture = new Texture2D(cpuImage.width, cpuImage.height, TextureFormat.RGB565, false); } var conversionParams = new XRCpuImage.ConversionParams(cpuImage, TextureFormat.R16); var rawTextureData = texture.GetRawTextureData <byte>(); cpuImage.Convert(conversionParams, rawTextureData); texture.Apply(); }
private static void UpdateRawImage(Texture2D texture, XRCpuImage cpuImage) { var conversionParams = new XRCpuImage.ConversionParams(cpuImage, cpuImage.format.AsTextureFormat(), XRCpuImage.Transformation.MirrorY); var rawTextureData = texture.GetRawTextureData <byte>(); Debug.Assert( rawTextureData.Length == cpuImage.GetConvertedDataSize(conversionParams.outputDimensions, conversionParams.outputFormat), "The Texture2D is not the same size as the converted data."); cpuImage.Convert(conversionParams, rawTextureData); texture.Apply(); }
void UpdateRawImage(Texture2D texture, XRCpuImage cpuImage) { // For display, we need to mirror about the vertical access. var conversionParams = new XRCpuImage.ConversionParams(cpuImage, cpuImage.format.AsTextureFormat(), XRCpuImage.Transformation.MirrorY); // Get the Texture2D's underlying pixel buffer. var rawTextureData = texture.GetRawTextureData <byte>(); // Make sure the destination buffer is large enough to hold the converted data (they should be the same size) Debug.Assert(rawTextureData.Length == cpuImage.GetConvertedDataSize(conversionParams.outputDimensions, conversionParams.outputFormat), "The Texture2D is not the same size as the converted data."); // Perform the conversion. cpuImage.Convert(conversionParams, rawTextureData); // "Apply" the new pixel data to the Texture2D. texture.Apply(); }
public static void GetPlaneDataRGB(out byte[] pixels, XRCpuImage image) { var conversionParams = new XRCpuImage.ConversionParams { inputRect = new RectInt(0, 0, image.width, image.height), outputDimensions = new Vector2Int(image.width, image.height), outputFormat = TextureFormat.RGB24, transformation = XRCpuImage.Transformation.None }; int size = image.GetConvertedDataSize(conversionParams); pixels = new byte[size]; GCHandle bufferHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned); image.Convert(conversionParams, bufferHandle.AddrOfPinnedObject(), pixels.Length); bufferHandle.Free(); }