Skip to content

forestrf/BCnEncoder.NET

 
 

Repository files navigation

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 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)
  • 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-BC5 and BC7 images in both KTX or DDS formats.

Dependencies

Current dependencies are:

API

For more detailed usage examples, you can go look at the unit tests.

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 = EncodingQuality.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.Encode(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.Decode(fs);

using FileStream outFs = File.OpenWrite("decoding_test_bc1.png");
image.SaveAsPng(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
  • ETC / ETC2 Encoding?
  • Implement saving and loading basic image formats to remove ImageSharp dependency

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.

About

Cross-platform texture encoding libary for .NET. With support for BC1-3/DXT, BC4-5/RGTC and BC7/BPTC compression. Outputs files in ktx or dds formats.

Resources

License

Unlicense, MIT licenses found

Licenses found

Unlicense
UNLICENSE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C# 100.0%