forked from crskycode/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBc7Decoder.cs
More file actions
36 lines (30 loc) · 923 Bytes
/
Copy pathBc7Decoder.cs
File metadata and controls
36 lines (30 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.IO;
using System.Runtime.InteropServices;
using BCnEncoder.Shared;
namespace BCnEncoder.Decoder
{
internal class Bc7Decoder : IBcBlockDecoder
{
public unsafe RawBlock4X4Rgba32[,] Decode(byte[] data, int pixelWidth, int pixelHeight, out int blockWidth, out int blockHeight) {
blockWidth = (int)Math.Ceiling(pixelWidth / 4.0f);
blockHeight = (int)Math.Ceiling(pixelHeight / 4.0f);
if (data.Length != (blockWidth * blockHeight * sizeof(Bc7Block))) {
throw new InvalidDataException();
}
RawBlock4X4Rgba32[,] output = new RawBlock4X4Rgba32[blockWidth, blockHeight];
fixed (byte* iDataBytes = data)
{
Bc7Block* encodedBlocks = (Bc7Block*)iDataBytes;
for (int x = 0; x < blockWidth; x++)
{
for (int y = 0; y < blockHeight; y++)
{
output[x, y] = encodedBlocks[x + y * blockWidth].Decode();
}
}
}
return output;
}
}
}