Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/basis_universal/transcoder/basisu.h
9905 views
1
// basisu.h
2
// Copyright (C) 2019-2024 Binomial LLC. All Rights Reserved.
3
// Important: If compiling with gcc, be sure strict aliasing is disabled: -fno-strict-aliasing
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
#pragma once
17
18
#ifdef _MSC_VER
19
20
#pragma warning (disable : 4201)
21
#pragma warning (disable : 4127) // warning C4127: conditional expression is constant
22
#pragma warning (disable : 4530) // C++ exception handler used, but unwind semantics are not enabled.
23
24
#endif // _MSC_VER
25
26
#include <stdlib.h>
27
#include <stdio.h>
28
#include <math.h>
29
#include <stdarg.h>
30
#include <string.h>
31
#include <memory.h>
32
#include <limits.h>
33
#include <stdint.h>
34
35
#include <algorithm>
36
#include <limits>
37
#include <functional>
38
#include <iterator>
39
#include <type_traits>
40
#include <assert.h>
41
#include <random>
42
#include <inttypes.h>
43
44
#include "basisu_containers.h"
45
46
#ifdef max
47
#undef max
48
#endif
49
50
#ifdef min
51
#undef min
52
#endif
53
54
#ifdef _WIN32
55
#define strcasecmp _stricmp
56
#endif
57
58
// Set to one to enable debug printf()'s when any errors occur, for development/debugging. Especially useful for WebGL development.
59
#ifndef BASISU_FORCE_DEVEL_MESSAGES
60
#define BASISU_FORCE_DEVEL_MESSAGES 0
61
#endif
62
63
#define BASISU_NOTE_UNUSED(x) (void)(x)
64
#define BASISU_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
65
#define BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(x) x(const x &) = delete; x& operator= (const x &) = delete;
66
#define BASISU_ASSUME(x) static_assert(x, #x);
67
#define BASISU_OFFSETOF(s, m) offsetof(s, m)
68
#define BASISU_STRINGIZE(x) #x
69
#define BASISU_STRINGIZE2(x) BASISU_STRINGIZE(x)
70
71
#if BASISU_FORCE_DEVEL_MESSAGES
72
#define BASISU_DEVEL_ERROR(...) do { basisu::debug_printf(__VA_ARGS__); } while(0)
73
#else
74
#define BASISU_DEVEL_ERROR(...)
75
#endif
76
77
namespace basisu
78
{
79
// Types/utilities
80
81
#ifdef _WIN32
82
const char BASISU_PATH_SEPERATOR_CHAR = '\\';
83
#else
84
const char BASISU_PATH_SEPERATOR_CHAR = '/';
85
#endif
86
87
typedef basisu::vector<uint8_t> uint8_vec;
88
typedef basisu::vector<int16_t> int16_vec;
89
typedef basisu::vector<uint16_t> uint16_vec;
90
typedef basisu::vector<uint32_t> uint_vec;
91
typedef basisu::vector<size_t> size_t_vec;
92
typedef basisu::vector<uint64_t> uint64_vec;
93
typedef basisu::vector<int> int_vec;
94
typedef basisu::vector<bool> bool_vec;
95
typedef basisu::vector<float> float_vec;
96
97
void enable_debug_printf(bool enabled);
98
void debug_printf(const char *pFmt, ...);
99
void debug_puts(const char* p);
100
101
template <typename... Args>
102
inline void fmt_debug_printf(const char* pFmt, Args&&... args)
103
{
104
std::string res;
105
if (!fmt_variants(res, pFmt, fmt_variant_vec{ fmt_variant(std::forward<Args>(args))... }))
106
return;
107
debug_puts(res.c_str());
108
}
109
110
#ifndef __EMSCRIPTEN__
111
#ifdef __GNUC__
112
#pragma GCC diagnostic push
113
#pragma GCC diagnostic ignored "-Wclass-memaccess"
114
#endif
115
#endif
116
117
template <typename T> inline void clear_obj(T& obj) { memset(&obj, 0, sizeof(obj)); }
118
119
#ifndef __EMSCRIPTEN__
120
#ifdef __GNUC__
121
#pragma GCC diagnostic pop
122
#endif
123
#endif
124
125
constexpr double cPiD = 3.14159265358979323846264338327950288;
126
constexpr float REALLY_SMALL_FLOAT_VAL = .000000125f;
127
constexpr float SMALL_FLOAT_VAL = .0000125f;
128
constexpr float BIG_FLOAT_VAL = 1e+30f;
129
130
template <typename T0, typename T1> inline T0 lerp(T0 a, T0 b, T1 c) { return a + (b - a) * c; }
131
132
inline float clampf(float value, float low, float high) { if (value < low) value = low; else if (value > high) value = high; return value; }
133
inline float saturate(float value) { return clampf(value, 0, 1.0f); }
134
inline uint8_t minimumub(uint8_t a, uint8_t b) { return (a < b) ? a : b; }
135
inline uint32_t minimumu(uint32_t a, uint32_t b) { return (a < b) ? a : b; }
136
inline int32_t minimumi(int32_t a, int32_t b) { return (a < b) ? a : b; }
137
inline float minimumf(float a, float b) { return (a < b) ? a : b; }
138
inline uint8_t maximumub(uint8_t a, uint8_t b) { return (a > b) ? a : b; }
139
inline uint32_t maximumu(uint32_t a, uint32_t b) { return (a > b) ? a : b; }
140
inline int32_t maximumi(int32_t a, int32_t b) { return (a > b) ? a : b; }
141
inline float maximumf(float a, float b) { return (a > b) ? a : b; }
142
inline int squarei(int i) { return i * i; }
143
inline float squaref(float i) { return i * i; }
144
inline double squared(double i) { return i * i; }
145
template<typename T> inline T square(T a) { return a * a; }
146
template<typename T> inline T sign(T a) { return (a < 0) ? (T)-1 : ((a == 0) ? (T)0 : (T)1); }
147
148
inline bool equal_tol(float a, float b, float t) { return fabsf(a - b) <= ((maximum(fabsf(a), fabsf(b)) + 1.0f) * t); }
149
inline bool equal_tol(double a, double b, double t) { return fabs(a - b) <= ((maximum(fabs(a), fabs(b)) + 1.0f) * t); }
150
151
template <class T>
152
inline T prev_wrap(T i, T n)
153
{
154
T temp = i - 1;
155
if (temp < 0)
156
temp = n - 1;
157
return temp;
158
}
159
160
template <class T>
161
inline T next_wrap(T i, T n)
162
{
163
T temp = i + 1;
164
if (temp >= n)
165
temp = 0;
166
return temp;
167
}
168
169
inline uint32_t iabs(int32_t i) { return (i < 0) ? static_cast<uint32_t>(-i) : static_cast<uint32_t>(i); }
170
inline uint64_t iabs64(int64_t i) { return (i < 0) ? static_cast<uint64_t>(-i) : static_cast<uint64_t>(i); }
171
172
template<typename T> inline void clear_vector(T &vec) { vec.erase(vec.begin(), vec.end()); }
173
template<typename T> inline typename T::value_type *enlarge_vector(T &vec, size_t n) { size_t cs = vec.size(); vec.resize(cs + n); return &vec[cs]; }
174
175
inline bool is_pow2(uint32_t x) { return x && ((x & (x - 1U)) == 0U); }
176
inline bool is_pow2(uint64_t x) { return x && ((x & (x - 1U)) == 0U); }
177
178
template<typename T> inline T open_range_check(T v, T minv, T maxv) { assert(v >= minv && v < maxv); BASISU_NOTE_UNUSED(minv); BASISU_NOTE_UNUSED(maxv); return v; }
179
template<typename T> inline T open_range_check(T v, T maxv) { assert(v < maxv); BASISU_NOTE_UNUSED(maxv); return v; }
180
181
// Open interval
182
inline bool in_bounds(int v, int l, int h)
183
{
184
return (v >= l) && (v < h);
185
}
186
187
// Closed interval
188
inline bool in_range(int v, int l, int h)
189
{
190
return (v >= l) && (v <= h);
191
}
192
193
inline uint32_t total_bits(uint32_t v) { uint32_t l = 0; for ( ; v > 0U; ++l) v >>= 1; return l; }
194
195
template<typename T> inline T saturate(T val) { return clamp(val, 0.0f, 1.0f); }
196
197
inline uint32_t get_bit(uint32_t src, int ndx)
198
{
199
assert(in_bounds(ndx, 0, 32));
200
return (src >> ndx) & 1;
201
}
202
203
inline bool is_bit_set(uint32_t src, int ndx)
204
{
205
return get_bit(src, ndx) != 0;
206
}
207
208
inline uint32_t get_bits(uint32_t val, int low, int high)
209
{
210
const int num_bits = (high - low) + 1;
211
assert(in_range(num_bits, 1, 32));
212
213
val >>= low;
214
if (num_bits != 32)
215
val &= ((1u << num_bits) - 1);
216
217
return val;
218
}
219
220
template<typename T, typename R> inline void append_vector(T &vec, const R *pObjs, size_t n)
221
{
222
if (n)
223
{
224
if (vec.size())
225
{
226
assert((pObjs + n) <= vec.begin() || (pObjs >= vec.end()));
227
}
228
const size_t cur_s = vec.size();
229
vec.resize(cur_s + n);
230
memcpy(&vec[cur_s], pObjs, sizeof(R) * n);
231
}
232
}
233
234
template<typename T> inline void append_vector(T &vec, const T &other_vec)
235
{
236
assert(&vec != &other_vec);
237
if (other_vec.size())
238
append_vector(vec, &other_vec[0], other_vec.size());
239
}
240
241
template<typename T> inline void vector_ensure_element_is_valid(T &vec, size_t idx)
242
{
243
if (idx >= vec.size())
244
vec.resize(idx + 1);
245
}
246
247
template<typename T> inline void vector_sort(T &vec)
248
{
249
if (vec.size())
250
std::sort(vec.begin(), vec.end());
251
}
252
253
template<typename T, typename U> inline bool unordered_set_contains(T& set, const U&obj)
254
{
255
return set.find(obj) != set.end();
256
}
257
258
template<typename T> int vector_find(const T &vec, const typename T::value_type &obj)
259
{
260
assert(vec.size() <= INT_MAX);
261
for (size_t i = 0; i < vec.size(); i++)
262
if (vec[i] == obj)
263
return static_cast<int>(i);
264
return -1;
265
}
266
267
template<typename T> void vector_set_all(T &vec, const typename T::value_type &obj)
268
{
269
for (size_t i = 0; i < vec.size(); i++)
270
vec[i] = obj;
271
}
272
273
inline uint64_t read_be64(const void *p)
274
{
275
uint64_t val = 0;
276
for (uint32_t i = 0; i < 8; i++)
277
val |= (static_cast<uint64_t>(static_cast<const uint8_t *>(p)[7 - i]) << (i * 8));
278
return val;
279
}
280
281
inline void write_be64(void *p, uint64_t x)
282
{
283
for (uint32_t i = 0; i < 8; i++)
284
static_cast<uint8_t *>(p)[7 - i] = static_cast<uint8_t>(x >> (i * 8));
285
}
286
287
static inline uint16_t byteswap16(uint16_t x) { return static_cast<uint16_t>((x << 8) | (x >> 8)); }
288
static inline uint32_t byteswap32(uint32_t x) { return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24)); }
289
290
inline uint32_t floor_log2i(uint32_t v)
291
{
292
uint32_t b = 0;
293
for (; v > 1U; ++b)
294
v >>= 1;
295
return b;
296
}
297
298
inline uint32_t ceil_log2i(uint32_t v)
299
{
300
uint32_t b = floor_log2i(v);
301
if ((b != 32) && (v > (1U << b)))
302
++b;
303
return b;
304
}
305
306
inline int posmod(int x, int y)
307
{
308
if (x >= 0)
309
return (x < y) ? x : (x % y);
310
int m = (-x) % y;
311
return (m != 0) ? (y - m) : m;
312
}
313
314
inline bool do_excl_ranges_overlap(int la, int ha, int lb, int hb)
315
{
316
assert(la < ha && lb < hb);
317
if ((ha <= lb) || (la >= hb)) return false;
318
return true;
319
}
320
321
static inline uint32_t read_le_word(const uint8_t* pBytes)
322
{
323
return (pBytes[1] << 8U) | (pBytes[0]);
324
}
325
326
static inline uint32_t read_le_dword(const uint8_t *pBytes)
327
{
328
return (pBytes[3] << 24U) | (pBytes[2] << 16U) | (pBytes[1] << 8U) | (pBytes[0]);
329
}
330
331
static inline void write_le_dword(uint8_t* pBytes, uint32_t val)
332
{
333
pBytes[0] = (uint8_t)val;
334
pBytes[1] = (uint8_t)(val >> 8U);
335
pBytes[2] = (uint8_t)(val >> 16U);
336
pBytes[3] = (uint8_t)(val >> 24U);
337
}
338
339
// Always little endian 1-8 byte unsigned int
340
template<uint32_t NumBytes>
341
struct packed_uint
342
{
343
uint8_t m_bytes[NumBytes];
344
345
inline packed_uint() { static_assert(NumBytes <= sizeof(uint64_t), "Invalid NumBytes"); }
346
inline packed_uint(uint64_t v) { *this = v; }
347
inline packed_uint(const packed_uint& other) { *this = other; }
348
349
inline packed_uint& operator= (uint64_t v)
350
{
351
for (uint32_t i = 0; i < NumBytes; i++)
352
m_bytes[i] = static_cast<uint8_t>(v >> (i * 8));
353
return *this;
354
}
355
356
inline packed_uint& operator= (const packed_uint& rhs)
357
{
358
memcpy(m_bytes, rhs.m_bytes, sizeof(m_bytes));
359
return *this;
360
}
361
362
#if 0
363
#ifdef __GNUC__
364
#pragma GCC diagnostic push
365
#pragma GCC diagnostic ignored "-Warray-bounds"
366
#endif
367
inline operator uint32_t() const
368
{
369
switch (NumBytes)
370
{
371
case 1:
372
{
373
return m_bytes[0];
374
}
375
case 2:
376
{
377
return (m_bytes[1] << 8U) | m_bytes[0];
378
}
379
case 3:
380
{
381
return (m_bytes[2] << 16U) | (m_bytes[1] << 8U) | m_bytes[0];
382
}
383
case 4:
384
{
385
return read_le_dword(m_bytes);
386
}
387
case 5:
388
{
389
uint32_t l = read_le_dword(m_bytes);
390
uint32_t h = m_bytes[4];
391
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
392
}
393
case 6:
394
{
395
uint32_t l = read_le_dword(m_bytes);
396
uint32_t h = (m_bytes[5] << 8U) | m_bytes[4];
397
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
398
}
399
case 7:
400
{
401
uint32_t l = read_le_dword(m_bytes);
402
uint32_t h = (m_bytes[6] << 16U) | (m_bytes[5] << 8U) | m_bytes[4];
403
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
404
}
405
case 8:
406
{
407
uint32_t l = read_le_dword(m_bytes);
408
uint32_t h = read_le_dword(m_bytes + 4);
409
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
410
}
411
default:
412
{
413
assert(0);
414
return 0;
415
}
416
}
417
}
418
#ifdef __GNUC__
419
#pragma GCC diagnostic pop
420
#endif
421
#else
422
inline operator uint32_t() const
423
{
424
if constexpr (NumBytes == 1)
425
{
426
return m_bytes[0];
427
}
428
else if constexpr (NumBytes == 2)
429
{
430
return (m_bytes[1] << 8U) | m_bytes[0];
431
}
432
else if constexpr (NumBytes == 3)
433
{
434
return (m_bytes[2] << 16U) | (m_bytes[1] << 8U) | m_bytes[0];
435
}
436
else if constexpr (NumBytes == 4)
437
{
438
return read_le_dword(m_bytes);
439
}
440
else if constexpr (NumBytes == 5)
441
{
442
uint32_t l = read_le_dword(m_bytes);
443
uint32_t h = m_bytes[4];
444
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
445
}
446
else if constexpr (NumBytes == 6)
447
{
448
uint32_t l = read_le_dword(m_bytes);
449
uint32_t h = (m_bytes[5] << 8U) | m_bytes[4];
450
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
451
}
452
else if constexpr (NumBytes == 7)
453
{
454
uint32_t l = read_le_dword(m_bytes);
455
uint32_t h = (m_bytes[6] << 16U) | (m_bytes[5] << 8U) | m_bytes[4];
456
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
457
}
458
else if constexpr (NumBytes == 8)
459
{
460
uint32_t l = read_le_dword(m_bytes);
461
uint32_t h = read_le_dword(m_bytes + 4);
462
return static_cast<uint64_t>(l) | (static_cast<uint64_t>(h) << 32U);
463
}
464
else
465
{
466
static_assert(NumBytes <= 8, "Invalid NumBytes");
467
return 0;
468
}
469
}
470
#endif
471
472
};
473
474
enum eZero { cZero };
475
enum eNoClamp { cNoClamp };
476
477
// Rice/Huffman entropy coding
478
479
// This is basically Deflate-style canonical Huffman, except we allow for a lot more symbols.
480
enum
481
{
482
cHuffmanMaxSupportedCodeSize = 16, cHuffmanMaxSupportedInternalCodeSize = 31,
483
cHuffmanFastLookupBits = 10,
484
cHuffmanMaxSymsLog2 = 14, cHuffmanMaxSyms = 1 << cHuffmanMaxSymsLog2,
485
486
// Small zero runs
487
cHuffmanSmallZeroRunSizeMin = 3, cHuffmanSmallZeroRunSizeMax = 10, cHuffmanSmallZeroRunExtraBits = 3,
488
489
// Big zero run
490
cHuffmanBigZeroRunSizeMin = 11, cHuffmanBigZeroRunSizeMax = 138, cHuffmanBigZeroRunExtraBits = 7,
491
492
// Small non-zero run
493
cHuffmanSmallRepeatSizeMin = 3, cHuffmanSmallRepeatSizeMax = 6, cHuffmanSmallRepeatExtraBits = 2,
494
495
// Big non-zero run
496
cHuffmanBigRepeatSizeMin = 7, cHuffmanBigRepeatSizeMax = 134, cHuffmanBigRepeatExtraBits = 7,
497
498
cHuffmanTotalCodelengthCodes = 21, cHuffmanSmallZeroRunCode = 17, cHuffmanBigZeroRunCode = 18, cHuffmanSmallRepeatCode = 19, cHuffmanBigRepeatCode = 20
499
};
500
501
static const uint8_t g_huffman_sorted_codelength_codes[] = { cHuffmanSmallZeroRunCode, cHuffmanBigZeroRunCode, cHuffmanSmallRepeatCode, cHuffmanBigRepeatCode, 0, 8, 7, 9, 6, 0xA, 5, 0xB, 4, 0xC, 3, 0xD, 2, 0xE, 1, 0xF, 0x10 };
502
const uint32_t cHuffmanTotalSortedCodelengthCodes = sizeof(g_huffman_sorted_codelength_codes) / sizeof(g_huffman_sorted_codelength_codes[0]);
503
504
// GPU texture formats and various uncompressed texture formats.
505
506
enum class texture_format
507
{
508
cInvalidTextureFormat = -1,
509
510
// Block-based formats
511
cETC1, // ETC1
512
cETC1S, // ETC1 (subset: diff colors only, no subblocks)
513
cETC2_RGB, // ETC2 color block (basisu doesn't support ETC2 planar/T/H modes - just basic ETC1)
514
cETC2_RGBA, // ETC2 EAC alpha block followed by ETC2 color block
515
cETC2_ALPHA, // ETC2 EAC alpha block
516
cBC1, // DXT1
517
cBC3, // DXT5 (BC4/DXT5A block followed by a BC1/DXT1 block)
518
cBC4, // DXT5A
519
cBC5, // 3DC/DXN (two BC4/DXT5A blocks)
520
cBC6HSigned, // HDR
521
cBC6HUnsigned, // HDR
522
cBC7,
523
cASTC_LDR_4x4, // ASTC 4x4 LDR only
524
cASTC_HDR_4x4, // ASTC 4x4 HDR only (but may use LDR ASTC blocks internally, although our encoders don't do this)
525
cASTC_HDR_6x6, // ASTC 6x6 HDR only (but may use LDR ASTC blocks internally, although our encoders don't do this)
526
cPVRTC1_4_RGB,
527
cPVRTC1_4_RGBA,
528
cATC_RGB,
529
cATC_RGBA_INTERPOLATED_ALPHA,
530
cFXT1_RGB,
531
cPVRTC2_4_RGBA,
532
cETC2_R11_EAC,
533
cETC2_RG11_EAC,
534
cUASTC4x4,
535
cUASTC_HDR_4x4,
536
cBC1_NV,
537
cBC1_AMD,
538
539
// Uncompressed/raw pixels
540
cRGBA32,
541
cRGB565,
542
cBGR565,
543
cRGBA4444,
544
cABGR4444,
545
cRGBA_HALF,
546
cRGB_HALF,
547
cRGB_9E5
548
};
549
550
inline bool is_uncompressed_texture_format(texture_format fmt)
551
{
552
switch (fmt)
553
{
554
case texture_format::cRGBA32:
555
case texture_format::cRGB565:
556
case texture_format::cBGR565:
557
case texture_format::cRGBA4444:
558
case texture_format::cABGR4444:
559
case texture_format::cRGBA_HALF:
560
case texture_format::cRGB_HALF:
561
case texture_format::cRGB_9E5:
562
return true;
563
default:
564
break;
565
}
566
567
return false;
568
}
569
570
inline bool is_block_based_texture_format(texture_format fmt)
571
{
572
return !is_uncompressed_texture_format(fmt);
573
}
574
575
// This is bytes per block for GPU formats, or bytes per texel for uncompressed formats.
576
inline uint32_t get_bytes_per_block_or_pixel(texture_format fmt)
577
{
578
switch (fmt)
579
{
580
case texture_format::cETC1:
581
case texture_format::cETC1S:
582
case texture_format::cETC2_RGB:
583
case texture_format::cETC2_ALPHA:
584
case texture_format::cBC1:
585
case texture_format::cBC1_NV:
586
case texture_format::cBC1_AMD:
587
case texture_format::cBC4:
588
case texture_format::cPVRTC1_4_RGB:
589
case texture_format::cPVRTC1_4_RGBA:
590
case texture_format::cATC_RGB:
591
case texture_format::cPVRTC2_4_RGBA:
592
case texture_format::cETC2_R11_EAC:
593
return 8;
594
case texture_format::cRGBA32:
595
case texture_format::cRGB_9E5:
596
return sizeof(uint32_t);
597
case texture_format::cRGB_HALF:
598
return sizeof(uint16_t) * 3;
599
case texture_format::cRGBA_HALF:
600
return sizeof(uint16_t) * 4;
601
case texture_format::cRGB565:
602
case texture_format::cBGR565:
603
case texture_format::cRGBA4444:
604
case texture_format::cABGR4444:
605
return sizeof(uint16_t);
606
607
default:
608
break;
609
}
610
611
// Everything else is 16 bytes/block.
612
return 16;
613
}
614
615
// This is qwords per block for GPU formats, or not valid for uncompressed formats.
616
inline uint32_t get_qwords_per_block(texture_format fmt)
617
{
618
assert(is_block_based_texture_format(fmt));
619
620
const uint32_t bytes_per_block = get_bytes_per_block_or_pixel(fmt);
621
return bytes_per_block >> 3;
622
}
623
624
inline uint32_t get_block_width(texture_format fmt)
625
{
626
assert(is_block_based_texture_format(fmt));
627
628
switch (fmt)
629
{
630
case texture_format::cFXT1_RGB:
631
return 8;
632
case texture_format::cASTC_HDR_6x6:
633
return 6;
634
default:
635
break;
636
}
637
return 4;
638
}
639
640
inline uint32_t get_block_height(texture_format fmt)
641
{
642
assert(is_block_based_texture_format(fmt));
643
644
switch (fmt)
645
{
646
case texture_format::cASTC_HDR_6x6:
647
return 6;
648
default:
649
break;
650
}
651
return 4;
652
}
653
654
inline bool is_hdr_texture_format(texture_format fmt)
655
{
656
switch (fmt)
657
{
658
case texture_format::cASTC_HDR_4x4:
659
case texture_format::cUASTC_HDR_4x4:
660
case texture_format::cASTC_HDR_6x6:
661
case texture_format::cBC6HSigned:
662
case texture_format::cBC6HUnsigned:
663
case texture_format::cRGBA_HALF:
664
case texture_format::cRGB_HALF:
665
case texture_format::cRGB_9E5:
666
return true;
667
default:
668
break;
669
}
670
671
return false;
672
}
673
674
inline bool is_ldr_texture_format(texture_format fmt)
675
{
676
return !is_hdr_texture_format(fmt);
677
}
678
679
} // namespace basisu
680
681
682