fix: homepage cover images are now in much better quality without bigger memory use (#862)
* fix: fixed background covers rendering poorly on bigger resolutions * fix: fixed onboarding cached images stacking from ~80MB to again ~20MB (like it was before)
This commit is contained in:
parent
2f7476ba6e
commit
36a925da06
3 changed files with 8 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ use crate::layout::AnimatedAppOutlet;
|
|||
use crate::theme;
|
||||
use crate::use_settings_snapshot;
|
||||
use oneclient_core::clusters::Cluster;
|
||||
use oneclient_core::images::BACKGROUND_IMAGE_EDGE;
|
||||
use oneclient_db::models::ClusterId;
|
||||
|
||||
use crate::hooks::{
|
||||
|
|
@ -274,6 +275,7 @@ fn home_cluster(clusters: &[Cluster], active: Option<ClusterId>) -> Option<&Clus
|
|||
fn home_art(cluster: Option<&Cluster>) -> DynamicArt {
|
||||
cluster
|
||||
.map_or_else(DynamicArt::fallback, DynamicArt::for_cluster)
|
||||
.max_edge(BACKGROUND_IMAGE_EDGE)
|
||||
.preview_edge(ART_PREVIEW_EDGE)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ impl Component for LoadingBackdrop {
|
|||
let pan_x = cx * sw * PARALLAX_STRENGTH;
|
||||
let pan_y = cy * sh * PARALLAX_STRENGTH;
|
||||
|
||||
// Default edge on purpose home shows the same art next so the same variant avoids a second fetch
|
||||
let art = match clusters.get(current) {
|
||||
Some(cluster) => DynamicArt::for_cluster(cluster),
|
||||
None => DynamicArt::fallback(),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ use polyio::sha1_bytes;
|
|||
|
||||
pub const DEFAULT_IMAGE_EDGE: u32 = 1200;
|
||||
|
||||
pub const BACKGROUND_IMAGE_EDGE: u32 = 2560;
|
||||
|
||||
/// Image urls come from untrusted remote descriptions, so cap what is fetched and decoded.
|
||||
const MAX_IMAGE_BYTES: usize = 8 * 1024 * 1024;
|
||||
|
||||
|
|
@ -135,6 +137,10 @@ static DECODE_LIMIT: std::sync::LazyLock<tokio::sync::Semaphore> =
|
|||
std::sync::LazyLock::new(|| tokio::sync::Semaphore::new(2));
|
||||
|
||||
async fn downscale_if_oversized(bytes: Bytes, max_edge: u32) -> Bytes {
|
||||
if max_edge == 0 {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
let _permit = DECODE_LIMIT.acquire().await;
|
||||
let candidate = bytes.clone();
|
||||
match tokio::task::spawn_blocking(move || downscale(&candidate, max_edge)).await {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue