VOOZH about

URL: https://www.nuget.org/packages/BCnEncoder.Net/

⇱ NuGet Gallery | BCnEncoder.Net 2.3.0




BCnEncoder.Net 2.3.0

dotnet add package BCnEncoder.Net --version 2.3.0
 
 
NuGet\Install-Package BCnEncoder.Net -Version 2.3.0
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BCnEncoder.Net" Version="2.3.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BCnEncoder.Net" Version="2.3.0" />
 
Directory.Packages.props
<PackageReference Include="BCnEncoder.Net" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BCnEncoder.Net --version 2.3.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BCnEncoder.Net, 2.3.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BCnEncoder.Net@2.3.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BCnEncoder.Net&version=2.3.0
 
Install as a Cake Addin
#tool nuget:?package=BCnEncoder.Net&version=2.3.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

👁 Nuget
👁 Tests

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:

Additionally, for .NET Standard 2.0:

Image library extensions

This library has extension packages available for the following image libraries:

ImageSharp

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 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

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 (21)

Showing the top 20 popular GitHub repositories that depend on BCnEncoder.Net:

Repository Stars
MonoGame/MonoGame
One framework for creating powerful cross-platform games.
Norbyte/lslib
Tools for manipulating Divinity Original Sin and Baldur's Gate 3 files
bcssov/IronyModManager
Mod Manager for Paradox Games. Official Discord: https://discord.gg/t9JmY8KFrV
amerkoleci/alimer
Cross-platform .NET 10 C# game engine.
FanTranslatorsInternational/Kuriimu2
Kuriimu is a general purpose game translation project manager and toolkit for authors of fan translations and game mods.
xivapi/SaintCoinach
A .NET library written in C# for extracting game assets and reading game assets from Final Fantasy XIV: A Realm Reborn.
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
Nenkai/GBFRDataTools
Tools/Libraries for dealing with Granblue Fantasy: Relink.
NotAdam/Lumina
A simple, performant and extensible framework for interacting with FFXIV game data
X-Hax/sa_tools
Sonic Adventure Toolset
R2NorthstarTools/VTOL
A Manager and Installer For the Titanfall 2 +Northstar launcher.
nanami5270/GARbro-Mod
Fork of morkt/GARbro
EmK530/BloxDump
A program that dumps game assets cached by Roblox.
bernatvadell/muonline
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.
Version Downloads Last Updated
2.3.0 5,671 3/5/2026
2.2.1 59,063 5/4/2025
2.2.0 6,071 3/7/2025
2.1.0 117,206 9/18/2021
2.0.3 17,580 3/22/2021
2.0.2 970 2/18/2021
2.0.1 1,785 2/16/2021
2.0.0 787 2/12/2021
1.2.3 1,523 10/20/2020
1.2.2 932 5/24/2020
1.2.1 815 4/30/2020
1.2.0 874 4/30/2020
1.1.1 776 4/28/2020
1.1.0 837 4/22/2020
1.0.1 759 4/20/2020
1.0.0 837 4/20/2020

2.3.0
- Add .NET Standard 2.0 support
- Fix some DecodeAllMipMaps methods not decoding all MipMaps