Skip to content

Commit d604a42

Browse files
narrowstacksclaude
andcommitted
style: Apply cargo fmt formatting
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7a9256a commit d604a42

8 files changed

Lines changed: 161 additions & 136 deletions

File tree

crates/invers-cli/src/main.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{Parser, Subcommand};
2-
use invers_cli::{parse_roi, determine_output_path, build_convert_options};
2+
use invers_cli::{build_convert_options, determine_output_path, parse_roi};
33
use rayon::prelude::*;
44
use std::path::PathBuf;
55
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -511,7 +511,6 @@ fn cmd_analyze_base(
511511
Ok(())
512512
}
513513

514-
515514
fn cmd_batch(
516515
inputs: Vec<PathBuf>,
517516
base_from: Option<PathBuf>,
@@ -566,10 +565,7 @@ fn cmd_batch(
566565
None
567566
};
568567

569-
println!(
570-
"\nProcessing {} files in parallel...\n",
571-
inputs.len()
572-
);
568+
println!("\nProcessing {} files in parallel...\n", inputs.len());
573569

574570
// Progress tracking
575571
let processed_count = AtomicUsize::new(0);
@@ -709,8 +705,10 @@ fn cmd_preset_show(preset: String) -> Result<(), String> {
709705
};
710706

711707
println!("\nPreset: {}", preset_obj.name);
712-
println!("Base Offsets (RGB): [{:.6}, {:.6}, {:.6}]",
713-
preset_obj.base_offsets[0], preset_obj.base_offsets[1], preset_obj.base_offsets[2]);
708+
println!(
709+
"Base Offsets (RGB): [{:.6}, {:.6}, {:.6}]",
710+
preset_obj.base_offsets[0], preset_obj.base_offsets[1], preset_obj.base_offsets[2]
711+
);
714712

715713
println!("\nTone Curve:");
716714
println!(" Type: {}", preset_obj.tone_curve.curve_type);
@@ -750,12 +748,11 @@ fn cmd_preset_create(output: PathBuf, name: String) -> Result<(), String> {
750748
};
751749

752750
// Serialize to YAML
753-
let yaml_str = serde_yaml::to_string(&preset)
754-
.map_err(|e| format!("Failed to serialize preset: {}", e))?;
751+
let yaml_str =
752+
serde_yaml::to_string(&preset).map_err(|e| format!("Failed to serialize preset: {}", e))?;
755753

756754
// Write to file
757-
std::fs::write(&output, yaml_str)
758-
.map_err(|e| format!("Failed to write preset file: {}", e))?;
755+
std::fs::write(&output, yaml_str).map_err(|e| format!("Failed to write preset file: {}", e))?;
759756

760757
println!("Preset created: {}", output.display());
761758
println!("You can now edit this file to customize the parameters.");

crates/invers-core/src/auto_adjust.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ pub fn auto_levels_with_mode(
5555

5656
// Single pass to build all three histograms
5757
for pixel in data.chunks_exact(3) {
58-
let r_bucket = ((pixel[0].clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize)
59-
.min(NUM_BUCKETS - 1);
60-
let g_bucket = ((pixel[1].clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize)
61-
.min(NUM_BUCKETS - 1);
62-
let b_bucket = ((pixel[2].clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize)
63-
.min(NUM_BUCKETS - 1);
58+
let r_bucket =
59+
((pixel[0].clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize).min(NUM_BUCKETS - 1);
60+
let g_bucket =
61+
((pixel[1].clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize).min(NUM_BUCKETS - 1);
62+
let b_bucket =
63+
((pixel[2].clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize).min(NUM_BUCKETS - 1);
6464
r_hist[r_bucket] += 1;
6565
g_hist[g_bucket] += 1;
6666
b_hist[b_bucket] += 1;
@@ -69,9 +69,12 @@ pub fn auto_levels_with_mode(
6969
let num_pixels = data.len() / 3;
7070

7171
// Compute initial min/max for each channel with clipping using histograms
72-
let (mut r_min, mut r_max) = compute_clipped_range_from_histogram(&r_hist, num_pixels, clip_percent);
73-
let (mut g_min, mut g_max) = compute_clipped_range_from_histogram(&g_hist, num_pixels, clip_percent);
74-
let (mut b_min, mut b_max) = compute_clipped_range_from_histogram(&b_hist, num_pixels, clip_percent);
72+
let (mut r_min, mut r_max) =
73+
compute_clipped_range_from_histogram(&r_hist, num_pixels, clip_percent);
74+
let (mut g_min, mut g_max) =
75+
compute_clipped_range_from_histogram(&g_hist, num_pixels, clip_percent);
76+
let (mut b_min, mut b_max) =
77+
compute_clipped_range_from_histogram(&b_hist, num_pixels, clip_percent);
7578

7679
// Apply mode-specific adjustments
7780
match mode {
@@ -353,8 +356,8 @@ fn find_percentile_via_histogram(data: &[f32], percentile: f32) -> f32 {
353356
// Build histogram
354357
let mut histogram = vec![0u32; NUM_BUCKETS];
355358
for &value in data {
356-
let bucket = ((value.clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize)
357-
.min(NUM_BUCKETS - 1);
359+
let bucket =
360+
((value.clamp(0.0, 1.0) * (NUM_BUCKETS - 1) as f32) as usize).min(NUM_BUCKETS - 1);
358361
histogram[bucket] += 1;
359362
}
360363

@@ -403,7 +406,7 @@ pub fn auto_exposure(
403406
// Pre-allocate luminance buffer with exact capacity
404407
let num_pixels = data.len() / 3;
405408
let mut luminances = Vec::with_capacity(num_pixels);
406-
409+
407410
// Collect luminance samples (Rec.709 weights)
408411
for pixel in data.chunks_exact(3) {
409412
let lum = 0.2126 * pixel[0] + 0.7152 * pixel[1] + 0.0722 * pixel[2];
@@ -416,9 +419,7 @@ pub fn auto_exposure(
416419

417420
// Use select_nth_unstable for efficient median finding
418421
let mid = luminances.len() / 2;
419-
luminances.select_nth_unstable_by(mid, |a, b| {
420-
a.partial_cmp(b).unwrap_or(Ordering::Equal)
421-
});
422+
luminances.select_nth_unstable_by(mid, |a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
422423
let median = luminances[mid];
423424

424425
if !median.is_finite() || median <= 1e-6 {
@@ -476,7 +477,7 @@ mod tests {
476477
0.5, 0.4, 0.4, 0.5, 0.4, 0.4, 0.5, 0.4, 0.4,
477478
];
478479

479-
let adjustments = auto_color(&mut data, 3, 1.0, 0.7, 1.3);
480+
let adjustments = auto_color(&mut data, 3, 1.0, 0.7, 1.3);
480481

481482
println!("Color adjustments: {:?}", adjustments);
482483
println!("Corrected data: {:?}", data);

crates/invers-core/src/config.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::sync::{Once, OnceLock};
66

77
/// Canonical list of candidate config file names we search for on disk.
8-
const CONFIG_FILENAMES: &[&str] = &[
9-
"pipeline.yml",
10-
"pipeline.yaml",
11-
"pipeline_defaults.yml",
12-
];
8+
const CONFIG_FILENAMES: &[&str] = &["pipeline.yml", "pipeline.yaml", "pipeline_defaults.yml"];
139

1410
/// Public handle that stores the loaded configuration, its source path, and warnings.
1511
pub struct PipelineConfigHandle {

crates/invers-core/src/decoders.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn decode_png_gray8(bytes: &[u8], width: u32, height: u32) -> Result<(Vec<f32>,
465465

466466
// Pre-allocate for RGB output
467467
let mut rgb_data = Vec::with_capacity((width * height * 3) as usize);
468-
468+
469469
// Convert to f32 and expand to RGB
470470
for &gray in bytes {
471471
let val = gray as f32 / 255.0;
@@ -490,7 +490,7 @@ fn decode_png_gray16(bytes: &[u8], width: u32, height: u32) -> Result<(Vec<f32>,
490490

491491
// Pre-allocate for RGB output
492492
let mut rgb_data = Vec::with_capacity((width * height * 3) as usize);
493-
493+
494494
// PNG 16-bit is big-endian
495495
for chunk in bytes.chunks_exact(2) {
496496
let gray16 = u16::from_be_bytes([chunk[0], chunk[1]]);
@@ -554,7 +554,7 @@ fn decode_png_rgba8(bytes: &[u8], width: u32, height: u32) -> Result<(Vec<f32>,
554554

555555
// Pre-allocate for RGB output
556556
let mut rgb_data = Vec::with_capacity((width * height * 3) as usize);
557-
557+
558558
// Drop alpha, keep RGB
559559
for rgba in bytes.chunks_exact(4) {
560560
rgb_data.push(rgba[0] as f32 / 255.0);
@@ -578,7 +578,7 @@ fn decode_png_rgba16(bytes: &[u8], width: u32, height: u32) -> Result<(Vec<f32>,
578578

579579
// Pre-allocate for RGB output
580580
let mut rgb_data = Vec::with_capacity((width * height * 3) as usize);
581-
581+
582582
// PNG 16-bit is big-endian, drop alpha
583583
for rgba in bytes.chunks_exact(8) {
584584
let r = u16::from_be_bytes([rgba[0], rgba[1]]);

crates/invers-core/src/diagnostics.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn compute_statistics(data: &[f32], channels: u8) -> [ChannelStats; 3] {
4545
}
4646

4747
let num_pixels = data.len() / 3;
48-
48+
4949
// Pre-allocate with exact capacity to avoid reallocation
5050
let mut channel_data: [Vec<f32>; 3] = [
5151
Vec::with_capacity(num_pixels),
@@ -83,20 +83,20 @@ fn compute_channel_stats(data: &[f32]) -> ChannelStats {
8383

8484
// Create a sorted copy for percentile calculations
8585
let mut sorted = data.to_vec();
86-
86+
8787
// Single pass for min, max, and sum
8888
let mut min = f32::INFINITY;
8989
let mut max = f32::NEG_INFINITY;
9090
let mut sum = 0.0;
91-
91+
9292
for &val in data {
9393
min = min.min(val);
9494
max = max.max(val);
9595
sum += val;
9696
}
97-
97+
9898
let mean = sum / data.len() as f32;
99-
99+
100100
// Use partial sort for median - only sort what we need
101101
let mid = sorted.len() / 2;
102102
sorted.select_nth_unstable_by(mid, |a, b| a.partial_cmp(b).unwrap());
@@ -109,7 +109,7 @@ fn compute_channel_stats(data: &[f32]) -> ChannelStats {
109109
// Compute percentiles efficiently using partial sorts
110110
let percentile_values = vec![1, 5, 25, 50, 75, 95, 99];
111111
let mut percentiles = Vec::with_capacity(percentile_values.len());
112-
112+
113113
for p in percentile_values {
114114
let idx = ((p as f32 / 100.0) * (sorted.len() - 1) as f32).round() as usize;
115115
// Use select_nth_unstable for each percentile
@@ -134,7 +134,7 @@ pub fn compute_histograms(data: &[f32], channels: u8, num_bins: usize) -> [Histo
134134
}
135135

136136
let num_pixels = data.len() / 3;
137-
137+
138138
// Pre-allocate with exact capacity
139139
let mut channel_data: [Vec<f32>; 3] = [
140140
Vec::with_capacity(num_pixels),

0 commit comments

Comments
 (0)