# HG changeset patch # User sheepluva # Date 1624652201 -7200 # Node ID 67f83b7dfc6cfb4ae264ea6caf18f0dfa9c3bf2f # Parent 36816af30583b533da1f4d2a0ad79b206fcb84a2 hedgewars-engine (rust): do something I consider approximate linear filtering for prettier previews diff -r 36816af30583 -r 67f83b7dfc6c rust/hedgewars-engine/src/main.rs --- a/rust/hedgewars-engine/src/main.rs Fri Jun 25 21:44:29 2021 +0200 +++ b/rust/hedgewars-engine/src/main.rs Fri Jun 25 22:16:41 2021 +0200 @@ -34,6 +34,7 @@ const PREVIEW_HEIGHT: u32 = 128; const PREVIEW_NPIXELS: usize = (PREVIEW_WIDTH * PREVIEW_HEIGHT) as usize; const SCALE_FACTOR: u32 = 16; +const VALUE_PER_INPIXEL: u8 = 1; fn resize_mono_preview(mono_pixels: &[u8], in_width: u32, in_height: u32, preview_pixels: &mut [u8]) { @@ -51,9 +52,21 @@ let in_x = h_offset + (x * SCALE_FACTOR); let out_px_address = (PREVIEW_WIDTH * y + x) as usize; - let in_px_address = (in_width * in_y + in_x) as usize; + + let mut in_px_address = (in_width * in_y + in_x) as usize; + + let mut value = 0; - preview_pixels[out_px_address] = mono_pixels[in_px_address]; + for i in 0..SCALE_FACTOR as usize { + for j in 0..SCALE_FACTOR as usize { + if (value < 0xff) && (mono_pixels[in_px_address + j] != 0) { + value += VALUE_PER_INPIXEL; + } + } + in_px_address += in_width as usize; + } + + preview_pixels[out_px_address] = value; } } }