MCPcopy Create free account
hub / github.com/BinomialLLC/basis_universal / encode_uastc_ldr

Function encode_uastc_ldr

example/example.cpp:140–174  ·  view source on GitHub ↗

This LDR example function uses the basis_compress() C-style function to compress a UASTC LDR .KTX2 file.

Source from the content-addressed store, hash-verified

138
139// This LDR example function uses the basis_compress() C-style function to compress a UASTC LDR .KTX2 file.
140static bool encode_uastc_ldr()
141{
142 const uint32_t W = 512, H = 512;
143
144 image img(W, H);
145 for (uint32_t y = 0; y < H; y++)
146 for (uint32_t x = 0; x < W; x++)
147 img(x, y).set(x >> 1, y >> 1, 0, 1);
148
149 basisu::vector<image> source_images;
150 source_images.push_back(img);
151
152 size_t file_size = 0;
153
154 // basis_compress() is a simple wrapper around the basis_compressor_params and basis_compressor classes.
155 void* pKTX2_data = basis_compress(
156 basist::basis_tex_format::cUASTC_LDR_4x4,
157 source_images,
158 cFlagThreaded | cFlagPrintStats | cFlagDebug | cFlagPrintStatus, 0.0f,
159 &file_size,
160 nullptr);
161
162 if (!pKTX2_data)
163 return false;
164
165 if (!write_data_to_file("test_uastc_ldr_4x4.ktx2", pKTX2_data, file_size))
166 {
167 basis_free_data(pKTX2_data);
168 return false;
169 }
170
171 basis_free_data(pKTX2_data);
172
173 return true;
174}
175
176// This HDR example function directly uses the basis_compressor_params and basis_compressor classes to compress to a UASTC HDR .KTX2 file.
177// These classes expose all encoder functionality (the C-style wrappers used above don't).

Callers 1

mainFunction · 0.85

Calls 5

basis_compressFunction · 0.85
write_data_to_fileFunction · 0.85
basis_free_dataFunction · 0.85
setMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected