Enhance mathematical capabilities and job system
Added new numeric types for unsigned integers, including uint2, uint3, and uint4, along with their matrix types. Added a new `quaternion` struct with constructors and methods for creating and manipulating quaternions. Added methods for projecting and reflecting vectors, enhancing geometric operations. Added utility functions for generating orthonormal bases and changing vector signs. Added comprehensive unit tests for new mathematical functions and quaternion operations. Added a high-performance job scheduling system with job management features and worker thread management. Added new structs for job execution, allowing efficient job scheduling and execution. Added utility functions for job execution, including methods for obtaining unique job IDs. Changed access modifiers and property definitions in several files for improved clarity and maintainability. Changed property definitions and method implementations in `ImageInfo.cs`, `ImageResult.cs`, and `ImageResultFloat.cs` for better readability. Changed memory management functions in `CRuntime.cs` and improved memory allocation tracking in `MemoryStats.cs`. Changed the project file to include references to necessary projects and enable unsafe code blocks. Removed the `WorkerThreadPool.cs` file, integrating worker thread management directly into the `JobScheduler`. Removed the `float4` struct and its associated methods and properties, transitioning to a new code generation strategy. Removed the `float4.tt` template and other related files, indicating a shift in code generation approach. Removed the `Vectorize.cs` file, indicating a change in how vector operations are handled. Updated the `.gitignore` file to include IDE-specific settings. Updated various XML files to define project components and structure. Updated the `AllocationManager.cs` to improve memory allocation management and introduce new strategies. Updated the `UnsafeArray.cs`, `UnsafeHashMap.cs`, and `UnsafeList.cs` to enhance performance and safety in unsafe contexts. Updated error handling and function pointer management in `MemoryLeakException.cs` and `FunctionPointer.cs`. Updated the `AssemblyInfo.cs` file to include global using directives for better code organization.
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Misaki.HighPerformance.Image;
|
||||
|
||||
public unsafe class ImageResult : IDisposable
|
||||
{
|
||||
private byte* _buffer;
|
||||
public byte* Data
|
||||
{
|
||||
get; init;
|
||||
}
|
||||
|
||||
public uint Width
|
||||
{
|
||||
@@ -20,22 +22,27 @@ public unsafe class ImageResult : IDisposable
|
||||
get; init;
|
||||
}
|
||||
|
||||
public ColorComponents SourceComponent
|
||||
public ColorComponents SourceComp
|
||||
{
|
||||
get; init;
|
||||
}
|
||||
|
||||
public ColorComponents Component
|
||||
public ColorComponents Comp
|
||||
{
|
||||
get; init;
|
||||
}
|
||||
|
||||
public Span<byte> Data => new(_buffer, (int)(Width * Height * (uint)Component));
|
||||
|
||||
internal void SetData(byte* data)
|
||||
public ulong Size
|
||||
{
|
||||
CRuntime.free(_buffer);
|
||||
_buffer = data;
|
||||
get
|
||||
{
|
||||
if (Data == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (ulong)(Width * Height * (int)Comp);
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe ImageResult FromResult(byte* result, uint width, uint height, ColorComponents comp,
|
||||
@@ -46,14 +53,13 @@ public unsafe class ImageResult : IDisposable
|
||||
|
||||
var image = new ImageResult
|
||||
{
|
||||
Data = result,
|
||||
Width = width,
|
||||
Height = height,
|
||||
SourceComponent = comp,
|
||||
Component = req_comp == ColorComponents.Default ? comp : req_comp
|
||||
SourceComp = comp,
|
||||
Comp = req_comp == ColorComponents.Default ? comp : req_comp
|
||||
};
|
||||
|
||||
image._buffer = result;
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -63,6 +69,7 @@ public unsafe class ImageResult : IDisposable
|
||||
int x, y, comp;
|
||||
|
||||
var context = new StbImage.stbi__context(stream);
|
||||
|
||||
var result = StbImage.stbi__load_and_postprocess_8bit(context, &x, &y, &comp, (int)requiredComponents);
|
||||
|
||||
return FromResult(result, (uint)x, (uint)y, (ColorComponents)comp, requiredComponents);
|
||||
@@ -74,25 +81,24 @@ public unsafe class ImageResult : IDisposable
|
||||
return FromStream(stream, requiredComponents);
|
||||
}
|
||||
|
||||
public static IEnumerable<AnimatedFrameResult> AnimatedGifFramesFromStream(Stream stream, ColorComponents requiredComponents = ColorComponents.Default)
|
||||
public static IEnumerable<AnimatedFrameResult> AnimatedGifFramesFromStream(Stream stream,
|
||||
ColorComponents requiredComponents = ColorComponents.Default)
|
||||
{
|
||||
return new AnimatedGifEnumerable(stream, requiredComponents);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public byte* GetUnsafePtr()
|
||||
public Span<byte> AsSpan()
|
||||
{
|
||||
return _buffer;
|
||||
if (Data == null)
|
||||
{
|
||||
return Span<byte>.Empty;
|
||||
}
|
||||
|
||||
return new Span<byte>(Data, (int)Size);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_buffer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CRuntime.free(_buffer);
|
||||
_buffer = null;
|
||||
CRuntime.free(Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user