godot/thirdparty/basis_universal/transcoder/basisu.h

// basisu.h
// Copyright (C) 2019-2024 Binomial LLC. All Rights Reserved.
// Important: If compiling with gcc, be sure strict aliasing is disabled: -fno-strict-aliasing
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once

#ifdef _MSC_VER

	#pragma warning (disable : 4201)
	#pragma warning (disable : 4127) // warning C4127: conditional expression is constant
	#pragma warning (disable : 4530) // C++ exception handler used, but unwind semantics are not enabled.

	// Slamming this off always for v1.16 because we've gotten rid of most std containers.
	#ifndef BASISU_NO_ITERATOR_DEBUG_LEVEL
		#define BASISU_NO_ITERATOR_DEBUG_LEVEL
	#endif

	#ifndef BASISU_NO_ITERATOR_DEBUG_LEVEL
		//#define _HAS_ITERATOR_DEBUGGING 0

		#if defined(_DEBUG) || defined(DEBUG)
			// This is madness, but we need to disable iterator debugging in debug builds or the encoder is unsable because MSVC's iterator debugging implementation is totally broken.
			#ifndef _ITERATOR_DEBUG_LEVEL
			#define _ITERATOR_DEBUG_LEVEL
			#endif
			#ifndef _SECURE_SCL
			#define _SECURE_SCL
			#endif
		#else // defined(_DEBUG) || defined(DEBUG)
			#ifndef _SECURE_SCL
			#define _SECURE_SCL
			#endif
			#ifndef _ITERATOR_DEBUG_LEVEL
			#define _ITERATOR_DEBUG_LEVEL
			#endif
		#endif // defined(_DEBUG) || defined(DEBUG)

	#endif // BASISU_NO_ITERATOR_DEBUG_LEVEL

#endif // _MSC_VER

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <stdint.h>

#include <algorithm>
#include <limits>
#include <functional>
#include <iterator>
#include <type_traits>
#include <assert.h>
#include <random>

#include "basisu_containers.h"

#ifdef max
#undef max
#endif

#ifdef min
#undef min
#endif

#ifdef _WIN32
#define strcasecmp
#endif

// Set to one to enable debug printf()'s when any errors occur, for development/debugging. Especially useful for WebGL development.
#ifndef BASISU_FORCE_DEVEL_MESSAGES
#define BASISU_FORCE_DEVEL_MESSAGES
#endif

#define BASISU_NOTE_UNUSED(x)
#define BASISU_ARRAY_SIZE(x)
#define BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(x)
#define BASISU_ASSUME(x)
#define BASISU_OFFSETOF(s, m)
#define BASISU_STRINGIZE(x)
#define BASISU_STRINGIZE2(x)

#if BASISU_FORCE_DEVEL_MESSAGES
	#define BASISU_DEVEL_ERROR
#else
	#define BASISU_DEVEL_ERROR(...)
#endif

namespace basisu
{
	// Types/utilities

#ifdef _WIN32
	const char BASISU_PATH_SEPERATOR_CHAR = '\\';
#else
	const char BASISU_PATH_SEPERATOR_CHAR =;
#endif

	uint8_vec;
	int16_vec;
	uint16_vec;
	uint_vec;
	uint64_vec;
	int_vec;
	bool_vec;
	float_vec;

	void enable_debug_printf(bool enabled);
	void debug_printf(const char *pFmt, ...);

#ifndef __EMSCRIPTEN__
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"            
#endif                  
#endif
		
	template <typename T> inline void clear_obj(T& obj) {}

#ifndef __EMSCRIPTEN__
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif                            
#endif

	template <typename T0, typename T1> inline T0 lerp(T0 a, T0 b, T1 c) {}

	template <typename S> inline S maximum(S a, S b) {}
	template <typename S> inline S maximum(S a, S b, S c) {}
	template <typename S> inline S maximum(S a, S b, S c, S d) {}
	
	template <typename S> inline S minimum(S a, S b) {}
	template <typename S> inline S minimum(S a, S b, S c) {}
	template <typename S> inline S minimum(S a, S b, S c, S d) {}

