mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 05:58:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
39
Brutal.Stb/StbImageF.cs
Normal file
39
Brutal.Stb/StbImageF.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Brutal.Numerics;
|
||||
|
||||
namespace Brutal.StbApi;
|
||||
|
||||
public readonly unsafe struct StbImageF(float* inData, int inWidth, int inHeight, int inChannels)
|
||||
: INullable,
|
||||
IDisposable
|
||||
{
|
||||
public readonly float* Data = inData;
|
||||
public readonly int Width = inWidth;
|
||||
public readonly int Height = inHeight;
|
||||
public readonly int Channels = inChannels;
|
||||
|
||||
public Span<float> AsSpan()
|
||||
{
|
||||
return new Span<float>(Data, Width * Height * Channels);
|
||||
}
|
||||
|
||||
public Span<T> AsSpan<T>()
|
||||
where T : IVector<T, float>
|
||||
{
|
||||
if (T.ComponentCount != Channels)
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot convert to Span<{typeof(T).Name}> because it has {T.ComponentCount} components, but the image has {Channels} channels."
|
||||
);
|
||||
|
||||
return new Span<T>(Data, Width * Height);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Stb.PInvoke.stbi_image_free(Data);
|
||||
}
|
||||
|
||||
public bool IsNull()
|
||||
{
|
||||
return Data == null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue