godot/thirdparty/basis_universal/encoder/basisu_enc.cpp

// basisu_enc.cpp
// Copyright (C) 2019-2024 Binomial LLC. All Rights Reserved.
//
// 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.
#include "basisu_enc.h"
#include "basisu_resampler.h"
#include "basisu_resampler_filters.h"
#include "basisu_etc.h"
#include "../transcoder/basisu_transcoder.h"
#include "basisu_bc7enc.h"
#include "jpgd.h"
#include "pvpngreader.h"
#include "basisu_opencl.h"
#include "basisu_astc_hdr_enc.h"
#include <vector>

#ifndef TINYEXR_USE_ZFP
#define TINYEXR_USE_ZFP
#endif
#include <tinyexr.h>

#ifndef MINIZ_HEADER_FILE_ONLY
#define MINIZ_HEADER_FILE_ONLY
#endif
#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
#endif
#include "basisu_miniz.h"

#if defined(_WIN32)
// For QueryPerformanceCounter/QueryPerformanceFrequency
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

namespace basisu
{
	uint64_t interval_timer::g_init_ticks, interval_timer::g_freq;
	double interval_timer::g_timer_freq;
#if BASISU_SUPPORT_SSE
	bool g_cpu_supports_sse41;
#endif

	uint8_t g_hamming_dist[256] =;

	// This is a Public Domain 8x8 font from here:
	// https://github.com/dhepper/font8x8/blob/master/font8x8_basic.h
	const uint8_t g_debug_font8x8_basic[127 - 32 + 1][8] =;

	bool g_library_initialized;
	std::mutex g_encoder_init_mutex;
		
	// Encoder library initialization (just call once at startup)
	bool basisu_encoder_init(bool use_opencl, bool opencl_force_serialization)
	{}

	void basisu_encoder_deinit()
	{}

	void error_vprintf(const char* pFmt, va_list args)
	{}

	void error_printf(const char *pFmt, ...)
	{}

#if defined(_WIN32)
	inline void query_counter(timer_ticks* pTicks)
	{
		QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(pTicks));
	}
	inline void query_counter_frequency(timer_ticks* pTicks)
	{
		QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(pTicks));
	}
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__)
#include <sys/time.h>
	inline void query_counter(timer_ticks* pTicks)
	{
		struct timeval cur_time;
		gettimeofday(&cur_time, NULL);
		*pTicks = static_cast<unsigned long long>(cur_time.tv_sec) * 1000000ULL + static_cast<unsigned long long>(cur_time.tv_usec);
	}
	inline void query_counter_frequency(timer_ticks* pTicks)
	{
		*pTicks = 1000000;
	}
#elif defined(__GNUC__)
#include <sys/timex.h>
	inline void query_counter(timer_ticks* pTicks)
	{}
	inline void query_counter_frequency(timer_ticks* pTicks)
	{}
