mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 997631aac9 | |||
| 725c6c6bfd | |||
| fca61d55b5 |
@@ -1,6 +1,8 @@
|
||||
# Unreleased
|
||||
|
||||
- Added windows support! (thank you to [@jarjk](https://github.com/jarjk) for helping out!)
|
||||
- Added keybindings (`0`/`$`) to scroll to left or right side of zoomed-in image ([#131](https://github.com/itsjunetime/tdf/pull/131), thank you [@IshDeshpa](https://github.com/IshDeshpa)!)
|
||||
- (Internal) decreased runtime footprint of tokio runtime
|
||||
|
||||
# v0.5.0
|
||||
|
||||
|
||||
@@ -34,7 +34,12 @@ fn for_all_combos(
|
||||
name: &'static str,
|
||||
mut f: impl FnMut(&Runtime, BenchmarkId, &'static str, ProtocolType)
|
||||
) {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(3)
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
for proto in PROTOS {
|
||||
for file in FILES {
|
||||
f(
|
||||
|
||||
+1
-1
Submodule ratatui-image updated: a276a87cb8...8ad154a219
+23
-16
@@ -1,11 +1,12 @@
|
||||
use std::{
|
||||
io::Cursor,
|
||||
num::NonZeroUsize,
|
||||
time::{SystemTime, UNIX_EPOCH}
|
||||
};
|
||||
|
||||
use flume::{Receiver, SendError, Sender, TryRecvError};
|
||||
use futures_util::stream::StreamExt as _;
|
||||
use image::DynamicImage;
|
||||
use image::{DynamicImage, codecs::pnm::PnmDecoder};
|
||||
use kittage::{NumberOrId, action::NONZERO_ONE};
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui_image::{
|
||||
@@ -111,22 +112,26 @@ pub async fn run_conversion_loop(
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut dyn_img = image::load_from_memory_with_format(
|
||||
&page_info.img_data.pixels,
|
||||
image::ImageFormat::Pnm
|
||||
)
|
||||
.map_err(|e| RenderError::Converting(format!("Can't load image: {e}")))?;
|
||||
let decoder = PnmDecoder::new(Cursor::new(&page_info.img_data.pixels)).map_err(|e| {
|
||||
RenderError::Converting(format!(
|
||||
"The image data provided from mupdf was not in pnm format ({e}); don't know how to convert"
|
||||
))
|
||||
})?;
|
||||
|
||||
match dyn_img {
|
||||
DynamicImage::ImageRgb8(ref mut img) =>
|
||||
for quad in &*page_info.result_rects {
|
||||
img.par_enumerate_pixels_mut()
|
||||
.filter(|(x, y, _)| {
|
||||
*x > quad.ul_x && *x < quad.lr_x && *y > quad.ul_y && *y < quad.lr_y
|
||||
})
|
||||
.for_each(|(_, _, px)| px.0[2] = px.0[2].saturating_sub(u8::MAX / 2));
|
||||
},
|
||||
_ => unreachable!()
|
||||
// The image we get should always already be `ImageRgb8`, so this `into` shouldn't do any
|
||||
// conversions or anything, but just in case some underlying detail of mupdf or image
|
||||
// changes, we do the `into` instead of just `match + unreachable!()` to avoid panicking
|
||||
let mut dyn_img = DynamicImage::from_decoder(decoder)
|
||||
.map_err(|e| RenderError::Converting(format!("Can't load image: {e}")))?
|
||||
.into_rgb8();
|
||||
|
||||
for quad in &*page_info.result_rects {
|
||||
dyn_img
|
||||
.par_enumerate_pixels_mut()
|
||||
.filter(|(x, y, _)| {
|
||||
*x > quad.ul_x && *x < quad.lr_x && *y > quad.ul_y && *y < quad.lr_y
|
||||
})
|
||||
.for_each(|(_, _, px)| px.0[2] = px.0[2].saturating_sub(u8::MAX / 2));
|
||||
}
|
||||
|
||||
let img_area = Rect {
|
||||
@@ -136,6 +141,8 @@ pub async fn run_conversion_loop(
|
||||
y: 0
|
||||
};
|
||||
|
||||
let dyn_img = DynamicImage::ImageRgb8(dyn_img);
|
||||
|
||||
let txt_img = match picker.protocol_type() {
|
||||
ProtocolType::Kitty => {
|
||||
let rn = SystemTime::now()
|
||||
|
||||
+12
-5
@@ -70,11 +70,18 @@ fn reset_term() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), WrappedErr> {
|
||||
let result = inner_main().await;
|
||||
reset_term();
|
||||
result
|
||||
fn main() -> Result<(), WrappedErr> {
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(3)
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
rt.block_on(async move {
|
||||
let result = inner_main().await;
|
||||
reset_term();
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
async fn inner_main() -> Result<(), WrappedErr> {
|
||||
|
||||
Reference in New Issue
Block a user