Image Exporter: added support for transparency

This commit is contained in:
biwa 2023-09-03 15:39:34 +02:00
parent edc4c2bd16
commit 3a7d926704
5 changed files with 427 additions and 394 deletions

View file

@ -678,9 +678,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
[BeginAction("exporttoimage")]
private void ExportToImage()
{
// Convert geometry selection to sectors
General.Map.Map.ConvertSelection(SelectionType.Sectors);
// Get sectors
ICollection<Sector> sectors = General.Map.Map.SelectedSectorsCount == 0 ? General.Map.Map.Sectors : General.Map.Map.GetSelectedSectors(true);
if (sectors.Count == 0)

View file

@ -50,11 +50,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
public bool ApplySectorColors;
public bool Brightmap;
public bool Tiles;
public bool Transparency;
public PixelFormat PixelFormat;
public ImageFormat ImageFormat;
public float Scale;
public ImageExportSettings(string path, string name, string extension, bool floor, bool fullbright, bool applysectorcolors, bool brightmap, bool tiles, float scale, PixelFormat pformat, ImageFormat iformat)
public ImageExportSettings(string path, string name, string extension, bool floor, bool fullbright, bool applysectorcolors, bool brightmap, bool transparency, bool tiles, float scale, PixelFormat pformat, ImageFormat iformat)
{
Path = path;
Name = name;
@ -63,6 +64,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
Brightmap = brightmap;
Tiles = tiles;
Fullbright = fullbright;
Transparency = transparency;
ApplySectorColors = applysectorcolors;
PixelFormat = pformat;
ImageFormat = iformat;
@ -200,12 +202,16 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
{
// The texture
using (Graphics gtexture = Graphics.FromImage(texturebitmap))
{
if (!settings.Transparency)
{
gtexture.Clear(Color.Black); // If we don't clear to black we'll see seams where the sectors touch, due to the AA
gtexture.SmoothingMode = SmoothingMode.AntiAlias; // Without AA the sector edges will be quite rough
}
gtexture.InterpolationMode = InterpolationMode.HighQualityBilinear;
gtexture.CompositingQuality = CompositingQuality.HighQuality;
gtexture.PixelOffsetMode = PixelOffsetMode.HighQuality;
gtexture.SmoothingMode = SmoothingMode.AntiAlias; // Without AA the sector edges will be quite rough
using (GraphicsPath gpath = new GraphicsPath())
{

View file

@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tbExportPath = new System.Windows.Forms.TextBox();
this.browse = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
@ -48,6 +49,8 @@
this.progress = new System.Windows.Forms.ProgressBar();
this.lbPhase = new System.Windows.Forms.Label();
this.cbApplySectorColors = new System.Windows.Forms.CheckBox();
this.cbTransparency = new System.Windows.Forms.CheckBox();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// tbExportPath
@ -78,8 +81,9 @@
//
// close
//
this.close.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.close.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.close.Location = new System.Drawing.Point(360, 153);
this.close.Location = new System.Drawing.Point(360, 172);
this.close.Name = "close";
this.close.Size = new System.Drawing.Size(75, 23);
this.close.TabIndex = 7;
@ -89,7 +93,8 @@
//
// export
//
this.export.Location = new System.Drawing.Point(279, 153);
this.export.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.export.Location = new System.Drawing.Point(279, 172);
this.export.Name = "export";
this.export.Size = new System.Drawing.Size(75, 23);
this.export.TabIndex = 6;
@ -182,7 +187,7 @@
// cbBrightmap
//
this.cbBrightmap.AutoSize = true;
this.cbBrightmap.Location = new System.Drawing.Point(279, 84);
this.cbBrightmap.Location = new System.Drawing.Point(279, 109);
this.cbBrightmap.Name = "cbBrightmap";
this.cbBrightmap.Size = new System.Drawing.Size(106, 17);
this.cbBrightmap.TabIndex = 15;
@ -192,7 +197,7 @@
// cbTiles
//
this.cbTiles.AutoSize = true;
this.cbTiles.Location = new System.Drawing.Point(279, 108);
this.cbTiles.Location = new System.Drawing.Point(279, 132);
this.cbTiles.Name = "cbTiles";
this.cbTiles.Size = new System.Drawing.Size(110, 17);
this.cbTiles.TabIndex = 16;
@ -224,7 +229,8 @@
//
// progress
//
this.progress.Location = new System.Drawing.Point(12, 153);
this.progress.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.progress.Location = new System.Drawing.Point(12, 172);
this.progress.Name = "progress";
this.progress.Size = new System.Drawing.Size(261, 23);
this.progress.Step = 1;
@ -233,8 +239,9 @@
//
// lbPhase
//
this.lbPhase.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.lbPhase.AutoSize = true;
this.lbPhase.Location = new System.Drawing.Point(14, 127);
this.lbPhase.Location = new System.Drawing.Point(14, 146);
this.lbPhase.Name = "lbPhase";
this.lbPhase.Size = new System.Drawing.Size(45, 13);
this.lbPhase.TabIndex = 20;
@ -246,20 +253,33 @@
this.cbApplySectorColors.AutoSize = true;
this.cbApplySectorColors.Checked = true;
this.cbApplySectorColors.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbApplySectorColors.Location = new System.Drawing.Point(279, 61);
this.cbApplySectorColors.Location = new System.Drawing.Point(279, 63);
this.cbApplySectorColors.Name = "cbApplySectorColors";
this.cbApplySectorColors.Size = new System.Drawing.Size(115, 17);
this.cbApplySectorColors.TabIndex = 14;
this.cbApplySectorColors.Text = "Apply sector colors";
this.cbApplySectorColors.UseVisualStyleBackColor = true;
//
// cbTransparency
//
this.cbTransparency.AutoSize = true;
this.cbTransparency.Location = new System.Drawing.Point(279, 86);
this.cbTransparency.Name = "cbTransparency";
this.cbTransparency.Size = new System.Drawing.Size(115, 17);
this.cbTransparency.TabIndex = 21;
this.cbTransparency.Text = "Allow transparency";
this.toolTip.SetToolTip(this.cbTransparency, "Unoccupied parts of the images will be transparent.\r\nWorks with transparent textu" +
"res, too.\r\n\r\nAntialiasing will be disabled.");
this.cbTransparency.UseVisualStyleBackColor = true;
//
// ImageExportSettingsForm
//
this.AcceptButton = this.export;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.close;
this.ClientSize = new System.Drawing.Size(447, 188);
this.ClientSize = new System.Drawing.Size(447, 208);
this.Controls.Add(this.cbTransparency);
this.Controls.Add(this.lbPhase);
this.Controls.Add(this.progress);
this.Controls.Add(this.label4);
@ -312,5 +332,7 @@
private System.Windows.Forms.ProgressBar progress;
private System.Windows.Forms.Label lbPhase;
private System.Windows.Forms.CheckBox cbApplySectorColors;
private System.Windows.Forms.CheckBox cbTransparency;
private System.Windows.Forms.ToolTip toolTip;
}
}

View file

@ -52,6 +52,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface
public string FilePath { get { return tbExportPath.Text.Trim(); } }
public bool Floor { get { return rbFloor.Checked; } }
public bool Fullbright { get { return cbFullbright.Checked; } }
public bool Transparency { get { return cbTransparency.Checked; } }
public bool ApplySectorColors { get { return cbApplySectorColors.Checked; } }
public bool Brightmap { get { return cbBrightmap.Checked; } }
public bool Tiles { get { return cbTiles.Checked; } }
@ -101,6 +102,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface
cbFullbright.Checked = General.Settings.ReadPluginSetting("imageexportfullbright", true);
cbApplySectorColors.Checked = General.Settings.ReadPluginSetting("imageexportapplysectorcolors", true);
cbTransparency.Checked = General.Settings.ReadPluginSetting("imageexporttransparency", false);
cbBrightmap.Checked = General.Settings.ReadPluginSetting("imageexportbrightmap", false);
cbTiles.Checked = General.Settings.ReadPluginSetting("imageexporttiles", false);
cbScale.SelectedIndex = General.Settings.ReadPluginSetting("imageexportscale", 0);
@ -160,11 +162,13 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface
export.Enabled = true;
export.Text = "Cancel";
ImageExportSettings settings = new ImageExportSettings(Path.GetDirectoryName(FilePath), Path.GetFileNameWithoutExtension(FilePath), Path.GetExtension(FilePath), Floor, Fullbright, ApplySectorColors, Brightmap, Tiles, ImageScale, GetPixelFormat(), GetImageFormat());
ImageExportSettings settings = new ImageExportSettings(Path.GetDirectoryName(FilePath), Path.GetFileNameWithoutExtension(FilePath), Path.GetExtension(FilePath), Floor, Fullbright, ApplySectorColors, Brightmap, Transparency, Tiles, ImageScale, GetPixelFormat(), GetImageFormat());
exportthread = new Thread(() => RunExport(settings));
exportthread.Name = "Image export";
exportthread.Priority = ThreadPriority.Normal;
exportthread = new Thread(() => RunExport(settings))
{
Name = "Image export",
Priority = ThreadPriority.Normal
};
exportthread.Start();
}
@ -323,6 +327,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface
General.Settings.WritePluginSetting("imageexportfullbright", cbFullbright.Checked);
General.Settings.WritePluginSetting("imageexportapplysectorcolors", cbApplySectorColors.Checked);
General.Settings.WritePluginSetting("imageexportbrightmap", cbBrightmap.Checked);
General.Settings.WritePluginSetting("imageexporttransparency", cbTransparency.Checked);
General.Settings.WritePluginSetting("imageexporttiles", cbTiles.Checked);
General.Settings.WritePluginSetting("imageexportscale", cbScale.SelectedIndex);

View file

@ -120,4 +120,7 @@
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>146, 17</value>
</metadata>
</root>