Beispiel #1
10
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            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;
        }
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new RotateTransformViewModel(configData);
            // Read from file
            using (MagickImage image = new MagickImage(infile))
            {

                image.BackgroundColor = new MagickColor(Color.Black);
                if (conf.AutoRotate)
                {
                    ExifProfile profile = image.GetExifProfile();
                    image.AutoOrient();
                    profile.SetValue(ExifTag.Orientation, (UInt16)0);
                }
                if (conf.Angle > 0)
                    image.Rotate(conf.Angle);

                if(conf.FlipHorizontal)
                    image.Flop();

                if (conf.FlipVertical)
                    image.Flip();

                image.Format = MagickFormat.Jpeg;
                // Save the result
                image.Write(dest);
            }
            return dest;
        }
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);
            using (MagickImage image = new MagickImage(infile))
            {
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left = (int) (image.Width*prop.LiveviewSettings.HorizontalMin/100);
                    conf.Width = (image.Width*
                                  (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
                    conf.Top = (image.Height*prop.LiveviewSettings.VerticalMin/100);
                    conf.Height = (image.Height*(prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/
                                   100);
                }
                if (conf.CropMargins)
                {
                    conf.Left = image.Width * conf.WidthProcent / 100;
                    conf.Width = image.Width - (conf.Left*2);
                    conf.Top = image.Height * conf.HeightProcent / 100;
                    conf.Height = image.Height - (conf.Top*2);
                }

                MagickGeometry geometry = new MagickGeometry();
                geometry.Width = conf.Width;
                geometry.Height = conf.Height;
                geometry.X = conf.Left;
                geometry.Y = conf.Top;
                image.Crop(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
        public string Execute(FileItem item,string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);
            using (var fileStream = new MemoryStream(File.ReadAllBytes(infile)))
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                    BitmapCreateOptions.PreservePixelFormat,
                    BitmapCacheOption.OnLoad);
                WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left = (int) (writeableBitmap.PixelWidth*prop.LiveviewSettings.HorizontalMin/100);
                    conf.Width =
                        (int)
                            (writeableBitmap.PixelWidth*
                             (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
                    conf.Top = (int) (writeableBitmap.Height*prop.LiveviewSettings.VerticalMin/100);
                    conf.Height =
                        (int)
                            (writeableBitmap.Height*
                             (prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/100);
                }

                BitmapLoader.Save2Jpg(writeableBitmap.Crop(conf.Left,conf.Top,conf.Width,conf.Height), dest);
            }
            return dest;
        }
 public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
 {
     Thread thread = new Thread(() => ExecuteThread(item, infile, dest, configData));
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
     thread.Join();
     return dest;
 }
 public AutoExportPluginConfig()
 {
     ConfigData = new ValuePairEnumerator();
     ConfigDataCollection = new ObservableCollection<ValuePairEnumerator>();
     Conditions = new AsyncObservableCollection<PluginCondition>();
     IsError = false;
     IsRedy = true;
     RunAfterTransfer = true;
 }
 public ChromakeyViewModel(ValuePairEnumerator config)
 {
     _config = config;
     // first run set default values
     if (Hue == 0 && Saturnation == 0 && Brigthness == 0)
     {
         Hue = 40;
         Saturnation = 70;
         Brigthness = 50;
     }
     BrowseCommand = new RelayCommand(Browse);
 }
Beispiel #8
0
 public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
 {
     var conf = new EffectViewModel(configData);
     dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
     using (MagickImage image = new MagickImage(infile))
     {
         switch (conf.SelectedMode)
         {
             case 0:
                 image.SepiaTone(new Percentage(conf.Param1));
                 break;
             case 1:
                 image.OilPaint(conf.Param1,0.1);
                 break;
             case 2:
                 image.Sketch();
                 break;
             case 3:
                 image.Charcoal();
                 break;
             case 4:
                 image.Solarize();
                 break;
             case 5:
                 image.Swirl(conf.Param1);
                 break;
             case 6:
                 image.Wave(PixelInterpolateMethod.Bilinear, conf.Param1, conf.Param2);
                 break;
             case 7:
                 image.BlueShift();
                 break;
             case 8:
                 image.RotationalBlur(conf.Param1);
                 break;
             case 9:
                 image.Raise(conf.Param1);
                 break;
             case 10:
                 image.Negate();
                 break;
             case 11:
                 image.ColorSpace = ColorSpace.Gray;
                 break;
         }
         image.Format = MagickFormat.Jpeg;
         image.Write(dest);
     }
     return dest;
 }
        public string Execute(FileItem fileItem,string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new ResizeTransformViewModel(configData);
            dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
            using (MagickImage image = new MagickImage(infile))
            {
                MagickGeometry geometry = new MagickGeometry(conf.Width, conf.Height);
                geometry.IgnoreAspectRatio = !conf.KeepAspect;

                image.Resize(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new ScriptTransformViewModel(configData);
            using (Stream stream = ToStream(conf.Script))
            {
                MagickScript script = new MagickScript(stream);

                // Read image from file
                using (MagickImage image = new MagickImage(infile))
                {
                    // Execute script with the image and write it to a jpg file
                    script.Execute(image);
                    image.Write(dest);
                }
            }
            return dest;
        }
 public ScriptTransformViewModel(ValuePairEnumerator config)
 {
     _config = config;
     AvailableScripts = new List<string>();
     LoadCommand = new RelayCommand(Load);
     try
     {
         var files = Directory.GetFiles(Path.Combine(Settings.ApplicationFolder, "Data", "msl"), "*.msl");
         foreach (var file in files)
         {
             AvailableScripts.Add(Path.GetFileNameWithoutExtension(file));
         }
     }
     catch (Exception ex)
     {
         Log.Error("Error load scrip list", ex);
     }
 }
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new PixelBinningViewModel(configData);
            dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");

            using (MagickImage image = new MagickImage(infile))
            {
                int newx = image.Width/(conf.SelectedMode + 2);
                int newy = image.Height / (conf.SelectedMode + 2);
                int cropx = newx * (conf.SelectedMode + 2);
                int cropy = newy * (conf.SelectedMode + 2);
                if (cropx != image.Width || cropy != image.Height)
                    image.Crop(cropx, cropy, Gravity.Center);
                image.FilterType = FilterType.Box;
                image.Resize(newx,newy);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
Beispiel #13
0
 public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
 {
     var conf = new EnhanceViewModel(configData);
     dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
     using (MagickImage image = new MagickImage(infile))
     {
         if (conf.Normalize)
             image.Normalize();
         if (conf.AutoGamma)
             image.AutoGamma();
         image.BrightnessContrast(new Percentage(conf.Brightness), new Percentage(conf.Contrast));
         if (conf.SContrast > 0)
             image.SigmoidalContrast(true, conf.SContrast);
         if (conf.Edge)
             image.AdaptiveSharpen();
         if (conf.Sharpen > 0)
             image.UnsharpMask(1.5, 1.5, conf.Sharpen/100.0, 0.2);
         image.Format = MagickFormat.Jpeg;
         image.Write(dest);
     }
     return dest;
 }
 public OverlayTransformViewModel(ValuePairEnumerator config)
 {
     _config = config;
     BrowseCommand = new RelayCommand(Browse);
 }
 public PixelBinningViewModel(ValuePairEnumerator config)
 {
     _config = config;
 }
 public AutoExportPluginConfig(IAutoExportPlugin plugin)
 {
     Type = plugin.Name;
     IsEnabled = true;
     IsError = false;
     IsRedy = true;
     ConfigData = new ValuePairEnumerator();
     ConfigDataCollection = new ObservableCollection<ValuePairEnumerator>();
 }
 public AutoExportPluginConfig()
 {
     ConfigData = new ValuePairEnumerator();
     ConfigDataCollection = new ObservableCollection<ValuePairEnumerator>();
     IsError = false;
     IsRedy = true;
 }
 public UserControl GetConfig(ValuePairEnumerator configData)
 {
     var control = new ResizeTransformView();
     control.DataContext = new ResizeTransformViewModel(configData);
     return control;
 }
 public void AddTransforPlugin(string plugin)
 {
     var c = new ValuePairEnumerator();
     c["TransformPlugin"] = plugin;
     Config.ConfigDataCollection.Add(c);
     RaisePropertyChanged(() => TransformPluginItems);
 }
 public FileInfo()
 {
     ExifTags = new ValuePairEnumerator();
     FocusPoints = new List<Rect>();
 }
 public EnhanceViewModel(ValuePairEnumerator config)
 {
     _config = config;
     ResetCommand = new RelayCommand(Reset);
 }
Beispiel #22
0
 public FileInfo()
 {
     ExifTags    = new ValuePairEnumerator();
     FocusPoints = new List <Rect>();
 }
 public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
 {
     return ExecuteThread(item, infile, dest, configData);
 }
Beispiel #24
0
 public string Execute(FileItem item,string infile, string dest, ValuePairEnumerator configData)
 {
     if (infile != dest)
         File.Copy(infile, dest, true);
     return dest;
 }
Beispiel #25
0
 public UserControl GetConfig(ValuePairEnumerator configData)
 {
     return null;
 }
 public CropTransformViewModel(ValuePairEnumerator config)
 {
     _config = config;
 }
Beispiel #27
0
 public UserControl GetConfig(ValuePairEnumerator configData)
 {
     var control = new EffectView();
     control.DataContext = new EffectViewModel(configData);
     return control;
 }
 public void AddTransforPlugin(string plugin)
 {
     var c = new ValuePairEnumerator();
     c["TransformPlugin"] = plugin;
     Config.ConfigDataCollection.Add(c);
     RaisePropertyChanged(() => TransformPluginItems);
     foreach (var item in TransformPluginItems)
     {
         if (item.Config == c)
             SelectedTransformPluginItem = item;
     }
 }
 public UserControl GetConfig(ValuePairEnumerator configData)
 {
     var control = new OverlayTransformView {DataContext = new OverlayTransformViewModel(configData)};
     return control;
 }
        public string ExecuteThread(FileItem item,string infile, string dest, ValuePairEnumerator configData)
        {
            try
            {

            var conf = new OverlayTransformViewModel(configData);
            using (var fileStream = new MemoryStream(File.ReadAllBytes(infile)))
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                    BitmapCreateOptions.PreservePixelFormat,
                    BitmapCacheOption.OnLoad);
                WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                writeableBitmap.Freeze();

                Grid grid = new Grid
                {
                    Width = writeableBitmap.PixelWidth,
                    Height = writeableBitmap.PixelHeight,
                    ClipToBounds = true,
                    SnapsToDevicePixels = true
                };
                grid.UpdateLayout();
                var size = new Size(writeableBitmap.PixelWidth, writeableBitmap.PixelWidth);
                grid.Measure(size);
                grid.Arrange(new Rect(size));

                Image overlay = new Image();
                Image image = new Image { Width = writeableBitmap.PixelWidth, Height = writeableBitmap.PixelHeight };
                image.BeginInit();
                image.Source = writeableBitmap;
                image.EndInit();
                image.Stretch = Stretch.Fill;
                grid.Children.Add(image);
                grid.UpdateLayout();

                string text = "";
                if (!string.IsNullOrEmpty(conf.Text))
                {
                    Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
                    MatchCollection matchX = regPattern.Matches(conf.Text);
                    text = matchX.Cast<Match>()
                        .Aggregate(conf.Text,
                            (current1, match) =>
                                item.FileNameTemplates.Where(
                                    template =>
                                        String.Compare(template.Name, match.Value,
                                            StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1,
                                                (current, template) => current.Replace(match.Value, template.Value)));
                }
                TextBlock textBlock = new TextBlock
                {
                    Text = text,
                    Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString(conf.FontColor),
                    FontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString(conf.Font),
                    FontSize = conf.FontSize,
                    Opacity = conf.Transparency/100.00
                };
                if (conf.A11)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Left;
                    textBlock.VerticalAlignment = VerticalAlignment.Top;
                }
                if (conf.A12)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Center;
                    textBlock.VerticalAlignment = VerticalAlignment.Top;
                }
                if (conf.A13)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Right;
                    textBlock.VerticalAlignment = VerticalAlignment.Top;
                }
                if (conf.A21)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Left;
                    textBlock.VerticalAlignment = VerticalAlignment.Center;
                }
                if (conf.A22)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Center;
                    textBlock.VerticalAlignment = VerticalAlignment.Center;
                }
                if (conf.A23)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Right;
                    textBlock.VerticalAlignment = VerticalAlignment.Center;
                }
                if (conf.A31)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Left;
                    textBlock.VerticalAlignment = VerticalAlignment.Bottom;
                }
                if (conf.A32)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Center;
                    textBlock.VerticalAlignment = VerticalAlignment.Bottom;
                }
                if (conf.A33)
                {
                    textBlock.HorizontalAlignment = HorizontalAlignment.Right;
                    textBlock.VerticalAlignment = VerticalAlignment.Bottom;
                }

                textBlock.Margin = new Thickness(conf.Margins);
                if (File.Exists(conf.OverlayFile))
                {
                    overlay.Source = BitmapLoader.Instance.LoadImage(conf.OverlayFile, 0, 0);
                    overlay.Opacity = textBlock.Opacity;
                    if (!conf.StrechOverlay)
                    {
                        overlay.HorizontalAlignment = textBlock.HorizontalAlignment;
                        overlay.VerticalAlignment = textBlock.VerticalAlignment;
                        overlay.Stretch = Stretch.None;
                    }
                    else
                    {
                        overlay.HorizontalAlignment = HorizontalAlignment.Stretch;
                        overlay.VerticalAlignment = VerticalAlignment.Stretch;
                        overlay.Stretch = Stretch.UniformToFill;
                    }
                    grid.Children.Add(overlay);
                    grid.UpdateLayout();
                }

                grid.Children.Add(textBlock);
                grid.UpdateLayout();

                BitmapLoader.Save2Jpg(
                    BitmapLoader.SaveImageSource(grid, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight), dest);
            }
            }
            catch (Exception ex)
            {
                Log.Error("Overlay Transform Plugin error ", ex);
            }
            return dest;
        }
Beispiel #31
0
 public AutoExportPluginConfig()
 {
     ConfigData = new ValuePairEnumerator();
     IsError    = false;
     IsRedy     = true;
 }
        public string ExecuteThread(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new OverlayTransformViewModel(configData);
            using (MagickImage image = new MagickImage(infile))
            {
                Gravity gravity = Gravity.Center;
                if (conf.A11)
                {
                    gravity = Gravity.Northwest;
                }
                if (conf.A12)
                {
                    gravity = Gravity.North;
                }
                if (conf.A13)
                {
                    gravity = Gravity.Northeast;
                }
                if (conf.A21)
                {
                    gravity = Gravity.West;
                }
                if (conf.A22)
                {
                    gravity = Gravity.Center;
                }
                if (conf.A23)
                {
                    gravity = Gravity.East;
                }
                if (conf.A31)
                {
                    gravity = Gravity.Southwest;
                }
                if (conf.A32)
                {
                    gravity = Gravity.South;
                }
                if (conf.A33)
                {
                    gravity = Gravity.Southeast;
                }


                if (File.Exists(conf.OverlayFile))
                {
                    // Read the watermark that will be put on top of the image
                    using (MagickImage watermark = new MagickImage(conf.OverlayFile))
                    {
                        if (conf.StrechOverlay)
                            watermark.Resize(image.Width, image.Height);
                        // Optionally make the watermark more transparent
                        if (conf.Transparency != 100)
                            watermark.Evaluate(Channels.Alpha, EvaluateOperator.Add,
                                -(255*(100 - conf.Transparency)/100));
                        // Draw the watermark in the bottom right corner
                        image.Composite(watermark, gravity, CompositeOperator.Over);

                        //// Optionally make the watermark more transparent
                        //watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 4);

                        //// Or draw the watermark at a specific location
                        //image.Composite(watermark, 200, 50, CompositeOperator.Over);
                    }
                }

                string text = "";
                if (!string.IsNullOrEmpty(conf.Text))
                {
                    Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
                    MatchCollection matchX = regPattern.Matches(conf.Text);
                    text = matchX.Cast<Match>()
                        .Aggregate(conf.Text,
                            (current1, match) =>
                                item.FileNameTemplates.Where(
                                    template =>
                                        String.Compare(template.Name, match.Value,
                                            StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1,
                                                (current, template) => current.Replace(match.Value, template.Value)));

                    image.Font = conf.Font;
                    image.FontPointsize = conf.FontSize;
                    Color color = (Color) ColorConverter.ConvertFromString(conf.FontColor);
                    image.FillColor = new MagickColor(color.R, color.G, color.B, color.A);
                    image.StrokeColor = new MagickColor(color.R, color.G, color.B, color.A);
                    image.Annotate(text, gravity);
                }
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }