-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
635 additions
and
176 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[package] | ||
name = "rmg" | ||
version = "0.2.1" | ||
version = "0.2.3" | ||
edition = "2021" | ||
authors = ["RSUU <[email protected]>"] | ||
description = "Rust: Tiny Manga Reader" | ||
description = "Rust: Tiny Manga/Image Viewer" | ||
readme = "README.md" | ||
homepage = "https://crates.io/crates/rmg" | ||
repository = "https://github.com/rsuu/rmg" | ||
|
@@ -47,6 +47,13 @@ image = { version = "0.24.4" } | |
fir = {package="fast_image_resize" ,version="1.0.0"} | ||
libheif-rs = { version = "0.15.0", optional = true } | ||
asefile ={ version = "0.3.5", optional = true } | ||
# gif | ||
gif = "0.12.0" | ||
gif-dispose = "4" | ||
# svg | ||
usvg = "0.27.0" | ||
tiny-skia = "0.8.2" | ||
resvg = "0.27.0" | ||
|
||
# args | ||
lexopt = "0.2.1" | ||
|
@@ -65,7 +72,6 @@ log = "0.4.17" | |
simple_logger = { version = "2.3.0", features = ["colors", "threads"] } | ||
|
||
|
||
|
||
[dev-dependencies] | ||
# benchmark | ||
criterion = "0.4.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
use image::codecs::gif::{GifDecoder, GifEncoder}; | ||
use image::{AnimationDecoder, ImageDecoder}; | ||
use gif; | ||
use log; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::mem; | ||
|
||
fn load_anim(bytes: &[u8]) { | ||
if let Ok(ref anim) = image::load_from_memory(bytes) { | ||
// let frames = gif::Frame::from_rgb(anim.width(), anim.height(), &mut anim.to_rgb8().to_vec()); | ||
use crate::utils::err::Res; | ||
use crate::utils::traits::AutoLog; | ||
use gif_dispose; | ||
|
||
use super::size::Size; | ||
|
||
pub fn load_gif(bytes: impl Read) -> Res<(Size<u32>, Vec<Vec<u8>>)> { | ||
let mut res = vec![]; | ||
let mut buffer_frame = Vec::new(); | ||
|
||
let mut gif_opts = gif::DecodeOptions::new(); | ||
gif_opts.set_color_output(gif::ColorOutput::Indexed); | ||
let mut decoder = gif_opts.read_info(bytes).unwrap(); | ||
let mut screen = gif_dispose::Screen::new_decoder(&decoder); | ||
|
||
let size = Size { | ||
width: decoder.width() as u32, | ||
height: decoder.height() as u32, | ||
}; | ||
|
||
loop { | ||
"decoded frame"._dbg(); | ||
|
||
if let Some(frame) = decoder.read_next_frame().unwrap() { | ||
screen.blit_frame(frame).unwrap(); | ||
|
||
for rgba in screen.pixels.buf().iter() { | ||
buffer_frame.push(rgba.r); | ||
buffer_frame.push(rgba.g); | ||
buffer_frame.push(rgba.b); | ||
buffer_frame.push(rgba.a); | ||
} | ||
|
||
res.push(mem::take(&mut buffer_frame)); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
Ok((size, res)) | ||
} | ||
|
||
// image | ||
// let gif_decoder = GifDecoder::new(file)?; | ||
// let frames = gif_decoder.into_frames().collect_frames()?; | ||
// for f in frames { | ||
// let delay = f.delay().numer_denom_ms().0 as u16; | ||
// col.add_anim_frame(f.into_buffer(), delay); | ||
// col.repeat = true; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use resvg; | ||
use tiny_skia; | ||
use usvg; | ||
|
||
/* | ||
pub fn load_svg(bytes: &[u8]) -> Res<(Size<u32>, Vec<Vec<u8>>)> { | ||
// let (width, height) = (3000, 3000); | ||
let opt = usvg::Options::default(); | ||
let svg_data = std::fs::read(&img_location)?; | ||
if let Ok(rtree) = usvg::Tree::from_data(&svg_data, &opt.to_ref()) { | ||
// let pixmap_size = rtree.svg_node().size.to_screen_size() | ||
let pixmap_size = rtree.size.to_screen_size(); | ||
// .scale_to(ScreenSize::new(width, height)?); | ||
if let Some(mut pixmap) = tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height()) | ||
{ | ||
resvg::render( | ||
&rtree, | ||
usvg::FitTo::Original, | ||
tiny_skia::Transform::identity(), | ||
pixmap.as_mut(), | ||
) | ||
.ok_or(anyhow!("Can't render SVG"))?; | ||
// resvg::render(&rtree, usvg::FitTo::Height(height), pixmap.as_mut())?; | ||
let buf: Option<RgbaImage> = image::ImageBuffer::from_raw( | ||
pixmap_size.width(), | ||
pixmap_size.height(), | ||
pixmap.data().to_vec(), | ||
); | ||
if let Some(valid_buf) = buf { | ||
col.add_still(valid_buf); | ||
} | ||
} | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,9 @@ where | |
} | ||
|
||
_ => { | ||
return Err(()); | ||
// Only one file. | ||
|
||
todo!() | ||
} | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.