public void Save(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback, bool rememberToken) { using (Surface scratch = new Surface(input.Width, input.Height)) { Save(input, output, token, callback, rememberToken); } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp); EncoderParameters parms = new EncoderParameters(1); EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24); // BMP's should always save as 24-bit parms.Param[0] = parm; scratchSurface.Clear(ColorBgra.White); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } // In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place // instead of allocating a new bitmap and copying it over. SquishSurfaceTo24Bpp(scratchSurface); using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface)) { GdiPlusFileType.LoadProperties(bitmap, input); bitmap.Save(output, icf, parms); } }
protected override void InitWidgetFromToken(SaveConfigToken token) { if (token is DdsSaveConfigToken) { DdsSaveConfigToken ddsToken = (DdsSaveConfigToken)token; this.fileFormatList.SelectedIndex = ( int )ddsToken.m_fileFormat; this.clusterFit.Checked = ( ddsToken.m_compressorType == 0 ); this.rangeFit.Checked = ( ddsToken.m_compressorType == 1 ); this.iterativeFit.Checked = ( ddsToken.m_compressorType == 2 ); this.perceptualMetric.Checked = ( ddsToken.m_errorMetric == 0 ); this.uniformMetric.Checked = !this.perceptualMetric.Checked; this.weightColourByAlpha.Checked = ddsToken.m_weightColourByAlpha; this.generateMipMaps.Checked = ddsToken.m_generateMipMaps; } else { this.fileFormatList.SelectedIndex = 0; this.clusterFit.Checked = true; this.rangeFit.Checked = false; this.iterativeFit.Checked = false; this.perceptualMetric.Checked = true; this.uniformMetric.Checked = false; this.weightColourByAlpha.Checked = false; this.generateMipMaps.Checked = false; } }
/// <summary> /// Because the old OnSave() method is obsolete, we must use reflection to call it. /// This is important for legacy FileType plugins. It allows us to ensure that no /// new plugins can be compiled using the old OnSave() overload. /// </summary> private void OldOnSaveTrampoline(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback) { MethodInfo onSave = GetType().GetMethod( "OnSave", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy, Type.DefaultBinder, new Type[] { typeof(Document), typeof(Stream), typeof(SaveConfigToken), typeof(ProgressEventHandler) }, null); onSave.Invoke( this, new object[] { input, output, token, callback }); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { RenderArgs ra = new RenderArgs(new Surface(input.Size)); input.Render(ra); ra.Bitmap.Save(output, ImageFormat.Bmp); }
public void Save(Stream dstStream, Document srcDocument, FileType dstFileType, SaveConfigToken parameters, Surface saveScratchSurface) { this.document = srcDocument; this.fileType = dstFileType; this.stream = dstStream; this.saveConfigToken = parameters; this.scratchSurface = saveScratchSurface; DialogResult dr = this.ShowDialog(false, !dstFileType.SavesWithProgress , new ThreadStart(SaveCallback)); }
public void Save(Stream dstStream, Document srcDocument, FileType dstFileType, SaveConfigToken parameters, Surface saveScratchSurface) { this.document = srcDocument; this.fileType = dstFileType; this.stream = dstStream; this.saveConfigToken = parameters; this.scratchSurface = saveScratchSurface; DialogResult dr = this.ShowDialog(false, !dstFileType.SavesWithProgress, new ThreadStart(SaveCallback)); }
protected override void OnLoad(EventArgs e) { if (this.scratchSurface == null) { ExceptionUtil.ThrowInvalidOperationException("ScratchSurface was never set: it is null"); } PaintDotNet.SaveConfigToken saveConfigToken = this.SaveConfigToken; this.LoadPositions(); this.SaveConfigToken = saveConfigToken; base.OnLoad(e); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { if (callback == null) { input.SaveToStream(output); } else { UpdateProgressTranslator upt = new UpdateProgressTranslator(ApproximateMaxOutputOffset(input), callback); input.SaveToStream(output, new IOEventHandler(upt.IOEventHandler)); } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback) { GifSaveConfigToken gsct = (GifSaveConfigToken)token; // Flatten and pre-process the image scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0)); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } for (int y = 0; y < scratchSurface.Height; ++y) { unsafe { ColorBgra* ptr = scratchSurface.GetRowAddressUnchecked(y); for (int x = 0; x < scratchSurface.Width; ++x) { if (ptr->A < gsct.Threshold) { ptr->Bgra = 0; } else { if (gsct.PreMultiplyAlpha) { int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255; int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255; int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255; int a = 255; *ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a); } else { ptr->Bgra |= 0xff000000; } } ++ptr; } } } using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback)) { quantized.Save(output, ImageFormat.Gif); } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback) { GifSaveConfigToken gsct = (GifSaveConfigToken)token; // Flatten and pre-process the image scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0)); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } for (int y = 0; y < scratchSurface.Height; ++y) { unsafe { ColorBgra *ptr = scratchSurface.GetRowAddressUnchecked(y); for (int x = 0; x < scratchSurface.Width; ++x) { if (ptr->A < gsct.Threshold) { ptr->Bgra = 0; } else { if (gsct.PreMultiplyAlpha) { int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255; int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255; int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255; int a = 255; *ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a); } else { ptr->Bgra |= 0xff000000; } } ++ptr; } } } using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback)) { quantized.Save(output, ImageFormat.Gif); } }
public SaveConfigToken GetLastSaveConfigToken() { Type ourType = this.GetType(); string savedTokenName = "SaveConfigToken." + ourType.Namespace + "." + ourType.Name + ".BinaryFormatter"; string savedToken = Settings.CurrentUser.GetString(savedTokenName, null); SaveConfigToken saveConfigToken = null; if (savedToken != null) { try { byte[] bytes = Convert.FromBase64String(savedToken); MemoryStream ms = new MemoryStream(bytes); BinaryFormatter formatter = new BinaryFormatter(); DeferredFormatter deferred = new DeferredFormatter(); StreamingContext streamingContext = new StreamingContext(formatter.Context.State, deferred); formatter.Context = streamingContext; SerializationFallbackBinder sfb = new SerializationFallbackBinder(); sfb.AddAssembly(this.GetType().Assembly); sfb.AddAssembly(typeof(FileType).Assembly); formatter.Binder = sfb; object obj = formatter.Deserialize(ms); deferred.FinishDeserialization(ms); ms.Close(); ms = null; //SaveConfigToken sct = new SaveConfigToken(); //saveConfigToken = (SaveConfigToken)obj; saveConfigToken = GetSaveConfigTokenFromSerializablePortion(obj); } catch (Exception) { // Ignore erros and revert to default saveConfigToken = null; } } if (saveConfigToken == null) { saveConfigToken = CreateDefaultSaveConfigToken(); } return(saveConfigToken); }
protected override unsafe void OnSave( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback ) { DdsSaveConfigToken ddsToken = ( DdsSaveConfigToken )token; // We need to be able to feast on the goo inside.. scratchSurface.Clear( ColorBgra.Transparent ); using ( RenderArgs ra = new RenderArgs( scratchSurface ) ) { input.Render( ra, true ); } // Create the DDS file, and save it.. DdsFile ddsFile = new DdsFile(); ddsFile.Save( output, scratchSurface, ddsToken, callback ); }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { JpegSaveConfigToken jsct = (JpegSaveConfigToken)token; ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg); EncoderParameters parms = new EncoderParameters(1); EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality' parms.Param[0] = parm; scratchSurface.Clear(ColorBgra.White); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap()) { GdiPlusFileType.LoadProperties(bitmap, input); bitmap.Save(output, icf, parms); } }
public SaveConfigToken GetLastSaveConfigToken() { Type ourType = this.GetType(); string savedTokenName = ourType.Namespace + "." + ourType.Name; string savedToken = Settings.CurrentUser.GetString(savedTokenName, null); SaveConfigToken saveConfigToken = null; if (savedToken != null) { try { SoapFormatter soap = new SoapFormatter(); byte[] bytes = Encoding.UTF8.GetBytes(savedToken); MemoryStream ms = new MemoryStream(bytes); SerializationFallbackBinder sfb = new SerializationFallbackBinder(); sfb.AddAssembly(this.GetType().Assembly); sfb.AddAssembly(typeof(FileType).Assembly); soap.Binder = sfb; object obj = soap.Deserialize(ms); ms.Close(); SaveConfigToken sct = new SaveConfigToken(); saveConfigToken = (SaveConfigToken)obj; } catch { // Ignore erros and revert to default saveConfigToken = null; } } if (saveConfigToken == null) { saveConfigToken = CreateDefaultSaveConfigToken(); } return(saveConfigToken); }
protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { throw new OnSaveNotImplementedException("Derived classes must implement this method. It is virtual instead of abstract in order to maintain compatibility with legacy plugins."); }
protected virtual object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token) { return token; }
/// <summary> /// Determines if saving with a given SaveConfigToken would alter the image /// in any way. Put another way, if the document is saved with these settings /// and then immediately loaded, would it have exactly the same pixel values? /// Any lossy codec should return 'false'. /// This value is used to optimizing preview rendering memory usage, and as such /// flattening should not be taken in to consideration. For example, the codec /// for PNG returns true, even though it flattens the image. /// </summary> /// <param name="token">The SaveConfigToken to determine reflexiveness for.</param> /// <returns>true if the save would be reflexive, false if not</returns> /// <remarks>If the SaveConfigToken is for another FileType, the result is undefined.</remarks> public virtual bool IsReflexive(SaveConfigToken token) { return false; }
public void Save( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback, bool rememberToken) { if (!this.SupportsSaving) { throw new NotImplementedException("Saving is not supported by this FileType"); } else { Surface disposeMe = null; if (scratchSurface == null) { disposeMe = new Surface(input.Size); scratchSurface = disposeMe; } else if (scratchSurface.Size != input.Size) { throw new ArgumentException("scratchSurface.Size must equal input.Size"); } if (rememberToken) { Type ourType = this.GetType(); string savedTokenName = ourType.Namespace + "." + ourType.Name; SoapFormatter soap = new SoapFormatter(); MemoryStream ms = new MemoryStream(); soap.Serialize(ms, token); byte[] bytes = ms.GetBuffer(); string utf8 = Encoding.UTF8.GetString(bytes); Settings.CurrentUser.SetString(savedTokenName, utf8); } if (!this.SavesWithProgress) { try { OnSave(input, output, token, scratchSurface, null); } catch (OnSaveNotImplementedException) { OldOnSaveTrampoline(input, output, token, null); } } else { try { OnSave(input, output, token, scratchSurface, callback); } catch (OnSaveNotImplementedException) { OldOnSaveTrampoline(input, output, token, callback); } } if (disposeMe != null) { disposeMe.Dispose(); disposeMe = null; } } }
protected override void InitWidgetFromToken(SaveConfigToken token) { TgaSaveConfigToken tgaToken = (TgaSaveConfigToken)token; if (tgaToken.BitDepth == 24) { this.bpp24Radio.Checked = true; this.bpp32Radio.Checked = false; } else { this.bpp24Radio.Checked = false; this.bpp32Radio.Checked = true; } this.rleCompressCheckBox.Checked = tgaToken.RleCompress; }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { GdiPlusFileType.Save(input, output, scratchSurface, this.ImageFormat, callback); }
protected override sealed void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { OnSaveT(input, output, (TToken)token, scratchSurface, callback); }
/// <summary> /// Determines if saving with a given SaveConfigToken would alter the image /// in any way. Put another way, if the document is saved with these settings /// and then immediately loaded, would it have exactly the same pixel values? /// Any lossy codec should return 'false'. /// This value is used to optimizing preview rendering memory usage, and as such /// flattening should not be taken in to consideration. For example, the codec /// for PNG returns true, even though it flattens the image. /// </summary> /// <param name="token">The SaveConfigToken to determine reflexiveness for.</param> /// <returns>true if the save would be reflexive, false if not</returns> /// <remarks>If the SaveConfigToken is for another FileType, the result is undefined.</remarks> public virtual bool IsReflexive(SaveConfigToken token) { return(false); }
protected override sealed object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token) { return(GetSerializablePortionOfSaveConfigToken((TToken)token)); }
/// <summary> /// This method must be overridden in derived classes. /// In this method you must take the values from the given EffectToken /// and use them to properly initialize the dialog's user interface elements. /// </summary> protected virtual void InitWidgetFromToken(SaveConfigToken sourceToken) { //throw new InvalidOperationException("InitWidgetFromToken was not implemented, or the derived method called the base method"); }
public override bool IsReflexive(SaveConfigToken token) { if (((TgaSaveConfigToken)token).BitDepth == 32) { return true; } else { return base.IsReflexive(token); } }
protected override void InitWidgetFromToken(SaveConfigToken token) { this.thresholdSlider.Value = ((GifSaveConfigToken)token).Threshold; this.ditherSlider.Value = ((GifSaveConfigToken)token).DitherLevel; this.preMultiplyAlphaCheckBox.Checked = ((GifSaveConfigToken)token).PreMultiplyAlpha; }
protected virtual object GetSerializablePortionOfSaveConfigToken(SaveConfigToken token) { return(token); }
/// <summary> /// Sets the FileType and SaveConfigToken parameters that are used if the /// user chooses "Save" from the File menu. These are not used by the /// DocumentControl class and should be used by whoever actually goes /// to save the Document instance. /// </summary> /// <param name="fileType"></param> /// <param name="saveParameters"></param> public void SetDocumentSaveOptions(string newFilePath, FileType newFileType, SaveConfigToken newSaveConfigToken) { this.filePath = newFilePath; OnFilePathChanged(); this.fileType = newFileType; if (newSaveConfigToken == null) { this.saveConfigToken = null; } else { this.saveConfigToken = (SaveConfigToken)newSaveConfigToken.Clone(); } OnSaveOptionsChanged(); }
protected virtual void OnSave(Document input, Stream output, SaveConfigToken token, ProgressEventHandler callback) { }
public override bool IsReflexive(SaveConfigToken token) { return false; }
private void SaveTga(Surface input, Stream output, SaveConfigToken token, ProgressEventHandler progressCallback) { TgaSaveConfigToken tgaToken = (TgaSaveConfigToken)token; TgaHeader header = new TgaHeader(); header.idLength = 0; header.cmapType = 0; header.imageType = tgaToken.RleCompress ? TgaType.RleRgb : TgaType.Rgb; header.cmapIndex = 0; header.cmapLength = 0; header.cmapEntrySize = 0; // if bpp=8, set this to 24 header.xOrigin = 0; header.yOrigin = 0; header.imageWidth = (ushort)input.Width; header.imageHeight = (ushort)input.Height; header.pixelDepth = (byte)tgaToken.BitDepth; header.imageDesc = 0; header.Write(output); // write palette if doing 8-bit // ... todo? for (int y = input.Height - 1; y >= 0; --y) { // non-rle output if (tgaToken.RleCompress) { SaveTgaRowRle(output, input, ref header, y); } else { SaveTgaRowRaw(output, input, ref header, y); } if (progressCallback != null) { progressCallback(this, new ProgressEventArgs(100.0 * ((double)(input.Height - y) / (double)input.Height))); } } }
public override sealed bool IsReflexive(SaveConfigToken token) { return(IsReflexive((TToken)token)); }
protected SaveConfigToken(SaveConfigToken copyMe) { }
/// <summary> /// Used to set the file name, file type, and save config token /// </summary> /// <param name="newFileName"></param> /// <param name="newFileType"></param> /// <param name="newSaveConfigToken"></param> /// <returns>true if the user clicked through and accepted, or false if they cancelled at any point</returns> private bool DoSaveAsDialog( out string newFileName, out FileType newFileType, out SaveConfigToken newSaveConfigToken, Surface saveScratchSurface) { FileTypeCollection fileTypes = FileTypes.GetFileTypes(); using (IFileSaveDialog sfd = SystemLayer.CommonDialogs.CreateFileSaveDialog()) { sfd.AddExtension = true; sfd.CheckPathExists = true; sfd.OverwritePrompt = true; string filter = fileTypes.ToString(false, null, true, false); sfd.Filter = filter; string localFileName; FileType localFileType; SaveConfigToken localSaveConfigToken; GetDocumentSaveOptions(out localFileName, out localFileType, out localSaveConfigToken); if (Document.Layers.Count > 1 && localFileType != null && !localFileType.SupportsLayers) { localFileType = null; } if (localFileType == null) { if (Document.Layers.Count == 1) { localFileType = PdnFileTypes.Png; } else { localFileType = PdnFileTypes.Pdn; } localFileName = Path.ChangeExtension(localFileName, localFileType.DefaultExtension); } if (localFileName == null) { string name = GetDefaultSaveName(); string newName = Path.ChangeExtension(name, localFileType.DefaultExtension); localFileName = Path.Combine(GetDefaultSavePath(), newName); } // If the filename is only an extension (i.e. ".lmnop") then we must treat it specially string fileNameOnly = Path.GetFileName(localFileName); if (fileNameOnly.Length >= 1 && fileNameOnly[0] == '.') { sfd.FileName = localFileName; } else { sfd.FileName = Path.ChangeExtension(localFileName, null); } sfd.FilterIndex = 1 + fileTypes.IndexOfFileType(localFileType); sfd.InitialDirectory = Path.GetDirectoryName(localFileName); sfd.Title = PdnResources.GetString("SaveAsDialog.Title"); DialogResult dr1 = ShowFileDialog(this, sfd); bool result; if (dr1 != DialogResult.OK) { result = false; } else { localFileName = sfd.FileName; FileType fileType2 = fileTypes[sfd.FilterIndex - 1]; result = GetSaveConfigToken(fileType2, localSaveConfigToken, out localSaveConfigToken, saveScratchSurface); localFileType = fileType2; } if (result) { newFileName = localFileName; newFileType = localFileType; newSaveConfigToken = localSaveConfigToken; } else { newFileName = null; newFileType = null; newSaveConfigToken = null; } return result; } }
public SaveConfigToken GetLastSaveConfigToken() { Type ourType = this.GetType(); string savedTokenName = ourType.Namespace + "." + ourType.Name; string savedToken = Settings.CurrentUser.GetString(savedTokenName, null); SaveConfigToken saveConfigToken = null; if (savedToken != null) { try { SoapFormatter soap = new SoapFormatter(); byte[] bytes = Encoding.UTF8.GetBytes(savedToken); MemoryStream ms = new MemoryStream(bytes); SerializationFallbackBinder sfb = new SerializationFallbackBinder(); sfb.AddAssembly(this.GetType().Assembly); sfb.AddAssembly(typeof(FileType).Assembly); soap.Binder = sfb; object obj = soap.Deserialize(ms); ms.Close(); SaveConfigToken sct = new SaveConfigToken(); saveConfigToken = (SaveConfigToken)obj; } catch { // Ignore erros and revert to default saveConfigToken = null; } } if (saveConfigToken == null) { saveConfigToken = CreateDefaultSaveConfigToken(); } return saveConfigToken; }
protected override void InitWidgetFromToken(SaveConfigToken token) { this.qualitySlider.Value = ((JpegSaveConfigToken)token).Quality; }
public override bool IsReflexive(SaveConfigToken token) { return(false); }
public void Save( Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback, bool rememberToken) { Tracing.LogFeature("Save(" + GetType().FullName + ")"); if (!this.SupportsSaving) { throw new NotImplementedException("Saving is not supported by this FileType"); } else { Surface disposeMe = null; if (scratchSurface == null) { disposeMe = new Surface(input.Size); scratchSurface = disposeMe; } else if (scratchSurface.Size != input.Size) { throw new ArgumentException("scratchSurface.Size must equal input.Size"); } if (rememberToken) { Type ourType = this.GetType(); string savedTokenName = "SaveConfigToken." + ourType.Namespace + "." + ourType.Name + ".BinaryFormatter"; MemoryStream ms = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); DeferredFormatter deferredFormatter = new DeferredFormatter(false, null); StreamingContext streamingContext = new StreamingContext(formatter.Context.State, deferredFormatter); formatter.Context = streamingContext; object tokenSubset = GetSerializablePortionOfSaveConfigToken(token); formatter.Serialize(ms, tokenSubset); deferredFormatter.FinishSerialization(ms); byte[] bytes = ms.GetBuffer(); string base64Bytes = Convert.ToBase64String(bytes); Settings.CurrentUser.SetString(savedTokenName, base64Bytes); } try { OnSave(input, output, token, scratchSurface, callback); } catch (OnSaveNotImplementedException) { OldOnSaveTrampoline(input, output, token, callback); } if (disposeMe != null) { disposeMe.Dispose(); disposeMe = null; } } }
protected override sealed void InitWidgetFromToken(SaveConfigToken sourceToken) { InitWidgetFromToken((TToken)sourceToken); }
private void defaultsButton_Click(object sender, System.EventArgs e) { this.SaveConfigToken = this.FileType.CreateDefaultSaveConfigToken(); }
private void DefaultsButton_Click(object sender, System.EventArgs e) { this.SaveConfigToken = this.FileType.CreateDefaultSaveConfigToken(); }
public void GetDocumentSaveOptions(out string filePathResult, out FileType fileTypeResult, out SaveConfigToken saveConfigTokenResult) { filePathResult = this.filePath; fileTypeResult = this.fileType; if (this.saveConfigToken == null) { saveConfigTokenResult = null; } else { saveConfigTokenResult = (SaveConfigToken)this.saveConfigToken.Clone(); } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0)); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } SaveTga(scratchSurface, output, token, callback); }
/// <summary> /// Use this to get a save config token. You should already know the filename and file type. /// An existing save config token is optional and will be used to pre-populate the config dialog. /// </summary> /// <param name="fileType"></param> /// <param name="saveConfigToken"></param> /// <param name="newSaveConfigToken"></param> /// <returns>false if the user cancelled, otherwise true</returns> private bool GetSaveConfigToken( FileType currentFileType, SaveConfigToken currentSaveConfigToken, out SaveConfigToken newSaveConfigToken, Surface saveScratchSurface) { if (currentFileType.SupportsConfiguration) { using (SaveConfigDialog scd = new SaveConfigDialog()) { scd.ScratchSurface = saveScratchSurface; ProgressEventHandler peh = delegate(object sender, ProgressEventArgs e) { if (e.Percent < 0 || e.Percent >= 100) { AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar(); AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar(); } else { AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(e.Percent); } }; //if (currentFileType.SavesWithProgress) { scd.Progress += peh; } scd.Document = Document; scd.FileType = currentFileType; SaveConfigToken token = currentFileType.GetLastSaveConfigToken(); if (currentSaveConfigToken != null && token.GetType() == currentSaveConfigToken.GetType()) { scd.SaveConfigToken = currentSaveConfigToken; } scd.EnableInstanceOpacity = false; // show configuration/preview dialog DialogResult dr = scd.ShowDialog(this); //if (currentFileType.SavesWithProgress) { scd.Progress -= peh; AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar(); AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar(); } if (dr == DialogResult.OK) { newSaveConfigToken = scd.SaveConfigToken; return true; } else { newSaveConfigToken = null; return false; } } } else { newSaveConfigToken = currentFileType.GetLastSaveConfigToken(); return true; } }