#include "basisu_astc_hdr_enc.h"
#include "../transcoder/basisu_transcoder.h"
usingnamespacebasist;
namespace basisu
{
const float DEF_R_ERROR_SCALE = …;
const float DEF_G_ERROR_SCALE = …;
static inline uint32_t get_max_qlog(uint32_t bits)
{ … }
#if 0
static inline float get_max_qlog_val(uint32_t bits)
{
switch (bits)
{
case 7: return MAX_QLOG7_VAL;
case 8: return MAX_QLOG8_VAL;
case 9: return MAX_QLOG9_VAL;
case 10: return MAX_QLOG10_VAL;
case 11: return MAX_QLOG11_VAL;
case 12: return MAX_QLOG12_VAL;
case 16: return MAX_QLOG16_VAL;
default: assert(0); break;
}
return 0;
}
#endif
static inline int get_bit(
int src_val, int src_bit)
{ … }
static inline void pack_bit(
int& dst, int dst_bit,
int src_val, int src_bit = 0)
{ … }
astc_hdr_codec_options::astc_hdr_codec_options()
{ … }
void astc_hdr_codec_options::init()
{ … }
void astc_hdr_codec_options::set_quality_best()
{ … }
void astc_hdr_codec_options::set_quality_normal()
{ … }
void astc_hdr_codec_options::set_quality_fastest()
{ … }
void astc_hdr_codec_options::set_quality_level(int level)
{ … }
#if 0
static inline half_float qlog12_to_half_slow(uint32_t qlog12)
{
return qlog_to_half_slow(qlog12, 12);
}
#endif
static half_float g_qlog16_to_half[65536];
inline half_float qlog_to_half(uint32_t val, uint32_t bits)
{ … }
static uint16_t g_half_to_qlog7[32768], g_half_to_qlog8[32768], g_half_to_qlog9[32768], g_half_to_qlog10[32768], g_half_to_qlog11[32768], g_half_to_qlog12[32768];
const uint32_t HALF_TO_QLOG_TABS_BASE = …;
static uint16_t* g_pHalf_to_qlog_tabs[8] = …;
static inline uint32_t half_to_qlog7_12(half_float h, uint32_t bits)
{ … }
#if 0
static int qlog11_to_half_float_mantissa(int M)
{
assert(M <= 0x7FF);
int Mt;
if (M < 512)
Mt = 3 * M;
else if (M >= 1536)
Mt = 5 * M - 2048;
else
Mt = 4 * M - 512;
return (Mt >> 3);
}
#endif
static inline int half_float_mantissa_to_qlog11(int hf)
{ … }
static inline int half_to_qlog16(int hf)
{ … }
static inline uint32_t quant_qlog16(uint32_t q16, uint32_t desired_bits)
{ … }
static void compute_half_to_qlog_table(uint32_t bits, uint16_t* pTable, const basisu::vector<float> &qlog16_to_float)
{ … }
static void init_qlog_tables()
{ … }
const uint32_t MIN_SUPPORTED_ISE_WEIGHT_INDEX = …;
const uint32_t MAX_SUPPORTED_ISE_WEIGHT_INDEX = …;
static const uint8_t g_ise_weight_lerps[MAX_SUPPORTED_ISE_WEIGHT_INDEX + 1][32] = …;
static vec3F calc_mean(uint32_t num_pixels, const vec4F* pPixels)
{ … }
static vec3F calc_rgb_pca(uint32_t num_pixels, const vec4F* pPixels, const vec3F& mean_color)
{ … }
static vec3F interp_color(const vec3F& mean, const vec3F& dir, float df, const aabb3F& colorspace_box, const aabb3F& input_box, bool* pInside = nullptr)
{ … }
static bool compute_least_squares_endpoints_rgb(
uint32_t N, const uint8_t* pSelectors, const vec4F* pSelector_weights,
vec3F* pXl, vec3F* pXh, const vec4F* pColors, const aabb3F& input_box)
{ … }
static vec4F g_astc_ls_weights_ise[MAX_SUPPORTED_ISE_WEIGHT_INDEX + 1][24];
static uint8_t g_map_astc_to_linear_order[MAX_SUPPORTED_ISE_WEIGHT_INDEX + 1][24];
static uint8_t g_map_linear_to_astc_order[MAX_SUPPORTED_ISE_WEIGHT_INDEX + 1][24];
static void encode_astc_hdr_init()
{ … }
void interpolate_qlog12_colors(
const int e[2][3],
half_float* pDecoded_half,
vec3F* pDecoded_float,
uint32_t n, uint32_t ise_weight_range)
{ … }
bool get_astc_hdr_mode_11_block_colors(
const uint8_t* pEndpoints,
half_float* pDecoded_half,
vec3F* pDecoded_float,
uint32_t n, uint32_t ise_weight_range, uint32_t ise_endpoint_range)
{ … }
bool get_astc_hdr_mode_7_block_colors(
const uint8_t* pEndpoints,
half_float* pDecoded_half,
vec3F* pDecoded_float,
uint32_t n, uint32_t ise_weight_range, uint32_t ise_endpoint_range)
{ … }
static inline double q(half_float x)
{ … }
double eval_selectors(
uint32_t num_pixels,
uint8_t* pWeights,
const half_float* pBlock_pixels_half,
uint32_t num_weight_levels,
const half_float* pDecoded_half,
const astc_hdr_codec_options& coptions,
uint32_t usable_selector_bitmask)
{ … }
double compute_block_error(const half_float* pOrig_block, const half_float* pPacked_block, const astc_hdr_codec_options& coptions)
{ … }
static inline int compute_clamped_val(int v, int l, int h, bool& did_clamp, int& max_clamp_mag)
{ … }
static bool pack_astc_mode11_submode(uint32_t submode, uint8_t* pEndpoints, const vec3F& low_q16, const vec3F& high_q16, int& max_clamp_mag)
{ … }
static void pack_astc_mode11_direct(uint8_t* pEndpoints, const vec3F& l_q16, const vec3F& h_q16)
{ … }
static bool pack_astc_mode7_submode(uint32_t submode, uint8_t* pEndpoints, const vec3F& rgb_q16, float s_q16, int& max_clamp_mag, uint32_t ise_weight_range)
{ … }
static void quantize_ise_endpoints(uint32_t ise_endpoint_range, const uint8_t* pSrc_endpoints, uint8_t *pDst_endpoints, uint32_t n)
{ … }
static bool try_mode11(uint32_t num_pixels,
uint8_t* pEndpoints, uint8_t* pWeights, double& cur_block_error, uint32_t& submode_used,
vec3F& low_color_q16, const vec3F& high_color_q16,
half_float block_pixels_half[16][3],
uint32_t num_weight_levels, uint32_t ise_weight_range, const astc_hdr_codec_options& coptions, bool direct_only, uint32_t ise_endpoint_range,
bool constrain_ise_weight8_selectors,
int32_t first_submode, int32_t last_submode)
{ … }
static bool try_mode7(
uint32_t num_pixels,
uint8_t* pEndpoints, uint8_t* pWeights, double& cur_block_error, uint32_t& submode_used,
vec3F& high_color_q16, const float s_q16,
half_float block_pixels_half[16][3],
uint32_t num_weight_levels, uint32_t ise_weight_range, const astc_hdr_codec_options& coptions,
uint32_t ise_endpoint_range)
{ … }
static double encode_astc_hdr_block_mode_11(
uint32_t num_pixels,
const vec4F* pBlock_pixels,
uint32_t ise_weight_range,
uint32_t& best_submode,
double cur_block_error,
uint8_t* blk_endpoints, uint8_t* blk_weights,
const astc_hdr_codec_options& coptions,
bool direct_only,
uint32_t ise_endpoint_range,
bool uber_mode,
bool constrain_ise_weight8_selectors,
int32_t first_submode, int32_t last_submode)
{ … }
static double encode_astc_hdr_block_mode_7(
uint32_t num_pixels, const vec4F* pBlock_pixels,
uint32_t ise_weight_range,
uint32_t& best_submode,
double cur_block_error,
uint8_t* blk_endpoints,
uint8_t* blk_weights,
const astc_hdr_codec_options& coptions,
uint32_t ise_endpoint_range)
{ … }
static bool pack_solid(const vec4F* pBlock_linear_colors, basisu::vector<astc_hdr_pack_results>& all_results, const astc_hdr_codec_options& coptions)
{ … }
static void pack_mode11(
const vec4F* pBlock_linear_colors,
basisu::vector<astc_hdr_pack_results>& all_results,
const astc_hdr_codec_options& coptions,
uint32_t first_weight_ise_range, uint32_t last_weight_ise_range, bool constrain_ise_weight8_selectors)
{ … }
static void pack_mode7_single_part(const vec4F* pBlock_linear_colors, basisu::vector<astc_hdr_pack_results>& all_results, const astc_hdr_codec_options& coptions)
{ … }
static bool estimate_partition2(const vec4F* pBlock_pixels, int* pBest_parts, uint32_t num_best_parts)
{ … }
static void pack_mode7_2part(const vec4F* pBlock_linear_colors, basisu::vector<astc_hdr_pack_results>& all_results, const astc_hdr_codec_options& coptions,
int num_estimated_partitions, const int *pEstimated_partitions,
uint32_t first_weight_ise_range, uint32_t last_weight_ise_range)
{ … }
static void pack_mode11_2part(const vec4F* pBlock_linear_colors, basisu::vector<astc_hdr_pack_results>& all_results, const astc_hdr_codec_options& coptions,
int num_estimated_partitions, const int* pEstimated_partitions)
{ … }
bool g_astc_hdr_enc_initialized;
void astc_hdr_enc_init()
{ … }
bool astc_hdr_enc_block(
const float* pRGBPixels,
const astc_hdr_codec_options& coptions,
basisu::vector<astc_hdr_pack_results>& all_results)
{ … }
bool astc_hdr_pack_results_to_block(astc_blk& dst_blk, const astc_hdr_pack_results& results)
{ … }
bool astc_hdr_refine_weights(const half_float *pSource_block, astc_hdr_pack_results& cur_results, const astc_hdr_codec_options& coptions, float bc6h_weight, bool *pImproved_flag)
{ … }
void astc_hdr_block_stats::update(const astc_hdr_pack_results& log_blk)
{ … }
void astc_hdr_block_stats::print()
{ … }
}