public void StoreSnapshot(IBitmapCustom bitmap) { const double INVERSE255 = 1d / 255d; this.Bitmap = Tuple.Create(TokenGenerator.NextToken(), bitmap); //TODO: This is called from the camera pool's thread, which is pretty taxed, so may want this logic in a task // R for (int cntr = 0; cntr < _neuronsR.Length; cntr++) { byte[] color = GetColor(_overlayR[cntr], bitmap); _neuronsR[cntr].Value = color[1] * INVERSE255; } // G for (int cntr = 0; cntr < _neuronsG.Length; cntr++) { byte[] color = GetColor(_overlayG[cntr], bitmap); _neuronsG[cntr].Value = color[2] * INVERSE255; } // B for (int cntr = 0; cntr < _neuronsB.Length; cntr++) { byte[] color = GetColor(_overlayB[cntr], bitmap); _neuronsB[cntr].Value = color[3] * INVERSE255; } }
private static void Run(TaskWrapper parent, CancellationToken cancel, Color background) { //NOTE: This method is running on an arbitrary thread try { // Create viewport ViewportOffline viewport = new ViewportOffline(background); List <ICameraPoolCamera> cameras = new List <ICameraPoolCamera>(); while (!cancel.IsCancellationRequested) { // Add/Remove items AddRemoveItems(parent, viewport, cameras); if (cameras.Count == 0) { // Hang out for a bit, then try again. No need to burn up the processor //TODO: UseAutoResetEvent (triggered by another thread in CameraPool.Add()) //http://stackoverflow.com/questions/382173/what-are-alternative-ways-to-suspend-and-resume-a-thread Thread.Sleep(450 + StaticRandom.Next(100)); continue; } MoveVisuals(viewport); #region Take pictures //TODO: If it takes a long time to get through these cameras, then maybe the visuals should be moved after every couple cameras foreach (ICameraPoolCamera camera in cameras) { if (cancel.IsCancellationRequested) { return; } if (camera.IsOn) { var location = camera.GetWorldLocation_Camera(); IBitmapCustom bitmap = viewport.GetSnapshot(location.Item1, location.Item2.Standard, location.Item2.Orth, camera.PixelWidthHeight); camera.StoreSnapshot(bitmap); } } #endregion Thread.Sleep(0); // not sure if this is useful or not //Thread.Yield(); } } catch (Exception) { // Don't leak errors, just go away } }
internal static byte[] GetColor(OverlayResult[] pixels, IBitmapCustom bitmap) { Tuple <byte[], double>[] colors = new Tuple <byte[], double> [pixels.Length]; for (int cntr = 0; cntr < pixels.Length; cntr++) { colors[cntr] = Tuple.Create(bitmap.GetColor_Byte(pixels[cntr].X, pixels[cntr].Y), pixels[cntr].Percent); } return(UtilityWPF.AverageColors(colors)); }
public void UpdateBitmap(IBitmapCustom bitmap) { if (_pixels == null) { return; } _bitmap = bitmap; Color[] colors = null; if (_bitmap == null) { colors = Enumerable.Repeat(Colors.Transparent, _pixels.Item1 * _pixels.Item2).ToArray(); } else { colors = bitmap.GetColors(0, 0, _pixels.Item1, _pixels.Item2); } ColorPixels(colors); ColorPolygons(colors); ColorTriangles(colors); ColorCircles(colors); }
internal static byte[] GetColor(OverlayResult[] pixels, IBitmapCustom bitmap) { Tuple<byte[], double>[] colors = new Tuple<byte[], double>[pixels.Length]; for (int cntr = 0; cntr < pixels.Length; cntr++) { colors[cntr] = Tuple.Create(bitmap.GetColor_Byte(pixels[cntr].X, pixels[cntr].Y), pixels[cntr].Percent); } return UtilityWPF.AverageColors(colors); }