jp2a ripoff
Diffstat (limited to 'src/picture.rs')
| -rw-r--r-- | src/picture.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/picture.rs b/src/picture.rs index 262def0..8fa1af8 100644 --- a/src/picture.rs +++ b/src/picture.rs @@ -1,4 +1,4 @@ -use image::{DynamicImage, GenericImageView, Pixel, Rgb, Rgba}; +use image::{DynamicImage, GenericImageView, Pixel, Rgb}; #[cfg(rayon)] use rayon::prelude::*; use rgb2ansi256::rgb_to_ansi256; @@ -24,7 +24,7 @@ impl ToText for DynamicImage { let iter = output.par_iter_mut(); iter.enumerate().for_each(|(mut y, output)| { y <<= 1; - let mut last_p: Option<Rgba<u8>> = None; + let mut last_p: Option<u8> = None; for x in 0..self.width() { let p = unsafe { self.unsafe_get_pixel(x, y as u32) }; let y = p.to_luma()[0] as f32 / 255_f32; @@ -32,14 +32,15 @@ impl ToText for DynamicImage { let pos = (p_len * y).round(); let i: usize = (pos * a).round() as usize; let ch = palette[i] as char; + // must round it into ansi256 or we will get duplicates + let color = p.to_rgb().ansi_256(); if let Some(last) = last_p { - if last == p { + if last == color { output.push(ch); continue; } } - let color = p.to_rgb().ansi_256(); - last_p = Some(p); + last_p = Some(color); output.push_str(&fg!(color, ch)); } }); |