Skip to content

Commit 70cdd61

Browse files
committed
New test gen scripts, fixed some formats
1 parent b7804b4 commit 70cdd61

10 files changed

Lines changed: 545 additions & 31 deletions

File tree

BCnEnc.Net/Shared/CompressionFormat.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88
namespace BCnEncoder.Shared
99
{
1010
// ReSharper disable InconsistentNaming
11+
/// <summary>
12+
/// Identifies a texture compression or raw pixel format.
13+
///
14+
/// <para><b>Non-packed formats</b> (e.g. <see cref="Rgba32"/>, <see cref="Bgr24"/>) store each
15+
/// component in its own byte. The component order in the name reflects memory layout: the first
16+
/// component in the name is at the lowest memory address.</para>
17+
///
18+
/// <para><b>Packed formats</b> (e.g. <see cref="R4G4B4A4_Packed"/>, <see cref="B5G6R5_Packed"/>)
19+
/// pack multiple components into a single integer. The naming convention follows DirectX/DXGI:
20+
/// the first component in the name occupies the <em>least-significant</em> bits of the integer
21+
/// (LSB → MSB). This keeps packed and non-packed names consistent on little-endian hardware,
22+
/// where the lowest-address byte is also the least-significant byte of any multi-byte value.</para>
23+
///
24+
/// <para><b>Vulkan/OpenGL/KTX note:</b> those APIs use the opposite convention for packed formats —
25+
/// the first component in the name is the <em>most-significant</em> (MSB → LSB). When mapping
26+
/// to or from Vulkan format names, the component order in the name will appear reversed.
27+
/// For example, <see cref="R4G4B4A4_Packed"/> (R in bits [3:0], A in bits [15:12]) corresponds
28+
/// to <c>VK_FORMAT_A4B4G4R4_UNORM_PACK16</c>.</para>
29+
/// </summary>
1130
public enum CompressionFormat
1231
{
1332
/// <summary>
@@ -159,98 +178,98 @@ public enum CompressionFormat
159178
// ==== PACKED Formats ====
160179

161180
/// <summary>
162-
/// 32-bit packed format with 2-bit Alpha, 10-bit Blue, 10-bit Green, and 10-bit Red components.
181+
/// 32-bit packed format with 10-bit Red, 10-bit Green, 10-bit Blue, and 2-bit Alpha components.
163182
/// Bits ordered from MSB to LSB as: A[31:30] B[29:20] G[19:10] R[9:0].
164183
/// Equivalent to VK_FORMAT_A2B10G10R10_UNORM_PACK32 and DXGI_FORMAT_R10G10B10A2_UNORM.
165184
/// </summary>
166185
R10G10B10A2_Packed,
167186

168187
/// <summary>
169-
/// 32-bit packed format with 2-bit Alpha, 10-bit Red, 10-bit Green, and 10-bit Blue components.
188+
/// 32-bit packed format with 10-bit Blue, 10-bit Green, 10-bit Red, and 2-bit Alpha components.
170189
/// Bits ordered from MSB to LSB as: A[31:30] R[29:20] G[19:10] B[9:0].
171190
/// Equivalent to VK_FORMAT_A2R10G10B10_UNORM_PACK32.
172191
/// </summary>
173192
B10G10R10A2_Packed,
174193

175194
/// <summary>
176-
/// 16-bit packed format with 5-bit Red, 6-bit Green, and 5-bit Blue components.
195+
/// 16-bit packed format with 5-bit Blue, 6-bit Green, and 5-bit Red components.
177196
/// Bits ordered from MSB to LSB as: R[15:11] G[10:5] B[4:0].
178197
/// Equivalent to VK_FORMAT_R5G6B5_UNORM_PACK16 and DXGI_FORMAT_B5G6R5_UNORM.
179198
/// </summary>
180199
B5G6R5_Packed,
181200

182201
/// <summary>
183-
/// 16-bit packed format with 5-bit Blue, 6-bit Green, and 5-bit Red components.
202+
/// 16-bit packed format with 5-bit Red, 6-bit Green, and 5-bit Blue components.
184203
/// Bits ordered from MSB to LSB as: B[15:11] G[10:5] R[4:0].
185204
/// Equivalent to VK_FORMAT_B5G6R5_UNORM_PACK16.
186205
/// </summary>
187206
R5G6B5_Packed,
188207

189208
/// <summary>
190-
/// 16-bit packed format with 5-bit Red, 5-bit Green, 5-bit Blue, and 1-bit Alpha components.
209+
/// 16-bit packed format with 1-bit Alpha, 5-bit Blue, 5-bit Green, and 5-bit Red components.
191210
/// Bits ordered from MSB to LSB as: R[15:11] G[10:6] B[5:1] A[0].
192211
/// Equivalent to VK_FORMAT_R5G5B5A1_UNORM_PACK16.
193212
/// </summary>
194213
A1B5G5R5_Packed,
195214

196215
/// <summary>
197-
/// 16-bit packed format with 5-bit Blue, 5-bit Green, 5-bit Red, and 1-bit Alpha components.
216+
/// 16-bit packed format with 1-bit Alpha, 5-bit Red, 5-bit Green, and 5-bit Blue components.
198217
/// Bits ordered from MSB to LSB as: B[15:11] G[10:6] R[5:1] A[0].
199218
/// Equivalent to VK_FORMAT_B5G5R5A1_UNORM_PACK16.
200219
/// </summary>
201220
A1R5G5B5_Packed,
202221

203222
/// <summary>
204-
/// 16-bit packed format with 1-bit Alpha, 5-bit Red, 5-bit Green, and 5-bit Blue components.
223+
/// 16-bit packed format with 5-bit Blue, 5-bit Green, 5-bit Red, and 1-bit Alpha components.
205224
/// Bits ordered from MSB to LSB as: A[15] R[14:10] G[9:5] B[4:0].
206225
/// Equivalent to VK_FORMAT_A1R5G5B5_UNORM_PACK16 and DXGI_FORMAT_B5G5R5A1_UNORM.
207226
/// </summary>
208227
B5G5R5A1_Packed,
209228

210229
/// <summary>
211-
/// 16-bit packed format with 1-bit Alpha, 5-bit Blue, 5-bit Green, and 5-bit Red components.
230+
/// 16-bit packed format with 5-bit Red, 5-bit Green, 5-bit Blue, and 1-bit Alpha components.
212231
/// Bits ordered from MSB to LSB as: A[15] B[14:10] G[9:5] R[4:0].
213232
/// Equivalent to VK_FORMAT_A1B5G5R5_UNORM_PACK16.
214233
/// </summary>
215234
R5G5B5A1_Packed,
216235

217236
/// <summary>
218-
/// 16-bit packed format with 4-bit Red, 4-bit Green, 4-bit Blue, and 4-bit Alpha components.
237+
/// 16-bit packed format with 4-bit Alpha, 4-bit Blue, 4-bit Green, and 4-bit Red components.
219238
/// Bits ordered from MSB to LSB as: R[15:12] G[11:8] B[7:4] A[3:0].
220239
/// Equivalent to VK_FORMAT_R4G4B4A4_UNORM_PACK16 and DXGI_FORMAT_A4B4G4R4_UNORM.
221240
/// </summary>
222241
A4B4G4R4_Packed,
223242

224243
/// <summary>
225-
/// 16-bit packed format with 4-bit Blue, 4-bit Green, 4-bit Red, and 4-bit Alpha components.
244+
/// 16-bit packed format with 4-bit Alpha, 4-bit Red, 4-bit Green, and 4-bit Blue components.
226245
/// Bits ordered from MSB to LSB as: B[15:12] G[11:8] R[7:4] A[3:0].
227246
/// Equivalent to VK_FORMAT_B4G4R4A4_UNORM_PACK16.
228247
/// </summary>
229248
A4R4G4B4_Packed,
230249

231250
/// <summary>
232-
/// 16-bit packed format with 4-bit Alpha, 4-bit Red, 4-bit Green, and 4-bit Blue components.
251+
/// 16-bit packed format with 4-bit Blue, 4-bit Green, 4-bit Red, and 4-bit Alpha components.
233252
/// Bits ordered from MSB to LSB as: A[15:12] R[11:8] G[7:4] B[3:0].
234253
/// Equivalent to VK_FORMAT_A4R4G4B4_UNORM_PACK16 and DXGI_FORMAT_B4G4R4A4_UNORM.
235254
/// </summary>
236255
B4G4R4A4_Packed,
237256

238257
/// <summary>
239-
/// 16-bit packed format with 4-bit Alpha, 4-bit Blue, 4-bit Green, and 4-bit Red components.
258+
/// 16-bit packed format with 4-bit Red, 4-bit Green, 4-bit Blue, and 4-bit Alpha components.
240259
/// Bits ordered from MSB to LSB as: A[15:12] B[11:8] G[7:4] R[3:0].
241260
/// Equivalent to VK_FORMAT_A4B4G4R4_UNORM_PACK16.
242261
/// </summary>
243262
R4G4B4A4_Packed,
244263

245264
/// <summary>
246-
/// 32-bit packed shared-exponent format with 5-bit Exponent, 9-bit Blue, 9-bit Green, and 9-bit Red components.
265+
/// 32-bit packed shared-exponent format with 9-bit Red, 9-bit Green, 9-bit Blue, and 5-bit Exponent components.
247266
/// Bits ordered from MSB to LSB as: E[31:27] B[26:18] G[17:9] R[8:0].
248267
/// Equivalent to VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 and DXGI_FORMAT_R9G9B9E5_SHAREDEXP.
249268
/// </summary>
250269
R9G9B9E5_Packed,
251270

252271
/// <summary>
253-
/// 32-bit packed floating point format with 10-bit Blue, 11-bit Green, and 11-bit Red components.
272+
/// 32-bit packed floating point format with 11-bit Red, 11-bit Green, and 10-bit Blue components.
254273
/// Bits ordered from MSB to LSB as: B[31:22] G[21:11] R[10:0].
255274
/// Equivalent to VK_FORMAT_B10G11R11_UFLOAT_PACK32 and DXGI_FORMAT_R11G11B10_FLOAT.
256275
/// </summary>

BCnEnc.Net/Shared/TextureData.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,16 @@ public static BCnTextureData ConvertTo(this BCnTextureData data, CompressionForm
622622
}
623623
if(data.Format.IsBlockCompressedFormat())
624624
{
625-
throw new ArgumentException(
626-
$"Source format should be a non-block-compressed format. Please use {nameof(BcDecoder)} for decoding from compressed formats!");
625+
BcDecoder decoder = new BcDecoder(new DecoderOptions
626+
{
627+
IsParallel = false
628+
}, new DecoderOutputOptions
629+
{
630+
InputColorSpace = InputColorSpaceAssumption.Auto,
631+
OutputColorSpace = convertColorspace ? OutputColorSpaceTarget.Auto : OutputColorSpaceTarget.KeepAsIs
632+
});
633+
634+
return decoder.Decode(data, format);
627635
}
628636

629637
if (data.Format == format)

BCnEncTests/Api/ApiTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public void TestEncode(bool raw, string name, CompressionFormat format)
8787

8888
Assert.True(inputData.Format != CompressionFormat.Unknown);
8989

90+
if (inputData.Format.IsBlockCompressedFormat())
91+
{
92+
inputData = inputData.ConvertTo(CompressionFormat.RgbaFloat);
93+
}
9094

9195
// Test
9296
var outputData = encoder.Encode(inputData);
@@ -123,15 +127,15 @@ public void TestEncodeBytes(bool raw, string name, CompressionFormat format)
123127

124128
[Theory]
125129
[InlineData("blocks", CompressionFormat.Bc1)]
126-
[InlineData("blocks", CompressionFormat.RgbaFloat)]
130+
[InlineData("blocks", CompressionFormat.R5G5B5A1_Packed)]
127131
public void TestEncodeLdr(string name, CompressionFormat format)
128132
{
129133
var encoder = MakeEncoder(format);
130134

131135
var inputData = LoadTestFile(true, name);
132136

133137
// Test
134-
var outputData = encoder.Encode(inputData.First.AsMemory2D<ColorRgba32>());
138+
var outputData = encoder.EncodeHdr(inputData.First.AsMemory2D<ColorRgbaFloat>());
135139

136140
AssertNonCube(format, outputData, inputData);
137141
ValidateData(encoder, inputData.Width, inputData.Height, inputData.Depth, outputData);
@@ -140,6 +144,8 @@ public void TestEncodeLdr(string name, CompressionFormat format)
140144
[Theory]
141145
[InlineData("hdr_1_rgbe", CompressionFormat.Bc6U)]
142146
[InlineData("hdr_1_rgbe", CompressionFormat.RgbaFloat)]
147+
[InlineData("hdr_1_rgbe", CompressionFormat.R9G9B9E5_Packed)]
148+
[InlineData("hdr_1_rgbe", CompressionFormat.RgbHalf)]
143149
[InlineData("hdr_1_rgbe", CompressionFormat.Bc1)]
144150
public void TestEncodeHdr(string name, CompressionFormat format)
145151
{

BCnEncTests/Api/DecodingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum FileType
2020
Ktx2
2121
}
2222

23-
const string testImageFolderRoot = "testimages";
23+
const string testImageFolderRoot = "testImages";
2424
const string referenceFolder = "reference";
2525

2626
static string[] unsupportedFilter = new string[] { "astc", "eac", "etc1", "etc2", "bc4s", "bc5s", "basisu" };
@@ -121,7 +121,7 @@ public static IEnumerable<object[]> GetTestFiles(string path, string extension)
121121
}
122122
else
123123
{
124-
throw new ArgumentException($"Reference image not found: {refImagePath}");
124+
//throw new ArgumentException($"Reference image not found: {refImagePath}");
125125
}
126126
}
127127

BCnEncTests/Colors/ColorTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,7 @@ public void TestEqualityAndHashCode<TColor, TRaw>(ColorTypeInfo<TColor, TRaw> ty
741741
Assert.Equal(defaultColor.GetHashCode(), zeroColor.GetHashCode());
742742
}
743743

744-
/// <summary>
745-
/// Tests equality operations and hash code consistency for all color types.
746-
/// </summary>
744+
747745
[Theory]
748746
[MemberData(nameof(GetAllPackedColorTypes))]
749747
public void TestPackedColors<TColor, TRaw, TPacked>(ColorTypeInfo<TColor, TRaw> typeInfo, TPacked _)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
# Quality benchmark image generator
3+
# Generates compressed test images for benchmarking quality metrics using cuttlefish
4+
5+
set -euo pipefail
6+
7+
# Define hardcoded paths
8+
INPUT_DIR="testImages/raw"
9+
OUTPUT_DIR="testImages/Quality"
10+
11+
# Create output directory if needed
12+
mkdir -p "$OUTPUT_DIR"
13+
14+
# Source files to use
15+
RGB_FILE="$INPUT_DIR/rgb_hard.png"
16+
NORMAL_FILE="$INPUT_DIR/normal_1.png"
17+
SPECULAR_FILE="$INPUT_DIR/height_1.png" # Using as stand-in for specular map
18+
19+
# Copy reference images
20+
cp -f "$RGB_FILE" "$OUTPUT_DIR/albedo_reference.png"
21+
cp -f "$NORMAL_FILE" "$OUTPUT_DIR/normal_reference.png"
22+
cp -f "$SPECULAR_FILE" "$OUTPUT_DIR/specular_reference.png"
23+
24+
echo "Copied reference images"
25+
26+
run_cuttlefish() {
27+
local input="$1"
28+
local output="$2"
29+
shift 2
30+
echo "Running: cuttlefish -i \"$input\" -o \"$output\" $*"
31+
cuttlefish -i "$input" -o "$output" "$@"
32+
if [[ -f "$output" ]]; then
33+
echo "Created $output"
34+
fi
35+
}
36+
37+
echo ""
38+
echo "Generating cuttlefish compressed images..."
39+
40+
# BC1 albedo image (sRGB)
41+
run_cuttlefish "$RGB_FILE" "$OUTPUT_DIR/albedo_cuttlefish_bc1.dds" \
42+
-f BC1_RGB --srgb -Q highest
43+
44+
# BC3 albedo image (sRGB)
45+
run_cuttlefish "$RGB_FILE" "$OUTPUT_DIR/albedo_cuttlefish_bc3.dds" \
46+
-f BC3 --srgb -Q highest
47+
48+
# BC6H albedo image (unsigned, sRGB input)
49+
run_cuttlefish "$RGB_FILE" "$OUTPUT_DIR/albedo_cuttlefish_bc6h.dds" \
50+
-f BC6H -t ufloat --srgb -Q highest
51+
52+
# BC6H Signed albedo image (signed, sRGB input)
53+
run_cuttlefish "$RGB_FILE" "$OUTPUT_DIR/albedo_cuttlefish_bc6h_sf16.dds" \
54+
-f BC6H -t float --srgb -Q highest
55+
56+
# BC7 albedo image (sRGB)
57+
run_cuttlefish "$RGB_FILE" "$OUTPUT_DIR/albedo_cuttlefish_bc7.dds" \
58+
-f BC7 --srgb -Q highest
59+
60+
# BC5 normal map (linear)
61+
run_cuttlefish "$NORMAL_FILE" "$OUTPUT_DIR/normal_cuttlefish_bc5.dds" \
62+
-f BC5 -Q highest
63+
64+
# BC1 specular map (linear)
65+
run_cuttlefish "$SPECULAR_FILE" "$OUTPUT_DIR/specular_cuttlefish_bc1.dds" \
66+
-f BC1_RGB -Q highest
67+
68+
# BC4 specular map (linear)
69+
run_cuttlefish "$SPECULAR_FILE" "$OUTPUT_DIR/specular_cuttlefish_bc4.dds" \
70+
-f BC4 -Q highest
71+
72+
echo ""
73+
echo "Test images generated successfully!"
74+
echo "You can now run the ImageQualityBenchmark test to analyze these images."

BCnEncTests/RepackFiles.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.IO;
2+
using BCnEncoder.TextureFormats;
3+
using BCnEncTests.Support;
4+
using Xunit;
5+
6+
namespace BCnEncTests;
7+
8+
public class RepackFiles
9+
{
10+
[Theory]
11+
[InlineData("testktx/raw-bc1-rgb.ktx", "testktx/raw-bc1-rgb-linear.ktx", GlInternalFormat.GlCompressedRgbS3TcDxt1Ext)]
12+
[InlineData("testktx/raw-bc1-rgb.ktx", "testktx/raw-bc1-rgb-srgb.ktx", GlInternalFormat.GlCompressedSrgbS3TcDxt1Ext)]
13+
[InlineData("testktx/raw-bc1-rgba.ktx", "testktx/raw-bc1-rgba-linear.ktx", GlInternalFormat.GlCompressedRgbaS3TcDxt1Ext)]
14+
[InlineData("testktx/raw-bc1-rgba.ktx", "testktx/raw-bc1-rgba-srgb.ktx", GlInternalFormat.GlCompressedSrgbAlphaS3TcDxt1Ext)]
15+
[InlineData("testktx/raw-bc2.ktx", "testktx/raw-bc2-linear.ktx", GlInternalFormat.GlCompressedRgbaS3TcDxt3Ext)]
16+
[InlineData("testktx/raw-bc2.ktx", "testktx/raw-bc2-srgb.ktx", GlInternalFormat.GlCompressedSrgbAlphaS3TcDxt3Ext)]
17+
[InlineData("testktx/raw-bc3.ktx", "testktx/raw-bc3-linear.ktx", GlInternalFormat.GlCompressedRgbaS3TcDxt5Ext)]
18+
[InlineData("testktx/raw-bc3.ktx", "testktx/raw-bc3-srgb.ktx", GlInternalFormat.GlCompressedSrgbAlphaS3TcDxt5Ext)]
19+
[InlineData("testktx/raw-bc7.ktx", "testktx/raw-bc7-linear.ktx", GlInternalFormat.GlCompressedRgbaBptcUnormArb)]
20+
[InlineData("testktx/raw-bc7.ktx", "testktx/raw-bc7-srgb.ktx", GlInternalFormat.GlCompressedSrgbAlphaBptcUnormArb)]
21+
[InlineData("testktx/raw-etc1.ktx", "testktx/raw-etc1-linear.ktx", GlInternalFormat.GlEtc1Rgb8Oes)]
22+
[InlineData("testktx/raw-etc2-rgb.ktx", "testktx/raw-etc2-rgb-linear.ktx", GlInternalFormat.GlCompressedRgb8Etc2)]
23+
[InlineData("testktx/raw-etc2-rgb.ktx", "testktx/raw-etc2-rgb-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Etc2)]
24+
[InlineData("testktx/raw-etc2-rgb-a1.ktx", "testktx/raw-etc2-rgb-a1-linear.ktx", GlInternalFormat.GlCompressedRgb8PunchthroughAlpha1Etc2)]
25+
[InlineData("testktx/raw-etc2-rgb-a1.ktx", "testktx/raw-etc2-rgb-a1-srgb.ktx", GlInternalFormat.GlCompressedSrgb8PunchthroughAlpha1Etc2)]
26+
[InlineData("testktx/raw-etc2-rgba.ktx", "testktx/raw-etc2-rgba-linear.ktx", GlInternalFormat.GlCompressedRgba8Etc2Eac)]
27+
[InlineData("testktx/raw-etc2-rgba.ktx", "testktx/raw-etc2-rgba-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Etc2Eac)]
28+
[InlineData("testktx/raw-astc-4x4.ktx", "testktx/raw-astc-4x4-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc4X4Khr)]
29+
[InlineData("testktx/raw-astc-4x4.ktx", "testktx/raw-astc-4x4-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc4X4Khr)]
30+
31+
[InlineData("testktx/raw-astc-4x4.ktx", "testktx/raw-astc-4x4-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc4X4Khr)]
32+
[InlineData("testktx/raw-astc-4x4.ktx", "testktx/raw-astc-4x4-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc4X4Khr)]
33+
34+
[InlineData("testktx/raw-astc-5x4.ktx", "testktx/raw-astc-5x4-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc5X4Khr)]
35+
[InlineData("testktx/raw-astc-5x4.ktx", "testktx/raw-astc-5x4-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc5X4Khr)]
36+
[InlineData("testktx/raw-astc-5x5.ktx", "testktx/raw-astc-5x5-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc5X5Khr)]
37+
[InlineData("testktx/raw-astc-5x5.ktx", "testktx/raw-astc-5x5-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc5X5Khr)]
38+
39+
[InlineData("testktx/raw-astc-6x5.ktx", "testktx/raw-astc-6x5-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc6X5Khr)]
40+
[InlineData("testktx/raw-astc-6x5.ktx", "testktx/raw-astc-6x5-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc6X5Khr)]
41+
[InlineData("testktx/raw-astc-6x6.ktx", "testktx/raw-astc-6x6-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc6X6Khr)]
42+
[InlineData("testktx/raw-astc-6x6.ktx", "testktx/raw-astc-6x6-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc6X6Khr)]
43+
44+
[InlineData("testktx/raw-astc-8x5.ktx", "testktx/raw-astc-8x5-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc8X5Khr)]
45+
[InlineData("testktx/raw-astc-8x5.ktx", "testktx/raw-astc-8x5-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc8X5Khr)]
46+
[InlineData("testktx/raw-astc-8x6.ktx", "testktx/raw-astc-8x6-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc8X6Khr)]
47+
[InlineData("testktx/raw-astc-8x6.ktx", "testktx/raw-astc-8x6-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc8X6Khr)]
48+
[InlineData("testktx/raw-astc-8x8.ktx", "testktx/raw-astc-8x8-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc8X8Khr)]
49+
[InlineData("testktx/raw-astc-8x8.ktx", "testktx/raw-astc-8x8-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc8X8Khr)]
50+
51+
[InlineData("testktx/raw-astc-10x5.ktx", "testktx/raw-astc-10x5-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc10X5Khr)]
52+
[InlineData("testktx/raw-astc-10x5.ktx", "testktx/raw-astc-10x5-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc10X5Khr)]
53+
[InlineData("testktx/raw-astc-10x6.ktx", "testktx/raw-astc-10x6-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc10X6Khr)]
54+
[InlineData("testktx/raw-astc-10x6.ktx", "testktx/raw-astc-10x6-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc10X6Khr)]
55+
[InlineData("testktx/raw-astc-10x8.ktx", "testktx/raw-astc-10x8-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc10X8Khr)]
56+
[InlineData("testktx/raw-astc-10x8.ktx", "testktx/raw-astc-10x8-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc10X8Khr)]
57+
[InlineData("testktx/raw-astc-10x10.ktx", "testktx/raw-astc-10x10-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc10X10Khr)]
58+
[InlineData("testktx/raw-astc-10x10.ktx", "testktx/raw-astc-10x10-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc10X10Khr)]
59+
60+
[InlineData("testktx/raw-astc-12x10.ktx", "testktx/raw-astc-12x10-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc12X10Khr)]
61+
[InlineData("testktx/raw-astc-12x10.ktx", "testktx/raw-astc-12x10-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc12X10Khr)]
62+
[InlineData("testktx/raw-astc-12x12.ktx", "testktx/raw-astc-12x12-linear.ktx", GlInternalFormat.GlCompressedRgbaAstc12X12Khr)]
63+
[InlineData("testktx/raw-astc-12x12.ktx", "testktx/raw-astc-12x12-srgb.ktx", GlInternalFormat.GlCompressedSrgb8Alpha8Astc12X12Khr)]
64+
65+
[InlineData("testktx/raw-r8g8b8.ktx", "testktx/raw-r8g8b8-linear.ktx", GlInternalFormat.GlRgb8)]
66+
[InlineData("testktx/raw-r8g8b8.ktx", "testktx/raw-r8g8b8-srgb.ktx", GlInternalFormat.GlSrgb8)]
67+
[InlineData("testktx/raw-r8g8b8a8.ktx", "testktx/raw-r8g8b8a8-linear.ktx", GlInternalFormat.GlRgba8)]
68+
[InlineData("testktx/raw-r8g8b8a8.ktx", "testktx/raw-r8g8b8a8-srgb.ktx", GlInternalFormat.GlSrgb8Alpha8)]
69+
public void RepackKtx(string input, string output, GlInternalFormat newFormat)
70+
{
71+
string iPath = Path.Combine(TestHelper.GetProjectRoot(), "testImages", input);
72+
string oPath = Path.Combine(TestHelper.GetProjectRoot(), "testImages", output);
73+
74+
KtxFile ktx;
75+
using (var ifs = File.OpenRead(iPath))
76+
{
77+
ktx = KtxFile.Load(ifs);
78+
}
79+
ktx.header.GlInternalFormat = newFormat;
80+
81+
using var ofs = File.OpenWrite(oPath);
82+
ktx.WriteToStream(ofs);
83+
}
84+
85+
[Theory]
86+
[InlineData("testdds/raw-bc1-srgb.dds", "testdds/raw-bc1-linear.dds", DxgiFormat.DxgiFormatBc1Unorm)]
87+
public void RepackDds(string input, string output, DxgiFormat newFormat)
88+
{
89+
string iPath = Path.Combine(TestHelper.GetProjectRoot(), "testImages", input);
90+
string oPath = Path.Combine(TestHelper.GetProjectRoot(), "testImages", output);
91+
92+
using var ifs = File.OpenRead(iPath);
93+
var dds = DdsFile.Load(ifs);
94+
dds.dx10Header.dxgiFormat = newFormat;
95+
96+
using var ofs = File.OpenWrite(oPath);
97+
dds.WriteToStream(ofs);
98+
}
99+
}

0 commit comments

Comments
 (0)