Rename Raw-rs to Rawkit (#2088)

* Rename within files

* Rename in CI

* Rename the folder and file names

* Rename raw_rs to rawkit

* Add example to README

* Add initial documentation

* Small API changes and extra documentation

* Bump versions and stuff

* Readme improvements

* Merge proc-macro crates into one

* Add README to rawkit-proc-macros

* Remove keywords and categories

* Add licenses to rawkit-proc-macros

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Elbert Ronnie
2024-11-03 13:40:39 +05:30
committed by GitHub
parent 8d3da83606
commit 8fdecaa487
89 changed files with 664 additions and 356 deletions

View File

@@ -0,0 +1,3 @@
pub mod scale_to_16bit;
pub mod scale_white_balance;
pub mod subtract_black;

View File

@@ -0,0 +1,15 @@
use crate::{RawImage, RawPixel, SubtractBlack};
impl RawImage {
pub fn scale_to_16bit_fn(&self) -> impl Fn(RawPixel) -> u16 {
let black_level = match self.black {
SubtractBlack::CfaGrid(x) => x,
_ => unreachable!(),
};
let maximum = self.maximum - black_level.iter().max().unwrap();
let scale_to_16bit_multiplier = if maximum > 0 { u16::MAX as f64 / maximum as f64 } else { 1. };
move |pixel: RawPixel| ((pixel.value as f64) * scale_to_16bit_multiplier).min(u16::MAX as f64).max(0.) as u16
}
}

View File

@@ -0,0 +1,31 @@
use crate::{RawImage, RawPixel};
impl RawImage {
pub fn scale_white_balance_fn(&self) -> impl Fn(RawPixel) -> u16 {
let Some(mut white_balance) = self.white_balance else { todo!() };
if white_balance[1] == 0. {
white_balance[1] = 1.;
}
// TODO: Move this at its correct location when highlights are implemented correctly.
let highlight = 0;
let normalization_factor = if highlight == 0 {
white_balance.into_iter().fold(f64::INFINITY, f64::min)
} else {
white_balance.into_iter().fold(f64::NEG_INFINITY, f64::max)
};
let normalized_white_balance = if normalization_factor > 0.00001 {
white_balance.map(|x| x / normalization_factor)
} else {
[1., 1., 1., 1.]
};
move |pixel: RawPixel| {
let cfa_index = 2 * (pixel.row % 2) + (pixel.column % 2);
((pixel.value as f64) * normalized_white_balance[cfa_index]).min(u16::MAX as f64).max(0.) as u16
}
}
}

View File

@@ -0,0 +1,11 @@
use crate::RawPixel;
use crate::{RawImage, SubtractBlack};
impl RawImage {
pub fn subtract_black_fn(&self) -> impl Fn(RawPixel) -> u16 {
match self.black {
SubtractBlack::CfaGrid(black_levels) => move |pixel: RawPixel| pixel.value.saturating_sub(black_levels[2 * (pixel.row % 2) + (pixel.column % 2)]),
_ => todo!(),
}
}
}