Files
Misaki.HighPerformance/Misaki.HighPerformance.Image/StbImage.Generated.Psd.cs
Misaki a2a760594e 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.
2025-09-06 12:07:02 +09:00

312 lines
10 KiB
C#

// Generated by Sichem at 12/24/2021 8:28:15 PM
using Misaki.HighPerformance.Image.Runtime;
// Generated by Sichem at 12/24/2021 8:28:15 PM
namespace Misaki.HighPerformance.Image
{
unsafe partial class StbImage
{
public static int stbi__psd_test(stbi__context s)
{
var r = stbi__get32be(s) == 0x38425053 ? 1 : 0;
stbi__rewind(s);
return r;
}
public static void* stbi__psd_load(stbi__context s, int* x, int* y, int* comp, int req_comp,
stbi__result_info* ri, int bpc)
{
var pixelCount = 0;
var channelCount = 0;
var compression = 0;
var channel = 0;
var i = 0;
var bitdepth = 0;
var w = 0;
var h = 0;
byte* _out_;
if (stbi__get32be(s) != 0x38425053)
return (byte*)(ulong)(stbi__err("not PSD") != 0 ? 0 : 0);
if (stbi__get16be(s) != 1)
return (byte*)(ulong)(stbi__err("wrong version") != 0 ? 0 : 0);
stbi__skip(s, 6);
channelCount = stbi__get16be(s);
if (channelCount < 0 || channelCount > 16)
return (byte*)(ulong)(stbi__err("wrong channel count") != 0 ? 0 : 0);
h = (int)stbi__get32be(s);
w = (int)stbi__get32be(s);
if (h > 1 << 24)
return (byte*)(ulong)(stbi__err("too large") != 0 ? 0 : 0);
if (w > 1 << 24)
return (byte*)(ulong)(stbi__err("too large") != 0 ? 0 : 0);
bitdepth = stbi__get16be(s);
if (bitdepth != 8 && bitdepth != 16)
return (byte*)(ulong)(stbi__err("unsupported bit depth") != 0 ? 0 : 0);
if (stbi__get16be(s) != 3)
return (byte*)(ulong)(stbi__err("wrong color format") != 0 ? 0 : 0);
stbi__skip(s, (int)stbi__get32be(s));
stbi__skip(s, (int)stbi__get32be(s));
stbi__skip(s, (int)stbi__get32be(s));
compression = stbi__get16be(s);
if (compression > 1)
return (byte*)(ulong)(stbi__err("bad compression") != 0 ? 0 : 0);
if (stbi__mad3sizes_valid(4, w, h, 0) == 0)
return (byte*)(ulong)(stbi__err("too large") != 0 ? 0 : 0);
if (compression == 0 && bitdepth == 16 && bpc == 16)
{
_out_ = (byte*)stbi__malloc_mad3(8, w, h, 0);
ri->bits_per_channel = 16;
}
else
{
_out_ = (byte*)stbi__malloc((ulong)(4 * w * h));
}
if (_out_ == null)
return (byte*)(ulong)(stbi__err("outofmem") != 0 ? 0 : 0);
pixelCount = w * h;
if (compression != 0)
{
stbi__skip(s, h * channelCount * 2);
for (channel = 0; channel < 4; channel++)
{
byte* p;
p = _out_ + channel;
if (channel >= channelCount)
{
for (i = 0; i < pixelCount; i++, p += 4)
*p = (byte)(channel == 3 ? 255 : 0);
}
else
{
if (stbi__psd_decode_rle(s, p, pixelCount) == 0)
{
CRuntime.free(_out_);
return (byte*)(ulong)(stbi__err("corrupt") != 0 ? 0 : 0);
}
}
}
}
else
{
for (channel = 0; channel < 4; channel++)
if (channel >= channelCount)
{
if (bitdepth == 16 && bpc == 16)
{
var q = (ushort*)_out_ + channel;
var val = (ushort)(channel == 3 ? 65535 : 0);
for (i = 0; i < pixelCount; i++, q += 4)
*q = val;
}
else
{
var p = _out_ + channel;
var val = (byte)(channel == 3 ? 255 : 0);
for (i = 0; i < pixelCount; i++, p += 4)
*p = val;
}
}
else
{
if (ri->bits_per_channel == 16)
{
var q = (ushort*)_out_ + channel;
for (i = 0; i < pixelCount; i++, q += 4)
*q = (ushort)stbi__get16be(s);
}
else
{
var p = _out_ + channel;
if (bitdepth == 16)
for (i = 0; i < pixelCount; i++, p += 4)
*p = (byte)(stbi__get16be(s) >> 8);
else
for (i = 0; i < pixelCount; i++, p += 4)
*p = stbi__get8(s);
}
}
}
if (channelCount >= 4)
{
if (ri->bits_per_channel == 16)
for (i = 0; i < w * h; ++i)
{
var pixel = (ushort*)_out_ + 4 * i;
if (pixel[3] != 0 && pixel[3] != 65535)
{
var a = pixel[3] / 65535.0f;
var ra = 1.0f / a;
var inv_a = 65535.0f * (1 - ra);
pixel[0] = (ushort)(pixel[0] * ra + inv_a);
pixel[1] = (ushort)(pixel[1] * ra + inv_a);
pixel[2] = (ushort)(pixel[2] * ra + inv_a);
}
}
else
for (i = 0; i < w * h; ++i)
{
var pixel = _out_ + 4 * i;
if (pixel[3] != 0 && pixel[3] != 255)
{
var a = pixel[3] / 255.0f;
var ra = 1.0f / a;
var inv_a = 255.0f * (1 - ra);
pixel[0] = (byte)(pixel[0] * ra + inv_a);
pixel[1] = (byte)(pixel[1] * ra + inv_a);
pixel[2] = (byte)(pixel[2] * ra + inv_a);
}
}
}
if (req_comp != 0 && req_comp != 4)
{
if (ri->bits_per_channel == 16)
_out_ = (byte*)stbi__convert_format16((ushort*)_out_, 4, req_comp, (uint)w, (uint)h);
else
_out_ = stbi__convert_format(_out_, 4, req_comp, (uint)w, (uint)h);
if (_out_ == null)
return _out_;
}
if (comp != null)
*comp = 4;
*y = h;
*x = w;
return _out_;
}
public static int stbi__psd_info(stbi__context s, int* x, int* y, int* comp)
{
var channelCount = 0;
var dummy = 0;
var depth = 0;
if (x == null)
x = &dummy;
if (y == null)
y = &dummy;
if (comp == null)
comp = &dummy;
if (stbi__get32be(s) != 0x38425053)
{
stbi__rewind(s);
return 0;
}
if (stbi__get16be(s) != 1)
{
stbi__rewind(s);
return 0;
}
stbi__skip(s, 6);
channelCount = stbi__get16be(s);
if (channelCount < 0 || channelCount > 16)
{
stbi__rewind(s);
return 0;
}
*y = (int)stbi__get32be(s);
*x = (int)stbi__get32be(s);
depth = stbi__get16be(s);
if (depth != 8 && depth != 16)
{
stbi__rewind(s);
return 0;
}
if (stbi__get16be(s) != 3)
{
stbi__rewind(s);
return 0;
}
*comp = 4;
return 1;
}
public static int stbi__psd_is16(stbi__context s)
{
var channelCount = 0;
var depth = 0;
if (stbi__get32be(s) != 0x38425053)
{
stbi__rewind(s);
return 0;
}
if (stbi__get16be(s) != 1)
{
stbi__rewind(s);
return 0;
}
stbi__skip(s, 6);
channelCount = stbi__get16be(s);
if (channelCount < 0 || channelCount > 16)
{
stbi__rewind(s);
return 0;
}
depth = stbi__get16be(s);
if (depth != 16)
{
stbi__rewind(s);
return 0;
}
return 1;
}
public static int stbi__psd_decode_rle(stbi__context s, byte* p, int pixelCount)
{
var count = 0;
var nleft = 0;
var len = 0;
count = 0;
while ((nleft = pixelCount - count) > 0)
{
len = stbi__get8(s);
if (len == 128)
{
}
else if (len < 128)
{
len++;
if (len > nleft)
return 0;
count += len;
while (len != 0)
{
*p = stbi__get8(s);
p += 4;
len--;
}
}
else if (len > 128)
{
byte val = 0;
len = 257 - len;
if (len > nleft)
return 0;
val = stbi__get8(s);
count += len;
while (len != 0)
{
*p = val;
p += 4;
len--;
}
}
}
return 1;
}
}
}