diff --git a/src/main.rs b/src/main.rs index 1c10200..42dc5e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -257,43 +257,51 @@ fn main() -> Result<(), Box> { } fn apply_image_parameters(lr: *mut libraw_data_t, args: &Args) { + if lr.is_null() { + eprintln!("Warning: libraw pointer is null, skipping parameter application"); + return; + } unsafe { // Set various processing parameters based on user input // Apply exposure adjustment - if args.exposure != 0.0 { + if args.exposure != 0.0 && !lr.is_null() { libraw_set_bright(lr, args.exposure); } // Apply contrast (using highlight parameters for demonstration) - if args.contrast != 0 { + if args.contrast != 0 && !lr.is_null() { let value = args.contrast.min(100).max(-100) as c_int; libraw_set_highlight(lr, value); } // Apply highlights adjustment - if args.highlights != 0 { + if args.highlights != 0 && !lr.is_null() { let value = args.highlights.min(100).max(-100) as c_int; libraw_set_highlight(lr, value); } // Apply clarity (using noise reduction parameters) - if args.clarity != 0 { + if args.clarity != 0 && !lr.is_null() { let value = args.clarity.min(100).max(-100) as c_int; libraw_set_fbdd_noiserd(lr, value); } // Apply saturation - if args.saturation != 0 { + if args.saturation != 0 && !lr.is_null() { let value = 1.0 + args.saturation.min(100).max(-100) as f32 / 100.0; libraw_set_gamma(lr, 0, value); // Apply gamma adjustment to simulate saturation } // Set output color space (sRGB in this case) - libraw_set_output_color(lr, 1); // 1 = sRGB + if !lr.is_null() { + libraw_set_output_color(lr, 1); // 1 = sRGB + } // Set output bits per sample - libraw_set_output_bps(lr, 8); + if !lr.is_null() { + libraw_set_output_bps(lr, 8); + } } }