This HDR example function directly uses the basis_compressor_params and basis_compressor classes to compress to a UASTC HDR .KTX2 file. These classes expose all encoder functionality (the C-style wrappers used above don't).
| 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). |
| 178 | static bool encode_uastc_hdr() |
| 179 | { |
| 180 | const uint32_t W = 256, H = 256; |
| 181 | |
| 182 | imagef img(W, H); |
| 183 | |
| 184 | #if 1 |
| 185 | create_mandelbrot(img); |
| 186 | #else |
| 187 | for (uint32_t y = 0; y < H; y++) |
| 188 | for (uint32_t x = 0; x < W; x++) |
| 189 | img(x, y).set(((x ^ y) & 1) ? basist::ASTC_HDR_MAX_VAL : 1000.0f); |
| 190 | #endif |
| 191 | |
| 192 | basis_compressor_params params; |
| 193 | params.m_hdr = true; |
| 194 | params.m_source_images_hdr.push_back(img); |
| 195 | params.m_uastc_hdr_4x4_options.set_quality_level(3); |
| 196 | params.m_debug = true; |
| 197 | //params.m_debug_images = true; |
| 198 | params.m_status_output = true; |
| 199 | params.m_compute_stats = true; |
| 200 | params.m_create_ktx2_file = true; |
| 201 | params.m_write_output_basis_or_ktx2_files = true; |
| 202 | params.m_out_filename = "test_uastc_hdr.ktx2"; |
| 203 | params.m_perceptual = true; |
| 204 | |
| 205 | #if 1 |
| 206 | // Create a job pool containing 7 total threads (the calling thread plus 6 additional threads). |
| 207 | // A job pool must be created, even if threading is disabled. |
| 208 | const uint32_t NUM_THREADS = 7; |
| 209 | job_pool jp(NUM_THREADS); |
| 210 | params.m_pJob_pool = &jp; |
| 211 | params.m_multithreading = true; |
| 212 | #else |
| 213 | // No threading |
| 214 | const uint32_t NUM_THREADS = 1; |
| 215 | job_pool jp(NUM_THREADS); |
| 216 | params.m_pJob_pool = &jp; |
| 217 | params.m_multithreading = false; |
| 218 | #endif |
| 219 | |
| 220 | basis_compressor comp; |
| 221 | if (!comp.init(params)) |
| 222 | return false; |
| 223 | |
| 224 | basisu::basis_compressor::error_code ec = comp.process(); |
| 225 | if (ec != basisu::basis_compressor::cECSuccess) |
| 226 | return false; |
| 227 | |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | // This example function loads a .KTX2 file and then transcodes it to various compressed/uncompressed texture formats. |
| 232 | // It writes .DDS and .ASTC files. |
no test coverage detected