Giter Site home page Giter Site logo

m0ldavia / bcnencoder.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nominom/bcnencoder.net

0.0 0.0 0.0 7.4 MB

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

License: The Unlicense

C# 100.00%

bcnencoder.net's Introduction

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.
Removed .NET Framkework and .NET 2.1 support and added .NET 8 support.

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.

Please note, that the API might change between versions.

Dependencies

Current dependencies are:

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;

bcnencoder.net's People

Contributors

nominom avatar onepiecefreak3 avatar ptasev avatar m0ldavia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.