protected override void InitDialogFromToken(EffectConfigToken effectTokenCopy)
        {
            SoftProofingConfigToken token = (SoftProofingConfigToken)effectTokenCopy;

            PushSuppressTokenUpdate();

            if (token.InputColorProfile != null)
            {
                this.inputProfile = token.InputColorProfile;
                this.inputProfileDescription.Text = this.inputProfile.Description;
            }

            if (token.DisplayColorProfile != null)
            {
                this.displayProfile = token.DisplayColorProfile;
                this.displayProfileDescription.Text = this.displayProfile.Description;
            }

            if (token.ProofingColorProfiles != null)
            {
                if (this.proofingColorProfiles.Count == 0)
                {
                    InitializeProfileListFromToken(token.ProofingColorProfiles);
                }

                if (token.ProofingProfileIndex >= 0)
                {
                    this.proofingProfilesCombo.SelectedIndex = token.ProofingProfileIndex + 1;
                }
            }

            this.displayIntentCombo.SelectedIndex  = (int)token.DisplayIntent;
            this.proofingIntentCombo.SelectedIndex = (int)token.ProofingIntent;
            this.gamutWarningCheckBox.Checked      = token.ShowGamutWarning;
            this.gamutWarningColorButton.Value     = token.GamutWarningColor;
            this.blackPointCheckBox.Checked        = token.BlackPointCompensation;

            PopSuppressTokenUpdate();
        }
        private bool SaveImage()
        {
            bool             result  = false;
            ColorProfileInfo profile = this.proofingProfileIndex >= 0 ? this.proofingColorProfiles[this.proofingProfileIndex] : this.inputProfile;

            if (CanSaveInColorSpace(profile.ColorSpace))
            {
                try
                {
                    if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
                    {
                        bool tiff = SaveFormatIsTIFF(this.saveFileDialog1.FileName);

                        using (SaveOptionsDialog optionsDialog = new SaveOptionsDialog(tiff, profile))
                        {
                            optionsDialog.BackColor = BackColor;
                            optionsDialog.ForeColor = ForeColor;

                            if (optionsDialog.ShowDialog(this) == DialogResult.OK)
                            {
                                SaveOptions options = optionsDialog.Options;

                                BitmapSource source = null;
                                Uri          destinationProfileUri = null;

                                if (profile.Equals(this.inputProfile))
                                {
                                    // No conversion is necessary when saving as the input color profile.
                                    source = GetBitmapSourceFromEffectSourceSurface(tiff, options);
                                    destinationProfileUri = new Uri(this.inputProfile.Path, UriKind.Absolute);
                                }
                                else
                                {
                                    // Convert the image to the destination color profile.
                                    PixelFormat     destinationPixelFormat = GetDestiniationPixelFormat(tiff, profile.ColorSpace);
                                    WriteableBitmap writable = new WriteableBitmap(
                                        this.EffectSourceSurface.Width,
                                        this.EffectSourceSurface.Height,
                                        options.HorizontalResolution,
                                        options.VerticalResolution,
                                        destinationPixelFormat,
                                        null
                                        );

                                    RenderingIntent destinationRenderingIntent = (RenderingIntent)this.proofingIntentCombo.SelectedIndex;

                                    ColorProfileHelper.ConvertToColorProfile(
                                        this.inputProfile.Path,
                                        profile.Path,
                                        destinationRenderingIntent,
                                        this.blackPointCheckBox.Checked,
                                        this.EffectSourceSurface,
                                        writable
                                        );

                                    source = writable;

                                    // Write a new profile with the selected rendering intent, if necessary.
                                    if (ColorProfileHelper.ChangeProfileRenderingIntent(profile.Path, destinationRenderingIntent, out this.destinationProfileTempPath))
                                    {
                                        destinationProfileUri = new Uri(this.destinationProfileTempPath, UriKind.Absolute);
                                    }
                                    else
                                    {
                                        destinationProfileUri = new Uri(profile.Path, UriKind.Absolute);
                                    }
                                }

                                BitmapEncoder encoder;
                                if (tiff)
                                {
                                    TIFFSaveOptions tiffOptions = (TIFFSaveOptions)options;
                                    encoder = new TiffBitmapEncoder()
                                    {
                                        Compression = tiffOptions.LZWCompression ? TiffCompressOption.Lzw : TiffCompressOption.None
                                    };
                                }
                                else
                                {
                                    JPEGSaveOptions jpegOptions = (JPEGSaveOptions)options;
                                    encoder = new JpegBitmapEncoder()
                                    {
                                        QualityLevel = jpegOptions.Quality,
                                    };
                                }

                                ColorContext[] colorContexts = new ColorContext[] { new ColorContext(destinationProfileUri) };

                                encoder.Frames.Add(BitmapFrame.Create(source, null, null, Array.AsReadOnly(colorContexts)));

                                using (FileStream stream = new FileStream(this.saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                                {
                                    encoder.Save(stream);
                                }

                                result = true;
                            }
                        }
                    }
                }
                catch (IOException ex)
                {
                    ShowErrorMessage(ex.Message);
                }
                catch (LCMSException ex)
                {
                    ShowErrorMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    ShowErrorMessage(ex.Message);
                }
                catch (UnauthorizedAccessException ex)
                {
                    ShowErrorMessage(ex.Message);
                }
            }

            return(result);
        }