#else
#error TODO
#endif
				
	interval_timer::interval_timer() :{}

	void interval_timer::start()
	{}

	void interval_timer::stop()
	{}

	double interval_timer::get_elapsed_secs() const
	{}
		
	void interval_timer::init()
	{}

	timer_ticks interval_timer::get_ticks()
	{}

	double interval_timer::ticks_to_secs(timer_ticks ticks)
	{}

	float linear_to_srgb(float l)
	{}

	float srgb_to_linear(float s)
	{}
		
	const uint32_t MAX_32BIT_ALLOC_SIZE =;
		
	bool load_tga(const char* pFilename, image& img)
	{}

	bool load_qoi(const char* pFilename, image& img)
	{}

	bool load_png(const uint8_t *pBuf, size_t buf_size, image &img, const char *pFilename)
	{}
		
	bool load_png(const char* pFilename, image& img)
	{}

	bool load_jpg(const char *pFilename, image& img)
	{}

	bool load_image(const char* pFilename, image& img)
	{}

	static void convert_ldr_to_hdr_image(imagef &img, const image &ldr_img, bool ldr_srgb_to_linear)
	{}

	bool load_image_hdr(const void* pMem, size_t mem_size, imagef& img, uint32_t width, uint32_t height, hdr_image_type img_type, bool ldr_srgb_to_linear)
	{}
	
	bool load_image_hdr(const char* pFilename, imagef& img, bool ldr_srgb_to_linear)
	{}
	
	bool save_png(const char* pFilename, const image &img, uint32_t image_save_flags, uint32_t grayscale_comp)
	{}
		
	bool read_file_to_vec(const char* pFilename, uint8_vec& data)
	{}

	bool read_file_to_data(const char* pFilename, void *pData, size_t len)
	{}

	bool write_data_to_file(const char* pFilename, const void* pData, size_t len)
	{}
		
	bool image_resample(const image &src, image &dst, bool srgb,
		const char *pFilter, float filter_scale, 
		bool wrapping,
		uint32_t first_comp, uint32_t num_comps)
	{}

	bool image_resample(const imagef& src, imagef& dst, 
		const char* pFilter, float filter_scale,
		bool wrapping,
		uint32_t first_comp, uint32_t num_comps)
	{}

	void canonical_huffman_calculate_minimum_redundancy(sym_freq *A, int num_syms)
	{}

	void canonical_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
	{}

	sym_freq *canonical_huffman_radix_sort_syms(uint32_t num_syms, sym_freq *pSyms0, sym_freq *pSyms1)
	{}

	bool huffman_encoding_table::init(uint32_t num_syms, const uint16_t *pFreq, uint32_t max_code_size)
	{}

	bool huffman_encoding_table::init(uint32_t num_syms, const uint32_t *pSym_freq, uint32_t max_code_size)
	{}

	void bitwise_coder::end_nonzero_run(uint16_vec &syms, uint32_t &run_size, uint32_t len)
	{}

	void bitwise_coder::end_zero_run(uint16_vec &syms, uint32_t &run_size)
	{}

	uint32_t bitwise_coder::emit_huffman_table(const huffman_encoding_table &tab)
	{}

	bool huffman_test(int rand_seed)
	{}

	void palette_index_reorderer::init(uint32_t num_indices, const uint32_t *pIndices, uint32_t num_syms, pEntry_dist_func pDist_func, void *pCtx, float dist_func_weight)
	{}

	void palette_index_reorderer::prepare_hist(uint32_t num_syms, uint32_t num_indices, const uint32_t *pIndices)
	{}

	void palette_index_reorderer::find_initial(uint32_t num_syms)
	{}

	void palette_index_reorderer::find_next_entry(uint32_t &best_entry, double &best_count, pEntry_dist_func pDist_func, void *pCtx, float dist_func_weight)
	{}

	float palette_index_reorderer::pick_side(uint32_t num_syms, uint32_t entry_to_move, pEntry_dist_func pDist_func, void *pCtx, float dist_func_weight)
	{}
	
	void image_metrics::calc(const imagef& a, const imagef& b, uint32_t first_chan, uint32_t total_chans, bool avg_comp_error, bool log)
	{}

	void image_metrics::calc_half(const imagef& a, const imagef& b, uint32_t first_chan, uint32_t total_chans, bool avg_comp_error)
	{}

	// Alt. variant, same as calc_half(), for validation.
	void image_metrics::calc_half2(const imagef& a, const imagef& b, uint32_t first_chan, uint32_t total_chans, bool avg_comp_error)
	{}

	void image_metrics::calc(const image &a, const image &b, uint32_t first_chan, uint32_t total_chans, bool avg_comp_error, bool use_601_luma)
	{}

	void fill_buffer_with_random_bytes(void *pBuf, size_t size, uint32_t seed)
	{}

	uint32_t hash_hsieh(const uint8_t *pBuf, size_t len)
	{}

	job_pool::job_pool(uint32_t num_threads) :{}

	job_pool::~job_pool()
	{}
				
	void job_pool::add_job(const std::function<void()>& job)
	{}

	void job_pool::add_job(std::function<void()>&& job)
	{}

	void job_pool::wait_for_all()
	{}

	void job_pool::job_thread(uint32_t index)
	{}

	// .TGA image loading
	#pragma pack(push)
	#pragma pack(1)
	struct tga_header
	{};
	#pragma pack(pop)

	const uint32_t MAX_TGA_IMAGE_SIZE =;

	enum tga_image_type
	{};

	uint8_t *read_tga(const uint8_t *pBuf, uint32_t buf_size, int &width, int &height, int &n_chans)
	{}

	uint8_t *read_tga(const char *pFilename, int &width, int &height, int &n_chans)
	{}

	static inline void hdr_convert(const color_rgba& rgbe, vec4F& c)
	{}

	bool string_begins_with(const std::string& str, const char* pPhrase)
	{}

	// Radiance RGBE (.HDR) image reading.
	// This code tries to preserve the original logic in Radiance's ray/src/common/color.c code:
	// https://www.radiance-online.org/cgi-bin/viewcvs.cgi/ray/src/common/color.c?revision=2.26&view=markup&sortby=log
	// Also see: https://flipcode.com/archives/HDR_Image_Reader.shtml.
	// https://github.com/LuminanceHDR/LuminanceHDR/blob/master/src/Libpfs/io/rgbereader.cpp.
	// https://radsite.lbl.gov/radiance/refer/filefmts.pdf
	// Buggy readers:
	// stb_image.h: appears to be a clone of rgbe.c, but with goto's (doesn't support old format files, doesn't support mixture of RLE/non-RLE scanlines)
	// http://www.graphics.cornell.edu/~bjw/rgbe.html - rgbe.c/h
	// http://www.graphics.cornell.edu/online/formats/rgbe/ - rgbe.c/.h - buggy
	bool read_rgbe(const uint8_vec &filedata, imagef& img, rgbe_header_info& hdr_info)
	{}

	bool read_rgbe(const char* pFilename, imagef& img, rgbe_header_info& hdr_info)
	{}

	static uint8_vec& append_string(uint8_vec& buf, const char* pStr)
	{}
	
	static uint8_vec& append_string(uint8_vec& buf, const std::string& str)
	{}

	static inline void float2rgbe(color_rgba &rgbe, const vec4F &c)
	{}

	const bool RGBE_FORCE_RAW =;
	const bool RGBE_FORCE_OLD_CRUNCH =; // note must readers (particularly stb_image.h's) don't properly support this, when they should
		
	bool write_rgbe(uint8_vec &file_data, imagef& img, rgbe_header_info& hdr_info)
	{}

	bool write_rgbe(const char* pFilename, imagef& img, rgbe_header_info& hdr_info)
	{}
		
	bool read_exr(const char* pFilename, imagef& img, int& n_chans)
	{}

	bool read_exr(const void* pMem, size_t mem_size, imagef& img)
	{}

	bool write_exr(const char* pFilename, imagef& img, uint32_t n_chans, uint32_t flags)
	{}

	void image::debug_text(uint32_t x_ofs, uint32_t y_ofs, uint32_t scale_x, uint32_t scale_y, const color_rgba& fg, const color_rgba* pBG, bool alpha_only, const char* pFmt, ...)
	{}
	
	// Very basic global Reinhard tone mapping, output converted to sRGB with no dithering, alpha is carried through unchanged. 
	// Only used for debugging/development.
	void tonemap_image_reinhard(image &ldr_img, const imagef &hdr_img, float exposure)
	{}

	bool tonemap_image_compressive(image& dst_img, const imagef& hdr_test_img)
	{}
					
} // namespace basisu