mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 04:18:11 +08:00
Raw-rs: use camera white balance when available (#1941)
* add new White Balance Tag * merge raw_to_image step with demosiacing * Use white balance from camera in scale colors step * Nit --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
444929adbf
commit
82ef5c83ae
@@ -49,7 +49,13 @@ pub fn calculate_conversion_matrices(mut raw_image: RawImage) -> RawImage {
|
||||
}
|
||||
let rgb_to_camera = transpose(pseudoinverse(camera_to_rgb));
|
||||
|
||||
raw_image.white_balance_multiplier = Some(white_balance_multiplier);
|
||||
let cfa_white_balance_multiplier = if let Some(white_balance) = raw_image.camera_white_balance_multiplier {
|
||||
white_balance
|
||||
} else {
|
||||
raw_image.cfa_pattern.map(|index| white_balance_multiplier[index as usize])
|
||||
};
|
||||
|
||||
raw_image.white_balance_multiplier = Some(cfa_white_balance_multiplier);
|
||||
raw_image.camera_to_rgb = Some(camera_to_rgb);
|
||||
raw_image.rgb_to_camera = Some(rgb_to_camera);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod camera_data;
|
||||
pub mod raw_to_image;
|
||||
pub mod scale_colors;
|
||||
pub mod subtract_black;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
use crate::RawImage;
|
||||
|
||||
pub fn raw_to_image(mut raw_image: RawImage) -> RawImage {
|
||||
let mut image = Vec::with_capacity(raw_image.width * raw_image.height * 3);
|
||||
|
||||
for row in 0..raw_image.height {
|
||||
for col in 0..raw_image.width {
|
||||
let mut pixel = [0_u16; 3];
|
||||
let color_index = raw_image.cfa_pattern[2 * (row % 2) + (col % 2)];
|
||||
pixel[color_index as usize] = raw_image.data[row * raw_image.width + col];
|
||||
image.extend_from_slice(&pixel);
|
||||
}
|
||||
}
|
||||
|
||||
raw_image.data = image;
|
||||
raw_image
|
||||
}
|
||||
@@ -22,12 +22,14 @@ pub fn scale_colors(mut raw_image: RawImage) -> RawImage {
|
||||
let scale_to_16bit_multiplier = u16::MAX as f64 / raw_image.maximum as f64;
|
||||
white_balance_multiplier.map(|x| x / normalize_white_balance * scale_to_16bit_multiplier)
|
||||
} else {
|
||||
[1., 1., 1.]
|
||||
[1., 1., 1., 1.]
|
||||
};
|
||||
|
||||
for i in 0..(raw_image.height * raw_image.width) {
|
||||
for (c, multiplier) in final_multiplier.iter().enumerate() {
|
||||
raw_image.data[3 * i + c] = ((raw_image.data[3 * i + c] as f64) * multiplier).min(u16::MAX as f64).max(0.) as u16;
|
||||
for row in 0..raw_image.height {
|
||||
for column in 0..raw_image.width {
|
||||
let index = row * raw_image.width + column;
|
||||
let cfa_index = 2 * (row % 2) + (column % 2);
|
||||
raw_image.data[index] = ((raw_image.data[index] as f64) * final_multiplier[cfa_index]).min(u16::MAX as f64).max(0.) as u16;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user