Merge pull request 'fix(#3): add null pointer checks before all libraw FFI calls' (#19) from fix/issue-3 into master

This commit is contained in:
jarianc 2026-07-05 09:47:38 -05:00
commit bab2f17533

View File

@ -257,43 +257,51 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
fn apply_image_parameters(lr: *mut libraw_data_t, args: &Args) { 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 { unsafe {
// Set various processing parameters based on user input // Set various processing parameters based on user input
// Apply exposure adjustment // Apply exposure adjustment
if args.exposure != 0.0 { if args.exposure != 0.0 && !lr.is_null() {
libraw_set_bright(lr, args.exposure); libraw_set_bright(lr, args.exposure);
} }
// Apply contrast (using highlight parameters for demonstration) // 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; let value = args.contrast.min(100).max(-100) as c_int;
libraw_set_highlight(lr, value); libraw_set_highlight(lr, value);
} }
// Apply highlights adjustment // 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; let value = args.highlights.min(100).max(-100) as c_int;
libraw_set_highlight(lr, value); libraw_set_highlight(lr, value);
} }
// Apply clarity (using noise reduction parameters) // 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; let value = args.clarity.min(100).max(-100) as c_int;
libraw_set_fbdd_noiserd(lr, value); libraw_set_fbdd_noiserd(lr, value);
} }
// Apply saturation // 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; 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 libraw_set_gamma(lr, 0, value); // Apply gamma adjustment to simulate saturation
} }
// Set output color space (sRGB in this case) // 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 // Set output bits per sample
libraw_set_output_bps(lr, 8); if !lr.is_null() {
libraw_set_output_bps(lr, 8);
}
} }
} }