Skip to content

Commit

Permalink
feat: add icns image support (internal png data only, load largest co…
Browse files Browse the repository at this point in the history
…ntained image)
  • Loading branch information
woelper committed May 12, 2024
1 parent fe85bdb commit 0703d22
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
58 changes: 53 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ imageproc = { version = "0.24.0", features = ["rayon"] }
zune-core = "0.4.12"
num-traits = "0.2.18"
zerocopy = "0.7.34"
icns = "0.3.1"

[features]
heif = ["libheif-rs"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pkgin install oculante
- gif (animation support and correct timing)
- hdr, tonemapped
- ico
- icns (via `rust-icns`)
- jpeg
- png
- pnm
Expand Down
Binary file modified icon.ico
Binary file not shown.
19 changes: 18 additions & 1 deletion src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use quickraw::{data, DemosaicingMethod, Export, Input, Output, OutputType};
use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
use rgb::*;
use std::fs::File;
use std::io::BufReader;
use std::io::{BufReader};
use std::path::Path;
use std::sync::mpsc::{channel, Receiver, Sender};
use tiff::decoder::Limits;
Expand Down Expand Up @@ -716,6 +716,23 @@ pub fn open_image(img_location: &Path) -> Result<Receiver<Frame>> {
_ = sender.send(Frame::new_still(d.to_rgba8()));
return Ok(receiver);
}
"icns" => {
let file = BufReader::new(File::open(img_location)?);
let icon_family = icns::IconFamily::read(file)?;

// loop over the largest icons, take the largest one and return
for icon_type in [icns::IconType::RGBA32_512x512_2x, icns::IconType::RGBA32_512x512, icns::IconType::RGBA32_256x256, icns::IconType::RGBA32_128x128] {
// just a vec to write the ong to
let mut target = vec![];
let image = icon_family.get_icon_with_type(icon_type)?;
image.write_png(&mut target)?;
let d = image::load_from_memory(&target).context("Load icns mem")?;
_ = sender.send(Frame::new_still(d.to_rgba8()));
return Ok(receiver);

}

}
"tif" | "tiff" => match load_tiff(&img_location) {
Ok(tiff) => {
_ = sender.send(Frame::new_still(tiff));
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[
"sr2",
"braw",
"r3d",
"icns",
"nrw",
"raw",
"avif",
Expand Down

0 comments on commit 0703d22

Please sign in to comment.