|
| 1 | +use crate::get_dimensions; |
1 | 2 | use anyhow::{Context, Result}; |
2 | 3 | use color_quant::NeuQuant; |
3 | 4 | use image::{ |
4 | 5 | imageops::{colorops, FilterType}, |
5 | 6 | DynamicImage, GenericImageView, ImageBuffer, Pixel, Rgb, |
6 | 7 | }; |
7 | 8 | use libc::{ |
8 | | - c_void, ioctl, poll, pollfd, read, tcgetattr, tcsetattr, termios, winsize, ECHO, ICANON, |
9 | | - POLLIN, STDIN_FILENO, STDOUT_FILENO, TCSANOW, TIOCGWINSZ, |
| 9 | + c_void, poll, pollfd, read, tcgetattr, tcsetattr, termios, ECHO, ICANON, POLLIN, STDIN_FILENO, |
| 10 | + TCSANOW, |
10 | 11 | }; |
11 | 12 | use std::io::{stdout, Write}; |
12 | 13 | use std::time::Instant; |
@@ -80,19 +81,15 @@ impl Default for SixelBackend { |
80 | 81 | impl super::ImageBackend for SixelBackend { |
81 | 82 | #[allow(clippy::map_entry)] |
82 | 83 | fn add_image(&self, lines: Vec<String>, image: &DynamicImage, colors: usize) -> Result<String> { |
83 | | - let tty_size = unsafe { |
84 | | - let tty_size: winsize = std::mem::zeroed(); |
85 | | - ioctl(STDOUT_FILENO, TIOCGWINSZ, &tty_size); |
86 | | - tty_size |
87 | | - }; |
| 84 | + let tty_size = unsafe { get_dimensions() }; |
88 | 85 | let cw = tty_size.ws_xpixel / tty_size.ws_col; |
89 | 86 | let lh = tty_size.ws_ypixel / tty_size.ws_row; |
90 | 87 | let width_ratio = 1.0 / cw as f64; |
91 | 88 | let height_ratio = 1.0 / lh as f64; |
92 | 89 |
|
93 | 90 | // resize image to fit the text height with the Lanczos3 algorithm |
94 | 91 | let image = image.resize( |
95 | | - u32::max_value(), |
| 92 | + u32::MAX, |
96 | 93 | (lines.len() as f64 / height_ratio) as u32, |
97 | 94 | FilterType::Lanczos3, |
98 | 95 | ); |
|
0 commit comments