/// <summary> /// Convert <paramref name="colors" /> to a packet and send it to the input stream. /// </summary> public Status PushColor32(Color32[] colors, int width, int height) { int timestamp = System.Environment.TickCount & System.Int32.MaxValue; var imageFrame = ImageFrame.FromPixels32(colors, width, height); if (!shouldUseGPU()) { var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet.GetPtr())); } var status = gpuHelper.RunInGlContext(() => { var texture = gpuHelper.CreateSourceTexture(imageFrame); var gpuFrame = texture.GetGpuBufferFrame(); UnsafeNativeMethods.GlFlush(); texture.Release(); return(graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuFrame, timestamp).GetPtr())); }); imageFrame.Dispose(); return(status); }
/// <summary> /// Convert <paramref name="colors" /> to a packet and send it to the input stream. /// </summary> public Status PushInput(PixelData pixelData) { var timestamp = new Timestamp(System.Environment.TickCount & System.Int32.MaxValue); var imageFrame = ImageFrame.FromPixels32(pixelData.Colors, pixelData.Width, pixelData.Height, true); if (!IsGpuEnabled()) { var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet)); } var status = gpuHelper.RunInGlContext(() => { var texture = gpuHelper.CreateSourceTexture(imageFrame); var gpuFrame = texture.GetGpuBufferFrame(); Gl.Flush(); texture.Release(); return(graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuFrame, timestamp))); }); imageFrame.Dispose(); return(status); }
public void CreateSourceTexture_ShouldFail_When_ImageFrameFormatIsInvalid() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var imageFrame = new ImageFrame(ImageFormat.Format.SBGRA, 32, 24); var status = glCalculatorHelper.RunInGlContext(() => { var texture = glCalculatorHelper.CreateSourceTexture(imageFrame); texture.Dispose(); return(Status.Ok()); }); Assert.AreEqual(status.code, Status.StatusCode.FailedPrecondition); }
public void CreateSourceTexture_ShouldReturnGlTexture_When_CalledWithImageFrame() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var imageFrame = new ImageFrame(ImageFormat.Format.SRGBA, 32, 24); var status = glCalculatorHelper.RunInGlContext(() => { var texture = glCalculatorHelper.CreateSourceTexture(imageFrame); Assert.AreEqual(texture.width, 32); Assert.AreEqual(texture.height, 24); texture.Dispose(); return(Status.Ok()); }); Assert.True(status.ok); }
/// <summary> /// Convert <paramref name="colors" /> to a packet and send it to the input stream. /// </summary> public Status PushInput(TextureFrame textureFrame) { var timestamp = new Timestamp(System.Environment.TickCount & System.Int32.MaxValue); ImageFrame imageFrame = null; if (!IsGpuEnabled()) { imageFrame = new ImageFrame( ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray()); textureFrame.Release(); var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet)); } #if UNITY_ANDROID var glTextureName = textureFrame.GetNativeTexturePtr(); return(gpuHelper.RunInGlContext(() => { var glContext = GlContext.GetCurrent(); var glTextureBuffer = new GlTextureBuffer((UInt32)glTextureName, textureFrame.width, textureFrame.height, textureFrame.gpuBufferformat, textureFrame.OnRelease, glContext); var gpuBuffer = new GpuBuffer(glTextureBuffer); return graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, timestamp)); })); #else imageFrame = new ImageFrame( ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray()); textureFrame.Release(); return(gpuHelper.RunInGlContext(() => { var texture = gpuHelper.CreateSourceTexture(imageFrame); var gpuBuffer = texture.GetGpuBufferFrame(); Gl.Flush(); texture.Release(); return graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, timestamp)); })); #endif }
public void CreateSourceTexture_ShouldFail_When_ImageFrameFormatIsInvalid() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); using (var imageFrame = new ImageFrame(ImageFormat.Types.Format.Sbgra, 32, 24)) { var status = glCalculatorHelper.RunInGlContext(() => { using (var texture = glCalculatorHelper.CreateSourceTexture(imageFrame)) { texture.Release(); } }); Assert.AreEqual(Status.StatusCode.FailedPrecondition, status.Code()); status.Dispose(); } } }
public void CreateSourceTexture_ShouldReturnGlTexture_When_CalledWithImageFrame() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); using (var imageFrame = new ImageFrame(ImageFormat.Types.Format.Srgba, 32, 24)) { var status = glCalculatorHelper.RunInGlContext(() => { var texture = glCalculatorHelper.CreateSourceTexture(imageFrame); Assert.AreEqual(32, texture.width); Assert.AreEqual(24, texture.height); texture.Dispose(); }); Assert.True(status.Ok()); status.Dispose(); } } }