Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -10,6 +10,107 @@ public static class ImageUtil {
|
|||||||
using var image16 = image as Image<Rgba64> ?? throw new NotSupportedException($"Image format not supported");
|
using var image16 = image as Image<Rgba64> ?? throw new NotSupportedException($"Image format not supported");
|
||||||
int width = image.Width;
|
int width = image.Width;
|
||||||
int height = image.Height;
|
int height = image.Height;
|
||||||
|
//result = new T[image.Width, image.Height];
|
||||||
|
return image switch {
|
||||||
|
Image<Rgba64> img => img.ProcessPixelsRgba64<T>(),
|
||||||
|
Image<Rgb24> img => img.ProcessPixelsRgb24<T>(),
|
||||||
|
Image<Rgba32> img => img.ProcessPixelsRgba32<T>(),
|
||||||
|
Image<Rgb48> img => img.ProcessPixelsRgb48<T>(),
|
||||||
|
_ => throw new NotSupportedException($"Image format not supported")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static T[,] ProcessPixelsRgba64<T>(this Image<Rgba64> image) where T : struct, IEquatable<T> {
|
||||||
|
int width = image.Width;
|
||||||
|
int height = image.Height;
|
||||||
|
var result = new T[image.Width, image.Height];
|
||||||
|
image.ProcessPixelRows(accessor => {
|
||||||
|
//we use Y as the row index and X as the column index
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
var span = accessor.GetRowSpan(y);
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
switch (result) {
|
||||||
|
case float[,] f:
|
||||||
|
f[x, y] = span[x].R;
|
||||||
|
break;
|
||||||
|
case Vector2[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G);
|
||||||
|
break;
|
||||||
|
case Vector3[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G, span[x].B);
|
||||||
|
break;
|
||||||
|
case Vector4[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G, span[x].B, 1f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static T[,] ProcessPixelsRgb24<T>(this Image<Rgb24> image) where T : struct, IEquatable<T> {
|
||||||
|
int width = image.Width;
|
||||||
|
int height = image.Height;
|
||||||
|
var result = new T[image.Width, image.Height];
|
||||||
|
image.ProcessPixelRows(accessor => {
|
||||||
|
//we use Y as the row index and X as the column index
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
var span = accessor.GetRowSpan(y);
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
switch (result) {
|
||||||
|
case float[,] f:
|
||||||
|
f[x, y] = span[x].R;
|
||||||
|
break;
|
||||||
|
case Vector2[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G);
|
||||||
|
break;
|
||||||
|
case Vector3[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G, span[x].B);
|
||||||
|
break;
|
||||||
|
case Vector4[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G, span[x].B, 1f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static T[,] ProcessPixelsRgba32<T>(this Image<Rgba32> image) where T : struct, IEquatable<T> {
|
||||||
|
int width = image.Width;
|
||||||
|
int height = image.Height;
|
||||||
|
var result = new T[image.Width, image.Height];
|
||||||
|
image.ProcessPixelRows(accessor => {
|
||||||
|
//we use Y as the row index and X as the column index
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
var span = accessor.GetRowSpan(y);
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
switch (result) {
|
||||||
|
case float[,] f:
|
||||||
|
f[x, y] = span[x].R;
|
||||||
|
break;
|
||||||
|
case Vector2[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G);
|
||||||
|
break;
|
||||||
|
case Vector3[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G, span[x].B);
|
||||||
|
break;
|
||||||
|
case Vector4[,] f:
|
||||||
|
f[x, y] = new(span[x].R, span[x].G, span[x].B, 1f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static T[,] ProcessPixelsRgb48<T>(this Image<Rgb48> image) where T : struct, IEquatable<T> {
|
||||||
|
using var image16 = image as Image<Rgb48> ?? throw new NotSupportedException($"Image format not supported");
|
||||||
|
int width = image.Width;
|
||||||
|
int height = image.Height;
|
||||||
var result = new T[image.Width, image.Height];
|
var result = new T[image.Width, image.Height];
|
||||||
image16.ProcessPixelRows(accessor => {
|
image16.ProcessPixelRows(accessor => {
|
||||||
//we use Y as the row index and X as the column index
|
//we use Y as the row index and X as the column index
|
||||||
@@ -33,7 +134,6 @@ public static class ImageUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ImageData(image, path);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Magick.NET-Q16-HDRI-OpenMP-x64" Version="14.5.0" />
|
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.5" />
|
|
||||||
<PackageReference Include="System.Numerics.Vectors" Version="4.6.1" />
|
<PackageReference Include="System.Numerics.Vectors" Version="4.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user