Skip to content

Commit 7a95ee6

Browse files
committed
Move around test files
1 parent 1256e8a commit 7a95ee6

45 files changed

Lines changed: 2451 additions & 1610 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BCnEnc.Net/Decoder/BcDecoder.cs

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private BCnTextureData DecodeInternal(BCnTextureData texture, CompressionFormat
230230
throw new NotSupportedException($"This Format is not supported: {texture.Format}");
231231
}
232232

233-
var outputAlphaChannelhint = OutputOptions.AlphaHandling == AlphaHandling.Unpremultiply
233+
var outputAlphaChannelhint = OutputOptions.AlphaHandling == DecoderAlphaHandling.Unpremultiply
234234
? AlphaChannelHint.Straight
235235
: texture.AlphaChannelHint;
236236

@@ -260,7 +260,7 @@ private BCnTextureData DecodeInternal(BCnTextureData texture, CompressionFormat
260260
// Apply alpha handling if needed
261261
if (texture.Format.SupportsAlpha() && !texture.Format.IsHdrFormat())
262262
{
263-
if (OutputOptions.AlphaHandling == AlphaHandling.Unpremultiply &&
263+
if (OutputOptions.AlphaHandling == DecoderAlphaHandling.Unpremultiply &&
264264
texture.AlphaChannelHint == AlphaChannelHint.Premultiplied)
265265
{
266266

@@ -338,7 +338,7 @@ private void DecodeRawInternal(ReadOnlyMemory<byte> input, Memory<byte> output,
338338
// Apply alpha handling if needed
339339
if (inputFormat.SupportsAlpha() && !inputFormat.IsHdrFormat())
340340
{
341-
if (OutputOptions.AlphaHandling == AlphaHandling.Unpremultiply)
341+
if (OutputOptions.AlphaHandling == DecoderAlphaHandling.Unpremultiply)
342342
{
343343
AlphaHandlingHelper.UnpremultiplyAlpha(resultSpan);
344344
}
@@ -401,57 +401,12 @@ private void DecodeBlockInternal<TOut>(ReadOnlySpan<byte> blockData, Memory2D<TO
401401
#region Get decoder
402402
private IBcDecoder GetDecoder(CompressionFormat format)
403403
{
404+
if (format.IsRawPixelFormat())
405+
{
406+
return Activator.CreateInstance(typeof(RawDecoder<>).MakeGenericType(format.GetPixelType())) as IBcDecoder;
407+
}
404408
switch (format)
405409
{
406-
case CompressionFormat.R8:
407-
return new RawDecoder<ColorR8>();
408-
409-
case CompressionFormat.R8S:
410-
return new RawDecoder<ColorR8S>();
411-
412-
case CompressionFormat.R8G8:
413-
return new RawDecoder<ColorR8G8>();
414-
415-
case CompressionFormat.R8G8S:
416-
return new RawDecoder<ColorR8G8S>();
417-
418-
case CompressionFormat.R10G10B10A2_Packed:
419-
return new RawDecoder<ColorR10G10B10A2Packed>();
420-
421-
case CompressionFormat.Rgb24:
422-
case CompressionFormat.Rgb24_sRGB:
423-
return new RawDecoder<ColorRgb24>();
424-
425-
case CompressionFormat.Bgr24:
426-
case CompressionFormat.Bgr24_sRGB:
427-
return new RawDecoder<ColorBgr24>();
428-
429-
case CompressionFormat.Rgba32:
430-
case CompressionFormat.Rgba32_sRGB:
431-
return new RawDecoder<ColorRgba32>();
432-
433-
case CompressionFormat.Bgra32:
434-
case CompressionFormat.Bgra32_sRGB:
435-
return new RawDecoder<ColorBgra32>();
436-
437-
case CompressionFormat.RgbaFloat:
438-
return new RawDecoder<ColorRgbaFloat>();
439-
440-
case CompressionFormat.RgbaHalf:
441-
return new RawDecoder<ColorRgbaHalf>();
442-
443-
case CompressionFormat.RgbFloat:
444-
return new RawDecoder<ColorRgbFloat>();
445-
446-
case CompressionFormat.RgbHalf:
447-
return new RawDecoder<ColorRgbHalf>();
448-
449-
case CompressionFormat.Rgbe32:
450-
return new RawDecoder<ColorRgbe>();
451-
452-
case CompressionFormat.Xyze32:
453-
return new RawDecoder<ColorXyze>();
454-
455410
case CompressionFormat.Bc1:
456411
case CompressionFormat.Bc1_sRGB:
457412
return new Bc1NoAlphaDecoder();

BCnEnc.Net/Decoder/Options/DecoderOutputOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public enum OutputColorSpaceTarget
6565
/// <summary>
6666
/// Controls how transparency (alpha channel) is handled during decoding.
6767
/// </summary>
68-
public enum AlphaHandling
68+
public enum DecoderAlphaHandling
6969
{
7070
/// <summary>
7171
/// Decode alpha channel exactly as stored without modification.
@@ -120,7 +120,7 @@ public class DecoderOutputOptions
120120
/// <summary>
121121
/// Controls how transparency (alpha channel) is handled during decoding.
122122
/// </summary>
123-
public AlphaHandling AlphaHandling { get; set; } = AlphaHandling.KeepAsIs;
123+
public DecoderAlphaHandling AlphaHandling { get; set; } = DecoderAlphaHandling.KeepAsIs;
124124

125125
/// <summary>
126126
/// Whether to rescale signed normalized values [-1, 1] to unsigned normalized values [0, 1], when applicable.

BCnEnc.Net/Encoder/AtcBlockEncoder.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@ public override AtcBlock EncodeBlock(RawBlock4X4RgbaFloat block, CompressionQual
1717
{
1818
var atcBlock = new AtcBlock();
1919

20+
Bc1Block bc1Block;
2021
// EncodeBlock with BC1 first
21-
var bc1Block = bc1BlockEncoder.EncodeBlock(block, quality, colorConversionMode);
22+
switch (quality)
23+
{
24+
case CompressionQuality.Fast:
25+
case CompressionQuality.Balanced:
26+
bc1Block = Bc1BlockEncoder.Bc1BlockEncoderBalanced.EncodeBlock(block, false);
27+
break;
28+
case CompressionQuality.BestQuality:
29+
bc1Block = Bc1BlockEncoder.Bc1BlockEncoderSlow.EncodeBlock(block, false);
30+
break;
31+
default:
32+
throw new ArgumentOutOfRangeException(nameof(quality), quality, null);
33+
}
2234

2335
// Atc specific modifications to BC1
2436
// According to http://www.guildsoftware.com/papers/2012.Converting.DXTC.to.Atc.pdf

BCnEnc.Net/Encoder/Bc1BlockEncoder.cs

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Diagnostics;
3+
using System.Numerics;
24
using BCnEncoder.Shared;
35
using BCnEncoder.Shared.Colors;
46

@@ -97,27 +99,44 @@ internal static Bc1Block EncodeBlock(RawBlock4X4RgbaFloat rawBlock, bool useColo
9799
{
98100
var pixels = rawBlock.AsSpan;
99101

100-
PcaVectors.Create(pixels, out var mean, out var pa);
102+
int blacks = 0;
103+
Vector4 mean, pa;
104+
105+
if (useColorModeSwitch)
106+
{
107+
blacks = PcaVectors.CreateIgnoreBlacks(pixels, out mean, out pa);
108+
}
109+
else
110+
{
111+
PcaVectors.Create(pixels, out mean, out pa);
112+
}
113+
101114
PcaVectors.GetMinMaxColor565(pixels, mean, pa, out var min, out var max);
102115

103116
var c0 = max;
104117
var c1 = min;
105118

106-
if (c0.data < c1.data)
119+
(c0, c1) = useColorModeSwitch switch
107120
{
108-
(c0, c1) = (c1, c0);
109-
}
121+
true when c0.data < c1.data && blacks == 0 => (c1, c0),
122+
true when c0.data > c1.data && blacks > 0 => (c1, c0),
123+
false when c0.data < c1.data => (c1, c0),
124+
_ => (c0, c1)
125+
};
110126

111127
var best = TryColors(rawBlock, c0, c1, useColorModeSwitch, out var bestError);
112128

113129
for (var i = 0; i < MaxTries; i++)
114130
{
115131
var (newC0, newC1) = ColorVariationGenerator.Variate565(c0, c1, i);
116132

117-
if (newC0.data < newC1.data)
133+
(newC0, newC1) = useColorModeSwitch switch
118134
{
119-
(newC0, newC1) = (newC1, newC0);
120-
}
135+
true when newC0.data < newC1.data && blacks == 0 => (newC1, newC0),
136+
true when newC0.data > newC1.data && blacks > 0 => (newC1, newC0),
137+
false when newC0.data < newC1.data => (newC1, newC0),
138+
_ => (newC0, newC1)
139+
};
121140

122141
var block = TryColors(rawBlock, newC0, newC1, useColorModeSwitch, out var error);
123142

@@ -148,16 +167,30 @@ internal static Bc1Block EncodeBlock(RawBlock4X4RgbaFloat rawBlock, bool useColo
148167
{
149168
var pixels = rawBlock.AsSpan;
150169

151-
PcaVectors.Create(pixels, out var mean, out var pa);
170+
int blacks = 0;
171+
Vector4 mean, pa;
172+
173+
if (useColorModeSwitch)
174+
{
175+
blacks = PcaVectors.CreateIgnoreBlacks(pixels, out mean, out pa);
176+
}
177+
else
178+
{
179+
PcaVectors.Create(pixels, out mean, out pa);
180+
}
181+
152182
PcaVectors.GetMinMaxColor565(pixels, mean, pa, out var min, out var max);
153183

154184
var c0 = max;
155185
var c1 = min;
156186

157-
if (c0.data < c1.data)
187+
(c0, c1) = useColorModeSwitch switch
158188
{
159-
(c0, c1) = (c1, c0);
160-
}
189+
true when c0.data < c1.data && blacks == 0 => (c1, c0),
190+
true when c0.data > c1.data && blacks > 0 => (c1, c0),
191+
false when c0.data < c1.data => (c1, c0),
192+
_ => (c0, c1)
193+
};
161194

162195
var best = TryColors(rawBlock, c0, c1, useColorModeSwitch, out var bestError);
163196

@@ -167,10 +200,13 @@ internal static Bc1Block EncodeBlock(RawBlock4X4RgbaFloat rawBlock, bool useColo
167200
{
168201
var (newC0, newC1) = ColorVariationGenerator.Variate565(c0, c1, i);
169202

170-
if (newC0.data < newC1.data)
203+
(newC0, newC1) = useColorModeSwitch switch
171204
{
172-
(newC0, newC1) = (newC1, newC0);
173-
}
205+
true when newC0.data < newC1.data && blacks == 0 => (newC1, newC0),
206+
true when newC0.data > newC1.data && blacks > 0 => (newC1, newC0),
207+
false when newC0.data < newC1.data => (newC1, newC0),
208+
_ => (newC0, newC1)
209+
};
174210

175211
var block = TryColors(rawBlock, newC0, newC1, useColorModeSwitch, out var error);
176212

0 commit comments

Comments
 (0)