better dithering, keep aspect ratio, send image #2
					 2 changed files with 32 additions and 2 deletions
				
			
		|  | @ -127,6 +127,13 @@ impl LedwandDither { | |||
|         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) { | ||||
|         let last_row = source.height() -1; | ||||
|         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 { | ||||
|         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 { | ||||
|             LedwandDither::median_brightness(&frame) | ||||
|         } else { | ||||
|             LedwandDither::histogram_correction(&mut frame); | ||||
|             LedwandDither::blur(&frame.clone(), &mut frame); | ||||
|             dither(&mut frame, &BiLevel); | ||||
|             u8::MAX / 2 | ||||
|         }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue