Exemplo n.º 1
0
 /// <summary>
 /// Raises the ImageProcessingCommandFinished event.
 /// </summary>
 /// <param name="command">Executed command.</param>
 /// <param name="e">The <see cref="ImageProcessedEventArgs"/> instance containing the event data.</param>
 void OnImageProcessingCommandFinished(ProcessingCommandBase command, ImageProcessedEventArgs e)
 {
     if (ImageProcessingCommandFinished != null)
     {
         ImageProcessingCommandFinished(command, e);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Raises the ImageProcessingCommandStarted event.
 /// </summary>
 /// <param name="command">Executing command.</param>
 /// <param name="e">The <see cref="ImageProcessingEventArgs"/> instance containing the event data.</param>
 void OnImageProcessingCommandStarted(ProcessingCommandBase command, ImageProcessingEventArgs e)
 {
     if (ImageProcessingCommandStarted != null)
     {
         ImageProcessingCommandStarted(command, e);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Raises the ImageProcessingCommandProgress event.
 /// </summary>
 /// <param name="command">Executing command.</param>
 /// <param name="e">The <see cref="ImageProcessingProgressEventArgs"/> instance containing the event data.</param>
 void OnImageProcessingCommandProgress(ProcessingCommandBase command, ImageProcessingProgressEventArgs e)
 {
     if (ImageProcessingCommandProgress != null)
     {
         ImageProcessingCommandProgress(command, e);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether specified processing command can process the specified image.
        /// </summary>
        /// <param name="command">Image processing command.</param>
        /// <param name="image">Image to process.</param>
        /// <returns>
        /// <b>true</b> - processing command can process image;
        /// otherwise, <b>false</b>.
        /// </returns>
        private bool CommandCanProcessImage(ProcessingCommandBase command, VintasoftImage image)
        {
            bool needConvertToSupportedPixelFormat = command.ExpandSupportedPixelFormats;

            command.ExpandSupportedPixelFormats = ExpandSupportedPixelFormats;
            PixelFormat outputPixelFormat = command.GetOutputPixelFormat(image);

            command.ExpandSupportedPixelFormats = needConvertToSupportedPixelFormat;

            if (outputPixelFormat != PixelFormat.Undefined)
            {
                return(true);
            }

            System.Text.StringBuilder        sb      = new System.Text.StringBuilder();
            ReadOnlyCollection <PixelFormat> formats = command.SupportedPixelFormats;

            for (int i = 0; i < formats.Count; i++)
            {
                sb.Append(" -");
                sb.Append(formats[i].ToString());
                sb.AppendLine(";");
            }
            string supportedPixelFormatNames = sb.ToString();

            string message = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "{0}: unsupported pixel format - {1}.\n\nProcessing command supports only the following pixel formats:\n{2}\nPlease convert the image to supported pixel format first.",
                command.Name,
                image.PixelFormat,
                supportedPixelFormatNames);

            DemosTools.ShowErrorMessage("Image processing exception", message);
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handler of the ProcessingCommandBase.Started event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ImageProcessingEventArgs"/> instance containing the event data.</param>
        void command_Started(object sender, ImageProcessingEventArgs e)
        {
            ProcessingCommandBase command = (ProcessingCommandBase)sender;

            command.Started -= new EventHandler <ImageProcessingEventArgs>(command_Started);

            OnImageProcessingCommandStarted((ProcessingCommandBase)sender, e);
        }
        /// <summary>
        /// Executes the processing command.
        /// </summary>
        protected virtual void ExecuteProcessing()
        {
            ProcessingCommandBase command = GetProcessingCommand();

            if (command != null)
            {
                _imageProcessingPreviewInViewer.SetCommand(command);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Builds the proccessing command to process current captured frame.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void ChangeProcessingCommandHandler(object sender, EventArgs e)
        {
            List <ProcessingCommandBase> commands = new List <ProcessingCommandBase>();

            // Invert
            switch (invertComboBox.SelectedIndex)
            {
            case 1:
                commands.Add(new InvertCommand());
                break;

            case 2:
                commands.Add(new ColorBlendCommand(BlendingMode.Difference, Color.FromArgb(255, 0, 0)));
                break;

            case 3:
                commands.Add(new ColorBlendCommand(BlendingMode.Difference, Color.FromArgb(0, 255, 0)));
                break;

            case 4:
                commands.Add(new ColorBlendCommand(BlendingMode.Difference, Color.FromArgb(0, 0, 255)));
                break;
            }

            // Grayscale
            if (grayscaleCheckBox.Checked)
            {
                commands.Add(new ChangePixelFormatToGrayscaleCommand(PixelFormat.Gray8));
            }

            // Rotate
            int rotate;

            if (int.TryParse(rotateComboBox.Text, out rotate))
            {
                if (rotate != 0)
                {
                    RotateCommand rotateCommand = new RotateCommand(rotate);
                    rotateCommand.BorderColorType = BorderColorType.Black;
                    commands.Add(rotateCommand);
                }
            }

            if (commands.Count == 0)
            {
                _processingCommand = null;
            }
            else if (commands.Count == 1)
            {
                _processingCommand = commands[0];
            }
            else
            {
                _processingCommand = new CompositeCommand(commands.ToArray());
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyGridConfigForm"/> class.
        /// </summary>
        /// <param name="viewer">The image viewer for image preview.</param>
        /// <param name="command">Image processing command.</param>
        public PropertyGridConfigForm(ImageViewer viewer, ProcessingCommandBase command)
            : base(viewer)
        {
            InitializeComponent();

            _command = command;

            Text = command.Name;

            propertyGrid1.SelectedObject = command;

            previewCheckBox.Checked = IsPreviewEnabled;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handler of the ProcessingCommandBase.Finished event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ImageProcessedEventArgs"/> instance containing the event data.</param>
        void command_Finished(object sender, ImageProcessedEventArgs e)
        {
            ProcessingCommandBase command = (ProcessingCommandBase)sender;

            command.Finished -= new EventHandler <ImageProcessedEventArgs>(command_Finished);

            if (command is ParallelizingProcessingCommand)
            {
                command = ((ParallelizingProcessingCommand)command).ProcessingCommand;
            }

            if (command is OverlayCommand ||
                command is OverlayWithBlendingCommand ||
                command is OverlayMaskedCommand)
            {
                if (_overlayImage != null)
                {
                    // dispose the temporary overlay image because the processing command is finished
                    _overlayImage.Dispose();
                    _overlayImage = null;
                }
                if (_maskImage != null)
                {
                    // dispose the temporary mask image because the processing command is finished
                    _maskImage.Dispose();
                    _maskImage = null;
                }
            }

            if (command is ImageComparisonCommand)
            {
                if (_comparisonImage != null)
                {
                    _comparisonImage.Dispose();
                    _comparisonImage = null;
                }
            }

            _isImageProcessingWorking = false;

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

            OnImageProcessingCommandFinished((ProcessingCommandBase)sender, e);
        }
        /// <summary>
        /// Sets the current image processing command.
        /// </summary>
        /// <param name="command">The processing command.</param>
        public void SetCommand(ProcessingCommandBase command)
        {
            if (_isPreviewStarted)
            {
                if (command != null)
                {
                    command.ExpandSupportedPixelFormats = ExpandSupportedPixelFormats;
                }

                if (_viewer.VisualTool is CustomSelectionTool)
                {
                    CustomSelectionTool selectionTool = (CustomSelectionTool)_viewer.VisualTool;
                    _processedSelectionRegionView.ProcessingCommand = command;
                    selectionTool.InvalidateItem(selectionTool.Selection);
                }
                else
                {
                    _rectangularPreview.ProcessingCommand = command;
                }
            }
        }
Exemplo n.º 11
0
 private void ExecuteCommand(ProcessingCommandBase command, VintasoftImage image)
 {
     command.Progress += new EventHandler <ImageProcessingProgressEventArgs>(command_Progress);
     command.ExecuteInPlace(image);
     command.Progress -= new EventHandler <ImageProcessingProgressEventArgs>(command_Progress);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessingCommandTask"/> class.
 /// </summary>
 /// <param name="command">Image processing command to execute.</param>
 /// <param name="image">Image to process.</param>
 public ProcessingCommandTask(ProcessingCommandBase command, VintasoftImage image)
 {
     _command = command;
     _image   = image;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Executes image processing command synchronously or asynchronously.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <param name="async">A value indicating whether to execute command asynchronously.</param>
        public bool ExecuteProcessingCommand(ProcessingCommandBase command, bool async)
        {
            RectangularSelectionToolWithCopyPaste rectSelectionTool = CompositeVisualTool.FindVisualTool <RectangularSelectionToolWithCopyPaste>(_viewer.VisualTool);
            CustomSelectionTool customSelectionTool = CompositeVisualTool.FindVisualTool <CustomSelectionTool>(_viewer.VisualTool);

            if (rectSelectionTool != null)
            {
                // set the region of interest
                Rectangle selectionRectangle = ViewerSelectionRectangle;
                ProcessingCommandWithRegion commandWorkWithRegion = command as ProcessingCommandWithRegion;
                if (commandWorkWithRegion != null)
                {
                    commandWorkWithRegion.RegionOfInterest = new RegionOfInterest(selectionRectangle.Left, selectionRectangle.Top, selectionRectangle.Width, selectionRectangle.Height);
                }
                else if (command is DrawImageCommand)
                {
                    ((DrawImageCommand)command).DestRect = selectionRectangle;
                }
                else if (!selectionRectangle.IsEmpty)
                {
                    MessageBox.Show("Selected image processing command cannot work with regions. Entire image will be processed.",
                                    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (customSelectionTool != null)
            {
                RectangleF selectionBBox = RectangleF.Empty;
                if (customSelectionTool.Selection != null)
                {
                    selectionBBox = customSelectionTool.Selection.GetBoundingBox();
                }
                if (selectionBBox.Width >= 1 && selectionBBox.Height >= 1)
                {
                    if (command is ChangePixelFormatCommand ||
                        command is ChangePixelFormatToBgrCommand ||
                        command is ChangePixelFormatToBlackWhiteCommand ||
                        command is ChangePixelFormatToGrayscaleCommand ||
                        command is ChangePixelFormatToPaletteCommand ||
                        command is RotateCommand ||
                        command is ResampleCommand ||
                        command is ResizeCommand ||
                        !command.CanModifyImage)
                    {
                        MessageBox.Show("Selected image processing command cannot work with custom selection. Entire image will be processed.",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        GraphicsPath path       = customSelectionTool.Selection.GetAsGraphicsPath();
                        RectangleF   pathBounds = path.GetBounds();
                        if (pathBounds.Width > 0 && pathBounds.Height > 0)
                        {
                            if (command is CropCommand)
                            {
                                // crop to custom selection
                                command = GetCropToPathCommand(path, pathBounds, (CropCommand)command);
                                // clear selection
                                customSelectionTool.Selection = null;
                            }
                            else
                            {
                                // process path
                                command = new ProcessPathCommand(command, path);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Selected path is empty.",
                                            "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return(false);
                        }
                    }
                }
            }

            // get a reference to the image for processing
            VintasoftImage imageToProcess = _viewer.Image;

            ProcessingCommandBase executeCommand = command;

            if (_executeMultithread)
            {
                ParallelizingProcessingCommand parallelizingCommand = new ParallelizingProcessingCommand(command);
                if (command is ProcessingCommandWithRegion)
                {
                    parallelizingCommand.RegionOfInterest = ((ProcessingCommandWithRegion)command).RegionOfInterest;
                }
                executeCommand = parallelizingCommand;
            }

            if (UndoManager != null)
            {
                _imageProcessingUndoMonitor = new ImageProcessingUndoMonitor(UndoManager, executeCommand);
            }

            // subscribe to the events of the image processing command
            executeCommand.Started  += new EventHandler <ImageProcessingEventArgs>(command_Started);
            executeCommand.Progress += new EventHandler <ImageProcessingProgressEventArgs>(command_Progress);
            executeCommand.Finished += new EventHandler <ImageProcessedEventArgs>(command_Finished);

            executeCommand.ExpandSupportedPixelFormats = ExpandSupportedPixelFormats;
            executeCommand.RestoreSourcePixelFormat    = false;

            // specify that image processing command is working (several commands cannot work together)
            _isImageProcessingWorking = true;
            // get the start time of the image processing command
            _processingCommandStartTime = DateTime.Now;

            // if image processing command should be executed asynchronously
            if (async)
            {
                // start the image processing command asynchronously
                ProcessingCommandTask executor = new ProcessingCommandTask(executeCommand, imageToProcess);
                executor.ImageProcessingExceptionOccurs += new EventHandler(executor_ImageProcessingExceptionOccurs);
                Thread thread = new Thread(executor.Execute);
                thread.IsBackground = true;
                thread.Start();
            }
            // if image processing command should be executed synchronously
            else
            {
                try
                {
                    // execute the image processing command synchronously
                    executeCommand.ExecuteInPlace(imageToProcess);
                }
                catch (Exception ex)
                {
                    executor_ImageProcessingExceptionOccurs(this, EventArgs.Empty);
                    DemosTools.ShowErrorMessage(ex);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Executes image processing command asynchronously.
 /// </summary>
 /// <param name="command">Command to execute.</param>
 public void ExecuteProcessingCommand(ProcessingCommandBase command)
 {
     ExecuteProcessingCommand(command, true);
 }