Debian Codegraph @

thirdparty/basis_universal/encoder/basisu_astc_hdr_6x6_enc.h

raw symbols SCIP
1 // File: basisu_astc_hdr_6x6_enc.h
2 #pragma once
3 #include "basisu_enc.h"
4 #include "../transcoder/basisu_astc_hdr_core.h"
5
6 namespace astc_6x6_hdr
7 {
8 const uint32_t ASTC_HDR_6X6_MAX_USER_COMP_LEVEL = 12;
9
10 const uint32_t ASTC_HDR_6X6_MAX_COMP_LEVEL = 4;
11
12 const float LDR_BLACK_BIAS = 0.0f;// .49f;
13
14 // Note: This struct is copied several times, so do not place any heavyweight objects in here.
15 struct astc_hdr_6x6_global_config
16 {
17 // 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.
18 // 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.
19 // By default the encoder assumes the input is in absolute luminance (in nits or candela per square meter, cd/m^2), specified as positive-only linear light RGB, using the REC 709 colorspace gamut (but NOT the sRGB transfer function, i.e. linear light).
20 // 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).
21 // 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).
22 // 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.
23 bool m_rec2020_bt2100_color_gamut = false;
24
25 // levels 0-3 normal levels, 4=exhaustive
26 uint32_t m_master_comp_level = 0;
27 uint32_t m_highest_comp_level = 1;
28
29 float m_lambda = 0.0f;
30
31 bool m_extra_patterns_flag = false; // def to false, works in comp levels [1,4]
32 bool m_brute_force_partition_matching = false; // def to false
33
34 bool m_jnd_optimization = false; // defaults to false for HDR inputs, on SDR upconverted images this can default to enabled
35 float m_jnd_delta_itp_thresh = .75f;
36
37 bool m_force_one_strip = false;
38
39 bool m_gaussian1_fallback = true; // def to true, if this is disabled m_gaussian2_fallback should be disabled too
40 float m_gaussian1_strength = 1.45f;
41
42 bool m_gaussian2_fallback = true; // def to true, hopefully rarely kicks in
43 float m_gaussian2_strength = 1.83f;
44
45 // m_disable_delta_endpoint_usage may give a slight increase in RDO ASTC encoding efficiency. It's also faster.
46 bool m_disable_delta_endpoint_usage = false;
47
48 // Scale up Delta ITP errors for very dark pixels, assuming they will be brightly exposed > 1.0x.
49 // We don't know if the output will be exposed, or not. If heavily exposed, our JND calculations will not be conservative enough.
50 bool m_delta_itp_dark_adjustment = true;
51
52 bool m_debug_images = false;
53 std::string m_debug_image_prefix = "dbg_astc_hdr_6x6_devel_";
54
55 bool m_output_images = false;
56 std::string m_output_image_prefix = "dbg_astc_hdr_6x6_output_";
57
58 bool m_debug_output = false;
59 bool m_image_stats = false;
60 bool m_status_output = false;
61
62 //-------------------------------------------------------------------------------------
63 // Very low level/devel parameters - intended for development. Best not to change them.
64 //-------------------------------------------------------------------------------------
65 bool m_deblocking_flag = true;
66 float m_deblock_penalty_weight = .03f;
67 bool m_disable_twothree_subsets = false; // def to false
68 bool m_use_solid_blocks = true; // def to true
69 bool m_use_runs = true; // def to true
70 bool m_block_stat_optimizations_flag = true; // def to true
71
72 bool m_rdo_candidate_diversity_boost = true; // def to true
73 float m_rdo_candidate_diversity_boost_bit_window_weight = 1.2f;
74
75 bool m_favor_higher_compression = true; // utilize all modes
76 uint32_t m_num_reuse_xy_deltas = basist::astc_6x6_hdr::NUM_REUSE_XY_DELTAS;
77
78 void print() const
79 {
80 basisu::fmt_debug_printf("m_master_comp_level: {}, m_highest_comp_level: {}\n", m_master_comp_level, m_highest_comp_level);
81 basisu::fmt_debug_printf("m_lambda: {}\n", m_lambda);
82 basisu::fmt_debug_printf("m_rec2020_bt2100_color_gamut: {}\n", m_rec2020_bt2100_color_gamut);
83 basisu::fmt_debug_printf("m_extra_patterns_flag: {}, m_brute_force_partition_matching: {}\n", m_extra_patterns_flag, m_brute_force_partition_matching);
84 basisu::fmt_debug_printf("m_jnd_optimization: {}, m_jnd_delta_itp_thresh: {}\n", m_jnd_optimization, m_jnd_delta_itp_thresh);
85 basisu::fmt_debug_printf("m_force_one_strip: {}\n", m_force_one_strip);
86 basisu::fmt_debug_printf("m_gaussian1_fallback: {}, m_gaussian1_strength: {}\n", m_gaussian1_fallback, m_gaussian1_strength);
87 basisu::fmt_debug_printf("m_gaussian2_fallback: {}, m_gaussian2_strength: {}\n", m_gaussian2_fallback, m_gaussian2_strength);
88 basisu::fmt_debug_printf("m_disable_delta_endpoint_usage: {}\n", m_disable_delta_endpoint_usage);
89 basisu::fmt_debug_printf("m_delta_itp_dark_adjustment: {}\n", m_delta_itp_dark_adjustment);
90 basisu::fmt_debug_printf("m_debug_images: {}, m_debug_image_prefix: {}\n", m_debug_images, m_debug_image_prefix);
91 basisu::fmt_debug_printf("m_output_images: {}, m_output_image_prefix: {}\n", m_output_images, m_output_image_prefix);
92 basisu::fmt_debug_printf("m_image_stats: {}, m_status_output: {}\n", m_image_stats, m_status_output);
93 basisu::fmt_debug_printf("m_deblocking_flag: {}, m_deblock_penalty_weight: {}\n", m_deblocking_flag, m_deblock_penalty_weight);
94 basisu::fmt_debug_printf("m_disable_twothree_subsets: {}, m_use_solid_blocks: {}\n", m_disable_twothree_subsets, m_use_solid_blocks);
95 basisu::fmt_debug_printf("m_use_runs: {}, m_block_stat_optimizations_flag: {}\n", m_use_runs, m_block_stat_optimizations_flag);
96 basisu::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);
97 basisu::fmt_debug_printf("m_favor_higher_compression: {}, m_num_reuse_xy_deltas: {}\n", m_favor_higher_compression, m_num_reuse_xy_deltas);
98 }
99
100 astc_hdr_6x6_global_config()
101 {
102 }
103
104 void clear()
105 {
106 astc_hdr_6x6_global_config def;
107 std::swap(*this, def);
108 }
109
110 // Max level is ASTC_HDR_6X6_MAX_USER_COMP_LEVEL
111 void set_user_level(int level);
112 };
113
114 void global_init();
115
116 struct result_metrics
117 {
118 basisu::image_metrics m_im_astc_log2;
119 basisu::image_metrics m_im_astc_half;
120
121 basisu::image_metrics m_im_bc6h_log2;
122 basisu::image_metrics m_im_bc6h_half;
123 };
124
125 // The input image should be unpadded to 6x6 boundaries, i.e. the original unexpanded image.
126 bool compress_photo(const basisu::imagef& orig_src_img, const astc_hdr_6x6_global_config& global_cfg, basisu::job_pool* pJob_pool,
127 basisu::uint8_vec& intermediate_tex_data, basisu::uint8_vec& astc_tex_data, result_metrics& metrics);
128
129 } // namespace uastc_6x6_hdr