Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
rsuu committed Dec 18, 2022
1 parent 9dabbd3 commit 7a99bc2
Show file tree
Hide file tree
Showing 33 changed files with 1,196 additions and 851 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

49 changes: 4 additions & 45 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rmg"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["RSUU <[email protected]>"]
description = "Rust: Tiny And Fast Manga/Image Viewer"
Expand Down Expand Up @@ -91,62 +91,21 @@ de_svg= ["dep:usvg","dep:tiny-skia","dep:resvg"]


[profile.release]
strip = true
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
lto = true
lto = "thin"
opt-level = 3
overflow-checks = false
panic = "abort"


[profile.dev.package.asefile]
strip = true
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
opt-level = 3
overflow-checks = false


[profile.dev.package.fast_image_resize]
strip = true
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
opt-level = 3
overflow-checks = false
panic = "abort"


[profile.dev.package.image]
strip = true
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
[profile.release.package."*"]
opt-level = 3
overflow-checks = false


[profile.dev.package.gif]
strip = true
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
opt-level = 3
overflow-checks = false


[profile.dev.package.gif-dispose]
strip = true
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
opt-level = 3
overflow-checks = false
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ cargo build --release
## Usage

```bash
rmg ./tests/files/img.tar
rmg file.tar

# OR
rmg --size 600,600 ./tests/files/img.tar
rmg --size 600,600 file.tar

# OR
rmg --size 600,600 --config ./tests/files/config.rs ./tests/files/img.tar
rmg --size 600,600 --config ./tests/files/config.rs file.tar

rmg file.gif
```

### KeyMap
Expand All @@ -67,14 +67,14 @@ q | quit

## Supported formats

| Format | Supported | Default |Dependency
|:-|:-|:-|:-|
.jpg |✅ | ✅|
.png|✅| ✅|
.heic / .avif|🔬|❌|libheif
.gif|🔬|✅|
.aseprite|🔬|❌|
.svg|🔬|❌|
| Format | Supported | Default |Dependency | Mode
|:-|:-|:-|:-|:-|
.jpg |✅ | ✅||Scroll/Once
.png|✅| ✅||Scroll/Once
.heic / .avif|🔬|❌|libheif|Scroll/Once
.gif|🔬|✅||Once
.aseprite|🔬|❌||Once
.svg|🔬|❌||Scroll/Once

---
| Format | Supported | Default |Dependency
Expand Down
3 changes: 3 additions & 0 deletions docs/BUG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
infer svg

gif OOM
7 changes: 3 additions & 4 deletions examples/heic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use cfg_if::cfg_if;

fn main() {
cfg_if! {
// decode heic
if #[cfg(feature="de_heic")] {
cfg_if! { // decode heic
if #[cfg(feature="de_heic")] {

// cg ex heic -F de_heic
use libheif_rs;
Expand Down Expand Up @@ -61,7 +60,7 @@ where

let rgb = yuv_to_rgb(img[y].into(), img[u].into(), img[v].into());

res[idx + 0] = rgb[0];
res[idx] = rgb[0];
res[idx + 1] = rgb[1];
res[idx + 2] = rgb[2];
}
Expand Down
54 changes: 0 additions & 54 deletions examples/minifb_rgba.rs

This file was deleted.

43 changes: 27 additions & 16 deletions src/archive/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@ pub fn load_file(path: impl AsRef<Path>) -> Res<Vec<u8>> {
}

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 file = OpenOptions::new()
.read(true)
.write(false)
.create(false)
.open(tmp?.path())?;

file.read_to_end(&mut buffer)?;

// done
return Ok(buffer);
let mut idx = 0;

for tmp in walkdir::WalkDir::new(path.as_ref()).into_iter() {
if tmp.as_ref().unwrap().file_type().is_file() {
if pos == idx {
let mut buffer = Vec::new();
let mut file = OpenOptions::new()
.read(true)
.write(false)
.create(false)
.open(tmp?.path())?;

file.read_to_end(&mut buffer)?;

log::debug!("{},{}", idx, pos);
// done
return Ok(buffer);
} else {
idx += 1;
}
} else {
// to next
}
}

Expand All @@ -39,9 +45,14 @@ pub fn load_dir(path: impl AsRef<Path>, pos: usize) -> Res<Vec<u8>> {

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

for (idx, file) in walkdir::WalkDir::new(path.as_ref()).into_iter().enumerate() {
list.push((file?.path().to_str().unwrap().to_string(), idx));
for file in walkdir::WalkDir::new(path.as_ref()).into_iter() {
if file.as_ref().unwrap().file_type().is_file() {
list.push((file?.path().to_str().unwrap().to_string(), idx));
idx += 1;
} else {
}
}

Ok(list)
Expand Down
4 changes: 2 additions & 2 deletions src/archive/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
pub fn load_file(path: &Path, idx: usize) -> Res<Vec<u8>> {
cfg_if::cfg_if! {
if #[cfg(feature = "ex_tar")] {
feat::load_file(path.as_ref(), idx)
feat::load_file(path, idx)
} else {
Err(MyErr::FeatTar)
}
Expand All @@ -33,7 +33,7 @@ pub fn load_file(path: &Path, idx: usize) -> Res<Vec<u8>> {
pub fn get_file_list(path: &Path) -> Res<Vec<(String, usize)>> {
cfg_if::cfg_if! {
if #[cfg(feature = "ex_tar")] {
feat::get_file_list(path.as_ref())
feat::get_file_list(path)
} else {
Err( MyErr::FeatTar)
}
Expand Down
5 changes: 0 additions & 5 deletions src/color/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PixelFormat {
Rgb8,
Rgba8,
}
21 changes: 3 additions & 18 deletions src/color/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,25 @@ impl TransRgba {
// (rgba & 0x0ff) as u8,
// ];

// SAFETY
// SAFETY:
unsafe { std::mem::transmute::<u32, [u8; 4]>(rgba.to_be()) }
}
}

// trait ExtRgba {
// fn as_u32(&self) -> u32;
// }
//
// impl ExtRgba for rgb::RGBA8 {
// #[inline(always)]
// fn as_u32(&self) -> u32 {
// let r = (self.r as u32) << 24;
// let g = (self.g as u32) << 16;
// let b = (self.b as u32) << 8;
// let a = self.a as u32;
//
// r + g + b + a
// }
// }

mod test {
use super::TransRgba;

#[test]
fn _rgba_as_argb_u32() {}

#[test]
fn _rgba_as_u32() {
use crate::color::rgba::TransRgba;
assert_eq!(16909060, TransRgba::rgba_as_u32(&1, &2, &3, &4));
}

#[test]
fn _rgba_from_u32() {
use crate::color::rgba::TransRgba;
assert_eq!([1_u8, 2, 3, 4], TransRgba::rgba_from_u32(&16909060));
}
}
9 changes: 8 additions & 1 deletion src/config/rsconf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ pub struct Keymap<Char_> {
pub left: Char_, // move to left
pub right: Char_, // move to right
pub exit: Char_, // exit
// pub fullscreen: Char_,
pub fullscreen: Char_,
}

#[derive(Debug)]
pub struct Image {
pub resize_anim: bool,
pub resize_bit: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -100,6 +106,7 @@ impl Default for Keymap<char> {
left: 'h',
right: 'l',
exit: 'q',
fullscreen: 'f',
}
}
}
Expand Down
Loading

0 comments on commit 7a99bc2

Please sign in to comment.