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:
commit
bab2f17533
18
src/main.rs
18
src/main.rs
@ -257,44 +257,52 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
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)
|
||||
if !lr.is_null() {
|
||||
libraw_set_output_color(lr, 1); // 1 = sRGB
|
||||
}
|
||||
|
||||
// Set output bits per sample
|
||||
if !lr.is_null() {
|
||||
libraw_set_output_bps(lr, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user