mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Return error if a pixel-gif is larger than the anime-display dimensions
This commit is contained in:
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased ]
|
## [Unreleased ]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Clear command for anime `asusctl anime --clear` will clear the display
|
||||||
|
### Changed
|
||||||
|
- Make rog-anime more error tolerent. Remove various asserts and return errors instead
|
||||||
|
- Return error if a pixel-gif is larger than the anime-display dimensions
|
||||||
|
|
||||||
## [4.2.1] - 2022-07-18
|
## [4.2.1] - 2022-07-18
|
||||||
### Added
|
### Added
|
||||||
- Add panel overdrive support (autodetects if supported)
|
- Add panel overdrive support (autodetects if supported)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ pub struct AnimeCommand {
|
|||||||
pub boot_enable: Option<bool>,
|
pub boot_enable: Option<bool>,
|
||||||
#[options(meta = "", help = "set global AniMe brightness value")]
|
#[options(meta = "", help = "set global AniMe brightness value")]
|
||||||
pub brightness: Option<f32>,
|
pub brightness: Option<f32>,
|
||||||
|
#[options(help = "clear the display")]
|
||||||
|
pub clear: bool,
|
||||||
#[options(command)]
|
#[options(command)]
|
||||||
pub command: Option<AnimeActions>,
|
pub command: Option<AnimeActions>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,13 @@ fn handle_anime(
|
|||||||
verify_brightness(bright);
|
verify_brightness(bright);
|
||||||
dbus.proxies().anime().set_brightness(bright)?
|
dbus.proxies().anime().set_brightness(bright)?
|
||||||
}
|
}
|
||||||
|
if cmd.clear {
|
||||||
|
let anime_type = get_anime_type()?;
|
||||||
|
let data = vec![0u8; anime_type.data_length()];
|
||||||
|
let tmp = AnimeDataBuffer::from_vec(anime_type, data)?;
|
||||||
|
dbus.proxies().anime().write(tmp)?;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(action) = cmd.command.as_ref() {
|
if let Some(action) = cmd.command.as_ref() {
|
||||||
let anime_type = get_anime_type()?;
|
let anime_type = get_anime_type()?;
|
||||||
match action {
|
match action {
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ pub enum AnimeError {
|
|||||||
UnsupportedDevice,
|
UnsupportedDevice,
|
||||||
InvalidBrightness(f32),
|
InvalidBrightness(f32),
|
||||||
DataBufferLength,
|
DataBufferLength,
|
||||||
|
PixelGifWidth(usize),
|
||||||
|
PixelGifHeight(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for AnimeError {
|
impl fmt::Display for AnimeError {
|
||||||
@@ -49,6 +51,13 @@ impl fmt::Display for AnimeError {
|
|||||||
"Image brightness must be between 0.0 and 1.0 (inclusive), was {}",
|
"Image brightness must be between 0.0 and 1.0 (inclusive), was {}",
|
||||||
bright
|
bright
|
||||||
),
|
),
|
||||||
|
AnimeError::PixelGifWidth(n) => {
|
||||||
|
write!(f, "The gif used for pixel-perfect gif is is wider than {n}")
|
||||||
|
}
|
||||||
|
AnimeError::PixelGifHeight(n) => write!(
|
||||||
|
f,
|
||||||
|
"The gif used for pixel-perfect gif is is taller than {n}"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use serde_derive::{Deserialize, Serialize};
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::{fs::File, path::Path, time::Duration};
|
use std::{fs::File, path::Path, time::Duration};
|
||||||
|
|
||||||
|
use crate::error::AnimeError;
|
||||||
use crate::{error::Result, AnimeDataBuffer, AnimeDiagonal, AnimeImage, AnimeType, Pixel};
|
use crate::{error::Result, AnimeDataBuffer, AnimeDiagonal, AnimeImage, AnimeType, Pixel};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
@@ -117,8 +118,17 @@ impl AnimeGif {
|
|||||||
// should be t but not in some gifs? What, ASUS, what?
|
// should be t but not in some gifs? What, ASUS, what?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
matrix.get_mut()[y + frame.top as usize][x + frame.left as usize] =
|
let tmp = matrix.get_mut();
|
||||||
(px[0] as f32 * brightness) as u8;
|
let y = y + frame.top as usize;
|
||||||
|
if y >= tmp.len() {
|
||||||
|
return Err(AnimeError::PixelGifHeight(tmp.len()));
|
||||||
|
}
|
||||||
|
let x = x + frame.left as usize;
|
||||||
|
if x >= tmp[y].len() {
|
||||||
|
return Err(AnimeError::PixelGifWidth(tmp[y].len()));
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix.get_mut()[y][x] = (px[0] as f32 * brightness) as u8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user