Giter VIP home page Giter VIP logo

slide-show-rs's Introduction

slide-show-rs

Rust

Show images continuously like:

example image

Usage

Before compiling, make sure that your window size is defined in .env file. For example,

WINDOW_WIDTH=1920
WINDOW_HEIGHT=1080

To reduce preprocessing time, use --release option. It makes this program much faster.

cargo run --release

By default, this app shows all images in photo/ directory. If you want to replace it, please give the app directory path as an argument like cargo run --release photo/test.

If you got error(s), please confirm support status of minifb crate (repo).

Speed

The default speed is 5.0s, that is, shown image is changed if 5.0s passes. To change this speed, please input key ⬆️ or ➡️ to increase speed by 0.5s, input key ⬇️ or ⬅️ to decrease speed by 0.5s.

Note that real speed is affected by your machine spec.

Test

In many cases such as this repo's GitHub Actions, cargo test is enough.

But, if you got NSInternalInconsistencyException (macOS) and failed to test, test must be run with --test_threads=1 option. That is, run cargo test -- --test-threads=1.

Formatter

Use clippy and rustfmt before committing changes.

cargo clippy
cargo fmt

Links

The idea of image viewer comes from:

slide-show-rs's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar yammmt avatar

Watchers

 avatar  avatar  avatar

slide-show-rs's Issues

Use GitHub Actions

Since this repo has (only one) test, it's better to use GItHub Actions.

I've tested Actions in actions branch, but the test failed.
And its error message is:

running 1 test
test tests::test_new_window ... FAILED

failures:

---- tests::test_new_window stdout ----
thread 'main' panicked at 'Unable to open Window: Failed to create window', src/main.rs:25:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

failures:
tests::test_new_window

Window::new(
"slide-show-rs - Press ESC to exit",
size.0,
size.1,
WindowOptions {
resize: true,
scale_mode: ScaleMode::Center,
..WindowOptions::default()
},
)
.expect("Unable to open Window")

Does this error come from minifb crate? I don't know 🤔

Avoid cloning filename in threads communications

Current code uses clone() method to send Pathbuf.

slide-show-rs/src/main.rs

Lines 291 to 293 in ac564d3

tx_to_buf_func
.send(ThreadMessage::Filepath(img_filepaths[img_idx].clone()))
.unwrap();

Here, it's better to use &'static lifetime to avoid running the clone() method. The clone() method could take a long time if its contents, here, the given file path is an incredible long.

The main thread must have the file path array as long as the program runs: its lifetime is &'static. And it's the reason why I couldn't use move.

Change speed during the app runs

It would be happy if I can adjust the speed.

⭐ Plan 1: adjust with keyboard inputs like ⬅️ ➡️

Increase (be faster) speed if ⬆️ or ➡️ is detected,
and decrease (be slower) if ⬇️ or ⬅️ is detected.

It's easy to understand and has enough flexibility.

Plan 2: add an argument option

I don't think this is a good way because this app already has one argument.

Prepare image buffer during previous image is shown

An image buffer is created just before its image is shown and it invites the delay.

slide-show-rs/src/main.rs

Lines 244 to 253 in a3dd754

if start_time.elapsed().unwrap() >= Duration::from_secs_f32(interval_sec) {
img_idx = (img_idx + 1) % img_filepaths.len();
// if error is detected, skip its image and try to read next one
img_buf = match image_buffer_from_filepath(&img_filepaths[img_idx]) {
Ok(i) => i,
Err(_) => {
warn!("Failed to read image {}", img_filepaths[img_idx].display());
continue;
}
};

It's better to create another buffer during the previous image is shown and just switch buffer when the shown image is changed.


For example, when I use Raspberry Pi 3B with FHD (1920x1080) screen size, the delay is about 0.3s. 🤔

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.