	inline float clampf(float value, float low, float high) {}
	inline float saturate(float value) {}
	inline uint8_t minimumub(uint8_t a, uint8_t b) {}
	inline uint32_t minimumu(uint32_t a, uint32_t b) {}
	inline int32_t minimumi(int32_t a, int32_t b) {}
	inline float minimumf(float a, float b) {}
	inline uint8_t maximumub(uint8_t a, uint8_t b) {}
	inline uint32_t maximumu(uint32_t a, uint32_t b) {}
	inline int32_t maximumi(int32_t a, int32_t b) {}
	inline float maximumf(float a, float b) {}
	inline int squarei(int i) {}
	inline float squaref(float i) {}
	template<typename T> inline T square(T a) {}

	template <typename S> inline S clamp(S value, S low, S high) {}

	inline uint32_t iabs(int32_t i) {}
	inline uint64_t iabs64(int64_t i) {}

	template<typename T> inline void clear_vector(T &vec) {}		
	template<typename T> inline typename T::value_type *enlarge_vector(T &vec, size_t n) {}

	inline bool is_pow2(uint32_t x) {}
	inline bool is_pow2(uint64_t x) {}

	template<typename T> inline T open_range_check(T v, T minv, T maxv) {}
	template<typename T> inline T open_range_check(T v, T maxv) {}

	// Open interval
	inline bool in_bounds(int v, int l, int h)
	{}

	// Closed interval
	inline bool in_range(int v, int l, int h)
	{}

	inline uint32_t total_bits(uint32_t v) {}

	template<typename T> inline T saturate(T val) {}

	inline uint32_t get_bit(uint32_t src, int ndx)
	{}

	inline bool is_bit_set(uint32_t src, int ndx)
	{}

	inline uint32_t get_bits(uint32_t val, int low, int high)
	{}

	template<typename T, typename R> inline void append_vector(T &vec, const R *pObjs, size_t n) 
	{}

	template<typename T> inline void append_vector(T &vec, const T &other_vec)
	{}

	template<typename T> inline void vector_ensure_element_is_valid(T &vec, size_t idx)
	{}

	template<typename T> inline void vector_sort(T &vec)
	{}

	template<typename T, typename U> inline bool unordered_set_contains(T& set, const U&obj)
	{}

	template<typename T> int vector_find(const T &vec, const typename T::value_type &obj)
	{}

	template<typename T> void vector_set_all(T &vec, const typename T::value_type &obj)
	{}
		
	inline uint64_t read_be64(const void *p)
	{}

	inline void write_be64(void *p, uint64_t x)
	{}

	static inline uint16_t byteswap16(uint16_t x) {}
	static inline uint32_t byteswap32(uint32_t x) {}

	inline uint32_t floor_log2i(uint32_t v)
	{}

	inline uint32_t ceil_log2i(uint32_t v)
	{}

	inline int posmod(int x, int y)
	{}

	inline bool do_excl_ranges_overlap(int la, int ha, int lb, int hb)
	{}

	static inline uint32_t read_le_word(const uint8_t* pBytes)
	{}

	static inline uint32_t read_le_dword(const uint8_t *pBytes)
	{}

	static inline void write_le_dword(uint8_t* pBytes, uint32_t val)
	{}
		
	// Always little endian 1-8 byte unsigned int
	template<uint32_t NumBytes>
	struct packed_uint
	{};

	enum eZero {};
	enum eNoClamp {};
	
	// Rice/Huffman entropy coding
		
	// This is basically Deflate-style canonical Huffman, except we allow for a lot more symbols.
	enum
	{};

	static const uint8_t g_huffman_sorted_codelength_codes[] =;
	const uint32_t cHuffmanTotalSortedCodelengthCodes =;

	// GPU texture formats

	enum class texture_format
	{};

	// This is bytes per block for GPU formats, or bytes per texel for uncompressed formats.
	inline uint32_t get_bytes_per_block(texture_format fmt)
	{}

	// This is qwords per block for GPU formats, or not valid for uncompressed formats.
	inline uint32_t get_qwords_per_block(texture_format fmt)
	{}

	inline uint32_t get_block_width(texture_format fmt)
	{}

	inline uint32_t get_block_height(texture_format fmt)
	{}

	inline bool is_hdr_texture_format(texture_format fmt)
	{}
							
} // namespace basisu