| 1 |
diff --git a/thirdparty/basis_universal/encoder/basisu_enc.cpp b/thirdparty/basis_universal/encoder/basisu_enc.cpp |
| 2 |
index cee9c77ca0..e9c8a01388 100644 |
| 3 |
--- a/thirdparty/basis_universal/encoder/basisu_enc.cpp |
| 4 |
+++ b/thirdparty/basis_universal/encoder/basisu_enc.cpp |
| 5 |
@@ -39,9 +39,6 @@ |
| 6 |
#endif |
| 7 |
#include "basisu_miniz.h" |
| 8 |
|
| 9 |
-#define QOI_IMPLEMENTATION |
| 10 |
-#include "3rdparty/qoi.h" |
| 11 |
- |
| 12 |
#if defined(_WIN32) |
| 13 |
// For QueryPerformanceCounter/QueryPerformanceFrequency |
| 14 |
#define WIN32_LEAN_AND_MEAN |
| 15 |
@@ -453,16 +450,7 @@ namespace basisu |
| 16 |
|
| 17 |
bool load_qoi(const char* pFilename, image& img) |
| 18 |
{ |
| 19 |
- qoi_desc desc; |
| 20 |
- clear_obj(desc); |
| 21 |
- |
| 22 |
- void* p = qoi_read(pFilename, &desc, 4); |
| 23 |
- if (!p) |
| 24 |
- return false; |
| 25 |
- |
| 26 |
- img.grant_ownership(static_cast<color_rgba *>(p), desc.width, desc.height); |
| 27 |
- |
| 28 |
- return true; |
| 29 |
+ return false; |
| 30 |
} |
| 31 |
|
| 32 |
bool load_png(const uint8_t *pBuf, size_t buf_size, image &img, const char *pFilename) |
| 33 |
diff --git a/thirdparty/basis_universal/encoder/basisu_gpu_texture.cpp b/thirdparty/basis_universal/encoder/basisu_gpu_texture.cpp |
| 34 |
index 3fa65b43c6..028ac3f314 100644 |
| 35 |
--- a/thirdparty/basis_universal/encoder/basisu_gpu_texture.cpp |
| 36 |
+++ b/thirdparty/basis_universal/encoder/basisu_gpu_texture.cpp |
| 37 |
@@ -19,9 +19,6 @@ |
| 38 |
#include "basisu_bc7enc.h" |
| 39 |
#include "../transcoder/basisu_astc_hdr_core.h" |
| 40 |
|
| 41 |
-#define TINYDDS_IMPLEMENTATION |
| 42 |
-#include "3rdparty/tinydds.h" |
| 43 |
- |
| 44 |
#define BASISU_USE_GOOGLE_ASTC_DECODER (1) |
| 45 |
|
| 46 |
namespace basisu |
| 47 |
@@ -2049,207 +2046,7 @@ namespace basisu |
| 48 |
// and cubemap, cubemap mipmapped, and cubemap array mipmapped. |
| 49 |
bool write_dds_file(uint8_vec &dds_data, const basisu::vector<gpu_image_vec>& gpu_images, bool cubemap_flag, bool use_srgb_format) |
| 50 |
{ |
| 51 |
- if (!gpu_images.size()) |
| 52 |
- { |
| 53 |
- assert(0); |
| 54 |
- return false; |
| 55 |
- } |
| 56 |
- |
| 57 |
- // Sanity check the input |
| 58 |
- uint32_t slices = 1; |
| 59 |
- if (cubemap_flag) |
| 60 |
- { |
| 61 |
- if ((gpu_images.size() % 6) != 0) |
| 62 |
- { |
| 63 |
- assert(0); |
| 64 |
- return false; |
| 65 |
- } |
| 66 |
- slices = gpu_images.size_u32() / 6; |
| 67 |
- } |
| 68 |
- else |
| 69 |
- { |
| 70 |
- slices = gpu_images.size_u32(); |
| 71 |
- } |
| 72 |
- |
| 73 |
- uint32_t width = 0, height = 0, total_levels = 0; |
| 74 |
- basisu::texture_format fmt = texture_format::cInvalidTextureFormat; |
| 75 |
- |
| 76 |
- // Sanity check the input for consistent # of dimensions and mip levels |
| 77 |
- for (uint32_t array_index = 0; array_index < gpu_images.size(); array_index++) |
| 78 |
- { |
| 79 |
- const gpu_image_vec& levels = gpu_images[array_index]; |
| 80 |
- |
| 81 |
- if (!levels.size()) |
| 82 |
- { |
| 83 |
- // Empty mip chain |
| 84 |
- assert(0); |
| 85 |
- return false; |
| 86 |
- } |
| 87 |
- |
| 88 |
- if (!array_index) |
| 89 |
- { |
| 90 |
- width = levels[0].get_pixel_width(); |
| 91 |
- height = levels[0].get_pixel_height(); |
| 92 |
- total_levels = (uint32_t)levels.size(); |
| 93 |
- fmt = levels[0].get_format(); |
| 94 |
- } |
| 95 |
- else |
| 96 |
- { |
| 97 |
- if ((width != levels[0].get_pixel_width()) || |
| 98 |
- (height != levels[0].get_pixel_height()) || |
| 99 |
- (total_levels != levels.size())) |
| 100 |
- { |
| 101 |
- // All cubemap/texture array faces must be the same dimension |
| 102 |
- assert(0); |
| 103 |
- return false; |
| 104 |
- } |
| 105 |
- } |
| 106 |
- |
| 107 |
- for (uint32_t level_index = 0; level_index < levels.size(); level_index++) |
| 108 |
- { |
| 109 |
- if (level_index) |
| 110 |
- { |
| 111 |
- if ((levels[level_index].get_pixel_width() != maximum<uint32_t>(1, levels[0].get_pixel_width() >> level_index)) || |
| 112 |
- (levels[level_index].get_pixel_height() != maximum<uint32_t>(1, levels[0].get_pixel_height() >> level_index))) |
| 113 |
- { |
| 114 |
- // Malformed mipmap chain |
| 115 |
- assert(0); |
| 116 |
- return false; |
| 117 |
- } |
| 118 |
- } |
| 119 |
- |
| 120 |
- if (fmt != levels[level_index].get_format()) |
| 121 |
- { |
| 122 |
- // All input textures must use the same GPU format |
| 123 |
- assert(0); |
| 124 |
- return false; |
| 125 |
- } |
| 126 |
- } |
| 127 |
- } |
| 128 |
- |
| 129 |
- // No mipmap levels |
| 130 |
- if (!total_levels) |
| 131 |
- { |
| 132 |
- assert(0); |
| 133 |
- return false; |
| 134 |
- } |
| 135 |
- |
| 136 |
- // Create the DDS mipmap level data |
| 137 |
- uint8_vec mipmaps[32]; |
| 138 |
- |
| 139 |
- // See https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dds-file-layout-for-cubic-environment-maps |
| 140 |
- // DDS cubemap organization is cubemap face 0 followed by all mips, then cubemap face 1 followed by all mips, etc. |
| 141 |
- // Unfortunately tinydds.h's writer doesn't handle this case correctly, so we work around it here. |
| 142 |
- // This also applies with 2D texture arrays, too. RenderDoc and ddsview (DirectXTex) views each type (cubemap array and 2D texture array) correctly. |
| 143 |
- // Also see "Using Texture Arrays in Direct3D 10/11": |
| 144 |
- // https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-pguide |
| 145 |
- for (uint32_t array_index = 0; array_index < gpu_images.size(); array_index++) |
| 146 |
- { |
| 147 |
- const gpu_image_vec& levels = gpu_images[array_index]; |
| 148 |
- |
| 149 |
- for (uint32_t level_index = 0; level_index < levels.size(); level_index++) |
| 150 |
- { |
| 151 |
- append_vector(mipmaps[0], (uint8_t*)levels[level_index].get_ptr(), levels[level_index].get_size_in_bytes()); |
| 152 |
- |
| 153 |
- } // level_index |
| 154 |
- } // array_index |
| 155 |
- |
| 156 |
-#if 0 |
| 157 |
- // This organization, required by tinydds.h's API, is wrong. |
| 158 |
- { |
| 159 |
- for (uint32_t array_index = 0; array_index < gpu_images.size(); array_index++) |
| 160 |
- { |
| 161 |
- const gpu_image_vec& levels = gpu_images[array_index]; |
| 162 |
- |
| 163 |
- for (uint32_t level_index = 0; level_index < levels.size(); level_index++) |
| 164 |
- { |
| 165 |
- append_vector(mipmaps[level_index], (uint8_t*)levels[level_index].get_ptr(), levels[level_index].get_size_in_bytes()); |
| 166 |
- |
| 167 |
- } // level_index |
| 168 |
- } // array_index |
| 169 |
- } |
| 170 |
-#endif |
| 171 |
- |
| 172 |
- // Write DDS file using tinydds |
| 173 |
- TinyDDS_WriteCallbacks cbs; |
| 174 |
- cbs.error = [](void* user, char const* msg) { BASISU_NOTE_UNUSED(user); fprintf(stderr, "tinydds: %s\n", msg); }; |
| 175 |
- cbs.alloc = [](void* user, size_t size) -> void* { BASISU_NOTE_UNUSED(user); return malloc(size); }; |
| 176 |
- cbs.free = [](void* user, void* memory) { BASISU_NOTE_UNUSED(user); free(memory); }; |
| 177 |
- cbs.write = [](void* user, void const* buffer, size_t byteCount) { BASISU_NOTE_UNUSED(user); uint8_vec* pVec = (uint8_vec*)user; append_vector(*pVec, (const uint8_t*)buffer, byteCount); }; |
| 178 |
- |
| 179 |
- uint32_t mipmap_sizes[32]; |
| 180 |
- const void* mipmap_ptrs[32]; |
| 181 |
- |
| 182 |
- clear_obj(mipmap_sizes); |
| 183 |
- clear_obj(mipmap_ptrs); |
| 184 |
- |
| 185 |
- assert(total_levels < 32); |
| 186 |
- for (uint32_t i = 0; i < total_levels; i++) |
| 187 |
- { |
| 188 |
- mipmap_sizes[i] = mipmaps[i].size_in_bytes_u32(); |
| 189 |
- mipmap_ptrs[i] = mipmaps[i].get_ptr(); |
| 190 |
- } |
| 191 |
- |
| 192 |
- // Select tinydds texture format |
| 193 |
- uint32_t tinydds_fmt = 0; |
| 194 |
- |
| 195 |
- switch (fmt) |
| 196 |
- { |
| 197 |
- case texture_format::cBC1_NV: |
| 198 |
- case texture_format::cBC1_AMD: |
| 199 |
- case texture_format::cBC1: |
| 200 |
- tinydds_fmt = use_srgb_format ? TDDS_BC1_RGBA_SRGB_BLOCK : TDDS_BC1_RGBA_UNORM_BLOCK; |
| 201 |
- break; |
| 202 |
- case texture_format::cBC3: |
| 203 |
- tinydds_fmt = use_srgb_format ? TDDS_BC3_SRGB_BLOCK : TDDS_BC3_UNORM_BLOCK; |
| 204 |
- break; |
| 205 |
- case texture_format::cBC4: |
| 206 |
- tinydds_fmt = TDDS_BC4_UNORM_BLOCK; |
| 207 |
- break; |
| 208 |
- case texture_format::cBC5: |
| 209 |
- tinydds_fmt = TDDS_BC5_UNORM_BLOCK; |
| 210 |
- break; |
| 211 |
- case texture_format::cBC6HSigned: |
| 212 |
- tinydds_fmt = TDDS_BC6H_SFLOAT_BLOCK; |
| 213 |
- break; |
| 214 |
- case texture_format::cBC6HUnsigned: |
| 215 |
- tinydds_fmt = TDDS_BC6H_UFLOAT_BLOCK; |
| 216 |
- break; |
| 217 |
- case texture_format::cBC7: |
| 218 |
- tinydds_fmt = use_srgb_format ? TDDS_BC7_SRGB_BLOCK : TDDS_BC7_UNORM_BLOCK; |
| 219 |
- break; |
| 220 |
- default: |
| 221 |
- { |
| 222 |
- fprintf(stderr, "Warning: Unsupported format in write_dds_file().\n"); |
| 223 |
- return false; |
| 224 |
- } |
| 225 |
- } |
| 226 |
- |
| 227 |
- // DirectXTex's DDSView doesn't handle odd sizes textures correctly. RenderDoc loads them fine, however. |
| 228 |
- // Trying to work around this here results in invalid mipmaps. |
| 229 |
- //width = (width + 3) & ~3; |
| 230 |
- //height = (height + 3) & ~3; |
| 231 |
- |
| 232 |
- bool status = TinyDDS_WriteImage(&cbs, |
| 233 |
- &dds_data, |
| 234 |
- width, |
| 235 |
- height, |
| 236 |
- 1, |
| 237 |
- slices, |
| 238 |
- total_levels, |
| 239 |
- (TinyDDS_Format)tinydds_fmt, |
| 240 |
- cubemap_flag, |
| 241 |
- true, |
| 242 |
- mipmap_sizes, |
| 243 |
- mipmap_ptrs); |
| 244 |
- |
| 245 |
- if (!status) |
| 246 |
- { |
| 247 |
- fprintf(stderr, "write_dds_file: Failed creating DDS file\n"); |
| 248 |
- return false; |
| 249 |
- } |
| 250 |
- |
| 251 |
- return true; |
| 252 |
+ return false; |
| 253 |
} |
| 254 |
|
| 255 |
bool write_dds_file(const char* pFilename, const basisu::vector<gpu_image_vec>& gpu_images, bool cubemap_flag, bool use_srgb_format) |
| 256 |
@@ -2270,188 +2067,6 @@ namespace basisu |
| 257 |
|
| 258 |
bool read_uncompressed_dds_file(const char* pFilename, basisu::vector<image> &ldr_mips, basisu::vector<imagef>& hdr_mips) |
| 259 |
{ |
| 260 |
- const uint32_t MAX_IMAGE_DIM = 16384; |
| 261 |
- |
| 262 |
- TinyDDS_Callbacks cbs; |
| 263 |
- |
| 264 |
- cbs.errorFn = [](void* user, char const* msg) { BASISU_NOTE_UNUSED(user); fprintf(stderr, "tinydds: %s\n", msg); }; |
| 265 |
- cbs.allocFn = [](void* user, size_t size) -> void* { BASISU_NOTE_UNUSED(user); return malloc(size); }; |
| 266 |
- cbs.freeFn = [](void* user, void* memory) { BASISU_NOTE_UNUSED(user); free(memory); }; |
| 267 |
- cbs.readFn = [](void* user, void* buffer, size_t byteCount) -> size_t { return (size_t)fread(buffer, 1, byteCount, (FILE*)user); }; |
| 268 |
- |
| 269 |
-#ifdef _MSC_VER |
| 270 |
- cbs.seekFn = [](void* user, int64_t ofs) -> bool { return _fseeki64((FILE*)user, ofs, SEEK_SET) == 0; }; |
| 271 |
- cbs.tellFn = [](void* user) -> int64_t { return _ftelli64((FILE*)user); }; |
| 272 |
-#else |
| 273 |
- cbs.seekFn = [](void* user, int64_t ofs) -> bool { return fseek((FILE*)user, (long)ofs, SEEK_SET) == 0; }; |
| 274 |
- cbs.tellFn = [](void* user) -> int64_t { return (int64_t)ftell((FILE*)user); }; |
| 275 |
-#endif |
| 276 |
- |
| 277 |
- FILE* pFile = fopen_safe(pFilename, "rb"); |
| 278 |
- if (!pFile) |
| 279 |
- { |
| 280 |
- error_printf("Can't open .DDS file \"%s\"\n", pFilename); |
| 281 |
- return false; |
| 282 |
- } |
| 283 |
- |
| 284 |
- // These are the formats AMD Compressonator supports in its UI. |
| 285 |
- enum dds_fmt |
| 286 |
- { |
| 287 |
- cRGBA32, |
| 288 |
- cRGBA_HALF, |
| 289 |
- cRGBA_FLOAT |
| 290 |
- }; |
| 291 |
- |
| 292 |
- bool status = false; |
| 293 |
- dds_fmt fmt = cRGBA32; |
| 294 |
- uint32_t width = 0, height = 0; |
| 295 |
- bool hdr_flag = false; |
| 296 |
- TinyDDS_Format tfmt = TDDS_UNDEFINED; |
| 297 |
- |
| 298 |
- TinyDDS_ContextHandle ctx = TinyDDS_CreateContext(&cbs, pFile); |
| 299 |
- if (!ctx) |
| 300 |
- goto failure; |
| 301 |
- |
| 302 |
- status = TinyDDS_ReadHeader(ctx); |
| 303 |
- if (!status) |
| 304 |
- { |
| 305 |
- error_printf("Failed parsing DDS header in file \"%s\"\n", pFilename); |
| 306 |
- goto failure; |
| 307 |
- } |
| 308 |
- |
| 309 |
- if ((!TinyDDS_Is2D(ctx)) || (TinyDDS_ArraySlices(ctx) > 1) || (TinyDDS_IsCubemap(ctx))) |
| 310 |
- { |
| 311 |
- error_printf("Unsupported DDS texture type in file \"%s\"\n", pFilename); |
| 312 |
- goto failure; |
| 313 |
- } |
| 314 |
- |
| 315 |
- width = TinyDDS_Width(ctx); |
| 316 |
- height = TinyDDS_Height(ctx); |
| 317 |
- |
| 318 |
- if (!width || !height) |
| 319 |
- { |
| 320 |
- error_printf("DDS texture dimensions invalid in file \"%s\"\n", pFilename); |
| 321 |
- goto failure; |
| 322 |
- } |
| 323 |
- |
| 324 |
- if ((width > MAX_IMAGE_DIM) || (height > MAX_IMAGE_DIM)) |
| 325 |
- { |
| 326 |
- error_printf("DDS texture dimensions too large in file \"%s\"\n", pFilename); |
| 327 |
- goto failure; |
| 328 |
- } |
| 329 |
- |
| 330 |
- tfmt = TinyDDS_GetFormat(ctx); |
| 331 |
- switch (tfmt) |
| 332 |
- { |
| 333 |
- case TDDS_R8G8B8A8_SRGB: |
| 334 |
- case TDDS_R8G8B8A8_UNORM: |
| 335 |
- case TDDS_B8G8R8A8_SRGB: |
| 336 |
- case TDDS_B8G8R8A8_UNORM: |
| 337 |
- fmt = cRGBA32; |
| 338 |
- break; |
| 339 |
- case TDDS_R16G16B16A16_SFLOAT: |
| 340 |
- fmt = cRGBA_HALF; |
| 341 |
- hdr_flag = true; |
| 342 |
- break; |
| 343 |
- case TDDS_R32G32B32A32_SFLOAT: |
| 344 |
- fmt = cRGBA_FLOAT; |
| 345 |
- hdr_flag = true; |
| 346 |
- break; |
| 347 |
- default: |
| 348 |
- error_printf("File \"%s\" has an unsupported DDS texture format (only supports RGBA/BGRA 32bpp, RGBA HALF float, or RGBA FLOAT)\n", pFilename); |
| 349 |
- goto failure; |
| 350 |
- } |
| 351 |
- |
| 352 |
- if (hdr_flag) |
| 353 |
- hdr_mips.resize(TinyDDS_NumberOfMipmaps(ctx)); |
| 354 |
- else |
| 355 |
- ldr_mips.resize(TinyDDS_NumberOfMipmaps(ctx)); |
| 356 |
- |
| 357 |
- for (uint32_t level = 0; level < TinyDDS_NumberOfMipmaps(ctx); level++) |
| 358 |
- { |
| 359 |
- const uint32_t level_width = TinyDDS_MipMapReduce(width, level); |
| 360 |
- const uint32_t level_height = TinyDDS_MipMapReduce(height, level); |
| 361 |
- const uint32_t total_level_texels = level_width * level_height; |
| 362 |
- |
| 363 |
- const void* pImage = TinyDDS_ImageRawData(ctx, level); |
| 364 |
- const uint32_t image_size = TinyDDS_ImageSize(ctx, level); |
| 365 |
- |
| 366 |
- if (fmt == cRGBA32) |
| 367 |
- { |
| 368 |
- ldr_mips[level].resize(level_width, level_height); |
| 369 |
- |
| 370 |
- if ((ldr_mips[level].get_total_pixels() * sizeof(uint32_t) != image_size)) |
| 371 |
- { |
| 372 |
- assert(0); |
| 373 |
- goto failure; |
| 374 |
- } |
| 375 |
- |
| 376 |
- memcpy(ldr_mips[level].get_ptr(), pImage, image_size); |
| 377 |
- |
| 378 |
- if ((tfmt == TDDS_B8G8R8A8_SRGB) || (tfmt == TDDS_B8G8R8A8_UNORM)) |
| 379 |
- { |
| 380 |
- // Swap R and B components. |
| 381 |
- uint32_t *pTexels = (uint32_t *)ldr_mips[level].get_ptr(); |
| 382 |
- for (uint32_t i = 0; i < total_level_texels; i++) |
| 383 |
- { |
| 384 |
- const uint32_t v = pTexels[i]; |
| 385 |
- const uint32_t r = (v >> 16) & 0xFF; |
| 386 |
- const uint32_t b = v & 0xFF; |
| 387 |
- pTexels[i] = r | (b << 16) | (v & 0xFF00FF00); |
| 388 |
- } |
| 389 |
- } |
| 390 |
- } |
| 391 |
- else if (fmt == cRGBA_FLOAT) |
| 392 |
- { |
| 393 |
- hdr_mips[level].resize(level_width, level_height); |
| 394 |
- |
| 395 |
- if ((hdr_mips[level].get_total_pixels() * sizeof(float) * 4 != image_size)) |
| 396 |
- { |
| 397 |
- assert(0); |
| 398 |
- goto failure; |
| 399 |
- } |
| 400 |
- |
| 401 |
- memcpy((void *)hdr_mips[level].get_ptr(), pImage, image_size); |
| 402 |
- } |
| 403 |
- else if (fmt == cRGBA_HALF) |
| 404 |
- { |
| 405 |
- hdr_mips[level].resize(level_width, level_height); |
| 406 |
- |
| 407 |
- if ((hdr_mips[level].get_total_pixels() * sizeof(basist::half_float) * 4 != image_size)) |
| 408 |
- { |
| 409 |
- assert(0); |
| 410 |
- goto failure; |
| 411 |
- } |
| 412 |
- |
| 413 |
- // Unpack half to float. |
| 414 |
- const basist::half_float* pSrc_comps = static_cast<const basist::half_float*>(pImage); |
| 415 |
- vec4F* pDst_texels = hdr_mips[level].get_ptr(); |
| 416 |
- |
| 417 |
- for (uint32_t i = 0; i < total_level_texels; i++) |
| 418 |
- { |
| 419 |
- (*pDst_texels)[0] = basist::half_to_float(pSrc_comps[0]); |
| 420 |
- (*pDst_texels)[1] = basist::half_to_float(pSrc_comps[1]); |
| 421 |
- (*pDst_texels)[2] = basist::half_to_float(pSrc_comps[2]); |
| 422 |
- (*pDst_texels)[3] = basist::half_to_float(pSrc_comps[3]); |
| 423 |
- |
| 424 |
- pSrc_comps += 4; |
| 425 |
- pDst_texels++; |
| 426 |
- } // y |
| 427 |
- } |
| 428 |
- } // level |
| 429 |
- |
| 430 |
- TinyDDS_DestroyContext(ctx); |
| 431 |
- fclose(pFile); |
| 432 |
- |
| 433 |
- return true; |
| 434 |
- |
| 435 |
- failure: |
| 436 |
- if (ctx) |
| 437 |
- TinyDDS_DestroyContext(ctx); |
| 438 |
- |
| 439 |
- if (pFile) |
| 440 |
- fclose(pFile); |
| 441 |
- |
| 442 |
return false; |
| 443 |
} |
| 444 |
|