mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 12:58:12 +08:00
Raw-rs: add post-processing steps (#1923)
* add convert_to_rgb step * add code to generate gamma correction curve * add gamma correction step * fix clippy warnings and cargo fmt * remove unnecessary dependencies * Code review 1 * Code review 2 * fix the order of operations * Code review 3 --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
40fd4473a7
commit
a7840b252d
@@ -1,10 +1,11 @@
|
||||
pub mod decoder;
|
||||
pub mod demosaicing;
|
||||
pub mod metadata;
|
||||
pub mod postprocessing;
|
||||
pub mod preprocessing;
|
||||
pub mod tiff;
|
||||
|
||||
use crate::preprocessing::camera_data::camera_to_xyz;
|
||||
use crate::metadata::identify::CameraModel;
|
||||
|
||||
use tag_derive::Tag;
|
||||
use tiff::file::TiffRead;
|
||||
@@ -27,14 +28,21 @@ pub struct RawImage {
|
||||
pub cfa_pattern: [u8; 4],
|
||||
pub maximum: u16,
|
||||
pub black: SubtractBlack,
|
||||
pub camera_to_xyz: Option<[f64; 9]>,
|
||||
pub camera_model: Option<CameraModel>,
|
||||
pub white_balance_multiplier: Option<[f64; 3]>,
|
||||
pub camera_to_rgb: Option<[[f64; 3]; 3]>,
|
||||
pub rgb_to_camera: Option<[[f64; 3]; 3]>,
|
||||
}
|
||||
|
||||
pub struct Image<T> {
|
||||
pub data: Vec<T>,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
/// We can assume this will be 3 for all non-obscure, modern cameras.
|
||||
/// See <https://github.com/GraphiteEditor/Graphite/pull/1923#discussion_r1725070342> for more information.
|
||||
pub channels: u8,
|
||||
pub rgb_to_camera: Option<[[f64; 3]; 3]>,
|
||||
pub histogram: Option<[[usize; 0x2000]; 3]>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -68,27 +76,32 @@ pub fn decode<R: Read + Seek>(reader: &mut R) -> Result<RawImage, DecoderError>
|
||||
}
|
||||
};
|
||||
|
||||
raw_image.camera_to_xyz = camera_to_xyz(&camera_model);
|
||||
raw_image.camera_model = Some(camera_model);
|
||||
|
||||
Ok(raw_image)
|
||||
}
|
||||
|
||||
pub fn process_8bit(raw_image: RawImage) -> Image<u8> {
|
||||
let raw_image = crate::preprocessing::subtract_black::subtract_black(raw_image);
|
||||
let raw_image = crate::preprocessing::raw_to_image::raw_to_image(raw_image);
|
||||
let raw_image = crate::preprocessing::scale_colors::scale_colors(raw_image);
|
||||
let image = crate::demosaicing::linear_demosaicing::linear_demosaic(raw_image);
|
||||
let image = process_16bit(raw_image);
|
||||
|
||||
Image {
|
||||
channels: image.channels,
|
||||
data: image.data.iter().map(|x| (x >> 8) as u8).collect(),
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
rgb_to_camera: image.rgb_to_camera,
|
||||
histogram: image.histogram,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_16bit(_image: RawImage) -> Image<u16> {
|
||||
todo!()
|
||||
pub fn process_16bit(raw_image: RawImage) -> Image<u16> {
|
||||
let raw_image = crate::preprocessing::camera_data::calculate_conversion_matrices(raw_image);
|
||||
let raw_image = crate::preprocessing::subtract_black::subtract_black(raw_image);
|
||||
let raw_image = crate::preprocessing::raw_to_image::raw_to_image(raw_image);
|
||||
let raw_image = crate::preprocessing::scale_colors::scale_colors(raw_image);
|
||||
let image = crate::demosaicing::linear_demosaicing::linear_demosaic(raw_image);
|
||||
let image = crate::postprocessing::convert_to_rgb::convert_to_rgb(image);
|
||||
crate::postprocessing::gamma_correction::gamma_correction(image)
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user