mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 08:21:47 +00:00
Get max_image_side from GL and limit media (resize) to it
This commit is contained in:
parent
8f65e87f37
commit
29cb75dd7b
@ -643,6 +643,23 @@ impl GossipUi {
|
||||
let theme = Theme::from_settings();
|
||||
theme::apply_theme(&theme, &cctx.egui_ctx);
|
||||
|
||||
// Let gossip-lib know the max texture side so it can resize things that are
|
||||
// too large.
|
||||
{
|
||||
let mut max_image_side = if let Some(context) = &cctx.gl {
|
||||
use eframe::glow::HasContext;
|
||||
unsafe { context.get_parameter_i32(eframe::glow::MAX_TEXTURE_SIZE) as usize }
|
||||
} else {
|
||||
2048
|
||||
};
|
||||
if max_image_side > 16384 {
|
||||
max_image_side = 16384;
|
||||
}
|
||||
GLOBALS
|
||||
.max_image_side
|
||||
.store(max_image_side, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
GossipUi {
|
||||
#[cfg(feature = "video-ffmpeg")]
|
||||
audio_device,
|
||||
|
@ -113,6 +113,9 @@ pub struct Globals {
|
||||
/// UI invalidate all
|
||||
pub ui_invalidate_all: AtomicBool,
|
||||
|
||||
/// Max image side length that can be rendered
|
||||
pub max_image_side: AtomicUsize,
|
||||
|
||||
/// Current zap data, for UI
|
||||
pub current_zap: PRwLock<ZapState>,
|
||||
|
||||
@ -200,6 +203,7 @@ lazy_static! {
|
||||
ui_notes_to_invalidate: PRwLock::new(Vec::new()),
|
||||
ui_people_to_invalidate: PRwLock::new(Vec::new()),
|
||||
ui_invalidate_all: AtomicBool::new(false),
|
||||
max_image_side: AtomicUsize::new(2048),
|
||||
current_zap: PRwLock::new(ZapState::None),
|
||||
hashtag_regex: Regex::new(r"(?:^|\W)(#[\w\p{Extended_Pictographic}]+)(?:$|\W)").unwrap(),
|
||||
tagging_regex: Regex::new(r"(?:^|\s+)@([\w\p{Extended_Pictographic}]+)(?:$|\W)").unwrap(),
|
||||
|
@ -172,12 +172,13 @@ pub(crate) fn load_image_bytes(
|
||||
force_resize: bool,
|
||||
round: bool,
|
||||
) -> Result<RgbaImage, Error> {
|
||||
let max_image_side = GLOBALS.max_image_side.load(Ordering::Relaxed) as u32;
|
||||
if let Ok(mut image) = image::load_from_memory(image_bytes) {
|
||||
image = adjust_orientation(image_bytes, image);
|
||||
if square {
|
||||
image = crop_square(image);
|
||||
}
|
||||
if force_resize || image.width() > 16384 || image.height() > 16384 {
|
||||
if force_resize || image.width() > max_image_side || image.height() > max_image_side {
|
||||
// https://docs.rs/image/latest/image/imageops/enum.FilterType.html
|
||||
let algo = match &*GLOBALS.storage.read_setting_image_resize_algorithm() {
|
||||
"Nearest" => FilterType::Nearest,
|
||||
@ -200,7 +201,9 @@ pub(crate) fn load_image_bytes(
|
||||
let opt = usvg::Options::default();
|
||||
let rtree = usvg::Tree::from_data(image_bytes, &opt)?;
|
||||
let pixmap_size = rtree.size.to_int_size();
|
||||
let [w, h] = if force_resize || pixmap_size.width() > 16384 || pixmap_size.height() > 16384
|
||||
let [w, h] = if force_resize
|
||||
|| pixmap_size.width() > max_image_side
|
||||
|| pixmap_size.height() > max_image_side
|
||||
{
|
||||
[default_size, default_size]
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user