forked from KFreon/CSharpImageLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeChannelsImage.cs
More file actions
180 lines (161 loc) · 4.74 KB
/
Copy pathMergeChannelsImage.cs
File metadata and controls
180 lines (161 loc) · 4.74 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using CSharpImageLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using UsefulThings.WPF;
namespace CSharpImageLibrary
{
/// <summary>
/// Represents an channel candidate to be merged into a single image.
/// </summary>
public class MergeChannelsImage : ViewModelBase
{
#region Properties
/// <summary>
/// Size of channel components in bytes. e.g. 16bit = 2.
/// </summary>
public int ComponentSize { get; private set; }
/// <summary>
/// Pixels of this channel.
/// </summary>
public byte[] Pixels { get; private set; }
/// <summary>
/// Path to image file.
/// </summary>
public string FilePath { get; private set; }
/// <summary>
/// Name to display in UI.
/// </summary>
public string DisplayName
{
get
{
return Path.GetFileNameWithoutExtension(FilePath);
}
}
bool isRed = false;
/// <summary>
/// Indicates whether this channel is the red channel.
/// </summary>
public bool IsRed
{
get
{
return isRed;
}
set
{
SetProperty(ref isRed, value);
OnPropertyChanged(nameof(HasAssignedChannel));
}
}
bool isGreen = false;
/// <summary>
/// Indicates whether this channel is the green channel.
/// </summary>
public bool IsGreen
{
get
{
return isGreen;
}
set
{
SetProperty(ref isGreen, value);
OnPropertyChanged(nameof(HasAssignedChannel));
}
}
bool isBlue = false;
/// <summary>
/// Indicates whether this channel is the blue channel.
/// </summary>
public bool IsBlue
{
get
{
return isBlue;
}
set
{
SetProperty(ref isBlue, value);
OnPropertyChanged(nameof(HasAssignedChannel));
}
}
bool isAlpha = false;
/// <summary>
/// Indicates whether this channel is the alpha channel.
/// </summary>
public bool IsAlpha
{
get
{
return isAlpha;
}
set
{
SetProperty(ref isAlpha, value);
OnPropertyChanged(nameof(HasAssignedChannel));
}
}
/// <summary>
/// Indicates if any of the channel colour settings have been set.
/// </summary>
public bool HasAssignedChannel
{
get
{
return IsAlpha || IsRed || IsBlue || IsGreen;
}
}
/// <summary>
/// Thumbnail of channel.
/// </summary>
public BitmapSource Thumbnail { get; private set; }
/// <summary>
/// Height of channel.
/// </summary>
public int Height { get; private set; }
/// <summary>
/// Width of channel.
/// </summary>
public int Width { get; private set; }
#endregion Properties
/// <summary>
/// Creates a channel from an image. Can merge together with other channels to form a proper image again.
/// MUST BE GRAYSCALE (PixelFormats.Gray8).
/// </summary>
/// <param name="mainPath">Path to channel.</param>
public MergeChannelsImage(string mainPath)
{
FilePath = mainPath;
var img = new ImageEngineImage(mainPath);
{
Width = img.Width;
Height = img.Height;
Thumbnail = img.GetWPFBitmap(128);
//Pixels = img.MipMaps[0].Pixels;
}
}
/// <summary>
/// Determines if this channel is compatible with other channels.
/// </summary>
/// <param name="channels">Channels to compare to.</param>
/// <returns>True if compatible with all channels.</returns>
public bool IsCompatibleWith(params MergeChannelsImage[] channels)
{
foreach(var channel in channels)
{
if (channel == this || channel == null)
continue;
if (Width != channel.Width || Height != channel.Height || Pixels.Length != channel.Pixels.Length)
return false;
}
return true;
}
}
}