Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rsuu committed Dec 10, 2022
1 parent 54e9cf3 commit a7ecaa2
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 218 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rmg"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
authors = ["RSUU <[email protected]>"]
description = "Rust: Tiny Manga/Image Viewer"
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ rmg --size 600,600 --config ./tests/files/config.rs ./tests/files/img.tar

### KeyMap

|#|#|
|Key| |
|:-|:-|
k/Up | up
j/Down | down
h/Left | left
r/Right | right
k/Up | move up
j/Down | move down
h/Left | move left
r/Right | move right
q | quit

### Configuration

> config file: https://raw.githubusercontent.com/rsuu/rmg/main/tests/files/config.rs
WARN: You have to create the file by yourself.
`WARN:` You have to create the file by yourself.

+ configuration file path
+ Linux: `$HOME/.config/rmg/config.rs`
Expand All @@ -68,7 +68,7 @@ WARN: You have to create the file by yourself.
## Supported formats

| Format | Supported | Default |Dependency
|:-|:-|:-|
|:-|:-|:-|:-|
.jpg |✅ | ✅|
.png|✅| ✅|
.heic / .avif|🔬|❌|libheif
Expand All @@ -77,7 +77,7 @@ WARN: You have to create the file by yourself.

---
| Format | Supported | Default |Dependency
|:-|:-|:-|
|:-|:-|:-|:-|
.tar |✅ | ✅| tar
.zip / .cbz |✅ | ✅| zip

Expand Down
25 changes: 2 additions & 23 deletions benches/benchmarks/color.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
#![allow(deprecated)]

use criterion::{criterion_group, Criterion};
use rmg::color::rgba::TransRgba;

pub static mut RES_BUFFER: Vec<u32> = Vec::new();
pub static mut COLOR_BUFFER: Vec<u8> = Vec::new();

pub fn c_color(c: &mut Criterion) {
c.bench_function("with_step: u8 to rgba", |b| b.iter(with_step));
c.bench_function("with_chunks: u8 to rgba", |b| b.iter(with_chunks));
}

#[inline]
fn with_step() {
unsafe {
COLOR_BUFFER = vec![0; 40];

for f in (4..COLOR_BUFFER.len()).step_by(4) {
RES_BUFFER.push(TransRgba::rgba_to_u32(
&COLOR_BUFFER[f - 4..f].try_into().unwrap(),
));
}
}
}
fn with_step() {}

#[inline]
fn with_chunks() {
unsafe {
COLOR_BUFFER = vec![0; 40];

for f in COLOR_BUFFER.as_slice().chunks(4) {
RES_BUFFER.push(TransRgba::rgba_to_u32(f.try_into().unwrap()));
}
}
}
fn with_chunks() {}

criterion_group!(bench, c_color);
35 changes: 24 additions & 11 deletions src/archive/dir.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
use crate::utils::err::{MyErr, Res};

use std::{fs::OpenOptions, io::Read, path::Path};
use walkdir;

