implement sharpen
This commit is contained in:
parent
ea7262f8f5
commit
f64365f5bd
|
@ -127,6 +127,13 @@ impl LedwandDither {
|
||||||
Self::blur_inner_pixels(source, destination);
|
Self::blur_inner_pixels(source, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sharpen(source: &GrayImage, destination: &mut GrayImage) {
|
||||||
|
assert_eq!(source.len(), destination.len());
|
||||||
|
|
||||||
|
Self::copy_border(source, destination);
|
||||||
|
Self::sharpen_inner_pixels(source, destination);
|
||||||
|
}
|
||||||
|
|
||||||
fn copy_border(source: &GrayImage, destination: &mut GrayImage) {
|
fn copy_border(source: &GrayImage, destination: &mut GrayImage) {
|
||||||
let last_row = source.height() -1;
|
let last_row = source.height() -1;
|
||||||
for x in 0..source.width() {
|
for x in 0..source.width() {
|
||||||
|
@ -157,4 +164,21 @@ impl LedwandDither {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sharpen_inner_pixels(source: &GrayImage, destination: &mut GrayImage) {
|
||||||
|
for y in 1..source.height() - 2 {
|
||||||
|
for x in 1..source.width() - 2 {
|
||||||
|
let weighted_sum = -(source.get_pixel(x - 1, y - 1).0[0] as i32)
|
||||||
|
- source.get_pixel(x, y - 1).0[0] as i32
|
||||||
|
- source.get_pixel(x + 1, y - 1).0[0] as i32
|
||||||
|
- source.get_pixel(x - 1, y).0[0] as i32
|
||||||
|
+ 9 * source.get_pixel(x, y).0[0] as i32
|
||||||
|
- source.get_pixel(x + 1, y).0[0] as i32
|
||||||
|
- source.get_pixel(x - 1, y + 1).0[0] as i32
|
||||||
|
- source.get_pixel(x, y + 1).0[0] as i32
|
||||||
|
- source.get_pixel(x + 1, y + 1).0[0] as i32;
|
||||||
|
destination.get_pixel_mut(x, y).0[0] = weighted_sum.clamp(u8::MIN as i32, u8::MAX as i32) as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,17 @@ pub fn stream_window(connection: &Connection, options: StreamScreenOptions) {
|
||||||
loop {
|
loop {
|
||||||
let mut frame = get_next_frame(&capturer);
|
let mut frame = get_next_frame(&capturer);
|
||||||
|
|
||||||
|
LedwandDither::histogram_correction(&mut frame);
|
||||||
|
|
||||||
|
let mut orig = frame.clone();
|
||||||
|
LedwandDither::blur(&orig, &mut frame);
|
||||||
|
|
||||||
|
std::mem::swap(&mut frame, &mut orig);
|
||||||
|
LedwandDither::sharpen(&orig, &mut frame);
|
||||||
|
|
||||||
let cutoff = if options.no_dither {
|
let cutoff = if options.no_dither {
|
||||||
LedwandDither::median_brightness(&frame)
|
LedwandDither::median_brightness(&frame)
|
||||||
} else {
|
} else {
|
||||||
LedwandDither::histogram_correction(&mut frame);
|
|
||||||
LedwandDither::blur(&frame.clone(), &mut frame);
|
|
||||||
dither(&mut frame, &BiLevel);
|
dither(&mut frame, &BiLevel);
|
||||||
u8::MAX / 2
|
u8::MAX / 2
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue