82 lines
2 KiB
C#
82 lines
2 KiB
C#
|
|
using System.Runtime.CompilerServices;
|
||
|
|
using System.Runtime.InteropServices;
|
||
|
|
using SixLabors.ImageSharp.PixelFormats;
|
||
|
|
|
||
|
|
namespace StitchATon2.Infra;
|
||
|
|
|
||
|
|
[StructLayout(LayoutKind.Sequential)]
|
||
|
|
public record struct Int32Pixel
|
||
|
|
{
|
||
|
|
public static int Size
|
||
|
|
{
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
get => Unsafe.SizeOf<Int32Pixel>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static Int32Pixel Zero
|
||
|
|
{
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
get => new();
|
||
|
|
}
|
||
|
|
|
||
|
|
public int R;
|
||
|
|
public int G;
|
||
|
|
public int B;
|
||
|
|
|
||
|
|
public Int32Pixel(int r, int g, int b)
|
||
|
|
{
|
||
|
|
R = r;
|
||
|
|
G = g;
|
||
|
|
B = b;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Accumulate(Int32Pixel pixel)
|
||
|
|
{
|
||
|
|
R += pixel.R;
|
||
|
|
G += pixel.G;
|
||
|
|
B += pixel.B;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Accumulate(Rgb24 pixel)
|
||
|
|
{
|
||
|
|
R += pixel.R;
|
||
|
|
G += pixel.G;
|
||
|
|
B += pixel.B;
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
public static Int32Pixel operator +(Int32Pixel a, Int32Pixel b)
|
||
|
|
{
|
||
|
|
return new Int32Pixel(a.R + b.R, a.G + b.G, a.B + b.B);
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
public static Int32Pixel operator +(Int32Pixel a, int b)
|
||
|
|
{
|
||
|
|
return new Int32Pixel(a.R + b, a.G + b, a.B + b);
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
public static Int32Pixel operator -(Int32Pixel a, Int32Pixel b)
|
||
|
|
{
|
||
|
|
return new Int32Pixel(a.R - b.R, a.G - b.G, a.B - b.B);
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
public static Int32Pixel operator /(Int32Pixel a, int b)
|
||
|
|
{
|
||
|
|
return new Int32Pixel(a.R / b, a.G / b, a.B / b);
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
public static explicit operator Int32Pixel(Rgb24 pixel)
|
||
|
|
{
|
||
|
|
return new Int32Pixel(pixel.R, pixel.G, pixel.B);
|
||
|
|
}
|
||
|
|
|
||
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
|
public static explicit operator Rgb24(Int32Pixel pixel)
|
||
|
|
{
|
||
|
|
return new Rgb24((byte)pixel.R, (byte)pixel.G, (byte)pixel.B);
|
||
|
|
}
|
||
|
|
}
|