pub fn load_file(path: &Path, pos: usize) -> Res<Vec<u8>> {
for (idx, f) in walkdir::WalkDir::new(path).into_iter().enumerate() {
pub fn load_file(path: impl AsRef<Path>) -> Res<Vec<u8>> {
let mut buffer = Vec::new();
let mut file = OpenOptions::new()
.write(false)
.read(true)
.create(false)
.open(path.as_ref())?;

file.read_to_end(&mut buffer)?;

Ok(buffer)
}

pub fn load_dir(path: impl AsRef<Path>, pos: usize) -> Res<Vec<u8>> {
for (idx, tmp) in walkdir::WalkDir::new(path.as_ref()).into_iter().enumerate() {
if pos == idx {
let mut buffer = Vec::new();
let mut f = OpenOptions::new()
let mut file = OpenOptions::new()
.write(false)
.read(true)
.create(false)
.open(f.unwrap().path())
.unwrap();
.open(tmp?.path())?;

f.read_to_end(&mut buffer).unwrap();
file.read_to_end(&mut buffer)?;

// done
return Ok(buffer);
} else {
// to next
}
}

Err(MyErr::Null(()))
Err(MyErr::Null)
}

pub fn get_file_list(path: &Path) -> Res<Vec<(String, usize)>> {
pub fn get_file_list(path: impl AsRef<Path>) -> Res<Vec<(String, usize)>> {
let mut list = Vec::new();

for (idx, f) in walkdir::WalkDir::new(path).into_iter().enumerate() {
list.push((f?.path().to_str().unwrap().to_string(), idx));
for (idx, file) in walkdir::WalkDir::new(path.as_ref()).into_iter().enumerate() {
list.push((file?.path().to_str().unwrap().to_string(), idx));
}

Ok(list)
Expand Down
8 changes: 3 additions & 5 deletions src/archive/tar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::utils::err::{MyErr, Res};
use crate::utils::err::{Res};
use std::{
fs::{File, OpenOptions},
io::Read,
path::Path,
};

Expand Down Expand Up @@ -46,7 +44,7 @@ pub fn get_file_list(path: &Path) -> Res<Vec<(String, usize)>> {
mod feat {
use crate::utils::err::{MyErr, Res};
use std::{
fs::{File, OpenOptions},
fs::{OpenOptions},
io::Read,
path::Path,
};
Expand Down Expand Up @@ -90,6 +88,6 @@ mod feat {
}
}

Err(MyErr::Null(()))
Err(MyErr::Null)
}
}
12 changes: 6 additions & 6 deletions src/archive/zip.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::utils::err::{MyErr, Res};
use std::io::prelude::*;
use std::io::BufReader;
use std::{fs::File, path::Path};
use zip::ZipArchive;
use crate::utils::err::{Res};


use std::{path::Path};


pub fn load_file<_Path>(path: &_Path, idx: usize) -> Res<Vec<u8>>
where
Expand Down Expand Up @@ -45,7 +45,7 @@ where

#[cfg(feature = "ex_zip")]
mod feat {
use crate::utils::err::{MyErr, Res};
use crate::utils::err::{Res};
use std::io::prelude::*;
use std::io::BufReader;
use std::{fs::File, path::Path};
Expand Down
2 changes: 1 addition & 1 deletion src/color/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub struct TransRgba {}

impl TransRgba {
#[inline(always)]
pub fn rgba_as_srgb_u32(r: &u8, g: &u8, b: &u8, a: &u8) -> u32 {
pub fn rgba_as_argb_u32(r: &u8, g: &u8, b: &u8, a: &u8) -> u32 {
// (r, g, b, a) -> (a, r, g, b) -> u32
// 3 2 1 0 3 2 1 0
((*r as u32) << 8 * 2)
Expand Down
1 change: 0 additions & 1 deletion src/img/ase.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
img::size::Size,
reader::view::Page,
utils::err::{MyErr, Res},
};

Expand Down
4 changes: 2 additions & 2 deletions src/img/gif.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use gif;
use log;
use std::fs::File;


use std::io::Read;
use std::mem;

Expand Down
3 changes: 1 addition & 2 deletions src/img/heic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::utils::err::{MyErr, Res};
use log;

pub fn load_heic(bytes: &[u8]) -> Res<(u32, u32, Vec<Vec<u8>>)> {
cfg_if::cfg_if! {
Expand Down Expand Up @@ -63,7 +62,7 @@ mod feat {

return Ok((width, height, vec![res]));
} else {
return Err(MyErr::Null(()));
return Err(MyErr::Null);
}
}
}
9 changes: 4 additions & 5 deletions src/img/resize.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::{
color::rgba::TransRgba,
img::heic,
img::size::{MetaSize, Size, TMetaSize},
img::size::{MetaSize, TMetaSize},
utils::err::Res,
};
use cfg_if::cfg_if;
use fir;
use image::DynamicImage;

use std::num::NonZeroU32;

#[inline(always)]
Expand Down Expand Up @@ -48,11 +47,11 @@ pub fn resize_rgba8(
}

#[inline(always)]
pub fn srgb_u32(buffer: &mut Vec<u32>, bytes: &[u8]) {
pub fn argb_u32(buffer: &mut Vec<u32>, bytes: &[u8]) {
*buffer = vec![0; bytes.len() / 4];

for (idx, f) in (0..bytes.len()).step_by(4).enumerate() {
buffer[idx] =
TransRgba::rgba_as_srgb_u32(&bytes[f], &bytes[f + 1], &bytes[f + 2], &bytes[f + 3]);
TransRgba::rgba_as_argb_u32(&bytes[f], &bytes[f + 1], &bytes[f + 2], &bytes[f + 3]);
}
}
41 changes: 20 additions & 21 deletions src/img/svg.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
use resvg;
use tiny_skia;
use usvg;
use usvg::{self, ScreenRect};

/*
use crate::utils::err::Res;

use super::size::Size;

pub fn load_svg(bytes: &[u8]) -> Res<(Size<u32>, Vec<Vec<u8>>)> {
// let (width, height) = (3000, 3000);
let size = Size::new(2000, 2000);
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 Ok(rtree) = usvg::Tree::from_data(&bytes, &opt.to_ref()) {
let pixmap_size = rtree
.size
.to_screen_size()
.scale_to(usvg::ScreenSize::new(size.width, size.height).unwrap());

if let Some(mut pixmap) = tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height())
{
resvg::render(
&rtree,
usvg::FitTo::Original,
usvg::FitTo::Height(size.height),
//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);
}
.unwrap();

return Ok((size, vec![pixmap.data().to_vec()]));
} else {
}
} else {
}
}

*/
Err(crate::utils::err::MyErr::Todo)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub mod archive {
Tar,
Zip,
Dir,
File,
}

pub mod dir;
Expand Down
Loading

0 comments on commit a7ecaa2

Please sign in to comment.