@@ -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) ;
0 commit comments