Example #1
0
 public void Commit(CaptureTask task)
 {
     if (m_CurrentFrame != null)
     {
         m_Requests.Enqueue(AsyncGPUReadback.Request(m_CurrentFrame));
         m_Tasks.Enqueue(task);
     }
     else
     {
         NRDebugger.LogWarning("[ImageEncoder] Lost frame data.");
     }
 }
Example #2
0
        public byte[] Encode(int width, int height, PhotoCaptureFileOutputFormat format)
        {
            if (m_CurrentFrame == null)
            {
                NRDebugger.LogWarning("Current frame is empty!");
                return(null);
            }
            byte[]        data     = null;
            RenderTexture pre      = RenderTexture.active;
            RenderTexture targetRT = m_CurrentFrame;

            RenderTexture.active = targetRT;
            Texture2D texture2D = new Texture2D(targetRT.width, targetRT.height, TextureFormat.ARGB32, false);

            texture2D.ReadPixels(new Rect(0, 0, targetRT.width, targetRT.height), 0, 0);
            texture2D.Apply();
            RenderTexture.active = pre;

            Texture2D outPutTex    = texture2D;
            Texture2D scaleTexture = null;

            // Scale the texture while the output width or height not equal to the targetRT.
            if (width != targetRT.width || height != targetRT.height)
            {
                scaleTexture = ImageEncoder.ScaleTexture(texture2D, width, height);
                outPutTex    = scaleTexture;
            }

            switch (format)
            {
            case PhotoCaptureFileOutputFormat.JPG:
                data = outPutTex.EncodeToJPG();
                break;

            case PhotoCaptureFileOutputFormat.PNG:
                data = outPutTex.EncodeToPNG();
                break;

            default:
                break;
            }

            // Clear the temp texture.
            GameObject.Destroy(texture2D);
            if (scaleTexture != null)
            {
                GameObject.Destroy(scaleTexture);
            }

            return(data);
        }
 /// <summary>
 /// Provides a COM pointer to the native IVideoDeviceController.
 /// A native COM pointer to the IVideoDeviceController.
 /// </summary>
 public IntPtr GetUnsafePointerToVideoDeviceController()
 {
     NRDebugger.LogWarning("[NRPhotoCapture] Interface not supported...");
     return(IntPtr.Zero);
 }