forked from crskycode/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawDecoder.cs
More file actions
40 lines (33 loc) · 1.16 KB
/
Copy pathRawDecoder.cs
File metadata and controls
40 lines (33 loc) · 1.16 KB
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
37
38
39
40
using System;
using System.Runtime.CompilerServices;
using BCnEncoder.Shared;
using BCnEncoder.Shared.Colors;
using CommunityToolkit.HighPerformance;
namespace BCnEncoder.Decoder
{
internal class RawDecoder<TColor> : IBcDecoder where TColor : unmanaged, IColor
{
/// <inheritdoc />
public byte[] Decode(ReadOnlyMemory<byte> data, int width, int height, OperationContext context)
{
if (data.Length != width * height * Unsafe.SizeOf<TColor>())
{
throw new ArgumentException("Input data buffer incorrectly sized!");
}
var bytes = data.Cast<byte, TColor>().ConvertToAsBytes<TColor, ColorRgbaFloat>(context.ColorConversionMode);
context.Progress?.Report(width * height);
return bytes;
}
/// <inheritdoc />
public ColorRgbaFloat[] DecodeColor(ReadOnlyMemory<byte> data, int width, int height, OperationContext context)
{
if (data.Length != width * height * Unsafe.SizeOf<TColor>())
{
throw new ArgumentException("Input data buffer incorrectly sized!");
}
var colors = data.Cast<byte, TColor>().ConvertTo<TColor, ColorRgbaFloat>(context.ColorConversionMode);
context.Progress?.Report(width * height);
return colors;
}
}
}