public void AddSample(FrameCapture capture) { bool samplePositive = _condition.CheckSample(capture.Capture); long frameIndex = capture.FrameIndex; _conditionFullfilled.Add(frameIndex, samplePositive); }
protected override void OnRender(DrawingContext drawingContext) { var rect = new Rect(0, 0, ActualWidth, ActualHeight); Color[] colors; if (_colors == null) { drawingContext.DrawRectangle(Brushes.Black, null, rect); } else { colors = _colors.ToArray(); Array.Reverse(colors); var background = new LinearGradientBrush(HeatMapGenerator.GradientsSharpFromColors(colors), new Point(0, 0), new Point(1, 0)); drawingContext.DrawRectangle(background, null, rect); var conditionRect = new Rect(0, ActualHeight - 8, ActualWidth, 8); if (SampleCondition == null) { drawingContext.DrawRectangle(Brushes.Black, null, conditionRect); } else { var samples = new Color[colors.Length]; Color previousColor = Colors.Black; for (int i = 0; i < samples.Length; i++) { bool isOk = SampleCondition.CheckSample( new[] { colors[i].R, colors[i].G, colors[i].B }, new[] { previousColor.R, previousColor.G, previousColor.B }); samples[i] = isOk ? Colors.Lime : Colors.Red; previousColor = colors[i]; } var results = new LinearGradientBrush(HeatMapGenerator.GradientsSharpFromColors(samples), new Point(0, 0), new Point(1, 0)); drawingContext.DrawRectangle(results, null, conditionRect); } if (_down) { _segment = (int)(_mousePos.X / ActualWidth * _colors.Count); _segment = Math.Max(0, Math.Min(_colors.Count - 1, _segment)); double segmentWidth = ActualWidth / _colors.Count; var selectRect = new Rect(segmentWidth * _segment, 0, segmentWidth, ActualHeight); drawingContext.DrawRectangle(null, new Pen(Brushes.Red, 1), selectRect); UpdateToolTip(); } } }
private void TakeSample(TimeSpan timestamp) { if (timestamp == lastTimestamp) { return; } lastTimestamp = timestamp; _bitmap.Render(_drawing); var rect = Sample; byte[] pixel = new byte[rect.Width * rect.Height * 4]; _bitmap.CopyPixels(new Int32Rect(0, 0, Sample.Width, Sample.Height), pixel, rect.Width * 4, 0); byte[] rgbPixels = SampleCondition.ConvertBgraToRgb(pixel); Color average = SampleCondition.GetAverageColor(rgbPixels); if (!_colorsByTime.Any(i => i.Item1 == timestamp)) { _colorsByTime.Add(new Tuple <TimeSpan, Color>(timestamp, average)); while (_colorsByTime.Count > 500) { _colorsByTime.RemoveAt(0); } } bool active = _condition.CheckSample(rgbPixels); if (active && !_active) { OnBeatDetected(timestamp); } _active = active; PixelPreview = new SolidColorBrush(average); }