diff --git a/Cargo.lock b/Cargo.lock index 60470e2..32a983f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3421,7 +3421,6 @@ dependencies = [ "once_cell", "pollster", "psd", - "qoi", "rand", "rawloader", "resvg", diff --git a/Cargo.toml b/Cargo.toml index 23709fe..a534cce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ num-traits = "0.2.15" once_cell = "1.14.0" pollster = "0.3.0" psd = "0.3.3" -qoi = "0.4.1" rand = "0.8.5" rawloader = "0.37.0" resvg = "0.40.0" diff --git a/src/app/load_image.rs b/src/app/load_image.rs index b2bc9fc..8b355d1 100644 --- a/src/app/load_image.rs +++ b/src/app/load_image.rs @@ -95,12 +95,8 @@ pub fn load_from_bytes(bytes: &[u8], path_buf: Option) -> Result save_with_format(path, &frames[0], ImageFormat::Png), + "qoi" => save_with_format(path, &frames[0], ImageFormat::Qoi), "jpg" | "jpeg" | "jpe" | "jif" | "jfif" => { let quality = match get_jpeg_quality(dialog_proxy.clone()) { Some(quality) => quality, @@ -119,7 +120,6 @@ pub fn save( } } "exr" => exr(path, &frames[0]), - "qoi" => qoi(path, &frames[0]), _ => { path.set_extension("png"); save_with_format(path, &frames[0], ImageFormat::Png) diff --git a/src/image_io/load.rs b/src/image_io/load.rs index aabe919..c4c998e 100644 --- a/src/image_io/load.rs +++ b/src/image_io/load.rs @@ -4,8 +4,7 @@ use fontdb::Database; use image::{ codecs::{gif::GifDecoder, openexr::OpenExrDecoder, png::PngDecoder}, io::Reader as ImageReader, - AnimationDecoder, DynamicImage, Frame, ImageBuffer, ImageFormat, Rgb, RgbImage, Rgba, - RgbaImage, + AnimationDecoder, DynamicImage, Frame, ImageBuffer, ImageFormat, Rgb, Rgba, }; use imagepipe::{ImageSource, Pipeline}; use psd::Psd; @@ -247,24 +246,4 @@ pub fn load_heif(bytes: &[u8]) -> Option> { let _ = bytes; None } -} - -pub fn load_qoi(bytes: &[u8]) -> Option> { - let ( - qoi::Header { - width, - height, - channels, - //colorspace, FIXME handle linear color - .. - }, - decoded, - ) = qoi::decode_to_vec(bytes).ok()?; - let image = match channels { - qoi::Channels::Rgb => DynamicImage::ImageRgb8(RgbImage::from_raw(width, height, decoded)?), - qoi::Channels::Rgba => { - DynamicImage::ImageRgba8(RgbaImage::from_raw(width, height, decoded)?) - } - }; - Some(vec![Image::new(image)]) -} +} \ No newline at end of file diff --git a/src/image_io/save.rs b/src/image_io/save.rs index 68f9b02..d11f4fa 100644 --- a/src/image_io/save.rs +++ b/src/image_io/save.rs @@ -25,7 +25,6 @@ pub enum SaveError { #[allow(unused)] WebpAnimation(webp_animation::Error), LibWebp(libwebp::error::WebPSimpleError), - Qoi(qoi::Error), } impl fmt::Display for SaveError { @@ -36,7 +35,6 @@ impl fmt::Display for SaveError { SaveError::Io(ref e) => e.fmt(f), SaveError::WebpAnimation(_) => write!(f, "error encoding webp"), SaveError::LibWebp(ref e) => e.fmt(f), - SaveError::Qoi(ref e) => e.fmt(f), } } } @@ -49,7 +47,6 @@ impl error::Error for SaveError { SaveError::Io(ref e) => Some(e), SaveError::WebpAnimation(_) => None, SaveError::LibWebp(ref e) => Some(e), - SaveError::Qoi(ref e) => Some(e), } } } @@ -82,13 +79,6 @@ impl From for SaveError { } } -impl From for SaveError { - #[inline] - fn from(err: qoi::Error) -> SaveError { - SaveError::Qoi(err) - } -} - fn open_file(path: impl AsRef) -> Result { OpenOptions::new() .write(true) @@ -281,20 +271,3 @@ pub fn exr(path: impl AsRef, image: &Image) -> SaveResult<()> { Ok(fs::rename(temp_path, path)?) } - -#[inline] -pub fn qoi(path: impl AsRef, image: &Image) -> SaveResult<()> { - let temp_path = get_temp_path(path.as_ref()); - let file = open_file(&temp_path)?; - let (width, height) = image.buffer().dimensions(); - let data = if image.buffer().color().has_alpha() { - image.buffer().to_rgba8().into_vec() - } else { - image.buffer().to_rgb8().into_vec() - }; - - // FIXME handle linear color - let encoder = qoi::Encoder::new(&data, width, height)?.with_colorspace(qoi::ColorSpace::Srgb); - encoder.encode_to_stream(&mut BufWriter::new(file))?; - Ok(fs::rename(temp_path, path)?) -} diff --git a/src/util/extensions.rs b/src/util/extensions.rs index 6fdc982..86dc04d 100644 --- a/src/util/extensions.rs +++ b/src/util/extensions.rs @@ -1,7 +1,5 @@ use once_cell::sync::Lazy; -pub static QOI: Lazy<&[&'static str]> = Lazy::new(|| &["qoi"]); - pub static JXL: Lazy<&[&'static str]> = Lazy::new(|| &["jxl"]); pub static HEIF: Lazy<&[&'static str]> = Lazy::new(|| &["heif", "heic"]); @@ -9,7 +7,7 @@ pub static HEIF: Lazy<&[&'static str]> = Lazy::new(|| &["heif", "heic"]); pub static RASTER: Lazy<&[&'static str]> = Lazy::new(|| { &[ "png", "jpg", "jpeg", "jpe", "jif", "jfif", "gif", "bmp", "ico", "tiff", "webp", "avif", - "pnm", "pbm", "pgm", "ppm", "pam", "dds", "tga", "ff", "farbfeld", "exr", + "pnm", "pbm", "pgm", "ppm", "pam", "dds", "tga", "ff", "farbfeld", "exr", "qoi", ] });