mirror of
https://github.com/wez/wezterm.git
synced 2024-11-27 02:25:28 +03:00
glyphcache: add some more error context
This commit is contained in:
parent
8c931dcbcb
commit
8d0b84a5ce
@ -5,6 +5,7 @@ use ::window::bitmaps::atlas::{Atlas, OutOfTextureSpace, Sprite};
|
||||
use ::window::bitmaps::{BitmapImage, Image, ImageTexture, Texture2d};
|
||||
use ::window::color::SrgbaPixel;
|
||||
use ::window::{Point, Rect};
|
||||
use anyhow::Context;
|
||||
use config::{AllowSquareGlyphOverflow, TextStyle};
|
||||
use euclid::num::Zero;
|
||||
use image::io::Limits;
|
||||
@ -213,8 +214,10 @@ impl FrameDecoder {
|
||||
pub fn start(lease: BlobLease) -> anyhow::Result<Receiver<DecodedFrame>> {
|
||||
let (tx, rx) = sync_channel(2);
|
||||
|
||||
let buf_reader = lease.get_reader()?;
|
||||
let reader = image::io::Reader::new(buf_reader).with_guessed_format()?;
|
||||
let buf_reader = lease.get_reader().context("lease.get_reader()")?;
|
||||
let reader = image::io::Reader::new(buf_reader)
|
||||
.with_guessed_format()
|
||||
.context("guess format from lease")?;
|
||||
let format = reader
|
||||
.format()
|
||||
.ok_or_else(|| anyhow::anyhow!("cannot determine image format"))?;
|
||||
@ -243,24 +246,26 @@ impl FrameDecoder {
|
||||
let mut frames = match format {
|
||||
ImageFormat::Gif => {
|
||||
let mut reader = reader.into_inner();
|
||||
reader.rewind()?;
|
||||
let decoder = image::codecs::gif::GifDecoder::with_limits(reader, limits)?;
|
||||
reader.rewind().context("rewinding reader for gif")?;
|
||||
let decoder = image::codecs::gif::GifDecoder::with_limits(reader, limits)
|
||||
.context("GifDecoder::with_limits")?;
|
||||
decoder.into_frames()
|
||||
}
|
||||
ImageFormat::Png => {
|
||||
let mut reader = reader.into_inner();
|
||||
reader.rewind()?;
|
||||
let decoder = image::codecs::png::PngDecoder::with_limits(reader, limits.clone())?;
|
||||
reader.rewind().context("rewinding reader for png")?;
|
||||
let decoder = image::codecs::png::PngDecoder::with_limits(reader, limits.clone())
|
||||
.context("PngDecoder::with_limits")?;
|
||||
if decoder.is_apng() {
|
||||
decoder.apng().into_frames()
|
||||
} else {
|
||||
let size = decoder.total_bytes() as usize;
|
||||
let mut buf = vec![0u8; size];
|
||||
let (width, height) = decoder.dimensions();
|
||||
let mut reader = decoder.into_reader()?;
|
||||
let mut reader = decoder.into_reader().context("PngDecoder into_reader")?;
|
||||
reader.read(&mut buf)?;
|
||||
let buf = image::RgbaImage::from_raw(width, height, buf).ok_or_else(|| {
|
||||
anyhow::anyhow!("inconsistent {width}x{height} -> {size}")
|
||||
anyhow::anyhow!("PNG data is inconsistent: {width}x{height}x4 is {} but is we have {size} bytes of data", width*height*4)
|
||||
})?;
|
||||
let delay = image::Delay::from_numer_denom_ms(u32::MAX, 1);
|
||||
let frame = Frame::from_parts(buf, 0, 0, delay);
|
||||
@ -269,13 +274,16 @@ impl FrameDecoder {
|
||||
}
|
||||
ImageFormat::WebP => {
|
||||
let mut reader = reader.into_inner();
|
||||
reader.rewind()?;
|
||||
let mut decoder = image::codecs::webp::WebPDecoder::new(reader)?;
|
||||
decoder.set_limits(limits)?;
|
||||
reader.rewind().context("rewinding reader for WebP")?;
|
||||
let mut decoder =
|
||||
image::codecs::webp::WebPDecoder::new(reader).context("WebPDecoder")?;
|
||||
decoder
|
||||
.set_limits(limits)
|
||||
.context("WebPDecoder::set_limits")?;
|
||||
decoder.into_frames()
|
||||
}
|
||||
_ => {
|
||||
let buf = reader.decode()?;
|
||||
let buf = reader.decode().context("decode image")?;
|
||||
let delay = image::Delay::from_numer_denom_ms(u32::MAX, 1);
|
||||
let frame = Frame::from_parts(buf.into_rgba8(), 0, 0, delay);
|
||||
Frames::new(Box::new(std::iter::once(ImageResult::Ok(frame))))
|
||||
@ -289,7 +297,7 @@ impl FrameDecoder {
|
||||
"Image format is not fully supported by \
|
||||
https://github.com/image-rs/image/blob/master/README.md#supported-image-formats")
|
||||
})?;
|
||||
let frame = frame?;
|
||||
let frame = frame.context("first frame result")?;
|
||||
|
||||
let mut decoded_frames = vec![];
|
||||
let (width, height) = frame.buffer().dimensions();
|
||||
@ -300,14 +308,15 @@ impl FrameDecoder {
|
||||
log::debug!("first frame took {:?} to decode.", start.elapsed());
|
||||
|
||||
let data = frame.into_buffer().into_raw();
|
||||
let lease = BlobManager::store(&data)?;
|
||||
let lease = BlobManager::store(&data).context("BlobManager::store")?;
|
||||
let decoded_frame = DecodedFrame {
|
||||
lease,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
};
|
||||
tx.send(decoded_frame.clone())?;
|
||||
tx.send(decoded_frame.clone())
|
||||
.context("sending first frame")?;
|
||||
decoded_frames.push(decoded_frame);
|
||||
|
||||
while let Some(frame) = frames.next() {
|
||||
@ -315,7 +324,7 @@ impl FrameDecoder {
|
||||
|
||||
let duration: Duration = frame.delay().into();
|
||||
let data = frame.into_buffer().into_raw();
|
||||
let lease = BlobManager::store(&data)?;
|
||||
let lease = BlobManager::store(&data).context("BlobManager::store")?;
|
||||
|
||||
let decoded_frame = DecodedFrame {
|
||||
lease,
|
||||
@ -323,7 +332,7 @@ impl FrameDecoder {
|
||||
width,
|
||||
height,
|
||||
};
|
||||
tx.send(decoded_frame.clone())?;
|
||||
tx.send(decoded_frame.clone()).context("sending a frame")?;
|
||||
decoded_frames.push(decoded_frame);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user