https://github.com/monogame/monogame.tool.basisuniversal
MonoGame tooling build for basis_universal
https://github.com/monogame/monogame.tool.basisuniversal
Last synced: about 1 year ago
JSON representation
MonoGame tooling build for basis_universal
- Host: GitHub
- URL: https://github.com/monogame/monogame.tool.basisuniversal
- Owner: MonoGame
- License: mit
- Created: 2024-06-12T14:34:14.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-22T07:52:32.000Z (almost 2 years ago)
- Last Synced: 2025-04-06T03:39:50.812Z (about 1 year ago)
- Language: C#
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MonoGame.Tool.BasisUniversal
MonoGame tooling build for basis_universal
This tool can be used to compress an image into various texture compression
formats. Examples are BC1-7, PVRTC, ETC1, ETC2, ASTC and ATC.
To use we must first create a "basis" file, this is an intermediate file containing
the image data. From this file ALL over texture formats can be created. It is probably
worth caching this "basis" file between builds.
```dotnetcli
basisu -file foo.png -ktx2
```
Adding a `-uastc` might give better results for some compression types.
Once you have the "basis" file you can then transform that into specific formats
by using the `-unpack` command. Providing the `-format_only` flag will produce
ONLY that format. Omitting this flag will result in ALL supported formats being
produced.
The values for `-format_only` are the numerical values for the [transcoder_texture_format]( https://github.com/BinomialLLC/basis_universal/blob/ad9386a4a1cf2a248f7bbd45f543a7448db15267/transcoder/basisu_transcoder.h#L49). For example ATC with an Alpha channel maps to [cTFATC_RGBA](https://github.com/BinomialLLC/basis_universal/blob/ad9386a4a1cf2a248f7bbd45f543a7448db15267/transcoder/basisu_transcoder.h#L73C3-L73C14) which has a numerical value of `12`.
```dotnetcli
basisu -unpack foo.ktx2 -ktx_only -linear -format_only 2
```
The output file(s) are listed in the output. There may be many output files. They will be stored in a .ktx files, but the internal image data will be compressed. We can use libraries like `libktxsharp` to read the .ktx data.
```csharp
byte[] ktxBytes = File.ReadAllBytes("myImage.ktx");
KtxStructure ktxStructure = null;
using (MemoryStream ms = new MemoryStream(ktxBytes))
{
ktxStructure = KtxLoader.LoadInput(ms);
}
Console.WriteLine(ktxStructure.header.pixelWidth);
```