wezterm: fix texture coordinates math for image protocols
There was an integer conversion happening when taking the per-cell image texture coordinates and applying them to the texture atlas image coordinates. This commit replaces that math with floating point and corrects the visual artifacts within squirrel.png. refs: #292
This commit is contained in:
1 parent
91ce0b77ea
commit
e2bf111426
2 files changed
+25
-13
No files matched your search
@@ -1344,9 +1344,14 @@ impl TerminalState {
|
||||
let cursor_x = self.cursor.x;
|
||||
let x_delta = 1.0 / (width as f32 / (self.pixel_width as f32 / physical_cols as f32));
|
||||
let y_delta = 1.0 / (height as f32 / (self.pixel_height as f32 / physical_rows as f32));
|
||||
log::error!(
|
||||
log::debug!(
|
||||
"image is {}x{} cells, {}x{} pixels, x_delta:{} y_delta:{}",
|
||||
width_in_cells, height_in_cells, width, height, x_delta, y_delta,
|
||||
width_in_cells,
|
||||
height_in_cells,
|
||||
width,
|
||||
height,
|
||||
x_delta,
|
||||
y_delta,
|
||||
);
|
||||
for _ in 0..height_in_cells {
|
||||
let mut xpos = NotNan::new(0.0).unwrap();
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::scripting::pane::PaneObject;
|
||||
use ::wezterm_term::input::MouseButton as TMB;
|
||||
use ::wezterm_term::input::MouseEventKind as TMEK;
|
||||
use ::window::bitmaps::atlas::{OutOfTextureSpace, SpriteSlice};
|
||||
use ::window::bitmaps::Texture2d;
|
||||
use ::window::bitmaps::{Texture2d, TextureCoord, TextureRect, TextureSize};
|
||||
use ::window::glium::uniforms::{
|
||||
MagnifySamplerFilter, MinifySamplerFilter, Sampler, SamplerWrapFunction,
|
||||
};
|
||||
@@ -2841,20 +2841,27 @@ impl TermWindow {
|
||||
|
||||
let top_left = image.top_left();
|
||||
let bottom_right = image.bottom_right();
|
||||
let origin = Point::new(
|
||||
sprite.coords.origin.x + (*top_left.x * width as f32) as isize,
|
||||
sprite.coords.origin.y + (*top_left.y * height as f32) as isize,
|
||||
|
||||
// We *could* call sprite.texture.to_texture_coords() here,
|
||||
// but since that takes integer pixel coordinates, we'd
|
||||
// lose precision and end up with visual artifacts.
|
||||
// Instead, we compute the texture coords here in floating point.
|
||||
|
||||
let texture_width = sprite.texture.width() as f32;
|
||||
let texture_height = sprite.texture.height() as f32;
|
||||
let origin = TextureCoord::new(
|
||||
(sprite.coords.origin.x as f32 + (*top_left.x * width as f32))
|
||||
/ texture_width,
|
||||
(sprite.coords.origin.y as f32 + (*top_left.y * height as f32))
|
||||
/ texture_height,
|
||||
);
|
||||
|
||||
let coords = Rect::new(
|
||||
origin,
|
||||
Size::new(
|
||||
((*bottom_right.x - *top_left.x) * width as f32) as isize,
|
||||
((*bottom_right.y - *top_left.y) * height as f32) as isize,
|
||||
),
|
||||
let size = TextureSize::new(
|
||||
(*bottom_right.x - *top_left.x) * width as f32 / texture_width,
|
||||
(*bottom_right.y - *top_left.y) * height as f32 / texture_height,
|
||||
);
|
||||
|
||||
let texture_rect = sprite.texture.to_texture_coords(coords);
|
||||
let texture_rect = TextureRect::new(origin, size);
|
||||
|
||||
let mut quad = match quads.cell(cell_idx, params.line_idx) {
|
||||
Ok(quad) => quad,
|
||||
|
||||
Reference in new issue
Block a user