Skip to content

Commit 1b892ac

Browse files
narrowstacksclaude
andcommitted
fix: resolve clippy warnings across workspace
- Replace manual Default impls with derive macros and #[default] attrs - Add RgbSamplePatches type alias to reduce type complexity - Use is_multiple_of() instead of modulo comparison - Change &PathBuf to &Path in determine_output_path signature - Remove unnecessary i32 casts in GUI sampling code - Remove needless borrow in export path handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d604a42 commit 1b892ac

8 files changed

Lines changed: 31 additions & 91 deletions

File tree

crates/invers-cli/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module provides reusable functions and utilities that can be
44
//! shared between the CLI and GUI applications.
55
6-
use std::path::PathBuf;
6+
use std::path::{Path, PathBuf};
77

88
/// Parse ROI string in format "x,y,width,height"
99
///
@@ -51,7 +51,7 @@ pub fn parse_roi(roi_str: &str) -> Result<(u32, u32, u32, u32), String> {
5151
/// # Returns
5252
/// The full output path for the converted image
5353
pub fn determine_output_path(
54-
input: &PathBuf,
54+
input: &Path,
5555
out: &Option<PathBuf>,
5656
export: &str,
5757
) -> Result<PathBuf, String> {

crates/invers-core/src/auto_adjust.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@
66
use std::cmp::Ordering;
77

88
/// Auto-levels mode for controlling color preservation
9-
#[derive(Debug, Clone, Copy, PartialEq)]
9+
#[derive(Debug, Clone, Copy, PartialEq, Default)]
1010
pub enum AutoLevelsMode {
1111
/// Independent per-channel stretching (default, may shift colors)
12+
#[default]
1213
PerChannel,
1314
/// Saturation-aware: reduces stretch for channels that would clip heavily
1415
SaturationAware,
1516
/// Preserve saturation: use minimum stretch across all channels
1617
PreserveSaturation,
1718
}
1819

19-
impl Default for AutoLevelsMode {
20-
fn default() -> Self {
21-
Self::PerChannel
22-
}
23-
}
24-
2520
/// Auto-levels: Stretch histogram to full 0.0-1.0 range per channel
2621
/// This is the key missing step that Photoshop/Grain2Pixel applies
2722
///

crates/invers-core/src/config.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl PipelineConfigHandle {
2525
}
2626

2727
/// Complete configuration file structure.
28-
#[derive(Debug, Clone, Deserialize)]
28+
#[derive(Debug, Clone, Deserialize, Default)]
2929
#[serde(default)]
3030
pub struct PipelineConfig {
3131
pub defaults: PipelineDefaults,
@@ -51,15 +51,6 @@ impl PipelineConfig {
5151
}
5252
}
5353

54-
impl Default for PipelineConfig {
55-
fn default() -> Self {
56-
Self {
57-
defaults: PipelineDefaults::default(),
58-
testing: TestingConfig::default(),
59-
}
60-
}
61-
}
62-
6354
/// Default pipeline parameter values.
6455
#[derive(Debug, Clone, Deserialize)]
6556
#[serde(default)]
@@ -132,7 +123,7 @@ impl Default for PipelineDefaults {
132123
}
133124

134125
/// Testing-related configuration overrides.
135-
#[derive(Debug, Clone, Deserialize)]
126+
#[derive(Debug, Clone, Deserialize, Default)]
136127
#[serde(default)]
137128
pub struct TestingConfig {
138129
pub parameter_test_defaults: Option<ParameterTestDefaults>,
@@ -141,17 +132,6 @@ pub struct TestingConfig {
141132
pub comprehensive_grid: Option<TestingGridValues>,
142133
}
143134

144-
impl Default for TestingConfig {
145-
fn default() -> Self {
146-
Self {
147-
parameter_test_defaults: None,
148-
default_grid: None,
149-
minimal_grid: None,
150-
comprehensive_grid: None,
151-
}
152-
}
153-
}
154-
155135
/// Defaults for a single parameter test run.
156136
#[derive(Debug, Clone, Deserialize)]
157137
#[serde(default)]

crates/invers-core/src/diagnostics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use crate::exporters::export_tiff16;
88
use crate::pipeline::ProcessedImage;
99
use std::path::Path;
1010

11+
/// RGB sample patches (shadow, midtone, highlight) as flat f32 arrays
12+
pub type RgbSamplePatches = (Vec<f32>, Vec<f32>, Vec<f32>);
13+
1114
/// Statistics for a single channel
1215
#[derive(Debug, Clone)]
1316
pub struct ChannelStats {
@@ -203,7 +206,7 @@ pub fn extract_sample_patches(
203206
width: u32,
204207
height: u32,
205208
patch_size: u32,
206-
) -> Result<(Vec<f32>, Vec<f32>, Vec<f32>), String> {
209+
) -> Result<RgbSamplePatches, String> {
207210
// Find representative regions
208211
let shadow_center = find_representative_pixel(data, width, height, 0.1, 0.3)?;
209212
let midtone_center = find_representative_pixel(data, width, height, 0.4, 0.6)?;

crates/invers-core/src/exporters.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn export_linear_dng<P: AsRef<Path>>(
8282
}
8383

8484
/// Metadata for DNG export
85-
#[derive(Debug, Clone)]
85+
#[derive(Debug, Clone, Default)]
8686
pub struct DngMetadata {
8787
/// Camera make
8888
pub make: Option<String>,
@@ -102,16 +102,3 @@ pub struct DngMetadata {
102102
/// Color matrix
103103
pub color_matrix: Option<[[f32; 3]; 3]>,
104104
}
105-
106-
impl Default for DngMetadata {
107-
fn default() -> Self {
108-
Self {
109-
make: None,
110-
model: None,
111-
black_level: None,
112-
white_level: None,
113-
as_shot_neutral: None,
114-
color_matrix: None,
115-
}
116-
}
117-
}

crates/invers-core/src/models.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,21 @@ fn default_auto_exposure_max_gain() -> f32 {
302302
}
303303

304304
/// Output format options
305-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
305+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
306306
pub enum OutputFormat {
307307
/// 16-bit linear TIFF
308+
#[default]
308309
Tiff16,
309310

310311
/// Linear DNG
311312
LinearDng,
312313
}
313314

314315
/// Bit depth handling policy
315-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
316+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
316317
pub enum BitDepthPolicy {
317318
/// Match input bit depth when possible
319+
#[default]
318320
MatchInput,
319321

320322
/// Always use 16-bit output
@@ -325,9 +327,10 @@ pub enum BitDepthPolicy {
325327
}
326328

327329
/// Base estimation sampling mode
328-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
330+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
329331
pub enum BaseSamplingMode {
330332
/// Use median of brightest pixels (default, robust)
333+
#[default]
331334
Median,
332335

333336
/// Use mean of brightest pixels (more sensitive to maximum)
@@ -338,22 +341,24 @@ pub enum BaseSamplingMode {
338341
}
339342

340343
/// Inversion mode for negative-to-positive conversion
341-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
344+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
342345
pub enum InversionMode {
343346
/// Linear inversion: (base - negative) / base
347+
#[default]
344348
Linear,
345349

346350
/// Logarithmic inversion: 10^(log10(base) - log10(negative))
347351
Logarithmic,
348352
}
349353

350354
/// Shadow lift mode
351-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
355+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
352356
pub enum ShadowLiftMode {
353357
/// Fixed lift value
354358
Fixed,
355359

356360
/// Percentile-based adaptive lift (e.g., lift 1st percentile to target)
361+
#[default]
357362
Percentile,
358363

359364
/// No shadow lift
@@ -373,33 +378,3 @@ impl Default for ToneCurveParams {
373378
}
374379
}
375380
}
376-
377-
impl Default for OutputFormat {
378-
fn default() -> Self {
379-
Self::Tiff16
380-
}
381-
}
382-
383-
impl Default for BitDepthPolicy {
384-
fn default() -> Self {
385-
Self::MatchInput
386-
}
387-
}
388-
389-
impl Default for BaseSamplingMode {
390-
fn default() -> Self {
391-
Self::Median
392-
}
393-
}
394-
395-
impl Default for InversionMode {
396-
fn default() -> Self {
397-
Self::Linear
398-
}
399-
}
400-
401-
impl Default for ShadowLiftMode {
402-
fn default() -> Self {
403-
Self::Percentile
404-
}
405-
}

crates/invers-core/src/testing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ pub fn run_parameter_grid_search_parallel<P: AsRef<Path>>(
652652

653653
// Progress reporting
654654
let count = completed.fetch_add(1, Ordering::Relaxed) + 1;
655-
if count % 10 == 0 || count == total_combinations {
655+
if count.is_multiple_of(10) || count == total_combinations {
656656
eprintln!(
657657
"[PARALLEL GRID SEARCH] Progress: {}/{}",
658658
count, total_combinations

crates/invers-gui/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,10 @@ impl InversApp {
556556

557557
for dy in 0..region_size {
558558
for dx in 0..region_size {
559-
let sample_x = (x as i32 + dx as i32 - half_size as i32)
560-
.clamp(0, orig_image.width as i32 - 1) as u32;
561-
let sample_y = (y as i32 + dy as i32 - half_size as i32)
562-
.clamp(0, orig_image.height as i32 - 1) as u32;
559+
let sample_x =
560+
(x as i32 + dx - half_size).clamp(0, orig_image.width as i32 - 1) as u32;
561+
let sample_y =
562+
(y as i32 + dy - half_size).clamp(0, orig_image.height as i32 - 1) as u32;
563563

564564
let idx = ((sample_y * orig_image.width + sample_x) * 3) as usize;
565565
if idx + 2 < orig_image.data.len() {
@@ -627,10 +627,10 @@ impl InversApp {
627627

628628
for dy in 0..region_size {
629629
for dx in 0..region_size {
630-
let sample_x = (x as i32 + dx as i32 - half_size as i32)
631-
.clamp(0, orig_image.width as i32 - 1) as u32;
632-
let sample_y = (y as i32 + dy as i32 - half_size as i32)
633-
.clamp(0, orig_image.height as i32 - 1) as u32;
630+
let sample_x =
631+
(x as i32 + dx - half_size).clamp(0, orig_image.width as i32 - 1) as u32;
632+
let sample_y =
633+
(y as i32 + dy - half_size).clamp(0, orig_image.height as i32 - 1) as u32;
634634

635635
let idx = ((sample_y * orig_image.width + sample_x) * 3) as usize;
636636
if idx + 2 < orig_image.data.len() {
@@ -944,7 +944,7 @@ impl InversApp {
944944
match self.process_original_for_export() {
945945
Ok(processed) => {
946946
let output_path = determine_output_path(
947-
&loaded_path,
947+
loaded_path,
948948
&Some(PathBuf::from(".")),
949949
match self.output_format {
950950
OutputFormat::Tiff16 => "tiff16",

0 commit comments

Comments
 (0)