mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
daemon: revert zbus to 1.9.1 in daemon
This commit is contained in:
@@ -26,6 +26,7 @@ impl AniMeFrame {
|
||||
pub struct AniMeGif(Vec<AniMeFrame>);
|
||||
|
||||
impl AniMeGif {
|
||||
/// Create an animation using the 74x36 ASUS gif format
|
||||
pub fn create_diagonal_gif(file_name: &Path, brightness: f32) -> Result<Self, AnimeError> {
|
||||
let mut matrix = AniMeDiagonal::new();
|
||||
|
||||
@@ -61,7 +62,15 @@ impl AniMeGif {
|
||||
Ok(Self(frames))
|
||||
}
|
||||
|
||||
pub fn create_png_gif(file_name: &Path, brightness: f32) -> Result<Self, AnimeError> {
|
||||
/// Create an animation using a gif of any size. This method must precompute the
|
||||
/// result.
|
||||
pub fn create_png_gif(
|
||||
file_name: &Path,
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
translation: Vec2,
|
||||
brightness: f32,
|
||||
) -> Result<Self, AnimeError> {
|
||||
let mut frames = Vec::new();
|
||||
|
||||
let mut decoder = gif::DecodeOptions::new();
|
||||
@@ -76,9 +85,9 @@ impl AniMeGif {
|
||||
let pixels: Vec<Pixel> =
|
||||
vec![Pixel::default(); (decoder.width() as u32 * decoder.height() as u32) as usize];
|
||||
let mut image = AniMeImage::new(
|
||||
Vec2::new(1.0, 1.0),
|
||||
0.0,
|
||||
Vec2::new(0.0, 0.0),
|
||||
Vec2::new(scale, scale),
|
||||
angle,
|
||||
translation,
|
||||
brightness,
|
||||
pixels,
|
||||
decoder.width() as u32,
|
||||
@@ -89,14 +98,8 @@ impl AniMeGif {
|
||||
if matches!(frame.dispose, gif::DisposalMethod::Background) {
|
||||
let pixels: Vec<Pixel> =
|
||||
vec![Pixel::default(); (width as u32 * height as u32) as usize];
|
||||
image = AniMeImage::new(
|
||||
Vec2::new(1.0, 1.0),
|
||||
0.0,
|
||||
Vec2::new(0.0, 0.0),
|
||||
brightness,
|
||||
pixels,
|
||||
width as u32,
|
||||
);
|
||||
image =
|
||||
AniMeImage::new(Vec2::new(scale,scale), angle, translation, brightness, pixels, width as u32);
|
||||
}
|
||||
for (y, row) in frame.buffer.chunks(frame.width as usize * 4).enumerate() {
|
||||
for (x, px) in row.chunks(4).enumerate() {
|
||||
|
||||
@@ -10,12 +10,21 @@ use crate::{
|
||||
|
||||
const LED_PIXEL_LEN: usize = 1244;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) struct Pixel {
|
||||
pub color: u32,
|
||||
pub alpha: f32,
|
||||
}
|
||||
|
||||
impl Default for Pixel {
|
||||
fn default() -> Self {
|
||||
Pixel {
|
||||
color: 0,
|
||||
alpha: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A single LED position and brightness. The intention of this struct
|
||||
/// is to be used to sample an image and set the LED brightness.
|
||||
///
|
||||
@@ -176,18 +185,10 @@ impl AniMeImage {
|
||||
for v in GROUP.iter() {
|
||||
let sample = x0 + *u * du + *v * dv;
|
||||
|
||||
let mut y = sample.y as i32;
|
||||
if y > height - 1 {
|
||||
y = height - 1
|
||||
} else if y < 0 {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
let mut x = sample.x as i32;
|
||||
if x > width - 1 {
|
||||
x = width - 1;
|
||||
} else if x < 0 {
|
||||
x = 0;
|
||||
let x = sample.x as i32;
|
||||
let y = sample.y as i32;
|
||||
if x > width - 1 || y > height - 1 || x < 0 || y < 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let p = self.img_pixels[(x + (y * width)) as usize];
|
||||
@@ -234,7 +235,7 @@ impl AniMeImage {
|
||||
/// updated via scale, position, or angle then displayed again after `update()`.
|
||||
pub fn from_png(
|
||||
path: &Path,
|
||||
scale: Vec2,
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
translation: Vec2,
|
||||
bright: f32,
|
||||
@@ -260,7 +261,7 @@ impl AniMeImage {
|
||||
_ => return Err(AnimeError::Format),
|
||||
};
|
||||
|
||||
let mut matrix = AniMeImage::new(scale, angle, translation, bright, pixels, width);
|
||||
let mut matrix = AniMeImage::new(Vec2::new(scale, scale), angle, translation, bright, pixels, width);
|
||||
|
||||
matrix.update();
|
||||
Ok(matrix)
|
||||
|
||||
@@ -28,7 +28,7 @@ pub mod error;
|
||||
// packet data
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum AniMeSequence {
|
||||
pub enum AniMeBlock {
|
||||
/// Full gif sequence. Immutable.
|
||||
Animation(AniMeGif),
|
||||
/// Basic image, can have properties changed
|
||||
@@ -37,15 +37,15 @@ pub enum AniMeSequence {
|
||||
Pause(Duration),
|
||||
}
|
||||
|
||||
impl AniMeSequence {
|
||||
pub fn gif(file: &Path, brightness: f32) -> Result<Self, AnimeError> {
|
||||
impl AniMeBlock {
|
||||
pub fn asus_gif(file: &Path, brightness: f32) -> Result<Self, AnimeError> {
|
||||
let frames = AniMeGif::create_diagonal_gif(file, brightness)?;
|
||||
Ok(Self::Animation(frames))
|
||||
}
|
||||
|
||||
pub fn png(
|
||||
file: &Path,
|
||||
scale: Vec2,
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
translation: Vec2,
|
||||
brightness: f32,
|
||||
@@ -55,27 +55,34 @@ impl AniMeSequence {
|
||||
Ok(Self::Image(Box::new(data)))
|
||||
}
|
||||
|
||||
pub fn png_gif(
|
||||
pub fn image_gif(
|
||||
file: &Path,
|
||||
// scale: Vec2,
|
||||
// angle: f32,
|
||||
// translation: Vec2,
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
translation: Vec2,
|
||||
brightness: f32,
|
||||
) -> Result<Self, AnimeError> {
|
||||
let frames = AniMeGif::create_png_gif(file, brightness)?;
|
||||
let frames = AniMeGif::create_png_gif(file, scale, angle, translation, brightness)?;
|
||||
Ok(Self::Animation(frames))
|
||||
}
|
||||
|
||||
pub fn get_animation(&self) -> Option<&AniMeGif> {
|
||||
match self {
|
||||
AniMeSequence::Animation(anim) => Some(anim),
|
||||
AniMeBlock::Animation(anim) => Some(anim),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_image(&self) -> Option<&AniMeDataBuffer> {
|
||||
match self {
|
||||
AniMeSequence::Image(image) => Some(image),
|
||||
AniMeBlock::Image(image) => Some(image),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_pause(&self) -> Option<Duration> {
|
||||
match self {
|
||||
AniMeBlock::Pause(pause) => Some(*pause),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user