- Make image result/info structs readonly; improve error handling and memory safety in image library - Introduce IJobScheduler interface; move job scheduling docs to interface - Remove "index 0 invalid" convention from slot/sparse maps; fix Count logic - Add Owner<T> for disposable value types in low-level utilities - Improve ObjectPool<T> thread safety and logic - Change List<T>.RemoveAndSwapBack to return bool - Remove unsafe methods from generated math types; add debug range checks - Update benchmarks and enable collection checks in tests - Improve documentation, comments, and error messages - Bump assembly versions across all projects
52 lines
1017 B
C#
52 lines
1017 B
C#
using System.IO;
|
|
|
|
namespace Misaki.HighPerformance.Image;
|
|
|
|
public readonly struct ImageInfo
|
|
{
|
|
public int Width
|
|
{
|
|
get; init;
|
|
}
|
|
|
|
public int Height
|
|
{
|
|
get; init;
|
|
}
|
|
|
|
public ColorComponents ColorComponents
|
|
{
|
|
get; init;
|
|
}
|
|
|
|
public int BitsPerChannel
|
|
{
|
|
get; init;
|
|
}
|
|
|
|
public static unsafe ImageInfo FromStream(Stream stream)
|
|
{
|
|
int width, height, comp;
|
|
var context = new StbImage.stbi__context(stream);
|
|
|
|
var is16Bit = StbImage.stbi__is_16_main(context) == 1;
|
|
StbImage.stbi__rewind(context);
|
|
|
|
var infoResult = StbImage.stbi__info_main(context, &width, &height, &comp);
|
|
StbImage.stbi__rewind(context);
|
|
|
|
if (infoResult == 0)
|
|
{
|
|
return default;
|
|
}
|
|
|
|
return new ImageInfo
|
|
{
|
|
Width = width,
|
|
Height = height,
|
|
ColorComponents = (ColorComponents)comp,
|
|
BitsPerChannel = is16Bit ? 16 : 8
|
|
};
|
|
}
|
|
}
|