Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

rf-jxl: edge-preserving filter on, tuned defaults

gelenmedya1183fa2863da
diff --git a/crates/rf-jxl/src/lib.rs b/crates/rf-jxl/src/lib.rs
index 637a8156..614e6609 100644
--- a/crates/rf-jxl/src/lib.rs
+++ b/crates/rf-jxl/src/lib.rs
@@ -18,6 +18,10 @@ use modular::{Chan, T, Tree};
/// The biggest picture side the encoder takes (one low-frequency group, which is 2048 pixels).
pub const MAX_SIDE: u32 = 2048;
+/// The decoder's default parameters of its edge-preserving filter's strength: the factor on the quantization step, the
+/// scale of the first and the last pass, the border weight.
+const EPF_SIGMA_DEFAULT: [f32; 4] = [0.46, 0.9, 6.5, 2.0 / 3.0];
+
/// Pixels per group side.
const GROUP: usize = 256;
@@ -37,6 +41,8 @@ pub struct Tuning {
/// The decoder's 3x3 smoothing; only worth it when the encoder sharpens before the transform, which it does not.
pub gaborish: bool,
pub epf_sharpness: u8,
+ /// How strongly the filter works (see `EPF_SIGMA_DEFAULT`).
+ pub epf_sigma: [f32; 4],
/// Print where the bytes go (for the measuring tools).
pub verbose: bool,
/// How much coarser X and B are quantized than the weights say (1.25 per step above 2).
@@ -67,13 +73,14 @@ impl Tuning {
Tuning {
distance,
strength: 1.0,
- dc_mult: 0.55,
+ dc_mult: 0.45,
round_threshold: 0.5,
- epf_iters: 0,
+ epf_iters: 1,
gaborish: false,
- epf_sharpness: 4,
+ epf_sharpness: 7,
+ epf_sigma: [0.7, 0.9, 6.5, 2.0 / 3.0],
verbose: false,
- x_qm_scale: 3,
+ x_qm_scale: 2,
b_qm_scale: 2,
dc_scale: [1.0; 3],
band_delta: [[0.0; 6]; 3],
@@ -93,6 +100,10 @@ impl Tuning {
"gab" => self.gaborish = v > 0.0,
"sharp" => self.epf_sharpness = v as u8,
"verbose" => self.verbose = v > 0.0,
+ "eq" => self.epf_sigma[0] = v,
+ "e0" => self.epf_sigma[1] = v,
+ "e2" => self.epf_sigma[2] = v,
+ "eb" => self.epf_sigma[3] = v,
"xqm" => self.x_qm_scale = v as u32,
"bqm" => self.b_qm_scale = v as u32,
"cfl" => self.cfl = v > 0.0,
@@ -432,7 +443,14 @@ pub fn encode_tuned(width: u32, height: u32, rgba: &[u8], has_alpha: bool, tunin
if tuning.epf_iters > 0 {
out.put(0, 1); // sharpness table
out.put(0, 1); // weights
- out.put(0, 1); // sigma
+ if tuning.epf_sigma == EPF_SIGMA_DEFAULT {
+ out.put(0, 1);
+ } else {
+ out.put(1, 1);
+ for v in tuning.epf_sigma {
+ out.put(bits::f16_bits(v) as u64, 16);
+ }
+ }
}
out.put(0, 2); // no extensions
out.put(0, 2); // frame header extensions