mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-04-27 12:30:50 -07:00
* dotnet format style --severity info Some changes were manually reverted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format CA2208 warnings * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Address IDE0251 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Address review feedback * Update src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Ryujinx.Graphics.Texture.Astc
|
|
{
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
struct AstcPixel
|
|
{
|
|
internal const int StructSize = 12;
|
|
|
|
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);
|
|
|
|
public AstcPixel(short a, short r, short g, short b)
|
|
{
|
|
A = a;
|
|
R = r;
|
|
G = g;
|
|
B = b;
|
|
|
|
_bitDepthInt = 0x08080808;
|
|
}
|
|
|
|
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)
|
|
{
|
|
return Components[index];
|
|
}
|
|
|
|
public void SetComponent(int index, int value)
|
|
{
|
|
Components[index] = (short)value;
|
|
}
|
|
|
|
public readonly int Pack()
|
|
{
|
|
return A << 24 |
|
|
B << 16 |
|
|
G << 8 |
|
|
R << 0;
|
|
}
|
|
|
|
// 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));
|
|
}
|
|
}
|
|
}
|