-
Notifications
You must be signed in to change notification settings - Fork 6
Add R11G11B10FloatToBGRA32 #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
AssetRipper.TextureDecoder.Tests/Formats/ColorRGB32HalfTests.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| //This code is source generated. Do not edit manually. | ||
|
|
||
| using AssetRipper.TextureDecoder.Rgb; | ||
| using AssetRipper.TextureDecoder.Rgb.Formats; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| namespace AssetRipper.TextureDecoder.Tests.Formats; | ||
|
|
||
| public partial class ColorRGB32HalfTests | ||
| { | ||
| [Test] | ||
| public void CorrectSizeTest() | ||
| { | ||
| Assert.That(Unsafe.SizeOf<ColorRGB32Half>(), Is.EqualTo(4)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PropertyIsSymmetric_R() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var r = color.R; | ||
| color.R = r; | ||
| Assert.That(color.R, Is.EqualTo(r)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PropertyIsSymmetric_G() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var g = color.G; | ||
| color.G = g; | ||
| Assert.That(color.G, Is.EqualTo(g)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PropertyIsSymmetric_B() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var b = color.B; | ||
| color.B = b; | ||
| Assert.That(color.B, Is.EqualTo(b)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PropertyIsSymmetric_A() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var a = color.A; | ||
| color.A = a; | ||
| Assert.That(color.A, Is.EqualTo(a)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ChannelsAreIndependent_R() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var g = color.G; | ||
| var b = color.B; | ||
| var a = color.A; | ||
| color.R = (Half)0.333f; | ||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(color.G, Is.EqualTo(g)); | ||
| Assert.That(color.B, Is.EqualTo(b)); | ||
| Assert.That(color.A, Is.EqualTo(a)); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ChannelsAreIndependent_G() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var r = color.R; | ||
| var b = color.B; | ||
| var a = color.A; | ||
| color.G = (Half)0.333f; | ||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(color.R, Is.EqualTo(r)); | ||
| Assert.That(color.B, Is.EqualTo(b)); | ||
| Assert.That(color.A, Is.EqualTo(a)); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ChannelsAreIndependent_B() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var r = color.R; | ||
| var g = color.G; | ||
| var a = color.A; | ||
| color.B = (Half)0.333f; | ||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(color.R, Is.EqualTo(r)); | ||
| Assert.That(color.G, Is.EqualTo(g)); | ||
| Assert.That(color.A, Is.EqualTo(a)); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ChannelsAreIndependent_A() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| var r = color.R; | ||
| var g = color.G; | ||
| var b = color.B; | ||
| color.A = (Half)0.333f; | ||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(color.R, Is.EqualTo(r)); | ||
| Assert.That(color.G, Is.EqualTo(g)); | ||
| Assert.That(color.B, Is.EqualTo(b)); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void GetMethodMatchesProperties() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| color.GetChannels(out var r, out var g, out var b, out var a); | ||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(color.R, Is.EqualTo(r)); | ||
| Assert.That(color.G, Is.EqualTo(g)); | ||
| Assert.That(color.B, Is.EqualTo(b)); | ||
| Assert.That(color.A, Is.EqualTo(a)); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MethodsAreSymmetric() | ||
| { | ||
| var color = MakeRandomColor(); | ||
| color.GetChannels(out var r, out var g, out var b, out var a); | ||
| color.SetChannels(r, g, b, a); | ||
| Assert.Multiple(() => | ||
| { | ||
| Assert.That(color.R, Is.EqualTo(r)); | ||
| Assert.That(color.G, Is.EqualTo(g)); | ||
| Assert.That(color.B, Is.EqualTo(b)); | ||
| Assert.That(color.A, Is.EqualTo(a)); | ||
| }); | ||
| } | ||
|
|
||
| public static ColorRGB32Half MakeRandomColor() | ||
| { | ||
| return new() | ||
| { | ||
| R = (Half)0.447f, | ||
| G = (Half)0.224f, | ||
| B = (Half)0.95f, | ||
| A = (Half)0.897f, | ||
| }; | ||
| } | ||
|
|
||
| [Test] | ||
| public void ConversionToColorRGBAHalfIsLossless() | ||
| { | ||
| ColorRGB32Half original = MakeRandomColor(); | ||
| ColorRGBAHalf converted = original.Convert<ColorRGB32Half, Half, ColorRGBAHalf, Half>(); | ||
| ColorRGB32Half convertedBack = converted.Convert<ColorRGBAHalf, Half, ColorRGB32Half, Half>(); | ||
| Assert.That(convertedBack, Is.EqualTo(original)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ConversionToColorRGBASingleIsLossless() | ||
| { | ||
| ColorRGB32Half original = MakeRandomColor(); | ||
| ColorRGBASingle converted = original.Convert<ColorRGB32Half, Half, ColorRGBASingle, float>(); | ||
| ColorRGB32Half convertedBack = converted.Convert<ColorRGBASingle, float, ColorRGB32Half, Half>(); | ||
| Assert.That(convertedBack, Is.EqualTo(original)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ConversionToColorRGBHalfIsLossless() | ||
| { | ||
| ColorRGB32Half original = MakeRandomColor(); | ||
| ColorRGBHalf converted = original.Convert<ColorRGB32Half, Half, ColorRGBHalf, Half>(); | ||
| ColorRGB32Half convertedBack = converted.Convert<ColorRGBHalf, Half, ColorRGB32Half, Half>(); | ||
| Assert.That(convertedBack, Is.EqualTo(original)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ConversionToColorRGBSingleIsLossless() | ||
| { | ||
| ColorRGB32Half original = MakeRandomColor(); | ||
| ColorRGBSingle converted = original.Convert<ColorRGB32Half, Half, ColorRGBSingle, float>(); | ||
| ColorRGB32Half convertedBack = converted.Convert<ColorRGBSingle, float, ColorRGB32Half, Half>(); | ||
| Assert.That(convertedBack, Is.EqualTo(original)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| namespace AssetRipper.TextureDecoder.Rgb.Formats | ||
| { | ||
| /// <summary> | ||
| /// Also called R11G11B10_FLOAT | ||
| /// </summary> | ||
neptuwunium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <remarks> | ||
| /// <see href="https://github.com/microsoft/DirectX-Graphics-Samples/blob/e5ea2ac7430ce39e6f6d619fd85ae32581931589/MiniEngine/Core/Shaders/PixelPacking_R11G11B10.hlsli#L31-L37" /> | ||
| /// </remarks> | ||
| public partial struct ColorRGB32Half : IColor<Half> | ||
| { | ||
| private uint bits; | ||
|
|
||
| /// <summary> | ||
| /// 11 bits | ||
| /// </summary> | ||
| public Half R { | ||
| get { | ||
| var value = (ushort) ((bits << 4) & 0x7FF0); | ||
| return Unsafe.As<ushort, Half>(ref value); | ||
| } | ||
| set => bits = (uint) ((bits & ~0x7FF) | ((uint) Unsafe.As<Half, ushort>(ref value) & 0x7FF0) >> 4); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 11 bits | ||
| /// </summary> | ||
| public Half G { | ||
| get { | ||
| var value = (ushort) ((bits >> 7) & 0x7FF0); | ||
| return Unsafe.As<ushort, Half>(ref value); | ||
| } | ||
| set => bits = (uint) ((bits & ~0x3FF800) | (((uint) Unsafe.As<Half, ushort>(ref value) >> 4) & 0x7FF0) << 11); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 10 bits | ||
| /// </summary> | ||
| public Half B { | ||
| get { | ||
| var value = (ushort) ((bits >> 17) & 0x7FE0); | ||
| return Unsafe.As<ushort, Half>(ref value); | ||
| } | ||
| set => bits = (bits & ~0xFFC00000) | ((((uint) Unsafe.As<Half, ushort>(ref value) >> 5) & 0x3FF) << 22); | ||
| } | ||
|
|
||
| public Half A | ||
| { | ||
| get => (Half) 1.0f; | ||
| set { } | ||
| } | ||
|
|
||
| public void GetChannels(out Half r, out Half g, out Half b, out Half a) | ||
| { | ||
| DefaultColorMethods.GetChannels(this, out r, out g, out b, out a); | ||
| } | ||
|
|
||
| public void SetChannels(Half r, Half g, Half b, Half a) | ||
| { | ||
| bits = (((uint) Unsafe.As<Half, ushort>(ref r) >> 4) & 0x7FF) | | ||
| ((((uint) Unsafe.As<Half, ushort>(ref g) >> 4) & 0x7FF) << 11) | | ||
| ((((uint) Unsafe.As<Half, ushort>(ref b) >> 5) & 0x3FF) << 22); | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB32Half.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //This code is source generated. Do not edit manually. | ||
|
|
||
| using AssetRipper.TextureDecoder.Attributes; | ||
|
|
||
| namespace AssetRipper.TextureDecoder.Rgb.Formats | ||
| { | ||
| [RgbaAttribute(RedChannel = true, GreenChannel = true, BlueChannel = true, AlphaChannel = false, FullyUtilizedChannels = false)] | ||
| public partial struct ColorRGB32Half : IColor<Half> | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.