Skip to content

Commit

Permalink
Upgrade rawkit
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Mar 6, 2025
1 parent 3066280 commit 254de97
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use quote::{ToTokens, quote};
use toml::{Table, Value};

use std::fs;
Expand Down
4 changes: 2 additions & 2 deletions libraries/rawkit/rawkit-proc-macros/src/tag_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn tag_derive(input: TokenStream) -> TokenStream {

let new_name = format_ident!("_{}", name);

let gen = quote! {
let r#gen = quote! {
struct #new_name {
#( #struct_idents: <#struct_types as Tag>::Output ),*
}
Expand All @@ -39,5 +39,5 @@ pub fn tag_derive(input: TokenStream) -> TokenStream {
}
};

gen.into()
r#gen.into()
}
10 changes: 3 additions & 7 deletions libraries/rawkit/src/decoder/arw1.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::tiff::Ifd;
use crate::tiff::file::TiffRead;
use crate::tiff::tags::SonyDataOffset;
use crate::tiff::Ifd;
use crate::{RawImage, SubtractBlack, Transform};

use bitstream_io::{BitRead, BitReader, Endianness, BE};
use bitstream_io::{BE, BitRead, BitReader, Endianness};
use std::io::{Read, Seek};

pub fn decode_a100<R: Read + Seek>(ifd: Ifd, file: &mut TiffRead<R>) -> RawImage {
Expand Down Expand Up @@ -63,11 +63,7 @@ fn ljpeg_diff<R: Read + Seek, E: Endianness>(huff: &[u16], file: &mut BitReader<

let diff = read_n_bits_from_file(length, file) as i32;

if length == 0 || (diff & (1 << (length - 1))) == 0 {
diff - (1 << length) - 1
} else {
diff
}
if length == 0 || (diff & (1 << (length - 1))) == 0 { diff - (1 << length) - 1 } else { diff }
}

fn sony_arw_load_raw<R: Read + Seek>(width: usize, height: usize, file: &mut BitReader<R, BE>) -> Option<Vec<u16>> {
Expand Down
4 changes: 2 additions & 2 deletions libraries/rawkit/src/postprocessing/convert_to_rgb.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Pixel, RawImage, CHANNELS_IN_RGB};
use crate::{CHANNELS_IN_RGB, Pixel, RawImage};

impl RawImage {
pub fn convert_to_rgb_fn(&self) -> impl Fn(Pixel) -> [u16; CHANNELS_IN_RGB] {
pub fn convert_to_rgb_fn(&self) -> impl Fn(Pixel) -> [u16; CHANNELS_IN_RGB] + use<> {
let Some(camera_to_rgb) = self.camera_to_rgb else { todo!() };

move |pixel: Pixel| {
Expand Down
4 changes: 2 additions & 2 deletions libraries/rawkit/src/postprocessing/gamma_correction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{Histogram, Image, Pixel, CHANNELS_IN_RGB};
use crate::{CHANNELS_IN_RGB, Histogram, Image, Pixel};
use std::f64::consts::E;

impl Image<u16> {
pub fn gamma_correction_fn(&self, histogram: &Histogram) -> impl Fn(Pixel) -> [u16; CHANNELS_IN_RGB] {
pub fn gamma_correction_fn(&self, histogram: &Histogram) -> impl Fn(Pixel) -> [u16; CHANNELS_IN_RGB] + use<> {
let percentage = self.width * self.height;

let mut white = 0;
Expand Down
2 changes: 1 addition & 1 deletion libraries/rawkit/src/postprocessing/record_histogram.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Histogram, Pixel, PixelTransform, RawImage, CHANNELS_IN_RGB};
use crate::{CHANNELS_IN_RGB, Histogram, Pixel, PixelTransform, RawImage};

impl RawImage {
pub fn record_histogram_fn(&self) -> RecordHistogram {
Expand Down
2 changes: 1 addition & 1 deletion libraries/rawkit/src/preprocessing/scale_to_16bit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{RawImage, RawPixel, SubtractBlack};

impl RawImage {
pub fn scale_to_16bit_fn(&self) -> impl Fn(RawPixel) -> u16 {
pub fn scale_to_16bit_fn(&self) -> impl Fn(RawPixel) -> u16 + use<> {
let black_level = match self.black {
SubtractBlack::CfaGrid(x) => x,
_ => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion libraries/rawkit/src/preprocessing/scale_white_balance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{RawImage, RawPixel};

impl RawImage {
pub fn scale_white_balance_fn(&self) -> impl Fn(RawPixel) -> u16 {
pub fn scale_white_balance_fn(&self) -> impl Fn(RawPixel) -> u16 + use<> {
let Some(mut white_balance) = self.white_balance else { todo!() };

if white_balance[1] == 0. {
Expand Down
2 changes: 1 addition & 1 deletion libraries/rawkit/src/preprocessing/subtract_black.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::RawPixel;
use crate::{RawImage, SubtractBlack};

impl RawImage {
pub fn subtract_black_fn(&self) -> impl Fn(RawPixel) -> u16 {
pub fn subtract_black_fn(&self) -> impl Fn(RawPixel) -> u16 + use<> {
match self.black {
SubtractBlack::CfaGrid(black_levels) => move |pixel: RawPixel| pixel.value.saturating_sub(black_levels[2 * (pixel.row % 2) + (pixel.column % 2)]),
_ => todo!(),
Expand Down
6 changes: 1 addition & 5 deletions libraries/rawkit/src/tiff/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ impl PrimitiveType for TypeAscii {

fn read_primitive<R: Read + Seek>(_: IfdTagType, file: &mut TiffRead<R>) -> Result<Self::Output, TiffError> {
let value = file.read_ascii()?;
if value.is_ascii() {
Ok(value)
} else {
Err(TiffError::InvalidValue)
}
if value.is_ascii() { Ok(value) } else { Err(TiffError::InvalidValue) }
}
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/rawkit/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libraw::Processor;
use rayon::prelude::*;
use std::collections::HashMap;
use std::fmt::Write;
use std::fs::{create_dir, metadata, read_dir, File};
use std::fs::{File, create_dir, metadata, read_dir};
use std::io::{BufWriter, Cursor, Read};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -338,10 +338,10 @@ fn extract_data_from_dng_images() {
}

fn extract_data_from_dng_image(path: &Path) {
use rawkit::tiff::Ifd;
use rawkit::tiff::file::TiffRead;
use rawkit::tiff::tags::{ColorMatrix2, Make, Model};
use rawkit::tiff::values::ToFloat;
use rawkit::tiff::Ifd;
use std::io::{BufReader, Write};

let reader = BufReader::new(File::open(path).unwrap());
Expand Down

0 comments on commit 254de97

Please sign in to comment.