2019-03-04 02:45:25 +01:00
|
|
|
|
using System;
|
2019-12-27 07:09:49 +01:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2019-03-04 02:45:25 +01:00
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
|
namespace Ryujinx.Graphics.Texture.Astc
|
2019-03-04 02:45:25 +01:00
|
|
|
|
{
|
2019-12-27 07:09:49 +01:00
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
struct AstcPixel
|
2019-03-04 02:45:25 +01:00
|
|
|
|
{
|
2019-12-27 07:09:49 +01:00
|
|
|
|
internal const int StructSize = 12;
|
2019-03-04 02:45:25 +01:00
|
|
|
|
|
2019-12-27 07:09:49 +01:00
|
|
|
|
public short A;
|
|
|
|
|
public short R;
|
|
|
|
|
public short G;
|
|
|
|
|
public short B;
|
|
|
|
|
|
|
|
|
|
private uint _bitDepthInt;
|
|
|
|
|
|
|
|
|
|
private Span<byte> BitDepth => MemoryMarshal.CreateSpan(ref Unsafe.As<uint, byte>(ref _bitDepthInt), 4);
|
|
|
|
|
private Span<short> Components => MemoryMarshal.CreateSpan(ref A, 4);
|
2019-03-04 02:45:25 +01:00
|
|
|
|
|
|
|
|
|
public AstcPixel(short a, short r, short g, short b)
|
|
|
|
|
{
|
|
|
|
|
A = a;
|
|
|
|
|
R = r;
|
|
|
|
|
G = g;
|
|
|
|
|
B = b;
|
|
|
|
|
|
2019-12-27 07:09:49 +01:00
|
|
|
|
_bitDepthInt = 0x08080808;
|
2019-03-04 02:45:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClampByte()
|
|
|
|
|
{
|
|
|
|
|
R = Math.Min(Math.Max(R, (short)0), (short)255);
|
|
|
|
|
G = Math.Min(Math.Max(G, (short)0), (short)255);
|
|
|
|
|
B = Math.Min(Math.Max(B, (short)0), (short)255);
|
|
|
|
|
A = Math.Min(Math.Max(A, (short)0), (short)255);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public short GetComponent(int index)
|
|
|
|
|
{
|
2019-12-27 07:09:49 +01:00
|
|
|
|
return Components[index];
|
2019-03-04 02:45:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetComponent(int index, int value)
|
|
|
|
|
{
|
2019-12-27 07:09:49 +01:00
|
|
|
|
Components[index] = (short)value;
|
2019-03-04 02:45:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Pack()
|
|
|
|
|
{
|
2019-12-27 07:09:49 +01:00
|
|
|
|
return A << 24 |
|
|
|
|
|
B << 16 |
|
|
|
|
|
G << 8 |
|
|
|
|
|
R << 0;
|
2019-03-04 02:45:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adds more precision to the blue channel as described
|
|
|
|
|
// in C.2.14
|
|
|
|
|
public static AstcPixel BlueContract(int a, int r, int g, int b)
|
|
|
|
|
{
|
|
|
|
|
return new AstcPixel((short)(a),
|
|
|
|
|
(short)((r + b) >> 1),
|
|
|
|
|
(short)((g + b) >> 1),
|
|
|
|
|
(short)(b));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|