Exemple #1
0
        protected override void DoProcess()
        {
            mUpdatePending = false;
            if (SourceImage != null)
            {
                try
                {
                    SetUIState(UIState.Processing);

                    CancelProcessingPending = false;

                    if (mProcessImageDuringUpdate)
                    {
                        // Checking if the stage is frozen or not and is there a frozen image.
                        if (FrozenAt == null || mFrozenImage == null)
                        {
                            CurrentImage = (IBitmapCore)SourceImage.Clone();

                            if (mZoomAfterPrescaleValue < 0.999 || mZoomAfterPrescaleValue > 1.001)
                            {
                                CurrentImage.ScaleFast(mZoomAfterPrescaleValue, delegate(double progress) {
                                    OnProgressMessageReport(true, progress, "Applying zoom (downscaling)...", false);
                                    return(!CancelProcessingPending);
                                });
                            }
                            if (ImageChanged != null)
                            {
                                ImageChanged(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            CurrentImage = (IBitmapCore)mFrozenImage.Clone();
                            if (ImageChanged != null)
                            {
                                ImageChanged(this, EventArgs.Empty);
                            }
                        }

                        // Making the list of stage operations to apply
                        List <StageOperation> operationsToApply = new List <StageOperation>();
                        List <double>         efforts           = new List <double>();
                        double full_efforts = 0;

                        int start_index = 0;
                        if (FrozenAt != null && mFrozenImage != null)
                        {
                            start_index = StageQueue.IndexOf(FrozenAt) + 1;
                        }

                        for (int i = start_index; i < StageQueue.Count; i++)
                        {
                            if (StageQueue[i] != _EditingOperation)
                            {
                                // Don't add inactives
                                if (StageQueue[i].Active == false)
                                {
                                    continue;
                                }

                                StageOperation newOperation = CallStageOperationFactory(StageQueue[i]);
                                operationsToApply.Add(newOperation);
                                efforts.Add(newOperation.CalculateEfforts(CurrentImage));
                                full_efforts += efforts[efforts.Count - 1];

                                newOperation.ReportProgress += delegate(object sender, ReportStageOperationProgressEventArgs e) {
                                    double cur_eff = 0;
                                    int    j       = 0;
                                    while (operationsToApply[j] != (StageOperation)sender)
                                    {
                                        cur_eff += efforts[j];
                                        j++;
                                    }
                                    cur_eff += e.Progress * efforts[j];
                                    string desc = StageOperationDescriptionAttribute.GetName(sender.GetType());

                                    OnProgressMessageReport(true,
                                                            cur_eff / full_efforts,
                                                            "" + (j + 1) + " of " + efforts.Count + ": " + desc + "...", true);

                                    if (CancelProcessingPending)
                                    {
                                        e.Cancel = true;
                                    }
                                };
                            }
                            else
                            {
                                break;
                            }
                        }

                        // Executing
                        for (int k = 0; k < operationsToApply.Count; k++)
                        {
                            Console.WriteLine("AnalyzeImage Calling for " + operationsToApply[k].GetType().Name);
                            _Holders[operationsToApply[k].Parameters].StageOperationParametersEditor.AnalyzeImage(CurrentImage);
                            operationsToApply[k].OnDo(CurrentImage);
                            if (operationsToApply[k].Parameters == FrozenAt)
                            {
                                // After the frozen line is reached,
                                // setting the current frozen image
                                mFrozenImage = (IBitmapCore)CurrentImage.Clone();
                            }
                        }
                    }

                    if (_EditingOperation != null)
                    {
                        Console.WriteLine("AnalyzeImage Calling for " + _EditingOperation.GetType().Name);
                        _Holders[_EditingOperation].StageOperationParametersEditor.AnalyzeImage(CurrentImage);
                    }

                    OnImageUpdatingCompleted();
                    SetUIState(UIState.Idle);
                }
                catch (UserCancelException)
                {
                    // The user cancelled processing.
                    // Setting to idle state
                    SetUIState(UIState.Idle);
                    // Unset cancelling flag.
                    AskUpdate();
                }
            }
        }
Exemple #2
0
        protected virtual void DoProcess()
        {
            if (mSourceImage != null)
            {
                try
                {
                    mCancelProcessingPending = false;

                    mCurrentImage = (IBitmapCore)mSourceImage.Clone();

                    // Making the list of stage operations to apply
                    List <StageOperation> operationsToApply = new List <StageOperation>();
                    List <double>         efforts           = new List <double>();
                    double full_efforts = 0;

                    for (int i = 0; i < mStageQueue.Count; i++)
                    {
                        // Don't add inactives
                        if (mStageQueue[i].Active == false)
                        {
                            continue;
                        }

                        StageOperation newOperation = CallStageOperationFactory(mStageQueue[i]);
                        operationsToApply.Add(newOperation);
                        efforts.Add(newOperation.CalculateEfforts(mCurrentImage));
                        full_efforts += efforts[efforts.Count - 1];

                        newOperation.ReportProgress += delegate(object sender, ReportStageOperationProgressEventArgs e) {
                            double cur_eff = 0;
                            int    j       = 0;
                            while (operationsToApply[j] != (StageOperation)sender)
                            {
                                cur_eff += efforts[j];
                                j++;
                            }
                            cur_eff += e.Progress * efforts[j];
                            string desc = StageOperationDescriptionAttribute.GetName(sender.GetType());

                            OnProgressMessageReport(true,
                                                    cur_eff / full_efforts,
                                                    "" + (j + 1) + " of " + efforts.Count + ": " + desc + "...", true);

                            if (mCancelProcessingPending)
                            {
                                e.Cancel = true;
                            }
                        };
                    }

                    // Executing
                    for (int k = 0; k < operationsToApply.Count; k++)
                    {
                        operationsToApply[k].OnDo(mCurrentImage);
                    }
                    OnImageUpdatingCompleted();
                }
                catch (UserCancelException ex)
                {
                    throw ex;
                }
            }
        }