daily update on 20250122 by nitload youmu, architect rearrange
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Internal;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Math;
|
||||
|
||||
@@ -41,6 +41,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StgSharp.Internal.OpenGL;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
@@ -106,7 +107,7 @@ namespace StgSharp.Graphics
|
||||
internal set => _rawInfo.Width = value;
|
||||
}
|
||||
|
||||
public int PixelSize => GlHelper.GetPixelSize(
|
||||
public int PixelSize => ImageInfo.GetPixelSize(
|
||||
_rawInfo.pixelLayout, _rawInfo.Channel );
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
@@ -173,7 +174,7 @@ namespace StgSharp.Graphics
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if( _data.Length == 0 ) {
|
||||
int size = Width * Height * GlHelper.GetPixelSize(
|
||||
int size = Width * Height * ImageInfo.GetPixelSize(
|
||||
PixelLayout, Channel );
|
||||
_data = new Span<byte>( ( byte* )_rawInfo.StreamPtr,
|
||||
size ).ToArray();
|
||||
@@ -207,76 +208,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
|
||||
private ImageChannel channel;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
internal PixelChannelLayout pixelLayout;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => GlHelper.GetChannelCount( channel );
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * GlHelper.GetPixelSize(
|
||||
pixelLayout, channel );
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 17 + width;
|
||||
hash = hash * 17 + height;
|
||||
hash = hash * 17 + ( int )channel;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
|
||||
SingleColor = GLconst.RED,
|
||||
DoubleColor = GLconst.RG,
|
||||
TripleColor = GLconst.RGB,
|
||||
WithAlphaChannel = GLconst.RGBA,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
@@ -284,54 +215,5 @@ namespace StgSharp.Graphics.OpenGL
|
||||
public static partial class GlHelper
|
||||
{
|
||||
|
||||
internal static int GetChannelCount( ImageChannel channel )
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
ImageChannel.SingleColor => 1,
|
||||
ImageChannel.DoubleColor => 2,
|
||||
ImageChannel.TripleColor => 3,
|
||||
ImageChannel.WithAlphaChannel => 4,
|
||||
_ => throw new InvalidCastException(
|
||||
"Unknown color channel decoding setting." )
|
||||
};
|
||||
}
|
||||
|
||||
internal static int GetPixelSize(
|
||||
PixelChannelLayout layout,
|
||||
ImageChannel cahnnel )
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.UByte => sizeof( byte ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.Byte => sizeof( byte ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.UShort => sizeof( short ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.Short => sizeof( short ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.UInt => sizeof( int ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.Int => sizeof( int ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.Float => sizeof( float ) * GetChannelCount(
|
||||
cahnnel ),
|
||||
PixelChannelLayout.UByte332 => sizeof( byte ),
|
||||
PixelChannelLayout.UByte233Rev => sizeof( byte ),
|
||||
PixelChannelLayout.UShort565 => sizeof( short ),
|
||||
PixelChannelLayout.UShort565Rev => sizeof( short ),
|
||||
PixelChannelLayout.UShort4444 => sizeof( short ),
|
||||
PixelChannelLayout.UShort4444Rev => sizeof( short ),
|
||||
PixelChannelLayout.UShort5551 => sizeof( short ),
|
||||
PixelChannelLayout.UShort1555Rev => sizeof( short ),
|
||||
PixelChannelLayout.UInt8888 => sizeof( int ),
|
||||
PixelChannelLayout.UInt8888Rev => sizeof( int ),
|
||||
PixelChannelLayout.UInt1010102 => sizeof( int ),
|
||||
PixelChannelLayout.UInt2101010Rev => sizeof( int ),
|
||||
_ => throw new ArgumentException( "Unknown layout type" ),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user