Skip to content

Commit 0b38f5d

Browse files
committed
BC6 loading done.
1 parent cb878c5 commit 0b38f5d

8 files changed

Lines changed: 1110 additions & 487 deletions

File tree

CSharpImageLibrary.sln

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.6
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpImageLibrary", "CSharpImageLibrary\CSharpImageLibrary.csproj", "{10E9F41A-45D2-4CC4-B625-76C295FFDF67}"
77
EndProject
@@ -25,4 +25,7 @@ Global
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE
2727
EndGlobalSection
28+
GlobalSection(Performance) = preSolution
29+
HasPerformanceSessions = true
30+
EndGlobalSection
2831
EndGlobal

CSharpImageLibrary/CSharpImageLibrary.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@
9494
<Reference Include="PresentationFramework" />
9595
</ItemGroup>
9696
<ItemGroup>
97+
<Compile Include="DDS\BC6.cs" />
9798
<Compile Include="DDS\BC7.cs" />
9899
<Compile Include="DDS\DDSGeneral.cs" />
99100
<Compile Include="DDS\DDS_BlockHelpers.cs" />
100101
<Compile Include="DDS\DDS_Decoders.cs" />
101102
<Compile Include="DDS\DDS_Encoders.cs" />
103+
<Compile Include="DDS\DX10_Helpers.cs" />
102104
<Compile Include="Headers\AbstractHeader.cs" />
103105
<Compile Include="Headers\BMP_Header.cs" />
104106
<Compile Include="Headers\DDS_Header.cs" />

CSharpImageLibrary/DDS/BC6.cs

Lines changed: 607 additions & 0 deletions
Large diffs are not rendered by default.

CSharpImageLibrary/DDS/BC7.cs

Lines changed: 8 additions & 472 deletions
Large diffs are not rendered by default.

CSharpImageLibrary/DDS/DDSGeneral.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ internal static List<MipMap> LoadDDS(MemoryStream compressed, DDS_Header header,
166166
break;
167167
}
168168
MipMap mipmap = ReadCompressedMipMap(compressed, mipWidth, mipHeight, mipOffset, formatDetails, DecompressBCBlock);
169-
170169
MipMaps[m] = mipmap;
171170
mipOffset += (int)(mipWidth * mipHeight * (blockSize / 16d)); // Also put the division in brackets cos if the mip dimensions are high enough, the multiplications can exceed int.MaxValue)
172171
mipWidth /= 2;

CSharpImageLibrary/DDS/DDS_Decoders.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ internal static void DecompressATI2Block(byte[] source, int sourceStart, byte[]
102102
// BC6
103103
internal static void DecompressBC6Block(byte[] source, int sourceStart, byte[] destination, int decompressedStart, int decompressedLineLength, bool unused)
104104
{
105-
throw new NotImplementedException("Not currently implemented.");
105+
var colours = BC6.DecompressBC6(source, sourceStart, false);
106+
SetColoursFromDX10(colours, destination, decompressedStart, decompressedLineLength);
106107
}
107108

108109

109110
// BC7
110111
internal static void DecompressBC7Block(byte[] source, int sourceStart, byte[] destination, int decompressedStart, int decompressedLineLength, bool unused)
111112
{
112-
BC7.LDRColour[] colours = BC7.DecompressBC7(source, sourceStart);
113+
var colours = BC7.DecompressBC7(source, sourceStart);
114+
SetColoursFromDX10(colours, destination, decompressedStart, decompressedLineLength);
115+
}
113116

114-
for(int i = 0; i < 4; i++)
117+
static void SetColoursFromDX10(DX10_Helpers.LDRColour[] block, byte[] destination, int decompressedStart, int decompressedLineLength)
118+
{
119+
for (int i = 0; i < 4; i++)
115120
{
116121
for (int j = 0; j < 4; j++)
117122
{
@@ -120,21 +125,14 @@ internal static void DecompressBC7Block(byte[] source, int sourceStart, byte[] d
120125
int GPos = decompressedStart + (i * decompressedLineLength) + (j * 4) + 1;
121126
int RPos = decompressedStart + (i * decompressedLineLength) + (j * 4) + 2;
122127
int APos = decompressedStart + (i * decompressedLineLength) + (j * 4) + 3;
123-
var colour = colours[(i * 4) + j];
124-
125-
/*Debug.WriteLine($"{nameof(BPos)}: {BPos}");
126-
Debug.WriteLine($"{nameof(GPos)}: {GPos}");
127-
Debug.WriteLine($"{nameof(RPos)}: {RPos}");
128-
Debug.WriteLine($"{nameof(APos)}: {APos}");
129-
Debug.WriteLine("");*/
128+
var colour = block[(i * 4) + j];
130129

131130
destination[RPos] = (byte)colour.R;
132131
destination[GPos] = (byte)colour.G;
133132
destination[BPos] = (byte)colour.B;
134133
destination[APos] = (byte)colour.A;
135134
}
136135
}
137-
138136
}
139137

140138

CSharpImageLibrary/DDS/DX10_Helpers.cs

Lines changed: 475 additions & 0 deletions
Large diffs are not rendered by default.

CSharpImageLibrary/ImageEngineFormatDetails.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ public class ImageEngineFormatDetails
241241
BlockDecoder = DDS_Decoders.DecompressATI2Block;
242242
break;
243243
case ImageEngineFormat.DDS_DX10:
244-
BlockDecoder = DDS_Decoders.DecompressBC7Block;
244+
if (DX10Format.ToString().Contains("BC7"))
245+
BlockDecoder = DDS_Decoders.DecompressBC7Block;
246+
else
247+
BlockDecoder = DDS_Decoders.DecompressBC6Block;
245248
break;
246249
}
247250
}

0 commit comments

Comments
 (0)