mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
term: avoid full image decode when parsing iterm2 protocol
Just decode the size refs: https://github.com/wez/wezterm/issues/537
This commit is contained in:
parent
e5974ad86f
commit
6133f88d6a
@ -4,7 +4,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::color::{ColorPalette, RgbColor};
|
use crate::color::{ColorPalette, RgbColor};
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use image::{self, GenericImageView};
|
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use ordered_float::NotNan;
|
use ordered_float::NotNan;
|
||||||
@ -1572,9 +1571,14 @@ impl TerminalState {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the image data
|
fn dimensions(data: &[u8]) -> anyhow::Result<(u32, u32)> {
|
||||||
let decoded_image = match image::load_from_memory(&image.data) {
|
let reader =
|
||||||
Ok(im) => im,
|
image::io::Reader::new(std::io::Cursor::new(data)).with_guessed_format()?;
|
||||||
|
Ok(reader.into_dimensions()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
let (image_width, image_height) = match dimensions(&image.data) {
|
||||||
|
Ok(dims) => dims,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!(
|
error!(
|
||||||
"Unable to decode image: {}: size={} {:?}",
|
"Unable to decode image: {}: size={} {:?}",
|
||||||
@ -1596,13 +1600,13 @@ impl TerminalState {
|
|||||||
let height = image.height.to_pixels(cell_pixel_height, physical_rows);
|
let height = image.height.to_pixels(cell_pixel_height, physical_rows);
|
||||||
|
|
||||||
// Compute any Automatic dimensions
|
// Compute any Automatic dimensions
|
||||||
let aspect = decoded_image.width() as f32 / decoded_image.height() as f32;
|
let aspect = image_width as f32 / image_height as f32;
|
||||||
|
|
||||||
let (width, height) = match (width, height) {
|
let (width, height) = match (width, height) {
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
// Take the image's native size
|
// Take the image's native size
|
||||||
let width = decoded_image.width() as usize;
|
let width = image_width as usize;
|
||||||
let height = decoded_image.height() as usize;
|
let height = image_height as usize;
|
||||||
// but ensure that it fits
|
// but ensure that it fits
|
||||||
if width as usize > self.pixel_width || height as usize > self.pixel_height {
|
if width as usize > self.pixel_width || height as usize > self.pixel_height {
|
||||||
let width = width as f32;
|
let width = width as f32;
|
||||||
|
Loading…
Reference in New Issue
Block a user