public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            try
            {
                var conf = new ChromakeyViewModel(configData);
                dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");

                KalikoImage image  = new KalikoImage(infile);
                var         x      = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(conf.BackgroundColor);
                var         filter = new ChromaKeyFilter();
                filter.KeyColor             = Color.FromArgb(x.R, x.G, x.B);
                filter.ToleranceHue         = conf.Hue;
                filter.ToleranceSaturnation = conf.Saturnation / 100f;
                filter.ToleranceBrightness  = conf.Brigthness / 100f;
                image.ApplyFilter(filter);
                var res = image.Clone();

                if (conf.UnsharpMask)
                {
                    res.ApplyFilter(new UnsharpMaskFilter(1.4f, 1.32f, 5));
                }

                var backdrop = new KalikoImage(conf.BackgroundFile);
                backdrop = backdrop.Scale(new FitScaling(image.Width, image.Height));
                backdrop.BlitImage(res);

                backdrop.SaveJpg(dest, 90);
                return(dest);
            }
            catch (Exception e)
            {
                Log.Debug("Chromakey error", e);
            }
            return(null);
        }
        private void Uninitialize()
        {
            _initialized = false;

            if (_timer != null)
            {
                _timer.Stop();
                _timer.Tick -= DispatcherTimer_Tick;
                _timer       = null;
            }

            if (_renderer != null)
            {
                _renderer.Dispose();
                _renderer = null;
            }

            if (_effect != null)
            {
                _effect.Dispose();
                _effect = null;
            }

            _filters         = null;
            _chromaKeyFilter = null;
            _rotationFilter  = null;
            _bitmap          = null;

            if (_source != null)
            {
                _source.Dispose();
                _source = null;
            }
        }
        private void Initialize()
        {
            // Initialize camera

            var rotation = App.Camera.SensorLocation == CameraSensorLocation.Back ?
                           App.Camera.SensorRotationInDegrees : -App.Camera.SensorRotationInDegrees;

            ViewfinderBrush.SetSource(App.Camera);
            ViewfinderBrushTransform.Rotation = rotation;

            // Setup image processing pipeline

            _source          = new CameraPreviewImageSource(App.Camera);
            _rotationFilter  = new RotationFilter(rotation);
            _chromaKeyFilter = new ChromaKeyFilter();

            _filters = new List <IFilter> {
                _rotationFilter, _chromaKeyFilter
            };

            _effect = new FilterEffect(_source)
            {
                Filters = _filters
            };

            _bitmap   = new WriteableBitmap((int)App.Camera.PreviewResolution.Width, (int)App.Camera.PreviewResolution.Height);
            _renderer = new WriteableBitmapRenderer(_effect, _bitmap, OutputOption.Stretch);

            FilteredImage.Source = _bitmap;

            _color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);

            ColorBorder.Background = new SolidColorBrush(_color);

            // Start rendering timer

            _timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(10)
            };
            _timer.Tick += DispatcherTimer_Tick;
            _timer.Start();

            _initialized = true;
        }
        private void Uninitialize()
        {
            _initialized = false;

            if (_timer != null)
            {
                _timer.Stop();
                _timer.Tick -= DispatcherTimer_Tick;
                _timer = null;
            }

            if (_renderer != null)
            {
                _renderer.Dispose();
                _renderer = null;
            }

            if (_effect != null)
            {
                _effect.Dispose();
                _effect = null;
            }

            _filters = null;
            _chromaKeyFilter = null;
            _rotationFilter = null;
            _bitmap = null;

            if (_source != null)
            {
                _source.Dispose();
                _source = null;
            }
        }
        private void Initialize()
        {
            // Initialize camera

            var rotation = App.Camera.SensorLocation == CameraSensorLocation.Back ?
                App.Camera.SensorRotationInDegrees : - App.Camera.SensorRotationInDegrees;

            ViewfinderBrush.SetSource(App.Camera);
            ViewfinderBrushTransform.Rotation = rotation;

            // Setup image processing pipeline

            _source = new CameraPreviewImageSource(App.Camera);
            _rotationFilter = new RotationFilter(rotation);
            _chromaKeyFilter = new ChromaKeyFilter();

            _filters = new List<IFilter> {_rotationFilter, _chromaKeyFilter};

            _effect = new FilterEffect(_source) {Filters = _filters};

            _bitmap = new WriteableBitmap((int)App.Camera.PreviewResolution.Width, (int)App.Camera.PreviewResolution.Height);
            _renderer = new WriteableBitmapRenderer(_effect, _bitmap, OutputOption.Stretch);

            FilteredImage.Source = _bitmap;

            _color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);

            ColorBorder.Background = new SolidColorBrush(_color);

            // Start rendering timer

            _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) };
            _timer.Tick += DispatcherTimer_Tick;
            _timer.Start();

            _initialized = true;
        }