diff --git a/Cargo.lock b/Cargo.lock index db0ac285..b7a3fce8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,6 +43,7 @@ name = "asusctl" version = "3.3.1" dependencies = [ "daemon", + "gif", "glam", "gumdrop", "rog_anime", @@ -177,6 +178,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "concurrent-queue" version = "1.2.2" @@ -440,6 +447,16 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "gif" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a668f699973d0f573d15749b7002a9ac9e1f9c6b220e7b165601334c173d8de" +dependencies = [ + "color_quant", + "weezl", +] + [[package]] name = "glam" version = "0.13.1" @@ -735,12 +752,6 @@ version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" -[[package]] -name = "owo-colors" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fe43bf372b08cc9ccee5144715db59c79ab00168bbe4cf0d274dc0d5f64d7f" - [[package]] name = "parking" version = "2.0.0" @@ -947,8 +958,8 @@ checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" name = "rog_anime" version = "1.0.0" dependencies = [ + "gif", "glam", - "owo-colors", "pix", "png_pong", "serde", @@ -1307,6 +1318,12 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "weezl" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a32b378380f4e9869b22f0b5177c68a5519f03b3454fde0b291455ddbae266c" + [[package]] name = "wepoll-sys" version = "3.0.1" diff --git a/README.md b/README.md index fd3f2e3c..9f363dce 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,11 @@ will probably suffer another rename once it becomes generic enough to do so. - `nvidia`, uses the Nvidia gpu only - `vfio`, binds the Nvidia gpu to vfio for VM pass-through +**Rebootless note:** You must edit `/etc/default/grub` to remove `nvidia-drm.modeset=1` +from the line `GRUB_CMDLINE_LINUX=` and then recreate your grub config. In fedora +you can do this with `sudo grub2-mkconfig -o /etc/grub2.cfg` - other distro may be +similar but with a different config location. + This can be disabled in the config with `"manage_gfx": false,`. Additionally there is an extra setting for laptops capable of g-sync dedicated gfx mode to enable the graphics switching to switch on dedicated gfx for "nvidia" mode. diff --git a/asusctl/Cargo.toml b/asusctl/Cargo.toml index 5145ddfe..b3141b49 100644 --- a/asusctl/Cargo.toml +++ b/asusctl/Cargo.toml @@ -19,4 +19,5 @@ yansi-term = "^0.1" [dev-dependencies] tinybmp = "^0.2.3" glam = "*" -rog_dbus = { path = "../rog-dbus" } \ No newline at end of file +rog_dbus = { path = "../rog-dbus" } +gif = "^0.11.2" \ No newline at end of file diff --git a/asusctl/examples/animatrix-diag-png.rs b/asusctl/examples/animatrix-diag-png.rs new file mode 100644 index 00000000..187a1b25 --- /dev/null +++ b/asusctl/examples/animatrix-diag-png.rs @@ -0,0 +1,32 @@ +use std::{env, error::Error, path::Path, process::exit}; + +use rog_anime::{ + AniMeDataBuffer, {AniMeDiagonal, Vec2}, +}; +use rog_dbus::AuraDbusClient; + +fn main() -> Result<(), Box> { + let (client, _) = AuraDbusClient::new().unwrap(); + + let args: Vec = env::args().into_iter().collect(); + if args.len() != 3 { + println!( + "Usage: " + ); + println!("e.g, asusctl/examples/doom_large.png 0.8"); + exit(-1); + } + + let matrix = AniMeDiagonal::from_png( + Path::new(&args[1]), + args[2].parse::().unwrap(), + )?; + + client + .proxies() + .anime() + .write(::from(&matrix)) + .unwrap(); + + Ok(()) +} diff --git a/asusctl/examples/animatrix-diag.rs b/asusctl/examples/animatrix-diag.rs new file mode 100644 index 00000000..fc61282a --- /dev/null +++ b/asusctl/examples/animatrix-diag.rs @@ -0,0 +1,32 @@ +use std::{thread::sleep, time::Duration}; + +use rog_anime::{AniMeDataBuffer, AniMeDiagonal}; +use rog_dbus::AuraDbusClient; + +// In usable data: +// Top row start at 1, ends at 32 + +// 74w x 36h diagonal used by the windows app + +fn main() { + let (client, _) = AuraDbusClient::new().unwrap(); + + for step in (2..50).rev() { + let mut matrix = AniMeDiagonal::new(); + for c in (0..60).into_iter().step_by(step) { + for i in matrix.get_mut().iter_mut() { + i[c] = 50; + } + } + + for c in (0..35).into_iter().step_by(step) { + for i in matrix.get_mut()[c].iter_mut() { + *i = 50; + } + } + + let m = ::from(&matrix); + client.proxies().anime().write(m).unwrap(); + sleep(Duration::from_millis(300)); + } +} diff --git a/asusctl/examples/animatrix-gif.rs b/asusctl/examples/animatrix-gif.rs new file mode 100644 index 00000000..e95d54f4 --- /dev/null +++ b/asusctl/examples/animatrix-gif.rs @@ -0,0 +1,29 @@ +use std::{env, fs::File, path::Path, thread::sleep, time::Duration}; + +use rog_anime::AniMeSequence; +use rog_dbus::AuraDbusClient; + +fn main() { + let (client, _) = AuraDbusClient::new().unwrap(); + + let args: Vec = env::args().into_iter().collect(); + if args.len() != 3 { + println!("Please supply filepath and brightness"); + return; + } + + let path = Path::new(&args[1]); + let brightness = args[2].parse::().unwrap(); + let gif = AniMeSequence::gif(path, brightness).unwrap(); + + loop { + for frame in gif.get_animation().unwrap().frames() { + client + .proxies() + .anime() + .write(frame.frame().clone()) + .unwrap(); + sleep(frame.delay()); + } + } +} diff --git a/asusctl/examples/animatrix-grid.rs b/asusctl/examples/animatrix-grid.rs index 1773d088..2e42c1cc 100644 --- a/asusctl/examples/animatrix-grid.rs +++ b/asusctl/examples/animatrix-grid.rs @@ -4,19 +4,37 @@ use rog_dbus::AuraDbusClient; // In usable data: // Top row start at 1, ends at 32 +// 74w x 36h diagonal used by the windows app + fn main() { let (client, _) = AuraDbusClient::new().unwrap(); let mut matrix = AniMeGrid::new(); - { - let tmp = matrix.get_mut(); - for row in tmp.iter_mut() { - row[row.len() - 33] = 0xff; + let tmp = matrix.get_mut(); - row[row.len() - 22] = 0xff; + let mut i = 0; + for (y, row) in tmp.iter_mut().enumerate() { + if y % 2 == 0 && i + 1 != row.len() -1 { + i += 1; + dbg!(i); + } + row[row.len() - i] = 0x22; + if i > 5{ + row[row.len() - i + 5] = 0x22; + } + if i > 10 { + row[row.len() - i + 10] = 0x22; + } - row[row.len() - 11] = 0xff; + if i > 15 { + row[row.len() - i + 15] = 0x22; + } - row[row.len() - 1] = 0xff; + if i > 20 { + row[row.len() - i + 20] = 0x22; + } + + if i > 25 { + row[row.len() - i + 25] = 0x22; } } diff --git a/asusctl/examples/animatrix-png.rs b/asusctl/examples/animatrix-png.rs index dc6619a3..f2d0e98e 100644 --- a/asusctl/examples/animatrix-png.rs +++ b/asusctl/examples/animatrix-png.rs @@ -1,7 +1,7 @@ use std::{env, error::Error, path::Path, process::exit}; use rog_anime::{ - AniMeDataBuffer, {AnimeImage, Vec2}, + AniMeDataBuffer, {AniMeImage, Vec2}, }; use rog_dbus::AuraDbusClient; @@ -11,14 +11,13 @@ fn main() -> Result<(), Box> { let args: Vec = env::args().into_iter().collect(); if args.len() != 8 { println!( - "Usage: " + "Usage: " ); - println!("e.g, asusctl/examples/doom_large.png 0.9 0.9 0.4 0.0 0.0, 0.8"); - println!("All args except path and fineness are floats"); + println!("e.g, asusctl/examples/doom_large.png 0.9 0.9 0.4 0.0 0.0,0.8"); exit(-1); } - let matrix = AnimeImage::from_png( + let matrix = AniMeImage::from_png( Path::new(&args[1]), Vec2::new( args[2].parse::().unwrap(), diff --git a/asusctl/examples/animatrix-spinning.rs b/asusctl/examples/animatrix-spinning.rs index 73bd8f2e..c28074f9 100644 --- a/asusctl/examples/animatrix-spinning.rs +++ b/asusctl/examples/animatrix-spinning.rs @@ -3,7 +3,7 @@ use std::{ }; use rog_anime::{ - AniMeDataBuffer, {AnimeImage, Vec2}, + AniMeDataBuffer, {AniMeImage, Vec2}, }; use rog_dbus::AuraDbusClient; @@ -18,7 +18,7 @@ fn main() -> Result<(), Box> { exit(-1); } - let mut matrix = AnimeImage::from_png( + let mut matrix = AniMeImage::from_png( Path::new(&args[1]), Vec2::new( args[2].parse::().unwrap(), diff --git a/asusctl/examples/controller.gif b/asusctl/examples/controller.gif new file mode 100644 index 00000000..ace761cd Binary files /dev/null and b/asusctl/examples/controller.gif differ diff --git a/asusctl/examples/controller.png b/asusctl/examples/controller.png new file mode 100644 index 00000000..36e29a15 Binary files /dev/null and b/asusctl/examples/controller.png differ diff --git a/asusctl/examples/diag_sq.png b/asusctl/examples/diag_sq.png new file mode 100644 index 00000000..36e29a15 Binary files /dev/null and b/asusctl/examples/diag_sq.png differ diff --git a/asusctl/examples/levelup.png b/asusctl/examples/levelup.png new file mode 100644 index 00000000..b7a8d333 Binary files /dev/null and b/asusctl/examples/levelup.png differ diff --git a/asusctl/examples/sunset.gif b/asusctl/examples/sunset.gif new file mode 100644 index 00000000..f114859c Binary files /dev/null and b/asusctl/examples/sunset.gif differ diff --git a/asusctl/src/anime_cli.rs b/asusctl/src/anime_cli.rs index 92b0dd18..c4fb7600 100644 --- a/asusctl/src/anime_cli.rs +++ b/asusctl/src/anime_cli.rs @@ -79,10 +79,8 @@ pub struct AniMeImage { pub help: bool, #[options(meta = "", help = "full path to the png to display")] pub path: String, - #[options(meta = "", default = "0.0", help = "x scale 0.0-1.0")] - pub x_scale: f32, - #[options(meta = "", default = "0.0", help = "y scale 0.0-1.0")] - pub y_scale: f32, + #[options(meta = "", default = "1.0", help = "scale 1.0 == normal")] + pub scale: f32, #[options(meta = "", default = "0.0", help = "x position (float)")] pub x_pos: f32, #[options(meta = "", default = "0.0", help = "y position (float)")] diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 657bfbe4..cfa05145 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -10,7 +10,7 @@ use daemon::{ use gumdrop::{Opt, Options}; use rog_anime::{ AniMeDataBuffer, ANIME_DATA_LEN, - AnimeImage, Vec2, + AniMeImage, Vec2, }; use rog_dbus::AuraDbusClient; use rog_types::{ @@ -178,9 +178,9 @@ fn main() -> Result<(), Box> { std::process::exit(1); } - let matrix = AnimeImage::from_png( + let matrix = AniMeImage::from_png( Path::new(&image.path), - Vec2::new(image.x_scale, image.y_scale), + Vec2::new(image.scale, image.scale), image.angle, Vec2::new(image.x_pos, image.y_pos), image.bright, diff --git a/data/anime/Festive/0.0.1/Category name translation.csv b/data/anime/Festive/0.0.1/Category name translation.csv new file mode 100755 index 00000000..c1590249 --- /dev/null +++ b/data/anime/Festive/0.0.1/Category name translation.csv @@ -0,0 +1,15 @@ +Language,String +en,Festive +zh-tw,節慶 +zh-cn,节庆 +nl,Feestelijk +fr,Festif +de,Festlich +ja,フェスティバル +pt,Festivo +ru,Праздники +es,Festivo +it,Feste +cs,Slavnostní +ko,축제 +tr,Eğlence diff --git a/data/anime/Festive/0.0.1/Halloween.gif b/data/anime/Festive/0.0.1/Halloween.gif new file mode 100755 index 00000000..3d69e436 Binary files /dev/null and b/data/anime/Festive/0.0.1/Halloween.gif differ diff --git a/data/anime/Festive/0.0.1/Happy Holiday.gif b/data/anime/Festive/0.0.1/Happy Holiday.gif new file mode 100755 index 00000000..6e089fd9 Binary files /dev/null and b/data/anime/Festive/0.0.1/Happy Holiday.gif differ diff --git a/data/anime/Festive/0.0.2/Category name translation.csv b/data/anime/Festive/0.0.2/Category name translation.csv new file mode 100755 index 00000000..12c5b8d5 --- /dev/null +++ b/data/anime/Festive/0.0.2/Category name translation.csv @@ -0,0 +1,18 @@ +Language,String +en,Festive +zh-tw,節慶 +zh-cn,节庆 +nl,Feestelijk +fr,Festif +de,Festlich +ja,フェスティバル +pt,Festivo +ru,Праздники +es,Festivo +it,Feste +cs,Slavnostní +ko,축제 +tr,Eğlence +fi,Juhlava +nb,Festlig +sv,Festligt diff --git a/data/anime/Festive/0.0.2/Cupid.gif b/data/anime/Festive/0.0.2/Cupid.gif new file mode 100755 index 00000000..30918b01 Binary files /dev/null and b/data/anime/Festive/0.0.2/Cupid.gif differ diff --git a/data/anime/Festive/0.0.2/Firework.gif b/data/anime/Festive/0.0.2/Firework.gif new file mode 100755 index 00000000..15d58c38 Binary files /dev/null and b/data/anime/Festive/0.0.2/Firework.gif differ diff --git a/data/anime/Festive/0.0.2/Happy new year.gif b/data/anime/Festive/0.0.2/Happy new year.gif new file mode 100755 index 00000000..4738fc9c Binary files /dev/null and b/data/anime/Festive/0.0.2/Happy new year.gif differ diff --git a/data/anime/Festive/0.0.2/Lantern.gif b/data/anime/Festive/0.0.2/Lantern.gif new file mode 100755 index 00000000..65f07b69 Binary files /dev/null and b/data/anime/Festive/0.0.2/Lantern.gif differ diff --git a/data/anime/Festive/0.0.2/Valentine's Day.gif b/data/anime/Festive/0.0.2/Valentine's Day.gif new file mode 100755 index 00000000..140db756 Binary files /dev/null and b/data/anime/Festive/0.0.2/Valentine's Day.gif differ diff --git a/data/anime/Festive/0.0.2/Year of the Ox.gif b/data/anime/Festive/0.0.2/Year of the Ox.gif new file mode 100755 index 00000000..ec18d40c Binary files /dev/null and b/data/anime/Festive/0.0.2/Year of the Ox.gif differ diff --git a/data/anime/Folder order.csv b/data/anime/Folder order.csv new file mode 100755 index 00000000..95e87243 --- /dev/null +++ b/data/anime/Folder order.csv @@ -0,0 +1,16 @@ +Language,Trend,Gaming,Festive,Music,ROG theme +cs,1,2,3,4,5 +de,1,2,3,4,5 +en,1,2,3,4,5 +es,1,2,3,4,5 +fr,1,2,3,4,5 +it,1,2,3,4,5 +ja,1,2,3,4,5 +ko,1,2,3,4,5 +nl,1,2,3,4,5 +pt,1,2,3,4,5 +ru,1,2,3,4,5 +tr,1,2,3,4,5 +zh-cn,1,2,3,4,5 +zh-tw,1,2,3,4,5 +default,1,2,3,4,5 diff --git a/data/anime/Gaming/0.0.1/Bird.gif b/data/anime/Gaming/0.0.1/Bird.gif new file mode 100755 index 00000000..482e52fe Binary files /dev/null and b/data/anime/Gaming/0.0.1/Bird.gif differ diff --git a/data/anime/Gaming/0.0.1/Category name translation.csv b/data/anime/Gaming/0.0.1/Category name translation.csv new file mode 100755 index 00000000..e0ea4444 --- /dev/null +++ b/data/anime/Gaming/0.0.1/Category name translation.csv @@ -0,0 +1,15 @@ +Language,String +en,Gaming +zh-tw,遊戲 +zh-cn,游戏 +nl,Gaming +fr,Jeu +de,Gaming +ja,ゲーム +pt,Jogos +ru,Игры +es,Juegos +it,Gaming +cs,Hraní +ko,게이밍 +tr,Oyun diff --git a/data/anime/Gaming/0.0.1/Controller.gif b/data/anime/Gaming/0.0.1/Controller.gif new file mode 100755 index 00000000..ace761cd Binary files /dev/null and b/data/anime/Gaming/0.0.1/Controller.gif differ diff --git a/data/anime/Gaming/0.0.1/FPS.gif b/data/anime/Gaming/0.0.1/FPS.gif new file mode 100755 index 00000000..31c3fed9 Binary files /dev/null and b/data/anime/Gaming/0.0.1/FPS.gif differ diff --git a/data/anime/Gaming/0.0.1/Keyboard.gif b/data/anime/Gaming/0.0.1/Keyboard.gif new file mode 100755 index 00000000..846c18b3 Binary files /dev/null and b/data/anime/Gaming/0.0.1/Keyboard.gif differ diff --git a/data/anime/Gaming/0.0.1/MOBA.gif b/data/anime/Gaming/0.0.1/MOBA.gif new file mode 100755 index 00000000..f9773d7e Binary files /dev/null and b/data/anime/Gaming/0.0.1/MOBA.gif differ diff --git a/data/anime/Gaming/0.0.2/Category name translation.csv b/data/anime/Gaming/0.0.2/Category name translation.csv new file mode 100755 index 00000000..e0ea4444 --- /dev/null +++ b/data/anime/Gaming/0.0.2/Category name translation.csv @@ -0,0 +1,15 @@ +Language,String +en,Gaming +zh-tw,遊戲 +zh-cn,游戏 +nl,Gaming +fr,Jeu +de,Gaming +ja,ゲーム +pt,Jogos +ru,Игры +es,Juegos +it,Gaming +cs,Hraní +ko,게이밍 +tr,Oyun diff --git a/data/anime/Gaming/0.0.2/Fight.gif b/data/anime/Gaming/0.0.2/Fight.gif new file mode 100755 index 00000000..ab5f094a Binary files /dev/null and b/data/anime/Gaming/0.0.2/Fight.gif differ diff --git a/data/anime/Gaming/0.0.2/UFO.gif b/data/anime/Gaming/0.0.2/UFO.gif new file mode 100755 index 00000000..a444c77e Binary files /dev/null and b/data/anime/Gaming/0.0.2/UFO.gif differ diff --git a/data/anime/Music/0.0.1/Category name translation.csv b/data/anime/Music/0.0.1/Category name translation.csv new file mode 100755 index 00000000..2ca9b78b --- /dev/null +++ b/data/anime/Music/0.0.1/Category name translation.csv @@ -0,0 +1,17 @@ +Language,String +en,Music +zh-tw,音樂 +zh-cn,音乐 +nl,Muziek +fr,Musique +de,Musik +ja,ミュージック +pt,Música +ru,Музыка +es,Música +it,Musica +cs,Hudba +ko,음악 +tr,Müzik +, +, diff --git a/data/anime/Music/0.0.1/Music-player.gif b/data/anime/Music/0.0.1/Music-player.gif new file mode 100755 index 00000000..7147f936 Binary files /dev/null and b/data/anime/Music/0.0.1/Music-player.gif differ diff --git a/data/anime/Music/0.0.2/DJ.gif b/data/anime/Music/0.0.2/DJ.gif new file mode 100755 index 00000000..f25a8705 Binary files /dev/null and b/data/anime/Music/0.0.2/DJ.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/Category name translation.csv b/data/anime/ROG Gallery/0.0.1/Category name translation.csv new file mode 100755 index 00000000..6ab5be52 --- /dev/null +++ b/data/anime/ROG Gallery/0.0.1/Category name translation.csv @@ -0,0 +1,15 @@ +Language,String +en,ROG Gallery +zh-tw,ROG 主題 +zh-cn,ROG 主题 +nl,ROG-thema +fr,Thème ROG +de,ROG-Thema +ja,ROG テーマ +pt,Tema ROG +ru,Тема ROG +es,Tema de ROG +it,Tema ROG +cs,Téma ROG +ko,ROG 테마 +tr,ROG teması diff --git a/data/anime/ROG Gallery/0.0.1/For-those-who-dare.gif b/data/anime/ROG Gallery/0.0.1/For-those-who-dare.gif new file mode 100755 index 00000000..134bb31b Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/For-those-who-dare.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/For-those-who-dare_2.gif b/data/anime/ROG Gallery/0.0.1/For-those-who-dare_2.gif new file mode 100755 index 00000000..c10795bf Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/For-those-who-dare_2.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/Fragment.gif b/data/anime/ROG Gallery/0.0.1/Fragment.gif new file mode 100755 index 00000000..e61fa340 Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/Fragment.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/Infinite-triangle.gif b/data/anime/ROG Gallery/0.0.1/Infinite-triangle.gif new file mode 100755 index 00000000..bac89252 Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/Infinite-triangle.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/Kaleidoscope1.gif b/data/anime/ROG Gallery/0.0.1/Kaleidoscope1.gif new file mode 100755 index 00000000..8ed95577 Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/Kaleidoscope1.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/Kaleidoscope2.gif b/data/anime/ROG Gallery/0.0.1/Kaleidoscope2.gif new file mode 100755 index 00000000..ca0efbf6 Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/Kaleidoscope2.gif differ diff --git a/data/anime/ROG Gallery/0.0.1/Sunset.gif b/data/anime/ROG Gallery/0.0.1/Sunset.gif new file mode 100755 index 00000000..f114859c Binary files /dev/null and b/data/anime/ROG Gallery/0.0.1/Sunset.gif differ diff --git a/data/anime/Trend/0.0.1/Category name translation.csv b/data/anime/Trend/0.0.1/Category name translation.csv new file mode 100755 index 00000000..20321136 --- /dev/null +++ b/data/anime/Trend/0.0.1/Category name translation.csv @@ -0,0 +1,15 @@ +Language,String +en,Trend +zh-tw,潮流 +zh-cn,潮流 +nl,Trend +fr,Tendance +de,Trend +ja,トレンド +pt,Tendência +ru,В тренде +es,Tendencia +it,Tendenza +cs,Trend +ko,트렌드 +tr,Popüler diff --git a/data/anime/Trend/0.0.1/Dog.gif b/data/anime/Trend/0.0.1/Dog.gif new file mode 100755 index 00000000..a3a7db5f Binary files /dev/null and b/data/anime/Trend/0.0.1/Dog.gif differ diff --git a/data/anime/Trend/0.0.1/Ski.gif b/data/anime/Trend/0.0.1/Ski.gif new file mode 100755 index 00000000..752b8702 Binary files /dev/null and b/data/anime/Trend/0.0.1/Ski.gif differ diff --git a/data/anime/Trend/0.0.2/Category name translation.csv b/data/anime/Trend/0.0.2/Category name translation.csv new file mode 100755 index 00000000..20321136 --- /dev/null +++ b/data/anime/Trend/0.0.2/Category name translation.csv @@ -0,0 +1,15 @@ +Language,String +en,Trend +zh-tw,潮流 +zh-cn,潮流 +nl,Trend +fr,Tendance +de,Trend +ja,トレンド +pt,Tendência +ru,В тренде +es,Tendencia +it,Tendenza +cs,Trend +ko,트렌드 +tr,Popüler diff --git a/data/anime/Trend/0.0.2/Wave.gif b/data/anime/Trend/0.0.2/Wave.gif new file mode 100755 index 00000000..63fd82d9 Binary files /dev/null and b/data/anime/Trend/0.0.2/Wave.gif differ diff --git a/rog-anime/Cargo.toml b/rog-anime/Cargo.toml index b22dbe35..50fd09ae 100644 --- a/rog-anime/Cargo.toml +++ b/rog-anime/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" png_pong = "^0.8.0" glam = "*" pix = "0.13" -owo-colors = "2.0.0" +gif = "^0.11.2" serde = "^1.0" serde_derive = "^1.0" diff --git a/rog-anime/src/anime_diagonal.rs b/rog-anime/src/anime_diagonal.rs new file mode 100644 index 00000000..ac7e8464 --- /dev/null +++ b/rog-anime/src/anime_diagonal.rs @@ -0,0 +1,136 @@ +use std::path::Path; + +use crate::{ + anime_data::{AniMeDataBuffer, ANIME_DATA_LEN}, + error::AnimeError, +}; + +const WIDTH: usize = 74; +const HEIGHT: usize = 36; + +#[derive(Debug, Clone)] +pub struct AniMeDiagonal([[u8; WIDTH]; HEIGHT]); + +impl Default for AniMeDiagonal { + fn default() -> Self { + Self::new() + } +} + +impl AniMeDiagonal { + pub fn new() -> Self { + Self([[0u8; WIDTH]; HEIGHT]) + } + + pub fn get_mut(&mut self) -> &mut [[u8; WIDTH]; HEIGHT] { + &mut self.0 + } + + fn get_row(&self, x: usize, y: usize, len: usize) -> Vec { + let mut buf = Vec::with_capacity(len); + for i in 0..len { + let val = self.0[HEIGHT - y - i - 1][x + i]; + buf.push(val); + } + buf + } + + /// Generate the base image from inputs. The result can be displayed as is or + /// updated via scale, position, or angle then displayed again after `update()`. + pub fn from_png( + path: &Path, + bright: f32, + ) -> Result { + use pix::el::Pixel; + let data = std::fs::read(path)?; + let data = std::io::Cursor::new(data); + let decoder = png_pong::Decoder::new(data)?.into_steps(); + let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??; + + let mut matrix = AniMeDiagonal::new(); + + let width; + match raster { + png_pong::PngRaster::Graya8(ras) => { + width = ras.width(); + for (y, row) in ras.pixels() + .chunks(width as usize).enumerate() { + for (x, px) in row.iter().enumerate() { + let v = ::from(px.one() * bright); + matrix.0[y][x] = v; + } + } + } + _ => return Err(AnimeError::Format), + }; + + Ok(matrix) + } +} + +impl From<&AniMeDiagonal> for AniMeDataBuffer { + /// Do conversion from the nested Vec in AniMeMatrix to the two required + /// packets suitable for sending over USB + #[inline] + fn from(anime: &AniMeDiagonal) -> Self { + let mut buf = vec![0u8; ANIME_DATA_LEN]; + + buf[1..=33].copy_from_slice(&anime.get_row(2, 3, 33)); + buf[34..=66].copy_from_slice(&anime.get_row(2, 2, 33)); + buf[68..=100].copy_from_slice(&anime.get_row(2, 1, 33)); + buf[101..=134].copy_from_slice(&anime.get_row(2, 0, 34)); + buf[136..=169].copy_from_slice(&anime.get_row(3, 0, 34)); + buf[170..=202].copy_from_slice(&anime.get_row(4, 0, 33)); + buf[204..=236].copy_from_slice(&anime.get_row(5, 0, 33)); + buf[237..=268].copy_from_slice(&anime.get_row(6, 0, 32)); + buf[270..=301].copy_from_slice(&anime.get_row(7, 0, 32)); + buf[302..=332].copy_from_slice(&anime.get_row(8, 0, 31)); + buf[334..=364].copy_from_slice(&anime.get_row(9, 0, 31)); + buf[365..=394].copy_from_slice(&anime.get_row(10, 0, 30)); + buf[396..=425].copy_from_slice(&anime.get_row(11, 0, 30)); + buf[426..=454].copy_from_slice(&anime.get_row(12, 0, 29)); + buf[456..=484].copy_from_slice(&anime.get_row(13, 0, 29)); + buf[485..=512].copy_from_slice(&anime.get_row(14, 0, 28)); + buf[514..=541].copy_from_slice(&anime.get_row(15, 0, 28)); + buf[542..=568].copy_from_slice(&anime.get_row(16, 0, 27)); + buf[570..=596].copy_from_slice(&anime.get_row(17, 0, 27)); + buf[597..=622].copy_from_slice(&anime.get_row(18, 0, 26)); + buf[624..=649].copy_from_slice(&anime.get_row(19, 0, 26)); + buf[650..=674].copy_from_slice(&anime.get_row(20, 0, 25)); + buf[676..=700].copy_from_slice(&anime.get_row(21, 0, 25)); + buf[701..=724].copy_from_slice(&anime.get_row(22, 0, 24)); + buf[726..=749].copy_from_slice(&anime.get_row(23, 0, 24)); + buf[750..=772].copy_from_slice(&anime.get_row(24, 0, 23)); + buf[774..=796].copy_from_slice(&anime.get_row(25, 0, 23)); + buf[797..=818].copy_from_slice(&anime.get_row(26, 0, 22)); + buf[820..=841].copy_from_slice(&anime.get_row(27, 0, 22)); + buf[842..=862].copy_from_slice(&anime.get_row(28, 0, 21)); + buf[864..=884].copy_from_slice(&anime.get_row(29, 0, 21)); + buf[885..=904].copy_from_slice(&anime.get_row(30, 0, 20)); + buf[906..=925].copy_from_slice(&anime.get_row(31, 0, 20)); + buf[926..=944].copy_from_slice(&anime.get_row(32, 0, 19)); + buf[946..=964].copy_from_slice(&anime.get_row(33, 0, 19)); + buf[965..=982].copy_from_slice(&anime.get_row(34, 0, 18)); + buf[984..=1001].copy_from_slice(&anime.get_row(35, 0, 18)); + buf[1002..=1018].copy_from_slice(&anime.get_row(36, 0, 17)); + buf[1020..=1036].copy_from_slice(&anime.get_row(37, 0, 17)); + buf[1037..=1052].copy_from_slice(&anime.get_row(38, 0, 16)); + buf[1054..=1069].copy_from_slice(&anime.get_row(39, 0, 16)); + buf[1070..=1084].copy_from_slice(&anime.get_row(40, 0, 15)); + buf[1086..=1100].copy_from_slice(&anime.get_row(41, 0, 15)); + buf[1101..=1114].copy_from_slice(&anime.get_row(42, 0, 14)); + buf[1116..=1129].copy_from_slice(&anime.get_row(43, 0, 14)); + buf[1130..=1142].copy_from_slice(&anime.get_row(44, 0, 13)); + buf[1144..=1156].copy_from_slice(&anime.get_row(45, 0, 13)); + buf[1157..=1168].copy_from_slice(&anime.get_row(46, 0, 12)); + buf[1170..=1181].copy_from_slice(&anime.get_row(47, 0, 12)); + buf[1182..=1192].copy_from_slice(&anime.get_row(48, 0, 11)); + buf[1194..=1204].copy_from_slice(&anime.get_row(49, 0, 11)); + buf[1205..=1214].copy_from_slice(&anime.get_row(50, 0, 10)); + buf[1216..=1225].copy_from_slice(&anime.get_row(51, 0, 10)); + buf[1226..=1234].copy_from_slice(&anime.get_row(52, 0, 9)); + buf[1236..=1244].copy_from_slice(&anime.get_row(53, 0, 9)); + + AniMeDataBuffer::from_vec(buf) + } +} diff --git a/rog-anime/src/anime_gif.rs b/rog-anime/src/anime_gif.rs new file mode 100644 index 00000000..13783721 --- /dev/null +++ b/rog-anime/src/anime_gif.rs @@ -0,0 +1,61 @@ +use serde_derive::{Deserialize, Serialize}; +use std::{fs::File, path::{Path}, time::Duration}; + +use crate::{error::AnimeError, AniMeDataBuffer, AniMeDiagonal}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct AniMeFrame { + data: AniMeDataBuffer, + delay: Duration, +} + +impl AniMeFrame { + pub fn frame(&self) -> &AniMeDataBuffer { + &self.data + } + + pub fn delay(&self) -> Duration { + self.delay + } +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct AniMeGif(Vec); + +impl AniMeGif { + pub fn new(file_name: &Path, brightness: f32) -> Result { + let mut frames = Vec::new(); + let mut matrix = AniMeDiagonal::new(); + + let mut decoder = gif::DecodeOptions::new(); + // Configure the decoder such that it will expand the image to RGBA. + decoder.set_color_output(gif::ColorOutput::RGBA); + // Read the file header + let file = File::open(file_name)?; + let mut decoder = decoder.read_info(file)?; + + while let Some(frame) = decoder.read_next_frame()? { + let wait = frame.delay * 10; + for (y, row) in frame.buffer.chunks(frame.width as usize * 4).enumerate() { + for (x, px) in row.chunks(4).enumerate() { + if px[3] != 255 { + // should be t but not in some gifs? What, ASUS, what? + continue; + } + matrix.get_mut()[y + frame.top as usize][x + frame.left as usize] = + (px[0] as f32 * brightness) as u8; + } + } + + frames.push(AniMeFrame { + data: ::from(&matrix), + delay: Duration::from_millis(wait as u64), + }); + } + Ok(Self(frames)) + } + + pub fn frames(&self) -> &[AniMeFrame] { + &self.0 + } +} diff --git a/rog-anime/src/anime_grid.rs b/rog-anime/src/anime_grid.rs index 0d0d319a..253f6406 100644 --- a/rog-anime/src/anime_grid.rs +++ b/rog-anime/src/anime_grid.rs @@ -1,6 +1,5 @@ use crate::anime_data::{AniMeDataBuffer, ANIME_DATA_LEN}; use crate::anime_image::LED_IMAGE_POSITIONS; -use owo_colors::{OwoColorize, Rgb}; const WIDTH: usize = 33; const HEIGHT: usize = 55; @@ -44,38 +43,38 @@ impl AniMeGrid { } } - pub fn debug_print(&self) { - // this is the index from right. It is used to progressively shorten rows - let mut prog_row_len = WIDTH - 2; + // pub fn debug_print(&self) { + // // this is the index from right. It is used to progressively shorten rows + // let mut prog_row_len = WIDTH - 2; - for (count, row) in self.0.iter().enumerate() { - // Switch to next block (looks like ) - if count % 2 != 0 { - // Row after 6 is only 1 less, then rows after 7 follow pattern - if count == 7 { - prog_row_len -= 1; - } else { - prog_row_len -= 2; - } - } else { - prog_row_len += 1; // if count 6, 0 - } + // for (count, row) in self.0.iter().enumerate() { + // // Switch to next block (looks like ) + // if count % 2 != 0 { + // // Row after 6 is only 1 less, then rows after 7 follow pattern + // if count == 7 { + // prog_row_len -= 1; + // } else { + // prog_row_len -= 2; + // } + // } else { + // prog_row_len += 1; // if count 6, 0 + // } - let index = row.len() - prog_row_len; + // let index = row.len() - prog_row_len; - if count % 2 == 0 { - print!(" "); - } - for (i, n) in row.iter().enumerate() { - if i >= index { - print!(" {}", "XXX".color(Rgb(0, *n, 0))); - } else { - print!(" "); - } - } - println!(); - } - } + // if count % 2 == 0 { + // print!(" "); + // } + // for (i, n) in row.iter().enumerate() { + // if i >= index { + // print!(" {}", "XXX".color(Rgb(0, *n, 0))); + // } else { + // print!(" "); + // } + // } + // println!(); + // } + // } } impl From for AniMeDataBuffer { diff --git a/rog-anime/src/anime_image.rs b/rog-anime/src/anime_image.rs index 8f1ad4b8..ffac92ee 100644 --- a/rog-anime/src/anime_image.rs +++ b/rog-anime/src/anime_image.rs @@ -49,7 +49,7 @@ impl Led { /// Container of `Led`, each of which specifies a position within the image /// The main use of this is to position and sample colours for the final image /// to show on AniMe -pub struct AnimeImage { +pub struct AniMeImage { pub scale: Vec2, /// Angle in radians pub angle: f32, @@ -63,7 +63,7 @@ pub struct AnimeImage { width: u32, } -impl AnimeImage { +impl AniMeImage { const fn new( scale: Vec2, angle: f32, @@ -133,11 +133,11 @@ impl AnimeImage { /// Really only used to generate the output for including as a full const in `LED_IMAGE_POSITIONS` pub fn generate() -> Vec> { - (0..AnimeImage::height()) + (0..AniMeImage::height()) .flat_map(|y| { - (0..AnimeImage::pitch(y)).map(move |l| { - if l < AnimeImage::width(y) { - let x = AnimeImage::first_x(y) + l; + (0..AniMeImage::pitch(y)).map(move |l| { + if l < AniMeImage::width(y) { + let x = AniMeImage::first_x(y) + l; Some(Led::new(x as f32 - 0.5 * (y % 2) as f32, y as f32)) } else { None @@ -203,8 +203,8 @@ impl AnimeImage { // Center of image let center = Mat3::from_translation(Vec2::new(-0.5 * bmp_w, -0.5 * bmp_h)); // Find the scale required for cleanly showing the image - let h = AnimeImage::phys_height() / bmp_h; - let mut base_scale = AnimeImage::phys_width() / bmp_w; + let h = AniMeImage::phys_height() / bmp_h; + let mut base_scale = AniMeImage::phys_width() / bmp_w; if base_scale > h { base_scale = h; } @@ -212,8 +212,8 @@ impl AnimeImage { let cm_from_px = Mat3::from_scale(Vec2::new(base_scale, base_scale)); let led_from_cm = Mat3::from_scale(Vec2::new( - 1.0 / AnimeImage::scale_x(), - 1.0 / AnimeImage::scale_y(), + 1.0 / AniMeImage::scale_x(), + 1.0 / AniMeImage::scale_y(), )); let transform = @@ -258,18 +258,18 @@ impl AnimeImage { _ => return Err(AnimeError::Format), }; - let mut matrix = AnimeImage::new(scale, angle, translation, bright, pixels, width); + let mut matrix = AniMeImage::new(scale, angle, translation, bright, pixels, width); matrix.update(); Ok(matrix) } } -impl From<&AnimeImage> for AniMeDataBuffer { +impl From<&AniMeImage> for AniMeDataBuffer { /// Do conversion from the nested Vec in AniMeMatrix to the two required /// packets suitable for sending over USB #[inline] - fn from(leds: &AnimeImage) -> Self { + fn from(leds: &AniMeImage) -> Self { let mut l: Vec = leds .led_pos .iter() @@ -1540,7 +1540,7 @@ mod tests { #[test] fn led_positions() { - let leds = AnimeImage::generate(); + let leds = AniMeImage::generate(); assert_eq!(leds[0], Some(Led(0.0, 0.0, 0))); assert_eq!(leds[1], Some(Led(1.0, 0.0, 0))); assert_eq!(leds[2], Some(Led(2.0, 0.0, 0))); @@ -1569,7 +1569,7 @@ mod tests { #[test] fn led_positions_const() { - let leds = AnimeImage::generate(); + let leds = AniMeImage::generate(); assert_eq!(leds[1], LED_IMAGE_POSITIONS[1]); assert_eq!(leds[34], LED_IMAGE_POSITIONS[34]); assert_eq!(leds[69], LED_IMAGE_POSITIONS[69]); @@ -1583,44 +1583,44 @@ mod tests { #[test] fn row_starts() { - assert_eq!(AnimeImage::first_x(5), 0); - assert_eq!(AnimeImage::first_x(6), 0); - assert_eq!(AnimeImage::first_x(7), 1); - assert_eq!(AnimeImage::first_x(8), 1); - assert_eq!(AnimeImage::first_x(9), 2); - assert_eq!(AnimeImage::first_x(10), 2); - assert_eq!(AnimeImage::first_x(11), 3); + assert_eq!(AniMeImage::first_x(5), 0); + assert_eq!(AniMeImage::first_x(6), 0); + assert_eq!(AniMeImage::first_x(7), 1); + assert_eq!(AniMeImage::first_x(8), 1); + assert_eq!(AniMeImage::first_x(9), 2); + assert_eq!(AniMeImage::first_x(10), 2); + assert_eq!(AniMeImage::first_x(11), 3); } #[test] fn row_widths() { - assert_eq!(AnimeImage::width(5), 33); - assert_eq!(AnimeImage::width(6), 33); - assert_eq!(AnimeImage::width(7), 32); - assert_eq!(AnimeImage::width(8), 32); - assert_eq!(AnimeImage::width(9), 31); - assert_eq!(AnimeImage::width(10), 31); - assert_eq!(AnimeImage::width(11), 30); - assert_eq!(AnimeImage::width(12), 30); - assert_eq!(AnimeImage::width(13), 29); - assert_eq!(AnimeImage::width(14), 29); - assert_eq!(AnimeImage::width(15), 28); - assert_eq!(AnimeImage::width(16), 28); - assert_eq!(AnimeImage::width(17), 27); - assert_eq!(AnimeImage::width(18), 27); + assert_eq!(AniMeImage::width(5), 33); + assert_eq!(AniMeImage::width(6), 33); + assert_eq!(AniMeImage::width(7), 32); + assert_eq!(AniMeImage::width(8), 32); + assert_eq!(AniMeImage::width(9), 31); + assert_eq!(AniMeImage::width(10), 31); + assert_eq!(AniMeImage::width(11), 30); + assert_eq!(AniMeImage::width(12), 30); + assert_eq!(AniMeImage::width(13), 29); + assert_eq!(AniMeImage::width(14), 29); + assert_eq!(AniMeImage::width(15), 28); + assert_eq!(AniMeImage::width(16), 28); + assert_eq!(AniMeImage::width(17), 27); + assert_eq!(AniMeImage::width(18), 27); } #[test] fn row_pitch() { - assert_eq!(AnimeImage::pitch(5), 34); - assert_eq!(AnimeImage::pitch(6), 33); - assert_eq!(AnimeImage::pitch(7), 33); - assert_eq!(AnimeImage::pitch(8), 32); - assert_eq!(AnimeImage::pitch(9), 32); - assert_eq!(AnimeImage::pitch(10), 31); - assert_eq!(AnimeImage::pitch(11), 31); - assert_eq!(AnimeImage::pitch(12), 30); - assert_eq!(AnimeImage::pitch(13), 30); - assert_eq!(AnimeImage::pitch(14), 29); + assert_eq!(AniMeImage::pitch(5), 34); + assert_eq!(AniMeImage::pitch(6), 33); + assert_eq!(AniMeImage::pitch(7), 33); + assert_eq!(AniMeImage::pitch(8), 32); + assert_eq!(AniMeImage::pitch(9), 32); + assert_eq!(AniMeImage::pitch(10), 31); + assert_eq!(AniMeImage::pitch(11), 31); + assert_eq!(AniMeImage::pitch(12), 30); + assert_eq!(AniMeImage::pitch(13), 30); + assert_eq!(AniMeImage::pitch(14), 29); } } diff --git a/rog-anime/src/error.rs b/rog-anime/src/error.rs index 3e7c7ddc..6bfa7e3f 100644 --- a/rog-anime/src/error.rs +++ b/rog-anime/src/error.rs @@ -1,5 +1,6 @@ use std::error::Error; use std::fmt; +use gif::DecodingError; use png_pong::decode::Error as PngError; #[derive(Debug)] @@ -7,6 +8,7 @@ pub enum AnimeError { NoFrames, Io(std::io::Error), Png(PngError), + Gif(DecodingError), Format } @@ -17,6 +19,7 @@ impl fmt::Display for AnimeError { AnimeError::NoFrames => write!(f, "No frames in PNG"), AnimeError::Io(e) => write!(f, "Could not open: {}", e), AnimeError::Png(e) => write!(f, "PNG error: {}", e), + AnimeError::Gif(e) => write!(f, "GIF error: {}", e), AnimeError::Format => write!(f, "PNG file is not 8bit greyscale"), } } @@ -34,4 +37,10 @@ impl From for AnimeError { fn from(err: PngError) -> Self { AnimeError::Png(err) } +} + +impl From for AnimeError { + fn from(err: DecodingError) -> Self { + AnimeError::Gif(err) + } } \ No newline at end of file diff --git a/rog-anime/src/lib.rs b/rog-anime/src/lib.rs index 0d9a86a0..e92b0da1 100644 --- a/rog-anime/src/lib.rs +++ b/rog-anime/src/lib.rs @@ -1,6 +1,9 @@ +use serde_derive::{Deserialize, Serialize}; /// The main data conversion for transfering in shortform over dbus or other, /// or writing directly to the USB device mod anime_data; +use std::{path::Path, time::Duration}; + pub use anime_data::*; /// Useful for specialised effects that required a grid of data @@ -11,5 +14,58 @@ pub use anime_grid::*; mod anime_image; pub use anime_image::*; +mod anime_diagonal; +pub use anime_diagonal::*; + +mod anime_gif; +pub use anime_gif::*; +use error::AnimeError; + /// Base errors that are possible -pub mod error; \ No newline at end of file +pub mod error; + +// TODO: make schema to rebuild the full sequence without requiring saving the actual +// packet data + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub enum AniMeSequence { + /// Full gif sequence. Immutable. + Animation(AniMeGif), + /// Basic image, can have properties changed + Image(Box), + /// A pause to be used between sequences + Pause(Duration), +} + +impl AniMeSequence { + pub fn gif(file: &Path, brightness: f32) -> Result { + let frames = AniMeGif::new(file, brightness)?; + Ok(Self::Animation(frames)) + } + + pub fn png( + file: &Path, + scale: Vec2, + angle: f32, + translation: Vec2, + brightness: f32, + ) -> Result { + let image = AniMeImage::from_png(file, scale, angle, translation, brightness)?; + let data = ::from(&image); + Ok(Self::Image(Box::new(data))) + } + + pub fn get_animation(&self) -> Option<&AniMeGif> { + match self { + AniMeSequence::Animation(anim) => Some(anim), + _ => None, + } + } + + pub fn get_image(&self) -> Option<&AniMeDataBuffer> { + match self { + AniMeSequence::Image(image) => Some(image), + _ => None, + } + } +}