Files
Misaki.HighPerformance/Misaki.HighPerformance.Image/ImageResultFloat.cs
Misaki cfd01eb9b6 Refactor SPMD job system, add GGX mipmap benchmark
- Replace IJobSPMD with T4-generated, multi-type SPMD job interfaces and wrappers (up to 8 numeric types)
- Extend ISPMD with Cast/BitCast; implement for ScalarLane and WideLane (SIMD-aware)
- Add unary minus, scalar-lane, and lane-scalar operators to Vector2/3/4; improve Select methods
- WideLane now partial with T4-generated Cast/BitCast (SIMD conversions)
- SPMD job Execute now requires unmanaged TLane; update all usages and benchmarks
- Add GGXMipGenerationBenchmark with vectorized and scalar paths, SkiaSharp output
- Update project files: add generated code, SkiaSharp, bump version to 1.3.0
- Misc: fix formatting, method signatures, FreeList logic
2026-04-25 01:50:06 +09:00

106 lines
2.6 KiB
C#

using Misaki.HighPerformance.Image.Runtime;
using System;
using System.IO;
namespace Misaki.HighPerformance.Image;
/// <summary>
/// Represents a decoded image with pixel data stored as floating-point values, including image dimensions and color
/// component information.
/// </summary>
/// <remarks>The image data is stored as a contiguous block of unmanaged memory and must be released by calling
/// <see cref="Dispose"/> when no longer needed. Be careful that this struct won't stop your double free if you copy it.
/// Ensure to have proper ownership management when using this struct.</remarks>
public readonly unsafe struct ImageResultFloat : IDisposable
{
public float* Data
{
get; init;
}
public uint Width
{
get; init;
}
public uint Height
{
get; init;
}
public ColorComponents SourceComp
{
get; init;
}
public ColorComponents Comp
{
get; init;
}
public ulong Size
{
get
{
if (Data == null)
{
return 0;
}
return (ulong)(Width * Height * (int)Comp * sizeof(float));
}
}
internal static ImageResultFloat FromResult(float* result, uint width, uint height, ColorComponents comp,
ColorComponents req_comp)
{
if (result == null)
{
throw new InvalidOperationException(StbImage.stbi__g_failure_reason);
}
var image = new ImageResultFloat
{
Data = result,
Width = width,
Height = height,
SourceComp = comp,
Comp = req_comp == ColorComponents.Default ? comp : req_comp
};
return image;
}
public static ImageResultFloat FromStream(Stream stream,
ColorComponents requiredComponents = ColorComponents.Default)
{
int x, y, comp;
var context = new StbImage.stbi__context(stream);
var result = StbImage.stbi__loadf_main(context, &x, &y, &comp, (int)requiredComponents);
return FromResult(result, (uint)x, (uint)y, (ColorComponents)comp, requiredComponents);
}
public static ImageResultFloat FromMemory(byte[] data,
ColorComponents requiredComponents = ColorComponents.Default)
{
using var stream = new MemoryStream(data);
return FromStream(stream, requiredComponents);
}
public Span<float> AsSpan()
{
if (Data == null)
{
return Span<float>.Empty;
}
return new Span<float>(Data, (int)Size);
}
public void Dispose()
{
CRuntime.free(Data);
}
}