Prepare for user saving of anime sequences
1
Cargo.lock
generated
@@ -958,6 +958,7 @@ checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
|
|||||||
name = "rog_anime"
|
name = "rog_anime"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"gif",
|
||||||
"glam",
|
"glam",
|
||||||
"pix",
|
"pix",
|
||||||
"png_pong",
|
"png_pong",
|
||||||
|
|||||||
@@ -9,26 +9,17 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let (client, _) = AuraDbusClient::new().unwrap();
|
let (client, _) = AuraDbusClient::new().unwrap();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().into_iter().collect();
|
let args: Vec<String> = env::args().into_iter().collect();
|
||||||
if args.len() != 7 {
|
if args.len() != 3 {
|
||||||
println!(
|
println!(
|
||||||
"Usage: <filepath> <x scale> <y scale> <x pos> <y pos> <brightness>"
|
"Usage: <filepath> <brightness>"
|
||||||
);
|
);
|
||||||
println!("e.g, asusctl/examples/doom_large.png 0.9 0.9 0.4 0.0 0.0 0.8");
|
println!("e.g, asusctl/examples/doom_large.png 0.8");
|
||||||
println!("All args except path and fineness are floats");
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let matrix = AniMeDiagonal::from_png(
|
let matrix = AniMeDiagonal::from_png(
|
||||||
Path::new(&args[1]),
|
Path::new(&args[1]),
|
||||||
Vec2::new(
|
args[2].parse::<f32>().unwrap(),
|
||||||
args[2].parse::<f32>().unwrap(),
|
|
||||||
args[3].parse::<f32>().unwrap(),
|
|
||||||
),
|
|
||||||
Vec2::new(
|
|
||||||
args[4].parse::<f32>().unwrap(),
|
|
||||||
args[5].parse::<f32>().unwrap(),
|
|
||||||
),
|
|
||||||
args[6].parse::<f32>().unwrap(),
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
client
|
client
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use rog_dbus::AuraDbusClient;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let (client, _) = AuraDbusClient::new().unwrap();
|
let (client, _) = AuraDbusClient::new().unwrap();
|
||||||
|
|
||||||
|
|
||||||
for step in (2..50).rev() {
|
for step in (2..50).rev() {
|
||||||
let mut matrix = AniMeDiagonal::new();
|
let mut matrix = AniMeDiagonal::new();
|
||||||
for c in (0..60).into_iter().step_by(step) {
|
for c in (0..60).into_iter().step_by(step) {
|
||||||
|
|||||||
@@ -1,60 +1,29 @@
|
|||||||
use std::{env, fs::File, path::Path, thread::sleep, time::Duration};
|
use std::{env, fs::File, path::Path, thread::sleep, time::Duration};
|
||||||
|
|
||||||
use rog_anime::{AniMeDataBuffer, AniMeDiagonal};
|
use rog_anime::AniMeSequence;
|
||||||
use rog_dbus::AuraDbusClient;
|
use rog_dbus::AuraDbusClient;
|
||||||
|
|
||||||
struct AniMeFrame {
|
|
||||||
data: AniMeDataBuffer,
|
|
||||||
delay: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (client, _) = AuraDbusClient::new().unwrap();
|
let (client, _) = AuraDbusClient::new().unwrap();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().into_iter().collect();
|
let args: Vec<String> = env::args().into_iter().collect();
|
||||||
// if args.len() != 7 {
|
if args.len() != 3 {
|
||||||
// exit(-1);
|
println!("Please supply filepath and brightness");
|
||||||
// }
|
return;
|
||||||
|
|
||||||
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(Path::new(&args[1])).unwrap();
|
|
||||||
let mut decoder = decoder.read_info(file).unwrap();
|
|
||||||
|
|
||||||
while let Some(frame) = decoder.read_next_frame().unwrap() {
|
|
||||||
let wait = frame.delay;
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
client
|
|
||||||
.proxies()
|
|
||||||
.anime()
|
|
||||||
.write(<AniMeDataBuffer>::from(&matrix))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
frames.push(AniMeFrame {
|
|
||||||
data: <AniMeDataBuffer>::from(&matrix),
|
|
||||||
delay: Duration::from_millis(wait as u64),
|
|
||||||
});
|
|
||||||
|
|
||||||
sleep(Duration::from_millis(wait as u64));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let path = Path::new(&args[1]);
|
||||||
|
let brightness = args[2].parse::<f32>().unwrap();
|
||||||
|
let gif = AniMeSequence::gif(path, brightness).unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
for frame in frames.iter() {
|
for frame in gif.get_animation().unwrap().frames() {
|
||||||
client.proxies().anime().write(frame.data.clone()).unwrap();
|
client
|
||||||
sleep(frame.delay);
|
.proxies()
|
||||||
|
.anime()
|
||||||
|
.write(frame.frame().clone())
|
||||||
|
.unwrap();
|
||||||
|
sleep(frame.delay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{env, error::Error, path::Path, process::exit};
|
use std::{env, error::Error, path::Path, process::exit};
|
||||||
|
|
||||||
use rog_anime::{
|
use rog_anime::{
|
||||||
AniMeDataBuffer, {AnimeImage, Vec2},
|
AniMeDataBuffer, {AniMeImage, Vec2},
|
||||||
};
|
};
|
||||||
use rog_dbus::AuraDbusClient;
|
use rog_dbus::AuraDbusClient;
|
||||||
|
|
||||||
@@ -13,12 +13,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
println!(
|
println!(
|
||||||
"Usage: <filepath> <x scale> <y scale> <angle> <x pos> <y pos> <brightness>"
|
"Usage: <filepath> <x scale> <y scale> <angle> <x pos> <y pos> <brightness>"
|
||||||
);
|
);
|
||||||
println!("e.g, asusctl/examples/doom_large.png 0.9 0.9 0.4 0.0 0.0, 0.8");
|
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");
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let matrix = AnimeImage::from_png(
|
let matrix = AniMeImage::from_png(
|
||||||
Path::new(&args[1]),
|
Path::new(&args[1]),
|
||||||
Vec2::new(
|
Vec2::new(
|
||||||
args[2].parse::<f32>().unwrap(),
|
args[2].parse::<f32>().unwrap(),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use rog_anime::{
|
use rog_anime::{
|
||||||
AniMeDataBuffer, {AnimeImage, Vec2},
|
AniMeDataBuffer, {AniMeImage, Vec2},
|
||||||
};
|
};
|
||||||
use rog_dbus::AuraDbusClient;
|
use rog_dbus::AuraDbusClient;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut matrix = AnimeImage::from_png(
|
let mut matrix = AniMeImage::from_png(
|
||||||
Path::new(&args[1]),
|
Path::new(&args[1]),
|
||||||
Vec2::new(
|
Vec2::new(
|
||||||
args[2].parse::<f32>().unwrap(),
|
args[2].parse::<f32>().unwrap(),
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use daemon::{
|
|||||||
use gumdrop::{Opt, Options};
|
use gumdrop::{Opt, Options};
|
||||||
use rog_anime::{
|
use rog_anime::{
|
||||||
AniMeDataBuffer, ANIME_DATA_LEN,
|
AniMeDataBuffer, ANIME_DATA_LEN,
|
||||||
AnimeImage, Vec2,
|
AniMeImage, Vec2,
|
||||||
};
|
};
|
||||||
use rog_dbus::AuraDbusClient;
|
use rog_dbus::AuraDbusClient;
|
||||||
use rog_types::{
|
use rog_types::{
|
||||||
@@ -178,7 +178,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let matrix = AnimeImage::from_png(
|
let matrix = AniMeImage::from_png(
|
||||||
Path::new(&image.path),
|
Path::new(&image.path),
|
||||||
Vec2::new(image.scale, image.scale),
|
Vec2::new(image.scale, image.scale),
|
||||||
image.angle,
|
image.angle,
|
||||||
|
|||||||
15
data/anime/Festive/0.0.1/Category name translation.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Festive/0.0.1/Halloween.gif
Executable file
|
After Width: | Height: | Size: 137 KiB |
BIN
data/anime/Festive/0.0.1/Happy Holiday.gif
Executable file
|
After Width: | Height: | Size: 109 KiB |
18
data/anime/Festive/0.0.2/Category name translation.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Festive/0.0.2/Cupid.gif
Executable file
|
After Width: | Height: | Size: 72 KiB |
BIN
data/anime/Festive/0.0.2/Firework.gif
Executable file
|
After Width: | Height: | Size: 61 KiB |
BIN
data/anime/Festive/0.0.2/Happy new year.gif
Executable file
|
After Width: | Height: | Size: 99 KiB |
BIN
data/anime/Festive/0.0.2/Lantern.gif
Executable file
|
After Width: | Height: | Size: 85 KiB |
BIN
data/anime/Festive/0.0.2/Valentine's Day.gif
Executable file
|
After Width: | Height: | Size: 48 KiB |
BIN
data/anime/Festive/0.0.2/Year of the Ox.gif
Executable file
|
After Width: | Height: | Size: 60 KiB |
16
data/anime/Folder order.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Gaming/0.0.1/Bird.gif
Executable file
|
After Width: | Height: | Size: 96 KiB |
15
data/anime/Gaming/0.0.1/Category name translation.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Gaming/0.0.1/Controller.gif
Executable file
|
After Width: | Height: | Size: 32 KiB |
BIN
data/anime/Gaming/0.0.1/FPS.gif
Executable file
|
After Width: | Height: | Size: 54 KiB |
BIN
data/anime/Gaming/0.0.1/Keyboard.gif
Executable file
|
After Width: | Height: | Size: 34 KiB |
BIN
data/anime/Gaming/0.0.1/MOBA.gif
Executable file
|
After Width: | Height: | Size: 49 KiB |
15
data/anime/Gaming/0.0.2/Category name translation.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Gaming/0.0.2/Fight.gif
Executable file
|
After Width: | Height: | Size: 234 KiB |
BIN
data/anime/Gaming/0.0.2/UFO.gif
Executable file
|
After Width: | Height: | Size: 63 KiB |
17
data/anime/Music/0.0.1/Category name translation.csv
Executable file
@@ -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
|
||||||
|
,
|
||||||
|
,
|
||||||
|
BIN
data/anime/Music/0.0.1/Music-player.gif
Executable file
|
After Width: | Height: | Size: 132 KiB |
BIN
data/anime/Music/0.0.2/DJ.gif
Executable file
|
After Width: | Height: | Size: 119 KiB |
15
data/anime/ROG Gallery/0.0.1/Category name translation.csv
Executable file
@@ -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ı
|
||||||
|
BIN
data/anime/ROG Gallery/0.0.1/For-those-who-dare.gif
Executable file
|
After Width: | Height: | Size: 90 KiB |
BIN
data/anime/ROG Gallery/0.0.1/For-those-who-dare_2.gif
Executable file
|
After Width: | Height: | Size: 64 KiB |
BIN
data/anime/ROG Gallery/0.0.1/Fragment.gif
Executable file
|
After Width: | Height: | Size: 16 KiB |
BIN
data/anime/ROG Gallery/0.0.1/Infinite-triangle.gif
Executable file
|
After Width: | Height: | Size: 56 KiB |
BIN
data/anime/ROG Gallery/0.0.1/Kaleidoscope1.gif
Executable file
|
After Width: | Height: | Size: 31 KiB |
BIN
data/anime/ROG Gallery/0.0.1/Kaleidoscope2.gif
Executable file
|
After Width: | Height: | Size: 46 KiB |
BIN
data/anime/ROG Gallery/0.0.1/Sunset.gif
Executable file
|
After Width: | Height: | Size: 40 KiB |
15
data/anime/Trend/0.0.1/Category name translation.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Trend/0.0.1/Dog.gif
Executable file
|
After Width: | Height: | Size: 120 KiB |
BIN
data/anime/Trend/0.0.1/Ski.gif
Executable file
|
After Width: | Height: | Size: 112 KiB |
15
data/anime/Trend/0.0.2/Category name translation.csv
Executable file
@@ -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
|
||||||
|
BIN
data/anime/Trend/0.0.2/Wave.gif
Executable file
|
After Width: | Height: | Size: 73 KiB |
@@ -13,6 +13,7 @@ edition = "2018"
|
|||||||
png_pong = "^0.8.0"
|
png_pong = "^0.8.0"
|
||||||
glam = "*"
|
glam = "*"
|
||||||
pix = "0.13"
|
pix = "0.13"
|
||||||
|
gif = "^0.11.2"
|
||||||
|
|
||||||
serde = "^1.0"
|
serde = "^1.0"
|
||||||
serde_derive = "^1.0"
|
serde_derive = "^1.0"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use glam::Vec2;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
anime_data::{AniMeDataBuffer, ANIME_DATA_LEN},
|
anime_data::{AniMeDataBuffer, ANIME_DATA_LEN},
|
||||||
error::AnimeError,
|
error::AnimeError,
|
||||||
@@ -28,11 +26,6 @@ impl AniMeDiagonal {
|
|||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
// use with height - y
|
|
||||||
const fn dy(x: usize, y: usize) -> usize {
|
|
||||||
x / 2 + x % 2 + y
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_row(&self, x: usize, y: usize, len: usize) -> Vec<u8> {
|
fn get_row(&self, x: usize, y: usize, len: usize) -> Vec<u8> {
|
||||||
let mut buf = Vec::with_capacity(len);
|
let mut buf = Vec::with_capacity(len);
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
@@ -46,8 +39,6 @@ impl AniMeDiagonal {
|
|||||||
/// updated via scale, position, or angle then displayed again after `update()`.
|
/// updated via scale, position, or angle then displayed again after `update()`.
|
||||||
pub fn from_png(
|
pub fn from_png(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
scale: Vec2,
|
|
||||||
offset: Vec2,
|
|
||||||
bright: f32,
|
bright: f32,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self, AnimeError> {
|
||||||
use pix::el::Pixel;
|
use pix::el::Pixel;
|
||||||
|
|||||||
61
rog-anime/src/anime_gif.rs
Normal file
@@ -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<AniMeFrame>);
|
||||||
|
|
||||||
|
impl AniMeGif {
|
||||||
|
pub fn new(file_name: &Path, brightness: f32) -> Result<Self, AnimeError> {
|
||||||
|
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: <AniMeDataBuffer>::from(&matrix),
|
||||||
|
delay: Duration::from_millis(wait as u64),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(Self(frames))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn frames(&self) -> &[AniMeFrame] {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,7 @@ impl Led {
|
|||||||
/// Container of `Led`, each of which specifies a position within the image
|
/// 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
|
/// The main use of this is to position and sample colours for the final image
|
||||||
/// to show on AniMe
|
/// to show on AniMe
|
||||||
pub struct AnimeImage {
|
pub struct AniMeImage {
|
||||||
pub scale: Vec2,
|
pub scale: Vec2,
|
||||||
/// Angle in radians
|
/// Angle in radians
|
||||||
pub angle: f32,
|
pub angle: f32,
|
||||||
@@ -63,7 +63,7 @@ pub struct AnimeImage {
|
|||||||
width: u32,
|
width: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnimeImage {
|
impl AniMeImage {
|
||||||
const fn new(
|
const fn new(
|
||||||
scale: Vec2,
|
scale: Vec2,
|
||||||
angle: f32,
|
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`
|
/// Really only used to generate the output for including as a full const in `LED_IMAGE_POSITIONS`
|
||||||
pub fn generate() -> Vec<Option<Led>> {
|
pub fn generate() -> Vec<Option<Led>> {
|
||||||
(0..AnimeImage::height())
|
(0..AniMeImage::height())
|
||||||
.flat_map(|y| {
|
.flat_map(|y| {
|
||||||
(0..AnimeImage::pitch(y)).map(move |l| {
|
(0..AniMeImage::pitch(y)).map(move |l| {
|
||||||
if l < AnimeImage::width(y) {
|
if l < AniMeImage::width(y) {
|
||||||
let x = AnimeImage::first_x(y) + l;
|
let x = AniMeImage::first_x(y) + l;
|
||||||
Some(Led::new(x as f32 - 0.5 * (y % 2) as f32, y as f32))
|
Some(Led::new(x as f32 - 0.5 * (y % 2) as f32, y as f32))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -203,8 +203,8 @@ impl AnimeImage {
|
|||||||
// Center of image
|
// Center of image
|
||||||
let center = Mat3::from_translation(Vec2::new(-0.5 * bmp_w, -0.5 * bmp_h));
|
let center = Mat3::from_translation(Vec2::new(-0.5 * bmp_w, -0.5 * bmp_h));
|
||||||
// Find the scale required for cleanly showing the image
|
// Find the scale required for cleanly showing the image
|
||||||
let h = AnimeImage::phys_height() / bmp_h;
|
let h = AniMeImage::phys_height() / bmp_h;
|
||||||
let mut base_scale = AnimeImage::phys_width() / bmp_w;
|
let mut base_scale = AniMeImage::phys_width() / bmp_w;
|
||||||
if base_scale > h {
|
if base_scale > h {
|
||||||
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 cm_from_px = Mat3::from_scale(Vec2::new(base_scale, base_scale));
|
||||||
|
|
||||||
let led_from_cm = Mat3::from_scale(Vec2::new(
|
let led_from_cm = Mat3::from_scale(Vec2::new(
|
||||||
1.0 / AnimeImage::scale_x(),
|
1.0 / AniMeImage::scale_x(),
|
||||||
1.0 / AnimeImage::scale_y(),
|
1.0 / AniMeImage::scale_y(),
|
||||||
));
|
));
|
||||||
|
|
||||||
let transform =
|
let transform =
|
||||||
@@ -258,18 +258,18 @@ impl AnimeImage {
|
|||||||
_ => return Err(AnimeError::Format),
|
_ => 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();
|
matrix.update();
|
||||||
Ok(matrix)
|
Ok(matrix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&AnimeImage> for AniMeDataBuffer {
|
impl From<&AniMeImage> for AniMeDataBuffer {
|
||||||
/// Do conversion from the nested Vec in AniMeMatrix to the two required
|
/// Do conversion from the nested Vec in AniMeMatrix to the two required
|
||||||
/// packets suitable for sending over USB
|
/// packets suitable for sending over USB
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(leds: &AnimeImage) -> Self {
|
fn from(leds: &AniMeImage) -> Self {
|
||||||
let mut l: Vec<u8> = leds
|
let mut l: Vec<u8> = leds
|
||||||
.led_pos
|
.led_pos
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1540,7 +1540,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn led_positions() {
|
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[0], Some(Led(0.0, 0.0, 0)));
|
||||||
assert_eq!(leds[1], Some(Led(1.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)));
|
assert_eq!(leds[2], Some(Led(2.0, 0.0, 0)));
|
||||||
@@ -1569,7 +1569,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn led_positions_const() {
|
fn led_positions_const() {
|
||||||
let leds = AnimeImage::generate();
|
let leds = AniMeImage::generate();
|
||||||
assert_eq!(leds[1], LED_IMAGE_POSITIONS[1]);
|
assert_eq!(leds[1], LED_IMAGE_POSITIONS[1]);
|
||||||
assert_eq!(leds[34], LED_IMAGE_POSITIONS[34]);
|
assert_eq!(leds[34], LED_IMAGE_POSITIONS[34]);
|
||||||
assert_eq!(leds[69], LED_IMAGE_POSITIONS[69]);
|
assert_eq!(leds[69], LED_IMAGE_POSITIONS[69]);
|
||||||
@@ -1583,44 +1583,44 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn row_starts() {
|
fn row_starts() {
|
||||||
assert_eq!(AnimeImage::first_x(5), 0);
|
assert_eq!(AniMeImage::first_x(5), 0);
|
||||||
assert_eq!(AnimeImage::first_x(6), 0);
|
assert_eq!(AniMeImage::first_x(6), 0);
|
||||||
assert_eq!(AnimeImage::first_x(7), 1);
|
assert_eq!(AniMeImage::first_x(7), 1);
|
||||||
assert_eq!(AnimeImage::first_x(8), 1);
|
assert_eq!(AniMeImage::first_x(8), 1);
|
||||||
assert_eq!(AnimeImage::first_x(9), 2);
|
assert_eq!(AniMeImage::first_x(9), 2);
|
||||||
assert_eq!(AnimeImage::first_x(10), 2);
|
assert_eq!(AniMeImage::first_x(10), 2);
|
||||||
assert_eq!(AnimeImage::first_x(11), 3);
|
assert_eq!(AniMeImage::first_x(11), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn row_widths() {
|
fn row_widths() {
|
||||||
assert_eq!(AnimeImage::width(5), 33);
|
assert_eq!(AniMeImage::width(5), 33);
|
||||||
assert_eq!(AnimeImage::width(6), 33);
|
assert_eq!(AniMeImage::width(6), 33);
|
||||||
assert_eq!(AnimeImage::width(7), 32);
|
assert_eq!(AniMeImage::width(7), 32);
|
||||||
assert_eq!(AnimeImage::width(8), 32);
|
assert_eq!(AniMeImage::width(8), 32);
|
||||||
assert_eq!(AnimeImage::width(9), 31);
|
assert_eq!(AniMeImage::width(9), 31);
|
||||||
assert_eq!(AnimeImage::width(10), 31);
|
assert_eq!(AniMeImage::width(10), 31);
|
||||||
assert_eq!(AnimeImage::width(11), 30);
|
assert_eq!(AniMeImage::width(11), 30);
|
||||||
assert_eq!(AnimeImage::width(12), 30);
|
assert_eq!(AniMeImage::width(12), 30);
|
||||||
assert_eq!(AnimeImage::width(13), 29);
|
assert_eq!(AniMeImage::width(13), 29);
|
||||||
assert_eq!(AnimeImage::width(14), 29);
|
assert_eq!(AniMeImage::width(14), 29);
|
||||||
assert_eq!(AnimeImage::width(15), 28);
|
assert_eq!(AniMeImage::width(15), 28);
|
||||||
assert_eq!(AnimeImage::width(16), 28);
|
assert_eq!(AniMeImage::width(16), 28);
|
||||||
assert_eq!(AnimeImage::width(17), 27);
|
assert_eq!(AniMeImage::width(17), 27);
|
||||||
assert_eq!(AnimeImage::width(18), 27);
|
assert_eq!(AniMeImage::width(18), 27);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn row_pitch() {
|
fn row_pitch() {
|
||||||
assert_eq!(AnimeImage::pitch(5), 34);
|
assert_eq!(AniMeImage::pitch(5), 34);
|
||||||
assert_eq!(AnimeImage::pitch(6), 33);
|
assert_eq!(AniMeImage::pitch(6), 33);
|
||||||
assert_eq!(AnimeImage::pitch(7), 33);
|
assert_eq!(AniMeImage::pitch(7), 33);
|
||||||
assert_eq!(AnimeImage::pitch(8), 32);
|
assert_eq!(AniMeImage::pitch(8), 32);
|
||||||
assert_eq!(AnimeImage::pitch(9), 32);
|
assert_eq!(AniMeImage::pitch(9), 32);
|
||||||
assert_eq!(AnimeImage::pitch(10), 31);
|
assert_eq!(AniMeImage::pitch(10), 31);
|
||||||
assert_eq!(AnimeImage::pitch(11), 31);
|
assert_eq!(AniMeImage::pitch(11), 31);
|
||||||
assert_eq!(AnimeImage::pitch(12), 30);
|
assert_eq!(AniMeImage::pitch(12), 30);
|
||||||
assert_eq!(AnimeImage::pitch(13), 30);
|
assert_eq!(AniMeImage::pitch(13), 30);
|
||||||
assert_eq!(AnimeImage::pitch(14), 29);
|
assert_eq!(AniMeImage::pitch(14), 29);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use gif::DecodingError;
|
||||||
use png_pong::decode::Error as PngError;
|
use png_pong::decode::Error as PngError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -7,6 +8,7 @@ pub enum AnimeError {
|
|||||||
NoFrames,
|
NoFrames,
|
||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
Png(PngError),
|
Png(PngError),
|
||||||
|
Gif(DecodingError),
|
||||||
Format
|
Format
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,6 +19,7 @@ impl fmt::Display for AnimeError {
|
|||||||
AnimeError::NoFrames => write!(f, "No frames in PNG"),
|
AnimeError::NoFrames => write!(f, "No frames in PNG"),
|
||||||
AnimeError::Io(e) => write!(f, "Could not open: {}", e),
|
AnimeError::Io(e) => write!(f, "Could not open: {}", e),
|
||||||
AnimeError::Png(e) => write!(f, "PNG error: {}", 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"),
|
AnimeError::Format => write!(f, "PNG file is not 8bit greyscale"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,3 +38,9 @@ impl From<PngError> for AnimeError {
|
|||||||
AnimeError::Png(err)
|
AnimeError::Png(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<DecodingError> for AnimeError {
|
||||||
|
fn from(err: DecodingError) -> Self {
|
||||||
|
AnimeError::Gif(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
/// The main data conversion for transfering in shortform over dbus or other,
|
/// The main data conversion for transfering in shortform over dbus or other,
|
||||||
/// or writing directly to the USB device
|
/// or writing directly to the USB device
|
||||||
mod anime_data;
|
mod anime_data;
|
||||||
|
use std::{path::Path, time::Duration};
|
||||||
|
|
||||||
pub use anime_data::*;
|
pub use anime_data::*;
|
||||||
|
|
||||||
/// Useful for specialised effects that required a grid of data
|
/// Useful for specialised effects that required a grid of data
|
||||||
@@ -14,5 +17,55 @@ pub use anime_image::*;
|
|||||||
mod anime_diagonal;
|
mod anime_diagonal;
|
||||||
pub use anime_diagonal::*;
|
pub use anime_diagonal::*;
|
||||||
|
|
||||||
|
mod anime_gif;
|
||||||
|
pub use anime_gif::*;
|
||||||
|
use error::AnimeError;
|
||||||
|
|
||||||
/// Base errors that are possible
|
/// Base errors that are possible
|
||||||
pub mod error;
|
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<AniMeDataBuffer>),
|
||||||
|
/// A pause to be used between sequences
|
||||||
|
Pause(Duration),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AniMeSequence {
|
||||||
|
pub fn gif(file: &Path, brightness: f32) -> Result<Self, AnimeError> {
|
||||||
|
let frames = AniMeGif::new(file, brightness)?;
|
||||||
|
Ok(Self::Animation(frames))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn png(
|
||||||
|
file: &Path,
|
||||||
|
scale: Vec2,
|
||||||
|
angle: f32,
|
||||||
|
translation: Vec2,
|
||||||
|
brightness: f32,
|
||||||
|
) -> Result<Self, AnimeError> {
|
||||||
|
let image = AniMeImage::from_png(file, scale, angle, translation, brightness)?;
|
||||||
|
let data = <AniMeDataBuffer>::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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||