daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
+72 -50
View File
@@ -46,15 +46,9 @@ namespace StgSharp.Graphics
{
public class Image : ISSDSerializable, IImageProvider
{
internal byte[] data;
internal ImageInfo info;
public PixelChannelLayout PixelLayout
{
get => info.pixelLayout;
private set => info.pixelLayout = value;
}
private byte[] _data;
private ImageInfo info;
private int _pixelUpdateCount = 0;
internal unsafe Image()
{
@@ -64,15 +58,42 @@ namespace StgSharp.Graphics
internal Image(ImageInfo information)
{
info = information;
data = Array.Empty<byte>();
_data = Array.Empty<byte>();
//int length = info.width * info.height * info.channel;
}
internal ref byte[] Data
{
get => ref _data;
}
public (int width, int height) Size
{
get => (info.Width, info.Height);
}
/// <summary>
/// Hash code of time pixels updated last time.
/// </summary>
public int PixelUpdateCount
{
get => _pixelUpdateCount;
internal set => _pixelUpdateCount = value;
}
public byte[] PixelBuffer
{
get
{
if ((_data.Length == 0) || (_data == null))
{
GetBytes();
return _data!;
}
return _data;
}
}
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height
@@ -89,6 +110,12 @@ namespace StgSharp.Graphics
public int PixelSize => GlHelper.GetPixelSize(info.pixelLayout, info.Channel);
public PixelChannelLayout PixelLayout
{
get => info.pixelLayout;
private set => info.pixelLayout = value;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
public void FromBytes(byte[] stream)
@@ -106,21 +133,6 @@ namespace StgSharp.Graphics
return ret;
}
public static Image FromMemory((int width, int height) size, ImageChannel channel, PixelChannelLayout layout, byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.PixelLayout = layout;
ret.data = stream;
return ret;
}
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
{
ImageInfo _info = new ImageInfo
@@ -132,35 +144,38 @@ namespace StgSharp.Graphics
};
Image ret = new Image(_info);
ret.PixelLayout = PixelChannelLayout.Byte;
ret.data = stream;
ret._data = stream;
return ret;
}
public static Image FromMemory((int width, int height) size, ImageChannel channel, PixelChannelLayout layout, byte[] stream)
{
ImageInfo _info = new ImageInfo
{
Height = size.height,
Width = size.width,
Channel = channel,
StreamPtr = IntPtr.Zero
};
Image ret = new Image(_info);
ret.PixelLayout = layout;
ret._data = stream;
return ret;
}
public unsafe byte[] GetBytes()
{
if (data.Length == 0)
if (_data.Length == 0)
{
int size = Width * Height * GlHelper.GetPixelSize(PixelLayout, Channel);
_data = new Span<byte>((byte*)info.StreamPtr, size).ToArray();
fixed (ImageInfo* pptr = &info)
{
int size = Width * Height * GlHelper.GetPixelSize(PixelLayout, Channel);
data = new Span<byte>((byte*)info.StreamPtr, size).ToArray();
fixed (ImageInfo* pptr = &info)
{
InternalIO.InternalUnloadImage(pptr);
}
info.StreamPtr = IntPtr.Zero;
InternalIO.InternalUnloadImage(pptr);
}
return data;
}
public byte[] PixelBuffer
{
get{
if ((data.Length == 0) || (data == null))
{
GetBytes();
return data!;
}
return data;
info.StreamPtr = IntPtr.Zero;
}
return _data;
}
public Image ProvideImage() => this;
@@ -168,6 +183,7 @@ namespace StgSharp.Graphics
{
throw new NotImplementedException();
}
}
[StructLayout(LayoutKind.Sequential)]
@@ -183,10 +199,7 @@ namespace StgSharp.Graphics
public ImageChannel Channel
{
get => channel;
set
{
channel = value;
}
set { channel = value; }
}
public int ChannelCount
@@ -222,6 +235,14 @@ namespace StgSharp.Graphics
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
}
public override int GetHashCode()
{
int hash = 17;
hash = hash * 17 + width;
hash = hash * 17 + height;
hash = hash * 17 + (int)channel;
return hash;
}
}
public enum ImageChannel : uint
@@ -276,5 +297,6 @@ namespace StgSharp.Graphics.OpenGL
_ => throw new ArgumentException("Unknown layout type"),
};
}
}
}