Beispiel #1
0
        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.All(i => i.Item1 != timestamp))
            {
                _colorsByTime.Add(new Tuple <TimeSpan, Color>(timestamp, average));

                while (_colorsByTime.Count > 500)
                {
                    _colorsByTime.RemoveAt(0);
                }
            }

            PixelPreview = new SolidColorBrush(average);
        }
Beispiel #2
0
        private void SourceOnProgressChanged(object sender, TimeSpan progress)
        {
            if (Sampler == null)
            {
                return;
            }

            if (Frames == null)
            {
                _colors = Sampler.GetColors(progress, Samples);
            }
            else
            {
                double frame      = progress.TotalSeconds * Frames.DurationDenominator * Frames.TotalFramesInVideo / Frames.DurationNumerator;
                int    lastIndex  = (int)Math.Round(frame);
                int    firstIndex = lastIndex - Samples + 1;

                lastIndex  = ClampInt(lastIndex, 0, Frames.Count);
                firstIndex = ClampInt(firstIndex, 0, Frames.Count);

                _colors = Frames.Skip(firstIndex - 1).Take(lastIndex - firstIndex)
                          .Select(p => SampleCondition.GetAverageColor(p.Capture)).Reverse().ToList();
            }

            InvalidateVisual();
        }
Beispiel #3
0
        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();
                }
            }
        }
Beispiel #4
0
 public SampleAnalyser(SampleCondition condition, AnalysisParameters parameters)
 {
     _previousSample = new byte[] { 0, 0, 0 };
     _condition      = condition;
     _parameters     = parameters;
 }
Beispiel #5
0
 public SampleAnalyser(SampleCondition condition, AnalysisParameters parameters)
 {
     _condition  = condition;
     _parameters = parameters;
 }