forked from crskycode/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBc2BlockEncoder.cs
More file actions
33 lines (26 loc) · 801 Bytes
/
Copy pathBc2BlockEncoder.cs
File metadata and controls
33 lines (26 loc) · 801 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
using System;
using BCnEncoder.Shared;
using BCnEncoder.Shared.Colors;
namespace BCnEncoder.Encoder
{
internal class Bc2BlockEncoder : BaseBcBlockEncoder<Bc2Block, RgbEncodingContext>
{
private static readonly Bc1BlockEncoder bc1BlockEncoder = new Bc1BlockEncoder(false, false);
public override Bc2Block EncodeBlock(in RgbEncodingContext context)
{
Bc1Block colorBlock = bc1BlockEncoder.EncodeBlock(context);
return EncodeAlpha(colorBlock, context.RawBlockVec);
}
private static Bc2Block EncodeAlpha(Bc1Block colorBlock, RawBlock4X4Vector4 rawBlock)
{
var pixels = rawBlock.AsSpan;
Bc2Block result = new Bc2Block();
result.colorBlock = colorBlock;
for (int i = 0; i < pixels.Length; i++)
{
result.SetAlpha(i, pixels[i].W);
}
return result;
}
}
}