1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
-
- namespace NRKernal
- {
- using System;
- using UnityEngine;
-
- public class NRRGBCamTexture : CameraModelView
- {
-
- public Action<CameraTextureFrame> OnUpdate;
-
- public CameraTextureFrame CurrentFrame;
-
- private Texture2D m_Texture;
-
- private byte[] m_RawData;
- public byte[] RawData { get { return m_RawData; } }
-
- public NRRGBCamTexture() : base(CameraImageFormat.RGB_888)
- {
- this.m_Texture = CreateTexture();
- this.CurrentFrame.texture = this.m_Texture;
- }
-
-
- private Texture2D CreateTexture()
- {
- return new Texture2D(Width, Height, TextureFormat.RGB24, false);
- }
-
-
- public Texture2D GetTexture()
- {
- if (m_Texture == null)
- {
- this.m_Texture = CreateTexture();
- this.CurrentFrame.texture = this.m_Texture;
- }
- return m_Texture;
- }
-
-
- protected override void OnRawDataUpdate(FrameRawData frame)
- {
- if (m_Texture == null)
- {
- this.m_Texture = CreateTexture();
- }
- int dataSize = frame.data.Length;
- if (m_RawData == null || m_RawData.Length != dataSize)
- {
- m_RawData = new byte[dataSize];
- }
- Array.Copy(frame.data, 0, m_RawData, 0, dataSize);
-
- m_Texture.LoadRawTextureData(m_RawData);
- m_Texture.Apply();
- CurrentFrame.timeStamp = frame.timeStamp;
- CurrentFrame.gain = frame.gain;
- CurrentFrame.exposureTime = frame.exposureTime;
- CurrentFrame.texture = m_Texture;
- OnUpdate?.Invoke(CurrentFrame);
- }
-
- protected override void OnStopped()
- {
- GameObject.Destroy(m_Texture);
- this.m_Texture = null;
- m_RawData = null;
- this.CurrentFrame.texture = null;
- }
- }
- }
|