Skip to content

Commit

Permalink
Merge pull request #319 from woelper/exr_single_layer
Browse files Browse the repository at this point in the history
Exr single layer support
  • Loading branch information
woelper authored May 10, 2024
2 parents 15976e6 + 12d0ca6 commit 3427bc0
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dds::DDS;
use exr::prelude as exrs;
use exr::prelude::*;
use image::{
DynamicImage, EncodableLayout, GenericImageView, GrayAlphaImage, GrayImage, ImageDecoder, Rgb32FImage, RgbImage, RgbaImage
DynamicImage, EncodableLayout, GrayAlphaImage, GrayImage, Rgb32FImage, RgbImage, RgbaImage
};
use jxl_oxide::{JxlImage, PixelFormat};
use quickraw::{data, DemosaicingMethod, Export, Input, Output, OutputType};
Expand Down Expand Up @@ -253,17 +253,38 @@ pub fn open_image(img_location: &Path) -> Result<Receiver<Frame>> {
Image<Layer<SpecificChannels<RgbaImage, RgbaChannels>>>,
exrs::Error,
> = reader.from_file(&img_location);

match maybe_image {
Ok(image) => {
let buf = image.layer_data.channel_data.pixels;
_ = sender.send(Frame::new_still(buf));
return Ok(receiver);
// return Ok(OpenResult::still(buf));
}
Err(e) => {
let layer = exrs::read_first_flat_layer_from_file(&img_location)?;

let size = layer.layer_data.size;
for i in layer.layer_data.channel_data.list {
let d = i.sample_data;
match d {
FlatSamples::F16(_) => bail!("F16 color mode not supported"),
FlatSamples::F32(f) => {
let gray_image = GrayImage::from_raw(
size.width() as u32,
size.height() as u32,
f.par_iter().map(|x| tonemap_f32(*x)).collect::<Vec<_>>(),
)
.context("Can't decode gray alpha buffer")?;

let d = DynamicImage::ImageLuma8(gray_image);
_ = sender.send(Frame::new_still(d.to_rgba8()));
return Ok(receiver);
}
FlatSamples::U32(_) => bail!("U32 color mode not supported"),
}
}

// col.add_still(png_buffer);
bail!("{} from {:?}", e, img_location)
}
Err(e) => bail!("{} from {:?}", e, img_location),
}
}
"nef" | "cr2" | "dng" | "mos" | "erf" | "raf" | "arw" | "3fr" | "ari" | "srf" | "sr2"
Expand Down

0 comments on commit 3427bc0

Please sign in to comment.