-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExportTextureScalingViewModel.cs
More file actions
120 lines (101 loc) · 3.83 KB
/
Copy pathExportTextureScalingViewModel.cs
File metadata and controls
120 lines (101 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using DolphinDynamicInputTexture.Data;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DolphinDynamicInputTextureCreator.ViewModels
{
public class ExportTextureScalingViewModel : Other.PropertyChangedBase
{
/// <summary>
/// Possible texture scaling modes.
/// </summary>
internal enum Modes
{
None, NearestNeighbor, Bicubic, Bilinear
}
/// <summary>
/// The currently selected export texture scaling mode.
/// </summary>
internal Modes SelectedScalingMode
{
get => _selected_scaling_mode;
set
{
_selected_scaling_mode = value;
SetExportTextureScaling();
OnPropertyChanged(nameof(SelectedScalingMode));
}
}
private Modes _selected_scaling_mode = Modes.None;
/// <summary>
/// Scaling factor that the exported image should have.
/// </summary>
public int SelectedScalingFactor { get; set; } = 4;
#region UI Helper
public string[] ScalingModesHelper
{
get => Enum.GetNames(typeof(Modes));
}
public string SelectedScalingModeHelper
{
get => SelectedScalingMode.ToString();
set
{
SelectedScalingMode = Enum.Parse<Modes>(value);
OnPropertyChanged(nameof(SelectedScalingModeHelper));
}
}
public int[] ScalingFactorHelper => new int[] { 1, 2, 3, 4, 5, 6, 8, 10 };
#endregion UI Helper
/// <summary>
/// set the export scale for each texture.
/// </summary>
private void SetExportTextureScaling()
{
switch (SelectedScalingMode)
{
case Modes.None:
DynamicInputTextureEvents.DynamicInputTextureExportProcessor = null;
break;
case Modes.NearestNeighbor:
case Modes.Bicubic:
case Modes.Bilinear:
DynamicInputTextureEvents.DynamicInputTextureExportProcessor = DefaultScalingProcessor;
break;
default:
break;
}
}
public bool DefaultScalingProcessor(string savepath, DynamicInputTexture dynamicinputtexture)
{
int Scaling = SelectedScalingFactor;
//Should we use scaling?
if (Scaling == dynamicinputtexture.ImageWidthScaling) return false;
//The actual scaling.
using (Bitmap newImage = new Bitmap(dynamicinputtexture.HashProperties.ImageWidth * Scaling, dynamicinputtexture.HashProperties.ImageHeight * Scaling))
{
using (Bitmap Image = new Bitmap(dynamicinputtexture.TexturePath))
using (Graphics graphics = Graphics.FromImage(newImage))
{
switch (SelectedScalingMode)
{
case Modes.NearestNeighbor:
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
break;
case Modes.Bicubic:
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
break;
case Modes.Bilinear:
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
break;
default:
break;
}
graphics.DrawImage(Image, 0, 0, newImage.Width, newImage.Height);
}
newImage.Save(savepath, System.Drawing.Imaging.ImageFormat.Png);
}
return true;
}
}
}