Implement inverting colors

This commit is contained in:
itsjunetime
2025-02-19 15:24:27 -07:00
parent 8c10a3c4bc
commit 9d2a730e40
5 changed files with 50 additions and 2 deletions
+1
View File
@@ -191,6 +191,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
to_converter.send(ConverterMsg::GoToPage(page))?;
},
InputAction::Search(term) => tui_tx.send(RenderNotif::Search(term))?,
InputAction::Invert => tui_tx.send(RenderNotif::Invert)?
}
}
},
+15 -1
View File
@@ -10,7 +10,8 @@ pub enum RenderNotif {
Area(Rect),
JumpToPage(usize),
Search(String),
Reload
Reload,
Invert
}
#[derive(Debug)]
@@ -90,6 +91,7 @@ pub fn start_rendering(
let col_h = size.height / size.rows;
let mut stored_doc = None;
let mut invert = false;
'reload: loop {
let doc = match Document::open(path) {
@@ -154,6 +156,13 @@ pub fn start_rendering(
($notif:ident) => {
match $notif {
RenderNotif::Reload => continue 'reload,
RenderNotif::Invert => {
invert = !invert;
for page in &mut rendered {
page.successful = false;
}
continue 'render_pages;
}
RenderNotif::Area(new_area) => {
let bigger =
new_area.width > area.width || new_area.height > area.height;
@@ -252,6 +261,7 @@ pub fn start_rendering(
&page,
search_term.as_deref(),
rendered_with_no_results,
invert,
(area_w, area_h)
) {
// If we've already rendered it just fine and we don't need to render it again,
@@ -319,6 +329,7 @@ fn render_single_page_to_ctx(
page: &Page,
search_term: Option<&str>,
already_rendered_no_results: bool,
invert: bool,
(area_w, area_h): (f32, f32)
) -> Result<Option<RenderedContext>, mupdf::error::Error> {
let mut max_hits = 10;
@@ -378,6 +389,9 @@ fn render_single_page_to_ctx(
let matrix = Matrix::new_scale(scale_factor, scale_factor);
let mut pixmap = page.to_pixmap(&matrix, &colorspace, 0.0, false)?;
if invert {
pixmap.invert()?;
}
let (x_res, y_res) = pixmap.resolution();
let new_x = (x_res as f32 * scale_factor) as i32;
+3 -1
View File
@@ -414,6 +414,7 @@ impl Tui {
)));
Some(InputAction::Redraw)
}
'i' => Some(InputAction::Invert),
'n' if self.page < self.rendered.len() - 1 => {
// TODO: If we can't find one, then maybe like block until we've verified
// all the pages have been checked?
@@ -604,7 +605,8 @@ pub enum InputAction {
Redraw,
JumpingToPage(usize),
Search(String),
QuitApp
QuitApp,
Invert
}
#[derive(Copy, Clone)]