Path: blob/master/thirdparty/basis_universal/encoder/basisu_astc_hdr_6x6_enc.h
9906 views
// File: basisu_astc_hdr_6x6_enc.h1#pragma once2#include "basisu_enc.h"3#include "../transcoder/basisu_astc_hdr_core.h"45namespace astc_6x6_hdr6{7const uint32_t ASTC_HDR_6X6_MAX_USER_COMP_LEVEL = 12;89const uint32_t ASTC_HDR_6X6_MAX_COMP_LEVEL = 4;1011const float LDR_BLACK_BIAS = 0.0f;// .49f;1213// Note: This struct is copied several times, so do not place any heavyweight objects in here.14struct astc_hdr_6x6_global_config15{16// Important: The Delta ITP colorspace error metric we use internally makes several assumptions about the nature of the HDR RGB inputs supplied to the encoder.17// This encoder computes colorspace error in the ICtCp (or more accurately the delta ITP, where CT is scaled by .5 vs. ICtCp to become T) colorspace, so getting this correct is important.18// By default the encoder assumes the input is in absolute luminance (in nits or candela per square meter, cd/m²), specified as positive-only linear light RGB, using the REC 709 colorspace gamut (but NOT the sRGB transfer function, i.e. linear light).19// If the m_rec2020_bt2100_color_gamut flag is true, the input colorspace is treated as REC 2020/BT.2100 (which is wider than 709).20// For SDR/LDR->HDR upconversion, the REC 709 sRGB input should be converted to linear light (sRGB->linear) and the resulting normalized linear RGB values scaled by either 80 or 100 nits (the luminance of a typical SDR monitor).21// SDR upconversion to normalized [0,1] (i.e. non-absolute) luminances may work but is not supported because ITP errors will not be predicted correctly.22bool m_rec2020_bt2100_color_gamut = false;2324// levels 0-3 normal levels, 4=exhaustive25uint32_t m_master_comp_level = 0;26uint32_t m_highest_comp_level = 1;2728float m_lambda = 0.0f;2930bool m_extra_patterns_flag = false; // def to false, works in comp levels [1,4]31bool m_brute_force_partition_matching = false; // def to false3233bool m_jnd_optimization = false; // defaults to false for HDR inputs, on SDR upconverted images this can default to enabled34float m_jnd_delta_itp_thresh = .75f;3536bool m_force_one_strip = false;3738bool m_gaussian1_fallback = true; // def to true, if this is disabled m_gaussian2_fallback should be disabled too39float m_gaussian1_strength = 1.45f;4041bool m_gaussian2_fallback = true; // def to true, hopefully rarely kicks in42float m_gaussian2_strength = 1.83f;4344// m_disable_delta_endpoint_usage may give a slight increase in RDO ASTC encoding efficiency. It's also faster.45bool m_disable_delta_endpoint_usage = false;4647// Scale up Delta ITP errors for very dark pixels, assuming they will be brightly exposed > 1.0x.48// We don't know if the output will be exposed, or not. If heavily exposed, our JND calculations will not be conservative enough.49bool m_delta_itp_dark_adjustment = true;5051bool m_debug_images = false;52std::string m_debug_image_prefix = "dbg_astc_hdr_6x6_devel_";5354bool m_output_images = false;55std::string m_output_image_prefix = "dbg_astc_hdr_6x6_output_";5657bool m_debug_output = false;58bool m_image_stats = false;59bool m_status_output = false;6061//-------------------------------------------------------------------------------------62// Very low level/devel parameters - intended for development. Best not to change them.63//-------------------------------------------------------------------------------------64bool m_deblocking_flag = true;65float m_deblock_penalty_weight = .03f;66bool m_disable_twothree_subsets = false; // def to false67bool m_use_solid_blocks = true; // def to true68bool m_use_runs = true; // def to true69bool m_block_stat_optimizations_flag = true; // def to true7071bool m_rdo_candidate_diversity_boost = true; // def to true72float m_rdo_candidate_diversity_boost_bit_window_weight = 1.2f;7374bool m_favor_higher_compression = true; // utilize all modes75uint32_t m_num_reuse_xy_deltas = basist::astc_6x6_hdr::NUM_REUSE_XY_DELTAS;7677void print() const78{79basisu::fmt_debug_printf("m_master_comp_level: {}, m_highest_comp_level: {}\n", m_master_comp_level, m_highest_comp_level);80basisu::fmt_debug_printf("m_lambda: {}\n", m_lambda);81basisu::fmt_debug_printf("m_rec2020_bt2100_color_gamut: {}\n", m_rec2020_bt2100_color_gamut);82basisu::fmt_debug_printf("m_extra_patterns_flag: {}, m_brute_force_partition_matching: {}\n", m_extra_patterns_flag, m_brute_force_partition_matching);83basisu::fmt_debug_printf("m_jnd_optimization: {}, m_jnd_delta_itp_thresh: {}\n", m_jnd_optimization, m_jnd_delta_itp_thresh);84basisu::fmt_debug_printf("m_force_one_strip: {}\n", m_force_one_strip);85basisu::fmt_debug_printf("m_gaussian1_fallback: {}, m_gaussian1_strength: {}\n", m_gaussian1_fallback, m_gaussian1_strength);86basisu::fmt_debug_printf("m_gaussian2_fallback: {}, m_gaussian2_strength: {}\n", m_gaussian2_fallback, m_gaussian2_strength);87basisu::fmt_debug_printf("m_disable_delta_endpoint_usage: {}\n", m_disable_delta_endpoint_usage);88basisu::fmt_debug_printf("m_delta_itp_dark_adjustment: {}\n", m_delta_itp_dark_adjustment);89basisu::fmt_debug_printf("m_debug_images: {}, m_debug_image_prefix: {}\n", m_debug_images, m_debug_image_prefix);90basisu::fmt_debug_printf("m_output_images: {}, m_output_image_prefix: {}\n", m_output_images, m_output_image_prefix);91basisu::fmt_debug_printf("m_image_stats: {}, m_status_output: {}\n", m_image_stats, m_status_output);92basisu::fmt_debug_printf("m_deblocking_flag: {}, m_deblock_penalty_weight: {}\n", m_deblocking_flag, m_deblock_penalty_weight);93basisu::fmt_debug_printf("m_disable_twothree_subsets: {}, m_use_solid_blocks: {}\n", m_disable_twothree_subsets, m_use_solid_blocks);94basisu::fmt_debug_printf("m_use_runs: {}, m_block_stat_optimizations_flag: {}\n", m_use_runs, m_block_stat_optimizations_flag);95basisu::fmt_debug_printf("m_rdo_candidate_diversity_boost: {}, m_rdo_candidate_diversity_boost_bit_window_weight: {}\n", m_rdo_candidate_diversity_boost, m_rdo_candidate_diversity_boost_bit_window_weight);96basisu::fmt_debug_printf("m_favor_higher_compression: {}, m_num_reuse_xy_deltas: {}\n", m_favor_higher_compression, m_num_reuse_xy_deltas);97}9899astc_hdr_6x6_global_config()100{101}102103void clear()104{105astc_hdr_6x6_global_config def;106std::swap(*this, def);107}108109// Max level is ASTC_HDR_6X6_MAX_USER_COMP_LEVEL110void set_user_level(int level);111};112113void global_init();114115struct result_metrics116{117basisu::image_metrics m_im_astc_log2;118basisu::image_metrics m_im_astc_half;119120basisu::image_metrics m_im_bc6h_log2;121basisu::image_metrics m_im_bc6h_half;122};123124// The input image should be unpadded to 6x6 boundaries, i.e. the original unexpanded image.125bool compress_photo(const basisu::imagef& orig_src_img, const astc_hdr_6x6_global_config& global_cfg, basisu::job_pool* pJob_pool,126basisu::uint8_vec& intermediate_tex_data, basisu::uint8_vec& astc_tex_data, result_metrics& metrics);127128} // namespace uastc_6x6_hdr129130131