BCnEncoder.Net
2.3.0
dotnet add package BCnEncoder.Net --version 2.3.0
NuGet\Install-Package BCnEncoder.Net -Version 2.3.0
<PackageReference Include="BCnEncoder.Net" Version="2.3.0" />
<PackageVersion Include="BCnEncoder.Net" Version="2.3.0" />
<PackageReference Include="BCnEncoder.Net" />
paket add BCnEncoder.Net --version 2.3.0
#r "nuget: BCnEncoder.Net, 2.3.0"
#:package BCnEncoder.Net@2.3.0
#addin nuget:?package=BCnEncoder.Net&version=2.3.0
#tool nuget:?package=BCnEncoder.Net&version=2.3.0
BCnEncoder.NET
A Cross-platform BCn / DXT encoding libary for .NET
What is it?
BCnEncoder.NET is a library for compressing rgba images to different block-compressed formats. It has no native dependencies and is .NET Standard 2.1 & 2.0 compatible.
Supported formats are:
- Raw unsigned byte R, RG, RGB and RGBA formats
- BC1 (S3TC DXT1)
- BC2 (S3TC DXT3)
- BC3 (S3TC DXT5)
- BC4 (RGTC1)
- BC5 (RGTC2)
- BC6 (BPTC_FLOAT)
- BC7 (BPTC)
Current state
The current state of this library is in development but quite usable. I'm planning on implementing support for more codecs and different algorithms. The current version is capable of encoding and decoding BC1-BC7 images in both KTX or DDS formats.
.NET Standard 2.0 support is experimental, and relies on PolySharp & Microsoft.Bcl.Numerics.
Please note, that the API might change between versions.
Dependencies
Current dependencies are:
- CommunityToolkit.HighPerformance licensed under the MIT license for Span2D and Memory2D types.
Additionally, for .NET Standard 2.0:
- PolySharp licensed under the MIT license.
- Microsoft.Bcl.Numerics licensed under the MIT license.
Image library extensions
This library has extension packages available for the following image libraries:
The extension packages provide extension methods for ease of use with the image library.
Upgrading to 2.0
If you're upgrading from 1.X.X to version 2, expect some of your exsting code to be broken. ImageSharp was removed as a core dependency in version 2.0, so the code will no longer work with ImageSharp's Image types by default. You can install the extension package for ImageSharp to continue using this library easily with ImageSharp apis.
API
The below examples are using the ImageSharp extension package. For more detailed usage examples, you can go look at the unit tests.
Remember add the following usings to the top of the file:
using BCnEncoder.Encoder;
using BCnEncoder.Decoder;
using BCnEncoder.Shared;
using BCnEncoder.ImageSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
Here's an example on how to encode a png image to BC1 without alpha, and save it to a file.
using Image<Rgba32> image = Image.Load<Rgba32>("example.png");
BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.GenerateMipMaps = true;
encoder.OutputOptions.Quality = CompressionQuality.Balanced;
encoder.OutputOptions.Format = CompressionFormat.Bc1;
encoder.OutputOptions.FileFormat = OutputFileFormat.Ktx; //Change to Dds for a dds file.
using FileStream fs = File.OpenWrite("example.ktx");
encoder.EncodeToStream(image, fs);
And how to decode a compressed image from a KTX file and save it to png format.
using FileStream fs = File.OpenRead("compressed_bc1.ktx");
BcDecoder decoder = new BcDecoder();
using Image<Rgba32> image = decoder.DecodeToImageRgba32(fs);
using FileStream outFs = File.OpenWrite("decoding_test_bc1.png");
image.SaveAsPng(outFs);
How to encode an HDR image with BC6H. (HdrImage class reads and writes Radiance HDR files. This class is experimental and subject to be removed)
HdrImage image = HdrImage.Read("example.hdr");
BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.GenerateMipMaps = true;
encoder.OutputOptions.Quality = CompressionQuality.Balanced;
encoder.OutputOptions.Format = CompressionFormat.Bc6U;
encoder.OutputOptions.FileFormat = OutputFileFormat.Ktx; //Change to Dds for a dds file.
using FileStream fs = File.OpenWrite("example.ktx");
encoder.EncodeToStreamHdr(image.PixelMemory, fs);
How to decode a BC6H encoded file.
using FileStream fs = File.OpenRead("compressed_bc6.ktx");
BcDecoder decoder = new BcDecoder();
Memory2D<ColorRgbFloat> pixels = decoder.DecodeHdr2D(fs);
HdrImage image = new HdrImage(pixels.Span);
using FileStream outFs = File.OpenWrite("decoded.hdr");
image.Write(outFs);
TO-DO
- BC1 / DXT1 Encoding Without Alpha
- BC1 / DXT1 Encoding With 1bit of alpha
- BC2 / DXT3 Encoding
- BC3 / DXT5 Encoding
- BC4 Encoding
- BC5 Encoding
- BC7 / BPTC Encoding
- DDS file support
- Implement PCA to remove Accord.Statistics dependency
- BC6H HDR Encoding
- Performance improvements
- ETC / ETC2 Encoding?
Contributing
All contributions are welcome. I'll try to respond to bug reports and feature requests as fast as possible, but you can also fix things yourself and submit a pull request. Please note, that by submitting a pull request you accept that your code will be dual licensed under MIT and public domain Unlicense.
License
This library is dual-licensed under the Unlicense and MIT licenses.
You may use this code under the terms of either license.
Please note, that any dependencies of this project are licensed under their own respective licenses.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CommunityToolkit.HighPerformance (>= 8.4.0)
- Microsoft.Bcl.Numerics (>= 10.0.3)
-
.NETStandard 2.1
- CommunityToolkit.HighPerformance (>= 8.4.0)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on BCnEncoder.Net:
| Package | Downloads |
|---|---|
|
MonoGame.Framework.Content.Pipeline
The Monogame Content Pipeline for Windows, Mac and Linux is used to compile raw content to xnb files. |
|
|
Lumina
Lumina is a small, performant and simple library for interacting with FINAL FANTASY XIV game data. |
|
|
BCnEncoder.Net.ImageSharp
Adds ImageSharp apis to BCnEncoder.Net |
|
|
RenderWareBuilders
Renderware IO builder library |
|
|
FF16Tools.Files
Library for handling various FF16 file formats. |
GitHub repositories (16)
Showing the top 16 popular GitHub repositories that depend on BCnEncoder.Net:
| Repository | Stars |
|---|---|
|
MonoGame/MonoGame
One framework for creating powerful cross-platform games.
|
|
|
bcssov/IronyModManager
Mod Manager for Paradox Games. Official Discord: https://discord.gg/t9JmY8KFrV
|
|
|
FanTranslatorsInternational/Kuriimu2
Kuriimu is a general purpose game translation project manager and toolkit for authors of fan translations and game mods.
|
|
|
Markemp/Cryengine-Converter
A c# program to convert Crytek files to Collada (XML) format
|
|
|
MeltyPlayer/MeltyTool
Multitool for viewing/extracting assets from various N64/GCN/3DS/PC games en-masse.
|
|
|
Nenkai/PDTools
A collection of utilities for working around certain Gran Turismo games.
|
|
|
Amethyst-szs/MoonFlow
Modding application for Super Mario Odyssey, specializing in text editing and event flowcharts
|
|
|
ME3Tweaks/LegendaryExplorer
Editor toolset for Mass Effect Trilogy and Mass Effect Legendary Edition
|
|
|
X-Hax/sa_tools
Sonic Adventure Toolset
|
|
|
NotAdam/Lumina
A simple, performant and extensible framework for interacting with FFXIV game data
|
|
|
R2NorthstarTools/VTOL
A Manager and Installer For the Titanfall 2 +Northstar launcher.
|
|
|
TombEngine/Tomb-Editor
A level editor for classic Tomb Raider engines and custom engines such as TRNG, TEN, and TRX.
|
|
|
LittleBigRefresh/Refresh
A second-generation custom server for LittleBigPlanet that focuses on quality of life features and improving user experience.
|
|
|
MapStudioProject/Track-Studio
A powerful MK8 map editor for creating and editing track models, objects, paths and animations.
|
|
|
EmK530/BloxDump
A program that dumps game assets cached by Roblox.
|
|
|
nanami5270/GARbro-Mod
Fork of morkt/GARbro
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.3.0 | 1,098 | 3/5/2026 |
| 2.2.1 | 41,985 | 5/4/2025 |
| 2.2.0 | 5,376 | 3/7/2025 |
| 2.1.0 | 106,950 | 9/18/2021 |
| 2.0.3 | 17,501 | 3/22/2021 |
| 2.0.2 | 954 | 2/18/2021 |
| 2.0.1 | 1,755 | 2/16/2021 |
| 2.0.0 | 757 | 2/12/2021 |
| 1.2.3 | 1,479 | 10/20/2020 |
| 1.2.2 | 916 | 5/24/2020 |
| 1.2.1 | 795 | 4/30/2020 |
| 1.2.0 | 846 | 4/30/2020 |
| 1.1.1 | 762 | 4/28/2020 |
| 1.1.0 | 815 | 4/22/2020 |
| 1.0.1 | 746 | 4/20/2020 |
| 1.0.0 | 817 | 4/20/2020 |
2.3.0
- Add .NET Standard 2.0 support
- Fix some DecodeAllMipMaps methods not decoding all MipMaps