From 26e6eca2088ab56c272c4365768e03ea20e321c9 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sat, 5 May 2018 15:14:57 +0200 Subject: [PATCH] Fixed auto scaling and added X8 on Linux Closes #51 Closes #52 --- src/native/x11/X11MiniFB.c | 40 ++++++++++++++++++++++++++++++++++++++ src/os/unix/mod.rs | 7 ++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/native/x11/X11MiniFB.c b/src/native/x11/X11MiniFB.c index cabb838..4a9609e 100644 --- a/src/native/x11/X11MiniFB.c +++ b/src/native/x11/X11MiniFB.c @@ -515,6 +515,41 @@ static void scale_4x(unsigned int* dest, unsigned int* source, int width, int he } } + +#define write_8(offset) \ + dest[(width * offset) + 0] = t; \ + dest[(width * offset) + 1] = t; \ + dest[(width * offset) + 2] = t; \ + dest[(width * offset) + 3] = t; \ + dest[(width * offset) + 4] = t; \ + dest[(width * offset) + 5] = t; \ + dest[(width * offset) + 6] = t; \ + dest[(width * offset) + 7] = t; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static void scale_8x(unsigned int* dest, unsigned int* source, int width, int height, int scale) { + int x, y; + for (y = 0; y < height; y += scale) { + for (x = 0; x < width; x += scale) { + const unsigned int t = *source++; + + write_8(0); + write_8(1); + write_8(2); + write_8(3); + write_8(4); + write_8(5); + write_8(6); + write_8(7); + + dest += scale; + } + + dest += width * (scale - 1); + } +} + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void mfb_update_with_buffer(void* window_info, void* buffer) @@ -539,6 +574,11 @@ void mfb_update_with_buffer(void* window_info, void* buffer) scale_4x(info->draw_buffer, buffer, width, height, scale); break; } + + case 8: { + scale_8x(info->draw_buffer, buffer, width, height, scale); + break; + } } XPutImage(s_display, info->window, s_gc, info->ximage, 0, 0, 0, 0, width, height); diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs index 2cfc753..61a3a13 100644 --- a/src/os/unix/mod.rs +++ b/src/os/unix/mod.rs @@ -374,6 +374,7 @@ impl Window { Scale::X1 => 1, Scale::X2 => 2, Scale::X4 => 4, + Scale::X8 => 8, Scale::FitScreen => { let wh: u32 = mfb_get_screen_size(); let screen_x = (wh >> 16) as i32; @@ -387,15 +388,15 @@ impl Window { let w = width as i32 * (scale + 1); let h = height as i32 * (scale + 1); - if w > screen_x || h > screen_y { + if w >= screen_x || h >= screen_y { break; } scale *= 2; } - if scale >= 4 { - 4 + if scale >= 8 { + 8 } else { scale }