Added new namespace `Misaki.HighPerformance.Image` for image processing, including classes for animated GIF handling and memory management. Added `AnimatedFrameResult` class for individual frames in animated images. Added `AnimatedGifEnumerator` class for enumerating frames in animated GIFs. Added `ColorComponents` enum for different color formats. Added `ImageInfo` struct for image dimensions and color components. Added `CRuntime` class for low-level memory management functions. Added `MemoryStats` class to track memory allocation statistics. Added utility functions for creating multi-dimensional arrays. Added new structures for fixed-size UTF-8 encoded strings. Added benchmarking classes to test new memory management features. Changed `StbImage.cs` to include new namespaces and functionality for image data manipulation. Changed project files to target .NET 9.0 and enable new features. Changed `Arena.cs` and `DynamicArena.cs` to use `nuint` for size parameters. Changed `BitSet.cs` to enhance bit manipulation methods. Changed `Program.cs` to run `FunctionPtrBenchmark` for performance testing. Removed memory tracking code from `AllocationManager.cs`, including the `_allocated` dictionary and related logic. Removed `Free` method from `IAllocator.cs` interface. Removed `UNSAFE_COLLECTION_CHECK` preprocessor directive from the codebase. Refactored various files to improve organization, moving from `Unsafe` to `LowLevel` namespace. Refactored `MemoryUtilities` class to include new memory operation methods. Refactored `UnsafeUtilities.cs` to support new collection structures.
96 lines
1.8 KiB
C#
96 lines
1.8 KiB
C#
using Misaki.HighPerformance.Image.Runtime;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using Misaki.HighPerformance.Image;
|
|
|
|
namespace Misaki.HighPerformance.Image
|
|
{
|
|
#if !STBSHARP_INTERNAL
|
|
public
|
|
#else
|
|
internal
|
|
#endif
|
|
static unsafe partial class StbImage
|
|
{
|
|
public static string stbi__g_failure_reason;
|
|
public static readonly char[] stbi__parse_png_file_invalid_chunk = new char[25];
|
|
|
|
public static int NativeAllocations
|
|
{
|
|
get
|
|
{
|
|
return MemoryStats.Allocations;
|
|
}
|
|
}
|
|
|
|
public class stbi__context
|
|
{
|
|
private readonly Stream _stream;
|
|
|
|
public byte[] _tempBuffer;
|
|
public int img_n = 0;
|
|
public int img_out_n = 0;
|
|
public uint img_x = 0;
|
|
public uint img_y = 0;
|
|
|
|
public stbi__context(Stream stream)
|
|
{
|
|
if (stream == null)
|
|
throw new ArgumentNullException("stream");
|
|
|
|
_stream = stream;
|
|
}
|
|
|
|
public Stream Stream
|
|
{
|
|
get
|
|
{
|
|
return _stream;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static int stbi__err(string str)
|
|
{
|
|
stbi__g_failure_reason = str;
|
|
return 0;
|
|
}
|
|
|
|
public static byte stbi__get8(stbi__context s)
|
|
{
|
|
var b = s.Stream.ReadByte();
|
|
if (b == -1) return 0;
|
|
|
|
return (byte)b;
|
|
}
|
|
|
|
public static void stbi__skip(stbi__context s, int skip)
|
|
{
|
|
s.Stream.Seek(skip, SeekOrigin.Current);
|
|
}
|
|
|
|
public static void stbi__rewind(stbi__context s)
|
|
{
|
|
s.Stream.Seek(0, SeekOrigin.Begin);
|
|
}
|
|
|
|
public static int stbi__at_eof(stbi__context s)
|
|
{
|
|
return s.Stream.Position == s.Stream.Length ? 1 : 0;
|
|
}
|
|
|
|
public static int stbi__getn(stbi__context s, byte* buf, int size)
|
|
{
|
|
if (s._tempBuffer == null ||
|
|
s._tempBuffer.Length < size)
|
|
s._tempBuffer = new byte[size * 2];
|
|
|
|
var result = s.Stream.Read(s._tempBuffer, 0, size);
|
|
Marshal.Copy(s._tempBuffer, 0, new IntPtr(buf), result);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|