private void onStart(int texPtr, int width, int height) { dispatch.Dispatch(() => { preview = preview ?? Texture2D.CreateExternalTexture(width, height, TextureFormat.RGBA32, false, false, (IntPtr)texPtr); if (preview.width != width || preview.height != height) { preview.Resize(width, height, preview.format, false); } if (OnStart != null) { OnStart(); } }); }
public void Play() { if (!supportedDevice) { return; } if (dispatch == null) { dispatch = new MainDispatch(); dispatch.Dispatch(Update, true); } if (preview == null) { int width, height, rate = (int)device.GetFramerate(camera); string name = WebCamTexture.devices[camera].name; device.GetPreviewResolution(camera, out width, out height); rate = rate == 0 ? 30 : rate; preview = width == 0 ? new WebCamTexture(name) : new WebCamTexture(name, width, height, rate); } #if NATCAM_EXTENDED SetDetection(OnMetadata != null); #endif firstFrame = true; preview.Play(); }
/* * 现在发送网络消息,都统一走EventCenter */ public override void DispatchToRealHandler() { if (dispatch != null) { dispatch.Dispatch(this); } }
private void Update() { // Check that we are playing if ( !PreviewTexture || !PreviewTexture.isPlaying || !PreviewTexture.didUpdateThisFrame || PreviewTexture.width == 16 || PreviewTexture.height == 16 ) { if (dispatch != null) { dispatch.Dispatch(Update); } return; } // Update preview buffer if (previewBuffer == null) { previewBuffer = PreviewTexture.GetPixels32(); } else { PreviewTexture.GetPixels32(previewBuffer); } // Invoke events if (firstFrame) { if (OnStart != null) { OnStart(); } firstFrame = false; } if (OnFrame != null) { OnFrame(); } // Re-invoke if (dispatch != null) { dispatch.Dispatch(Update); } }
public static void DetectBarcode(Color32[] frame, int width, int height, IDispatch dispatch, MetadataCallback <IMetadata> callback) { if (frame == null || dispatch == null || callback == null) { return; } #if ZXING_API var results = reader.DecodeMultiple(frame, width, height); dispatch.Dispatch(() => results.ForEach(result => callback(NatCamBarcode(result)))); #endif }
public void Update() { if (Input.GetKey(KeyCode.Space)) { sourceDispatcher.Dispatch(); } else { dispatchcer.Dispatch(); } }
public void Update() { if (Input.GetKey(KeyCode.Space)) { sourceDispatcher.Dispatch(); } else { dispatchcer.Dispatch(); } if (tensionDispatcher != null) { tensionDispatcher.Dispatch(); } }
public static void RotateImage(Texture2D texture, Orientation rotation, IDispatch workerDispatch, IDispatch mainDispatch, PhotoCallback callback) { if (callback == null) { return; } if (rotation == 0) { callback(texture, rotation); return; } int width = texture.width, height = texture.height; Color32[] src = texture.GetPixels32(), dst = new Color32[src.Length]; Action completion = () => { if (((int)rotation & 7) % 2 != 0) { texture.Resize(height, width); } texture.SetPixels32(dst); texture.Apply(); src = dst = null; GC.Collect(); // No guarantees, but just have it anyway callback(texture, (Orientation)rotation); }; Action process = () => { RotateImage(dst, src, width, height, (byte)rotation); if (mainDispatch != null) { mainDispatch.Dispatch(completion); } else { completion(); } }; if (workerDispatch != null) { workerDispatch.Dispatch(process); } else { process(); } }
public void Play() { // Create dispatch if (dispatch == null) { dispatch = new MainDispatch(); dispatch.Dispatch(Update); } // Create preview if (!PreviewTexture) { string name = WebCamTexture.devices[camera].name; var resolution = Device.GetPreviewResolution(camera); var rate = Mathf.Max(30, (int)Device.GetFramerate(camera)); PreviewTexture = resolution.width == 0 ? new WebCamTexture(name) : new WebCamTexture(name, resolution.width, resolution.height, rate); } // Start preview firstFrame = true; PreviewTexture.Play(); }
private void MetadataUpdate() { int width = preview.width, height = preview.height, size = width * height; lock (bufferFence) { if (metadataBuffer != null && metadataBuffer.Length != size) { metadataBuffer = null; } metadataBuffer = metadataBuffer ?? new Color32[size]; preview.GetPixels32(metadataBuffer); } metadataDispatch.Dispatch(() => { if (dispatchBuffer != null && dispatchBuffer.Length != size) { dispatchBuffer = null; } dispatchBuffer = dispatchBuffer ?? new Color32[size]; lock (bufferFence) Array.Copy(metadataBuffer, dispatchBuffer, size); DetectBarcode(dispatchBuffer, width, height, dispatch, OnMetadata); }); }