diff --git a/Cargo.lock b/Cargo.lock index 55da0a4..7e1cd1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -126,8 +126,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -277,6 +277,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "case" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88b166b48e29667f5443df64df3c61dc07dc2b1a0b0d231800e07f09a33ecc1" + [[package]] name = "cc" version = "1.1.14" @@ -522,6 +528,17 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive-error" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec098440b29ea3b1ece3e641bac424c19cf996779b623c9e0f2171495425c2c8" +dependencies = [ + "case", + "quote 0.3.15", + "syn 0.11.11", +] + [[package]] name = "derive_arbitrary" version = "1.3.2" @@ -529,8 +546,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -557,8 +574,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -679,16 +696,16 @@ dependencies = [ [[package]] name = "fontdb" -version = "0.21.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37be9fc20d966be438cd57a45767f73349477fb0f85ce86e000557f787298afb" +checksum = "457e789b3d1202543297a350643cf459f836cade38934e7a4cf6a39e7cde2905" dependencies = [ "fontconfig-parser", "log", "memmap2", "slotmap", "tinyvec", - "ttf-parser 0.24.1", + "ttf-parser 0.25.1", ] [[package]] @@ -777,6 +794,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hex-slice" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5491a308e0214554f07a81d8944abe45f552871c12e3c3c6e7e5d354039a6c4c" + [[package]] name = "hmac" version = "0.12.1" @@ -873,7 +896,7 @@ dependencies = [ "color_quant", "exr", "gif", - "image-webp", + "image-webp 0.1.3", "num-traits", "png", "qoi", @@ -895,6 +918,16 @@ dependencies = [ "quick-error", ] +[[package]] +name = "image-webp" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b77d01e822461baa8409e156015a1d91735549f0f2c17691bd2d996bef238f7f" +dependencies = [ + "byteorder-lite", + "quick-error", +] + [[package]] name = "imagesize" version = "0.12.0" @@ -939,8 +972,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -1124,7 +1157,7 @@ dependencies = [ "markdown", "mime", "mime_guess", - "resvg 0.43.0", + "resvg 0.45.0", "serde", "serde_json", "serde_yaml", @@ -1134,7 +1167,8 @@ dependencies = [ "tempfile", "tera", "tiny-skia", - "usvg 0.43.0", + "usvg 0.45.0", + "xcf-rs", "zip", ] @@ -1198,8 +1232,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mime_guess" version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +source = "git+https://github.com/mothsART/mime_guess?branch=feature%2Fxcf-file#dc06121d990c02f037aa2987006b69d719a41280" dependencies = [ "mime", "unicase", @@ -1275,8 +1308,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -1387,8 +1420,8 @@ dependencies = [ "pest", "pest_meta", "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -1510,8 +1543,8 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" dependencies = [ - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -1529,6 +1562,12 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" +[[package]] +name = "quote" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" + [[package]] name = "quote" version = "1.0.37" @@ -1684,18 +1723,18 @@ dependencies = [ [[package]] name = "resvg" -version = "0.43.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7314563c59c7ce31c18e23ad3dd092c37b928a0fa4e1c0a1a6504351ab411d1" +checksum = "dd43d1c474e9dadf09a8fdf22d713ba668b499b5117b9b9079500224e26b5b29" dependencies = [ "gif", - "image-webp", + "image-webp 0.2.1", "log", "pico-args", "rgb", "svgtypes", "tiny-skia", - "usvg 0.43.0", + "usvg 0.45.0", "zune-jpeg", ] @@ -1745,18 +1784,18 @@ dependencies = [ [[package]] name = "rustybuzz" -version = "0.18.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85d1ccd519e61834798eb52c4e886e8c2d7d698dd3d6ce0b1b47eb8557f1181" +checksum = "fd3c7c96f8a08ee34eff8857b11b49b07d71d1c3f4e88f8a88d4c9e9f90b1702" dependencies = [ "bitflags 2.6.0", "bytemuck", "core_maths", "log", "smallvec", - "ttf-parser 0.24.1", - "unicode-bidi-mirroring 0.3.0", - "unicode-ccc 0.3.0", + "ttf-parser 0.25.1", + "unicode-bidi-mirroring 0.4.0", + "unicode-ccc 0.4.0", "unicode-properties", "unicode-script", ] @@ -1798,8 +1837,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -1877,7 +1916,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6" dependencies = [ - "quote", + "quote 1.0.37", ] [[package]] @@ -1999,14 +2038,25 @@ dependencies = [ [[package]] name = "svgtypes" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794de53cc48eaabeed0ab6a3404a65f40b3e38c067e4435883a65d2aa4ca000e" +checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc" dependencies = [ "kurbo", "siphasher 1.0.1", ] +[[package]] +name = "syn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" +dependencies = [ + "quote 0.3.15", + "synom", + "unicode-xid", +] + [[package]] name = "syn" version = "2.0.76" @@ -2014,10 +2064,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" dependencies = [ "proc-macro2", - "quote", + "quote 1.0.37", "unicode-ident", ] +[[package]] +name = "synom" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" +dependencies = [ + "unicode-xid", +] + [[package]] name = "system-deps" version = "6.2.2" @@ -2088,8 +2147,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -2217,9 +2276,9 @@ checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" [[package]] name = "ttf-parser" -version = "0.24.1" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a" +checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31" dependencies = [ "core_maths", ] @@ -2309,9 +2368,9 @@ checksum = "23cb788ffebc92c5948d0e997106233eeb1d8b9512f93f41651f52b6c5f5af86" [[package]] name = "unicode-bidi-mirroring" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64af057ad7466495ca113126be61838d8af947f41d93a949980b2389a118082f" +checksum = "5dfa6e8c60bb66d49db113e0125ee8711b7647b5579dc7f5f19c42357ed039fe" [[package]] name = "unicode-ccc" @@ -2321,9 +2380,9 @@ checksum = "1df77b101bcc4ea3d78dafc5ad7e4f58ceffe0b2b16bf446aeb50b6cb4157656" [[package]] name = "unicode-ccc" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260bc6647b3893a9a90668360803a15f96b85a5257b1c3a0c3daf6ae2496de42" +checksum = "ce61d488bcdc9bc8b5d1772c404828b17fc481c0a582b5581e95fb233aef503e" [[package]] name = "unicode-ident" @@ -2342,9 +2401,9 @@ dependencies = [ [[package]] name = "unicode-properties" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" [[package]] name = "unicode-script" @@ -2358,6 +2417,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" +[[package]] +name = "unicode-xid" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" + [[package]] name = "unsafe-libyaml" version = "0.2.11" @@ -2404,20 +2469,20 @@ dependencies = [ [[package]] name = "usvg" -version = "0.43.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6803057b5cbb426e9fb8ce2216f3a9b4ca1dd2c705ba3cbebc13006e437735fd" +checksum = "2ac8e0e3e4696253dc06167990b3fe9a2668ab66270adf949a464db4088cb354" dependencies = [ "base64 0.22.1", "data-url", "flate2", - "fontdb 0.21.0", + "fontdb 0.23.0", "imagesize 0.13.0", "kurbo", "log", "pico-args", "roxmltree", - "rustybuzz 0.18.0", + "rustybuzz 0.20.1", "simplecss", "siphasher 1.0.1", "strict-num", @@ -2495,8 +2560,8 @@ dependencies = [ "log", "once_cell", "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", "wasm-bindgen-shared", ] @@ -2506,7 +2571,7 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ - "quote", + "quote 1.0.37", "wasm-bindgen-macro-support", ] @@ -2517,8 +2582,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2710,6 +2775,17 @@ dependencies = [ "memchr", ] +[[package]] +name = "xcf-rs" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b39cdb1a8141bc133b101c25f850f6731059e58077ccd7ca8fc7f49093e7d7c" +dependencies = [ + "byteorder", + "derive-error", + "hex-slice", +] + [[package]] name = "xml-rs" version = "0.8.21" @@ -2739,8 +2815,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] @@ -2759,8 +2835,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", - "quote", - "syn", + "quote 1.0.37", + "syn 2.0.76", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4e42b2b..e6eab5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ clap = { version="4.5", features=['cargo'] } lopdf = { version="0.33", features=["embed_image"] } exitcode="1.1.2" mime="0.3" -mime_guess="2.0" -resvg="0.43" -usvg="0.43" +mime_guess = { git = "https://github.com/mothsART/mime_guess", branch = "feature/xcf-file" } +resvg="0.45" +usvg="0.45" tiny-skia="0.11" image = { version="0.25" } markdown = "0.3" @@ -31,6 +31,7 @@ serde_json = { version = "1.0", features = ["preserve_order"] } serde_yaml = "0.9" tera = "1.17" svg2pdf = "0.11" +xcf-rs = "0.5" [dev-dependencies] sha1 = "0.10.6" diff --git a/src/bin/machmap.rs b/src/bin/machmap.rs index cb86714..7112046 100644 --- a/src/bin/machmap.rs +++ b/src/bin/machmap.rs @@ -48,7 +48,6 @@ fn main() { )); process::exit(exitcode::DATAERR); } - for _l in readlines() { if !Path::new(&_l).exists() { colored_err!(format!("Input file \"{_l}\" doesn't exist")); diff --git a/src/machmap/mod.rs b/src/machmap/mod.rs index 6238c76..df17c26 100644 --- a/src/machmap/mod.rs +++ b/src/machmap/mod.rs @@ -9,6 +9,7 @@ pub mod macros; pub mod jpg; pub mod png; pub mod webp; +//pub mod xcf; pub mod markdown; pub mod svg; @@ -34,6 +35,7 @@ impl<'a> InputsFiles<'a> { let jpg = JPGInputFile::new(input_file, output_file); let png = PNGInputFile::new(input_file, output_file); let webp = WebpInputFile::new(input_file, output_file); + //let xcf = XcfInputFile::new(input_file, output_file); let markdown = MarkdownInputFile::new(input_file, output_file); let yaml = YamlInputFile::new(input_file, output_file); let json = JsonInputFile::new(input_file, output_file); @@ -42,6 +44,7 @@ impl<'a> InputsFiles<'a> { map.insert("image/jpeg", Box::new(jpg)); map.insert("image/png", Box::new(png)); map.insert("image/webp", Box::new(webp)); + //map.insert("image/x-xcf", Box::new(xcf)); map.insert("text/markdown", Box::new(markdown)); map.insert("text/x-yaml", Box::new(yaml)); map.insert("application/json", Box::new(json)); @@ -61,7 +64,10 @@ impl<'a> InputsFiles<'a> { match &input_mime.first_raw() { Some(i_mime) => match self.map.get(i_mime) { Some(val) => val.support(), - None => Err(Box::new(e)), + None => { + println!("ppppp"); + Err(Box::new(e)) + }, }, None => Err(Box::new(e)), } @@ -76,7 +82,10 @@ impl<'a> InputsFiles<'a> { match &input_mime.first_raw() { Some(i_mime) => match self.map.get(i_mime) { Some(val) => val.mime_map(), - None => Err(Box::new(e)), + None => { + println!("yyyy"); + Err(Box::new(e)) + }, }, None => Err(Box::new(e)), } @@ -91,6 +100,7 @@ create_input!(SVGInputFile, InputTo); create_input!(JPGInputFile, InputTo); create_input!(PNGInputFile, InputTo); create_input!(WebpInputFile, InputTo); +//create_input!(XcfInputFile, InputTo); create_input!(MarkdownInputFile, InputTo); create_input!(YamlInputFile, InputTo); create_input!(JsonInputFile, InputTo); diff --git a/src/machmap/png/mod.rs b/src/machmap/png/mod.rs index 742636f..d536144 100644 --- a/src/machmap/png/mod.rs +++ b/src/machmap/png/mod.rs @@ -1,9 +1,10 @@ pub mod pngtopdf; +pub mod pngtoxcf; use colored::Colorize; use image::{ImageFormat, ImageReader}; -use crate::machmap::png::pngtopdf::PngToPdf; +use crate::machmap::png::{pngtopdf::PngToPdf, pngtoxcf::PngToXcf}; use crate::machmap::{Error, HashMap, InputTo, PNGInputFile}; impl<'a> PNGInputFile<'a> { @@ -14,12 +15,16 @@ impl<'a> PNGInputFile<'a> { convert_img!(PngToAvif, "png", "avif"); let avif = PngToAvif::new(input_file, output_file); + let xcf = PngToXcf::new(input_file, output_file); + let pdf = PngToPdf::new(input_file, output_file); let mut map: HashMap<&'a str, Box + 'a>> = HashMap::new(); map.insert("image/jpeg", Box::new(jpg)); map.insert("image/avif", Box::new(avif)); + map.insert("image/x-xcf", Box::new(xcf)); map.insert("application/pdf", Box::new(pdf)); + PNGInputFile { input_file, output_file, diff --git a/src/machmap/png/pngtoxcf.rs b/src/machmap/png/pngtoxcf.rs new file mode 100644 index 0000000..34fc6fc --- /dev/null +++ b/src/machmap/png/pngtoxcf.rs @@ -0,0 +1,84 @@ +use std::error::Error; +use std::path::PathBuf; + +use crate::machmap::InputTo; + +use image::ImageReader; +use image::GenericImageView; + +use xcf_rs::create::XcfCreator; +use xcf_rs::data::color::ColorType; +use xcf_rs::data::rgba::RgbaPixel; +use xcf_rs::data::pixeldata::PixelData; +use xcf_rs::data::layer::Layer; +use xcf_rs::{LayerColorType, LayerColorValue}; + +pub struct PngToXcf<'a> { + pub input_file: &'a str, + pub output_file: &'a str, +} + +impl<'a> PngToXcf<'a> { + pub fn new(input_file: &'a str, output_file: &'a str) -> PngToXcf<'a> { + PngToXcf { + input_file, + output_file, + } + } +} + +impl<'a> InputTo<'a> for PngToXcf<'a> { + fn convert(&self) -> Result> { + let img = ImageReader::open(self.input_file)?.decode()?; + let dimensions = img.dimensions(); + let width = dimensions.0; + let height = dimensions.1; + + + let mut xcf = XcfCreator::new(11, width, height, ColorType::Rgb); + xcf.add_properties(&vec![]); + + let mut layers = vec![]; + let mut pixels = vec![]; + + for p in img.pixels() { + let rgba = p.2.0; + pixels.push(RgbaPixel::new( + *rgba.get(0).unwrap(), + *rgba.get(1).unwrap(), + *rgba.get(2).unwrap(), + *rgba.get(3).unwrap() + )); + } + + let pixels_layer_one: PixelData = PixelData { + width: width, + height: height, + pixels: pixels, + }; + let properties_layer_one = vec![]; + let mut kind = LayerColorType { + kind: LayerColorValue::Rgb, + alpha: false, + }; + if img.color().has_alpha() { + kind = LayerColorType { + kind: LayerColorValue::Rgba, + alpha: true, + }; + } + let layer_one = Layer { + width, + height, + kind, + name: "Background".to_string(), + pixels: pixels_layer_one, + properties: properties_layer_one, + }; + layers.push(layer_one); + xcf.add_layers(&layers); + let output_path = PathBuf::from(self.output_file); + xcf.save(&output_path)?; + Ok("".to_string()) + } +} diff --git a/src/machmap/xcf/mod.rs b/src/machmap/xcf/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/tests/datasets/machmap/Rust_programming_language_black_logo.pdf b/tests/datasets/machmap/Rust_programming_language_black_logo.pdf index cbc3c06..e7426a7 100644 Binary files a/tests/datasets/machmap/Rust_programming_language_black_logo.pdf and b/tests/datasets/machmap/Rust_programming_language_black_logo.pdf differ