10 ArgumentNullException.ThrowIfNull(image);
17 ArgumentNullException.ThrowIfNull(image);
24 ArgumentOutOfRangeException.ThrowIfNegative(width);
25 ArgumentOutOfRangeException.ThrowIfNegative(height);
31 public Color GetPixel(
int x,
int y) => x < 0 || x >=
Width ?
throw new ArgumentOutOfRangeException(nameof(x)) :
32 y < 0 || y >=
Height ? throw new ArgumentOutOfRangeException(nameof(y)) :
Pixels[x + y *
Width];
37 throw new ArgumentOutOfRangeException(nameof(x));
41 throw new ArgumentOutOfRangeException(nameof(y));
47 for (
int i = 0; i < image.
Pixels.Length; i++) {
53 ArgumentNullException.ThrowIfNull(image);
54 ArgumentOutOfRangeException.ThrowIfNegative(maxLevelsCount);
55 if (maxLevelsCount == 0) {
58 int mipWidth = image.
Width;
59 int mipHeight = image.
Height;
63 if (level >= maxLevelsCount) {
66 if ((mipWidth > 1 && mipWidth % 2 != 0)
67 || (mipHeight > 1 && mipHeight % 2 != 0)) {
75 int num3 = num / mipWidth;
76 int num4 = num2 / mipHeight;
81 for (; i < mipHeight; i++) {
82 int num6 = i * 2 * num;
84 while (num7 < mipWidth) {
89 byte r = (byte)((color.
R + color2.
R + color3.
R + color4.
R + 2) / 4);
90 byte g = (byte)((color.
G + color2.
G + color3.
G + color4.
G + 2) / 4);
91 byte b = (byte)((color.
B + color2.
B + color3.
B + color4.
B + 2) / 4);
92 byte a = (byte)((color.
A + color2.
A + color3.
A + color4.
A + 2) / 4);
104 for (; j < mipHeight; j++) {
107 while (num10 < mipWidth) {
110 byte r2 = (byte)((color5.
R + color6.
R + 1) / 2);
111 byte g2 = (byte)((color5.
G + color6.
G + 1) / 2);
112 byte b2 = (byte)((color5.
B + color6.
B + 1) / 2);
113 byte a2 = (byte)((color5.
A + color6.
A + 1) / 2);
128 for (; k < mipHeight; k++) {
129 int num12 = k * 2 * num;
131 while (num13 < mipWidth) {
134 byte r3 = (byte)((color7.
R + color8.
R + 1) / 2);
135 byte g3 = (byte)((color7.
G + color8.
G + 1) / 2);
136 byte b3 = (byte)((color7.
B + color8.
B + 1) / 2);
137 byte a3 = (byte)((color7.
A + color8.
A + 1) / 2);
138 mipImage.
Pixels[num11] =
new Color(r3, g3, b3, a3);
145 yield
return mipImage;
147 int num14 = level + 1;
150 throw new InvalidOperationException(
151 "Generating mipmaps with not 2:1 scaling is not supported. Limit mipmap levels count using maxLevelsCount parameter."
163 return Load(stream, format);
180 Save(image, stream, format, saveAlpha);
static int Max(int x1, int x2)
static Stream OpenFile(string path, OpenFileMode openFileMode)
static Color PremultiplyAlpha(Color c)